Qt Utilities 6.10.0
Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models
desktoputils.cpp
Go to the documentation of this file.
1#include "./desktoputils.h"
2
3#include <QDesktopServices>
4#include <QUrl>
5#ifdef Q_OS_WIN32
6#include <QFileInfo>
7#endif
8
9namespace QtUtilities {
10
21bool openLocalFileOrDir(const QString &path)
22{
23 QUrl url(QStringLiteral("file://"));
24
25#ifdef Q_OS_WIN32
26 // replace backslashes with regular slashes
27 QString tmp(path);
28 tmp.replace(QChar('\\'), QChar('/'));
29
30 // add a slash before the drive letter of an absolute path
31 if (QFileInfo(path).isAbsolute()) {
32 tmp = QStringLiteral("/") + tmp;
33 }
34 url.setPath(tmp, QUrl::DecodedMode);
35
36#else
37 url.setPath(path, QUrl::DecodedMode);
38#endif
39 return QDesktopServices::openUrl(url);
40}
41
46bool isPaletteDark(const QPalette &palette)
47{
48 return palette.color(QPalette::WindowText).lightness() > palette.color(QPalette::Window).lightness();
49}
50
51} // namespace QtUtilities
QT_UTILITIES_EXPORT bool isPaletteDark(const QPalette &palette=QPalette())
Returns whether palette is dark.
QT_UTILITIES_EXPORT bool openLocalFileOrDir(const QString &path)
Shows the specified file or directory using the default file browser.