2017-06-22 17:41:29 +02:00
|
|
|
#include "settingsdialog.hpp"
|
2017-07-05 12:05:55 +02:00
|
|
|
#include "filenamevalidator.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-07-02 22:31:27 +02:00
|
|
|
#include <QComboBox>
|
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>
|
2019-05-11 15:00:12 +02:00
|
|
|
#include <clipboard/clipboardcopy.hpp>
|
2017-06-22 17:41:29 +02:00
|
|
|
|
2017-07-29 17:22:17 +02:00
|
|
|
static QMap<QString, std::function<void()>> fncs;
|
2017-06-22 17:41:29 +02:00
|
|
|
|
|
|
|
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-07-04 22:35:34 +02:00
|
|
|
setScheme(settings::settings().value("fileFormat", "Screenshot %(yyyy-MM-dd HH-mm-ss)date.%ext").toString());
|
2017-06-22 23:21:15 +02:00
|
|
|
|
2019-05-15 23:34:45 +02:00
|
|
|
ui->folderFormat->setText(settings::settings().value("folderFormat", "%(yyyy-MM)date").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);
|
|
|
|
|
2017-07-29 17:22:17 +02:00
|
|
|
addHotkeyItem(ui->hotkeys, tr("Fullscreen image"), "fullscreen", [] { screenshotter::fullscreen(); });
|
|
|
|
addHotkeyItem(ui->hotkeys, tr("Area image"), "area", [] { screenshotter::area(); });
|
2017-06-27 11:33:11 +02:00
|
|
|
#ifdef PLATFORM_CAPABILITY_ACTIVEWINDOW
|
2017-07-29 17:22:17 +02:00
|
|
|
addHotkeyItem(ui->hotkeys, tr("Active window"), "active", [&] { screenshotter::active(); });
|
2017-06-27 11:33:11 +02:00
|
|
|
#endif
|
2019-05-11 20:29:51 +02:00
|
|
|
addHotkeyItem(ui->hotkeys, tr("Copy from Clipboard"), "clipboard", [] { clipboardcopy::copyClipboard(); });
|
2017-07-29 17:22:17 +02:00
|
|
|
addHotkeyItem(ui->hotkeys, tr("Color picker"), "picker", [] { ColorPickerScene::showPicker(); });
|
|
|
|
addHotkeyItem(ui->hotkeys, tr("Stop Recording"), "recordingstop", [&] { MainWindow::inst()->controller->end(); });
|
|
|
|
addHotkeyItem(ui->hotkeys, tr("Start Recording"), "recordingstart", [&] { MainWindow::inst()->rec(); });
|
2017-06-22 17:41:29 +02:00
|
|
|
|
|
|
|
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());
|
2017-07-02 22:31:27 +02:00
|
|
|
ui->saveLocation->setCurrentIndex(settings::settings().value("saveLocation", 1).toInt());
|
2017-06-22 17:41:29 +02:00
|
|
|
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());
|
2017-07-03 22:37:00 +02:00
|
|
|
ui->cropX->setValue(settings::settings().value("cropx", 0).toInt());
|
|
|
|
ui->cropY->setValue(settings::settings().value("cropy", 0).toInt());
|
2017-06-22 17:41:29 +02:00
|
|
|
setWindowTitle("Settings");
|
2017-07-05 12:05:55 +02:00
|
|
|
ui->nameScheme->setValidator(new FilenameValidator(ui->nameScheme));
|
2017-06-27 11:33:11 +02:00
|
|
|
#ifndef PLATFORM_CAPABILITY_CURSOR
|
|
|
|
ui->captureCursor->setEnabled(false);
|
2017-07-29 17:22:17 +02:00
|
|
|
ui->captureCursor->setText(tr("Capture cursor (disabled: implementation missing)"));
|
2017-06-27 11:33:11 +02:00
|
|
|
#endif
|
2017-09-05 18:26:17 +02:00
|
|
|
ui->fpsMax->setValue(settings::settings().value("recording/framerate", 30).toInt());
|
2017-12-17 19:59:16 +01:00
|
|
|
ui->focusedCapture->setText(settings::settings().value("command/activeCommand", "").toString());
|
2017-12-20 01:19:07 +01:00
|
|
|
ui->fullscreenCapture->setText(settings::settings().value("command/fullscreenCommand", "").toString());
|
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);
|
|
|
|
}
|
|
|
|
|
2019-05-15 23:34:45 +02:00
|
|
|
void SettingsDialog::on_folderFormat_textChanged(const QString &arg1) {
|
|
|
|
settings::settings().setValue("folderFormat", 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();
|
|
|
|
}
|
2017-07-02 22:31:27 +02:00
|
|
|
|
|
|
|
void SettingsDialog::on_saveLocation_currentIndexChanged(int index) {
|
|
|
|
settings::settings().setValue("saveLocation", index);
|
|
|
|
}
|
2017-07-03 21:29:03 +02:00
|
|
|
|
|
|
|
void SettingsDialog::on_cropX_valueChanged(int arg1) {
|
|
|
|
settings::settings().setValue("cropx", arg1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::on_cropY_valueChanged(int arg1) {
|
|
|
|
settings::settings().setValue("cropy", arg1);
|
|
|
|
}
|
2017-09-05 18:26:17 +02:00
|
|
|
|
2017-12-17 19:59:16 +01:00
|
|
|
void SettingsDialog::on_focusedCapture_textChanged(QString arg1) {
|
|
|
|
settings::settings().setValue("command/activeCommand", arg1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::on_fullscreenCapture_textChanged(QString arg1) {
|
|
|
|
settings::settings().setValue("command/fullscreenCommand", arg1);
|
|
|
|
}
|
|
|
|
|
2017-09-05 18:26:17 +02:00
|
|
|
void SettingsDialog::on_fpsMax_valueChanged(int arg1) {
|
|
|
|
settings::settings().setValue("recording/framerate", arg1);
|
|
|
|
}
|