3#include "../misc/compat.h"
5#include <c++utilities/conversion/stringconversion.h>
6#include <c++utilities/io/ansiescapecodes.h>
12#ifdef QT_UTILITIES_GUI_QTWIDGETS
13#include <QApplication>
15#include <QStyleFactory>
17#include <QGuiApplication>
20#include <initializer_list>
24using namespace CppUtilities::EscapeCodes;
35 : m_qtWidgetsGuiArg(
"qt-widgets-gui",
'g',
"shows a Qt widgets based graphical user interface")
36 , m_qtQuickGuiArg(
"qt-quick-gui",
'q',
"shows a Qt quick based graphical user interface")
37 , m_lngArg(
"lang",
'l',
"sets the language for the Qt GUI")
38 , m_qmlDebuggerArg(
"qmljsdebugger",
'q',
39 "enables QML debugging (see "
40 "http://doc.qt.io/qt-5/"
41 "qtquick-debugging.html)")
42 , m_widgetsStyleArg(
"widgets-style",
'\0',
"sets the Qt Widgets style")
43 , m_quickControls2StyleArg(
"qqc2-style",
'\0',
"sets the Qt Quick Controls 2 style")
44 , m_iconThemeArg(
"icon-theme",
'\0',
45 "sets the icon theme and additional "
46 "theme search paths for the Qt GUI")
47 , m_fontArg(
"font",
'\0',
"sets the font family and size (point) for the Qt GUI")
48 , m_libraryPathsArg(
"library-paths",
'\0',
49 "sets the list of directories to search when loading "
50 "libraries (all existing paths will be deleted)")
51 , m_platformThemeArg(
"platformtheme",
'\0',
"specifies the Qt platform theme to be used")
52 , m_sceneGraphRenderLoopArg(
"scene-graph-render-loop",
'\0',
"sets the loop for the Qt Quick Scene Graph OpenGL Renderer")
55 m_lngArg.setValueNames({
"language" });
56 m_lngArg.setRequiredValueCount(1);
57 m_lngArg.setRequired(
false);
58 m_lngArg.setCombinable(
true);
60 m_qmlDebuggerArg.setValueNames({
"port:<port_from>[,port_to][,host:<ip address>][,block]" });
61 m_qmlDebuggerArg.setRequiredValueCount(1);
62 m_qmlDebuggerArg.setCombinable(
true);
64 m_widgetsStyleArg.setValueNames({
"breeze/cleanlooks/fusion/kvantum/oxygen/adwaita/windows/..." });
65 m_widgetsStyleArg.setRequiredValueCount(1);
66 m_widgetsStyleArg.setCombinable(
true);
67 m_widgetsStyleArg.setEnvironmentVariable(
"QT_STYLE_OVERRIDE");
68 m_quickControls2StyleArg.setValueNames({
"default/material/universal/org.kde.desktop/..." });
69 m_quickControls2StyleArg.setRequiredValueCount(1);
70 m_quickControls2StyleArg.setCombinable(
true);
71 m_quickControls2StyleArg.setEnvironmentVariable(
"QT_QUICK_CONTROLS_STYLE");
72 m_iconThemeArg.setValueNames({
"theme name",
"search path 1",
"search path 2" });
73 m_iconThemeArg.setRequiredValueCount(Argument::varValueCount);
74 m_iconThemeArg.setCombinable(
true);
75 m_iconThemeArg.setEnvironmentVariable(
"ICON_THEME_SEARCH_PATH and ICON_THEME");
76 m_fontArg.setValueNames({
"name",
"size" });
77 m_fontArg.setRequiredValueCount(2);
78 m_fontArg.setCombinable(
true);
79 m_libraryPathsArg.setValueNames({
"path 1",
"path 2" });
80 m_libraryPathsArg.setRequiredValueCount(Argument::varValueCount);
81 m_libraryPathsArg.setCombinable(
true);
82 m_platformThemeArg.setRequiredValueCount(1);
83 m_platformThemeArg.setCombinable(
true);
84 m_platformThemeArg.setValueNames({
"qt5ct/kde/..." });
85 m_platformThemeArg.setPreDefinedCompletionValues(
"kde gnome "
86#
if QT_VERSION_MAJOR == 5
88#elif QT_VERSION_MAJOR == 6
92 m_platformThemeArg.setEnvironmentVariable(
"QT_QPA_PLATFORMTHEME");
93 m_sceneGraphRenderLoopArg.setRequiredValueCount(1);
94 m_sceneGraphRenderLoopArg.setCombinable(
true);
95 m_sceneGraphRenderLoopArg.setValueNames({
"basic/windows/threaded" });
96 m_sceneGraphRenderLoopArg.setPreDefinedCompletionValues(
"basic windows threaded");
97 m_sceneGraphRenderLoopArg.setEnvironmentVariable(
"QSG_RENDER_LOOP");
98 m_qtWidgetsGuiArg.setSubArguments(
99 { &m_lngArg, &m_qmlDebuggerArg, &m_widgetsStyleArg, &m_iconThemeArg, &m_fontArg, &m_libraryPathsArg, &m_platformThemeArg });
100 m_qtQuickGuiArg.setSubArguments({ &m_lngArg, &m_qmlDebuggerArg, &m_quickControls2StyleArg, &m_iconThemeArg, &m_fontArg, &m_libraryPathsArg,
101 &m_platformThemeArg, &m_sceneGraphRenderLoopArg });
102 m_qtWidgetsGuiArg.setDenotesOperation(
true);
103 m_qtQuickGuiArg.setDenotesOperation(
true);
104#if defined(QT_UTILITIES_GUI_QTWIDGETS)
105 m_qtWidgetsGuiArg.setImplicit(
true);
106#elif defined(QT_UTILITIES_GUI_QTQUICK)
107 m_qtQuickGuiArg.setImplicit(
true);
119 if (m_lngArg.isPresent()) {
120 QLocale::setDefault(QLocale(QString::fromLocal8Bit(m_lngArg.values().front())));
122#ifdef QT_UTILITIES_GUI_QTWIDGETS
123 if (m_widgetsStyleArg.isPresent()) {
124 if (QStyle *
const style = QStyleFactory::create(QString::fromLocal8Bit(m_widgetsStyleArg.values().front()))) {
125 QApplication::setStyle(style);
127 cerr << Phrases::Warning <<
"Can not find the specified Qt Widgets style." << Phrases::EndFlush;
131 if (m_iconThemeArg.isPresent()) {
133 if (
auto i = m_iconThemeArg.values().cbegin(), end = m_iconThemeArg.values().cend(); i != end) {
134 QIcon::setThemeName(QString::fromUtf8(*i));
136 auto searchPaths = QStringList();
137 searchPaths.reserve(
static_cast<QStringList::size_type
>(m_iconThemeArg.values().size()));
138 for (; i != end; ++i) {
139 searchPaths << QString::fromUtf8(*i);
141 searchPaths << QStringLiteral(
":/icons");
142 QIcon::setThemeSearchPaths(searchPaths);
146 if (qEnvironmentVariableIsSet(
"ICON_THEME_SEARCH_PATH")) {
147 QIcon::setThemeSearchPaths(QStringList({ qEnvironmentVariable(
"ICON_THEME_SEARCH_PATH"), QStringLiteral(
":/icons") }));
149 QIcon::setThemeSearchPaths(QIcon::themeSearchPaths() << QStringLiteral(
"../share/icons") << QStringLiteral(
":/icons"));
151 if (qEnvironmentVariableIsSet(
"ICON_THEME")) {
152 QIcon::setThemeName(qEnvironmentVariable(
"ICON_THEME"));
155 if (m_fontArg.isPresent()) {
157 font.setFamily(QString::fromLocal8Bit(m_fontArg.values().front()));
159 font.setPointSize(stringToNumber<int>(m_fontArg.values().back()));
160 }
catch (
const ConversionException &) {
161 cerr << Phrases::Warning <<
"The specified font size is no number and will be ignored." << Phrases::EndFlush;
163 QGuiApplication::setFont(font);
166 else if (!preventApplyingDefaultFont) {
167 QGuiApplication::setFont(QFont(QStringLiteral(
"Segoe UI"), 9));
170 CPP_UTILITIES_UNUSED(preventApplyingDefaultFont)
172 if (m_libraryPathsArg.isPresent()) {
173 QStringList libraryPaths;
174 libraryPaths.reserve(
static_cast<QStringList::size_type
>(m_libraryPathsArg.values().size()));
175 for (
const auto &path : m_libraryPathsArg.values()) {
176 libraryPaths << QString::fromLocal8Bit(path);
178 QCoreApplication::setLibraryPaths(libraryPaths);
180 if (m_sceneGraphRenderLoopArg.isPresent()) {
181 qputenv(m_sceneGraphRenderLoopArg.environmentVariable(), QByteArray(m_sceneGraphRenderLoopArg.firstValue()));
QtConfigArguments()
Constructs new Qt config arguments.
void applySettings(bool preventApplyingDefaultFont=false) const
Applies the settings from the arguments.
The CppUtilities namespace contains addons to the c++utilities library provided by the qtutilities li...