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).
This commit is contained in:
Martchus 2018-06-16 13:10:19 +02:00
parent 6be2f87988
commit b7f2ce0f10
3 changed files with 34 additions and 12 deletions

View File

@ -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

View File

@ -1,6 +1,7 @@
#include "./qtconfigarguments.h"
#include <c++utilities/conversion/stringconversion.h>
#include <c++utilities/io/ansiescapecodes.h>
#include <QFont>
#include <QIcon>
@ -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()) {

View File

@ -5,6 +5,9 @@
#include <c++utilities/application/argumentparser.h>
#ifdef QT_UTILITIES_GUI_QTQUICK
#include <QQuickStyle>
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