123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- /*
- *openPilot Log - A FOSS Pilot Logbook Application
- *Copyright (C) 2020 Felix Turowsky
- *
- *This program is free software: you can redistribute it and/or modify
- *it under the terms of the GNU General Public License as published by
- *the Free Software Foundation, either version 3 of the License, or
- *(at your option) any later version.
- *
- *This program is distributed in the hope that it will be useful,
- *but WITHOUT ANY WARRANTY; without even the implied warranty of
- *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- *GNU General Public License for more details.
- *
- *You should have received a copy of the GNU General Public License
- *along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
- #include "settingswidget.h"
- #include "ui_settingswidget.h"
- #include "src/database/dbinfo.h"
- SettingsWidget::SettingsWidget(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::SettingsWidget)
- {
- ui->setupUi(this);
- QSettings settings;
- /*
- * General Tab
- */
- auto *themeGroup = new QButtonGroup;
- themeGroup->addButton(ui->systemThemeCheckBox, 0);
- themeGroup->addButton(ui->lightThemeCheckBox, 1);
- themeGroup->addButton(ui->darkThemeCheckBox, 2);
- connect(themeGroup, SIGNAL(buttonClicked(int)), this, SLOT(themeGroup_toggled(int)));
- switch (settings.value("main/theme").toInt()) {
- case 0:
- ui->systemThemeCheckBox->setChecked(true);
- break;
- case 1:
- ui->lightThemeCheckBox->setChecked(true);
- break;
- case 2:
- ui->darkThemeCheckBox->setChecked(true);
- }
- /*
- * Flight Logging Tab
- */
- //QString storedPrefix = db::singleSelect("setting","settings","setting_id","50",sql::exactMatch);
- QString storedPrefix = settings.value("userdata/flightnumberPrefix").toString();
- if (storedPrefix.length() != 0) {
- ui->flightNumberPrefixLineEdit->setText(storedPrefix);
- }
- QRegExp flightNumberPrefix_rx("[a-zA-Z0-9]?[a-zA-Z0-9]?[a-zA-Z0-9]"); // allow max 3 letters (upper and lower) and numbers
- QValidator *flightNumberPrefixValidator = new QRegExpValidator(flightNumberPrefix_rx, this);
- ui->flightNumberPrefixLineEdit->setValidator(flightNumberPrefixValidator);
- /*
- * Aircraft Tab
- */
- ui->acSortComboBox->setCurrentIndex(settings.value("userdata/acSortColumn").toInt());
- }
- SettingsWidget::~SettingsWidget()
- {
- delete ui;
- }
- /*
- * Slots
- */
- void SettingsWidget::on_flightNumberPrefixLineEdit_textEdited(const QString &arg1)
- {
- QSettings settings;
- settings.setValue("userdata/flightnumberPrefix", arg1);
- }
- void SettingsWidget::themeGroup_toggled(int id)
- {
- QSettings settings;
- settings.setValue("main/theme", id);
- QMessageBox::StandardButton reply;
- reply = QMessageBox::question(this, "Changing Themes",
- "Changing the theme requires restarting the Application.\n\nWould you like to restart now?",
- QMessageBox::Yes | QMessageBox::No);
- if (reply == QMessageBox::Yes) {
- qApp->quit();
- QProcess::startDetached(qApp->arguments()[0], qApp->arguments());
- } else {
- QMessageBox *info = new QMessageBox(this);
- info->setText("Theme change will take effect the next time you start the application.");
- info->exec();
- }
- }
- void SettingsWidget::on_aboutPushButton_clicked()
- {
- auto mb = new QMessageBox(this);
- QString SQLITE_VERSION = DbInfo().version;
- QString text = QMessageBox::tr(
- "<h3><center>About openPilotLog</center></h3>"
- "<br>"
- "(c) 2020 Felix Turowsky"
- "<br>"
- "<p>This is a collaboratively developed Free and Open Source Application. "
- "Visit us <a href=\"https://%1/\">here</a> for more information.</p>"
- "<p>This program is free software: you can redistribute it and/or modify "
- "it under the terms of the GNU General Public License as published by "
- "the Free Software Foundation, either version 3 of the License, or "
- "(at your option) any later version.</p>"
- "<p>This program is distributed in the hope that it will be useful, "
- "but WITHOUT ANY WARRANTY; without even the implied warranty of "
- "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
- "GNU General Public License for more details.</p> "
- "<p>You should have received a copy of the GNU General Public License "
- "along with this program. If not, "
- "please click <a href=\"https://www.gnu.org/licenses/\">here</a>.</p>"
- "<br>"
- "<p>This program uses <a href=\"http://%2/\">Qt</a> version %3 and "
- "<a href=\"https://sqlite.org/about.html\">SQLite</a> version %4</p>"
- ).arg(QLatin1String("github.com/fiffty-50/openpilotlog"),
- QLatin1String("qt.io"),
- QLatin1String(QT_VERSION_STR),
- QString(SQLITE_VERSION));
- mb->setText(text);
- mb->open();
- }
- void SettingsWidget::on_acSortComboBox_currentIndexChanged(int index)
- {
- QSettings settings;
- settings.setValue("userdata/acSortColumn", index);
- }
- void SettingsWidget::on_acAllowIncompleteComboBox_currentIndexChanged(int index)
- {
- QSettings settings;
- settings.setValue("userdata/acAllowIncomplete", index);
- if (index) {
- QMessageBox::StandardButton reply;
- reply = QMessageBox::question(this, "Warning",
- "Warning: Enabling incomplete logging will enable you to add aircraft with incomplete data.\n\n"
- "If you do not fill out the aircraft details, "
- "it will be impossible to automatically determine Single/Multi Pilot Times or Single/Multi Engine Time."
- "This will also impact statistics and auto-logging capabilites.\n\n"
- "It is highly recommended to keep this option off unless you have a specific reason not to.\n\n"
- "Are you sure you want to proceed?",
- QMessageBox::Yes | QMessageBox::No);
- if (reply == QMessageBox::Yes) {
- QSettings settings;
- settings.setValue("userdata/acAllowIncomplete", index);
- } else {
- ui->acAllowIncompleteComboBox->setCurrentIndex(0);
- }
- }
- }
|