forked from ArsenArsen/KShare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settingsdialog.cpp
171 lines (139 loc) · 6.63 KB
/
settingsdialog.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
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
#include "settingsdialog.hpp"
#include "hotkeyinputdialog.hpp"
#include "mainwindow.hpp"
#include "ui_settingsdialog.h"
#include <QCheckBox>
#include <QComboBox>
#include <QDesktopServices>
#include <QInputDialog>
#include <QListWidget>
#include <QListWidgetItem>
#include <QStandardPaths>
#include <colorpicker/colorpickerscene.hpp>
#include <formats.hpp>
#include <hotkeying.hpp>
#include <platformbackend.hpp>
#include <recording/encoders/encodersettingsdialog.hpp>
#include <screenshotter.hpp>
#include <settings.hpp>
#include <uploaders/uploadersingleton.hpp>
QMap<QString, std::function<void()>> fncs;
void addHotkeyItem(QListWidget *hotkeys, QString text, QString name, std::function<void()> func, QString def = QString()) {
QListWidgetItem *item = new QListWidgetItem(text, hotkeys);
item->setData(Qt::UserRole + 1, name);
hotkeys->addItem(item);
fncs.insert(name, func);
hotkeying::load(name, func, def);
}
SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::SettingsDialog) {
ui->setupUi(this);
ui->uploaderList->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->uploaderList->setSelectionMode(QAbstractItemView::SingleSelection);
// Add items to uploader selection
connect(&UploaderSingleton::inst(), &UploaderSingleton::newUploader, this, &SettingsDialog::newUploader);
connect(&UploaderSingleton::inst(), &UploaderSingleton::uploaderChanged, this, &SettingsDialog::uploaderChanged);
for (Uploader *u : UploaderSingleton::inst().uploaderList()) newUploader(u);
// Set filename scheme
setScheme(settings::settings().value("fileFormat", "Screenshot %(yyyy-MM-dd HH:mm:ss)date.%ext").toString());
// Set delay
if ((settings::settings().contains("delay")))
ui->delay->setValue(settings::settings().value("delay").toDouble());
else
ui->delay->setValue(0.25);
ui->hotkeys->setSelectionMode(QListWidget::SingleSelection);
addHotkeyItem(ui->hotkeys, "Fullscreen image", "fullscreen", [] { screenshotter::fullscreen(); });
addHotkeyItem(ui->hotkeys, "Area image", "area", [] { screenshotter::area(); });
#ifdef PLATFORM_CAPABILITY_ACTIVEWINDOW
addHotkeyItem(ui->hotkeys, "Active window", "active", [&] { screenshotter::active(); });
#endif
addHotkeyItem(ui->hotkeys, "Color picker", "picker", [] { ColorPickerScene::showPicker(); });
addHotkeyItem(ui->hotkeys, "Stop Recording", "recordingstop", [&] { MainWindow::inst()->controller->end(); });
addHotkeyItem(ui->hotkeys, "Start Recording", "recordingstart", [&] { MainWindow::inst()->rec(); });
ui->quickMode->setChecked(settings::settings().value("quickMode", false).toBool());
ui->hideToTray->setChecked(settings::settings().value("hideOnClose", true).toBool());
ui->captureCursor->setChecked(settings::settings().value("captureCursor", true).toBool());
ui->saveLocation->setCurrentIndex(settings::settings().value("saveLocation", 1).toInt());
for (int i = 0; i < (int)formats::Recording::None; i++) {
ui->formatBox->addItem(formats::recordingFormatName(static_cast<formats::Recording>(i)));
}
for (int i = 0; i < (int)formats::Normal::None; i++) {
ui->imageFormatBox->addItem(formats::normalFormatName(static_cast<formats::Normal>(i)));
}
ui->formatBox->addItem("None");
ui->formatBox->setCurrentIndex(settings::settings().value("recording/format", (int)formats::Recording::None).toInt());
ui->cropX->setValue(settings::settings().value("cropx", 0).toInt());
ui->cropY->setValue(settings::settings().value("cropy", 0).toInt());
setWindowTitle("Settings");
#ifndef PLATFORM_CAPABILITY_CURSOR
ui->captureCursor->setEnabled(false);
ui->captureCursor->setText("Capture cursor (disabled: implementation missing)");
#endif
}
void SettingsDialog::setScheme(QString scheme) {
ui->nameScheme->setText(scheme);
}
SettingsDialog::~SettingsDialog() {
delete ui;
}
void SettingsDialog::newUploader(Uploader *u) {
QListWidgetItem *uploader = new QListWidgetItem(u->name(), ui->uploaderList);
uploader->setToolTip(u->description());
ui->uploaderList->addItem(uploader);
if (UploaderSingleton::inst().currentUploader() == u->name()) ui->uploaderList->setCurrentItem(uploader);
}
void SettingsDialog::uploaderChanged(QString newName) {
for (auto item : ui->uploaderList->findItems(newName, Qt::MatchCaseSensitive))
ui->uploaderList->setCurrentItem(item);
}
void SettingsDialog::on_uploaderList_clicked(const QModelIndex &) {
UploaderSingleton::inst().set(ui->uploaderList->currentItem()->text());
}
void SettingsDialog::on_uploaderList_doubleClicked(const QModelIndex &) {
UploaderSingleton::inst().showSettings();
}
void SettingsDialog::on_nameScheme_textChanged(const QString &arg1) {
settings::settings().setValue("fileFormat", arg1);
}
void SettingsDialog::on_delay_valueChanged(double arg1) {
settings::settings().setValue("delay", arg1);
}
void SettingsDialog::on_hotkeys_doubleClicked(const QModelIndex &) {
QListWidgetItem *i = ui->hotkeys->currentItem();
QString str = i->data(Qt::UserRole + 1).toString();
HotkeyInputDialog *hotkey = new HotkeyInputDialog(str, hotkeying::sequence(str), this);
connect(hotkey, &HotkeyInputDialog::sequenceSelected,
[&](QKeySequence seq, QString name) { hotkeying::hotkey(name, seq, fncs.value(name)); });
hotkey->show();
}
void SettingsDialog::on_settingsButton_clicked() {
QDesktopServices::openUrl(QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/KShare"));
}
void SettingsDialog::on_quickMode_clicked(bool checked) {
settings::settings().setValue("quickMode", checked);
}
void SettingsDialog::on_hideToTray_clicked(bool checked) {
settings::settings().setValue("hideOnClose", checked);
}
void SettingsDialog::on_captureCursor_clicked(bool checked) {
settings::settings().setValue("captureCursor", checked);
}
void SettingsDialog::on_formatBox_currentIndexChanged(int index) {
if (isVisible()) settings::settings().setValue("recording/format", index);
}
void SettingsDialog::on_imageFormatBox_currentIndexChanged(int index) {
if (isVisible()) settings::settings().setValue("imageformat", index);
}
void SettingsDialog::on_pushButton_clicked() {
auto a = new EncoderSettingsDialog();
a->setAttribute(Qt::WA_DeleteOnClose);
a->show();
}
void SettingsDialog::on_saveLocation_currentIndexChanged(int index) {
settings::settings().setValue("saveLocation", index);
}
void SettingsDialog::on_cropX_valueChanged(int arg1) {
settings::settings().setValue("cropx", arg1);
}
void SettingsDialog::on_cropY_valueChanged(int arg1) {
settings::settings().setValue("cropy", arg1);
}