openPilotLog
homewidget.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 HOMEWIDGET_H
19 #define HOMEWIDGET_H
20 
21 #include <QWidget>
22 #include <QStackedLayout>
23 #include <QLabel>
24 #include <QLineEdit>
25 #include <QSettings>
26 #include "src/functions/statistics.h"
27 #include "src/database/database.h"
28 #include "src/classes/settings.h"
29 
30 namespace Ui {
31 class HomeWidget;
32 }
33 
42 class HomeWidget : public QWidget
43 {
44  Q_OBJECT
45 
46 public:
47  explicit HomeWidget(QWidget *parent = nullptr);
48  ~HomeWidget();
49 
50 private:
51  Ui::HomeWidget *ui;
52 
53  QList<QLabel*> limitationDisplayLabels;
54  QDate today;
59  int currWarningThreshold;
64  double ftlWarningThreshold;
65 
66  void fillTotals();
67  void fillSelectedCurrencies();
68  void fillCurrencyTakeOffLanding();
69  void fillCurrency(OPL::CurrencyName currency_name, QLabel *display_label);
70  void fillLimitations();
71 
72  enum class Colour {Red, Orange, None};
73  inline void setLabelColour(QLabel* label, Colour colour)
74  {
75  switch (colour) {
76  case Colour::None:
77  label->setStyleSheet(QString());
78  break;
79  case Colour::Red:
80  label->setStyleSheet(QStringLiteral("color: red"));
81  break;
82  case Colour::Orange:
83  label->setStyleSheet(QStringLiteral("color: orange"));
84  break;
85  default:
86  label->setStyleSheet(QString());
87  break;
88  }
89  }
90 
91  inline void hideLabels(QLabel* label1, QLabel* label2) {
92  label1->hide();
93  label2->hide();
94  }
95 
99  const QString userName();
100 
101 public slots:
102  void refresh();
103 
104  void onPilotsDatabaseChanged(const OPL::DbTable table);
105 
106 protected:
110  void changeEvent(QEvent* event) override;
111 };
112 
113 #endif // HOMEWIDGET_H
The HomeWidget is the welcome screen of the application.
Definition: homewidget.h:43
void changeEvent(QEvent *event) override
Handles change events, like updating the UI to new localisation.
Definition: homewidget.cpp:88
CurrencyName
Enumerates the currency names.
Definition: opl.h:127
DbTable
Enumerates the tables in the database.
Definition: opl.h:122