mainwindow.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. #include "mainwindow.h"
  19. #include "ui_mainwindow.h"
  20. #include "src/testing/adebug.h"
  21. #include "src/database/adatabase.h"
  22. #include "src/classes/astyle.h"
  23. MainWindow::MainWindow(QWidget *parent)
  24. : QMainWindow(parent)
  25. , ui(new Ui::MainWindow)
  26. {
  27. ui->setupUi(this);
  28. // Create a spacer for the toolbar to separate left and right parts
  29. auto *spacer = new QWidget();
  30. spacer->setMinimumWidth(1);
  31. spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
  32. // Set up Toolbar
  33. ui->actionHome->setIcon(QIcon(Opl::Assets::ICON_TOOLBAR_HOME));
  34. ui->actionNewFlight->setIcon(QIcon(Opl::Assets::ICON_TOOLBAR_NEW_FLIGHT));
  35. ui->actionLogbook->setIcon(QIcon(Opl::Assets::ICON_TOOLBAR_LOGBOOK));
  36. ui->actionAircraft->setIcon(QIcon(Opl::Assets::ICON_TOOLBAR_AIRCRAFT));
  37. ui->actionPilots->setIcon(QIcon(Opl::Assets::ICON_TOOLBAR_PILOT));
  38. ui->toolBar->insertWidget(ui->actionSettings, spacer); // spacer goes here
  39. ui->actionBackup->setIcon(QIcon(Opl::Assets::ICON_TOOLBAR_BACKUP));
  40. ui->actionSettings->setIcon(QIcon(Opl::Assets::ICON_TOOLBAR_SETTINGS));
  41. ui->actionQuit->setIcon(QIcon(Opl::Assets::ICON_TOOLBAR_QUIT));
  42. ui->toolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
  43. const auto buttons = ui->toolBar->findChildren<QWidget *>();
  44. ui->toolBar->setIconSize(QSize(64, 64));
  45. for (const auto &button : buttons) {
  46. button->setMinimumWidth(128);
  47. }
  48. // Construct Widgets
  49. homeWidget = new HomeWidget(this);
  50. ui->stackedWidget->addWidget(homeWidget);
  51. logbookWidget = new LogbookWidget(this);
  52. ui->stackedWidget->addWidget(logbookWidget);
  53. aircraftWidget = new AircraftWidget(this);
  54. ui->stackedWidget->addWidget(aircraftWidget);
  55. pilotsWidget = new PilotsWidget(this);
  56. ui->stackedWidget->addWidget(pilotsWidget);
  57. backupWidget = new BackupWidget(this);
  58. ui->stackedWidget->addWidget(backupWidget);
  59. settingsWidget = new SettingsWidget(this);
  60. ui->stackedWidget->addWidget(settingsWidget);
  61. debugWidget = new DebugWidget(this);
  62. ui->stackedWidget->addWidget(debugWidget);
  63. connectWidgets();
  64. // Startup Screen (Home Screen)
  65. ui->stackedWidget->setCurrentWidget(homeWidget);
  66. // check database version (Debug)
  67. int db_ver = aDB->dbVersion();
  68. if (db_ver != DATABASE_REVISION) {
  69. DEB << "############## WARNING ##############";
  70. DEB << "Your database is out of date.";
  71. DEB << "Current Revision:\t" << DATABASE_REVISION;
  72. DEB << "You have revision:\t" << db_ver;
  73. DEB << "############## WARNING ##############";
  74. QMessageBox message_box(this); //error box
  75. message_box.setText(tr("Database revision out of date!"));
  76. message_box.exec();
  77. } else {
  78. DEB << "Your database is up to date with the latest revision:" << db_ver;
  79. }
  80. }
  81. MainWindow::~MainWindow()
  82. {
  83. delete ui;
  84. }
  85. void MainWindow::nope()
  86. {
  87. QMessageBox message_box(this); //error box
  88. message_box.setText(tr("This feature is not yet available!"));
  89. message_box.exec();
  90. }
  91. /*!
  92. * \brief Connect the widgets to signals that are emitted when an update of the widegts' contents,
  93. * is required, either because the database has changed (model and view need to be refreshed) or
  94. * because a setting that affects the widgets layout has changed.
  95. */
  96. void MainWindow::connectWidgets()
  97. {
  98. QObject::connect(aDB, &ADatabase::dataBaseUpdated,
  99. homeWidget, &HomeWidget::refresh);
  100. QObject::connect(settingsWidget, &SettingsWidget::settingChanged,
  101. homeWidget, &HomeWidget::refresh);
  102. QObject::connect(aDB, &ADatabase::dataBaseUpdated,
  103. logbookWidget, &LogbookWidget::refresh);
  104. QObject::connect(settingsWidget, &SettingsWidget::settingChanged,
  105. logbookWidget, &LogbookWidget::onLogbookWidget_viewSelectionChanged);
  106. QObject::connect(aDB, &ADatabase::dataBaseUpdated,
  107. aircraftWidget, &AircraftWidget::onAircraftWidget_dataBaseUpdated);
  108. QObject::connect(settingsWidget, &SettingsWidget::settingChanged,
  109. aircraftWidget, &AircraftWidget::onAircraftWidget_settingChanged);
  110. QObject::connect(aDB, &ADatabase::dataBaseUpdated,
  111. pilotsWidget, &PilotsWidget::onPilotsWidget_databaseUpdated);
  112. QObject::connect(settingsWidget, &SettingsWidget::settingChanged,
  113. pilotsWidget, &PilotsWidget::onPilotsWidget_settingChanged);
  114. }
  115. /*
  116. * Slots
  117. */
  118. void MainWindow::on_actionHome_triggered()
  119. {
  120. ui->stackedWidget->setCurrentWidget(homeWidget);
  121. }
  122. void MainWindow::on_actionNewFlight_triggered()
  123. {
  124. NewFlightDialog nf(this);
  125. nf.exec();
  126. }
  127. void MainWindow::on_actionLogbook_triggered()
  128. {
  129. ui->stackedWidget->setCurrentWidget(logbookWidget);
  130. }
  131. void MainWindow::on_actionAircraft_triggered()
  132. {
  133. ui->stackedWidget->setCurrentWidget(aircraftWidget);
  134. }
  135. void MainWindow::on_actionPilots_triggered()
  136. {
  137. ui->stackedWidget->setCurrentWidget(pilotsWidget);
  138. }
  139. void MainWindow::on_actionBackup_triggered()
  140. {
  141. ui->stackedWidget->setCurrentWidget(backupWidget);
  142. }
  143. void MainWindow::on_actionSettings_triggered()
  144. {
  145. ui->stackedWidget->setCurrentWidget(settingsWidget);
  146. }
  147. void MainWindow::on_actionQuit_triggered()
  148. {
  149. QApplication::quit();
  150. }
  151. void MainWindow::on_actionDebug_triggered()
  152. {
  153. ui->stackedWidget->setCurrentWidget(debugWidget);
  154. }
  155. // Debug
  156. // not used at the moment
  157. /*void MainWindow::on_actionNewAircraft_triggered()
  158. {
  159. NewTailDialog nt(QString(), this);
  160. nt.exec();
  161. }
  162. void MainWindow::on_actionNewPilot_triggered()
  163. {
  164. NewPilotDialog np(this);
  165. np.exec();
  166. }*/