[vlc-commits] [Git][videolan/vlc][master] 5 commits: qml: use MouseArea instead of MouseEventFilter in KeyNavigableListView

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Fri Apr 28 09:00:53 UTC 2023



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
e5b382a4 by Fatih Uzunoglu at 2023-04-28T08:06:30+00:00
qml: use MouseArea instead of MouseEventFilter in KeyNavigableListView

- - - - -
410a4674 by Fatih Uzunoglu at 2023-04-28T08:06:30+00:00
qml: use MouseArea instead of MouseEventFilter in ExpandGridView

- - - - -
f86b5979 by Fatih Uzunoglu at 2023-04-28T08:06:30+00:00
qml: use MouseArea instead of MouseEventFilter in EditorDNDView

- - - - -
484d465d by Fatih Uzunoglu at 2023-04-28T08:06:30+00:00
qml: use MouseArea instead of MouseEventFilter in ToolbarEditorButtonList

- - - - -
e6ff7c6e by Fatih Uzunoglu at 2023-04-28T08:06:30+00:00
qt: get rid of MouseEventFilter

- - - - -


9 changed files:

- modules/gui/qt/Makefile.am
- modules/gui/qt/dialogs/toolbar/qml/EditorDNDView.qml
- modules/gui/qt/dialogs/toolbar/qml/ToolbarEditorButtonList.qml
- modules/gui/qt/maininterface/mainui.cpp
- modules/gui/qt/meson.build
- − modules/gui/qt/util/mouse_event_filter.cpp
- − modules/gui/qt/util/mouse_event_filter.hpp
- modules/gui/qt/widgets/qml/ExpandGridView.qml
- modules/gui/qt/widgets/qml/KeyNavigableListView.qml


Changes:

=====================================
modules/gui/qt/Makefile.am
=====================================
@@ -325,8 +325,6 @@ libqt_plugin_la_SOURCES = \
 	gui/qt/util/vlctick.cpp \
 	gui/qt/util/vlctick.hpp \
 	gui/qt/util/qmlinputitem.hpp \
-	gui/qt/util/mouse_event_filter.cpp \
-	gui/qt/util/mouse_event_filter.hpp \
 	gui/qt/util/effects_image_provider.cpp \
 	gui/qt/util/effects_image_provider.hpp \
 	gui/qt/util/qsgroundedrectangularimagenode.cpp \
@@ -505,7 +503,6 @@ nodist_libqt_plugin_la_SOURCES = \
 	gui/qt/util/keyhelper.moc.cpp \
 	gui/qt/util/navigation_history.moc.cpp \
 	gui/qt/util/item_key_event_filter.moc.cpp \
-	gui/qt/util/mouse_event_filter.moc.cpp \
 	gui/qt/util/effects_image_provider.moc.cpp \
 	gui/qt/util/flickable_scroll_handler.moc.cpp \
 	gui/qt/util/hover_handler_rev11.moc.cpp \


=====================================
modules/gui/qt/dialogs/toolbar/qml/EditorDNDView.qml
=====================================
@@ -98,10 +98,6 @@ ListView {
         colorSet: ColorContext.View
     }
     
-    MouseEventFilter {
-        target: playerBtnDND
-    }
-
     Util.FlickableScrollHandler {
         fallbackScroll: true
         enabled: true
@@ -110,7 +106,8 @@ ListView {
     MouseArea {
         anchors.fill: parent
 
-        acceptedButtons: Qt.NoButton
+        preventStealing: true
+
         z: -1
 
         cursorShape: root.dragActive ? Qt.DragMoveCursor : Qt.ArrowCursor


=====================================
modules/gui/qt/dialogs/toolbar/qml/ToolbarEditorButtonList.qml
=====================================
@@ -52,8 +52,11 @@ GridView {
         colorSet: ColorContext.View
     }
 
-    MouseEventFilter {
-        target: root
+    MouseArea {
+        anchors.fill: parent
+        z: -1
+
+        preventStealing: true
     }
 
     Util.FlickableScrollHandler { }


=====================================
modules/gui/qt/maininterface/mainui.cpp
=====================================
@@ -40,7 +40,6 @@
 #include "util/sortfilterproxymodel.hpp"
 #include "util/navigation_history.hpp"
 #include "util/qmlinputitem.hpp"
-#include "util/mouse_event_filter.hpp"
 #include "util/flickable_scroll_handler.hpp"
 #include "util/hover_handler_rev11.hpp"
 #include "util/color_svg_image_provider.hpp"
@@ -287,7 +286,6 @@ void MainUI::registerQMLTypes()
         qmlRegisterUncreatableType<DialogId>( uri, versionMajor, versionMinor, "DialogId", "");
 
         qmlRegisterType<ItemKeyEventFilter>( uri, versionMajor, versionMinor, "KeyEventFilter" );
-        qmlRegisterType<MouseEventFilter>( uri, versionMajor, versionMinor, "MouseEventFilter" );
         qmlRegisterType<FlickableScrollHandler>( uri, versionMajor, versionMinor, "FlickableScrollHandler" );
 
         qmlRegisterUncreatableType<ControlbarProfileModel>(uri, versionMajor, versionMinor, "ControlbarProfileModel", "");


=====================================
modules/gui/qt/meson.build
=====================================
@@ -126,7 +126,6 @@ moc_headers = files(
     'util/keyhelper.hpp',
     'util/navigation_history.hpp',
     'util/item_key_event_filter.hpp',
-    'util/mouse_event_filter.hpp',
     'util/effects_image_provider.hpp',
     'util/flickable_scroll_handler.hpp',
     'util/hover_handler_rev11.hpp',
@@ -455,8 +454,6 @@ some_sources = files(
     'util/vlctick.cpp',
     'util/vlctick.hpp',
     'util/qmlinputitem.hpp',
-    'util/mouse_event_filter.cpp',
-    'util/mouse_event_filter.hpp',
     'util/effects_image_provider.cpp',
     'util/effects_image_provider.hpp',
     'util/qsgroundedrectangularimagenode.cpp',


=====================================
modules/gui/qt/util/mouse_event_filter.cpp deleted
=====================================
@@ -1,124 +0,0 @@
-/*****************************************************************************
- * Copyright (C) 2021 VLC authors and VideoLAN
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * ( at your option ) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-#include "mouse_event_filter.hpp"
-
-#include <QMouseEvent>
-#include <QQuickItem>
-
-MouseEventFilter::MouseEventFilter(QObject *parent)
-    : QObject(parent)
-{
-
-}
-
-MouseEventFilter::~MouseEventFilter()
-{
-    detach();
-}
-
-QObject *MouseEventFilter::target() const
-{
-    return m_target;
-}
-
-void MouseEventFilter::setTarget(QObject *newTarget)
-{
-    if (m_target == newTarget)
-        return;
-
-    detach();
-    m_target = newTarget;
-    attach();
-
-    emit targetChanged();
-}
-
-bool MouseEventFilter::eventFilter(QObject *watched, QEvent *event)
-{
-    assert(watched == m_target);
-
-    const auto mouse = dynamic_cast<QMouseEvent*>(event);
-    if (!mouse)
-        return false;
-
-    if (!m_filterEventsSynthesizedByQt &&
-        mouse->source() == Qt::MouseEventSource::MouseEventSynthesizedByQt)
-        return false;
-
-    switch (event->type())
-    {
-    case QEvent::MouseButtonDblClick:
-        emit mouseButtonDblClick(mouse->localPos(),
-                                 mouse->globalPos(),
-                                 mouse->buttons(),
-                                 mouse->modifiers(),
-                                 mouse->source(),
-                                 mouse->flags()); break;
-    case QEvent::MouseButtonPress:
-        emit mouseButtonPress(mouse->localPos(),
-                              mouse->globalPos(),
-                              mouse->buttons(),
-                              mouse->modifiers(),
-                              mouse->source(),
-                              mouse->flags()); break;
-    case QEvent::MouseButtonRelease:
-        emit mouseButtonRelease(mouse->localPos(),
-                                mouse->globalPos(),
-                                mouse->button(),
-                                mouse->modifiers(),
-                                mouse->source(),
-                                mouse->flags()); break;
-    case QEvent::MouseMove:
-        emit mouseMove(mouse->localPos(),
-                       mouse->globalPos(),
-                       mouse->buttons(),
-                       mouse->modifiers(),
-                       mouse->source(),
-                       mouse->flags()); break;
-
-    default:
-        return false;
-    }
-
-    return true;
-}
-
-void MouseEventFilter::attach()
-{
-    if (m_target)
-    {
-        m_target->installEventFilter(this);
-        const auto item = qobject_cast<QQuickItem*>(m_target);
-        if (item)
-        {
-            m_targetItemInitialAcceptedMouseButtons = item->acceptedMouseButtons();
-            item->setAcceptedMouseButtons(Qt::AllButtons);
-        }
-    }
-}
-
-void MouseEventFilter::detach()
-{
-    if (m_target)
-    {
-        m_target->removeEventFilter(this);
-        const auto item = qobject_cast<QQuickItem*>(m_target);
-        if (item)
-            item->setAcceptedMouseButtons(m_targetItemInitialAcceptedMouseButtons);
-    }
-}


=====================================
modules/gui/qt/util/mouse_event_filter.hpp deleted
=====================================
@@ -1,60 +0,0 @@
-/*****************************************************************************
- * Copyright (C) 2021 VLC authors and VideoLAN
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * ( at your option ) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-#ifndef MOUSEEVENTFILTER_HPP
-#define MOUSEEVENTFILTER_HPP
-
-#include <QObject>
-#include <QPointF>
-#include <QPointer>
-
-class MouseEventFilter : public QObject
-{
-    Q_OBJECT
-
-    Q_PROPERTY(QObject* target READ target WRITE setTarget NOTIFY targetChanged FINAL)
-    Q_PROPERTY(bool filterEventsSynthesizedByQt MEMBER m_filterEventsSynthesizedByQt NOTIFY filterEventsSynthesizedByQtChanged FINAL)
-
-public:
-    explicit MouseEventFilter(QObject *parent = nullptr);
-    ~MouseEventFilter();
-
-    QObject *target() const;
-    void setTarget(QObject *newTarget);
-
-signals:
-    void targetChanged();
-    void filterEventsSynthesizedByQtChanged();
-
-    void mouseButtonDblClick(QPointF localPos, QPointF globalPos, int buttons, int modifiers, int source, int flags);
-    void mouseButtonPress(QPointF localPos, QPointF globalPos, int buttons, int modifiers, int source, int flags);
-    void mouseButtonRelease(QPointF localPos, QPointF globalPos, int button, int modifiers, int source, int flags);
-    void mouseMove(QPointF localPos, QPointF globalPos, int buttons, int modifiers, int source, int flags);
-
-private:
-    bool eventFilter(QObject *watched, QEvent *event) override;
-
-    void attach();
-    void detach();
-
-private:
-    QPointer<QObject> m_target;
-    Qt::MouseButtons m_targetItemInitialAcceptedMouseButtons = Qt::NoButton;
-    bool m_filterEventsSynthesizedByQt = false;
-};
-
-#endif // MOUSEEVENTFILTER_HPP


=====================================
modules/gui/qt/widgets/qml/ExpandGridView.qml
=====================================
@@ -606,23 +606,25 @@ FocusScope {
             id: flickableScrollBar
         }
 
-        MouseEventFilter {
-            target: flickable
+        MouseArea {
+            anchors.fill: parent
+            z: -1
 
-            onMouseButtonPress: {
-                if (buttons & (Qt.LeftButton | Qt.RightButton)) {
-                    Helpers.enforceFocus(flickable, Qt.MouseFocusReason)
+            preventStealing: true
+            acceptedButtons: Qt.LeftButton | Qt.RightButton
 
-                    if (!(modifiers & (Qt.ShiftModifier | Qt.ControlModifier))) {
-                        if (selectionDelegateModel)
-                            selectionDelegateModel.clear()
-                    }
+            onPressed: {
+                Helpers.enforceFocus(flickable, Qt.MouseFocusReason)
+
+                if (!(mouse.modifiers & (Qt.ShiftModifier | Qt.ControlModifier))) {
+                    if (selectionDelegateModel)
+                        selectionDelegateModel.clear()
                 }
             }
 
-            onMouseButtonRelease: {
-                if (button & Qt.RightButton) {
-                    root.showContextMenu(globalPos)
+            onReleased: {
+                if (mouse.button & Qt.RightButton) {
+                    root.showContextMenu(mapToGlobal(mouse.x, mouse.y))
                 }
             }
         }


=====================================
modules/gui/qt/widgets/qml/KeyNavigableListView.qml
=====================================
@@ -266,27 +266,6 @@ FadingEdgeListView {
         }
     }
 
-
-    MouseEventFilter {
-        target: root
-
-        onMouseButtonPress: {
-            if (buttons & (Qt.LeftButton | Qt.RightButton)) {
-                Helpers.enforceFocus(root, Qt.MouseFocusReason)
-
-                if (!(modifiers & (Qt.ShiftModifier | Qt.ControlModifier))) {
-                    root.deselectAll()
-                }
-            }
-        }
-
-        onMouseButtonRelease: {
-            if (button & Qt.RightButton) {
-                root.showContextMenu(globalPos)
-            }
-        }
-    }
-
     Util.ViewDragAutoScrollHandler {
         id: dragAutoScrollHandler
 
@@ -305,6 +284,32 @@ FadingEdgeListView {
         }
     }
 
+    MouseArea {
+        anchors.fill: parent
+
+        z: -1
+
+        preventStealing: true
+
+        acceptedButtons: Qt.LeftButton | Qt.RightButton
+
+        onPressed: {
+            Helpers.enforceFocus(root, Qt.MouseFocusReason)
+
+            if (!(mouse.modifiers & (Qt.ShiftModifier | Qt.ControlModifier))) {
+                root.deselectAll()
+            }
+
+            mouse.accepted = true
+        }
+
+        onReleased: {
+            if (mouse.button & Qt.RightButton) {
+                root.showContextMenu(mapToGlobal(mouse.x, mouse.y))
+            }
+        }
+    }
+
     // FIXME: We probably need to upgrade these RoundButton(s) eventually. And we probably need
     //        to have some kind of animation when switching pages.
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/a29868eb4bf91bddb5f2ea631b54c8cb60dbb5b9...e6ff7c6e59fde04b40d0e33cd3198a2a036b7348

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/a29868eb4bf91bddb5f2ea631b54c8cb60dbb5b9...e6ff7c6e59fde04b40d0e33cd3198a2a036b7348
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list