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',
"enables QML debugging (see " 32 "http://doc.qt.io/qt-5/" 33 "qtquick-debugging.html)")
34 , m_styleArg(
"style",
'\0',
"sets the Qt widgets style")
35 , m_iconThemeArg(
"icon-theme",
'\0',
"sets the icon theme and additional " 36 "theme search paths for the Qt GUI")
37 , m_fontArg(
"font",
'\0',
"sets the font family and size (point) for the Qt GUI")
38 , m_libraryPathsArg(
"library-paths",
'\0',
"sets the list of directories to search when loading " 39 "libraries (all existing paths will be deleted)")
40 , m_platformThemeArg(
"platformtheme",
'\0',
"specifies the Qt platform theme to be used")
43 m_lngArg.setValueNames({
"language" });
44 m_lngArg.setRequiredValueCount(1);
45 m_lngArg.setRequired(
false);
46 m_lngArg.setCombinable(
true);
48 m_qmlDebuggerArg.setValueNames({
"port:<port_from>[,port_to][,host:<ip address>][,block]" });
49 m_qmlDebuggerArg.setRequiredValueCount(1);
50 m_qmlDebuggerArg.setCombinable(
true);
52 m_styleArg.setValueNames({
"style name" });
53 m_styleArg.setRequiredValueCount(1);
54 m_styleArg.setCombinable(
true);
55 m_iconThemeArg.setValueNames({
"theme name",
"search path 1",
"search path 2" });
56 m_iconThemeArg.setRequiredValueCount(-1);
57 m_iconThemeArg.setCombinable(
true);
58 m_fontArg.setValueNames({
"name",
"size" });
59 m_fontArg.setRequiredValueCount(2);
60 m_fontArg.setCombinable(
true);
61 m_libraryPathsArg.setValueNames({
"path 1",
"path 2" });
62 m_libraryPathsArg.setRequiredValueCount(-1);
63 m_libraryPathsArg.setCombinable(
true);
64 m_platformThemeArg.setRequiredValueCount(1);
65 m_platformThemeArg.setCombinable(
true);
66 m_platformThemeArg.setValueNames({
"qt5ct/kde/..." });
67 m_platformThemeArg.setPreDefinedCompletionValues(
"qt5ct kde gnome");
68 m_qtWidgetsGuiArg.setSubArguments(
69 { &m_lngArg, &m_qmlDebuggerArg, &m_styleArg, &m_iconThemeArg, &m_fontArg, &m_libraryPathsArg, &m_platformThemeArg });
70 m_qtQuickGuiArg.setSubArguments({ &m_lngArg, &m_qmlDebuggerArg, &m_iconThemeArg, &m_fontArg, &m_libraryPathsArg, &m_platformThemeArg });
71 m_qtWidgetsGuiArg.setDenotesOperation(
true);
72 m_qtQuickGuiArg.setDenotesOperation(
true);
73 #if defined QT_UTILITIES_GUI_QTWIDGETS 74 m_qtWidgetsGuiArg.setImplicit(
true);
75 #elif defined QT_UTILITIES_GUI_QTQUICK 76 m_qtQuickGuiArg.setImplicit(
true);
88 if (m_lngArg.isPresent()) {
89 QLocale::setDefault(QLocale(QString::fromLocal8Bit(m_lngArg.values().front())));
91 if (m_styleArg.isPresent()) {
92 #ifdef QT_UTILITIES_GUI_QTWIDGETS 93 if (QStyle *style = QStyleFactory::create(QString::fromLocal8Bit(m_styleArg.values().front()))) {
94 QApplication::setStyle(style);
96 cerr <<
"Warning: Can not find the specified style." << endl;
99 #ifdef QT_UTILITIES_GUI_QTQUICK 100 cerr <<
"Warning: Can not set a style for the Qt Quick GUI." << endl;
104 if (m_iconThemeArg.isPresent()) {
105 auto i = m_iconThemeArg.values().cbegin(), end = m_iconThemeArg.values().end();
107 QIcon::setThemeName(QString::fromLocal8Bit(*i));
109 QStringList searchPaths;
110 searchPaths.reserve(m_iconThemeArg.values().size() - 1);
111 for (; i != end; ++i) {
112 searchPaths << QString::fromLocal8Bit(*i);
114 searchPaths << QStringLiteral(
":/icons");
115 QIcon::setThemeSearchPaths(searchPaths);
119 if (qEnvironmentVariableIsSet(
"ICON_THEME_SEARCH_PATH")) {
121 path.append(qgetenv(
"ICON_THEME_SEARCH_PATH"));
122 QIcon::setThemeSearchPaths(QStringList() << path << QStringLiteral(
":/icons"));
124 QIcon::setThemeSearchPaths(QIcon::themeSearchPaths() << QStringLiteral(
"../share/icons") << QStringLiteral(
":/icons"));
126 if (qEnvironmentVariableIsSet(
"ICON_THEME")) {
128 themeName.append(qgetenv(
"ICON_THEME"));
129 QIcon::setThemeName(themeName);
134 if (QIcon::themeName().isEmpty()) {
135 QIcon::setThemeName(QStringLiteral(
"default"));
138 if (m_fontArg.isPresent()) {
140 font.setFamily(QString::fromLocal8Bit(m_fontArg.values().front()));
142 font.setPointSize(stringToNumber<int>(m_fontArg.values().back()));
143 }
catch (
const ConversionException &) {
144 cerr <<
"Warning: The specified font size is no number and will be " 148 QGuiApplication::setFont(font);
151 else if (!preventApplyingDefaultFont) {
152 QGuiApplication::setFont(QFont(QStringLiteral(
"Segoe UI"), 9));
155 VAR_UNUSED(preventApplyingDefaultFont)
157 if (m_libraryPathsArg.isPresent()) {
158 QStringList libraryPaths;
159 libraryPaths.reserve(m_libraryPathsArg.values().size());
160 for (
const auto &path : m_libraryPathsArg.values()) {
161 libraryPaths << QString::fromLocal8Bit(path);
163 QCoreApplication::setLibraryPaths(libraryPaths);
void applySettings(bool preventApplyingDefaultFont=false) const
Applies the settings from the arguments.