-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.cpp
132 lines (97 loc) · 4.07 KB
/
settings.cpp
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
#include "settings.h"
#include "mainmenu.h"
void Settings::makeUI(QWidget* parent, ConfigMan* cfgMan) {
this->setWindowIcon(parent->windowIcon());
this->setWindowTitle("iMemo Settings");
QFont font;
font.setPointSize(11);
this->setFont(font);
this->setStyleSheet(parent->styleSheet());
QVBoxLayout* mainLayout = new QVBoxLayout(this);
QHBoxLayout* upperLayout = new QHBoxLayout();
QPushButton* backPushButton = new QPushButton("Back");
backPushButton->setMinimumWidth(60);
backPushButton->setMaximumWidth(60);
backPushButton->setIcon(QIcon(":/icons/go-previous.png"));
upperLayout->addWidget(backPushButton);
upperLayout->addSpacerItem(new QSpacerItem(0, 0,
QSizePolicy::MinimumExpanding,
QSizePolicy::Ignored));
mainLayout->addLayout(upperLayout);
QLabel* themeLabel = new QLabel("Theme");
QVBoxLayout* themeLayout = new QVBoxLayout();
QRadioButton* lightRadioButton = new QRadioButton("Light");
themeLayout->addWidget(lightRadioButton);
QRadioButton* darkRadioButton = new QRadioButton("Dark");
themeLayout->addWidget(darkRadioButton);
mainLayout->addLayout(themeLayout);
QLabel* fontFamilyLabel = new QLabel("Font Family");
mainLayout->addWidget(fontFamilyLabel);
QFontComboBox* fontComboBox = new QFontComboBox();
mainLayout->addWidget(fontComboBox);
QLabel* autosaveInterval = new QLabel("Auto-Save interval");
mainLayout->addWidget(autosaveInterval);
QHBoxLayout* intervalLayout = new QHBoxLayout();
QSpinBox* spinBox = new QSpinBox();
spinBox->setMinimum(1);
spinBox->setMaximum(20);
intervalLayout->addWidget(spinBox);
QLabel* minLabel = new QLabel("min");
intervalLayout->addWidget(minLabel);
mainLayout->addLayout(intervalLayout);
mainLayout->addSpacerItem(new QSpacerItem(0, 0,
QSizePolicy::Ignored,
QSizePolicy::MinimumExpanding));
QPushButton* saveButton = new QPushButton("Save");
mainLayout->addWidget(saveButton);
// Set current settings
if (!cfgMan->mAppTheme.compare("light")) {
lightRadioButton->setChecked(true);
}
else { // Dark
darkRadioButton->setChecked(true);
}
fontComboBox->setCurrentFont(QFont(cfgMan->mFontFamily));
spinBox->setValue(cfgMan->mAutosaveIntervalMin);
// Making connections
connect(backPushButton, &QPushButton::clicked, this, [this, parent]() {
QString req = static_cast<MainMenu*>(mParent)->mSearchBox->text();
static_cast<MainMenu*>(mParent)->buildList(req);
parent->show();
this->hide();
delete this;
});
connect(saveButton, &QPushButton::clicked, this, [this, cfgMan,
lightRadioButton,
fontComboBox,
spinBox, parent]() {
if (lightRadioButton->isChecked()) {
cfgMan->mAppTheme = "light";
}
else { // Dark
cfgMan->mAppTheme = "dark";
}
cfgMan->mFontFamily = fontComboBox->currentFont().family();
cfgMan->mAutosaveIntervalMin = spinBox->value();
cfgMan->saveConfig(static_cast<MainMenu*>(parent)->mCfgDir);
static_cast<MainMenu*>(parent)->setTheme();
QString req = static_cast<MainMenu*>(parent)->mSearchBox->text();
static_cast<MainMenu*>(parent)->buildList(req);
parent->show();
this->hide();
delete this;
});
}
void Settings::closeEvent(QCloseEvent* event) {
QString req = static_cast<MainMenu*>(mParent)->mSearchBox->text();
static_cast<MainMenu*>(mParent)->buildList(req);
mParent->show();
this->hide();
delete this;
}
Settings::Settings(QWidget* parent, ConfigMan* cfgMan) : QWidget(nullptr) {
mParent = parent;
makeUI(parent, cfgMan);
this->setObjectName("settings");
this->setGeometry(parent->geometry());
}