3 #include <c++utilities/conversion/stringconversion.h>
4 #include <c++utilities/io/ansiescapecodes.h>
10 #ifdef QT_UTILITIES_GUI_QTWIDGETS
11 #include <QApplication>
13 #include <QStyleFactory>
15 #include <QGuiApplication>
18 #include <initializer_list>
22 using namespace CppUtilities::EscapeCodes;
32 QtConfigArguments::QtConfigArguments()
33 : m_qtWidgetsGuiArg(
"qt-widgets-gui",
'g',
"shows a Qt widgets based graphical user interface")
34 , m_qtQuickGuiArg(
"qt-quick-gui",
'q',
"shows a Qt quick based graphical user interface")
35 , m_lngArg(
"lang",
'l',
"sets the language for the Qt GUI")
36 , m_qmlDebuggerArg(
"qmljsdebugger",
'q',
37 "enables QML debugging (see "
38 "http://doc.qt.io/qt-5/"
39 "qtquick-debugging.html)")
40 , m_widgetsStyleArg(
"widgets-style",
'\0',
"sets the Qt Widgets style")
41 , m_quickControls2StyleArg(
"qqc2-style",
'\0',
"sets the Qt Quick Controls 2 style")
42 , m_iconThemeArg(
"icon-theme",
'\0',
43 "sets the icon theme and additional "
44 "theme search paths for the Qt GUI")
45 , m_fontArg(
"font",
'\0',
"sets the font family and size (point) for the Qt GUI")
46 , m_libraryPathsArg(
"library-paths",
'\0',
47 "sets the list of directories to search when loading "
48 "libraries (all existing paths will be deleted)")
49 , m_platformThemeArg(
"platformtheme",
'\0',
"specifies the Qt platform theme to be used")
50 , m_sceneGraphRenderLoopArg(
"scene-graph-render-loop",
'\0',
"sets the loop for the Qt Quick Scene Graph OpenGL Renderer")
53 m_lngArg.setValueNames({
"language" });
54 m_lngArg.setRequiredValueCount(1);
55 m_lngArg.setRequired(
false);
56 m_lngArg.setCombinable(
true);
58 m_qmlDebuggerArg.setValueNames({
"port:<port_from>[,port_to][,host:<ip address>][,block]" });
59 m_qmlDebuggerArg.setRequiredValueCount(1);
60 m_qmlDebuggerArg.setCombinable(
true);
62 m_widgetsStyleArg.setValueNames({
"breeze/cleanlooks/fusion/kvantum/oxygen/adwaita/windows/..." });
63 m_widgetsStyleArg.setRequiredValueCount(1);
64 m_widgetsStyleArg.setCombinable(
true);
65 m_widgetsStyleArg.setEnvironmentVariable(
"QT_STYLE_OVERRIDE");
66 m_quickControls2StyleArg.setValueNames({
"default/material/universal/org.kde.desktop/..." });
67 m_quickControls2StyleArg.setRequiredValueCount(1);
68 m_quickControls2StyleArg.setCombinable(
true);
69 m_quickControls2StyleArg.setEnvironmentVariable(
"QT_QUICK_CONTROLS_STYLE");
70 m_iconThemeArg.setValueNames({
"theme name",
"search path 1",
"search path 2" });
71 m_iconThemeArg.setRequiredValueCount(Argument::varValueCount);
72 m_iconThemeArg.setCombinable(
true);
73 m_iconThemeArg.setEnvironmentVariable(
"ICON_THEME_SEARCH_PATH and ICON_THEME");
74 m_fontArg.setValueNames({
"name",
"size" });
75 m_fontArg.setRequiredValueCount(2);
76 m_fontArg.setCombinable(
true);
77 m_libraryPathsArg.setValueNames({
"path 1",
"path 2" });
78 m_libraryPathsArg.setRequiredValueCount(Argument::varValueCount);
79 m_libraryPathsArg.setCombinable(
true);
80 m_platformThemeArg.setRequiredValueCount(1);
81 m_platformThemeArg.setCombinable(
true);
82 m_platformThemeArg.setValueNames({
"qt5ct/kde/..." });
83 m_platformThemeArg.setPreDefinedCompletionValues(
"qt5ct kde gnome");
84 m_platformThemeArg.setEnvironmentVariable(
"QT_QPA_PLATFORMTHEME");
85 m_sceneGraphRenderLoopArg.setRequiredValueCount(1);
86 m_sceneGraphRenderLoopArg.setCombinable(
true);
87 m_sceneGraphRenderLoopArg.setValueNames({
"basic/windows/threaded" });
88 m_sceneGraphRenderLoopArg.setPreDefinedCompletionValues(
"basic windows threaded");
89 m_sceneGraphRenderLoopArg.setEnvironmentVariable(
"QSG_RENDER_LOOP");
90 m_qtWidgetsGuiArg.setSubArguments(
91 { &m_lngArg, &m_qmlDebuggerArg, &m_widgetsStyleArg, &m_iconThemeArg, &m_fontArg, &m_libraryPathsArg, &m_platformThemeArg });
92 m_qtQuickGuiArg.setSubArguments({ &m_lngArg, &m_qmlDebuggerArg, &m_quickControls2StyleArg, &m_iconThemeArg, &m_fontArg, &m_libraryPathsArg,
93 &m_platformThemeArg, &m_sceneGraphRenderLoopArg });
94 m_qtWidgetsGuiArg.setDenotesOperation(
true);
95 m_qtQuickGuiArg.setDenotesOperation(
true);
96 #if defined(QT_UTILITIES_GUI_QTWIDGETS)
97 m_qtWidgetsGuiArg.setImplicit(
true);
98 #elif defined(QT_UTILITIES_GUI_QTQUICK)
99 m_qtQuickGuiArg.setImplicit(
true);
111 if (m_lngArg.isPresent()) {
112 QLocale::setDefault(QLocale(QString::fromLocal8Bit(m_lngArg.values().front())));
114 #ifdef QT_UTILITIES_GUI_QTWIDGETS
115 if (m_widgetsStyleArg.isPresent()) {
116 if (QStyle *
const style = QStyleFactory::create(QString::fromLocal8Bit(m_widgetsStyleArg.values().front()))) {
117 QApplication::setStyle(style);
119 cerr << Phrases::Warning <<
"Can not find the specified Qt Widgets style." << Phrases::EndFlush;
123 if (m_iconThemeArg.isPresent()) {
124 auto i = m_iconThemeArg.values().cbegin(), end = m_iconThemeArg.values().end();
126 QIcon::setThemeName(QString::fromLocal8Bit(*i));
128 QStringList searchPaths;
129 searchPaths.reserve(m_iconThemeArg.values().size() - 1);
130 for (; i != end; ++i) {
131 searchPaths << QString::fromLocal8Bit(*i);
133 searchPaths << QStringLiteral(
":/icons");
134 QIcon::setThemeSearchPaths(searchPaths);
138 if (qEnvironmentVariableIsSet(
"ICON_THEME_SEARCH_PATH")) {
140 path.append(qgetenv(
"ICON_THEME_SEARCH_PATH"));
141 QIcon::setThemeSearchPaths(QStringList({ path, QStringLiteral(
":/icons") }));
143 QIcon::setThemeSearchPaths(QIcon::themeSearchPaths() << QStringLiteral(
"../share/icons") << QStringLiteral(
":/icons"));
145 if (qEnvironmentVariableIsSet(
"ICON_THEME")) {
147 themeName.append(qgetenv(
"ICON_THEME"));
148 QIcon::setThemeName(themeName);
153 if (QIcon::themeName().isEmpty()) {
154 QIcon::setThemeName(QStringLiteral(
"default"));
157 if (m_fontArg.isPresent()) {
159 font.setFamily(QString::fromLocal8Bit(m_fontArg.values().front()));
161 font.setPointSize(stringToNumber<int>(m_fontArg.values().back()));
162 }
catch (
const ConversionException &) {
163 cerr << Phrases::Warning <<
"The specified font size is no number and will be ignored." << Phrases::EndFlush;
165 QGuiApplication::setFont(font);
168 else if (!preventApplyingDefaultFont) {
169 QGuiApplication::setFont(QFont(QStringLiteral(
"Segoe UI"), 9));
172 CPP_UTILITIES_UNUSED(preventApplyingDefaultFont)
174 if (m_libraryPathsArg.isPresent()) {
175 QStringList libraryPaths;
176 libraryPaths.reserve(m_libraryPathsArg.values().size());
177 for (
const auto &path : m_libraryPathsArg.values()) {
178 libraryPaths << QString::fromLocal8Bit(path);
180 QCoreApplication::setLibraryPaths(libraryPaths);
182 if (m_sceneGraphRenderLoopArg.isPresent()) {
183 qputenv(m_sceneGraphRenderLoopArg.environmentVariable(), QByteArray(m_sceneGraphRenderLoopArg.firstValue()));