-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsettingdialog.cpp
84 lines (70 loc) · 2.44 KB
/
settingdialog.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
#include <QSettings>
#include <QFile>
#include <QDir>
#include <QShortcut>
#include "settingdialog.h"
#include "ui_settingdialog.h"
SettingDialog::SettingDialog(QWidget *parent)
: QDialog(parent),
ui(new Ui::SettingDialog)
{
ui->setupUi(this);
// load settings
loadSettings();
connect(ui->closeButton, SIGNAL(clicked()),
this, SLOT(close()));
connect(ui->autostartCheckBox, SIGNAL(toggled(bool)),
this, SLOT(slotToggleAutostart(bool)));
connect(ui->toggleVisibleShortcutEdit, SIGNAL(shortcutChanged(QKeySequence)),
this, SIGNAL(toggleVisibleShortcutChanged(QKeySequence)));
connect(ui->toggleVisibleShortcutEdit, SIGNAL(shortcutChanged(QKeySequence)),
this, SLOT(slotToggleVisibleShortcutChanged(QKeySequence)));
connect(ui->searchSelectedShortcutEdit, SIGNAL(shortcutChanged(QKeySequence)),
this, SIGNAL(searchSelectedShortcutChanged(QKeySequence)));
connect(ui->searchSelectedShortcutEdit, SIGNAL(shortcutChanged(QKeySequence)),
this, SLOT(slotSearchSelectedShortcutChanged(QKeySequence)));
// Esc
QShortcut *escShortcut = new QShortcut(QKeySequence(Qt::Key_Escape), this, SLOT(close()));
(void)escShortcut;
}
SettingDialog::~SettingDialog()
{
delete ui;
}
/**
* @brief Toggle autostart
*/
void SettingDialog::slotToggleAutostart(bool checked)
{
QSettings settings;
settings.setValue("Autostart", checked);
if (checked) {
QFile::copy(":/thindict.desktop", QDir::homePath() + "/.config/autostart/thindict.desktop");
} else {
QDir dir(QDir::homePath() + "/.config/autostart");
dir.remove("thindict.desktop");
}
}
void SettingDialog::slotToggleVisibleShortcutChanged(const QKeySequence &key)
{
QSettings settings;
settings.setValue("ToggleVisibleShortcut", key.toString());
}
void SettingDialog::slotSearchSelectedShortcutChanged(const QKeySequence &key)
{
QSettings settings;
settings.setValue("SearchSelectedShortcut", key.toString());
}
/**
* @brief Load settings
*/
void SettingDialog::loadSettings()
{
QSettings settings;
ui->autostartCheckBox->setChecked(
settings.value("Autostart", false).toBool());
ui->toggleVisibleShortcutEdit->setKey(
QKeySequence(settings.value("ToggleVisibleShortcut").toString()));
ui->searchSelectedShortcutEdit->setKey(
QKeySequence(settings.value("SearchSelectedShortcut").toString()));
}