openPilotLog
style.h
1 /*
2  *openPilotLog - A FOSS Pilot Logbook Application
3  *Copyright (C) 2020-2022 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 STYLE_H
19 #define STYLE_H
20 #include <QString>
21 #include <QFileInfo>
22 #include <QHash>
23 #include <QTextStream>
24 #include <QComboBox>
25 
26 namespace OPL {
27 
32 struct StyleSheet
33 {
34  StyleSheet(QLatin1String style_sheet_name, QLatin1String file_name)
35  : styleSheetName(style_sheet_name), fileName(file_name)
36  {}
37  QLatin1String styleSheetName;
38  QLatin1String fileName;
39 };
40 
41 static inline QString read_stylesheet(const QString &stylesheet)
42 {
43  QFile file(stylesheet);
44  file.open(QFile::ReadOnly | QFile::Text);
45  QTextStream stream(&file);
46  return stream.readAll();
47 }
48 
52 class Style
53 {
54 private:
55  static QString currentStyle;
56  static QLatin1String DARK_PALETTE;
57  static void resetStyle();
58 public:
59 
60  enum class StyleType {Light, Dark};
61 
62  static const QStringList styles;
63  static const inline QString defaultStyle = QStringLiteral("Fusion");
64  static const QList<StyleSheet> styleSheets;
65 
66  static void setup();
67  static void setStyle(const QString &style_key);
68  static void setStyle(const StyleSheet &style_sheet);
69  static void setStyle(const QPalette &palette);
70  static QString getCurrentStyle() {return currentStyle;}
71  static StyleType getStyleType();
72  static QPalette darkPalette();
73  static const QString& style();
74 
75  static inline void loadStylesComboBox(QComboBox *combo_box){
76  const QSignalBlocker blocker(combo_box);
77  combo_box->addItems(Style::styles);
78  for (const auto &style_sheet : Style::styleSheets) {
79  combo_box->addItem(style_sheet.styleSheetName);
80  }
81  combo_box->addItem(QStringLiteral("Dark-Palette"));
82  combo_box->model()->sort(0);
83  }
84 };
85 
86 } // namespace OPL
87 
88 #endif // STYLE_H
The AStyle class encapsulates style and stylesheet logic.
Definition: style.h:53
static void setup()
Setup Application style by reading from openPilotLog.ini.
Definition: style.cpp:51
A namespace to collect constants and enums used throughout the application.
Definition: paths.cpp:3
The StyleSheet struct holds the Display Name and File Name (in the resource system) for the available...
Definition: style.h:33