Add function to determine whether palette is dark

This commit is contained in:
Martchus 2022-07-16 18:41:47 +02:00
parent 6e5a9419be
commit 0f7a4eb059
2 changed files with 14 additions and 2 deletions

View File

@ -38,4 +38,14 @@ bool openLocalFileOrDir(const QString &path)
#endif
return QDesktopServices::openUrl(url);
}
/*!
* \brief Returns whether \a palette is dark.
* \remarks Just call with no argument to check for the default palette to see whether "dark mode" is enabled.
*/
bool isPaletteDark(const QPalette &palette)
{
return palette.color(QPalette::WindowText).lightness() > palette.color(QPalette::Window).lightness();
}
} // namespace QtUtilities

View File

@ -3,13 +3,15 @@
#include "../global.h"
#include <QtGlobal>
#include <QPalette>
QT_FORWARD_DECLARE_CLASS(QString)
namespace QtUtilities {
QT_UTILITIES_EXPORT bool openLocalFileOrDir(const QString &path);
}
QT_UTILITIES_EXPORT bool isPaletteDark(const QPalette &palette = QPalette());
} // namespace QtUtilities
#endif // DESKTOP_UTILS_DESKTOPSERVICES_H