diff --git a/tools/chatgui/src/imageviewer_window.cpp b/tools/chatgui/src/imageviewer_window.cpp index 4d1314ff..858596ca 100644 --- a/tools/chatgui/src/imageviewer_window.cpp +++ b/tools/chatgui/src/imageviewer_window.cpp @@ -15,6 +15,22 @@ #include #include +static QPointF mouseLocalPos(const QMouseEvent* e) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + return e->position(); +#else + return e->localPos(); +#endif +} + +static QPointF wheelPos(const QWheelEvent* e) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + return e->position(); +#else + return e->posF(); +#endif +} + ImageViewerWindow::ImageViewerWindow(QWidget *parent) : QWidget(parent) { @@ -138,7 +154,7 @@ void ImageViewerWindow::wheelEvent(QWheelEvent* e) { if (qFuzzyCompare(newScale, m_scale)) return; /* зум в точку курсора */ - QPointF cursor = e->position(); + QPointF cursor = wheelPos(e); QPointF center((double)width() / 2.0, (double)height() / 2.0); double ratio = newScale / m_scale; m_offset = (m_offset - (cursor - center)) * ratio + (cursor - center); @@ -151,7 +167,7 @@ void ImageViewerWindow::wheelEvent(QWheelEvent* e) { void ImageViewerWindow::mousePressEvent(QMouseEvent* e) { if (e->button() == Qt::LeftButton && m_scale > 1.0) { m_dragging = true; - m_dragStart = e->position(); + m_dragStart = mouseLocalPos(e); m_offsetStart = m_offset; setCursor(Qt::ClosedHandCursor); e->accept(); @@ -163,7 +179,7 @@ void ImageViewerWindow::mousePressEvent(QMouseEvent* e) { void ImageViewerWindow::mouseMoveEvent(QMouseEvent* e) { showOverlay(); if (m_dragging) { - m_offset = m_offsetStart + (e->position() - m_dragStart); + m_offset = m_offsetStart + (mouseLocalPos(e) - m_dragStart); clampOffset(); update(); e->accept();