2017-06-22 17:41:29 +02:00
|
|
|
#include "settingsdialog.hpp"
|
2017-06-27 12:46:35 +02:00
|
|
|
#include "hotkeyinputdialog.hpp"
|
2017-06-22 17:41:29 +02:00
|
|
|
#include "mainwindow.hpp"
|
|
|
|
#include "ui_settingsdialog.h"
|
|
|
|
|
2017-06-27 11:33:11 +02:00
|
|
|
#include <QCheckBox>
|
2017-06-22 17:41:29 +02:00
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QInputDialog>
|
|
|
|
#include <QListWidget>
|
|
|
|
#include <QListWidgetItem>
|
|
|
|
#include <QStandardPaths>
|
|
|
|
#include <colorpicker/colorpickerscene.hpp>
|
|
|
|
#include <formats.hpp>
|
|
|
|
#include <hotkeying.hpp>
|
2017-06-27 11:33:11 +02:00
|
|
|
#include <platformbackend.hpp>
|
2017-06-22 17:41:29 +02:00
|
|
|
#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
|
2017-06-30 15:05:37 +02:00
|
|
|
connect(&UploaderSingleton::inst(), &UploaderSingleton::newUploader, this, &SettingsDialog::newUploader);
|
|
|
|
connect(&UploaderSingleton::inst(), &UploaderSingleton::uploaderChanged, this, &SettingsDialog::uploaderChanged);
|
2017-06-22 17:41:29 +02:00
|
|
|
for (Uploader *u : UploaderSingleton::inst().uploaderList()) newUploader(u);
|
|
|
|
|
|
|
|
// Set filename scheme
|
2017-06-22 23:21:15 +02:00
|
|
|
setScheme(settings::settings().value("fileFormat", "Screenshot %(yyyy-MM-dd HH:mm:ss)date.ext").toString());
|
|
|
|
|
2017-06-22 17:41:29 +02:00
|
|
|
// 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(); });
|
2017-06-27 11:33:11 +02:00
|
|
|
#ifdef PLATFORM_CAPABILITY_ACTIVEWINDOW
|
|
|
|
addHotkeyItem(ui->hotkeys, "Active window", "active", [&] { screenshotter::active(); });
|
|
|
|
#endif
|
2017-06-22 17:41:29 +02:00
|
|
|
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());
|
|
|
|
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());
|
|
|
|
setWindowTitle("Settings");
|
2017-06-27 11:33:11 +02:00
|
|
|
#ifndef PLATFORM_CAPABILITY_CURSOR
|
|
|
|
ui->captureCursor->setEnabled(false);
|
|
|
|
ui->captureCursor->setText("Capture cursor (disabled: implementation missing)");
|
|
|
|
#endif
|
2017-06-22 17:41:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2017-06-23 14:39:51 +02:00
|
|
|
if (UploaderSingleton::inst().currentUploader() == u->name()) ui->uploaderList->setCurrentItem(uploader);
|
2017-06-22 17:41:29 +02:00
|
|
|
}
|
|
|
|
|
2017-06-30 15:05:37 +02:00
|
|
|
void SettingsDialog::uploaderChanged(QString newName) {
|
|
|
|
for (auto item : ui->uploaderList->findItems(newName, Qt::MatchCaseSensitive))
|
|
|
|
ui->uploaderList->setCurrentItem(item);
|
|
|
|
}
|
|
|
|
|
2017-06-22 17:41:29 +02:00
|
|
|
void SettingsDialog::on_uploaderList_clicked(const QModelIndex &) {
|
2017-06-30 15:05:37 +02:00
|
|
|
UploaderSingleton::inst().set(ui->uploaderList->currentItem()->text());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::on_uploaderList_doubleClicked(const QModelIndex &) {
|
|
|
|
UploaderSingleton::inst().showSettings();
|
2017-06-22 17:41:29 +02:00
|
|
|
}
|
|
|
|
|
2017-06-22 23:21:15 +02:00
|
|
|
void SettingsDialog::on_nameScheme_textChanged(const QString &arg1) {
|
|
|
|
settings::settings().setValue("fileFormat", arg1);
|
|
|
|
}
|
|
|
|
|
2017-06-22 17:41:29 +02:00
|
|
|
void SettingsDialog::on_delay_valueChanged(double arg1) {
|
|
|
|
settings::settings().setValue("delay", arg1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::on_hotkeys_doubleClicked(const QModelIndex &) {
|
2017-06-30 15:05:37 +02:00
|
|
|
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();
|
2017-06-22 17:41:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|