From b7f2ce0f1017d6ee0509ea00b7047742f3e3399a Mon Sep 17 00:00:00 2001 From: Martchus Date: Sat, 16 Jun 2018 13:10:19 +0200 Subject: [PATCH] Allow to overriding Qt Quick Controls 2 style Make it an extra function in the header so the utilities don't depend on the Qt Quick Controls 2 library (just for one function call). --- CMakeLists.txt | 4 ++-- resources/qtconfigarguments.cpp | 23 +++++++++++++---------- resources/qtconfigarguments.h | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cee702c..f024016 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,8 +8,8 @@ set(META_APP_AUTHOR "Martchus") 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 5) -set(META_VERSION_MINOR 10) -set(META_VERSION_PATCH 1) +set(META_VERSION_MINOR 11) +set(META_VERSION_PATCH 0) set(META_APP_VERSION ${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}) # add project files diff --git a/resources/qtconfigarguments.cpp b/resources/qtconfigarguments.cpp index 0aa72ee..d231922 100644 --- a/resources/qtconfigarguments.cpp +++ b/resources/qtconfigarguments.cpp @@ -1,6 +1,7 @@ #include "./qtconfigarguments.h" #include +#include #include #include @@ -19,11 +20,13 @@ using namespace std; using namespace ConversionUtilities; +using namespace EscapeCodes; namespace ApplicationUtilities { /*! * \brief Constructs new Qt config arguments. + * \todo Split style args in v6. */ QtConfigArguments::QtConfigArguments() : m_qtWidgetsGuiArg("qt-widgets-gui", 'g', "shows a Qt widgets based graphical user interface") @@ -33,7 +36,7 @@ QtConfigArguments::QtConfigArguments() "enables QML debugging (see " "http://doc.qt.io/qt-5/" "qtquick-debugging.html)") - , m_styleArg("style", '\0', "sets the Qt widgets style") + , m_styleArg("style", '\0', "sets the Qt Widgets or Qt Quick style") , m_iconThemeArg("icon-theme", '\0', "sets the icon theme and additional " "theme search paths for the Qt GUI") @@ -56,6 +59,7 @@ QtConfigArguments::QtConfigArguments() m_styleArg.setValueNames({ "style name" }); m_styleArg.setRequiredValueCount(1); m_styleArg.setCombinable(true); + m_styleArg.setEnvironmentVariable("QT_STYLE_OVERRIDE for Qt Widgets and QT_QUICK_CONTROLS_STYLE for Qt Quick"); m_iconThemeArg.setValueNames({ "theme name", "search path 1", "search path 2" }); m_iconThemeArg.setRequiredValueCount(Argument::varValueCount); m_iconThemeArg.setCombinable(true); @@ -71,7 +75,8 @@ QtConfigArguments::QtConfigArguments() m_platformThemeArg.setPreDefinedCompletionValues("qt5ct kde gnome"); m_qtWidgetsGuiArg.setSubArguments( { &m_lngArg, &m_qmlDebuggerArg, &m_styleArg, &m_iconThemeArg, &m_fontArg, &m_libraryPathsArg, &m_platformThemeArg }); - m_qtQuickGuiArg.setSubArguments({ &m_lngArg, &m_qmlDebuggerArg, &m_iconThemeArg, &m_fontArg, &m_libraryPathsArg, &m_platformThemeArg }); + m_qtQuickGuiArg.setSubArguments( + { &m_lngArg, &m_qmlDebuggerArg, &m_styleArg, &m_iconThemeArg, &m_fontArg, &m_libraryPathsArg, &m_platformThemeArg }); m_qtWidgetsGuiArg.setDenotesOperation(true); m_qtQuickGuiArg.setDenotesOperation(true); #if defined QT_UTILITIES_GUI_QTWIDGETS @@ -94,15 +99,13 @@ void QtConfigArguments::applySettings(bool preventApplyingDefaultFont) const } if (m_styleArg.isPresent()) { #ifdef QT_UTILITIES_GUI_QTWIDGETS - if (QStyle *style = QStyleFactory::create(QString::fromLocal8Bit(m_styleArg.values().front()))) { - QApplication::setStyle(style); - } else { - cerr << "Warning: Can not find the specified style." << endl; + if (m_qtWidgetsGuiArg.isPresent()) { + if (QStyle *const style = QStyleFactory::create(QString::fromLocal8Bit(m_styleArg.values().front()))) { + QApplication::setStyle(style); + } else { + cerr << Phrases::Warning << "Can not find the specified Qt Widgets style." << Phrases::EndFlush; + } } -#else -#ifdef QT_UTILITIES_GUI_QTQUICK - cerr << "Warning: Can not set a style for the Qt Quick GUI." << endl; -#endif #endif } if (m_iconThemeArg.isPresent()) { diff --git a/resources/qtconfigarguments.h b/resources/qtconfigarguments.h index e59138e..b9df69d 100644 --- a/resources/qtconfigarguments.h +++ b/resources/qtconfigarguments.h @@ -5,6 +5,9 @@ #include +#ifdef QT_UTILITIES_GUI_QTQUICK +#include + namespace ApplicationUtilities { class QT_UTILITIES_EXPORT QtConfigArguments { @@ -61,6 +64,22 @@ inline bool QtConfigArguments::areQtGuiArgsPresent() const { return m_qtWidgetsGuiArg.isPresent() || m_qtQuickGuiArg.isPresent(); } + +#ifdef QT_UTILITIES_GUI_QTQUICK +/*! + * \brief Applies settings the for Qt Quick GUI. + */ +inline void QtConfigArguments::applySettingsForQuickGui() const +{ + if (!m_qtQuickGuiArg.isPresent()) { + return; + } + if (m_styleArg.isPresent()) { + QQuickStyle::setStyle(QString::fromLocal8Bit(m_styleArg.values().front())); + } +} +#endif + } // namespace ApplicationUtilities #endif // APPLICATION_UTILITIES_QTCONFIGARGUMENTS_H