From f425d47bcd27ac030b82dd56310ba5f8f74b932f Mon Sep 17 00:00:00 2001 From: ArsenArsen Date: Sun, 18 Jun 2017 19:04:25 +0200 Subject: [PATCH] Some improvemnts on the color picked & crop editor --- colorpicker/colorpickerscene.cpp | 2 +- cropeditor/cropeditor.cpp | 6 ++--- cropeditor/cropview.cpp | 2 +- mainwindow.cpp | 41 ++++++++++++++++++------------- mainwindow.hpp | 2 ++ recording/recordingcontroller.cpp | 2 ++ recording/recordingcontroller.hpp | 2 ++ 7 files changed, 35 insertions(+), 22 deletions(-) diff --git a/colorpicker/colorpickerscene.cpp b/colorpicker/colorpickerscene.cpp index 308feb0..0180e9b 100644 --- a/colorpicker/colorpickerscene.cpp +++ b/colorpicker/colorpickerscene.cpp @@ -11,7 +11,7 @@ ColorPickerScene::ColorPickerScene(QPixmap *pixmap, QWidget *parentWidget) setFrameShape(QFrame::NoFrame); // Time taken to solve: A george99g and 38 minutes. setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint); + setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing); setCursor(QCursor(Qt::CrossCursor)); setMouseTracking(true); diff --git a/cropeditor/cropeditor.cpp b/cropeditor/cropeditor.cpp index c9160ad..1b12497 100644 --- a/cropeditor/cropeditor.cpp +++ b/cropeditor/cropeditor.cpp @@ -18,15 +18,15 @@ CropEditor::CropEditor(QPixmap *image, QObject *parent) : QObject(parent) { pixmapItem->setScale(1 / ratio); scene->addItem(pixmapItem); scene->setSceneRect(image->rect()); - view->showFullScreen(); - - QTimer::singleShot(0, [&] { view->showFullScreen(); }); + view->show(); + view->resize(pixmapItem->pixmap().width(), pixmapItem->pixmap().height()); connect(scene, &CropScene::closedWithRect, this, &CropEditor::crop); } CropEditor::~CropEditor() { delete scene; + delete view; } void CropEditor::crop(QRect rect) { diff --git a/cropeditor/cropview.cpp b/cropeditor/cropview.cpp index 9988104..1352331 100644 --- a/cropeditor/cropview.cpp +++ b/cropeditor/cropview.cpp @@ -4,7 +4,7 @@ CropView::CropView(QGraphicsScene *scene) : QGraphicsView(scene) { setFrameShape(QFrame::NoFrame); // Time taken to solve: A george99g and 38 minutes. setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint); + setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing); setCursor(QCursor(Qt::CrossCursor)); } diff --git a/mainwindow.cpp b/mainwindow.cpp index f7fe5e2..f7b3d54 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -33,6 +33,22 @@ void addHotkeyItem(QString text, QString name, std::function func, QStri hotkeying::load(name, func, def); } +void MainWindow::rec() { + if (controller->isRunning()) return; + auto f + = static_cast(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); +} + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { instance = this; ui->setupUi(this); @@ -46,9 +62,13 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi QAction *fullscreen = new QAction("Take fullscreen shot", this); QAction *area = new QAction("Take area shot", this); QAction *picker = new QAction("Show color picker", this); + QAction *rec = new QAction("Record screen", this); + QAction *recoff = new QAction("Stop recording", this); menu->addActions({ quit, shtoggle, picker }); menu->addSeparator(); menu->addActions({ fullscreen, area }); + menu->addSeparator(); + menu->addActions({ rec, recoff }); connect(quit, &QAction::triggered, this, &MainWindow::quit); connect(shtoggle, &QAction::triggered, this, &MainWindow::toggleVisible); connect(picker, &QAction::triggered, [] { ColorPickerScene::showPicker(); }); @@ -58,6 +78,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi }); connect(fullscreen, &QAction::triggered, this, [] { screenshotter::fullscreenDelayed(); }); connect(area, &QAction::triggered, this, [] { screenshotter::areaDelayed(); }); + connect(rec, &QAction::triggered, this, &MainWindow::rec); + connect(recoff, &QAction::triggered, [this] { controller->end(); }); tray->setContextMenu(menu); ui->uploaderList->setSelectionBehavior(QAbstractItemView::SelectRows); @@ -88,25 +110,10 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi ui->hotkeys->setSelectionMode(QListWidget::SingleSelection); addHotkeyItem("Fullscreen image", "fullscreen", [] { screenshotter::fullscreen(); }); - addHotkeyItem("Area image", "area", [] { // - screenshotter::area(); // - }); + addHotkeyItem("Area image", "area", [] { screenshotter::area(); }); addHotkeyItem("Color picker", "picker", [] { ColorPickerScene::showPicker(); }); addHotkeyItem("Stop Recording", "recordingstop", [&] { controller->end(); }); - addHotkeyItem("Start Recording", "recordingstart", [&] { - auto f - = static_cast(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); - }); + addHotkeyItem("Start Recording", "recordingstart", [&] { this->rec(); }); ui->quickMode->setChecked(settings::settings().value("quickMode", false).toBool()); ui->hideToTray->setChecked(settings::settings().value("hideOnClose", true).toBool()); diff --git a/mainwindow.hpp b/mainwindow.hpp index 043ee69..9a77043 100644 --- a/mainwindow.hpp +++ b/mainwindow.hpp @@ -53,6 +53,8 @@ public: private: static MainWindow *instance; RecordingController *controller = new RecordingController; +private slots: + void rec(); protected: void closeEvent(QCloseEvent *event); diff --git a/recording/recordingcontroller.cpp b/recording/recordingcontroller.cpp index b0722e5..cea7dda 100644 --- a/recording/recordingcontroller.cpp +++ b/recording/recordingcontroller.cpp @@ -25,10 +25,12 @@ bool RecordingController::start(RecordingContext *context) { _context = context; ScreenAreaSelector *sel = new ScreenAreaSelector; connect(sel, &ScreenAreaSelector::selectedArea, this, &RecordingController::startWithArea); + connect(this, &RecordingController::ended, sel, &ScreenAreaSelector::deleteLater); return true; } bool RecordingController::end() { + emit ended(); if (!isRunning()) return false; area = QRect(); if (preview) { diff --git a/recording/recordingcontroller.hpp b/recording/recordingcontroller.hpp index a44291a..d1dce00 100644 --- a/recording/recordingcontroller.hpp +++ b/recording/recordingcontroller.hpp @@ -52,6 +52,8 @@ private: RecordingPreview *preview = nullptr; unsigned int frame = 0; unsigned int time = 0; +signals: + void ended(); }; #endif // RECORDINGCONTROLLER_HPP