aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/settings/SettingsAppearance.cpp
blob: 91bef9efca20aee79826da256cb0019d72ad55d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/**
 * This file is part of GpgFrontend.
 *
 * GpgFrontend 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.
 *
 * Foobar 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/>.
 *
 * The initial version of the source code is inherited from gpg4usb-team.
 * Their source code version also complies with GNU General Public License.
 *
 * The source code version of this software was modified and released
 * by Saturneric<[email protected]> starting on May 12, 2021.
 *
 */

#include "SettingsAppearance.h"

namespace GpgFrontend::UI {

AppearanceTab::AppearanceTab(QWidget* parent)
    : QWidget(parent),
      appPath(qApp->applicationDirPath()),
      settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini",
               QSettings::IniFormat) {
  /*****************************************
   * Icon-Size-Box
   *****************************************/
  auto* iconSizeBox = new QGroupBox(_("Icon Size"));
  iconSizeGroup = new QButtonGroup();
  iconSizeSmall = new QRadioButton(_("small"));
  iconSizeMedium = new QRadioButton(_("medium"));
  iconSizeLarge = new QRadioButton(_("large"));

  iconSizeGroup->addButton(iconSizeSmall, 1);
  iconSizeGroup->addButton(iconSizeMedium, 2);
  iconSizeGroup->addButton(iconSizeLarge, 3);

  auto* iconSizeBoxLayout = new QHBoxLayout();
  iconSizeBoxLayout->addWidget(iconSizeSmall);
  iconSizeBoxLayout->addWidget(iconSizeMedium);
  iconSizeBoxLayout->addWidget(iconSizeLarge);

  iconSizeBox->setLayout(iconSizeBoxLayout);

  /*****************************************
   * 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"));

  iconStyleGroup->addButton(iconTextButton, 1);
  iconStyleGroup->addButton(iconIconsButton, 2);
  iconStyleGroup->addButton(iconAllButton, 3);

  auto* iconStyleBoxLayout = new QHBoxLayout();
  iconStyleBoxLayout->addWidget(iconTextButton);
  iconStyleBoxLayout->addWidget(iconIconsButton);
  iconStyleBoxLayout->addWidget(iconAllButton);

  iconStyleBox->setLayout(iconStyleBoxLayout);

  /*****************************************
   * Window-Size-Box
   *****************************************/
  auto* windowSizeBox = new QGroupBox(_("Window State"));
  auto* windowSizeBoxLayout = new QHBoxLayout();
  windowSizeCheckBox =
      new QCheckBox(_("Save window size and position on exit."), this);
  windowSizeBoxLayout->addWidget(windowSizeCheckBox);
  windowSizeBox->setLayout(windowSizeBoxLayout);

  /*****************************************
   * Info-Board-Font-Size-Box
   *****************************************/

  auto* infoBoardBox = new QGroupBox(_("Information Board"));
  auto* infoBoardLayout = new QHBoxLayout();
  infoBoardFontSizeSpin = new QSpinBox();
  infoBoardFontSizeSpin->setRange(9, 18);
  infoBoardFontSizeSpin->setValue(10);
  infoBoardFontSizeSpin->setSingleStep(1);
  infoBoardLayout->addWidget(new QLabel(_("Front Size")));
  infoBoardLayout->addWidget(infoBoardFontSizeSpin);
  infoBoardBox->setLayout(infoBoardLayout);

  auto* mainLayout = new QVBoxLayout;
  mainLayout->addWidget(iconSizeBox);
  mainLayout->addWidget(iconStyleBox);
  mainLayout->addWidget(windowSizeBox);
  mainLayout->addWidget(infoBoardBox);
  mainLayout->addStretch(1);
  setSettings();
  setLayout(mainLayout);
}

/**********************************
 * Read the settings from config
 * and set the buttons and checkboxes
 * appropriately
 **********************************/
void AppearanceTab::setSettings() {
  // Iconsize
  QSize iconSize = settings.value("toolbar/iconsize", QSize(24, 24)).toSize();
  switch (iconSize.height()) {
    case 12:
      iconSizeSmall->setChecked(true);
      break;
    case 24:
      iconSizeMedium->setChecked(true);
      break;
    case 32:
      iconSizeLarge->setChecked(true);
      break;
  }
  // Iconstyle
  Qt::ToolButtonStyle iconStyle = static_cast<Qt::ToolButtonStyle>(
      settings.value("toolbar/iconstyle", Qt::ToolButtonTextUnderIcon)
          .toUInt());
  switch (iconStyle) {
    case Qt::ToolButtonTextOnly:
      iconTextButton->setChecked(true);
      break;
    case Qt::ToolButtonIconOnly:
      iconIconsButton->setChecked(true);
      break;
    case Qt::ToolButtonTextUnderIcon:
      iconAllButton->setChecked(true);
      break;
    default:
      break;
  }

  // Window Save and Position
  if (settings.value("window/windowSave").toBool())
    windowSizeCheckBox->setCheckState(Qt::Checked);

  // infoBoardFontSize
  auto infoBoardFontSize =
      settings.value("informationBoard/fontSize", 10).toInt();
  if (infoBoardFontSize < 9 || infoBoardFontSize > 18) infoBoardFontSize = 10;
  infoBoardFontSizeSpin->setValue(infoBoardFontSize);
}

/***********************************
 * get the values of the buttons and
 * write them to settings-file
 *************************************/
void AppearanceTab::applySettings() {
  switch (iconSizeGroup->checkedId()) {
    case 1:
      settings.setValue("toolbar/iconsize", QSize(12, 12));
      break;
    case 2:
      settings.setValue("toolbar/iconsize", QSize(24, 24));
      break;
    case 3:
      settings.setValue("toolbar/iconsize", QSize(32, 32));
      break;
  }

  switch (iconStyleGroup->checkedId()) {
    case 1:
      settings.setValue("toolbar/iconstyle", Qt::ToolButtonTextOnly);
      break;
    case 2:
      settings.setValue("toolbar/iconstyle", Qt::ToolButtonIconOnly);
      break;
    case 3:
      settings.setValue("toolbar/iconstyle", Qt::ToolButtonTextUnderIcon);
      break;
  }

  settings.setValue("window/windowSave", windowSizeCheckBox->isChecked());

  settings.setValue("informationBoard/fontSize",
                    infoBoardFontSizeSpin->value());
}

}  // namespace GpgFrontend::UI