mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-07-31 00:34:45 +00:00
homescreens/folio: Block propagation if edit mode is active to avoid widget to trigger event
Fixes https://invent.kde.org/plasma/plasma-mobile/-/issues/387 and https://invent.kde.org/plasma/plasma-mobile/-/issues/353 I can't only block the touch events because it blocks also MouseEvent. > I think because it's used to convert it by QT into Mouse Event with source == MouseEventSynthesizedByQt or MouseEventSynthesizedBySystem. So the solution, it's to check if mouse event is a synthetized event and if edit mode has been triggered to block or not the event propagation Test: - On VM with kwin_wayland command - On mobile
This commit is contained in:
parent
3f3f4c9630
commit
43672a5ec5
2 changed files with 36 additions and 0 deletions
|
|
@ -57,6 +57,11 @@ bool WidgetContainer::childMouseEventFilter(QQuickItem *item, QEvent *event)
|
||||||
switch (event->type()) {
|
switch (event->type()) {
|
||||||
case QEvent::MouseButtonPress: {
|
case QEvent::MouseButtonPress: {
|
||||||
QMouseEvent *me = static_cast<QMouseEvent *>(event);
|
QMouseEvent *me = static_cast<QMouseEvent *>(event);
|
||||||
|
|
||||||
|
if (!validMouseEvent(me)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (me->buttons() & Qt::LeftButton) {
|
if (me->buttons() & Qt::LeftButton) {
|
||||||
mousePressEvent(me);
|
mousePressEvent(me);
|
||||||
}
|
}
|
||||||
|
|
@ -64,11 +69,21 @@ bool WidgetContainer::childMouseEventFilter(QQuickItem *item, QEvent *event)
|
||||||
}
|
}
|
||||||
case QEvent::MouseMove: {
|
case QEvent::MouseMove: {
|
||||||
QMouseEvent *me = static_cast<QMouseEvent *>(event);
|
QMouseEvent *me = static_cast<QMouseEvent *>(event);
|
||||||
|
|
||||||
|
if (!validMouseEvent(me)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
mouseMoveEvent(me);
|
mouseMoveEvent(me);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QEvent::MouseButtonRelease: {
|
case QEvent::MouseButtonRelease: {
|
||||||
QMouseEvent *me = static_cast<QMouseEvent *>(event);
|
QMouseEvent *me = static_cast<QMouseEvent *>(event);
|
||||||
|
|
||||||
|
if (!validMouseEvent(me)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
mouseReleaseEvent(me);
|
mouseReleaseEvent(me);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -129,3 +144,22 @@ void WidgetContainer::onActiveFocusChanged(bool activeFocus)
|
||||||
setEditMode(false);
|
setEditMode(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WidgetContainer::validMouseEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
bool synthesized = event->source() == Qt::MouseEventSynthesizedByQt || event->source() == Qt::MouseEventSynthesizedBySystem;
|
||||||
|
|
||||||
|
// Don't need to block propagated events
|
||||||
|
if (!synthesized || event->type() != QEvent::MouseButtonRelease) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If edit mode is not enabled, let the event propagate
|
||||||
|
if (!m_editMode) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
// If edit mode is enabled, block the event propagation and handle it only on the WidgetContainer
|
||||||
|
mouseReleaseEvent(event);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,8 @@ private Q_SLOTS:
|
||||||
void onActiveFocusChanged(bool activeFocus);
|
void onActiveFocusChanged(bool activeFocus);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool validMouseEvent(QMouseEvent *event);
|
||||||
|
|
||||||
bool m_pressed{false};
|
bool m_pressed{false};
|
||||||
bool m_editMode{false};
|
bool m_editMode{false};
|
||||||
QTimer *m_pressAndHoldTimer{nullptr};
|
QTimer *m_pressAndHoldTimer{nullptr};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue