mainwindow.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. *openPilot Log - A FOSS Pilot Logbook Application
  3. *Copyright (C) 2020 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 "newflight.h"
  21. #include "editflight.h"
  22. #include "newacft.h"
  23. #include "easaview.h"
  24. #include "dbman.cpp"
  25. #include "calc.h"
  26. #include "homewidget.h"
  27. #include "logbookwidget.h"
  28. #include "settingswidget.h"
  29. #include <QTime>
  30. #include <QSqlDatabase>
  31. #include <QSqlDriver>
  32. #include <QSqlError>
  33. #include <QSqlQuery>
  34. #include <QSqlTableModel>
  35. #include <QTableView>
  36. #include <chrono>
  37. #include <QMessageBox>
  38. #include <QDir>
  39. #include <QFile>
  40. qlonglong SelectedFlightold = -1;
  41. MainWindow::MainWindow(QWidget *parent)
  42. : QMainWindow(parent)
  43. , ui(new Ui::MainWindow)
  44. {
  45. ui->setupUi(this);
  46. // Set up Toolbar
  47. ui->toolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
  48. ui->toolBar->setIconSize(QSize(64,64));
  49. ui->actionLogbook->setIcon(QIcon(":/logbook_icon.png"));
  50. ui->actionHome->setIcon(QIcon(":/home_icon.svg"));
  51. ui->actionSettings->setIcon(QIcon(":/settings_icon.svg"));
  52. ui->actionQuit->setIcon(QIcon(":/quit_icon.svg"));
  53. ui->actionNewFlight->setIcon(QIcon(":/new_flight_icon.jpg"));
  54. // Adds space between toolbar items and actionSetting item
  55. auto *spacer = new QWidget();
  56. spacer->setMinimumWidth(10);
  57. spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
  58. ui->toolBar->insertWidget(ui->actionSettings,spacer);
  59. // create and show homeWidget
  60. auto hw = new homeWidget(this);
  61. ui->stackedWidget->addWidget(hw);
  62. ui->stackedWidget->setCurrentWidget(hw);
  63. }
  64. MainWindow::~MainWindow()
  65. {
  66. delete ui;
  67. }
  68. /*
  69. * Functions
  70. */
  71. void MainWindow::nope()
  72. {
  73. QMessageBox nope(this); //error box
  74. nope.setText("This feature is not yet available!");
  75. nope.exec();
  76. }
  77. /*
  78. * Slots
  79. */
  80. void MainWindow::on_actionQuit_triggered()
  81. {
  82. QApplication::quit();
  83. }
  84. void MainWindow::on_actionHome_triggered()
  85. {
  86. auto hw = new homeWidget(this);
  87. ui->stackedWidget->addWidget(hw);
  88. ui->stackedWidget->setCurrentWidget(hw);
  89. }
  90. void MainWindow::on_actionLogbook_triggered()
  91. {
  92. auto lw = new logbookWidget(this);
  93. ui->stackedWidget->addWidget(lw);
  94. ui->stackedWidget->setCurrentWidget(lw);
  95. }
  96. void MainWindow::on_actionSettings_triggered()
  97. {
  98. //nope();
  99. auto sw = new settingsWidget(this);
  100. ui->stackedWidget->addWidget(sw);
  101. ui->stackedWidget->setCurrentWidget(sw);
  102. }
  103. void MainWindow::on_actionNewFlight_triggered()
  104. {
  105. auto locationList = dbAirport::retreiveIataIcaoList();
  106. auto registrationList = dbAircraft::retreiveRegistrationList();
  107. QStringList pilotNameList;
  108. NewFlight nf(this, locationList, registrationList, pilotNameList);
  109. nf.exec();
  110. }