settingswidget.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 "src/database/dbinfo.h"
  21. SettingsWidget::SettingsWidget(QWidget *parent) :
  22. QWidget(parent),
  23. ui(new Ui::SettingsWidget)
  24. {
  25. ui->setupUi(this);
  26. QSettings settings;
  27. /*
  28. * General Tab
  29. */
  30. auto *themeGroup = new QButtonGroup;
  31. themeGroup->addButton(ui->systemThemeCheckBox, 0);
  32. themeGroup->addButton(ui->lightThemeCheckBox, 1);
  33. themeGroup->addButton(ui->darkThemeCheckBox, 2);
  34. connect(themeGroup, SIGNAL(buttonClicked(int)), this, SLOT(themeGroup_toggled(int)));
  35. switch (settings.value("main/theme").toInt()) {
  36. case 0:
  37. ui->systemThemeCheckBox->setChecked(true);
  38. break;
  39. case 1:
  40. ui->lightThemeCheckBox->setChecked(true);
  41. break;
  42. case 2:
  43. ui->darkThemeCheckBox->setChecked(true);
  44. }
  45. /*
  46. * Flight Logging Tab
  47. */
  48. //QString storedPrefix = db::singleSelect("setting","settings","setting_id","50",sql::exactMatch);
  49. QString storedPrefix = settings.value("userdata/flightnumberPrefix").toString();
  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. * Aircraft Tab
  58. */
  59. ui->acSortComboBox->setCurrentIndex(settings.value("userdata/acSortColumn").toInt());
  60. }
  61. SettingsWidget::~SettingsWidget()
  62. {
  63. delete ui;
  64. }
  65. /*
  66. * Slots
  67. */
  68. void SettingsWidget::on_flightNumberPrefixLineEdit_textEdited(const QString &arg1)
  69. {
  70. QSettings settings;
  71. settings.setValue("userdata/flightnumberPrefix", arg1);
  72. }
  73. void SettingsWidget::themeGroup_toggled(int id)
  74. {
  75. QSettings settings;
  76. settings.setValue("main/theme", id);
  77. QMessageBox::StandardButton reply;
  78. reply = QMessageBox::question(this, "Changing Themes",
  79. "Changing the theme requires restarting the Application.\n\nWould you like to restart now?",
  80. QMessageBox::Yes | QMessageBox::No);
  81. if (reply == QMessageBox::Yes) {
  82. qApp->quit();
  83. QProcess::startDetached(qApp->arguments()[0], qApp->arguments());
  84. } else {
  85. QMessageBox *info = new QMessageBox(this);
  86. info->setText("Theme change will take effect the next time you start the application.");
  87. info->exec();
  88. }
  89. }
  90. void SettingsWidget::on_aboutPushButton_clicked()
  91. {
  92. auto mb = new QMessageBox(this);
  93. QString SQLITE_VERSION = DbInfo().version;
  94. QString text = QMessageBox::tr(
  95. "<h3><center>About openPilotLog</center></h3>"
  96. "<br>"
  97. "(c) 2020 Felix Turowsky"
  98. "<br>"
  99. "<p>This is a collaboratively developed Free and Open Source Application. "
  100. "Visit us <a href=\"https://%1/\">here</a> for more information.</p>"
  101. "<p>This program is free software: you can redistribute it and/or modify "
  102. "it under the terms of the GNU General Public License as published by "
  103. "the Free Software Foundation, either version 3 of the License, or "
  104. "(at your option) any later version.</p>"
  105. "<p>This program is distributed in the hope that it will be useful, "
  106. "but WITHOUT ANY WARRANTY; without even the implied warranty of "
  107. "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
  108. "GNU General Public License for more details.</p> "
  109. "<p>You should have received a copy of the GNU General Public License "
  110. "along with this program. If not, "
  111. "please click <a href=\"https://www.gnu.org/licenses/\">here</a>.</p>"
  112. "<br>"
  113. "<p>This program uses <a href=\"http://%2/\">Qt</a> version %3 and "
  114. "<a href=\"https://sqlite.org/about.html\">SQLite</a> version %4</p>"
  115. ).arg(QLatin1String("github.com/fiffty-50/openpilotlog"),
  116. QLatin1String("qt.io"),
  117. QLatin1String(QT_VERSION_STR),
  118. QString(SQLITE_VERSION));
  119. mb->setText(text);
  120. mb->open();
  121. }
  122. void SettingsWidget::on_acSortComboBox_currentIndexChanged(int index)
  123. {
  124. QSettings settings;
  125. settings.setValue("userdata/acSortColumn", index);
  126. }
  127. void SettingsWidget::on_acAllowIncompleteComboBox_currentIndexChanged(int index)
  128. {
  129. QSettings settings;
  130. settings.setValue("userdata/acAllowIncomplete", index);
  131. if (index) {
  132. QMessageBox::StandardButton reply;
  133. reply = QMessageBox::question(this, "Warning",
  134. "Warning: Enabling incomplete logging will enable you to add aircraft with incomplete data.\n\n"
  135. "If you do not fill out the aircraft details, "
  136. "it will be impossible to automatically determine Single/Multi Pilot Times or Single/Multi Engine Time."
  137. "This will also impact statistics and auto-logging capabilites.\n\n"
  138. "It is highly recommended to keep this option off unless you have a specific reason not to.\n\n"
  139. "Are you sure you want to proceed?",
  140. QMessageBox::Yes | QMessageBox::No);
  141. if (reply == QMessageBox::Yes) {
  142. QSettings settings;
  143. settings.setValue("userdata/acAllowIncomplete", index);
  144. } else {
  145. ui->acAllowIncompleteComboBox->setCurrentIndex(0);
  146. }
  147. }
  148. }