3 #include <c++utilities/conversion/stringconversion.h> 9 #ifdef QT_UTILITIES_GUI_QTWIDGETS 10 #include <QApplication> 11 #include <QStyleFactory> 13 #include <QGuiApplication> 16 #include <initializer_list> 27 QtConfigArguments::QtConfigArguments()
28 : m_qtWidgetsGuiArg(
"qt-widgets-gui",
'g',
"shows a Qt widgets based graphical user interface")
29 , m_qtQuickGuiArg(
"qt-quick-gui",
'q',
"shows a Qt quick based graphical user interface")
30 , m_lngArg(
"lang",
'l',
"sets the language for the Qt GUI")
31 , m_qmlDebuggerArg(
"qmljsdebugger",
'\0',
32 "enables QML debugging (see " 33 "http://doc.qt.io/qt-5/" 34 "qtquick-debugging.html)")
35 , m_styleArg(
"style",
'\0',
"sets the Qt widgets style")
36 , m_iconThemeArg(
"icon-theme",
'\0',
37 "sets the icon theme and additional " 38 "theme search paths for the Qt GUI")
39 , m_fontArg(
"font",
'\0',
"sets the font family and size (point) for the Qt GUI")
40 , m_libraryPathsArg(
"library-paths",
'\0',
41 "sets the list of directories to search when loading " 42 "libraries (all existing paths will be deleted)")
43 , m_platformThemeArg(
"platformtheme",
'\0',
"specifies the Qt platform theme to be used")
46 m_lngArg.setValueNames({
"language" });
47 m_lngArg.setRequiredValueCount(1);
48 m_lngArg.setRequired(
false);
49 m_lngArg.setCombinable(
true);
51 m_qmlDebuggerArg.setValueNames({
"port:<port_from>[,port_to][,host:<ip address>][,block]" });
52 m_qmlDebuggerArg.setRequiredValueCount(1);
53 m_qmlDebuggerArg.setCombinable(
true);
55 m_styleArg.setValueNames({
"style name" });
56 m_styleArg.setRequiredValueCount(1);
57 m_styleArg.setCombinable(
true);
58 m_iconThemeArg.setValueNames({
"theme name",
"search path 1",
"search path 2" });
59 m_iconThemeArg.setRequiredValueCount(-1);
60 m_iconThemeArg.setCombinable(
true);
61 m_fontArg.setValueNames({
"name",
"size" });
62 m_fontArg.setRequiredValueCount(2);
63 m_fontArg.setCombinable(
true);
64 m_libraryPathsArg.setValueNames({
"path 1",
"path 2" });
65 m_libraryPathsArg.setRequiredValueCount(-1);
66 m_libraryPathsArg.setCombinable(
true);
67 m_platformThemeArg.setRequiredValueCount(1);
68 m_platformThemeArg.setCombinable(
true);
69 m_platformThemeArg.setValueNames({
"qt5ct/kde/..." });
70 m_platformThemeArg.setPreDefinedCompletionValues(
"qt5ct kde gnome");
71 m_qtWidgetsGuiArg.setSubArguments(
72 { &m_lngArg, &m_qmlDebuggerArg, &m_styleArg, &m_iconThemeArg, &m_fontArg, &m_libraryPathsArg, &m_platformThemeArg });
73 m_qtQuickGuiArg.setSubArguments({ &m_lngArg, &m_qmlDebuggerArg, &m_iconThemeArg, &m_fontArg, &m_libraryPathsArg, &m_platformThemeArg });
74 m_qtWidgetsGuiArg.setDenotesOperation(
true);
75 m_qtQuickGuiArg.setDenotesOperation(
true);
76 #if defined QT_UTILITIES_GUI_QTWIDGETS 77 m_qtWidgetsGuiArg.setImplicit(
true);
78 #elif defined QT_UTILITIES_GUI_QTQUICK 79 m_qtQuickGuiArg.setImplicit(
true);
91 if (m_lngArg.isPresent()) {
92 QLocale::setDefault(QLocale(QString::fromLocal8Bit(m_lngArg.values().front())));
94 if (m_styleArg.isPresent()) {
95 #ifdef QT_UTILITIES_GUI_QTWIDGETS 96 if (QStyle *style = QStyleFactory::create(QString::fromLocal8Bit(m_styleArg.values().front()))) {
97 QApplication::setStyle(style);
99 cerr <<
"Warning: Can not find the specified style." << endl;
102 #ifdef QT_UTILITIES_GUI_QTQUICK 103 cerr <<
"Warning: Can not set a style for the Qt Quick GUI." << endl;
107 if (m_iconThemeArg.isPresent()) {
108 auto i = m_iconThemeArg.values().cbegin(), end = m_iconThemeArg.values().end();
110 QIcon::setThemeName(QString::fromLocal8Bit(*i));
112 QStringList searchPaths;
113 searchPaths.reserve(m_iconThemeArg.values().size() - 1);
114 for (; i != end; ++i) {
115 searchPaths << QString::fromLocal8Bit(*i);
117 searchPaths << QStringLiteral(
":/icons");
118 QIcon::setThemeSearchPaths(searchPaths);
122 if (qEnvironmentVariableIsSet(
"ICON_THEME_SEARCH_PATH")) {
124 path.append(qgetenv(
"ICON_THEME_SEARCH_PATH"));
125 QIcon::setThemeSearchPaths(QStringList() << path << QStringLiteral(
":/icons"));
127 QIcon::setThemeSearchPaths(QIcon::themeSearchPaths() << QStringLiteral(
"../share/icons") << QStringLiteral(
":/icons"));
129 if (qEnvironmentVariableIsSet(
"ICON_THEME")) {
131 themeName.append(qgetenv(
"ICON_THEME"));
132 QIcon::setThemeName(themeName);
137 if (QIcon::themeName().isEmpty()) {
138 QIcon::setThemeName(QStringLiteral(
"default"));
141 if (m_fontArg.isPresent()) {
143 font.setFamily(QString::fromLocal8Bit(m_fontArg.values().front()));
145 font.setPointSize(stringToNumber<int>(m_fontArg.values().back()));
146 }
catch (
const ConversionException &) {
147 cerr <<
"Warning: The specified font size is no number and will be " 151 QGuiApplication::setFont(font);
154 else if (!preventApplyingDefaultFont) {
155 QGuiApplication::setFont(QFont(QStringLiteral(
"Segoe UI"), 9));
158 VAR_UNUSED(preventApplyingDefaultFont)
160 if (m_libraryPathsArg.isPresent()) {
161 QStringList libraryPaths;
162 libraryPaths.reserve(m_libraryPathsArg.values().size());
163 for (
const auto &path : m_libraryPathsArg.values()) {
164 libraryPaths << QString::fromLocal8Bit(path);
166 QCoreApplication::setLibraryPaths(libraryPaths);
void applySettings(bool preventApplyingDefaultFont=false) const
Applies the settings from the arguments.