aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/settings/SettingsAppearance.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/settings/SettingsAppearance.cpp')
-rw-r--r--src/ui/settings/SettingsAppearance.cpp220
1 files changed, 90 insertions, 130 deletions
diff --git a/src/ui/settings/SettingsAppearance.cpp b/src/ui/settings/SettingsAppearance.cpp
index 49dc349c..7e54c9f8 100644
--- a/src/ui/settings/SettingsAppearance.cpp
+++ b/src/ui/settings/SettingsAppearance.cpp
@@ -1,4 +1,6 @@
/**
+ * Copyright (C) 2021 Saturneric
+ *
* This file is part of GpgFrontend.
*
* GpgFrontend is free software: you can redistribute it and/or modify
@@ -6,25 +8,28 @@
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
- * Foobar is distributed in the hope that it will be useful,
+ * GpgFrontend 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 Foobar. If not, see <https://www.gnu.org/licenses/>.
+ * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from
+ * the gpg4usb project, which is under GPL-3.0-or-later.
*
- * The initial version of the source code is inherited from gpg4usb-team.
- * Their source code version also complies with GNU General Public License.
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric<[email protected]> starting on May 12, 2021.
*
- * The source code version of this software was modified and released
- * by Saturneric<[email protected]> starting on May 12, 2021.
+ * SPDX-License-Identifier: GPL-3.0-or-later
*
*/
#include "SettingsAppearance.h"
-#include "GlobalSettingStation.h"
+#include "core/function/GlobalSettingStation.h"
+#include "ui/struct/SettingsObject.h"
namespace GpgFrontend::UI {
@@ -33,19 +38,19 @@ AppearanceTab::AppearanceTab(QWidget* parent) : QWidget(parent) {
* Icon-Size-Box
*****************************************/
auto* iconSizeBox = new QGroupBox(_("Icon Size"));
- iconSizeGroup = new QButtonGroup();
- iconSizeSmall = new QRadioButton(_("small"));
- iconSizeMedium = new QRadioButton(_("medium"));
- iconSizeLarge = new QRadioButton(_("large"));
+ icon_size_group_ = new QButtonGroup();
+ icon_size_small_ = new QRadioButton(_("small"));
+ icon_size_medium_ = new QRadioButton(_("medium"));
+ icon_size_large_ = new QRadioButton(_("large"));
- iconSizeGroup->addButton(iconSizeSmall, 1);
- iconSizeGroup->addButton(iconSizeMedium, 2);
- iconSizeGroup->addButton(iconSizeLarge, 3);
+ icon_size_group_->addButton(icon_size_small_, 1);
+ icon_size_group_->addButton(icon_size_medium_, 2);
+ icon_size_group_->addButton(icon_size_large_, 3);
auto* iconSizeBoxLayout = new QHBoxLayout();
- iconSizeBoxLayout->addWidget(iconSizeSmall);
- iconSizeBoxLayout->addWidget(iconSizeMedium);
- iconSizeBoxLayout->addWidget(iconSizeLarge);
+ iconSizeBoxLayout->addWidget(icon_size_small_);
+ iconSizeBoxLayout->addWidget(icon_size_medium_);
+ iconSizeBoxLayout->addWidget(icon_size_large_);
iconSizeBox->setLayout(iconSizeBoxLayout);
@@ -53,19 +58,19 @@ AppearanceTab::AppearanceTab(QWidget* parent) : QWidget(parent) {
* Icon-Style-Box
*****************************************/
auto* iconStyleBox = new QGroupBox(_("Icon Style"));
- iconStyleGroup = new QButtonGroup();
- iconTextButton = new QRadioButton(_("just text"));
- iconIconsButton = new QRadioButton(_("just icons"));
- iconAllButton = new QRadioButton(_("text and icons"));
+ icon_style_group_ = new QButtonGroup();
+ icon_text_button_ = new QRadioButton(_("just text"));
+ icon_icons_button_ = new QRadioButton(_("just icons"));
+ icon_all_button_ = new QRadioButton(_("text and icons"));
- iconStyleGroup->addButton(iconTextButton, 1);
- iconStyleGroup->addButton(iconIconsButton, 2);
- iconStyleGroup->addButton(iconAllButton, 3);
+ icon_style_group_->addButton(icon_text_button_, 1);
+ icon_style_group_->addButton(icon_icons_button_, 2);
+ icon_style_group_->addButton(icon_all_button_, 3);
auto* iconStyleBoxLayout = new QHBoxLayout();
- iconStyleBoxLayout->addWidget(iconTextButton);
- iconStyleBoxLayout->addWidget(iconIconsButton);
- iconStyleBoxLayout->addWidget(iconAllButton);
+ iconStyleBoxLayout->addWidget(icon_text_button_);
+ iconStyleBoxLayout->addWidget(icon_icons_button_);
+ iconStyleBoxLayout->addWidget(icon_all_button_);
iconStyleBox->setLayout(iconStyleBoxLayout);
@@ -74,9 +79,9 @@ AppearanceTab::AppearanceTab(QWidget* parent) : QWidget(parent) {
*****************************************/
auto* windowSizeBox = new QGroupBox(_("Window State"));
auto* windowSizeBoxLayout = new QHBoxLayout();
- windowSizeCheckBox =
+ window_size_check_box_ =
new QCheckBox(_("Save window size and position on exit."), this);
- windowSizeBoxLayout->addWidget(windowSizeCheckBox);
+ windowSizeBoxLayout->addWidget(window_size_check_box_);
windowSizeBox->setLayout(windowSizeBoxLayout);
/*****************************************
@@ -85,12 +90,12 @@ AppearanceTab::AppearanceTab(QWidget* parent) : QWidget(parent) {
auto* infoBoardBox = new QGroupBox(_("Information Board"));
auto* infoBoardLayout = new QHBoxLayout();
- infoBoardFontSizeSpin = new QSpinBox();
- infoBoardFontSizeSpin->setRange(9, 18);
- infoBoardFontSizeSpin->setValue(10);
- infoBoardFontSizeSpin->setSingleStep(1);
+ info_board_font_size_spin_ = new QSpinBox();
+ info_board_font_size_spin_->setRange(9, 18);
+ info_board_font_size_spin_->setValue(10);
+ info_board_font_size_spin_->setSingleStep(1);
infoBoardLayout->addWidget(new QLabel(_("Font Size in Information Board")));
- infoBoardLayout->addWidget(infoBoardFontSizeSpin);
+ infoBoardLayout->addWidget(info_board_font_size_spin_);
infoBoardBox->setLayout(infoBoardLayout);
auto* mainLayout = new QVBoxLayout;
@@ -99,7 +104,7 @@ AppearanceTab::AppearanceTab(QWidget* parent) : QWidget(parent) {
mainLayout->addWidget(windowSizeBox);
mainLayout->addWidget(infoBoardBox);
mainLayout->addStretch(1);
- setSettings();
+ SetSettings();
setLayout(mainLayout);
}
@@ -108,89 +113,64 @@ AppearanceTab::AppearanceTab(QWidget* parent) : QWidget(parent) {
* and set the buttons and checkboxes
* appropriately
**********************************/
-void AppearanceTab::setSettings() {
- auto& settings = GlobalSettingStation::GetInstance().GetUISettings();
-
- try {
- int width = settings.lookup("window.icon_size.width");
- int height = settings.lookup("window.icon_size.height");
-
- auto icon_size = QSize(width, height);
-
- switch (icon_size.height()) {
- case 12:
- iconSizeSmall->setChecked(true);
- break;
- case 24:
- iconSizeMedium->setChecked(true);
- break;
- case 32:
- iconSizeLarge->setChecked(true);
- break;
- }
-
- } catch (...) {
- LOG(ERROR) << _("Setting Operation Error") << _("icon_size");
- }
+void AppearanceTab::SetSettings() {
- // icon_style
- try {
- int s_icon_style = settings.lookup("window.icon_style");
- auto icon_style = static_cast<Qt::ToolButtonStyle>(s_icon_style);
-
- switch (icon_style) {
- case Qt::ToolButtonTextOnly:
- iconTextButton->setChecked(true);
- break;
- case Qt::ToolButtonIconOnly:
- iconIconsButton->setChecked(true);
- break;
- case Qt::ToolButtonTextUnderIcon:
- iconAllButton->setChecked(true);
- break;
- default:
- break;
- }
-
- } catch (...) {
- LOG(ERROR) << _("Setting Operation Error") << _("icon_style");
- }
+ SettingsObject main_windows_state("main_windows_state");
+
+ int width = main_windows_state.Check("icon_size").Check("width", 24),
+ height = main_windows_state.Check("icon_size").Check("height", 24);
- // Window Save and Position
- try {
- bool window_save = settings.lookup("window.window_save");
- if (window_save) windowSizeCheckBox->setCheckState(Qt::Checked);
+ auto icon_size = QSize(width, height);
- } catch (...) {
- LOG(ERROR) << _("Setting Operation Error") << _("window_save");
+ switch (icon_size.width()) {
+ case 12:
+ icon_size_small_->setChecked(true);
+ break;
+ case 24:
+ icon_size_medium_->setChecked(true);
+ break;
+ case 32:
+ icon_size_large_->setChecked(true);
+ break;
}
- // info board font size
- try {
- int info_font_size = settings.lookup("window.info_font_size");
- if (info_font_size < 9 || info_font_size > 18) info_font_size = 10;
- infoBoardFontSizeSpin->setValue(info_font_size);
- } catch (...) {
- LOG(ERROR) << _("Setting Operation Error") << _("info_font_size");
+ // icon_style
+ int s_icon_style =
+ main_windows_state.Check("icon_style", Qt::ToolButtonTextUnderIcon);
+ auto icon_style = static_cast<Qt::ToolButtonStyle>(s_icon_style);
+
+ switch (icon_style) {
+ case Qt::ToolButtonTextOnly:
+ icon_text_button_->setChecked(true);
+ break;
+ case Qt::ToolButtonIconOnly:
+ icon_icons_button_->setChecked(true);
+ break;
+ case Qt::ToolButtonTextUnderIcon:
+ icon_all_button_->setChecked(true);
+ break;
+ default:
+ break;
}
+
+ bool window_save = main_windows_state.Check("window_save", true);
+ if (window_save) window_size_check_box_->setCheckState(Qt::Checked);
+
+ auto info_font_size = main_windows_state.Check("info_font_size", 10);
+ if (info_font_size < 9 || info_font_size > 18) info_font_size = 10;
+ info_board_font_size_spin_->setValue(info_font_size);
}
/***********************************
* get the values of the buttons and
* write them to settings-file
*************************************/
-void AppearanceTab::applySettings() {
- auto& settings =
- GpgFrontend::UI::GlobalSettingStation::GetInstance().GetUISettings();
-
- if (!settings.exists("window") ||
- settings.lookup("window").getType() != libconfig::Setting::TypeGroup)
- settings.add("window", libconfig::Setting::TypeGroup);
+void AppearanceTab::ApplySettings() {
- auto& window = settings["window"];
+ SettingsObject main_windows_state("main_windows_state");
int icon_size = 24;
- switch (iconSizeGroup->checkedId()) {
+ switch (icon_size_group_->checkedId()) {
case 1:
icon_size = 12;
break;
@@ -202,18 +182,11 @@ void AppearanceTab::applySettings() {
break;
}
- if (!window.exists("icon_size")) {
- auto& icon_size_settings =
- window.add("icon_size", libconfig::Setting::TypeGroup);
- icon_size_settings.add("width", libconfig::Setting::TypeInt) = icon_size;
- icon_size_settings.add("height", libconfig::Setting::TypeInt) = icon_size;
- } else {
- window["icon_size"]["width"] = icon_size;
- window["icon_size"]["height"] = icon_size;
- }
+ main_windows_state["icon_size"]["width"] = icon_size;
+ main_windows_state["icon_size"]["height"] = icon_size;
auto icon_style = Qt::ToolButtonTextUnderIcon;
- switch (iconStyleGroup->checkedId()) {
+ switch (icon_style_group_->checkedId()) {
case 1:
icon_style = Qt::ToolButtonTextOnly;
break;
@@ -225,25 +198,12 @@ void AppearanceTab::applySettings() {
break;
}
- if (!window.exists("icon_style")) {
- window.add("icon_style", libconfig::Setting::TypeInt) = icon_style;
- } else {
- window["icon_style"] = icon_style;
- }
+ main_windows_state["icon_style"] = icon_style;
- if (!window.exists("window_save")) {
- window.add("window_save", libconfig::Setting::TypeBoolean) =
- windowSizeCheckBox->isChecked();
- } else {
- window["window_save"] = windowSizeCheckBox->isChecked();
- }
+ main_windows_state["window_save"] = window_size_check_box_->isChecked();
+
+ main_windows_state["info_font_size"] = info_board_font_size_spin_->value();
- if (!window.exists("info_font_size")) {
- window.add("info_font_size", libconfig::Setting::TypeBoolean) =
- infoBoardFontSizeSpin->value();
- } else {
- window["info_font_size"] = infoBoardFontSizeSpin->value();
- }
}
} // namespace GpgFrontend::UI