From 698d1238152150cb21ece2a25ffe65c3045bbfb9 Mon Sep 17 00:00:00 2001 From: ArsenArsen Date: Wed, 5 Jul 2017 16:41:53 +0200 Subject: [PATCH] Partial fix for #9 - now the position is good --- cropeditor/cropeditor.cpp | 4 +++- hotkeying.cpp | 10 +++++----- screenshotutil.cpp | 17 ++++++++++++++--- screenshotutil.hpp | 1 + 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/cropeditor/cropeditor.cpp b/cropeditor/cropeditor.cpp index de15ffa..16291ff 100644 --- a/cropeditor/cropeditor.cpp +++ b/cropeditor/cropeditor.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include CropEditor::CropEditor(QPixmap image, QObject *parent) : QObject(parent) { @@ -20,7 +21,8 @@ CropEditor::CropEditor(QPixmap image, QObject *parent) : QObject(parent) { scene->setSceneRect(image.rect()); view->resize(image.width(), image.height()); view->setMinimumSize(image.size()); - view->move(settings::settings().value("cropx", 0).toInt(), settings::settings().value("cropy", 0).toInt()); + QPoint p = screenshotutil::smallestScreenCoordinate(); + view->move(p.x() + settings::settings().value("cropx", 0).toInt(), p.y() + settings::settings().value("cropy", 0).toInt()); view->setWindowTitle("KShare Crop Editor"); view->show(); diff --git a/hotkeying.cpp b/hotkeying.cpp index 2dd5971..90de05d 100644 --- a/hotkeying.cpp +++ b/hotkeying.cpp @@ -28,17 +28,17 @@ void hotkeying::load(QString seqName, std::function func, QString def) { QString name = seqName; name.prepend("hotkey_"); if (hotkeys.contains(seqName)) return; - if (settings::settings().contains(name)) { - QString k = settings::settings().value(name).toString(); + QString k = settings::settings().value(name).toString(); + if (!k.isEmpty()) { if (!k.isEmpty()) h = new QHotkey(QKeySequence(settings::settings().value(k).toString()), true); else - h = new QHotkey(def.isNull() ? "" : def, true); + h = new QHotkey(def.isEmpty() ? "" : def, true); } else - h = new QHotkey(def.isNull() ? "" : def, true); + h = new QHotkey(def.isEmpty() ? "" : def, true); QObject::connect(h, &QHotkey::activated, func); hotkeys.insert(seqName, h); - if (!h->isRegistered() && (settings::settings().contains(name) || !def.isEmpty())) + if (!h->isRegistered() && !h->shortcut().toString().isEmpty()) qWarning().noquote().nospace() << "Could not bind the hotkey " << seqName << "! Is the keybind already registered?"; } diff --git a/screenshotutil.cpp b/screenshotutil.cpp index d0ec325..b6d3268 100644 --- a/screenshotutil.cpp +++ b/screenshotutil.cpp @@ -11,16 +11,17 @@ QPixmap screenshotutil::fullscreen(bool cursor) { QPixmap image; QPainter painter; + QPoint smallestCoordinate = smallestScreenCoordinate(); - // Hack for https://bugreports.qt.io/browse/QTBUG-58110 - static QStringList qVer = QString(qVersion()).split('.'); +// Hack for https://bugreports.qt.io/browse/QTBUG-58110 #ifdef Q_OS_LINUX + static QStringList qVer = QString(qVersion()).split('.'); if (qVer.at(0).toInt() == 5 && qVer.at(1).toInt() < 9) { image = window(0); painter.begin(&image); } else { #endif - int height = 0, width = 0; + int height = qAbs(smallestCoordinate.y()), width = qAbs(smallestCoordinate.x()); // qute abs for (QScreen *screen : QApplication::screens()) { QRect geo = screen->geometry(); width = qMax(geo.left() + geo.width(), width); @@ -30,6 +31,7 @@ QPixmap screenshotutil::fullscreen(bool cursor) { image.fill(Qt::transparent); width = 0; painter.begin(&image); + painter.translate(qAbs(smallestCoordinate.x()), qAbs(smallestCoordinate.y())); for (QScreen *screen : QApplication::screens()) { QPixmap currentScreen = window(0, screen); @@ -61,3 +63,12 @@ void screenshotutil::toClipboard(QString value) { QPixmap screenshotutil::fullscreenArea(bool cursor, qreal x, qreal y, qreal w, qreal h) { return fullscreen(cursor).copy(x, y, w, h); } + +QPoint screenshotutil::smallestScreenCoordinate() { + QPoint smallestCoordinate; + for (QScreen *screen : QApplication::screens()) { + smallestCoordinate.rx() = qMin(smallestCoordinate.x(), screen->geometry().left()); + smallestCoordinate.ry() = qMin(smallestCoordinate.y(), screen->geometry().top()); + } + return smallestCoordinate; +} diff --git a/screenshotutil.hpp b/screenshotutil.hpp index 02808ea..df156d6 100644 --- a/screenshotutil.hpp +++ b/screenshotutil.hpp @@ -9,6 +9,7 @@ QPixmap fullscreen(bool cursor = true); QPixmap fullscreenArea(bool cursor = true, qreal x = 0, qreal y = 0, qreal w = -1, qreal h = -1); QPixmap window(WId wid, QScreen *w = QApplication::primaryScreen()); void toClipboard(QString value); +QPoint smallestScreenCoordinate(); } #endif // SCREENSHOTUTIL_HPP