-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsDialog.cpp
More file actions
143 lines (118 loc) · 4.75 KB
/
SettingsDialog.cpp
File metadata and controls
143 lines (118 loc) · 4.75 KB
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
#include "SettingsDialog.h"
#include <QVBoxLayout>
#include <QDialogButtonBox>
#include <QFormLayout>
#include <QSpinBox>
#include <QFontDialog>
#include <QFileDialog>
#include <QFileDevice>
#include <QCheckBox>
#include <QPushButton>
#include <QSettings>
#include <QMessageBox>
#include <QLineEdit>
SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent) {
setWindowTitle("Settings");
QVBoxLayout *mainLayout = new QVBoxLayout(this);
QFormLayout *formLayout = new QFormLayout;
// Sets the labels to be aligned to the left, so they're not all willy nilly.
formLayout->setLabelAlignment(Qt::AlignLeft);
// Font picker
fontButton = new QPushButton("Choose Font");
connect(fontButton, &QPushButton::clicked, this, &SettingsDialog::chooseFont);
formLayout->addRow("Font:", fontButton);
// Tab Size
tabSizeSpin = new QSpinBox;
tabSizeSpin->setRange(2, 16);
formLayout->addRow("Tab Size:", tabSizeSpin);
// Checkbox for session restoration
restoreSessionCheck = new QCheckBox("Restore previous session");
formLayout->addRow(restoreSessionCheck);
// RSA key fields, done in a compact grid
QLabel *rsaPublicLabel = new QLabel("RSA Public Key:", this);
rsaPublicKeyEdit = new QLineEdit(this);
browseRSAPublicKeyButton = new QPushButton("Browse...", this);
QLabel *rsaPrivateLabel = new QLabel("RSA Private Key:", this);
rsaPrivateKeyEdit = new QLineEdit(this);
browseRSAPrivateKeyButton = new QPushButton("Browse...", this);
QGridLayout *rsaGrid = new QGridLayout;
rsaGrid->setVerticalSpacing(4);
rsaGrid->setHorizontalSpacing(8);
rsaGrid->addWidget(rsaPublicLabel, 0, 0);
rsaGrid->addWidget(rsaPublicKeyEdit, 0, 1);
rsaGrid->addWidget(browseRSAPublicKeyButton, 0, 2);
rsaGrid->addWidget(rsaPrivateLabel, 1, 0);
rsaGrid->addWidget(rsaPrivateKeyEdit, 1, 1);
rsaGrid->addWidget(browseRSAPrivateKeyButton, 1, 2);
// Wrap the grid layout in a QWidget so it can be added to formLayout as one row
QWidget *rsaWidget = new QWidget(this);
rsaWidget->setLayout(rsaGrid);
// Now insert into the form layout
formLayout->addRow(rsaWidget);
mainLayout->addLayout(formLayout);
// Clearing recent files and resetting UI, to help with any potential issues
QHBoxLayout *buttonLayout = new QHBoxLayout;
clearRecentFilesButton = new QPushButton("Clear Recent Files");
resetUILayoutButton = new QPushButton("Reset UI");
buttonLayout->addWidget(clearRecentFilesButton);
buttonLayout->addWidget(resetUILayoutButton);
mainLayout->addLayout(buttonLayout);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, &QDialogButtonBox::accepted, this, &SettingsDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &SettingsDialog::reject);
mainLayout->addWidget(buttonBox);
connect(clearRecentFilesButton, &QPushButton::clicked, this, [this]() {
if (QMessageBox::question(this, "Confirm", "Clear recent files list?") == QMessageBox::Yes)
emit clearRecentFiles();
});
connect(resetUILayoutButton, &QPushButton::clicked, this, [this]() {
if (QMessageBox::question(this, "Confirm", "Reset UI layout to default?") == QMessageBox::Yes) {
QFont defaultFont = QFont("Monospace", 10);
int defaultTabSize = 4;
selectedFont = defaultFont;
fontButton->setText(selectedFont.family());
tabSizeSpin->setValue(defaultTabSize);
emit resetUILayout();
}
});
}
// Functions for passing info to and from the main window
void SettingsDialog::chooseFont() {
bool ok;
QFont selected = QFontDialog::getFont(&ok, selectedFont, this);
if (ok) {
selectedFont = selected;
fontButton->setText(selectedFont.family());
}
}
void SettingsDialog::setFont(const QFont &f) {
selectedFont = f;
fontButton->setText(selectedFont.family());
}
QFont SettingsDialog::getFont() const {
return selectedFont;
}
int SettingsDialog::getTabSize() const {
return tabSizeSpin->value();
}
void SettingsDialog::setTabSize(int size) {
tabSizeSpin->setValue(size);
}
bool SettingsDialog::shouldRestoreSession() const {
return restoreSessionCheck->isChecked();
}
void SettingsDialog::setRestoreSession(bool restore) {
restoreSessionCheck->setChecked(restore);
}
QString SettingsDialog::getRSAPublicKeyPath() const {
return rsaPublicKeyEdit->text();
}
QString SettingsDialog::getRSAPrivateKeyPath() const {
return rsaPrivateKeyEdit->text();
}
void SettingsDialog::setRSAPublicKeyPath(const QString &path) {
rsaPublicKeyEdit->setText(path);
}
void SettingsDialog::setRSAPrivateKeyPath(const QString &path) {
rsaPrivateKeyEdit->setText(path);
}