settingswidget.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 "settingswidget.h"
  19. #include "ui_settingswidget.h"
  20. #include "dbman.cpp"
  21. #include <QButtonGroup>
  22. #include <QRegExp>
  23. #include <QValidator>
  24. #include <QMessageBox>
  25. #include <QDebug>
  26. settingsWidget::settingsWidget(QWidget *parent) :
  27. QWidget(parent),
  28. ui(new Ui::settingsWidget)
  29. {
  30. ui->setupUi(this);
  31. /*
  32. * General Tab
  33. */
  34. auto *themeGroup = new QButtonGroup;
  35. themeGroup->addButton(ui->systemThemeCheckBox, 0);
  36. themeGroup->addButton(ui->lightThemeCheckBox, 1);
  37. themeGroup->addButton(ui->darkThemeCheckBox, 2);
  38. connect(themeGroup, SIGNAL(buttonClicked(int)), this, SLOT(themeGroup_toggled(int)));
  39. switch (dbSettings::retreiveSetting(10).toInt()) {
  40. case 0:
  41. qDebug() << "System Theme";
  42. ui->systemThemeCheckBox->setChecked(true);
  43. break;
  44. case 1:
  45. qDebug() << "Light Theme";
  46. ui->lightThemeCheckBox->setChecked(true);
  47. break;
  48. case 2:
  49. qDebug() << "Dark Theme";
  50. ui->darkThemeCheckBox->setChecked(true);
  51. }
  52. /*
  53. * Flight Logging Tab
  54. */
  55. QString storedPrefix = dbSettings::retreiveSetting(50);
  56. if (storedPrefix.length() != 0){
  57. ui->flightNumberPrefixLineEdit->setText(storedPrefix);
  58. }
  59. QRegExp flightNumberPrefix_rx("[a-zA-Z0-9]?[a-zA-Z0-9]?[a-zA-Z0-9]"); // allow max 3 letters (upper and lower) and numbers
  60. QValidator *flightNumberPrefixValidator = new QRegExpValidator(flightNumberPrefix_rx, this);
  61. ui->flightNumberPrefixLineEdit->setValidator(flightNumberPrefixValidator);
  62. }
  63. settingsWidget::~settingsWidget()
  64. {
  65. delete ui;
  66. }
  67. /*
  68. * Slots
  69. */
  70. void settingsWidget::on_flightNumberPrefixLineEdit_textEdited(const QString &arg1)
  71. {
  72. dbSettings::storeSetting(50, arg1);
  73. }
  74. void settingsWidget::themeGroup_toggled(int id)
  75. {
  76. dbSettings::storeSetting(10,QString::number(id));
  77. QMessageBox *info = new QMessageBox(this);
  78. info->setText("Theme change will take effect next time you start the application.");
  79. info->exec();
  80. }