3 #include <c++utilities/conversion/stringconversion.h> 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 http://doc.qt.io/qt-5/qtquick-debugging.html)"),
32 m_styleArg(
"style",
'\0',
"sets the Qt widgets style"),
33 m_iconThemeArg(
"icon-theme",
'\0',
"sets the icon theme and additional theme search paths for the Qt GUI"),
34 m_fontArg(
"font",
'\0',
"sets the font family and size (point) for the Qt GUI"),
35 m_libraryPathsArg(
"library-paths",
'\0',
"sets the list of directories to search when loading libraries (all existing paths will be deleted)"),
36 m_platformThemeArg(
"platformtheme",
'\0',
"specifies the Qt platform theme to be used")
39 m_lngArg.setValueNames({
"language"});
40 m_lngArg.setRequiredValueCount(1);
41 m_lngArg.setRequired(
false);
42 m_lngArg.setCombinable(
true);
44 m_qmlDebuggerArg.setValueNames({
"port:<port_from>[,port_to][,host:<ip address>][,block]"});
45 m_qmlDebuggerArg.setRequiredValueCount(1);
46 m_qmlDebuggerArg.setCombinable(
true);
48 m_styleArg.setValueNames({
"style name"});
49 m_styleArg.setRequiredValueCount(1);
50 m_styleArg.setCombinable(
true);
51 m_iconThemeArg.setValueNames({
"theme name",
"search path 1",
"search path 2"});
52 m_iconThemeArg.setRequiredValueCount(-1);
53 m_iconThemeArg.setCombinable(
true);
54 m_fontArg.setValueNames({
"name",
"size"});
55 m_fontArg.setRequiredValueCount(2);
56 m_fontArg.setCombinable(
true);
57 m_libraryPathsArg.setValueNames({
"path 1",
"path 2"});
58 m_libraryPathsArg.setRequiredValueCount(-1);
59 m_libraryPathsArg.setCombinable(
true);
60 m_platformThemeArg.setRequiredValueCount(1);
61 m_platformThemeArg.setCombinable(
true);
62 m_platformThemeArg.setValueNames({
"qt5ct/kde/..."});
63 m_platformThemeArg.setPreDefinedCompletionValues(
"qt5ct kde gnome");
64 m_qtWidgetsGuiArg.setSubArguments({&m_lngArg, &m_qmlDebuggerArg, &m_styleArg, &m_iconThemeArg, &m_fontArg, &m_libraryPathsArg, &m_platformThemeArg});
65 m_qtQuickGuiArg.setSubArguments({&m_lngArg, &m_qmlDebuggerArg, &m_iconThemeArg, &m_fontArg, &m_libraryPathsArg, &m_platformThemeArg});
66 m_qtWidgetsGuiArg.setDenotesOperation(
true);
67 m_qtQuickGuiArg.setDenotesOperation(
true);
68 #if defined GUI_QTWIDGETS 69 m_qtWidgetsGuiArg.setImplicit(
true);
70 #elif defined GUI_QTQUICK 71 m_qtQuickGuiArg.setImplicit(
true);
82 if(m_lngArg.isPresent()) {
83 QLocale::setDefault(QLocale(QString::fromLocal8Bit(m_lngArg.values().front())));
85 if(m_styleArg.isPresent()) {
87 if(QStyle *style = QStyleFactory::create(QString::fromLocal8Bit(m_styleArg.values().front()))) {
88 QApplication::setStyle(style);
90 cerr <<
"Warning: Can not find the specified style." << endl;
94 cerr <<
"Warning: Can not set a style for the Qt Quick GUI." << endl;
98 if(m_iconThemeArg.isPresent()) {
99 auto i = m_iconThemeArg.values().cbegin(), end = m_iconThemeArg.values().end();
101 QIcon::setThemeName(QString::fromLocal8Bit(*i));
103 QStringList searchPaths;
104 searchPaths.reserve(m_iconThemeArg.values().size() - 1);
105 for(; i != end; ++i) {
106 searchPaths << QString::fromLocal8Bit(*i);
108 searchPaths << QStringLiteral(
":/icons");
109 QIcon::setThemeSearchPaths(searchPaths);
113 if(qEnvironmentVariableIsSet(
"ICON_THEME_SEARCH_PATH")) {
115 path.append(qgetenv(
"ICON_THEME_SEARCH_PATH"));
116 QIcon::setThemeSearchPaths(QStringList() << path << QStringLiteral(
":/icons"));
118 QIcon::setThemeSearchPaths(QIcon::themeSearchPaths() << QStringLiteral(
"../share/icons") << QStringLiteral(
":/icons"));
120 if(qEnvironmentVariableIsSet(
"ICON_THEME")) {
122 themeName.append(qgetenv(
"ICON_THEME"));
123 QIcon::setThemeName(themeName);
128 if(QIcon::themeName().isEmpty()) {
129 QIcon::setThemeName(QStringLiteral(
"default"));
132 if(m_fontArg.isPresent()) {
134 font.setFamily(QString::fromLocal8Bit(m_fontArg.values().front()));
136 font.setPointSize(stringToNumber<int>(m_fontArg.values().back()));
137 }
catch(
const ConversionException &) {
138 cerr <<
"Warning: The specified font size is no number and will be ignored." << endl;
140 QGuiApplication::setFont(font);
143 else if(!preventApplyingDefaultFont) {
144 QGuiApplication::setFont(QFont(QStringLiteral(
"Segoe UI"), 9));
147 VAR_UNUSED(preventApplyingDefaultFont)
149 if(m_libraryPathsArg.isPresent()) {
150 QStringList libraryPaths;
151 libraryPaths.reserve(m_libraryPathsArg.values().size());
152 for(
const auto &path : m_libraryPathsArg.values()) {
153 libraryPaths << QString::fromLocal8Bit(path);
155 QCoreApplication::setLibraryPaths(libraryPaths);
void applySettings(bool preventApplyingDefaultFont=false) const
Applies the settings from the arguments.