Browse Source

Rework of user-facing style choices

closes #62
- User-facing style choices unified into the style combo box in the settingswidget, styleCheckBox removed
- Distinction between style and stylesheets are handled in the AStyle class.
- ASettings adjusted accordingly
Felix Turo 4 years ago
parent
commit
68a5bc92da

+ 0 - 1
src/classes/asettings.cpp

@@ -21,7 +21,6 @@
 
 
 QMap<ASettings::Main, QString> ASettings::mainMap = {
 QMap<ASettings::Main, QString> ASettings::mainMap = {
     {Main::Style,                       QStringLiteral("style")},
     {Main::Style,                       QStringLiteral("style")},
-    {Main::StyleSheet,                  QStringLiteral("stylesheet")},
 };
 };
 
 
 QMap<ASettings::LogBook, QString> ASettings::logBookMap = {
 QMap<ASettings::LogBook, QString> ASettings::logBookMap = {

+ 34 - 40
src/classes/astyle.cpp

@@ -15,6 +15,11 @@
  *You should have received a copy of the GNU General Public License
  *You should have received a copy of the GNU General Public License
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
  */
+
+/*
+ * Stylesheets used (c) Alexander Huszagh
+ * https://github.com/Alexhuszagh/BreezeStyleSheets
+ */
 #include "astyle.h"
 #include "astyle.h"
 #include <QStyle>
 #include <QStyle>
 #include <QStyleFactory>
 #include <QStyleFactory>
@@ -24,27 +29,22 @@
 
 
 const QString AStyle::defaultStyle = QStringLiteral("Fusion");
 const QString AStyle::defaultStyle = QStringLiteral("Fusion");
 
 
-const QString AStyle::defaultStyleSheet = QStringLiteral("");
+const QString AStyle::defaultStyleSheet = QString();
 
 
 const QStringList AStyle::styles = QStyleFactory::keys();
 const QStringList AStyle::styles = QStyleFactory::keys();
 
 
-const QMap<AStyle::StyleSheet, QFileInfo> AStyle::defaultStyleSheets = {
-    {Dark, QFileInfo(QStringLiteral("dark.qss"))},
-    {Light, QFileInfo(QStringLiteral("light.qss"))},
-    {Default, QFileInfo(defaultStyleSheet)},
+const QList<QPair <QString, QString>> AStyle::styleSheets = {
+    {QStringLiteral("Breeze"), QStringLiteral(":light.qss")},
+    {QStringLiteral("Breeze-Dark"), QStringLiteral(":dark.qss")}
 };
 };
 
 
 QString AStyle::currentStyle = defaultStyle;
 QString AStyle::currentStyle = defaultStyle;
 QString AStyle::currentStyleSheet = defaultStyleSheet;
 QString AStyle::currentStyleSheet = defaultStyleSheet;
 
 
 
 
-static inline
-QString read_stylesheet(const AStyle::StyleSheet stylesheet)
+static inline QString read_stylesheet(const QString &stylesheet)
 {
 {
-    QFileInfo qss_file_info = AStyle::defaultStyleSheets[stylesheet];
-//    DEB << "reading:" << ":" + qss_file_info.fileName();
-
-    QFile file(":" + qss_file_info.fileName());
+    QFile file(stylesheet);
     file.open(QFile::ReadOnly | QFile::Text);
     file.open(QFile::ReadOnly | QFile::Text);
     QTextStream stream(&file);
     QTextStream stream(&file);
     return stream.readAll();
     return stream.readAll();
@@ -55,50 +55,44 @@ QString read_stylesheet(const AStyle::StyleSheet stylesheet)
  */
  */
 void AStyle::setup()
 void AStyle::setup()
 {
 {
-    // [G]: Are there leaks when style changes?
-    QVariant app_style = ASettings::read(ASettings::Main::Style);
-    if(!app_style.toBool()){
+    QVariant style_setting = ASettings::read(ASettings::Main::Style);
+    if(!style_setting.toBool()){
         //DEB << "Setting style to default:" << defaultStyle;
         //DEB << "Setting style to default:" << defaultStyle;
-        app_style = defaultStyle;
-        ASettings::write(ASettings::Main::Style, app_style);
+        style_setting = defaultStyle;
+        ASettings::write(ASettings::Main::Style, style_setting);
     }
     }
-    //DEB << "Style set to:" << app_style;
-    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:" << defaultStyleSheet;
-        app_stylesheet = defaultStyleSheet;
-        ASettings::write(ASettings::Main::StyleSheet, app_stylesheet);
+    for (const auto &style_name : styles) {
+        if (style_setting == style_name) {
+            setStyle(style_name);
+            currentStyle = style_name;
+            return;
+        }
+    }
+    for (const auto &style_sheet_name : styleSheets) {
+        if (style_setting == style_sheet_name.first) {
+            setStyle(style_sheet_name);
+            currentStyle = style_sheet_name.first;
+            return;
+        }
     }
     }
-    //DEB << "Stylesheet set to:" << app_stylesheet;
-    qApp->setStyleSheet(read_stylesheet(static_cast<StyleSheet>(app_stylesheet.toUInt())));
-    currentStyleSheet = app_stylesheet.toString();
 }
 }
 
 
 void AStyle::setStyle(const QString style)
 void AStyle::setStyle(const QString style)
 {
 {
-    //DEB << "Setting style to:" << style;
+    DEB << "Setting style: " << style;
+    qApp->setStyleSheet(QString());
     QApplication::setStyle(QStyleFactory::create(style));
     QApplication::setStyle(QStyleFactory::create(style));
-    ASettings::write(ASettings::Main::Style, style);
     currentStyle = style;
     currentStyle = style;
 }
 }
 
 
-void AStyle::setStyleSheet(const StyleSheet stylesheet)
+void AStyle::setStyle(const QPair<QString, QString> stylesheet)
 {
 {
-    //DEB << "Setting stylesheet to:" << defaultStyleSheets[stylesheet].baseName();
-    qApp->setStyleSheet(read_stylesheet(stylesheet));
-    ASettings::write(ASettings::Main::StyleSheet, stylesheet);
-    currentStyleSheet = defaultStyleSheets[stylesheet].fileName();
+    DEB << "Setting stylesheet: " << stylesheet.first;
+    qApp->setStyleSheet(read_stylesheet(stylesheet.second));
+    currentStyleSheet = stylesheet.first;
 }
 }
 
 
 const QString& AStyle::style()
 const QString& AStyle::style()
 {
 {
     return currentStyle;
     return currentStyle;
 }
 }
-
-const QString& AStyle::styleSheet()
-{
-    return currentStyleSheet;
-}

+ 6 - 9
src/classes/astyle.h

@@ -28,26 +28,23 @@
  */
  */
 class AStyle
 class AStyle
 {
 {
-public:
-    enum StyleSheet{
-        Default = 0,
-        Dark,
-        Light
-    };
 private:
 private:
     static QString currentStyle;
     static QString currentStyle;
     static QString currentStyleSheet;
     static QString currentStyleSheet;
 public:
 public:
     static const QStringList styles;
     static const QStringList styles;
     static const QString defaultStyle;
     static const QString defaultStyle;
+    /*!
+     * \brief contains a List of the available style sheets and their
+     * file name in the resource system.
+     */
+    static const QList<QPair<QString, QString>> styleSheets;
     static const QString defaultStyleSheet;
     static const QString defaultStyleSheet;
-    static const QMap<StyleSheet, QFileInfo> defaultStyleSheets;
 
 
     static void setup();
     static void setup();
     static void setStyle(const QString style);
     static void setStyle(const QString style);
-    static void setStyleSheet(const StyleSheet stylesheet);
+    static void setStyle(const QPair<QString, QString> stylesheet);
     static const QString& style();
     static const QString& style();
-    static const QString& styleSheet();
 };
 };
 
 
 #endif // ASTYLE_H
 #endif // ASTYLE_H

+ 30 - 27
src/gui/widgets/settingswidget.cpp

@@ -65,21 +65,19 @@ SettingsWidget::~SettingsWidget()
 }
 }
 
 
 void SettingsWidget::setupComboBoxes(){
 void SettingsWidget::setupComboBoxes(){
-    // Style Combo Box
-    auto styles = AStyle::styles;
-    auto current_style = AStyle::style();
-    ui->styleComboBox->addItem(current_style);
-    styles.removeOne(current_style);
-
-    ui->styleComboBox->addItems(styles);
-    ui->styleComboBox->model()->sort(0);
-    ui->styleComboBox->setCurrentText(current_style);
-
-    if(ASettings::read(ASettings::Main::StyleSheet).toUInt() == AStyle::Dark)
-        ui->darkStyleCheckBox->setCheckState(Qt::Checked);
-    // Approach Combo Box
-    for (const auto &approach : Opl::ApproachTypes) {
-        ui->approachComboBox->addItem(approach);
+    {
+        // Style combo box
+        const QSignalBlocker blocker_style(ui->styleComboBox);
+        ui->styleComboBox->addItems(AStyle::styles);
+        for (const auto &style_sheet_name : AStyle::styleSheets) {
+            ui->styleComboBox->addItem(style_sheet_name.first);
+        }
+
+        // Approach Combo Box
+        const QSignalBlocker blocker_approach(ui->approachComboBox);
+        for (const auto &approach : Opl::ApproachTypes) {
+            ui->approachComboBox->addItem(approach);
+        }
     }
     }
 }
 }
 
 
@@ -111,11 +109,12 @@ void SettingsWidget::readSettings()
 
 
     ui->logbookViewComboBox->setCurrentIndex(ASettings::read(ASettings::LogBook::View).toInt());
     ui->logbookViewComboBox->setCurrentIndex(ASettings::read(ASettings::LogBook::View).toInt());
     /*
     /*
-     * Aircraft Tab
+     * Misc Tab
      */
      */
     ui->acSortComboBox->setCurrentIndex(ASettings::read(ASettings::UserData::AcftSortColumn).toInt());
     ui->acSortComboBox->setCurrentIndex(ASettings::read(ASettings::UserData::AcftSortColumn).toInt());
     ui->pilotSortComboBox->setCurrentIndex(ASettings::read(ASettings::UserData::PilSortColumn).toInt());
     ui->pilotSortComboBox->setCurrentIndex(ASettings::read(ASettings::UserData::PilSortColumn).toInt());
     ui->acAllowIncompleteComboBox->setCurrentIndex(ASettings::read(ASettings::UserData::AcAllowIncomplete).toInt());
     ui->acAllowIncompleteComboBox->setCurrentIndex(ASettings::read(ASettings::UserData::AcAllowIncomplete).toInt());
+    ui->styleComboBox->setCurrentText(ASettings::read(ASettings::Main::Style).toString());
 }
 }
 
 
 void SettingsWidget::setupValidators()
 void SettingsWidget::setupValidators()
@@ -339,17 +338,21 @@ void SettingsWidget::on_aboutPushButton_clicked()
     message_box.exec();
     message_box.exec();
 }
 }
 
 
-void SettingsWidget::on_styleComboBox_currentTextChanged(const QString& text)
+void SettingsWidget::on_styleComboBox_currentTextChanged(const QString& new_style_setting)
 {
 {
-    DEB << text;
-    AStyle::setStyle(text);
-}
+    for (const auto &style_name : AStyle::styles) {
+        if (new_style_setting == style_name) {
+            AStyle::setStyle(style_name);
+            ASettings::write(ASettings::Main::Style, new_style_setting);
+            return;
+        }
+    }
 
 
-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);
+    for (const auto &style_sheet_name : AStyle::styleSheets) {
+        if (new_style_setting == style_sheet_name.first) {
+            AStyle::setStyle(style_sheet_name);
+            ASettings::write(ASettings::Main::Style, new_style_setting);
+            return;
+        }
+    }
 }
 }

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

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

+ 62 - 69
src/gui/widgets/settingswidget.ui

@@ -17,7 +17,7 @@
    <item row="0" column="1">
    <item row="0" column="1">
     <widget class="QTabWidget" name="tabWidget">
     <widget class="QTabWidget" name="tabWidget">
      <property name="currentIndex">
      <property name="currentIndex">
-      <number>1</number>
+      <number>2</number>
      </property>
      </property>
      <widget class="QWidget" name="personalTab">
      <widget class="QWidget" name="personalTab">
       <attribute name="title">
       <attribute name="title">
@@ -381,28 +381,6 @@
          </property>
          </property>
         </widget>
         </widget>
        </item>
        </item>
-       <item row="3" column="2">
-        <widget class="QComboBox" name="acSortComboBox">
-         <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>
-         <item>
-          <property name="text">
-           <string>Registration</string>
-          </property>
-         </item>
-         <item>
-          <property name="text">
-           <string>Type</string>
-          </property>
-         </item>
-         <item>
-          <property name="text">
-           <string>Company</string>
-          </property>
-         </item>
-        </widget>
-       </item>
        <item row="4" column="1">
        <item row="4" column="1">
         <widget class="QLabel" name="acAllowIncompleteLabel">
         <widget class="QLabel" name="acAllowIncompleteLabel">
          <property name="sizePolicy">
          <property name="sizePolicy">
@@ -419,27 +397,35 @@
          </property>
          </property>
         </widget>
         </widget>
        </item>
        </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>
+       <item row="0" column="1">
+        <widget class="QLabel" name="styleLabel">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <property name="text">
+          <string>Style</string>
          </property>
          </property>
-         <item>
-          <property name="text">
-           <string>No</string>
-          </property>
-         </item>
-         <item>
-          <property name="text">
-           <string>Yes</string>
-          </property>
-         </item>
         </widget>
         </widget>
        </item>
        </item>
-       <item row="0" column="3">
-        <widget class="QCheckBox" name="darkStyleCheckBox">
+       <item row="2" column="1">
+        <widget class="QLabel" name="pilotSortLabel">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </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>
+         </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">
          <property name="text">
-          <string>Dark</string>
+          <string>Sort Pilots by</string>
          </property>
          </property>
         </widget>
         </widget>
        </item>
        </item>
@@ -462,6 +448,28 @@
          </property>
          </property>
         </widget>
         </widget>
        </item>
        </item>
+       <item row="3" column="2">
+        <widget class="QComboBox" name="acSortComboBox">
+         <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>
+         <item>
+          <property name="text">
+           <string>Registration</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>Type</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>Company</string>
+          </property>
+         </item>
+        </widget>
+       </item>
        <item row="2" column="2">
        <item row="2" column="2">
         <widget class="QComboBox" name="pilotSortComboBox">
         <widget class="QComboBox" name="pilotSortComboBox">
          <property name="toolTip">
          <property name="toolTip">
@@ -487,17 +495,21 @@
        <item row="0" column="2">
        <item row="0" column="2">
         <widget class="QComboBox" name="styleComboBox"/>
         <widget class="QComboBox" name="styleComboBox"/>
        </item>
        </item>
-       <item row="0" column="1">
-        <widget class="QLabel" name="styleLabel">
-         <property name="sizePolicy">
-          <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
-           <horstretch>0</horstretch>
-           <verstretch>0</verstretch>
-          </sizepolicy>
-         </property>
-         <property name="text">
-          <string>Style</string>
+       <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>
          </property>
          </property>
+         <item>
+          <property name="text">
+           <string>No</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>Yes</string>
+          </property>
+         </item>
         </widget>
         </widget>
        </item>
        </item>
        <item row="5" column="2">
        <item row="5" column="2">
@@ -517,25 +529,6 @@
          </item>
          </item>
         </widget>
         </widget>
        </item>
        </item>
-       <item row="2" column="1">
-        <widget class="QLabel" name="pilotSortLabel">
-         <property name="sizePolicy">
-          <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
-           <horstretch>0</horstretch>
-           <verstretch>0</verstretch>
-          </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>
-         </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>Sort Pilots by</string>
-         </property>
-        </widget>
-       </item>
       </layout>
       </layout>
      </widget>
      </widget>
      <widget class="QWidget" name="aboutTab">
      <widget class="QWidget" name="aboutTab">