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> 31 QtConfigArguments::QtConfigArguments()
32 : m_qtWidgetsGuiArg(
"qt-widgets-gui",
'g',
"shows a Qt widgets based graphical user interface")
33 , m_qtQuickGuiArg(
"qt-quick-gui",
'q',
"shows a Qt quick based graphical user interface")
34 , m_lngArg(
"lang",
'l',
"sets the language for the Qt GUI")
35 , m_qmlDebuggerArg(
"qmljsdebugger",
'q',
36 "enables QML debugging (see " 37 "http://doc.qt.io/qt-5/" 38 "qtquick-debugging.html)")
39 , m_styleArg(
"style",
'\0',
"sets the Qt Widgets or Qt Quick style")
40 , m_iconThemeArg(
"icon-theme",
'\0',
41 "sets the icon theme and additional " 42 "theme search paths for the Qt GUI")
43 , m_fontArg(
"font",
'\0',
"sets the font family and size (point) for the Qt GUI")
44 , m_libraryPathsArg(
"library-paths",
'\0',
45 "sets the list of directories to search when loading " 46 "libraries (all existing paths will be deleted)")
47 , m_platformThemeArg(
"platformtheme",
'\0',
"specifies the Qt platform theme to be used")
50 m_lngArg.setValueNames({
"language" });
51 m_lngArg.setRequiredValueCount(1);
52 m_lngArg.setRequired(
false);
53 m_lngArg.setCombinable(
true);
55 m_qmlDebuggerArg.setValueNames({
"port:<port_from>[,port_to][,host:<ip address>][,block]" });
56 m_qmlDebuggerArg.setRequiredValueCount(1);
57 m_qmlDebuggerArg.setCombinable(
true);
59 m_styleArg.setValueNames({
"breeze/cleanlooks/fusion/kvantum/oxygen/adwaita/windows/... or default/material/universal/org.kde.desktop" });
60 m_styleArg.setRequiredValueCount(1);
61 m_styleArg.setCombinable(
true);
62 m_styleArg.setEnvironmentVariable(
"QT_STYLE_OVERRIDE for Qt Widgets and QT_QUICK_CONTROLS_STYLE for Qt Quick");
63 m_iconThemeArg.setValueNames({
"theme name",
"search path 1",
"search path 2" });
64 m_iconThemeArg.setRequiredValueCount(Argument::varValueCount);
65 m_iconThemeArg.setCombinable(
true);
66 m_iconThemeArg.setEnvironmentVariable(
"ICON_THEME_SEARCH_PATH and ICON_THEME");
67 m_fontArg.setValueNames({
"name",
"size" });
68 m_fontArg.setRequiredValueCount(2);
69 m_fontArg.setCombinable(
true);
70 m_libraryPathsArg.setValueNames({
"path 1",
"path 2" });
71 m_libraryPathsArg.setRequiredValueCount(Argument::varValueCount);
72 m_libraryPathsArg.setCombinable(
true);
73 m_platformThemeArg.setRequiredValueCount(1);
74 m_platformThemeArg.setCombinable(
true);
75 m_platformThemeArg.setValueNames({
"qt5ct/kde/..." });
76 m_platformThemeArg.setPreDefinedCompletionValues(
"qt5ct kde gnome");
77 m_platformThemeArg.setEnvironmentVariable(
"QT_QPA_PLATFORMTHEME");
78 m_qtWidgetsGuiArg.setSubArguments(
79 { &m_lngArg, &m_qmlDebuggerArg, &m_styleArg, &m_iconThemeArg, &m_fontArg, &m_libraryPathsArg, &m_platformThemeArg });
80 m_qtQuickGuiArg.setSubArguments(
81 { &m_lngArg, &m_qmlDebuggerArg, &m_styleArg, &m_iconThemeArg, &m_fontArg, &m_libraryPathsArg, &m_platformThemeArg });
82 m_qtWidgetsGuiArg.setDenotesOperation(
true);
83 m_qtQuickGuiArg.setDenotesOperation(
true);
84 #if defined QT_UTILITIES_GUI_QTWIDGETS 85 m_qtWidgetsGuiArg.setImplicit(
true);
86 #elif defined QT_UTILITIES_GUI_QTQUICK 87 m_qtQuickGuiArg.setImplicit(
true);
99 if (m_lngArg.isPresent()) {
100 QLocale::setDefault(QLocale(QString::fromLocal8Bit(m_lngArg.values().front())));
102 if (m_styleArg.isPresent()) {
103 #ifdef QT_UTILITIES_GUI_QTWIDGETS 104 if (m_qtWidgetsGuiArg.isPresent()) {
105 if (QStyle *
const style = QStyleFactory::create(QString::fromLocal8Bit(m_styleArg.values().front()))) {
106 QApplication::setStyle(style);
108 cerr << Phrases::Warning <<
"Can not find the specified Qt Widgets style." << Phrases::EndFlush;
113 if (m_iconThemeArg.isPresent()) {
114 auto i = m_iconThemeArg.values().cbegin(), end = m_iconThemeArg.values().end();
116 QIcon::setThemeName(QString::fromLocal8Bit(*i));
118 QStringList searchPaths;
119 searchPaths.reserve(m_iconThemeArg.values().size() - 1);
120 for (; i != end; ++i) {
121 searchPaths << QString::fromLocal8Bit(*i);
123 searchPaths << QStringLiteral(
":/icons");
124 QIcon::setThemeSearchPaths(searchPaths);
128 if (qEnvironmentVariableIsSet(
"ICON_THEME_SEARCH_PATH")) {
130 path.append(qgetenv(
"ICON_THEME_SEARCH_PATH"));
131 QIcon::setThemeSearchPaths(QStringList({ path, QStringLiteral(
":/icons") }));
133 QIcon::setThemeSearchPaths(QIcon::themeSearchPaths() << QStringLiteral(
"../share/icons") << QStringLiteral(
":/icons"));
135 if (qEnvironmentVariableIsSet(
"ICON_THEME")) {
137 themeName.append(qgetenv(
"ICON_THEME"));
138 QIcon::setThemeName(themeName);
143 if (QIcon::themeName().isEmpty()) {
144 QIcon::setThemeName(QStringLiteral(
"default"));
147 if (m_fontArg.isPresent()) {
149 font.setFamily(QString::fromLocal8Bit(m_fontArg.values().front()));
151 font.setPointSize(stringToNumber<int>(m_fontArg.values().back()));
152 }
catch (
const ConversionException &) {
153 cerr << Phrases::Warning <<
"The specified font size is no number and will be ignored." << Phrases::EndFlush;
155 QGuiApplication::setFont(font);
158 else if (!preventApplyingDefaultFont) {
159 QGuiApplication::setFont(QFont(QStringLiteral(
"Segoe UI"), 9));
162 VAR_UNUSED(preventApplyingDefaultFont)
164 if (m_libraryPathsArg.isPresent()) {
165 QStringList libraryPaths;
166 libraryPaths.reserve(m_libraryPathsArg.values().size());
167 for (
const auto &path : m_libraryPathsArg.values()) {
168 libraryPaths << QString::fromLocal8Bit(path);
170 QCoreApplication::setLibraryPaths(libraryPaths);
void applySettings(bool preventApplyingDefaultFont=false) const
Applies the settings from the arguments.