mainwindow.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. MainWindow::MainWindow(QWidget *parent)
  21. : QMainWindow(parent)
  22. , ui(new Ui::MainWindow)
  23. {
  24. ui->setupUi(this);
  25. Db::connect();
  26. // Set up Toolbar
  27. ui->toolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
  28. ui->toolBar->setIconSize(QSize(64, 64));
  29. auto buttons = ui->toolBar->findChildren<QWidget *>();
  30. for (const auto &button : buttons) {
  31. button->setMinimumWidth(128);
  32. }
  33. ui->actionLogbook->setIcon(QIcon(":/icons/ionicon-icons/book-outline.png"));
  34. ui->actionHome->setIcon(QIcon(":/icons/ionicon-icons/home-outline.png"));
  35. ui->actionSettings->setIcon(QIcon(":/icons/ionicon-icons/settings-outline.png"));
  36. ui->actionQuit->setIcon(QIcon(":/icons/ionicon-icons/power-outline.png"));
  37. ui->actionAircraft->setIcon(QIcon(":/icons/ionicon-icons/airplane-outline.png"));
  38. ui->actionPilots->setIcon(QIcon(":/icons/ionicon-icons/settings-outline.png"));
  39. // Adds space between toolbar items
  40. auto *spacer = new QWidget();
  41. spacer->setMinimumWidth(10);
  42. spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
  43. ui->toolBar->insertWidget(ui->actionSettings, spacer);
  44. // create and show HomeWidget
  45. auto hw = new HomeWidget(this);
  46. ui->stackedWidget->addWidget(hw);
  47. ui->stackedWidget->setCurrentWidget(hw);
  48. }
  49. MainWindow::~MainWindow()
  50. {
  51. delete ui;
  52. }
  53. void MainWindow::nope()
  54. {
  55. QMessageBox nope(this); //error box
  56. nope.setText("This feature is not yet available!");
  57. nope.exec();
  58. }
  59. /*
  60. * Slots
  61. */
  62. void MainWindow::on_actionQuit_triggered()
  63. {
  64. QApplication::quit();
  65. }
  66. void MainWindow::on_actionHome_triggered()
  67. {
  68. auto hw = new HomeWidget(this);
  69. ui->stackedWidget->addWidget(hw);
  70. ui->stackedWidget->setCurrentWidget(hw);
  71. }
  72. void MainWindow::on_actionLogbook_triggered()
  73. {
  74. auto lw = new LogbookWidget(this);
  75. ui->stackedWidget->addWidget(lw);
  76. ui->stackedWidget->setCurrentWidget(lw);
  77. }
  78. void MainWindow::on_actionSettings_triggered()
  79. {
  80. //nope();
  81. auto sw = new SettingsWidget(this);
  82. ui->stackedWidget->addWidget(sw);
  83. ui->stackedWidget->setCurrentWidget(sw);
  84. }
  85. void MainWindow::on_actionNewFlight_triggered()
  86. {
  87. /*
  88. QVector<QStringList> lineEdit_completionLists = {
  89. QStringList(),//empty dummy list for TimeLineEdits
  90. dbAirport::retreiveIataIcaoList(),
  91. dbAircraft::retreiveRegistrationList(),
  92. dbPilots::retreivePilotList()
  93. };
  94. NewFlight nf(this, lineEdit_completionLists);
  95. nf.exec();
  96. */
  97. }
  98. void MainWindow::on_actionAircraft_triggered()
  99. {
  100. auto aw = new AircraftWidget(this);
  101. ui->stackedWidget->addWidget(aw);
  102. ui->stackedWidget->setCurrentWidget(aw);
  103. }
  104. void MainWindow::on_actionNewAircraft_triggered()
  105. {
  106. auto nt = new NewTail(QString(), Db::createNew, this);
  107. nt->show();
  108. }
  109. void MainWindow::on_actionPilots_triggered()
  110. {
  111. auto pw = new PilotsWidget(this);
  112. ui->stackedWidget->addWidget(pw);
  113. ui->stackedWidget->setCurrentWidget(pw);
  114. }
  115. void MainWindow::on_actionNewPilot_triggered()
  116. {
  117. auto np = new NewPilot(Db::createNew, this);
  118. np->show();
  119. }