Kaynağa Gözat

Added option to select custom fonts

Added an option to not only select a style, but also a custom font.
Felix Turo 4 yıl önce
ebeveyn
işleme
d12ecf727b

+ 22 - 13
mainwindow.cpp

@@ -25,15 +25,9 @@ MainWindow::MainWindow(QWidget *parent)
     , ui(new Ui::MainWindow)
 {
     ui->setupUi(this);
+    readSettings();
 
     // Set up Toolbar
-    ui->toolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
-    ui->toolBar->setIconSize(QSize(64, 64));
-    auto buttons = ui->toolBar->findChildren<QWidget *>();
-    for (const auto &button : buttons) {
-        button->setMinimumWidth(128);
-    }
-
     ui->actionHome->setIcon(QIcon(":/icons/ionicon-icons/home-outline.png"));
     ui->actionNewFlight->setIcon(QIcon(":/icons/ionicon-icons/airplane-outline.png"));
     ui->actionLogbook->setIcon(QIcon(":/icons/ionicon-icons/book-outline.png"));
@@ -42,15 +36,21 @@ MainWindow::MainWindow(QWidget *parent)
     ui->actionDebug->setIcon(QIcon(":/icons/ionicon-icons/settings-outline.png"));
     ui->actionSettings->setIcon(QIcon(":/icons/ionicon-icons/settings-outline.png"));
     ui->actionQuit->setIcon(QIcon(":/icons/ionicon-icons/power-outline.png"));
+    ui->toolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
+
+    const auto buttons = ui->toolBar->findChildren<QWidget *>();
+    ui->toolBar->setIconSize(QSize(64, 64));
+    for (const auto &button : buttons) {
+        button->setMinimumWidth(128);
+    }
 
-    // Adds space between toolbar items
+    // Add spacer
     auto *spacer = new QWidget();
-    spacer->setMinimumWidth(10);
+    spacer->setMinimumWidth(1);
     spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
+    spacer->setObjectName("spacer");
     ui->toolBar->insertWidget(ui->actionDebug, spacer);
 
-
-    DEB << "Construction MainWindow Widgets\n";
     // Construct Widgets
     homeWidget = new HomeWidget(this);
     ui->stackedWidget->addWidget(homeWidget);
@@ -102,7 +102,6 @@ void MainWindow::nope()
     message_box.exec();
 }
 
-
 /*
  * Slots
  */
@@ -139,6 +138,17 @@ void MainWindow::connectWidgets()
     QObject::connect(settingsWidget, &SettingsWidget::viewSelectionChanged,
                      logbookWidget, &LogbookWidget::onLogbookWidget_viewSelectionChanged);
 }
+#include <QFontDatabase>
+void MainWindow::readSettings()
+{
+    DEB << "Use system font?" << ASettings::read(ASettings::Main::UseSystemFont).toBool();
+    if (!ASettings::read(ASettings::Main::UseSystemFont).toBool()) {
+        QFont font(ASettings::read(ASettings::Main::Font).toString());
+        font.setPointSize(ASettings::read(ASettings::Main::FontSize).toUInt());
+        qApp->setFont(font);
+        DEB << "Font set:" << font;
+    }
+}
 
 void MainWindow::on_actionSettings_triggered()
 {
@@ -159,7 +169,6 @@ void MainWindow::on_actionNewFlight_triggered()
 {
     NewFlightDialog nf(this);
     nf.exec();
-
 }
 
 void MainWindow::on_actionNewAircraft_triggered()

+ 2 - 6
mainwindow.h

@@ -85,7 +85,7 @@ private:
 
     SettingsWidget* settingsWidget;
 
-    AircraftWidget* aircraftWidget ;
+    AircraftWidget* aircraftWidget;
 
     PilotsWidget* pilotsWidget;
 
@@ -93,11 +93,7 @@ private:
 
     void connectWidgets();
 
-
-
-
-
-
+    void readSettings();
 
 };
 #endif // MAINWINDOW_H

+ 35 - 2
mainwindow.ui

@@ -6,13 +6,28 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>1920</width>
-    <height>1080</height>
+    <width>1024</width>
+    <height>768</height>
    </rect>
   </property>
+  <property name="sizePolicy">
+   <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+    <horstretch>0</horstretch>
+    <verstretch>0</verstretch>
+   </sizepolicy>
+  </property>
+  <property name="maximumSize">
+   <size>
+    <width>16777215</width>
+    <height>16777215</height>
+   </size>
+  </property>
   <property name="windowTitle">
    <string>openPilotLog v0.6</string>
   </property>
+  <property name="toolButtonStyle">
+   <enum>Qt::ToolButtonTextUnderIcon</enum>
+  </property>
   <widget class="QWidget" name="centralwidget">
    <layout class="QGridLayout" name="gridLayout">
     <item row="0" column="0">
@@ -26,9 +41,27 @@
   </widget>
   <widget class="QStatusBar" name="statusbar"/>
   <widget class="QToolBar" name="toolBar">
+   <property name="sizePolicy">
+    <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+     <horstretch>0</horstretch>
+     <verstretch>0</verstretch>
+    </sizepolicy>
+   </property>
    <property name="windowTitle">
     <string>toolBar</string>
    </property>
+   <property name="iconSize">
+    <size>
+     <width>12</width>
+     <height>12</height>
+    </size>
+   </property>
+   <property name="toolButtonStyle">
+    <enum>Qt::ToolButtonTextUnderIcon</enum>
+   </property>
+   <property name="floatable">
+    <bool>false</bool>
+   </property>
    <attribute name="toolBarArea">
     <enum>TopToolBarArea</enum>
    </attribute>

+ 3 - 0
src/classes/asettings.cpp

@@ -21,6 +21,9 @@
 
 QMap<ASettings::Main, QString> ASettings::mainMap = {
     {Main::Style,                       QStringLiteral("style")},
+    {Main::Font,                        QStringLiteral("font")},
+    {Main::FontSize,                    QStringLiteral("fontSize")},
+    {Main::UseSystemFont,               QStringLiteral("useSystemFont")},
 };
 
 QMap<ASettings::LogBook, QString> ASettings::logBookMap = {

+ 3 - 1
src/classes/asettings.h

@@ -32,7 +32,9 @@ public:
 
     enum class Main {
         Style,
-        StyleSheet,
+        Font,
+        FontSize,
+        UseSystemFont,
     };
 
     enum class LogBook {

+ 51 - 3
src/gui/widgets/settingswidget.cpp

@@ -24,8 +24,6 @@
 #include "src/classes/apilotentry.h"
 #include "src/oplconstants.h"
 
-#include <QStyleFactory>
-
 static const auto FIRSTNAME_VALID = QPair<QString, QRegularExpression> {
     QStringLiteral("firstnameLineEdit"), QRegularExpression("[a-zA-Z]+")};
 static const auto LASTNAME_VALID = QPair<QString, QRegularExpression> {
@@ -116,6 +114,13 @@ void SettingsWidget::readSettings()
     ui->pilotSortComboBox->setCurrentIndex(ASettings::read(ASettings::UserData::PilSortColumn).toInt());
     ui->acAllowIncompleteComboBox->setCurrentIndex(ASettings::read(ASettings::UserData::AcAllowIncomplete).toInt());
     ui->styleComboBox->setCurrentText(ASettings::read(ASettings::Main::Style).toString());
+    {
+        const QSignalBlocker font_blocker1(ui->fontSpinBox);
+        const QSignalBlocker font_blocker2(ui->fontComboBox);
+        ui->fontSpinBox->setValue(ASettings::read(ASettings::Main::FontSize).toUInt());
+        ui->fontComboBox->setCurrentFont(QFont(ASettings::read(ASettings::Main::Font).toString()));
+    }
+    ui->fontCheckBox->setChecked(ASettings::read(ASettings::Main::UseSystemFont).toBool());
 }
 
 void SettingsWidget::setupValidators()
@@ -129,7 +134,6 @@ void SettingsWidget::setupValidators()
         }else{
             DEB << "Error: Line Edit not found: "<< pair.first << " - skipping.";
         }
-
     }
 }
 
@@ -357,3 +361,47 @@ void SettingsWidget::on_styleComboBox_currentTextChanged(const QString& new_styl
         }
     }
 }
+
+void SettingsWidget::on_fontComboBox_currentFontChanged(const QFont &f)
+{
+    qApp->setFont(f);
+    ASettings::write(ASettings::Main::Font, f.toString());
+}
+
+void SettingsWidget::on_fontSpinBox_valueChanged(int arg1)
+{
+    QFont f = qApp->font();
+    f.setPointSize(arg1);
+    qApp->setFont(f);
+    ASettings::write(ASettings::Main::FontSize, arg1);
+}
+
+void SettingsWidget::on_fontCheckBox_stateChanged(int arg1)
+{
+    switch (arg1) {
+    case Qt::Unchecked:
+    {
+        ui->fontComboBox->setEnabled(true);
+        ui->fontSpinBox->setEnabled(true);
+        ASettings::write(ASettings::Main::UseSystemFont, false);
+        QFont font(ui->fontComboBox->currentFont());
+        font.setPointSize(ui->fontSpinBox->value());
+        qApp->setFont(font);
+        break;
+    }
+    case Qt::Checked:
+    {
+        ui->fontComboBox->setEnabled(false);
+        ui->fontSpinBox->setEnabled(false);
+        ASettings::write(ASettings::Main::UseSystemFont, true);
+        QMessageBox message_box(this);
+        message_box.setText(tr("The application will be restarted for this change to take effect."));
+        message_box.exec();
+        qApp->quit();
+        QProcess::startDetached(qApp->arguments()[0], qApp->arguments());
+    }
+        break;
+    default:
+        break;
+    }
+}

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

@@ -24,6 +24,7 @@
 #include <QMessageBox>
 #include <QProcess>
 #include <QDebug>
+#include <QFontDialog>
 
 namespace Ui {
 class SettingsWidget;
@@ -59,6 +60,14 @@ private slots:
     void on_companyLineEdit_editingFinished();
     void on_styleComboBox_currentTextChanged(const QString& new_style_setting);
 
+    //void on_fontPushButton_clicked();
+
+    void on_fontComboBox_currentFontChanged(const QFont &f);
+
+    void on_fontSpinBox_valueChanged(int arg1);
+
+    void on_fontCheckBox_stateChanged(int arg1);
+
 private:
     Ui::SettingsWidget *ui;
 

+ 98 - 52
src/gui/widgets/settingswidget.ui

@@ -361,56 +361,70 @@
       <attribute name="title">
        <string>Misc</string>
       </attribute>
-      <layout class="QGridLayout" name="gridLayout_5">
-       <item row="5" column="1">
-        <widget class="QLabel" name="logbookViewLabel">
+      <layout class="QGridLayout" name="gridLayout_8">
+       <item row="0" column="0">
+        <widget class="QLabel" name="styleLabel">
          <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 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 name="text">
+          <string>Style</string>
          </property>
+        </widget>
+       </item>
+       <item row="0" column="2">
+        <widget class="QComboBox" name="styleComboBox"/>
+       </item>
+       <item row="1" column="0">
+        <widget class="QLabel" name="fontLabel">
          <property name="text">
-          <string>Logbook Dispay</string>
+          <string>Font</string>
          </property>
         </widget>
        </item>
-       <item row="4" column="1">
-        <widget class="QLabel" name="acAllowIncompleteLabel">
-         <property name="sizePolicy">
-          <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
-           <horstretch>0</horstretch>
-           <verstretch>0</verstretch>
-          </sizepolicy>
+       <item row="1" column="1">
+        <widget class="QCheckBox" name="fontCheckBox">
+         <property name="text">
+          <string>Use System Font</string>
          </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>
+         <property name="checked">
+          <bool>true</bool>
          </property>
-         <property name="text">
-          <string>Allow incomplete Entries </string>
+        </widget>
+       </item>
+       <item row="1" column="2">
+        <widget class="QFontComboBox" name="fontComboBox">
+         <property name="enabled">
+          <bool>false</bool>
          </property>
         </widget>
        </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>
+       <item row="1" column="3">
+        <widget class="QSpinBox" name="fontSpinBox">
+         <property name="enabled">
+          <bool>false</bool>
          </property>
-         <property name="text">
-          <string>Style</string>
+         <property name="maximumSize">
+          <size>
+           <width>80</width>
+           <height>16777215</height>
+          </size>
+         </property>
+         <property name="minimum">
+          <number>8</number>
+         </property>
+         <property name="maximum">
+          <number>18</number>
+         </property>
+         <property name="value">
+          <number>10</number>
          </property>
         </widget>
        </item>
-       <item row="2" column="1">
+       <item row="2" column="0">
         <widget class="QLabel" name="pilotSortLabel">
          <property name="sizePolicy">
           <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
@@ -429,7 +443,29 @@
          </property>
         </widget>
        </item>
-       <item row="3" column="1">
+       <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="3" column="0">
         <widget class="QLabel" name="acSortLabel">
          <property name="sizePolicy">
           <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
@@ -470,31 +506,22 @@
          </item>
         </widget>
        </item>
-       <item row="2" column="2">
-        <widget class="QComboBox" name="pilotSortComboBox">
+       <item row="4" column="0" colspan="2">
+        <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;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 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>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="4" column="2">
         <widget class="QComboBox" name="acAllowIncompleteComboBox">
          <property name="toolTip">
@@ -512,6 +539,25 @@
          </item>
         </widget>
        </item>
+       <item row="5" column="0">
+        <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;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>Logbook Dispay</string>
+         </property>
+        </widget>
+       </item>
        <item row="5" column="2">
         <widget class="QComboBox" name="logbookViewComboBox">
          <property name="toolTip">