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>
This commit is contained in:
Jan-Marek Glogowski
2020-06-28 12:52:30 +02:00
parent c97fea5481
commit a3634fe80f
2 changed files with 26 additions and 25 deletions
+5
View File
@@ -25,8 +25,10 @@
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/accessibility/XAccessibleEditableText.hpp>
class QInputEvent;
class Qt5Frame;
class Qt5Object;
struct SalAbstractMouseEvent;
class Qt5Widget : public QWidget
{
@@ -46,6 +48,9 @@ class Qt5Widget : public QWidget
static void commitText(Qt5Frame&, const QString& aText);
static bool handleKeyEvent(Qt5Frame&, const QWidget&, QKeyEvent*, const ButtonKeyState);
static void handleMouseButtonEvent(const Qt5Frame&, const QMouseEvent*, const ButtonKeyState);
static void fillSalAbstractMouseEvent(const Qt5Frame& rFrame, const QInputEvent* pQEvent,
const QPoint& rPos, Qt::MouseButtons eButtons, int nWidth,
SalAbstractMouseEvent& aSalEvent);
virtual bool event(QEvent*) override;
+21 -25
View File
@@ -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.