Add capture individual screens option

This commit is contained in:
lupoDharkael
2018-05-08 21:23:09 +02:00
parent 888f8a1370
commit c766b3e048
13 changed files with 200 additions and 28 deletions

View File

@@ -28,6 +28,7 @@
#include <QSystemTrayIcon>
#include <QAction>
#include <QMenu>
#include <QDesktopWidget>
#ifdef Q_OS_WIN
#include "src/core/globalshortcutfilter.h"
@@ -57,11 +58,6 @@ Controller::Controller() : m_captureWindow(nullptr) {
QString StyleSheet = CaptureButton::globalStyleSheet();
qApp->setStyleSheet(StyleSheet);
connect(this, &Controller::captureTaken,
this, &Controller::handleCaptureTaken);
connect(this, &Controller::captureFailed,
this, &Controller::handleCaptureFailed);
}
Controller *Controller::getInstance() {
@@ -69,6 +65,13 @@ Controller *Controller::getInstance() {
return &c;
}
void Controller::enableExports() {
connect(this, &Controller::captureTaken,
this, &Controller::handleCaptureTaken);
connect(this, &Controller::captureFailed,
this, &Controller::handleCaptureFailed);
}
void Controller::requestCapture(const CaptureRequest &request) {
uint id = request.id();
m_requestMap.insert(id, request);
@@ -79,7 +82,13 @@ void Controller::requestCapture(const CaptureRequest &request) {
this->startFullscreenCapture(id);
});
break;
case CaptureRequest::GRAPHICAL_MODE: {
case CaptureRequest::SCREEN_MODE: {
int &&number = request.data().toInt();
doLater(request.delay(), this, [this, id, number](){
this->startScreenGrab(id, number);
});
break;
} case CaptureRequest::GRAPHICAL_MODE: {
QString &&path = request.path();
doLater(request.delay(), this, [this, id, path](){
this->startVisualCapture(id, path);
@@ -121,6 +130,22 @@ void Controller::startVisualCapture(const uint id, const QString &forcedSavePath
}
}
void Controller::startScreenGrab(const uint id, const int screenNumber) {
bool ok = true;
int n = screenNumber;
if (n < 0) {
QPoint globalCursorPos = QCursor::pos();
n = qApp->desktop()->screenNumber(globalCursorPos);
}
QPixmap p(ScreenGrabber().grabScreen(n, ok));
if (ok) {
emit captureTaken(id, p);
} else {
emit captureFailed(id);
}
}
// creation of the configuration window
void Controller::openConfigWindow() {
if (!m_configWindow) {
@@ -226,10 +251,6 @@ void Controller::handleCaptureFailed(uint id) {
}
void Controller::doLater(int msec, QObject *receiver, lambda func) {
if (msec == 0) {
func();
return;
}
QTimer *timer = new QTimer(receiver);
QObject::connect(timer, &QTimer::timeout, receiver,
[timer, func](){ func(); timer->deleteLater(); });