Compare commits
10 Commits
Author | SHA1 | Date |
---|---|---|
Martchus | 6016ec4bff | |
Martchus | 4feedbb057 | |
Martchus | ded20b34a6 | |
Martchus | d20130d770 | |
Martchus | a7d2611400 | |
Martchus | 264386acad | |
Martchus | 8ee322abb7 | |
Martchus | bbd42e167d | |
Martchus | 63ffbc4a6f | |
Martchus | 600470e609 |
|
@ -9,8 +9,8 @@ set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}")
|
|||
set(META_APP_DESCRIPTION
|
||||
"Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models")
|
||||
set(META_VERSION_MAJOR 6)
|
||||
set(META_VERSION_MINOR 13)
|
||||
set(META_VERSION_PATCH 5)
|
||||
set(META_VERSION_MINOR 14)
|
||||
set(META_VERSION_PATCH 1)
|
||||
set(META_APP_VERSION ${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH})
|
||||
|
||||
project(${META_PROJECT_NAME})
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
cmake_minimum_required(VERSION 3.17.0 FATAL_ERROR)
|
||||
|
||||
message(DEPRECATION "Do not use the AndroidApk module anymore. It broke after some minor Qt 5 version. As of Qt 6 the "
|
||||
"CMake functions that come with Qt itself are sufficient.")
|
||||
|
||||
# adds a target to create an Android APK with the help of androiddeployqt if target platform is Android
|
||||
|
||||
if (NOT ANDROID)
|
||||
|
|
|
@ -69,4 +69,27 @@ std::optional<bool> isDarkModeEnabled()
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Invokes the specified callback when the color scheme changed.
|
||||
*
|
||||
* The first argument of the callback will be whether the color scheme is dark now (Qt::ColorScheme::Dark).
|
||||
* The callback is invoked immediately by this function unless \a invokeImmediately is set to false.
|
||||
*
|
||||
* \remarks Whether dark mode is enabled can only be determined on Qt 6.5 or newer and only on certain
|
||||
* platforms. If it cannot be determined the \a darkModeChangedCallback is never invoked.
|
||||
*/
|
||||
QMetaObject::Connection onDarkModeChanged(std::function<void(bool)> &&darkModeChangedCallback, QObject *context, bool invokeImmediately)
|
||||
{
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0))
|
||||
if (const auto *const styleHints = QGuiApplication::styleHints()) {
|
||||
if (invokeImmediately) {
|
||||
darkModeChangedCallback(styleHints->colorScheme() == Qt::ColorScheme::Dark);
|
||||
}
|
||||
return QObject::connect(styleHints, &QStyleHints::colorSchemeChanged, context,
|
||||
[handler = std::move(darkModeChangedCallback)](Qt::ColorScheme colorScheme) { return handler(colorScheme == Qt::ColorScheme::Dark); });
|
||||
}
|
||||
#endif
|
||||
return QMetaObject::Connection();
|
||||
}
|
||||
|
||||
} // namespace QtUtilities
|
||||
|
|
|
@ -3,10 +3,13 @@
|
|||
|
||||
#include "../global.h"
|
||||
|
||||
#include <QMetaObject>
|
||||
#include <QPalette>
|
||||
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QObject)
|
||||
QT_FORWARD_DECLARE_CLASS(QString)
|
||||
|
||||
namespace QtUtilities {
|
||||
|
@ -14,6 +17,8 @@ namespace QtUtilities {
|
|||
QT_UTILITIES_EXPORT bool openLocalFileOrDir(const QString &path);
|
||||
QT_UTILITIES_EXPORT bool isPaletteDark(const QPalette &palette = QPalette());
|
||||
QT_UTILITIES_EXPORT std::optional<bool> isDarkModeEnabled();
|
||||
QT_UTILITIES_EXPORT QMetaObject::Connection onDarkModeChanged(
|
||||
std::function<void(bool)> &&darkModeChangedCallback, QObject *context = nullptr, bool invokeImmediately = true);
|
||||
|
||||
} // namespace QtUtilities
|
||||
|
||||
|
|
|
@ -9,6 +9,13 @@
|
|||
#include <QQuickStyle>
|
||||
#include <QString>
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
#if defined(PLATFORM_ANDROID)
|
||||
#define QT_UTILITIES_DEFAULT_QQC2_STYLE "Material"
|
||||
#elif defined(PLATFORM_WINDOWS)
|
||||
#define QT_UTILITIES_DEFAULT_QQC2_STYLE "Universal"
|
||||
#endif
|
||||
#else
|
||||
#if defined(PLATFORM_ANDROID)
|
||||
#define QT_UTILITIES_DEFAULT_QQC2_STYLE "material"
|
||||
#elif defined(PLATFORM_WINDOWS)
|
||||
|
@ -16,6 +23,8 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
namespace CppUtilities {
|
||||
|
||||
class QT_UTILITIES_EXPORT QtConfigArguments {
|
||||
|
|
|
@ -16,6 +16,18 @@ QT_FORWARD_DECLARE_CLASS(QSettings)
|
|||
QT_FORWARD_DECLARE_CLASS(QStringList)
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \brief Sets the base name of the desktop entry for this application from buildsystem-provided meta-data.
|
||||
* \remarks
|
||||
* - This is done as part of SET_QT_APPLICATION_INFO and thus normally doesn't need to be invoked individually.
|
||||
* - This macro is still experimental.
|
||||
*/
|
||||
#define SET_QT_DESKTOP_FILE_NAME
|
||||
#if defined(Q_OS_LINUX) && defined(qGuiApp) && defined(APP_ID)
|
||||
#undef SET_QT_DESKTOP_FILE_NAME
|
||||
#define SET_QT_DESKTOP_FILE_NAME QGuiApplication::setDesktopFileName(QStringLiteral(APP_ID));
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \brief Sets the application meta data in the QCoreApplication singleton and attributes commonly used
|
||||
* within my applications.
|
||||
|
@ -26,6 +38,7 @@ QT_FORWARD_DECLARE_CLASS(QStringList)
|
|||
QCoreApplication::setOrganizationDomain(QStringLiteral(APP_DOMAIN)); \
|
||||
QCoreApplication::setApplicationName(QStringLiteral(APP_NAME)); \
|
||||
QCoreApplication::setApplicationVersion(QStringLiteral(APP_VERSION)); \
|
||||
SET_QT_DESKTOP_FILE_NAME \
|
||||
::QtUtilities::setupCommonQtApplicationAttributes()
|
||||
|
||||
/*!
|
||||
|
|
|
@ -352,7 +352,7 @@ void QtSettings::apply()
|
|||
}
|
||||
const auto debugLoggingEnabled = CppUtilities::isEnvVariableSet(PROJECT_VARNAME_UPPER "_LOG_QT_CONFIG");
|
||||
if (debugLoggingEnabled.has_value() && debugLoggingEnabled.value()) {
|
||||
if (const auto os = QOperatingSystemVersion::current(); os.type() != QOperatingSystemVersion::Unknown) {
|
||||
if (const auto os = QOperatingSystemVersion::current(); os.type() != static_cast<decltype(os.type())>(QOperatingSystemVersion::Unknown)) {
|
||||
const auto version = QVersionNumber(os.majorVersion(), os.minorVersion(), os.microVersion());
|
||||
std::cerr << "OS name and version: " << os.name().toStdString() << ' ' << version.toString().toStdString() << '\n';
|
||||
}
|
||||
|
@ -365,6 +365,33 @@ void QtSettings::apply()
|
|||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Re-applies default icon theme assuming the palette is dark or not depending on \a isPaletteDark.
|
||||
*
|
||||
* Re-assigns the appropriate default icon theme depending on the current palette. Call this function after the
|
||||
* darkmode setting has changed without the current palette reflecting that but you want the darkmode setting take
|
||||
* precedence over the palette (e.g. when using Qt Quick Material style under Android). If your application makes
|
||||
* actually use of the palette and you want the palette take precedence than call \a reevaluatePaletteAndDefaultIconTheme()
|
||||
* instead.
|
||||
*
|
||||
* Note that QtSettings::isPaletteDark() will return \a isPaletteDark after calling this function (even though the current
|
||||
* palette is not actually reflecting that).
|
||||
*
|
||||
* \remarks
|
||||
* - The default icon theme must have been assigned before using the apply() function.
|
||||
* - This function has no effect if a custom icon theme is configured.
|
||||
*/
|
||||
void QtSettings::reapplyDefaultIconTheme(bool isPaletteDark)
|
||||
{
|
||||
if (isPaletteDark == m_d->isPaletteDark) {
|
||||
return; // no need to do anything if there's no change
|
||||
}
|
||||
m_d->isPaletteDark = isPaletteDark;
|
||||
if (auto iconTheme = QIcon::themeName(); iconTheme == QStringLiteral("default") || iconTheme == QStringLiteral("default-dark")) {
|
||||
QIcon::setThemeName(m_d->isPaletteDark ? QStringLiteral("default-dark") : QStringLiteral("default"));
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Re-evaluates whether the palette is dark and re-applies default icon theme.
|
||||
*
|
||||
|
@ -377,14 +404,7 @@ void QtSettings::apply()
|
|||
*/
|
||||
void QtSettings::reevaluatePaletteAndDefaultIconTheme()
|
||||
{
|
||||
const auto isPaletteDark = QtUtilities::isPaletteDark();
|
||||
if (isPaletteDark == m_d->isPaletteDark) {
|
||||
return; // no need to do anything if there's no change
|
||||
}
|
||||
m_d->isPaletteDark = isPaletteDark;
|
||||
if (auto iconTheme = QIcon::themeName(); iconTheme == QStringLiteral("default") || iconTheme == QStringLiteral("default-dark")) {
|
||||
QIcon::setThemeName(m_d->isPaletteDark ? QStringLiteral("default-dark") : QStringLiteral("default"));
|
||||
}
|
||||
reapplyDefaultIconTheme(QtUtilities::isPaletteDark());
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
@ -51,6 +51,7 @@ public:
|
|||
void restore(QSettings &settings);
|
||||
void save(QSettings &settings) const;
|
||||
void apply();
|
||||
void reapplyDefaultIconTheme(bool isPaletteDark);
|
||||
void reevaluatePaletteAndDefaultIconTheme();
|
||||
bool isPaletteDark();
|
||||
bool hasCustomFont() const;
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<context>
|
||||
<name>QtGui::QtLanguageOptionPage</name>
|
||||
<message>
|
||||
<location filename="../settingsdialog/qtsettings.cpp" line="566"/>
|
||||
<location filename="../settingsdialog/qtsettings.cpp" line="586"/>
|
||||
<source>recognized by Qt as</source>
|
||||
<translation>von Qt erkannt als</translation>
|
||||
</message>
|
||||
|
@ -28,7 +28,7 @@
|
|||
<context>
|
||||
<name>QtGui::QtOptionCategory</name>
|
||||
<message>
|
||||
<location filename="../settingsdialog/qtsettings.cpp" line="420"/>
|
||||
<location filename="../settingsdialog/qtsettings.cpp" line="440"/>
|
||||
<source>Qt</source>
|
||||
<translation></translation>
|
||||
</message>
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<context>
|
||||
<name>QtGui::QtLanguageOptionPage</name>
|
||||
<message>
|
||||
<location filename="../settingsdialog/qtsettings.cpp" line="566"/>
|
||||
<location filename="../settingsdialog/qtsettings.cpp" line="586"/>
|
||||
<source>recognized by Qt as</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
@ -28,7 +28,7 @@
|
|||
<context>
|
||||
<name>QtGui::QtOptionCategory</name>
|
||||
<message>
|
||||
<location filename="../settingsdialog/qtsettings.cpp" line="420"/>
|
||||
<location filename="../settingsdialog/qtsettings.cpp" line="440"/>
|
||||
<source>Qt</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<context>
|
||||
<name>QtGui::QtLanguageOptionPage</name>
|
||||
<message>
|
||||
<location filename="../settingsdialog/qtsettings.cpp" line="566"/>
|
||||
<location filename="../settingsdialog/qtsettings.cpp" line="586"/>
|
||||
<source>recognized by Qt as</source>
|
||||
<translation>被 Qt 识别为</translation>
|
||||
</message>
|
||||
|
@ -28,7 +28,7 @@
|
|||
<context>
|
||||
<name>QtGui::QtOptionCategory</name>
|
||||
<message>
|
||||
<location filename="../settingsdialog/qtsettings.cpp" line="420"/>
|
||||
<location filename="../settingsdialog/qtsettings.cpp" line="440"/>
|
||||
<source>Qt</source>
|
||||
<translation>Qt</translation>
|
||||
</message>
|
||||
|
|
Loading…
Reference in New Issue