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(
"kde gnome "
84 #
if QT_VERSION_MAJOR == 5
86 #elif QT_VERSION_MAJOR == 6
90 m_platformThemeArg.setEnvironmentVariable(
"QT_QPA_PLATFORMTHEME");
91 m_sceneGraphRenderLoopArg.setRequiredValueCount(1);
92 m_sceneGraphRenderLoopArg.setCombinable(
true);
93 m_sceneGraphRenderLoopArg.setValueNames({
"basic/windows/threaded" });
94 m_sceneGraphRenderLoopArg.setPreDefinedCompletionValues(
"basic windows threaded");
95 m_sceneGraphRenderLoopArg.setEnvironmentVariable(
"QSG_RENDER_LOOP");
96 m_qtWidgetsGuiArg.setSubArguments(
97 { &m_lngArg, &m_qmlDebuggerArg, &m_widgetsStyleArg, &m_iconThemeArg, &m_fontArg, &m_libraryPathsArg, &m_platformThemeArg });
98 m_qtQuickGuiArg.setSubArguments({ &m_lngArg, &m_qmlDebuggerArg, &m_quickControls2StyleArg, &m_iconThemeArg, &m_fontArg, &m_libraryPathsArg,
99 &m_platformThemeArg, &m_sceneGraphRenderLoopArg });
100 m_qtWidgetsGuiArg.setDenotesOperation(
true);
101 m_qtQuickGuiArg.setDenotesOperation(
true);
102 #if defined(QT_UTILITIES_GUI_QTWIDGETS)
103 m_qtWidgetsGuiArg.setImplicit(
true);
104 #elif defined(QT_UTILITIES_GUI_QTQUICK)
105 m_qtQuickGuiArg.setImplicit(
true);
117 if (m_lngArg.isPresent()) {
118 QLocale::setDefault(QLocale(QString::fromLocal8Bit(m_lngArg.values().front())));
120 #ifdef QT_UTILITIES_GUI_QTWIDGETS
121 if (m_widgetsStyleArg.isPresent()) {
122 if (QStyle *
const style = QStyleFactory::create(QString::fromLocal8Bit(m_widgetsStyleArg.values().front()))) {
123 QApplication::setStyle(style);
125 cerr << Phrases::Warning <<
"Can not find the specified Qt Widgets style." << Phrases::EndFlush;
129 if (m_iconThemeArg.isPresent()) {
130 auto i = m_iconThemeArg.values().cbegin(), end = m_iconThemeArg.values().end();
132 QIcon::setThemeName(QString::fromLocal8Bit(*i));
134 QStringList searchPaths;
135 searchPaths.reserve(
static_cast<QStringList::size_type
>(m_iconThemeArg.values().size() - 1));
136 for (; i != end; ++i) {
137 searchPaths << QString::fromLocal8Bit(*i);
139 searchPaths << QStringLiteral(
":/icons");
140 QIcon::setThemeSearchPaths(searchPaths);
144 if (qEnvironmentVariableIsSet(
"ICON_THEME_SEARCH_PATH")) {
146 path.append(qgetenv(
"ICON_THEME_SEARCH_PATH"));
147 QIcon::setThemeSearchPaths(QStringList({ path, QStringLiteral(
":/icons") }));
149 QIcon::setThemeSearchPaths(QIcon::themeSearchPaths() << QStringLiteral(
"../share/icons") << QStringLiteral(
":/icons"));
151 if (qEnvironmentVariableIsSet(
"ICON_THEME")) {
153 themeName.append(qgetenv(
"ICON_THEME"));
154 QIcon::setThemeName(themeName);
159 if (QIcon::themeName().isEmpty()) {
160 QIcon::setThemeName(QStringLiteral(
"default"));
163 if (m_fontArg.isPresent()) {
165 font.setFamily(QString::fromLocal8Bit(m_fontArg.values().front()));
167 font.setPointSize(stringToNumber<int>(m_fontArg.values().back()));
168 }
catch (
const ConversionException &) {
169 cerr << Phrases::Warning <<
"The specified font size is no number and will be ignored." << Phrases::EndFlush;
171 QGuiApplication::setFont(font);
174 else if (!preventApplyingDefaultFont) {
175 QGuiApplication::setFont(QFont(QStringLiteral(
"Segoe UI"), 9));
178 CPP_UTILITIES_UNUSED(preventApplyingDefaultFont)
180 if (m_libraryPathsArg.isPresent()) {
181 QStringList libraryPaths;
182 libraryPaths.reserve(
static_cast<QStringList::size_type
>(m_libraryPathsArg.values().size()));
183 for (
const auto &path : m_libraryPathsArg.values()) {
184 libraryPaths << QString::fromLocal8Bit(path);
186 QCoreApplication::setLibraryPaths(libraryPaths);
188 if (m_sceneGraphRenderLoopArg.isPresent()) {
189 qputenv(m_sceneGraphRenderLoopArg.environmentVariable(), QByteArray(m_sceneGraphRenderLoopArg.firstValue()));
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...