Partial fix for #9 - now the position is good

This commit is contained in:
ArsenArsen 2017-07-05 16:41:53 +02:00
parent 159720d9fa
commit 698d123815
4 changed files with 23 additions and 9 deletions

View File

@ -7,6 +7,7 @@
#include <QGraphicsView>
#include <QScreen>
#include <QTimer>
#include <screenshotutil.hpp>
#include <settings.hpp>
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();

View File

@ -28,17 +28,17 @@ void hotkeying::load(QString seqName, std::function<void()> 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?";
}

View File

@ -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;
}

View File

@ -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