homewidget.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. #include <QWidget>
  21. #include <QStackedLayout>
  22. #include <QLabel>
  23. #include <QLineEdit>
  24. #include <QSettings>
  25. #include "src/functions/statistics.h"
  26. #include "src/database/database.h"
  27. #include "src/classes/settings.h"
  28. namespace Ui {
  29. class HomeWidget;
  30. }
  31. /*!
  32. * \brief The HomeWidget is the welcome screen of the application.
  33. * \details The HomeWidget shows total flight times and a user-configurable set of currencies
  34. * (expiry dates for licenses, ratings, medicals,...). Most data is provided by the AStat class
  35. * and the ACurrencyEntry class. Notifications are provided by means of pop-up warnings on application
  36. * start via QMessageBox and the INFO/WARN interfaces, as well as by colouring the labels according
  37. * to the warning level (orange/red).
  38. */
  39. class HomeWidget : public QWidget
  40. {
  41. Q_OBJECT
  42. public:
  43. explicit HomeWidget(QWidget *parent = nullptr);
  44. ~HomeWidget();
  45. private:
  46. Ui::HomeWidget *ui;
  47. QList<QLabel*> limitationDisplayLabels;
  48. QDate today;
  49. /*!
  50. * \brief currWarningThreshold - Retreived from Settings::UserData::CurrWarningThreshold, the number
  51. * of days before expiry that the user gets notified about impending expiries.
  52. */
  53. int currWarningThreshold;
  54. /*!
  55. * \brief ftlWarningThreshold - Retreived from Settings::UserData::FtlWarningThreshold, the percentage
  56. * of how close the user has to be to reaching a Flight Time Limitation before getting notified.
  57. */
  58. double ftlWarningThreshold;
  59. void fillTotals();
  60. void fillSelectedCurrencies();
  61. void fillCurrencyTakeOffLanding();
  62. void fillCurrency(OPL::CurrencyName currency_name, QLabel *display_label);
  63. void fillLimitations();
  64. enum class Colour {Red, Orange, None};
  65. inline void setLabelColour(QLabel* label, Colour colour)
  66. {
  67. switch (colour) {
  68. case Colour::None:
  69. label->setStyleSheet(QString());
  70. break;
  71. case Colour::Red:
  72. label->setStyleSheet(QStringLiteral("color: red"));
  73. break;
  74. case Colour::Orange:
  75. label->setStyleSheet(QStringLiteral("color: orange"));
  76. break;
  77. default:
  78. label->setStyleSheet(QString());
  79. break;
  80. }
  81. }
  82. inline void hideLabels(QLabel* label1, QLabel* label2) {
  83. label1->hide();
  84. label2->hide();
  85. }
  86. /*!
  87. * \brief Retreives the users first name from the database.
  88. */
  89. const QString userName();
  90. public slots:
  91. void refresh();
  92. void onPilotsDatabaseChanged(const OPL::DbTable table);
  93. protected:
  94. /*!
  95. * \brief Handles change events, like updating the UI to new localisation
  96. */
  97. void changeEvent(QEvent* event) override;
  98. };
  99. #endif // HOMEWIDGET_H