mainwindow.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. *openPilotLog - A FOSS Pilot Logbook Application
  3. *Copyright (C) 2020-2023 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/logbooktableeditwidget.h>
  31. #include "src/gui/widgets/homewidget.h"
  32. #include "src/gui/widgets/settingswidget.h"
  33. #include "src/gui/widgets/logbookwidget.h"
  34. #include "src/gui/widgets/tableeditwidget.h"
  35. #include "src/gui/widgets/debugwidget.h"
  36. #include "src/classes/style.h"
  37. QT_BEGIN_NAMESPACE
  38. namespace Ui {
  39. class MainWindow;
  40. }
  41. QT_END_NAMESPACE
  42. /*!
  43. * \brief The MainWindow contains a QStackedWidget and a QToolBar as the main User Interface.
  44. * \details The Tool bar contains shortcuts to the different widgets, which are on selection set active on the stacked main widget.
  45. * For a detailed description of what each widget does, please refer to the documentation for each widget. This is only a short synopsis:
  46. *
  47. * ## HomeWidget
  48. *
  49. * The home widget displays the total amount of hours for all logged flights, seperated into different categories. It also enables keeping track
  50. * of currencies and license expiries
  51. *
  52. * ## New Flight
  53. *
  54. * Opens a NewFlightDialog which can be used to submit a new flight to the database.
  55. *
  56. * ## Logboook
  57. *
  58. * 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.
  59. *
  60. * ## Aircraft
  61. *
  62. * 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.
  63. *
  64. * ## Pilots
  65. *
  66. * 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.
  67. *
  68. * ## Airports
  69. *
  70. * Enables viewing and editing the airports database
  71. *
  72. * ## Settings
  73. *
  74. * Enables changing application settings
  75. */
  76. class MainWindow : public QMainWindow
  77. {
  78. Q_OBJECT
  79. public:
  80. MainWindow(QWidget *parent = nullptr);
  81. ~MainWindow();
  82. public slots:
  83. void onStyleChanged(SettingsWidget::SettingSignal signal){
  84. if (signal == SettingsWidget::MainWindow)
  85. setActionIcons(OPL::Style::getStyleType());
  86. }
  87. private slots:
  88. void on_actionHome_triggered();
  89. void on_actionNewFlight_triggered();
  90. void on_actionLogbook_triggered();
  91. void on_actionAircraft_triggered();
  92. void on_actionPilots_triggered();
  93. void on_actionAirports_triggered();
  94. void on_actionSettings_triggered();
  95. void on_actionQuit_triggered();
  96. void on_actionDebug_triggered();
  97. void on_actionNewSim_triggered();
  98. private:
  99. Ui::MainWindow *ui;
  100. HomeWidget* homeWidget;
  101. LogbookTableEditWidget* logbookWidget;
  102. TableEditWidget* tailsWidget;
  103. TableEditWidget* pilotsWidget;
  104. TableEditWidget* airportWidget;
  105. SettingsWidget* settingsWidget;
  106. DebugWidget* debugWidget;
  107. bool airportDbIsDirty = false;
  108. void init();
  109. void setupToolbar();
  110. void initialiseWidgets();
  111. void connectDatabase();
  112. void setActionIcons(OPL::Style::StyleType style = OPL::Style::StyleType::Light);
  113. void nope();
  114. void connectWidgets();
  115. // Prompts the user to fix a broken database or import a backup
  116. void onDatabaseInvalid();
  117. //
  118. void doDebugStuff();
  119. protected:
  120. /*!
  121. * \brief Shows the debug widget by pressing <ctrl + t>
  122. * <Shift+Enter for a quick and dirty debug>
  123. */
  124. void keyPressEvent(QKeyEvent* keyEvent) override
  125. {
  126. if(keyEvent->type() == QKeyEvent::KeyPress) {
  127. if(keyEvent->matches(QKeySequence::AddTab)) {
  128. on_actionDebug_triggered();
  129. } else if (keyEvent->matches(QKeySequence::InsertLineSeparator)) {
  130. doDebugStuff();
  131. }
  132. }
  133. }
  134. /*!
  135. * \brief resizeEvent Resize the Toolbar's icon size to match the window height
  136. */
  137. void resizeEvent(QResizeEvent *event) override
  138. {
  139. //DEB << "SIZE:" << this->size();
  140. int icon_size;
  141. if (this->height() < 760)
  142. icon_size = (this->height() / 16);
  143. else
  144. icon_size = (this->height() / 14);
  145. auto tool_bar = this->findChild<QToolBar*>();
  146. tool_bar->setIconSize(QSize(icon_size, icon_size));
  147. event->accept();
  148. }
  149. //void closeEvent(QCloseEvent *event) override; //TODO check and prompt for creation of backup?
  150. };
  151. #endif // MAINWINDOW_H