From 2f1545de38cf8a40250fb999944f7c03ddf58ab7 Mon Sep 17 00:00:00 2001 From: evgeny Date: Mon, 21 Sep 2026 00:51:48 +0300 Subject: [PATCH] =?UTF-8?q?chatgui:=20fix=20Qt5=20build=20=E2=80=94=20QMou?= =?UTF-8?q?seEvent/QWheelEvent=20position()=20->=20localPos()/posF()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/chatgui/src/imageviewer_window.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) 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();