settingswidget.cpp 6.6 KB

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