2017-04-23 15:05:48 +02:00
|
|
|
#include "mainwindow.hpp"
|
2017-06-22 17:41:29 +02:00
|
|
|
#include "aboutbox.hpp"
|
2017-04-23 15:05:48 +02:00
|
|
|
#include "screenshotter.hpp"
|
|
|
|
#include "screenshotutil.hpp"
|
2017-06-22 17:41:29 +02:00
|
|
|
#include "settingsdialog.hpp"
|
2017-04-23 15:05:48 +02:00
|
|
|
#include "ui_mainwindow.h"
|
2017-06-22 17:41:29 +02:00
|
|
|
#include <QMessageBox>
|
2017-05-16 15:52:15 +02:00
|
|
|
#include <colorpicker/colorpickerscene.hpp>
|
2017-06-22 17:41:29 +02:00
|
|
|
#include <formats.hpp>
|
2017-04-26 22:00:13 +02:00
|
|
|
#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-18 19:04:25 +02:00
|
|
|
void MainWindow::rec() {
|
|
|
|
if (controller->isRunning()) return;
|
|
|
|
auto f
|
|
|
|
= static_cast<formats::Recording>(settings::settings().value("recording/format", (int)formats::Recording::None).toInt());
|
|
|
|
if (f >= formats::Recording::None) return;
|
|
|
|
RecordingContext *ctx = new RecordingContext;
|
|
|
|
RecordingFormats *format = new RecordingFormats(f);
|
|
|
|
ctx->consumer = format->getConsumer();
|
|
|
|
ctx->finalizer = format->getFinalizer();
|
|
|
|
ctx->validator = format->getValidator();
|
|
|
|
ctx->format = format->getFormat();
|
|
|
|
ctx->postUploadTask = format->getPostUploadTask();
|
|
|
|
ctx->anotherFormat = format->getAnotherFormat();
|
|
|
|
controller->start(ctx);
|
|
|
|
}
|
|
|
|
|
2017-06-22 17:41:29 +02:00
|
|
|
void addHotkey(QString name, std::function<void()> action) {
|
|
|
|
hotkeying::load(name, action);
|
|
|
|
}
|
|
|
|
|
2017-05-09 17:26:00 +02:00
|
|
|
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
|
|
|
|
instance = this;
|
|
|
|
ui->setupUi(this);
|
2017-06-22 17:41:29 +02:00
|
|
|
setWindowIcon(QIcon(":/icons/icon.svg"));
|
2017-05-09 17:26:00 +02:00
|
|
|
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);
|
2017-06-18 19:04:25 +02:00
|
|
|
QAction *rec = new QAction("Record screen", this);
|
|
|
|
QAction *recoff = new QAction("Stop recording", this);
|
2017-05-16 15:52:15 +02:00
|
|
|
menu->addActions({ quit, shtoggle, picker });
|
2017-05-09 17:26:00 +02:00
|
|
|
menu->addSeparator();
|
|
|
|
menu->addActions({ fullscreen, area });
|
2017-06-18 19:04:25 +02:00
|
|
|
menu->addSeparator();
|
|
|
|
menu->addActions({ rec, recoff });
|
2017-05-09 17:26:00 +02:00
|
|
|
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(); });
|
2017-06-18 19:04:25 +02:00
|
|
|
connect(rec, &QAction::triggered, this, &MainWindow::rec);
|
|
|
|
connect(recoff, &QAction::triggered, [this] { controller->end(); });
|
2017-06-22 17:41:29 +02:00
|
|
|
connect(ui->settings, &QPushButton::clicked, this, &MainWindow::on_actionSettings_triggered);
|
2017-05-09 17:26:00 +02:00
|
|
|
|
2017-06-22 17:41:29 +02:00
|
|
|
tray->setContextMenu(menu);
|
2017-05-09 17:26:00 +02:00
|
|
|
|
2017-06-22 17:41:29 +02:00
|
|
|
addHotkey("fullscreen", [] { screenshotter::fullscreen(); });
|
|
|
|
addHotkey("area", [] { screenshotter::area(); });
|
|
|
|
addHotkey("picker", [] { ColorPickerScene::showPicker(); });
|
|
|
|
addHotkey("recordingstop", [&] { controller->end(); });
|
|
|
|
addHotkey("recordingstart", [&] { this->rec(); });
|
2017-05-09 17:26:00 +02:00
|
|
|
|
|
|
|
auto errors = UploaderSingleton::inst().errors();
|
2017-06-22 17:41:29 +02:00
|
|
|
for (auto err : errors) ui->logBox->addItem(QString("ERROR: ") + err.what());
|
|
|
|
setWindowTitle("KShare v" + QApplication::applicationVersion());
|
|
|
|
val = true;
|
2017-05-09 17:26:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow() {
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2017-06-22 17:41:29 +02:00
|
|
|
bool MainWindow::valid() {
|
|
|
|
return val;
|
2017-05-09 17:26:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2017-06-22 17:41:29 +02:00
|
|
|
hide();
|
2017-05-15 14:42:40 +02:00
|
|
|
} 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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2017-06-18 23:31:40 +02:00
|
|
|
void MainWindow::on_actionStart_triggered() {
|
|
|
|
rec();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionStop_triggered() {
|
|
|
|
controller->end();
|
|
|
|
}
|
2017-06-22 17:41:29 +02:00
|
|
|
|
2017-06-23 14:39:51 +02:00
|
|
|
void MainWindow::on_actionColor_Picker_triggered() {
|
|
|
|
ColorPickerScene::showPicker();
|
|
|
|
}
|
|
|
|
|
2017-06-22 17:41:29 +02:00
|
|
|
void MainWindow::on_actionSettings_triggered() {
|
|
|
|
SettingsDialog *dialog = new SettingsDialog(this);
|
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
dialog->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_actionAbout_triggered() {
|
|
|
|
AboutBox *box = new AboutBox(this);
|
|
|
|
box->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
box->show();
|
|
|
|
}
|