| openPilotLog

astyle.h
1 /*
2 *openPilotLog - A FOSS Pilot Logbook Application
3 *Copyright (C) 2020-2021 Felix Turowsky
4 *
5 *This program is free software: you can redistribute it and/or modify
6 *it under the terms of the GNU General Public License as published by
7 *the Free Software Foundation, either version 3 of the License, or
8 *(at your option) any later version.
9 *
10 *This program is distributed in the hope that it will be useful,
11 *but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 *GNU General Public License for more details.
14 *
15 *You should have received a copy of the GNU General Public License
16 *along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18 #ifndef ASTYLE_H
19 #define ASTYLE_H
20 #include <QString>
21 #include <QFileInfo>
22 #include <QHash>
23 #include <QTextStream>
24 #include <QComboBox>
25
30 struct StyleSheet
31 {
32 StyleSheet(QLatin1String style_sheet_name, QLatin1String file_name)
33 : styleSheetName(style_sheet_name), fileName(file_name)
34 {}
35 QLatin1String styleSheetName;
36 QLatin1String fileName;
37 };
38
39 static inline QString read_stylesheet(const QString &stylesheet)
40 {
41 QFile file(stylesheet);
42 file.open(QFile::ReadOnly | QFile::Text);
43 QTextStream stream(&file);
44 return stream.readAll();
45 }
46
50 class AStyle
51 {
52 private:
53 static QString currentStyle;
54 static void resetStyle();
55 public:
56 static const QStringList styles;
57 static const QString defaultStyle;
58 static const QList<StyleSheet> styleSheets;
59
60 static void setup();
61 static void setStyle(const QString &style_key);
62 static void setStyle(const StyleSheet &style_sheet);
63 static void setStyle(const QPalette &palette);
64 static QPalette darkPalette();
65 static const QString& style();
66
67 static inline void loadStylesComboBox(QComboBox *combo_box){
68 combo_box->addItems(AStyle::styles);
69 for (const auto &style_sheet : AStyle::styleSheets) {
70 combo_box->addItem(style_sheet.styleSheetName);
71 }
72 combo_box->addItem(QStringLiteral("Dark-Palette"));
73 combo_box->model()->sort(0);
74 }
75 };
76
77 #endif // ASTYLE_H
AStyle
The AStyle class encapsulates style and stylesheet logic.
Definition: astyle.h:51
AStyle::setup
static void setup()
Setup Application style by reading from openPilotLog.ini.
Definition: astyle.cpp:47
StyleSheet
The StyleSheet struct holds the Display Name and File Name (in the resource system) for the available...
Definition: astyle.h:31