settingswidget.cpp 2.6 KB

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