settingswidget.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. }
  75. void settingsWidget::on_aboutPushButton_clicked()
  76. {
  77. auto mb = new QMessageBox(this);
  78. QString SQLITE_VERSION = dbSettings::sqliteversion();
  79. QString text = QMessageBox::tr(
  80. "<h3><center>About openPilotLog</center></h3>"
  81. "<br>"
  82. "(c) 2020 Felix Turowsky"
  83. "<br>"
  84. "<p>This is a collaboratively developed Free and Open Source Application. "
  85. "Visit us <a href=\"https://%1/\">here</a> for more information.</p>"
  86. "<p>This program is free software: you can redistribute it and/or modify "
  87. "it under the terms of the GNU General Public License as published by "
  88. "the Free Software Foundation, either version 3 of the License, or "
  89. "(at your option) any later version.</p>"
  90. "<p>This program is distributed in the hope that it will be useful, "
  91. "but WITHOUT ANY WARRANTY; without even the implied warranty of "
  92. "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
  93. "GNU General Public License for more details.</p> "
  94. "<p>You should have received a copy of the GNU General Public License "
  95. "along with this program. If not, "
  96. "please click <a href=\"https://www.gnu.org/licenses/\">here</a>.</p>"
  97. "<br>"
  98. "<p>This program uses <a href=\"http://%2/\">Qt</a> version %3 and "
  99. "<a href=\"https://sqlite.org/about.html/\">SQLite</a> version %4</p>"
  100. ).arg(QLatin1String("github.com/fiffty-50/openpilotlog"),
  101. QLatin1String("qt.io"),
  102. QLatin1String(QT_VERSION_STR),
  103. QString(SQLITE_VERSION));
  104. mb->setText(text);
  105. mb->open();
  106. }