Browse Source

Setup AStyle static class

George 4 years ago
parent
commit
a67b04bbfb
7 changed files with 201 additions and 124 deletions
  1. 24 22
      main.cpp
  2. 2 0
      openPilotLog.pro
  3. 22 0
      src/astyle.cpp
  4. 14 0
      src/astyle.h
  5. 29 14
      src/gui/widgets/settingswidget.cpp
  6. 2 0
      src/gui/widgets/settingswidget.h
  7. 108 88
      src/gui/widgets/settingswidget.ui

+ 24 - 22
main.cpp

@@ -22,6 +22,7 @@
 #include "src/classes/asettings.h"
 #include "src/classes/astandardpaths.h"
 #include "src/classes/asettings.h"
+#include "src/astyle.h"
 #include <QApplication>
 #include <QProcess>
 #include <QSettings>
@@ -58,31 +59,32 @@ int main(int argc, char *argv[])
         }
         ASettings::write(ASettings::Setup::SetupComplete, true);
         DEB << "Wrote setup_commplete?";
-        qApp->quit();
-        QProcess::startDetached(qApp->arguments()[0], qApp->arguments());
+//        qApp->quit();
+//        QProcess::startDetached(qApp->arguments()[0], qApp->arguments());
     }
 
+    AStyle::setup();
     //Theming
-    switch (ASettings::read(ASettings::Main::Theme).toInt()) {
-    case 1:{
-        DEB << "main :: Loading light theme";
-        QFile file(":light.qss");
-        file.open(QFile::ReadOnly | QFile::Text);
-        QTextStream stream(&file);
-        openPilotLog.setStyleSheet(stream.readAll());
-        break;
-    }
-    case 2:{
-        DEB << "Loading dark theme";
-        QFile file(":dark.qss");
-        file.open(QFile::ReadOnly | QFile::Text);
-        QTextStream stream(&file);
-        openPilotLog.setStyleSheet(stream.readAll());
-        break;
-    }
-    default:
-        break;
-    }
+//    switch (ASettings::read(ASettings::Main::Theme).toInt()) {
+//    case 1:{
+//        DEB << "main :: Loading light theme";
+//        QFile file(":light.qss");
+//        file.open(QFile::ReadOnly | QFile::Text);
+//        QTextStream stream(&file);
+//        openPilotLog.setStyleSheet(stream.readAll());
+//        break;
+//    }
+//    case 2:{
+//        DEB << "Loading dark theme";
+//        QFile file(":dark.qss");
+//        file.open(QFile::ReadOnly | QFile::Text);
+//        QTextStream stream(&file);
+//        openPilotLog.setStyleSheet(stream.readAll());
+//        break;
+//    }
+//    default:
+//        break;
+//    }
 
     //sqlite does not deal well with multiple connections, ensure only one instance is running
     ARunGuard guard(QStringLiteral("opl_single_key"));

+ 2 - 0
openPilotLog.pro

@@ -18,6 +18,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
 SOURCES += \
     main.cpp \
     mainwindow.cpp \
+    src/astyle.cpp \
     src/classes/astandardpaths.cpp \
     src/classes/aaircraftentry.cpp \
     src/classes/adownload.cpp \
@@ -48,6 +49,7 @@ SOURCES += \
 
 HEADERS += \
     mainwindow.h \
+    src/astyle.h \
     src/classes/astandardpaths.h \
     src/classes/aaircraftentry.h \
     src/classes/adownload.h \

+ 22 - 0
src/astyle.cpp

@@ -0,0 +1,22 @@
+#include "astyle.h"
+#include <QStyle>
+#include <QStyleFactory>
+#include <QApplication>
+#include "src/testing/adebug.h"
+
+// [G]: Kvantum crashes
+// Are there leaks when style changes?
+void AStyle::setup()
+{
+    QApplication::setStyle(QStyleFactory::create("Windows"));
+}
+
+void AStyle::setStyle(const QString& style)
+{
+    QApplication::setStyle(QStyleFactory::create(style));
+}
+
+void AStyle::setStyleSheet(const QString &qss_file)
+{
+
+}

+ 14 - 0
src/astyle.h

@@ -0,0 +1,14 @@
+#ifndef ASTYLE_H
+#define ASTYLE_H
+#include <QString>
+#include <QFile>
+
+class AStyle
+{
+public:
+    static void setup();
+    static void setStyle(const QString& style);
+    static void setStyleSheet(const QString& qss_file);
+};
+
+#endif // ASTYLE_H

+ 29 - 14
src/gui/widgets/settingswidget.cpp

@@ -18,11 +18,13 @@
 #include "settingswidget.h"
 #include "ui_settingswidget.h"
 #include "src/testing/adebug.h"
-
+#include "src/astyle.h"
 #include "src/classes/asettings.h"
 #include "src/database/adatabase.h"
 #include "src/classes/apilotentry.h"
 
+#include <QStyleFactory>
+
 static const auto FIRSTNAME_VALID = QPair<QString, QRegularExpression> {
     "firstnameLineEdit", QRegularExpression("[a-zA-Z]+")};
 static const auto LASTNAME_VALID = QPair<QString, QRegularExpression> {
@@ -56,6 +58,9 @@ SettingsWidget::SettingsWidget(QWidget *parent) :
     themeGroup->addButton(ui->lightThemeCheckBox, 1);
     themeGroup->addButton(ui->darkThemeCheckBox, 2);
 
+    for(auto & x : QStyleFactory::keys())
+        ui->styleComboBox->addItem(x);
+
     readSettings();
     setupValidators();
 
@@ -63,6 +68,12 @@ SettingsWidget::SettingsWidget(QWidget *parent) :
                      this, &SettingsWidget::onThemeGroup_buttonClicked);
 }
 
+void SettingsWidget::on_styleComboBox_currentTextChanged(const QString& text)
+{
+    DEB << text;
+    AStyle::setStyle(text);
+}
+
 SettingsWidget::~SettingsWidget()
 {
     delete ui;
@@ -268,19 +279,23 @@ void SettingsWidget::on_prefixLineEdit_textChanged(const QString &arg1)
 void SettingsWidget::onThemeGroup_buttonClicked(int theme_id)
 {
     ASettings::write(ASettings::Main::Theme, theme_id);
-
-    QMessageBox::StandardButton reply;
-    reply = QMessageBox::question(this, "Changing Themes",
-                                  "Changing the theme requires restarting the Application.\n\nWould you like to restart now?",
-                                  QMessageBox::Yes | QMessageBox::No);
-    if (reply == QMessageBox::Yes) {
-        qApp->quit();
-        QProcess::startDetached(qApp->arguments()[0], qApp->arguments());
-
-    } else {
-        QMessageBox *info = new QMessageBox(this);
-        info->setText("Theme change will take effect the next time you start the application.");
-        info->exec();
+    switch (ASettings::read(ASettings::Main::Theme).toInt()) {
+    case 1:{
+        DEB << "main :: Loading light theme";
+        QFile file(":light.qss");
+        file.open(QFile::ReadOnly | QFile::Text);
+        QTextStream stream(&file);
+        qApp->setStyleSheet(stream.readAll());
+        break;
+    }
+    case 2:{
+        DEB << "Loading dark theme";
+        QFile file(":dark.qss");
+        file.open(QFile::ReadOnly | QFile::Text);
+        QTextStream stream(&file);
+        qApp->setStyleSheet(stream.readAll());
+        break;
+    }
     }
 }
 void SettingsWidget::on_logbookViewComboBox_currentIndexChanged(int index)

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

@@ -58,6 +58,8 @@ private slots:
     void on_logbookViewComboBox_currentIndexChanged(int index);
     void on_companyLineEdit_editingFinished();
 
+    void on_styleComboBox_currentTextChanged(const QString& index);
+
 private:
     Ui::SettingsWidget *ui;
 

+ 108 - 88
src/gui/widgets/settingswidget.ui

@@ -468,116 +468,142 @@
        <string>Misc</string>
       </attribute>
       <layout class="QGridLayout" name="gridLayout_5">
-       <item row="0" column="1">
-        <widget class="QLabel" name="themeLabel">
+       <item row="3" 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;Changes the theme of the application.&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>Theme</string>
+          <string>Sort Pilots by</string>
          </property>
         </widget>
        </item>
-       <item row="0" column="2">
-        <widget class="QCheckBox" name="systemThemeCheckBox">
+       <item row="5" column="1">
+        <widget class="QLabel" name="acAllowIncompleteLabel">
+         <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;Uses your default system theme.&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>System</string>
+          <string>Allow incomplete Entries </string>
          </property>
         </widget>
        </item>
-       <item row="1" column="2">
-        <widget class="QCheckBox" name="lightThemeCheckBox">
+       <item row="6" column="1">
+        <widget class="QLabel" name="logbookViewLabel">
+         <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;Uses the Breeze light theme.&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 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>Light</string>
+          <string>Logbook Dispay</string>
          </property>
         </widget>
        </item>
-       <item row="2" column="2">
-        <widget class="QCheckBox" name="darkThemeCheckBox">
+       <item row="4" column="1">
+        <widget class="QLabel" name="acSortLabel">
+         <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;Uses the breeze dark theme (night mode)&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 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>Dark</string>
+          <string>Sort Aircraft by</string>
          </property>
         </widget>
        </item>
-       <item row="3" column="0">
-        <spacer name="horizontalSpacer">
-         <property name="orientation">
-          <enum>Qt::Horizontal</enum>
-         </property>
-         <property name="sizeHint" stdset="0">
-          <size>
-           <width>173</width>
-           <height>20</height>
-          </size>
+       <item row="0" column="1">
+        <widget class="QLabel" name="themeLabel">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
          </property>
-        </spacer>
-       </item>
-       <item row="3" column="1">
-        <widget class="QLabel" name="logbookViewLabel">
          <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>
-         </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;Changes the theme of the application.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
          </property>
          <property name="text">
-          <string>Logbook Dispay</string>
+          <string>Theme</string>
          </property>
         </widget>
        </item>
-       <item row="3" column="2">
-        <widget class="QComboBox" name="logbookViewComboBox">
+       <item row="0" column="2">
+        <widget class="QCheckBox" name="systemThemeCheckBox">
          <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;Uses your default system theme.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+         </property>
+         <property name="text">
+          <string>System</string>
          </property>
-         <item>
-          <property name="text">
-           <string>Default</string>
-          </property>
-         </item>
-         <item>
-          <property name="text">
-           <string>EASA Part-FCL</string>
-          </property>
-         </item>
         </widget>
        </item>
-       <item row="3" column="3">
-        <spacer name="horizontalSpacer_2">
-         <property name="orientation">
-          <enum>Qt::Horizontal</enum>
+       <item row="0" column="3">
+        <widget class="QCheckBox" name="lightThemeCheckBox">
+         <property name="toolTip">
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Uses the Breeze light theme.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
          </property>
-         <property name="sizeHint" stdset="0">
-          <size>
-           <width>173</width>
-           <height>20</height>
-          </size>
+         <property name="text">
+          <string>Light</string>
          </property>
-        </spacer>
+        </widget>
        </item>
-       <item row="4" column="1">
-        <widget class="QLabel" name="pilotSortLabel">
+       <item row="0" column="4">
+        <widget class="QCheckBox" name="darkThemeCheckBox">
          <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;Uses the breeze dark theme (night mode)&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 name="text">
+          <string>Dark</string>
+         </property>
+        </widget>
+       </item>
+       <item row="1" 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>Sort Pilots by</string>
+          <string>Style</string>
          </property>
         </widget>
        </item>
-       <item row="4" column="2">
+       <item row="1" column="2">
+        <widget class="QComboBox" name="styleComboBox"/>
+       </item>
+       <item row="3" 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>
@@ -599,20 +625,7 @@
          </item>
         </widget>
        </item>
-       <item row="5" column="1">
-        <widget class="QLabel" name="acSortLabel">
-         <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>
-         </property>
-         <property name="text">
-          <string>Sort Aircraft by</string>
-         </property>
-        </widget>
-       </item>
-       <item row="5" column="2">
+       <item row="4" 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>
@@ -634,29 +647,36 @@
          </item>
         </widget>
        </item>
-       <item row="6" column="1">
-        <widget class="QLabel" name="acAllowIncompleteLabel">
+       <item row="5" 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 name="text">
-          <string>Allow incomplete Entries </string>
-         </property>
+         <item>
+          <property name="text">
+           <string>No</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>Yes</string>
+          </property>
+         </item>
         </widget>
        </item>
        <item row="6" column="2">
-        <widget class="QComboBox" name="acAllowIncompleteComboBox">
+        <widget class="QComboBox" name="logbookViewComboBox">
          <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 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>No</string>
+           <string>Default</string>
           </property>
          </item>
          <item>
           <property name="text">
-           <string>Yes</string>
+           <string>EASA Part-FCL</string>
           </property>
          </item>
         </widget>