diff --git a/src/tools/abstractpathtool.cpp b/src/tools/abstractpathtool.cpp index 7096eec0..c4a771b9 100644 --- a/src/tools/abstractpathtool.cpp +++ b/src/tools/abstractpathtool.cpp @@ -46,17 +46,15 @@ bool AbstractPathTool::showMousePreview() const void AbstractPathTool::undo(QPixmap& pixmap) { QPainter p(&pixmap); - const int val = m_thickness + m_padding; #if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \ defined(Q_OS_MACX)) - // On edge borders MacOS returns nullptr instead of current screen, - // it means that we cannot get devicePixelRatio for the current screen, - // so we have no choice and have to save the whole screen in the - // history. - p.drawPixmap(QPoint(0, 0), m_pixmapBackup); + // Not sure how will it work on 4k and fullHd on Linux or Windows with a + // capture of different displays with different DPI, so let it be MacOS + // specific only. + const qreal pixelRatio = pixmap.devicePixelRatio(); + p.drawPixmap(backupRect(pixmap).topLeft() / pixelRatio, m_pixmapBackup); #else - QRect area = m_backupArea + QMargins(val, val, val, val); - p.drawPixmap(area.intersected(pixmap.rect()).topLeft(), m_pixmapBackup); + p.drawPixmap(backupRect(pixmap).topLeft(), m_pixmapBackup); #endif } @@ -82,18 +80,30 @@ void AbstractPathTool::thicknessChanged(const int th) void AbstractPathTool::updateBackup(const QPixmap& pixmap) { + m_pixmapBackup = pixmap.copy(backupRect(pixmap)); +} + +QRect AbstractPathTool::backupRect(const QPixmap& pixmap) const +{ + const QRect& limits = pixmap.rect(); #if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \ defined(Q_OS_MACX)) - // On edge borders MacOS returns nullptr instead of current screen, - // it means that we cannot get devicePixelRatio for the current screen, - // so we have no choice and have to save the whole screen in the - // history. - m_pixmapBackup = pixmap; + // Not sure how will it work on 4k and fullHd on Linux or Windows with a + // capture of different displays with different DPI, so let it be MacOS + // specific only. + const qreal pixelRatio = pixmap.devicePixelRatio(); + const int val = (m_thickness + m_padding) * pixelRatio; + QRect r = m_backupArea.normalized(); + if (1 != pixelRatio) { + r.moveTo(r.topLeft() * pixelRatio); + r.setSize(r.size() * pixelRatio); + } #else const int val = m_thickness + m_padding; - QRect area = m_backupArea.normalized() + QMargins(val, val, val, val); - m_pixmapBackup = pixmap.copy(area); + QRect r = m_backupArea.normalized(); #endif + r += QMargins(val, val, val, val); + return r.intersected(limits); } void AbstractPathTool::addPoint(const QPoint& point) diff --git a/src/tools/abstractpathtool.h b/src/tools/abstractpathtool.h index 8b4a93f9..4b80016f 100644 --- a/src/tools/abstractpathtool.h +++ b/src/tools/abstractpathtool.h @@ -41,6 +41,7 @@ public slots: protected: void updateBackup(const QPixmap& pixmap); void addPoint(const QPoint& point); + QRect backupRect(const QPixmap& pixmap) const; QPixmap m_pixmapBackup; QRect m_backupArea; diff --git a/src/tools/abstracttwopointtool.cpp b/src/tools/abstracttwopointtool.cpp index 20a648bb..681d8312 100644 --- a/src/tools/abstracttwopointtool.cpp +++ b/src/tools/abstracttwopointtool.cpp @@ -76,12 +76,13 @@ void AbstractTwoPointTool::undo(QPixmap& pixmap) QPainter p(&pixmap); #if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \ defined(Q_OS_MACX)) + // Not sure how will it work on 4k and fullHd on Linux or Windows with a + // capture of different displays with different DPI, so let it be MacOS + // specific only. const qreal pixelRatio = pixmap.devicePixelRatio(); p.drawPixmap(backupRect(pixmap).topLeft() / pixelRatio, m_pixmapBackup); - p.drawPixmap(backupRect(pixmap).topLeft() / pixelRatio, m_pixmapBackup); #else p.drawPixmap(backupRect(pixmap).topLeft(), m_pixmapBackup); - p.drawPixmap(backupRect(pixmap).topLeft(), m_pixmapBackup); #endif if (this->nameID() == ToolType::CIRCLECOUNT) { emit requestAction(REQ_DECREMENT_CIRCLE_COUNT);