Qt use QEvent::type to handle the event correctly
No need for an extra function parameter. Change-Id: Iedb949b45ad3f161121110e2db2132b6c3cb706e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135894 Tested-by: Jenkins Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
This commit is contained in:
parent
c78193b321
commit
393c9f736b
2 changed files with 15 additions and 34 deletions
|
@ -42,17 +42,10 @@ class QtWidget : public QWidget
|
|||
int m_nDeltaX;
|
||||
int m_nDeltaY;
|
||||
|
||||
enum class ButtonKeyState
|
||||
{
|
||||
Pressed,
|
||||
Released
|
||||
};
|
||||
|
||||
static void commitText(QtFrame&, const QString& aText);
|
||||
static void deleteReplacementText(QtFrame& rFrame, int nReplacementStart,
|
||||
int nReplacementLength);
|
||||
static bool handleKeyEvent(QtFrame&, const QWidget&, QKeyEvent*, const ButtonKeyState);
|
||||
static void handleMouseButtonEvent(const QtFrame&, const QMouseEvent*, const ButtonKeyState);
|
||||
static bool handleKeyEvent(QtFrame&, const QWidget&, QKeyEvent*);
|
||||
static void handleMouseEnterLeaveEvents(const QtFrame&, QEvent*);
|
||||
static void fillSalAbstractMouseEvent(const QtFrame& rFrame, const QInputEvent* pQEvent,
|
||||
const QPoint& rPos, Qt::MouseButtons eButtons, int nWidth,
|
||||
|
@ -101,23 +94,12 @@ public:
|
|||
// key events might be propagated further down => call base on false
|
||||
static inline bool handleKeyReleaseEvent(QtFrame&, const QWidget&, QKeyEvent*);
|
||||
// mouse events are always accepted
|
||||
static inline void handleMousePressEvent(const QtFrame&, const QMouseEvent*);
|
||||
static inline void handleMouseReleaseEvent(const QtFrame&, const QMouseEvent*);
|
||||
static void handleMouseButtonEvent(const QtFrame&, const QMouseEvent*);
|
||||
};
|
||||
|
||||
bool QtWidget::handleKeyReleaseEvent(QtFrame& rFrame, const QWidget& rWidget, QKeyEvent* pEvent)
|
||||
{
|
||||
return handleKeyEvent(rFrame, rWidget, pEvent, ButtonKeyState::Released);
|
||||
}
|
||||
|
||||
void QtWidget::handleMousePressEvent(const QtFrame& rFrame, const QMouseEvent* pEvent)
|
||||
{
|
||||
handleMouseButtonEvent(rFrame, pEvent, ButtonKeyState::Pressed);
|
||||
}
|
||||
|
||||
void QtWidget::handleMouseReleaseEvent(const QtFrame& rFrame, const QMouseEvent* pEvent)
|
||||
{
|
||||
handleMouseButtonEvent(rFrame, pEvent, ButtonKeyState::Released);
|
||||
return handleKeyEvent(rFrame, rWidget, pEvent);
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
|
|
@ -153,8 +153,7 @@ void QtWidget::fillSalAbstractMouseEvent(const QtFrame& rFrame, const QInputEven
|
|||
#define FILL_SAME(rFrame, nWidth) \
|
||||
fillSalAbstractMouseEvent(rFrame, pEvent, pEvent->pos(), pEvent->buttons(), nWidth, aEvent)
|
||||
|
||||
void QtWidget::handleMouseButtonEvent(const QtFrame& rFrame, const QMouseEvent* pEvent,
|
||||
const ButtonKeyState eState)
|
||||
void QtWidget::handleMouseButtonEvent(const QtFrame& rFrame, const QMouseEvent* pEvent)
|
||||
{
|
||||
SalMouseEvent aEvent;
|
||||
FILL_SAME(rFrame, rFrame.GetQWidget()->width());
|
||||
|
@ -175,7 +174,7 @@ void QtWidget::handleMouseButtonEvent(const QtFrame& rFrame, const QMouseEvent*
|
|||
}
|
||||
|
||||
SalEvent nEventType;
|
||||
if (eState == ButtonKeyState::Pressed)
|
||||
if (pEvent->type() == QEvent::MouseButtonPress)
|
||||
nEventType = SalEvent::MouseButtonDown;
|
||||
else
|
||||
nEventType = SalEvent::MouseButtonUp;
|
||||
|
@ -184,13 +183,13 @@ void QtWidget::handleMouseButtonEvent(const QtFrame& rFrame, const QMouseEvent*
|
|||
|
||||
void QtWidget::mousePressEvent(QMouseEvent* pEvent)
|
||||
{
|
||||
handleMousePressEvent(m_rFrame, pEvent);
|
||||
handleMouseButtonEvent(m_rFrame, pEvent);
|
||||
if (m_rFrame.isPopup()
|
||||
&& !geometry().translated(geometry().topLeft() * -1).contains(pEvent->pos()))
|
||||
closePopup();
|
||||
}
|
||||
|
||||
void QtWidget::mouseReleaseEvent(QMouseEvent* pEvent) { handleMouseReleaseEvent(m_rFrame, pEvent); }
|
||||
void QtWidget::mouseReleaseEvent(QMouseEvent* pEvent) { handleMouseButtonEvent(m_rFrame, pEvent); }
|
||||
|
||||
void QtWidget::mouseMoveEvent(QMouseEvent* pEvent)
|
||||
{
|
||||
|
@ -514,11 +513,12 @@ void QtWidget::deleteReplacementText(QtFrame& rFrame, int nReplacementStart, int
|
|||
rFrame.CallCallback(SalEvent::DeleteSurroundingTextRequest, &aEvt);
|
||||
}
|
||||
|
||||
bool QtWidget::handleKeyEvent(QtFrame& rFrame, const QWidget& rWidget, QKeyEvent* pEvent,
|
||||
const ButtonKeyState eState)
|
||||
bool QtWidget::handleKeyEvent(QtFrame& rFrame, const QWidget& rWidget, QKeyEvent* pEvent)
|
||||
{
|
||||
const bool bIsKeyPressed
|
||||
= pEvent->type() == QEvent::KeyPress || pEvent->type() == QEvent::ShortcutOverride;
|
||||
sal_uInt16 nCode = GetKeyCode(pEvent->key(), pEvent->modifiers());
|
||||
if (eState == ButtonKeyState::Pressed && nCode == 0 && pEvent->text().length() > 1
|
||||
if (bIsKeyPressed && nCode == 0 && pEvent->text().length() > 1
|
||||
&& rWidget.testAttribute(Qt::WA_InputMethodEnabled))
|
||||
{
|
||||
commitText(rFrame, pEvent->text());
|
||||
|
@ -530,7 +530,7 @@ bool QtWidget::handleKeyEvent(QtFrame& rFrame, const QWidget& rWidget, QKeyEvent
|
|||
{
|
||||
sal_uInt16 nModCode = GetKeyModCode(pEvent->modifiers());
|
||||
SalKeyModEvent aModEvt;
|
||||
aModEvt.mbDown = eState == ButtonKeyState::Pressed;
|
||||
aModEvt.mbDown = bIsKeyPressed;
|
||||
aModEvt.mnModKeyCode = ModKeyFlags::NONE;
|
||||
|
||||
#if CHECK_ANY_QT_USING_X11
|
||||
|
@ -582,7 +582,7 @@ bool QtWidget::handleKeyEvent(QtFrame& rFrame, const QWidget& rWidget, QKeyEvent
|
|||
break;
|
||||
}
|
||||
|
||||
if (eState == ButtonKeyState::Released)
|
||||
if (!bIsKeyPressed)
|
||||
{
|
||||
// sending the old mnModKeyCode mask on release is needed to
|
||||
// implement the writing direction switch with Ctrl + L/R-Shift
|
||||
|
@ -618,7 +618,7 @@ bool QtWidget::handleKeyEvent(QtFrame& rFrame, const QWidget& rWidget, QKeyEvent
|
|||
QGuiApplication::inputMethod()->update(Qt::ImCursorRectangle);
|
||||
|
||||
bool bStopProcessingKey;
|
||||
if (eState == ButtonKeyState::Pressed)
|
||||
if (bIsKeyPressed)
|
||||
bStopProcessingKey = rFrame.CallCallback(SalEvent::KeyInput, &aEvent);
|
||||
else
|
||||
bStopProcessingKey = rFrame.CallCallback(SalEvent::KeyUp, &aEvent);
|
||||
|
@ -650,8 +650,7 @@ bool QtWidget::handleEvent(QtFrame& rFrame, QWidget& rWidget, QEvent* pEvent)
|
|||
// and if it's handled - disable the shortcut, it should have been activated.
|
||||
// Don't process keyPressEvent generated after disabling shortcut since it was handled here.
|
||||
// If event is not handled, don't accept it and let Qt activate related shortcut.
|
||||
if (handleKeyEvent(rFrame, rWidget, static_cast<QKeyEvent*>(pEvent),
|
||||
ButtonKeyState::Pressed))
|
||||
if (handleKeyEvent(rFrame, rWidget, static_cast<QKeyEvent*>(pEvent)))
|
||||
return true;
|
||||
}
|
||||
else if (pEvent->type() == QEvent::ToolTip)
|
||||
|
|
Loading…
Reference in a new issue