settingswidget.cpp 26 KB

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