mainwindow.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 MAINWINDOW_H
  19. #define MAINWINDOW_H
  20. #include <QMainWindow>
  21. #include <QTime>
  22. #include <QSqlTableModel>
  23. #include <QTableView>
  24. #include <chrono>
  25. #include <QMessageBox>
  26. #include <QDir>
  27. #include <QFile>
  28. #include <QKeyEvent>
  29. #include <QToolBar>
  30. #include "src/gui/widgets/homewidget.h"
  31. #include "src/gui/widgets/settingswidget.h"
  32. #include "src/gui/widgets/logbookwidget.h"
  33. #include "src/gui/widgets/aircraftwidget.h"
  34. #include "src/gui/widgets/backupwidget.h"
  35. #include "src/gui/widgets/pilotswidget.h"
  36. #include "src/gui/widgets/debugwidget.h"
  37. #include "src/gui/dialogues/newtaildialog.h"
  38. #include "src/gui/dialogues/newpilotdialog.h"
  39. #include "src/gui/dialogues/newflightdialog.h"
  40. #include "src/classes/arunguard.h"
  41. #include "src/classes/acompletiondata.h"
  42. #include "src/testing/atimer.h"
  43. #include "src/classes/astyle.h"
  44. enum Style {Light, Dark};
  45. QT_BEGIN_NAMESPACE
  46. namespace Ui {
  47. class MainWindow;
  48. }
  49. QT_END_NAMESPACE
  50. /*!
  51. * \brief The MainWindow contains a QStackedWidget and a QToolBar as the main User Interface.
  52. * \details The Tool bar contains shortcuts to the different widgets, which are on selection set active on the stacked main widget.
  53. * For a detailed description of what each widget does, please refer to the documentation for each widget. This is only a short synopsis:
  54. *
  55. * # HomeWidget
  56. *
  57. * The home widget displays the total amount of hours for all logged flights, seperated into different categories. It also enables keeping track
  58. * of currencies and license expiries
  59. *
  60. * # New Flight
  61. *
  62. * Opens a NewFlightDialog which can be used to submit a new flight to the database.
  63. *
  64. * # Logboook
  65. *
  66. * Shows a view of the logbook table in a QTableView and enables editing the entries by spawning a child NewFlightDialog with the details for a selected flight.
  67. *
  68. * # Aircraft
  69. *
  70. * Shows a view of the tails table in a QTableView and enables editing the entries by spawning a child NewTailDialog with the details for a selected tail.
  71. *
  72. * # Pilots
  73. *
  74. * Shows a view of the pilots table in a QTableView and enables editing the entries by spawning a child NewPilotDialog with the details for a selected pilot.
  75. *
  76. * # Backup
  77. *
  78. * Enables backing up and restoring the database.
  79. *
  80. * # Settings
  81. *
  82. * Enables changing application settings
  83. */
  84. class MainWindow : public QMainWindow
  85. {
  86. Q_OBJECT
  87. public:
  88. MainWindow(QWidget *parent = nullptr);
  89. ~MainWindow();
  90. public slots:
  91. void onStyleChanged(SettingsWidget::SettingSignal signal){
  92. if (signal == SettingsWidget::MainWindow)
  93. setActionIcons(AStyle::getStyleType());
  94. }
  95. private slots:
  96. void on_actionHome_triggered();
  97. void on_actionNewFlight_triggered();
  98. void on_actionLogbook_triggered();
  99. void on_actionAircraft_triggered();
  100. void on_actionPilots_triggered();
  101. void on_actionBackup_triggered();
  102. void on_actionSettings_triggered();
  103. void on_actionQuit_triggered();
  104. void on_actionDebug_triggered();
  105. void on_actionNewSim_triggered();
  106. private:
  107. Ui::MainWindow *ui;
  108. HomeWidget* homeWidget;
  109. LogbookWidget* logbookWidget;
  110. AircraftWidget* aircraftWidget;
  111. PilotsWidget* pilotsWidget;
  112. BackupWidget* backupWidget;
  113. SettingsWidget* settingsWidget;
  114. DebugWidget* debugWidget;
  115. // Completion Data for QCompleters and Mapping
  116. ACompletionData completionData;
  117. void setupToolbar();
  118. void setActionIcons(StyleType style = StyleType::Light);
  119. void nope();
  120. void connectWidgets();
  121. // Prompts the user to fix a broken database or import a backup
  122. void onDatabaseInvalid();
  123. //
  124. void doDebugStuff();
  125. protected:
  126. /*!
  127. * \brief Shows the debug widget by pressing <ctrl + t>
  128. * <Shift+Enter for a quick and dirty debug>
  129. */
  130. void keyPressEvent(QKeyEvent* keyEvent) override
  131. {
  132. if(keyEvent->type() == QKeyEvent::KeyPress) {
  133. if(keyEvent->matches(QKeySequence::AddTab)) {
  134. on_actionDebug_triggered();
  135. } else if (keyEvent->matches(QKeySequence::InsertLineSeparator)) {
  136. doDebugStuff();
  137. }
  138. }
  139. }
  140. /*!
  141. * \brief resizeEvent Resize the Toolbar's icon size to match the window height
  142. */
  143. void resizeEvent(QResizeEvent *event) override
  144. {
  145. LOG << "SIZE:" << this->size();
  146. int icon_size;
  147. if (this->height() < 760)
  148. icon_size = (this->height() / 16);
  149. else
  150. icon_size = (this->height() / 14);
  151. auto tool_bar = this->findChild<QToolBar*>();
  152. tool_bar->setIconSize(QSize(icon_size, icon_size));
  153. }
  154. };
  155. #endif // MAINWINDOW_H