settingswidget.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. /*
  2. *openPilotLog - A FOSS Pilot Logbook Application
  3. *Copyright (C) 2020-2021 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/functions/alog.h"
  21. #include "src/classes/astyle.h"
  22. #include "src/classes/asettings.h"
  23. #include "src/database/adatabase.h"
  24. #include "src/classes/apilotentry.h"
  25. #include "src/opl.h"
  26. #include "src/functions/adate.h"
  27. static const auto FIRSTNAME_VALID = QPair<QString, QRegularExpression> {
  28. QStringLiteral("firstnameLineEdit"), QRegularExpression("[a-zA-Z]+")};
  29. static const auto LASTNAME_VALID = QPair<QString, QRegularExpression> {
  30. QStringLiteral("lastnameLineEdit"), QRegularExpression("\\w+")};
  31. static const auto PHONE_VALID = QPair<QString, QRegularExpression> {
  32. QStringLiteral("phoneLineEdit"), QRegularExpression("^[+]{0,1}[0-9\\-\\s]+")};
  33. static const auto EMAIL_VALID = QPair<QString, QRegularExpression> {
  34. QStringLiteral("emailLineEdit"), QRegularExpression("\\A[a-z0-9!#$%&'*+/=?^_‘{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_‘{|}~-]+)*@"
  35. "(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\z")};
  36. static const auto COMPANY_VALID = QPair<QString, QRegularExpression> {
  37. QStringLiteral("companyLineEdit"), QRegularExpression("\\w+")};
  38. static const auto EMPLOYEENR_VALID = QPair<QString, QRegularExpression> {
  39. QStringLiteral("employeeidLineEdit"), QRegularExpression("\\w+")};
  40. static const auto PREFIX_VALID = QPair<QString, QRegularExpression> {
  41. QStringLiteral("prefixLineEdit"), QRegularExpression("[a-zA-Z0-9]?[a-zA-Z0-9]?[a-zA-Z0-9]")};
  42. static const auto LINE_EDIT_VALIDATORS = QVector<QPair<QString, QRegularExpression>>{
  43. FIRSTNAME_VALID, LASTNAME_VALID, PHONE_VALID, EMAIL_VALID,
  44. COMPANY_VALID, EMPLOYEENR_VALID, PREFIX_VALID};
  45. SettingsWidget::SettingsWidget(QWidget *parent) :
  46. QWidget(parent),
  47. ui(new Ui::SettingsWidget)
  48. {
  49. ui->setupUi(this);
  50. ui->tabWidget->setCurrentIndex(0);
  51. ui->acAllowIncompleteComboBox->hide(); // [F]: Hidden for now, thinking of removing that option
  52. ui->acAllowIncompleteLabel->hide();
  53. setupComboBoxes();
  54. setupDateEdits();
  55. setupValidators();
  56. readSettings();
  57. }
  58. SettingsWidget::~SettingsWidget()
  59. {
  60. delete ui;
  61. }
  62. void SettingsWidget::changeEvent(QEvent *event)
  63. {
  64. if (event != nullptr)
  65. if(event->type() == QEvent::LanguageChange)
  66. ui->retranslateUi(this);
  67. }
  68. void SettingsWidget::setupComboBoxes(){
  69. {
  70. // Style combo box
  71. const QSignalBlocker blocker_style(ui->styleComboBox);
  72. ui->styleComboBox->addItems(AStyle::styles);
  73. for (const auto &style_sheet : AStyle::styleSheets) {
  74. ui->styleComboBox->addItem(style_sheet.styleSheetName);
  75. }
  76. ui->styleComboBox->addItem(QStringLiteral("Dark-Palette"));
  77. ui->styleComboBox->model()->sort(0);
  78. // Approach Combo Box
  79. const QSignalBlocker blocker_approach(ui->approachComboBox);
  80. for (const auto &approach : Opl::ApproachTypes)
  81. ui->approachComboBox->addItem(approach);
  82. // Language Combo Box
  83. const QSignalBlocker blocker_language(ui->languageComboBox);
  84. for (const auto &lang : Opl::L10N_NAMES)
  85. ui->languageComboBox->addItem(lang);
  86. }
  87. }
  88. void SettingsWidget::setupDateEdits()
  89. {
  90. // Read Display Format Setting
  91. int date_format_index = ASettings::read(ASettings::Main::DateFormat).toInt();
  92. const QString date_format_string = ADate::getFormatString(
  93. static_cast<Opl::Date::ADateFormat>(date_format_index));
  94. // Set Up Date Format Combo Box
  95. const QSignalBlocker blocker_date(ui->dateFormatComboBox);
  96. for (const auto &date_format : ADate::getDisplayNames())
  97. ui->dateFormatComboBox->addItem(date_format);
  98. ui->dateFormatComboBox->setCurrentIndex(date_format_index);
  99. const auto date_edits = this->findChildren<QDateEdit*>();
  100. for (const auto &date_edit : date_edits) {
  101. date_edit->setDisplayFormat(date_format_string);
  102. }
  103. // De-activate non-default date settings for now, implement in future release
  104. ui->dateFormatComboBox->setVisible(false);
  105. ui->dateFormatLabel->setVisible(false);
  106. // Fill currencies
  107. const QList<QPair<ACurrencyEntry::CurrencyName, QDateEdit* >> currencies = {
  108. {ACurrencyEntry::CurrencyName::Licence, ui->currLicDateEdit},
  109. {ACurrencyEntry::CurrencyName::TypeRating, ui->currTrDateEdit},
  110. {ACurrencyEntry::CurrencyName::LineCheck, ui->currLckDateEdit},
  111. {ACurrencyEntry::CurrencyName::Medical, ui->currMedDateEdit},
  112. {ACurrencyEntry::CurrencyName::Custom1, ui->currCustom1DateEdit},
  113. {ACurrencyEntry::CurrencyName::Custom2, ui->currCustom2DateEdit}
  114. };
  115. for (const auto &pair : currencies) {
  116. const QSignalBlocker signal_blocker(pair.second);
  117. const auto entry = aDB->getCurrencyEntry(pair.first);
  118. if (entry.isValid()) { // set date
  119. const auto date = QDate::fromString(
  120. entry.tableData.value(Opl::Db::CURRENCIES_EXPIRYDATE).toString(),
  121. Qt::ISODate);
  122. pair.second->setDate(date);
  123. } else { // set current date
  124. pair.second->setDate(QDate::currentDate());
  125. }
  126. }
  127. }
  128. /*!
  129. * \brief SettingsWidget::readSettings Reads settings from ASettings and sets up the UI accordingly
  130. */
  131. void SettingsWidget::readSettings()
  132. {
  133. /*
  134. * Personal Tab
  135. */
  136. {
  137. const QSignalBlocker blocker(this); // don't emit editing finished for setting these values
  138. auto user_data = aDB->getPilotEntry(1).getData();
  139. ui->lastnameLineEdit->setText(user_data.value(Opl::Db::PILOTS_LASTNAME).toString());
  140. ui->firstnameLineEdit->setText(user_data.value(Opl::Db::PILOTS_FIRSTNAME).toString());
  141. ui->companyLineEdit->setText(user_data.value(Opl::Db::PILOTS_COMPANY).toString());
  142. ui->employeeidLineEdit->setText(user_data.value(Opl::Db::PILOTS_EMPLOYEEID).toString());
  143. ui->phoneLineEdit->setText(user_data.value(Opl::Db::PILOTS_PHONE).toString());
  144. ui->emailLineEdit->setText(user_data.value(Opl::Db::PILOTS_EMAIL).toString());
  145. }
  146. /*
  147. * Flight Logging Tab
  148. */
  149. ui->aliasComboBox->setCurrentIndex(ASettings::read(ASettings::UserData::DisplaySelfAs).toInt());
  150. ui->functionComboBox->setCurrentText(ASettings::read(ASettings::FlightLogging::Function).toString());
  151. ui->rulesComboBox->setCurrentText(ASettings::read(ASettings::FlightLogging::Rules).toString());
  152. ui->approachComboBox->setCurrentText(ASettings::read(ASettings::FlightLogging::Approach).toString());
  153. ui->nightComboBox->setCurrentIndex(ASettings::read(ASettings::FlightLogging::NightLoggingEnabled).toInt());
  154. ui->prefixLineEdit->setText(ASettings::read(ASettings::FlightLogging::FlightNumberPrefix).toString());
  155. ui->logbookViewComboBox->setCurrentIndex(ASettings::read(ASettings::Main::LogbookView).toInt());
  156. /*
  157. * Currencies Tab
  158. */
  159. ui->currToLdgCheckBox->setChecked(ASettings::read(ASettings::UserData::ShowToLgdCurrency).toBool());
  160. ui->currLicCheckBox->setChecked(ASettings::read(ASettings::UserData::ShowLicCurrency).toBool());
  161. ui->currTrCheckBox->setChecked(ASettings::read(ASettings::UserData::ShowTrCurrency).toBool());
  162. ui->currLckCheckBox->setChecked(ASettings::read(ASettings::UserData::ShowLckCurrency).toBool());
  163. ui->currMedCheckBox->setChecked(ASettings::read(ASettings::UserData::ShowMedCurrency).toBool());
  164. ui->currCustom1CheckBox->setChecked(ASettings::read(ASettings::UserData::ShowCustom1Currency).toBool());
  165. ui->currCustom2CheckBox->setChecked(ASettings::read(ASettings::UserData::ShowCustom2Currency).toBool());
  166. ui->currWarningThresholdSpinBox->setValue(ASettings::read(ASettings::UserData::CurrWarningThreshold).toInt());
  167. ui->currWarningCheckBox->setChecked(ASettings::read(ASettings::UserData::CurrWarningEnabled).toBool());
  168. ui->currCustom1LineEdit->setText(ASettings::read(ASettings::UserData::Custom1CurrencyName).toString());
  169. ui->currCustom2LineEdit->setText(ASettings::read(ASettings::UserData::Custom2CurrencyName).toString());
  170. /*
  171. * Misc Tab
  172. */
  173. ui->acftSortComboBox->setCurrentIndex(ASettings::read(ASettings::UserData::TailSortColumn).toInt());
  174. ui->pilotSortComboBox->setCurrentIndex(ASettings::read(ASettings::UserData::PilotSortColumn).toInt());
  175. //ui->acAllowIncompleteComboBox->setCurrentIndex(ASettings::read(ASettings::UserData::AcftAllowIncomplete).toInt());
  176. {
  177. // Block style widgets signals to not trigger style changes during UI setup
  178. const QSignalBlocker style_blocker(ui->styleComboBox);
  179. const QSignalBlocker font_blocker1(ui->fontSpinBox);
  180. const QSignalBlocker font_blocker2(ui->fontComboBox);
  181. const QSignalBlocker font_blocker3(ui->fontCheckBox);
  182. ui->styleComboBox->setCurrentText(ASettings::read(ASettings::Main::Style).toString());
  183. ui->fontSpinBox->setValue(ASettings::read(ASettings::Main::FontSize).toUInt());
  184. ui->fontComboBox->setCurrentFont(QFont(ASettings::read(ASettings::Main::Font).toString()));
  185. bool use_system_font = ASettings::read(ASettings::Main::UseSystemFont).toBool();
  186. ui->fontCheckBox->setChecked(use_system_font);
  187. if (!use_system_font) {
  188. ui->fontComboBox->setEnabled(true);
  189. ui->fontSpinBox->setEnabled(true);
  190. }
  191. }
  192. }
  193. void SettingsWidget::setupValidators()
  194. {
  195. // DEB << "Setting up Validators...";
  196. for(const auto& pair : LINE_EDIT_VALIDATORS){
  197. auto line_edit = parent()->findChild<QLineEdit*>(pair.first);
  198. if(line_edit != nullptr){
  199. auto validator = new QRegularExpressionValidator(pair.second,line_edit);
  200. line_edit->setValidator(validator);
  201. }else{
  202. DEB << "Error: Line Edit not found: "<< pair.first << " - skipping.";
  203. }
  204. }
  205. }
  206. /*!
  207. * \brief SettingsWidget::updatePersonalDetails Updates the database with the users personal details.
  208. */
  209. void SettingsWidget::updatePersonalDetails()
  210. {
  211. RowData_T user_data;
  212. switch (ui->aliasComboBox->currentIndex()) {
  213. case 0:
  214. user_data.insert(Opl::Db::PILOTS_ALIAS, QStringLiteral("self"));
  215. break;
  216. case 1:
  217. user_data.insert(Opl::Db::PILOTS_ALIAS, QStringLiteral("SELF"));
  218. break;
  219. case 2:{
  220. QString name;
  221. name.append(ui->lastnameLineEdit->text());
  222. name.append(QLatin1String(", "));
  223. name.append(ui->firstnameLineEdit->text().leftRef(1));
  224. name.append(QLatin1Char('.'));
  225. user_data.insert(Opl::Db::PILOTS_ALIAS, name);
  226. }
  227. break;
  228. default:
  229. break;
  230. }
  231. user_data.insert(Opl::Db::PILOTS_LASTNAME, ui->lastnameLineEdit->text());
  232. user_data.insert(Opl::Db::PILOTS_FIRSTNAME, ui->firstnameLineEdit->text());
  233. user_data.insert(Opl::Db::PILOTS_COMPANY, ui->companyLineEdit->text());
  234. user_data.insert(Opl::Db::PILOTS_EMPLOYEEID, ui->employeeidLineEdit->text());
  235. user_data.insert(Opl::Db::PILOTS_PHONE, ui->phoneLineEdit->text());
  236. user_data.insert(Opl::Db::PILOTS_EMAIL, ui->emailLineEdit->text());
  237. auto user = APilotEntry(1);
  238. user.setData(user_data);
  239. aDB->commit(user);
  240. }
  241. /*
  242. * Slots
  243. */
  244. /*
  245. * Personal Tab
  246. */
  247. void SettingsWidget::on_lastnameLineEdit_editingFinished()
  248. {
  249. updatePersonalDetails();
  250. }
  251. void SettingsWidget::on_firstnameLineEdit_editingFinished()
  252. {
  253. updatePersonalDetails();
  254. }
  255. void SettingsWidget::on_companyLineEdit_editingFinished()
  256. {
  257. updatePersonalDetails();
  258. }
  259. void SettingsWidget::on_employeeidLineEdit_editingFinished()
  260. {
  261. updatePersonalDetails();
  262. }
  263. void SettingsWidget::on_emailLineEdit_editingFinished()
  264. {
  265. updatePersonalDetails();
  266. }
  267. void SettingsWidget::on_phoneLineEdit_editingFinished()
  268. {
  269. updatePersonalDetails();
  270. }
  271. /*
  272. * Flight Logging Tab
  273. */
  274. void SettingsWidget::on_aliasComboBox_currentIndexChanged(int index)
  275. {
  276. ASettings::write(ASettings::UserData::DisplaySelfAs, index);
  277. updatePersonalDetails();
  278. }
  279. void SettingsWidget::on_functionComboBox_currentIndexChanged(const QString &arg1)
  280. {
  281. ASettings::write(ASettings::FlightLogging::Function, arg1);
  282. }
  283. void SettingsWidget::on_rulesComboBox_currentIndexChanged(const QString &arg1)
  284. {
  285. ASettings::write(ASettings::FlightLogging::Rules, arg1);
  286. }
  287. void SettingsWidget::on_approachComboBox_currentIndexChanged(const QString &arg1)
  288. {
  289. ASettings::write(ASettings::FlightLogging::Approach, arg1);
  290. }
  291. void SettingsWidget::on_nightComboBox_currentIndexChanged(int index)
  292. {
  293. ASettings::write(ASettings::FlightLogging::NightLoggingEnabled, index);
  294. switch (index) {
  295. case 1:
  296. ASettings::write(ASettings::FlightLogging::NightAngle, -6);
  297. break;
  298. case 2:
  299. ASettings::write(ASettings::FlightLogging::NightAngle, 0);
  300. break;
  301. default:
  302. ASettings::write(ASettings::FlightLogging::NightAngle, -6);
  303. }
  304. }
  305. void SettingsWidget::on_prefixLineEdit_textChanged(const QString &arg1)
  306. {
  307. ASettings::write(ASettings::FlightLogging::FlightNumberPrefix, arg1);
  308. }
  309. /*
  310. * Misc Tab
  311. */
  312. void SettingsWidget::on_logbookViewComboBox_currentIndexChanged(int index)
  313. {
  314. ASettings::write(ASettings::Main::LogbookView, index);
  315. emit settingChanged(SettingSignal::LogbookWidget);
  316. }
  317. void SettingsWidget::on_pilotSortComboBox_currentIndexChanged(int index)
  318. {
  319. ASettings::write(ASettings::UserData::PilotSortColumn, index);
  320. emit settingChanged(PilotsWidget);
  321. }
  322. void SettingsWidget::on_acftSortComboBox_currentIndexChanged(int index)
  323. {
  324. ASettings::write(ASettings::UserData::TailSortColumn, index);
  325. emit settingChanged(AircraftWidget);
  326. }
  327. QT_DEPRECATED
  328. void SettingsWidget::on_acAllowIncompleteComboBox_currentIndexChanged(int index)
  329. {
  330. ASettings::write(ASettings::UserData::AcftAllowIncomplete, index);
  331. if (index) {
  332. QMessageBox::StandardButton reply;
  333. reply = QMessageBox::warning(this, tr("Warning"),
  334. tr("Enabling incomplete logging will enable you to add aircraft with incomplete data.<br><br>"
  335. "If you do not fill out the aircraft details, "
  336. "it will be impossible to automatically determine Single/Multi Pilot Times or Single/Multi Engine Time. "
  337. "This will also impact statistics and auto-logging capabilites as well as jeopardise database integrity.<br><br>"
  338. "It is highly recommended to keep this option off unless you have a specific reason not to.<br><br>"
  339. "Are you sure you want to proceed?"),
  340. QMessageBox::Yes | QMessageBox::No);
  341. if (reply == QMessageBox::Yes) {
  342. ASettings::write(ASettings::UserData::AcftAllowIncomplete, index);
  343. } else {
  344. ui->acAllowIncompleteComboBox->setCurrentIndex(0);
  345. }
  346. }
  347. }
  348. /*
  349. * About Tab
  350. */
  351. /*!
  352. * \brief SettingsWidget::on_aboutPushButton_clicked Displays Application Version and Licensing information
  353. */
  354. void SettingsWidget::on_aboutPushButton_clicked()
  355. {
  356. QMessageBox message_box(this);
  357. QPixmap icon = QPixmap(Opl::Assets::ICON_MAIN);
  358. message_box.setIconPixmap(icon.scaledToWidth(64, Qt::TransformationMode::SmoothTransformation));
  359. QString SQLITE_VERSION = aDB->sqliteVersion();
  360. QString text = QMessageBox::tr(
  361. "<h3><center>About openPilotLog</center></h3>"
  362. "<br>"
  363. "&#169; 2020-2021 Felix Turowsky"
  364. "<br>"
  365. "<p>This is a collaboratively developed Free and Open Source Application. "
  366. "Visit us <a href=\"https://%1/\">here</a> for more information.</p>"
  367. "<p>This program is free software: you can redistribute it and/or modify "
  368. "it under the terms of the GNU General Public License as published by "
  369. "the Free Software Foundation, either version 3 of the License, or "
  370. "(at your option) any later version.</p>"
  371. "<p>This program is distributed in the hope that it will be useful, "
  372. "but WITHOUT ANY WARRANTY; without even the implied warranty of "
  373. "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
  374. "GNU General Public License for more details.</p> "
  375. "<p>You should have received a copy of the GNU General Public License "
  376. "along with this program. If not, "
  377. "please click <a href=\"https://%2\">here</a>.</p>"
  378. "<br>"
  379. "<p>This program uses <a href=\"http://%3/\">Qt</a> version %4 and "
  380. "<a href=\"https://%5/\">SQLite</a> version %6</p>"
  381. ).arg(QStringLiteral("github.com/fiffty-50/openpilotlog"),
  382. QStringLiteral("gnu.org/licenses/"),
  383. QStringLiteral("qt.io"),
  384. QT_VERSION_STR,
  385. QStringLiteral("sqlite.org/about.html"),
  386. SQLITE_VERSION);
  387. message_box.setText(text);
  388. message_box.exec();
  389. }
  390. void SettingsWidget::on_styleComboBox_currentTextChanged(const QString& new_style_setting)
  391. {
  392. if (new_style_setting == QLatin1String("Dark-Palette")) {
  393. AStyle::setStyle(AStyle::darkPalette());
  394. ASettings::write(ASettings::Main::Style, new_style_setting);
  395. return;
  396. }
  397. for (const auto &style_name : AStyle::styles) {
  398. if (new_style_setting == style_name) {
  399. AStyle::setStyle(style_name);
  400. ASettings::write(ASettings::Main::Style, new_style_setting);
  401. return;
  402. }
  403. }
  404. for (const auto &style_sheet : AStyle::styleSheets) {
  405. if (new_style_setting == style_sheet.styleSheetName) {
  406. AStyle::setStyle(style_sheet);
  407. ASettings::write(ASettings::Main::Style, new_style_setting);
  408. return;
  409. }
  410. }
  411. }
  412. void SettingsWidget::on_fontComboBox_currentFontChanged(const QFont &f)
  413. {
  414. qApp->setFont(f);
  415. ASettings::write(ASettings::Main::Font, f.toString());
  416. DEB << "Setting Font:" << f.toString();
  417. }
  418. void SettingsWidget::on_fontSpinBox_valueChanged(int arg1)
  419. {
  420. QFont f = qApp->font();
  421. f.setPointSize(arg1);
  422. qApp->setFont(f);
  423. ASettings::write(ASettings::Main::FontSize, arg1);
  424. DEB << "Setting Font:" << f.toString();
  425. }
  426. void SettingsWidget::on_fontCheckBox_stateChanged(int arg1)
  427. {
  428. if (usingStylesheet() && arg1 == Qt::Unchecked) {
  429. WARN(tr("The style you have currently selected may not be fully compatible "
  430. "with changing to a custom font while the application is running.<br><br>"
  431. "Applying your changes may require restarting the application.<br>"));
  432. }
  433. switch (arg1) {
  434. case Qt::Unchecked:
  435. {
  436. ui->fontComboBox->setEnabled(true);
  437. ui->fontSpinBox->setEnabled(true);
  438. ASettings::write(ASettings::Main::UseSystemFont, false);
  439. QFont font(ui->fontComboBox->currentFont());
  440. font.setPointSize(ui->fontSpinBox->value());
  441. qApp->setFont(font);
  442. LOG << "Setting Font:" << font.toString();
  443. break;
  444. }
  445. case Qt::Checked:
  446. {
  447. ui->fontComboBox->setEnabled(false);
  448. ui->fontSpinBox->setEnabled(false);
  449. ASettings::write(ASettings::Main::UseSystemFont, true);
  450. INFO(tr("The application will be restarted for this change to take effect."));
  451. qApp->quit();
  452. QProcess::startDetached(qApp->arguments()[0], qApp->arguments());
  453. }
  454. break;
  455. default:
  456. break;
  457. }
  458. }
  459. /*!
  460. * \brief Determines if the user has selected a stylesheet or is using a Qt Style Factory Style
  461. */
  462. bool SettingsWidget::usingStylesheet()
  463. {
  464. for (const auto &style_sheet : AStyle::styleSheets) {
  465. if (style_sheet.styleSheetName == ui->styleComboBox->currentText())
  466. return true;
  467. }
  468. return false;
  469. }
  470. void SettingsWidget::on_resetStylePushButton_clicked()
  471. {
  472. LOG << "Resetting style to default...";
  473. ui->styleComboBox->setCurrentText(AStyle::defaultStyle);
  474. ui->fontCheckBox->setChecked(true);
  475. }
  476. void SettingsWidget::on_currLicDateEdit_userDateChanged(const QDate &date)
  477. {
  478. ACurrencyEntry entry(ACurrencyEntry::CurrencyName::Licence, date);
  479. aDB->commit(entry);
  480. emit settingChanged(HomeWidget);
  481. }
  482. void SettingsWidget::on_currTrDateEdit_userDateChanged(const QDate &date)
  483. {
  484. ACurrencyEntry entry(ACurrencyEntry::CurrencyName::TypeRating, date);
  485. aDB->commit(entry);
  486. emit settingChanged(HomeWidget);
  487. }
  488. void SettingsWidget::on_currLckDateEdit_userDateChanged(const QDate &date)
  489. {
  490. ACurrencyEntry entry(ACurrencyEntry::CurrencyName::LineCheck, date);
  491. aDB->commit(entry);
  492. emit settingChanged(HomeWidget);
  493. }
  494. void SettingsWidget::on_currMedDateEdit_userDateChanged(const QDate &date)
  495. {
  496. ACurrencyEntry entry(ACurrencyEntry::CurrencyName::Medical, date);
  497. aDB->commit(entry);
  498. emit settingChanged(HomeWidget);
  499. }
  500. void SettingsWidget::on_currCustom1DateEdit_userDateChanged(const QDate &date)
  501. {
  502. ACurrencyEntry entry(ACurrencyEntry::CurrencyName::Custom1, date);
  503. aDB->commit(entry);
  504. emit settingChanged(HomeWidget);
  505. }
  506. void SettingsWidget::on_currCustom2DateEdit_userDateChanged(const QDate &date)
  507. {
  508. ACurrencyEntry entry(ACurrencyEntry::CurrencyName::Custom2, date);
  509. aDB->commit(entry);
  510. emit settingChanged(HomeWidget);
  511. }
  512. void SettingsWidget::on_currToLdgCheckBox_stateChanged(int arg1)
  513. {
  514. switch (arg1) {
  515. case Qt::CheckState::Checked:
  516. ASettings::write(ASettings::UserData::ShowToLgdCurrency, true);
  517. break;
  518. case Qt::CheckState::Unchecked:
  519. ASettings::write(ASettings::UserData::ShowToLgdCurrency, false);
  520. break;
  521. default:
  522. break;
  523. }
  524. emit settingChanged(HomeWidget);
  525. }
  526. void SettingsWidget::on_currLicCheckBox_stateChanged(int arg1)
  527. {
  528. switch (arg1) {
  529. case Qt::CheckState::Checked:
  530. ASettings::write(ASettings::UserData::ShowLicCurrency, true);
  531. break;
  532. case Qt::CheckState::Unchecked:
  533. ASettings::write(ASettings::UserData::ShowLicCurrency, false);
  534. break;
  535. default:
  536. break;
  537. }
  538. emit settingChanged(HomeWidget);
  539. }
  540. void SettingsWidget::on_currTrCheckBox_stateChanged(int arg1)
  541. {
  542. switch (arg1) {
  543. case Qt::CheckState::Checked:
  544. ASettings::write(ASettings::UserData::ShowTrCurrency, true);
  545. break;
  546. case Qt::CheckState::Unchecked:
  547. ASettings::write(ASettings::UserData::ShowTrCurrency, false);
  548. break;
  549. default:
  550. break;
  551. }
  552. emit settingChanged(HomeWidget);
  553. }
  554. void SettingsWidget::on_currLckCheckBox_stateChanged(int arg1)
  555. {
  556. switch (arg1) {
  557. case Qt::CheckState::Checked:
  558. ASettings::write(ASettings::UserData::ShowLckCurrency, true);
  559. break;
  560. case Qt::CheckState::Unchecked:
  561. ASettings::write(ASettings::UserData::ShowLckCurrency, false);
  562. break;
  563. default:
  564. break;
  565. }
  566. emit settingChanged(HomeWidget);
  567. }
  568. void SettingsWidget::on_currMedCheckBox_stateChanged(int arg1)
  569. {
  570. switch (arg1) {
  571. case Qt::CheckState::Checked:
  572. ASettings::write(ASettings::UserData::ShowMedCurrency, true);
  573. break;
  574. case Qt::CheckState::Unchecked:
  575. ASettings::write(ASettings::UserData::ShowMedCurrency, false);
  576. break;
  577. default:
  578. break;
  579. }
  580. emit settingChanged(HomeWidget);
  581. }
  582. void SettingsWidget::on_currCustom1CheckBox_stateChanged(int arg1)
  583. {
  584. switch (arg1) {
  585. case Qt::CheckState::Checked:
  586. ASettings::write(ASettings::UserData::ShowCustom1Currency, true);
  587. break;
  588. case Qt::CheckState::Unchecked:
  589. ASettings::write(ASettings::UserData::ShowCustom1Currency, false);
  590. break;
  591. default:
  592. break;
  593. }
  594. emit settingChanged(HomeWidget);
  595. }
  596. void SettingsWidget::on_currCustom2CheckBox_stateChanged(int arg1)
  597. {
  598. switch (arg1) {
  599. case Qt::CheckState::Checked:
  600. ASettings::write(ASettings::UserData::ShowCustom2Currency, true);
  601. break;
  602. case Qt::CheckState::Unchecked:
  603. ASettings::write(ASettings::UserData::ShowCustom2Currency, false);
  604. break;
  605. default:
  606. break;
  607. }
  608. emit settingChanged(HomeWidget);
  609. }
  610. void SettingsWidget::on_currWarningCheckBox_stateChanged(int arg1)
  611. {
  612. switch (arg1) {
  613. case Qt::CheckState::Checked:
  614. ASettings::write(ASettings::UserData::CurrWarningEnabled, true);
  615. break;
  616. case Qt::CheckState::Unchecked:
  617. ASettings::write(ASettings::UserData::CurrWarningEnabled, false);
  618. break;
  619. default:
  620. break;
  621. }
  622. emit settingChanged(HomeWidget);
  623. }
  624. void SettingsWidget::on_currWarningThresholdSpinBox_valueChanged(int arg1)
  625. {
  626. ASettings::write(ASettings::UserData::CurrWarningThreshold, arg1);
  627. emit settingChanged(SettingSignal::HomeWidget);
  628. }
  629. void SettingsWidget::on_currCustom1LineEdit_editingFinished()
  630. {
  631. ASettings::write(ASettings::UserData::Custom1CurrencyName, ui->currCustom1LineEdit->text());
  632. }
  633. void SettingsWidget::on_currCustom2LineEdit_editingFinished()
  634. {
  635. ASettings::write(ASettings::UserData::Custom2CurrencyName, ui->currCustom2LineEdit->text());
  636. }
  637. void SettingsWidget::on_dateFormatComboBox_currentIndexChanged(int index)
  638. {
  639. ASettings::write(ASettings::Main::DateFormat, index);
  640. const auto date_edits = this->findChildren<QDateEdit*>();
  641. for (const auto & date_edit : date_edits) {
  642. date_edit->setDisplayFormat(
  643. ADate::getFormatString(
  644. static_cast<Opl::Date::ADateFormat>(ASettings::read(ASettings::Main::DateFormat).toInt())));
  645. }
  646. }
  647. void SettingsWidget::on_languageComboBox_activated(const QString &arg1)
  648. {
  649. if (arg1 != Opl::L10N_NAMES[Opl::Translations::English]) {
  650. INFO(tr("Translations are not yet available. If you are interested in making openPilotLog available in your native "
  651. "language, visit us <a href=\"https://%1/\">here</a> for more information."
  652. ).arg(QStringLiteral("github.com/fiffty-50/openpilotlog/wiki/Translations")));
  653. ui->languageComboBox->setCurrentIndex(0);
  654. }
  655. }