-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSettingsDialog.cpp
More file actions
125 lines (105 loc) · 3.96 KB
/
Copy pathSettingsDialog.cpp
File metadata and controls
125 lines (105 loc) · 3.96 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
#include "SettingsDialog.h"
#include <QCheckBox>
#include <QDialogButtonBox>
#include <QFileDialog>
#include <QFileInfo>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QMessageBox>
#include <QPushButton>
#include <QSpinBox>
#include <QVBoxLayout>
namespace {
constexpr int kMinFontSize = 8;
constexpr int kMaxFontSize = 24;
}
SettingsDialog::SettingsDialog(int uiFontSize, int editorFontSize, bool confirmDestructive,
const QString& defaultDir, QWidget* parent)
: QDialog(parent)
{
setWindowTitle("Settings");
resize(420, 280);
auto* layout = new QVBoxLayout(this);
auto* appearanceLabel = new QLabel("APPEARANCE", this);
appearanceLabel->setObjectName("sectionLabel");
layout->addWidget(appearanceLabel);
auto* uiFontRow = new QHBoxLayout();
uiFontRow->addWidget(new QLabel("UI font size:", this));
m_uiFontSizeSpin = new QSpinBox(this);
m_uiFontSizeSpin->setRange(kMinFontSize, kMaxFontSize);
m_uiFontSizeSpin->setValue(uiFontSize);
m_uiFontSizeSpin->setSuffix(" px");
uiFontRow->addWidget(m_uiFontSizeSpin);
uiFontRow->addStretch();
layout->addLayout(uiFontRow);
auto* editorFontRow = new QHBoxLayout();
editorFontRow->addWidget(new QLabel("SQL editor font size:", this));
m_editorFontSizeSpin = new QSpinBox(this);
m_editorFontSizeSpin->setRange(kMinFontSize, kMaxFontSize);
m_editorFontSizeSpin->setValue(editorFontSize);
m_editorFontSizeSpin->setSuffix(" px");
editorFontRow->addWidget(m_editorFontSizeSpin);
editorFontRow->addStretch();
layout->addLayout(editorFontRow);
layout->addSpacing(10);
auto* behaviorLabel = new QLabel("BEHAVIOR", this);
behaviorLabel->setObjectName("sectionLabel");
layout->addWidget(behaviorLabel);
m_confirmDestructiveCheck = new QCheckBox("Ask for confirmation before Drop Table / Drop Index", this);
m_confirmDestructiveCheck->setChecked(confirmDestructive);
layout->addWidget(m_confirmDestructiveCheck);
layout->addSpacing(10);
auto* filesLabel = new QLabel("FILES", this);
filesLabel->setObjectName("sectionLabel");
layout->addWidget(filesLabel);
auto* dirRow = new QHBoxLayout();
m_defaultDirEdit = new QLineEdit(defaultDir, this);
m_defaultDirEdit->setPlaceholderText("Last used folder (default)");
dirRow->addWidget(m_defaultDirEdit, 1);
auto* browseBtn = new QPushButton("Browse…", this);
dirRow->addWidget(browseBtn);
layout->addLayout(dirRow);
auto* dirHint = new QLabel("Starting folder for Open/New/Export/Import dialogs.", this);
dirHint->setStyleSheet("color: #888780; font-size: 10px;");
layout->addWidget(dirHint);
layout->addStretch(1);
auto* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
buttons->button(QDialogButtonBox::Ok)->setText("Save");
layout->addWidget(buttons);
connect(browseBtn, &QPushButton::clicked, this, &SettingsDialog::browseForDir);
connect(buttons, &QDialogButtonBox::accepted, this, &SettingsDialog::accept);
connect(buttons, &QDialogButtonBox::rejected, this, &SettingsDialog::reject);
}
void SettingsDialog::browseForDir()
{
const QString chosen = QFileDialog::getExistingDirectory(this, "Default Folder", m_defaultDirEdit->text());
if (!chosen.isEmpty()) {
m_defaultDirEdit->setText(chosen);
}
}
int SettingsDialog::uiFontSize() const
{
return m_uiFontSizeSpin->value();
}
int SettingsDialog::editorFontSize() const
{
return m_editorFontSizeSpin->value();
}
bool SettingsDialog::confirmDestructive() const
{
return m_confirmDestructiveCheck->isChecked();
}
QString SettingsDialog::defaultDir() const
{
return m_defaultDirEdit->text().trimmed();
}
void SettingsDialog::accept()
{
const QString dir = defaultDir();
if (!dir.isEmpty() && !QFileInfo(dir).isDir()) {
QMessageBox::warning(this, "Settings", "\"" + dir + "\" is not a valid folder.");
return;
}
QDialog::accept();
}