瀏覽代碼

Implemented stylesheet dark checkbox

George 4 年之前
父節點
當前提交
6ec0a35e28
共有 5 個文件被更改,包括 127 次插入78 次删除
  1. 29 13
      src/classes/astyle.cpp
  2. 16 3
      src/classes/astyle.h
  3. 18 5
      src/gui/widgets/settingswidget.cpp
  4. 1 1
      src/gui/widgets/settingswidget.h
  5. 63 56
      src/gui/widgets/settingswidget.ui

+ 29 - 13
src/classes/astyle.cpp

@@ -10,28 +10,39 @@ const QString AStyle::defaultStyle = QStringLiteral("fusion");
 #elif defined(_WIN32) || defined(_WIN64)
 const QString AStyle::defaultStyle = QStringLiteral("Windows");
 #endif
+const QString AStyle::defaultStyleSheet = QStringLiteral("");
 
-const QString AStyle::defaultQStyleSheet = QStringLiteral("dark");
 const QStringList AStyle::styles = QStyleFactory::keys();
-QString AStyle::currentStyle;
-QString AStyle::currentStyleSheet;
+
+const QMap<AStyle::StyleSheet, QFileInfo> AStyle::defaultStyleSheets = {
+    {Dark, QFileInfo(QStringLiteral("dark.qss"))},
+    {Light, QFileInfo(QStringLiteral("light.qss"))},
+    {Default, QFileInfo(defaultStyleSheet)},
+};
+
+QString AStyle::currentStyle = defaultStyle;
+QString AStyle::currentStyleSheet = defaultStyleSheet;
+
 
 static inline
-QString read_stylesheet(const QString stylesheet)
+QString read_stylesheet(const AStyle::StyleSheet stylesheet)
 {
-    DEB << "reading:" << ":" + stylesheet + ".qss";
-    QFile file(":" + stylesheet + ".qss");
+    QFileInfo qss_file_info = AStyle::defaultStyleSheets[stylesheet];
+    DEB << "reading:" << ":" + qss_file_info.fileName();
+
+    QFile file(":" + qss_file_info.fileName());
     file.open(QFile::ReadOnly | QFile::Text);
     QTextStream stream(&file);
     return stream.readAll();
 }
 
-// [G]: Are there leaks when style changes?
+/*!
+ * \brief Setup style and stylesheet by reading from openPilotLog.ini
+ */
 void AStyle::setup()
 {
+    // [G]: Are there leaks when style changes?
     QVariant app_style = ASettings::read(ASettings::Main::Style);
-    QVariant app_stylesheet = ASettings::read(ASettings::Main::StyleSheet);
-
     if(!app_style.toBool()){
         DEB << "Setting style to default:" << defaultStyle;
         app_style = defaultStyle;
@@ -41,13 +52,14 @@ void AStyle::setup()
     QApplication::setStyle(QStyleFactory::create(app_style.toString()));
     currentStyle = app_style.toString();
 
+    auto app_stylesheet = ASettings::read(ASettings::Main::StyleSheet);
     if(!app_stylesheet.toBool()){
-        DEB << "Setting stylesheet to default:" << defaultQStyleSheet;
-        app_stylesheet = defaultQStyleSheet;
+        DEB << "Setting stylesheet to default:" << defaultStyleSheet;
+        app_stylesheet = defaultStyleSheet;
         ASettings::write(ASettings::Main::StyleSheet, app_stylesheet);
     }
     DEB << "Stylesheet set to:" << app_stylesheet;
-    qApp->setStyleSheet(read_stylesheet(app_stylesheet.toString()));
+    qApp->setStyleSheet(read_stylesheet(static_cast<StyleSheet>(app_stylesheet.toUInt())));
     currentStyleSheet = app_stylesheet.toString();
 }
 
@@ -56,11 +68,15 @@ void AStyle::setStyle(const QString style)
     DEB << "Setting style to:" << style;
     QApplication::setStyle(QStyleFactory::create(style));
     ASettings::write(ASettings::Main::Style, style);
+    currentStyle = style;
 }
 
-void AStyle::setStyleSheet(const QString stylesheet)
+void AStyle::setStyleSheet(const StyleSheet stylesheet)
 {
+    DEB << "Setting stylesheet to:" << defaultStyleSheets[stylesheet];
     qApp->setStyleSheet(read_stylesheet(stylesheet));
+    ASettings::write(ASettings::Main::StyleSheet, stylesheet);
+    currentStyleSheet = defaultStyleSheets[stylesheet].fileName();
 }
 
 const QString& AStyle::style()

+ 16 - 3
src/classes/astyle.h

@@ -1,21 +1,34 @@
 #ifndef ASTYLE_H
 #define ASTYLE_H
 #include <QString>
-#include <QFile>
+#include <QFileInfo>
+#include <QMap>
 
+/*!
+ * \brief The AStyle class encapsulates style and stylesheet logic.
+ * \todo Agree upon the file naming of the assets that will be read.
+ * for now it is assumed that dark means "dark.qss"
+ */
 class AStyle
 {
+public:
+    enum StyleSheet{
+        Dark = 0,
+        Light,
+        Default,
+    };
 private:
     static QString currentStyle;
     static QString currentStyleSheet;
 public:
     static const QStringList styles;
     static const QString defaultStyle;
-    static const QString defaultQStyleSheet;
+    static const QString defaultStyleSheet;
+    static const QMap<StyleSheet, QFileInfo> defaultStyleSheets;
 
     static void setup();
     static void setStyle(const QString style);
-    static void setStyleSheet(const QString style_sheet);
+    static void setStyleSheet(const StyleSheet stylesheet);
     static const QString& style();
     static const QString& styleSheet();
 };

+ 18 - 5
src/gui/widgets/settingswidget.cpp

@@ -62,15 +62,13 @@ SettingsWidget::SettingsWidget(QWidget *parent) :
     ui->styleComboBox->model()->sort(0);
     ui->styleComboBox->setCurrentText(current_style);
 
+    if(ASettings::read(ASettings::Main::StyleSheet).toUInt() == AStyle::Dark)
+        ui->darkStyleCheckBox->setCheckState(Qt::Checked);
+
     readSettings();
     setupValidators();
 }
 
-void SettingsWidget::on_styleComboBox_currentTextChanged(const QString& text)
-{
-    DEB << text;
-    AStyle::setStyle(text);
-}
 
 SettingsWidget::~SettingsWidget()
 {
@@ -341,3 +339,18 @@ void SettingsWidget::on_aboutPushButton_clicked()
     message_box.setText(text);
     message_box.exec();
 }
+
+void SettingsWidget::on_styleComboBox_currentTextChanged(const QString& text)
+{
+    DEB << text;
+    AStyle::setStyle(text);
+}
+
+void SettingsWidget::on_darkStyleCheckBox_stateChanged(int state)
+{
+    DEB << "Setting to:" << (state ? "dark" : "default");
+    if(state == Qt::Checked)
+        AStyle::setStyleSheet(AStyle::Dark);
+    else
+        AStyle::setStyleSheet(AStyle::Default);
+}

+ 1 - 1
src/gui/widgets/settingswidget.h

@@ -57,7 +57,7 @@ private slots:
     void on_pilotSortComboBox_currentIndexChanged(int index);
     void on_logbookViewComboBox_currentIndexChanged(int index);
     void on_companyLineEdit_editingFinished();
-
+    void on_darkStyleCheckBox_stateChanged(int state);
     void on_styleComboBox_currentTextChanged(const QString& index);
 
 private:

+ 63 - 56
src/gui/widgets/settingswidget.ui

@@ -468,8 +468,8 @@
        <string>Misc</string>
       </attribute>
       <layout class="QGridLayout" name="gridLayout_5">
-       <item row="2" column="1">
-        <widget class="QLabel" name="pilotSortLabel">
+       <item row="5" column="1">
+        <widget class="QLabel" name="logbookViewLabel">
          <property name="sizePolicy">
           <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
            <horstretch>0</horstretch>
@@ -477,31 +477,14 @@
           </sizepolicy>
          </property>
          <property name="toolTip">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines by which column to sort the display of Pilots in the Pilots Tab.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines how your logbook is displayed in the logbook tab. This has no influence on what details are logged, just on what is displayed by default.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
          </property>
          <property name="whatsThis">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines by which column to sort the display of Pilots in the Pilots Tab.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines how your logbook is displayed in the logbook tab. This has no influence on what details are logged, just on what is displayed by default.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
          </property>
          <property name="text">
-          <string>Sort Pilots by</string>
-         </property>
-        </widget>
-       </item>
-       <item row="4" column="2">
-        <widget class="QComboBox" name="acAllowIncompleteComboBox">
-         <property name="toolTip">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines whether incomplete database entries are permitted. It is highly recommended to keep this option off.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+          <string>Logbook Dispay</string>
          </property>
-         <item>
-          <property name="text">
-           <string>No</string>
-          </property>
-         </item>
-         <item>
-          <property name="text">
-           <string>Yes</string>
-          </property>
-         </item>
         </widget>
        </item>
        <item row="3" column="2">
@@ -526,11 +509,8 @@
          </item>
         </widget>
        </item>
-       <item row="0" column="2">
-        <widget class="QComboBox" name="styleComboBox"/>
-       </item>
-       <item row="3" column="1">
-        <widget class="QLabel" name="acSortLabel">
+       <item row="4" column="1">
+        <widget class="QLabel" name="acAllowIncompleteLabel">
          <property name="sizePolicy">
           <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
            <horstretch>0</horstretch>
@@ -538,35 +518,39 @@
           </sizepolicy>
          </property>
          <property name="toolTip">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines by which column to sort the display of Aircaft in the Aircraft Tab.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
-         </property>
-         <property name="whatsThis">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines by which column to sort the display of Aircaft in the Aircraft Tab.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines whether incomplete database entries are permitted. It is highly recommended to keep this option off.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
          </property>
          <property name="text">
-          <string>Sort Aircraft by</string>
+          <string>Allow incomplete Entries </string>
          </property>
         </widget>
        </item>
-       <item row="5" column="2">
-        <widget class="QComboBox" name="logbookViewComboBox">
+       <item row="4" column="2">
+        <widget class="QComboBox" name="acAllowIncompleteComboBox">
          <property name="toolTip">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines how your logbook is displayed in the logbook tab. This has no influence on what details are logged, just on what is displayed by default.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines whether incomplete database entries are permitted. It is highly recommended to keep this option off.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
          </property>
          <item>
           <property name="text">
-           <string>Default</string>
+           <string>No</string>
           </property>
          </item>
          <item>
           <property name="text">
-           <string>EASA Part-FCL</string>
+           <string>Yes</string>
           </property>
          </item>
         </widget>
        </item>
-       <item row="5" column="1">
-        <widget class="QLabel" name="logbookViewLabel">
+       <item row="0" column="3">
+        <widget class="QCheckBox" name="darkStyleCheckBox">
+         <property name="text">
+          <string>Dark</string>
+         </property>
+        </widget>
+       </item>
+       <item row="3" column="1">
+        <widget class="QLabel" name="acSortLabel">
          <property name="sizePolicy">
           <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
            <horstretch>0</horstretch>
@@ -574,16 +558,41 @@
           </sizepolicy>
          </property>
          <property name="toolTip">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines how your logbook is displayed in the logbook tab. This has no influence on what details are logged, just on what is displayed by default.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines by which column to sort the display of Aircaft in the Aircraft Tab.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
          </property>
          <property name="whatsThis">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines how your logbook is displayed in the logbook tab. This has no influence on what details are logged, just on what is displayed by default.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines by which column to sort the display of Aircaft in the Aircraft Tab.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
          </property>
          <property name="text">
-          <string>Logbook Dispay</string>
+          <string>Sort Aircraft by</string>
          </property>
         </widget>
        </item>
+       <item row="2" column="2">
+        <widget class="QComboBox" name="pilotSortComboBox">
+         <property name="toolTip">
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines by which column to sort the display of Pilots in the Pilots Tab.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+         </property>
+         <item>
+          <property name="text">
+           <string>Last Name</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>First Name</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>Company</string>
+          </property>
+         </item>
+        </widget>
+       </item>
+       <item row="0" column="2">
+        <widget class="QComboBox" name="styleComboBox"/>
+       </item>
        <item row="0" column="1">
         <widget class="QLabel" name="styleLabel">
          <property name="sizePolicy">
@@ -597,30 +606,25 @@
          </property>
         </widget>
        </item>
-       <item row="2" column="2">
-        <widget class="QComboBox" name="pilotSortComboBox">
+       <item row="5" column="2">
+        <widget class="QComboBox" name="logbookViewComboBox">
          <property name="toolTip">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines by which column to sort the display of Pilots in the Pilots Tab.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines how your logbook is displayed in the logbook tab. This has no influence on what details are logged, just on what is displayed by default.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
          </property>
          <item>
           <property name="text">
-           <string>Last Name</string>
-          </property>
-         </item>
-         <item>
-          <property name="text">
-           <string>First Name</string>
+           <string>Default</string>
           </property>
          </item>
          <item>
           <property name="text">
-           <string>Company</string>
+           <string>EASA Part-FCL</string>
           </property>
          </item>
         </widget>
        </item>
-       <item row="4" column="1">
-        <widget class="QLabel" name="acAllowIncompleteLabel">
+       <item row="2" column="1">
+        <widget class="QLabel" name="pilotSortLabel">
          <property name="sizePolicy">
           <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
            <horstretch>0</horstretch>
@@ -628,10 +632,13 @@
           </sizepolicy>
          </property>
          <property name="toolTip">
-          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines whether incomplete database entries are permitted. It is highly recommended to keep this option off.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines by which column to sort the display of Pilots in the Pilots Tab.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+         </property>
+         <property name="whatsThis">
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines by which column to sort the display of Pilots in the Pilots Tab.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
          </property>
          <property name="text">
-          <string>Allow incomplete Entries </string>
+          <string>Sort Pilots by</string>
          </property>
         </widget>
        </item>