diff --git a/containments/homescreens/folio/widgetcontainer.cpp b/containments/homescreens/folio/widgetcontainer.cpp index 523ccae6..852a33c1 100644 --- a/containments/homescreens/folio/widgetcontainer.cpp +++ b/containments/homescreens/folio/widgetcontainer.cpp @@ -57,6 +57,11 @@ bool WidgetContainer::childMouseEventFilter(QQuickItem *item, QEvent *event) switch (event->type()) { case QEvent::MouseButtonPress: { QMouseEvent *me = static_cast(event); + + if (!validMouseEvent(me)) { + return true; + } + if (me->buttons() & Qt::LeftButton) { mousePressEvent(me); } @@ -64,11 +69,21 @@ bool WidgetContainer::childMouseEventFilter(QQuickItem *item, QEvent *event) } case QEvent::MouseMove: { QMouseEvent *me = static_cast(event); + + if (!validMouseEvent(me)) { + return true; + } + mouseMoveEvent(me); break; } case QEvent::MouseButtonRelease: { QMouseEvent *me = static_cast(event); + + if (!validMouseEvent(me)) { + return true; + } + mouseReleaseEvent(me); break; } @@ -129,3 +144,22 @@ void WidgetContainer::onActiveFocusChanged(bool activeFocus) 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; + } +} diff --git a/containments/homescreens/folio/widgetcontainer.h b/containments/homescreens/folio/widgetcontainer.h index cee3ce85..d7c74ff7 100644 --- a/containments/homescreens/folio/widgetcontainer.h +++ b/containments/homescreens/folio/widgetcontainer.h @@ -37,6 +37,8 @@ private Q_SLOTS: void onActiveFocusChanged(bool activeFocus); private: + bool validMouseEvent(QMouseEvent *event); + bool m_pressed{false}; bool m_editMode{false}; QTimer *m_pressAndHoldTimer{nullptr};