diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2020-06-28 03:00:50 +0200 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2020-06-28 12:52:30 +0200 |
commit | a3634fe80fa5578774df07a2dc327de730f11348 (patch) | |
tree | 21ad4cb887952df2fcf90e7cb565c4a9b979d476 /vcl/qt5 | |
parent | c97fea54813052953fc0ff2ef0b506c372689ac8 (diff) |
Qt5 refactor mouse event fill code
Adds Qt5Widget::fillSalAbstractMouseEvent to set the common
Sal*MouseEvent members. While the member functions of QMouseEvent
and QWheelEvent have the same name, they aren't shared via
QInputEvent, so this uses a small FILL_SAME macro for less code,
Change-Id: I3e5aa52b1bf2774251d97534ce0106a27ef5899b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97343
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
Diffstat (limited to 'vcl/qt5')
-rw-r--r-- | vcl/qt5/Qt5Widget.cxx | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/vcl/qt5/Qt5Widget.cxx b/vcl/qt5/Qt5Widget.cxx index 0ef305f42949..2d3951ad8203 100644 --- a/vcl/qt5/Qt5Widget.cxx +++ b/vcl/qt5/Qt5Widget.cxx @@ -127,10 +127,28 @@ void Qt5Widget::resizeEvent(QResizeEvent* pEvent) m_rFrame.CallCallback(SalEvent::Resize, nullptr); } +void Qt5Widget::fillSalAbstractMouseEvent(const Qt5Frame& rFrame, const QInputEvent* pQEvent, + const QPoint& rPos, Qt::MouseButtons eButtons, int nWidth, + SalAbstractMouseEvent& aSalEvent) +{ + const qreal fRatio = rFrame.devicePixelRatioF(); + const Point aPos = toPoint(rPos * fRatio); + + aSalEvent.mnX = QGuiApplication::isLeftToRight() ? aPos.X() : round(nWidth * fRatio) - aPos.X(); + aSalEvent.mnY = aPos.Y(); + aSalEvent.mnTime = pQEvent->timestamp(); + aSalEvent.mnCode = GetKeyModCode(pQEvent->modifiers()) | GetMouseModCode(eButtons); +} + +#define FILL_SAME(rFrame, nWidth) \ + fillSalAbstractMouseEvent(rFrame, pEvent, pEvent->pos(), pEvent->buttons(), nWidth, aEvent) + void Qt5Widget::handleMouseButtonEvent(const Qt5Frame& rFrame, const QMouseEvent* pEvent, const ButtonKeyState eState) { SalMouseEvent aEvent; + FILL_SAME(rFrame, rFrame.GetQWidget()->width()); + switch (pEvent->button()) { case Qt::LeftButton: @@ -146,16 +164,6 @@ void Qt5Widget::handleMouseButtonEvent(const Qt5Frame& rFrame, const QMouseEvent return; } - const qreal fRatio = rFrame.devicePixelRatioF(); - const Point aPos = toPoint(pEvent->pos() * fRatio); - - aEvent.mnX = QGuiApplication::isLeftToRight() - ? aPos.X() - : round(rFrame.GetQWidget()->width() * fRatio) - aPos.X(); - aEvent.mnY = aPos.Y(); - aEvent.mnTime = pEvent->timestamp(); - aEvent.mnCode = GetKeyModCode(pEvent->modifiers()) | GetMouseModCode(pEvent->buttons()); - SalEvent nEventType; if (eState == ButtonKeyState::Pressed) nEventType = SalEvent::MouseButtonDown; @@ -173,14 +181,9 @@ void Qt5Widget::mouseReleaseEvent(QMouseEvent* pEvent) void Qt5Widget::mouseMoveEvent(QMouseEvent* pEvent) { - const qreal fRatio = m_rFrame.devicePixelRatioF(); - const Point aPos = toPoint(pEvent->pos() * fRatio); - SalMouseEvent aEvent; - aEvent.mnX = QGuiApplication::isLeftToRight() ? aPos.X() : round(width() * fRatio) - aPos.X(); - aEvent.mnY = aPos.Y(); - aEvent.mnTime = pEvent->timestamp(); - aEvent.mnCode = GetKeyModCode(pEvent->modifiers()) | GetMouseModCode(pEvent->buttons()); + FILL_SAME(m_rFrame, width()); + aEvent.mnButton = 0; m_rFrame.CallCallback(SalEvent::MouseMove, &aEvent); @@ -189,15 +192,8 @@ void Qt5Widget::mouseMoveEvent(QMouseEvent* pEvent) void Qt5Widget::wheelEvent(QWheelEvent* pEvent) { - const Point aPos = toPoint(pEvent->pos() * m_rFrame.devicePixelRatioF()); - SalWheelMouseEvent aEvent; - aEvent.mnX = QGuiApplication::isLeftToRight() - ? aPos.X() - : round(width() * m_rFrame.devicePixelRatioF()) - aPos.X(); - aEvent.mnY = aPos.Y(); - aEvent.mnTime = pEvent->timestamp(); - aEvent.mnCode = GetKeyModCode(pEvent->modifiers()) | GetMouseModCode(pEvent->buttons()); + FILL_SAME(m_rFrame, width()); // mouse wheel ticks are 120, which we map to 3 lines. // we have to accumulate for touch scroll to keep track of the absolute delta. |