chatgui: fix Qt5 build — QMouseEvent/QWheelEvent position() -> localPos()/posF()
This commit is contained in:
1 parent
de850db548
commit
2f1545de38
1 file changed
+19
-3
@@ -15,6 +15,22 @@
|
||||
#include <QEasingCurve>
|
||||
#include <QtMath>
|
||||
|
||||
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();
|
||||
|
||||
Reference in new issue
Block a user