homewidget.h 3.3 KB

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