2017-04-23 15:05:48 +02:00
|
|
|
#include "mainwindow.hpp"
|
|
|
|
#include "screenshotter.hpp"
|
|
|
|
#include "screenshotutil.hpp"
|
|
|
|
#include "ui_mainwindow.h"
|
|
|
|
#include <QAction>
|
2017-05-15 14:42:40 +02:00
|
|
|
#include <QApplication>
|
2017-05-13 19:19:56 +02:00
|
|
|
#include <QCheckBox>
|
2017-04-23 15:05:48 +02:00
|
|
|
#include <QCloseEvent>
|
2017-06-06 13:38:15 +02:00
|
|
|
#include <QComboBox>
|
2017-04-23 15:05:48 +02:00
|
|
|
#include <QCoreApplication>
|
2017-05-13 19:19:56 +02:00
|
|
|
#include <QDesktopServices>
|
2017-04-25 22:36:33 +02:00
|
|
|
#include <QDoubleSpinBox>
|
2017-04-26 23:26:00 +02:00
|
|
|
#include <QInputDialog>
|
2017-04-23 15:05:48 +02:00
|
|
|
#include <QListWidgetItem>
|
|
|
|
#include <QMenu>
|
2017-04-25 16:04:46 +02:00
|
|
|
#include <QStatusBar>
|
2017-04-23 15:05:48 +02:00
|
|
|
#include <QSystemTrayIcon>
|
|
|
|
#include <QTimer>
|
2017-05-16 15:52:15 +02:00
|
|
|
#include <colorpicker/colorpickerscene.hpp>
|
2017-04-26 22:00:13 +02:00
|
|
|
#include <functional>
|
|
|
|
#include <hotkeying.hpp>
|
2017-06-06 01:26:26 +02:00
|
|
|
#include <recording/recordingformats.hpp>
|
2017-04-23 20:29:24 +02:00
|
|
|
#include <settings.hpp>
|
2017-04-23 15:05:48 +02:00
|
|
|
#include <uploaders/uploadersingleton.hpp>
|
|
|
|
|
2017-04-25 22:17:36 +02:00
|
|
|
MainWindow *MainWindow::instance;
|
|
|
|
|
2017-06-04 01:04:42 +02:00
|
|
|
void addHotkeyItem(QString text, QString name, std::function<void()> func, QString def = QString()) {
|
2017-05-09 17:26:00 +02:00
|
|
|
QListWidgetItem *item = new QListWidgetItem(text, MainWindow::inst()->ui->hotkeys);
|
|
|
|
item->setData(Qt::UserRole + 1, name);
|
|
|
|
MainWindow::inst()->fncs.insert(name, func);
|
2017-06-04 01:04:42 +02:00
|
|
|
hotkeying::load(name, func, def);
|
2017-05-09 17:26:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
|
|
|
|
instance = this;
|
|
|
|
ui->setupUi(this);
|
|
|
|
setWindowIcon(QIcon(":/icons/icon.png"));
|
|
|
|
tray = new QSystemTrayIcon(windowIcon(), this);
|
|
|
|
tray->setToolTip("KShare");
|
|
|
|
tray->setVisible(true);
|
|
|
|
QMenu *menu = new QMenu(this);
|
|
|
|
QAction *quit = new QAction("Quit", this);
|
|
|
|
QAction *shtoggle = new QAction("Show/Hide", this);
|
|
|
|
QAction *fullscreen = new QAction("Take fullscreen shot", this);
|
|
|
|
QAction *area = new QAction("Take area shot", this);
|
2017-05-16 15:52:15 +02:00
|
|
|
QAction *picker = new QAction("Show color picker", this);
|
|
|
|
menu->addActions({ quit, shtoggle, picker });
|
2017-05-09 17:26:00 +02:00
|
|
|
menu->addSeparator();
|
|
|
|
menu->addActions({ fullscreen, area });
|
|
|
|
connect(quit, &QAction::triggered, this, &MainWindow::quit);
|
|
|
|
connect(shtoggle, &QAction::triggered, this, &MainWindow::toggleVisible);
|
2017-05-16 19:16:09 +02:00
|
|
|
connect(picker, &QAction::triggered, [] { ColorPickerScene::showPicker(); });
|
2017-05-09 17:26:00 +02:00
|
|
|
connect(tray, &QSystemTrayIcon::messageClicked, this, &MainWindow::toggleVisible);
|
|
|
|
connect(tray, &QSystemTrayIcon::activated, this, [this](QSystemTrayIcon::ActivationReason reason) {
|
|
|
|
if (reason == QSystemTrayIcon::DoubleClick) toggleVisible();
|
|
|
|
});
|
|
|
|
connect(fullscreen, &QAction::triggered, this, [] { screenshotter::fullscreenDelayed(); });
|
|
|
|
connect(area, &QAction::triggered, this, [] { screenshotter::areaDelayed(); });
|
|
|
|
tray->setContextMenu(menu);
|
|
|
|
|
|
|
|
ui->uploaderList->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
ui->uploaderList->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
|
|
|
|
// Add items to uploader selection
|
|
|
|
for (Uploader *u : UploaderSingleton::inst().uploaderList()) newUploader(u);
|
|
|
|
connect(&UploaderSingleton::inst(), &UploaderSingleton::newUploader, this, &MainWindow::newUploader);
|
|
|
|
|
|
|
|
// Set filename scheme
|
|
|
|
if ((settings::settings().contains("fileFormat")))
|
|
|
|
setScheme(settings::settings().value("fileFormat").toString());
|
|
|
|
else
|
|
|
|
setScheme("Screenshot %(yyyy-MM-dd HH:mm:ss)date");
|
|
|
|
|
|
|
|
auto errors = UploaderSingleton::inst().errors();
|
|
|
|
if (errors.length() == 1)
|
|
|
|
statusBar()->showMessage(errors.at(0).what());
|
|
|
|
else
|
|
|
|
statusBar()->showMessage(QString("Errors visible in console (if present). Count: " + QString::number(errors.size())));
|
|
|
|
|
|
|
|
// 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-06-04 01:04:42 +02:00
|
|
|
addHotkeyItem("Fullscreen image", "fullscreen", [] { screenshotter::fullscreen(); });
|
|
|
|
addHotkeyItem("Area image", "area", [] { screenshotter::area(); });
|
|
|
|
addHotkeyItem("Color picker", "picker", [] { ColorPickerScene::showPicker(); });
|
|
|
|
addHotkeyItem("Stop Recording", "recordingstop", [&] { controller->end(); });
|
2017-06-06 01:26:26 +02:00
|
|
|
addHotkeyItem("Start Recording", "recordingstart", [&] {
|
2017-06-06 17:05:34 +02:00
|
|
|
auto f
|
|
|
|
= static_cast<formats::Recording>(settings::settings().value("recording/format", (int)formats::Recording::None).toInt());
|
|
|
|
if (f >= formats::Recording::None) return;
|
2017-06-06 01:26:26 +02:00
|
|
|
RecordingContext *ctx = new RecordingContext;
|
2017-06-06 13:38:15 +02:00
|
|
|
RecordingFormats *format = new RecordingFormats(f);
|
2017-06-06 01:26:26 +02:00
|
|
|
ctx->consumer = format->getConsumer();
|
|
|
|
ctx->finalizer = format->getFinalizer();
|
|
|
|
ctx->validator = format->getValidator();
|
|
|
|
ctx->format = format->getFormat();
|
2017-06-13 18:23:33 +02:00
|
|
|
ctx->postUploadTask = format->getPostUploadTask();
|
2017-06-06 17:05:34 +02:00
|
|
|
ctx->anotherFormat = format->getAnotherFormat();
|
2017-06-06 01:26:26 +02:00
|
|
|
controller->start(ctx);
|
|
|
|
});
|
2017-05-13 19:19:56 +02:00
|
|
|
|
|
|
|
ui->quickMode->setChecked(settings::settings().value("quickMode", false).toBool());
|
2017-05-15 14:42:40 +02:00
|
|
|
ui->hideToTray->setChecked(settings::settings().value("hideOnClose", true).toBool());
|
2017-05-15 14:10:00 +02:00
|
|
|
ui->captureCursor->setChecked(settings::settings().value("captureCursor", true).toBool());
|
2017-06-06 13:38:15 +02:00
|
|
|
|
2017-06-06 17:05:34 +02:00
|
|
|
for (int i = 0; i < (int)formats::Recording::None; i++) {
|
|
|
|
ui->formatBox->addItem(formats::recordingFormatName(static_cast<formats::Recording>(i)));
|
2017-06-06 13:38:15 +02:00
|
|
|
}
|
2017-06-06 17:05:34 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < (int)formats::Normal::None; i++) {
|
|
|
|
ui->imageFormatBox->addItem(formats::normalFormatName(static_cast<formats::Normal>(i)));
|
|
|
|
}
|
|
|
|
|
2017-06-06 13:38:15 +02:00
|
|
|
ui->formatBox->addItem("None");
|
2017-06-06 17:05:34 +02:00
|
|
|
ui->formatBox->setCurrentIndex(settings::settings().value("recording/format", (int)formats::Recording::None).toInt());
|
2017-05-09 17:26:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow() {
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::setScheme(QString scheme) {
|
|
|
|
ui->nameScheme->setText(scheme);
|
|
|
|
}
|
|
|
|
|
|
|
|
QDoubleSpinBox *MainWindow::delay() {
|
|
|
|
return ui->delay;
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow *MainWindow::inst() {
|
|
|
|
return instance;
|
|
|
|
}
|
2017-05-06 13:21:12 +02:00
|
|
|
|
|
|
|
void MainWindow::closeEvent(QCloseEvent *event) {
|
2017-05-15 14:42:40 +02:00
|
|
|
if (settings::settings().value("hideOnClose", true).toBool()) {
|
|
|
|
event->ignore();
|
|
|
|
QTimer::singleShot(0, this, &MainWindow::hide);
|
|
|
|
} else
|
|
|
|
QApplication::exit(0);
|
2017-05-06 13:21:12 +02:00
|
|
|
}
|
|
|
|
|
2017-05-09 17:26:00 +02:00
|
|
|
void MainWindow::quit() {
|
|
|
|
QCoreApplication::quit();
|
|
|
|
}
|
2017-05-06 13:21:12 +02:00
|
|
|
|
|
|
|
void MainWindow::toggleVisible() {
|
2017-05-09 17:26:00 +02:00
|
|
|
this->setVisible(!this->isVisible());
|
|
|
|
if (this->isVisible()) {
|
2017-05-13 22:39:05 +02:00
|
|
|
this->raise(); // that didn't work
|
|
|
|
this->setWindowState(Qt::WindowActive); // maybe that works
|
|
|
|
this->activateWindow(); // maybe that works
|
2017-05-09 17:26:00 +02:00
|
|
|
}
|
2017-05-06 13:21:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::newUploader(Uploader *u) {
|
2017-05-09 17:26:00 +02:00
|
|
|
QListWidgetItem *item = new QListWidgetItem(u->name());
|
|
|
|
item->setToolTip(u->description());
|
|
|
|
ui->uploaderList->addItem(item);
|
|
|
|
if (u->name() == UploaderSingleton::inst().selectedUploader()) item->setSelected(true);
|
2017-05-06 13:21:12 +02:00
|
|
|
}
|
|
|
|
|
2017-05-09 17:26:00 +02:00
|
|
|
void MainWindow::on_actionQuit_triggered() {
|
|
|
|
quit();
|
|
|
|
}
|
2017-05-06 13:21:12 +02:00
|
|
|
|
|
|
|
void MainWindow::on_actionFullscreen_triggered() {
|
2017-05-09 17:26:00 +02:00
|
|
|
screenshotter::fullscreenDelayed();
|
2017-05-06 13:21:12 +02:00
|
|
|
}
|
|
|
|
|
2017-05-09 17:26:00 +02:00
|
|
|
void MainWindow::on_actionArea_triggered() {
|
|
|
|
screenshotter::areaDelayed();
|
|
|
|
}
|
2017-05-06 13:21:12 +02:00
|
|
|
|
|
|
|
void MainWindow::on_uploaderList_clicked(const QModelIndex &) {
|
2017-05-09 17:26:00 +02:00
|
|
|
QList<QListWidgetItem *> index = ui->uploaderList->selectedItems();
|
|
|
|
if (index.size() == 1) {
|
|
|
|
UploaderSingleton::inst().set(index.at(0)->text());
|
|
|
|
}
|
2017-04-26 22:00:13 +02:00
|
|
|
}
|
|
|
|
|
2017-05-06 13:21:12 +02:00
|
|
|
void MainWindow::on_nameScheme_textEdited(const QString &arg1) {
|
2017-05-09 17:26:00 +02:00
|
|
|
settings::settings().setValue("fileFormat", arg1);
|
2017-04-23 20:29:24 +02:00
|
|
|
}
|
2017-04-25 22:36:33 +02:00
|
|
|
|
2017-05-06 13:21:12 +02:00
|
|
|
void MainWindow::on_delay_valueChanged(double arg1) {
|
2017-05-09 17:26:00 +02:00
|
|
|
settings::settings().setValue("delay", arg1);
|
2017-04-25 22:36:33 +02:00
|
|
|
}
|
2017-04-26 22:00:13 +02:00
|
|
|
|
2017-05-06 13:21:12 +02:00
|
|
|
void MainWindow::on_hotkeys_doubleClicked(const QModelIndex &) {
|
2017-05-09 17:26:00 +02:00
|
|
|
if (ui->hotkeys->selectedItems().length() == 1) {
|
|
|
|
QListWidgetItem *i = ui->hotkeys->selectedItems().at(0);
|
|
|
|
QString str = i->data(Qt::UserRole + 1).toString();
|
2017-05-13 18:50:54 +02:00
|
|
|
bool ok;
|
2017-06-04 01:04:42 +02:00
|
|
|
QString seq = QInputDialog::getText(ui->centralWidget, "Hotkey Input", "Insert hotkey:", QLineEdit::Normal,
|
|
|
|
hotkeying::sequence(str), &ok);
|
|
|
|
if (ok && hotkeying::valid(seq)) hotkeying::hotkey(str, QKeySequence(seq), fncs.value(str));
|
2017-05-09 17:26:00 +02:00
|
|
|
}
|
2017-04-26 22:00:13 +02:00
|
|
|
}
|
2017-05-13 19:19:56 +02:00
|
|
|
|
|
|
|
void MainWindow::on_settingsButton_clicked() {
|
|
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/KShare"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_quickMode_clicked(bool checked) {
|
|
|
|
settings::settings().setValue("quickMode", checked);
|
|
|
|
}
|
2017-05-15 14:42:40 +02:00
|
|
|
|
|
|
|
void MainWindow::on_hideToTray_clicked(bool checked) {
|
|
|
|
settings::settings().setValue("hideOnClose", checked);
|
|
|
|
}
|
2017-05-16 15:52:15 +02:00
|
|
|
|
|
|
|
void MainWindow::on_actionColor_Picker_triggered() {
|
|
|
|
ColorPickerScene::showPicker();
|
|
|
|
}
|
2017-05-17 13:53:30 +02:00
|
|
|
|
2017-05-15 14:10:00 +02:00
|
|
|
void MainWindow::on_captureCursor_clicked(bool checked) {
|
|
|
|
settings::settings().setValue("captureCursor", checked);
|
|
|
|
}
|
2017-06-06 13:38:15 +02:00
|
|
|
|
|
|
|
void MainWindow::on_formatBox_currentIndexChanged(int index) {
|
2017-06-13 00:38:32 +02:00
|
|
|
if (isVisible()) settings::settings().setValue("recording/format", index);
|
2017-06-06 13:38:15 +02:00
|
|
|
}
|
2017-06-06 17:05:34 +02:00
|
|
|
|
2017-06-13 00:38:32 +02:00
|
|
|
void MainWindow::on_imageFormatBox_currentIndexChanged(int index) {
|
|
|
|
if (isVisible()) settings::settings().setValue("imageformat", index);
|
2017-06-06 17:05:34 +02:00
|
|
|
}
|