[vlc-commits] [Git][videolan/vlc][master] 2 commits: qt: qml: rename QmlEventFilter to ItemKeyEventFilter

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Sun Nov 28 14:28:03 UTC 2021



Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC


Commits:
d9062980 by Fatih Uzunoglu at 2021-11-28T14:14:33+00:00
qt: qml: rename QmlEventFilter to ItemKeyEventFilter

- - - - -
016dfd44 by Fatih Uzunoglu at 2021-11-28T14:14:33+00:00
qt: rename properties in ItemKeyEventFilter

- - - - -


5 changed files:

- modules/gui/qt/Makefile.am
- modules/gui/qt/maininterface/mainui.cpp
- modules/gui/qt/player/qml/Player.qml
- modules/gui/qt/util/qmleventfilter.cpp → modules/gui/qt/util/item_key_event_filter.cpp
- modules/gui/qt/util/qmleventfilter.hpp → modules/gui/qt/util/item_key_event_filter.hpp


Changes:

=====================================
modules/gui/qt/Makefile.am
=====================================
@@ -240,8 +240,8 @@ libqt_plugin_la_SOURCES = \
 	gui/qt/util/navigation_history.cpp gui/qt/util/navigation_history.hpp \
 	gui/qt/util/qml_main_context.cpp \
 	gui/qt/util/qml_main_context.hpp \
-	gui/qt/util/qmleventfilter.cpp \
-	gui/qt/util/qmleventfilter.hpp \
+	gui/qt/util/item_key_event_filter.cpp \
+	gui/qt/util/item_key_event_filter.hpp \
 	gui/qt/util/qt_dirs.cpp gui/qt/util/qt_dirs.hpp \
 	gui/qt/util/qvlcapp.hpp \
 	gui/qt/util/proxycolumnmodel.hpp \
@@ -418,7 +418,7 @@ nodist_libqt_plugin_la_SOURCES = \
 	gui/qt/util/listcache.moc.cpp \
 	gui/qt/util/navigation_history.moc.cpp \
 	gui/qt/util/qml_main_context.moc.cpp \
-	gui/qt/util/qmleventfilter.moc.cpp \
+	gui/qt/util/item_key_event_filter.moc.cpp \
 	gui/qt/util/mouse_event_filter.moc.cpp \
 	gui/qt/util/qvlcapp.moc.cpp \
 	gui/qt/util/renderer_manager.moc.cpp \


=====================================
modules/gui/qt/maininterface/mainui.cpp
=====================================
@@ -29,7 +29,7 @@
 #include "playlist/playlist_controller.hpp"
 
 #include "util/qml_main_context.hpp"
-#include "util/qmleventfilter.hpp"
+#include "util/item_key_event_filter.hpp"
 #include "util/imageluminanceextractor.hpp"
 #include "util/i18n.hpp"
 #include "util/keyhelper.hpp"
@@ -211,7 +211,7 @@ void MainUI::registerQMLTypes()
         qmlRegisterUncreatableType<DialogErrorModel>( uri, versionMajor, versionMinor, "DialogErrorModel", "");
         qRegisterMetaType<DialogId>();
 
-        qmlRegisterType<QmlEventFilter>( uri, versionMajor, versionMinor, "EventFilter" );
+        qmlRegisterType<ItemKeyEventFilter>( uri, versionMajor, versionMinor, "KeyEventFilter" );
         qmlRegisterType<MouseEventFilter>( uri, versionMajor, versionMinor, "MouseEventFilter" );
 
         qmlRegisterUncreatableType<ControlbarProfileModel>(uri, versionMajor, versionMinor, "ControlbarProfileModel", "");


=====================================
modules/gui/qt/player/qml/Player.qml
=====================================
@@ -635,13 +635,13 @@ FocusScope {
 
     }
 
-    //filter global events to keep toolbar
+    //filter key events to keep toolbar
     //visible when user navigates within the control bar
-    EventFilter {
+    KeyEventFilter {
         id: filter
-        source: topWindow
-        filterEnabled: controlBarView.state === "visible"
-                       && (controlBarView.focus || topcontrolView.focus)
+        target: topWindow
+        enabled: controlBarView.state === "visible"
+                 && (controlBarView.focus || topcontrolView.focus)
         Keys.onPressed: toolbarAutoHide.setVisible(5000)
     }
 


=====================================
modules/gui/qt/util/qmleventfilter.cpp → modules/gui/qt/util/item_key_event_filter.cpp
=====================================
@@ -15,27 +15,29 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
-#include "qmleventfilter.hpp"
+#include "item_key_event_filter.hpp"
 #include <QEvent>
 
-QmlEventFilter::QmlEventFilter(QQuickItem *parent)
+ItemKeyEventFilter::ItemKeyEventFilter(QQuickItem *parent)
     : QQuickItem(parent)
 {
 }
 
-QmlEventFilter::~QmlEventFilter()
+ItemKeyEventFilter::~ItemKeyEventFilter()
 {
-    if (m_source != nullptr)
-        m_source->removeEventFilter(this);
+    if (m_target)
+        m_target->removeEventFilter(this);
 }
 
-void QmlEventFilter::setSource(QObject* source)
+void ItemKeyEventFilter::setTarget(QObject* target)
 {
-    source->installEventFilter(this);
-    m_source = source;
+    assert(target);
+
+    target->installEventFilter(this);
+    m_target = target;
 }
 
-void QmlEventFilter::keyPressEvent(QKeyEvent* event)
+void ItemKeyEventFilter::keyPressEvent(QKeyEvent* event)
 {
     // This is actually called when the QML event handler hasn't accepted the event
     m_qmlAccepted = false;
@@ -43,15 +45,15 @@ void QmlEventFilter::keyPressEvent(QKeyEvent* event)
     event->setAccepted(true);
 }
 
-void QmlEventFilter::keyReleaseEvent(QKeyEvent* event)
+void ItemKeyEventFilter::keyReleaseEvent(QKeyEvent* event)
 {
     m_qmlAccepted = false;
     event->setAccepted(true);
 }
 
-bool QmlEventFilter::eventFilter(QObject*, QEvent* event)
+bool ItemKeyEventFilter::eventFilter(QObject*, QEvent* event)
 {
-    if (!m_filterEnabled)
+    if (!m_enabled)
         return false;
 
     bool ret = false;


=====================================
modules/gui/qt/util/qmleventfilter.hpp → modules/gui/qt/util/item_key_event_filter.hpp
=====================================
@@ -15,15 +15,16 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
-#ifndef QMLEVENTFILTER_HPP
-#define QMLEVENTFILTER_HPP
+#ifndef ITEMKEYEVENTFILTER_HPP
+#define ITEMKEYEVENTFILTER_HPP
 
 #include <QQuickItem>
 
 /**
- * @brief The QmlEventFilter class allows to register an event filter from QML
- * this might be usefull to process key press before they are processed (and
- * eventually accepted) by children components
+ * @brief The ItemKeyEventFilter class allows to register an event filter,
+ * which forwards the filtered key events to itself. This might be useful to
+ * process key press before they are processed (and eventually accepted) by
+ * children components
  *
  * this is usable as
  *
@@ -39,37 +40,30 @@
  *      filter.source = rootWindow
  *  }
  *
- * Note that this solution doesn't work as-is for mouse events as Qml doesn't provide
- * the equivalent of Keys.onPressed.
  */
-class QmlEventFilter : public QQuickItem
+class ItemKeyEventFilter : public QQuickItem
 {
     Q_OBJECT
 public:
-    Q_PROPERTY(QObject * source READ getSource WRITE setSource FINAL)
-    Q_PROPERTY(bool filterEnabled READ getFilterEnabled WRITE setFilterEnabled FINAL)
+    Q_PROPERTY(QObject * target MEMBER m_target WRITE setTarget FINAL)
+    Q_PROPERTY(bool enabled MEMBER m_enabled FINAL)
 
 public:
-    QmlEventFilter(QQuickItem *parent = nullptr);
-    ~QmlEventFilter();
+    ItemKeyEventFilter(QQuickItem *parent = nullptr);
+    ~ItemKeyEventFilter();
 
-    void setSource(QObject *source);
-
-    inline QObject * getSource() { return m_source; }
-    inline void setFilterEnabled(bool value) { m_filterEnabled = value; }
-    inline bool getFilterEnabled() { return m_filterEnabled; }
+    void setTarget(QObject *target);
 
 private:
-
     void keyPressEvent(QKeyEvent *event) override;
-
     void keyReleaseEvent(QKeyEvent *event) override;
 
     bool eventFilter(QObject *obj, QEvent *event) override;
 
 private:
-    QObject *m_source = nullptr;
-    bool m_filterEnabled = true;
+    QObject *m_target = nullptr;
+    bool m_enabled = true;
     bool m_qmlAccepted = false;
 };
-#endif // QMLEVENTFILTER_HPP
+
+#endif // ITEMKEYEVENTFILTER_HPP



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/8a56f80c5998d7863493a1db7ce3f89f4d781444...016dfd442a008ea6f0dcb676cb6a32603d10c4ad

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




More information about the vlc-commits mailing list