[vlc-commits] [Git][videolan/vlc][master] 2 commits: qml: compat for HoverHandler

Steve Lhomme (@robUx4) gitlab at videolan.org
Tue Jan 17 10:26:15 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
e52b8e95 by Yann Lochet at 2023-01-17T09:53:59+01:00
qml: compat for HoverHandler

- - - - -
39e7bc0f by Yann Lochet at 2023-01-17T09:54:01+01:00
qml/GridItem: make hover mouse-only

- - - - -


8 changed files:

- modules/gui/qt/Makefile.am
- modules/gui/qt/maininterface/mainui.cpp
- modules/gui/qt/meson.build
- + modules/gui/qt/util/hover_handler_rev11.cpp
- + modules/gui/qt/util/hover_handler_rev11.hpp
- + modules/gui/qt/util/qml/MouseHoverHandlerRev12.qml
- modules/gui/qt/vlc.qrc
- modules/gui/qt/widgets/qml/GridItem.qml


Changes:

=====================================
modules/gui/qt/Makefile.am
=====================================
@@ -287,6 +287,8 @@ libqt_plugin_la_SOURCES = \
 	gui/qt/util/item_key_event_filter.hpp \
 	gui/qt/util/flickable_scroll_handler.cpp \
 	gui/qt/util/flickable_scroll_handler.hpp \
+	gui/qt/util/hover_handler_rev11.cpp \
+	gui/qt/util/hover_handler_rev11.hpp \
 	gui/qt/util/qt_dirs.cpp gui/qt/util/qt_dirs.hpp \
 	gui/qt/util/qvlcapp.hpp \
 	gui/qt/util/proxycolumnmodel.hpp \
@@ -486,6 +488,7 @@ nodist_libqt_plugin_la_SOURCES = \
 	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 \
 	gui/qt/util/qvlcapp.moc.cpp \
 	gui/qt/util/renderer_manager.moc.cpp \
 	gui/qt/util/selectable_list_model.moc.cpp \
@@ -565,6 +568,7 @@ uic_verbose__0 = $(uic_verbose_0)
 
 MOC_CPPFLAGS = $(DEFS) \
 	-I$(top_srcdir)/include -I$(top_builddir)/include -I$(top_builddir) \
+	$(QT_CFLAGS) \
 	$(libqt_plugin_la_CPPFLAGS)
 if HAVE_DARWIN
 MOC_CPPFLAGS += -DQ_OS_MAC
@@ -969,6 +973,7 @@ libqt_plugin_la_QML = \
 	gui/qt/util/qml/ViewDragAutoScrollHandler.qml \
 	gui/qt/util/qml/BindingRev8.qml \
 	gui/qt/util/qml/BindingRev14.qml \
+	gui/qt/util/qml/MouseHoverHandlerRev12.qml \
 	gui/qt/util/qml/TouchScreenTapHandlerRev11.qml \
 	gui/qt/util/qml/TouchScreenTapHandlerRev12.qml \
 	gui/qt/util/qml/VanillaObject.qml \


=====================================
modules/gui/qt/maininterface/mainui.cpp
=====================================
@@ -42,6 +42,7 @@
 #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"
 #include "util/effects_image_provider.hpp"
 #include "util/csdbuttonmodel.hpp"
@@ -331,8 +332,10 @@ void MainUI::registerQMLTypes()
 #endif
 
 #if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
+        qmlRegisterType(QUrl("qrc:///util/MouseHoverHandlerRev12.qml"), uri, versionMajor, versionMinor, "MouseHoverHandlerCompat");
         qmlRegisterType(QUrl("qrc:///util/TouchScreenTapHandlerRev12.qml"), uri, versionMajor, versionMinor, "TouchScreenTapHandlerCompat");
 #else
+        qmlRegisterType<HoverHandlerRev11>( uri, versionMajor, versionMinor, "MouseHoverHandlerCompat" );
         qmlRegisterType(QUrl("qrc:///util/TouchScreenTapHandlerRev11.qml"), uri, versionMajor, versionMinor, "TouchScreenTapHandlerCompat");
 #endif
 


=====================================
modules/gui/qt/meson.build
=====================================
@@ -125,6 +125,7 @@ moc_headers = files(
     'util/mouse_event_filter.hpp',
     'util/effects_image_provider.hpp',
     'util/flickable_scroll_handler.hpp',
+    'util/hover_handler_rev11.hpp',
     'util/qvlcapp.hpp',
     'util/renderer_manager.hpp',
     'util/selectable_list_model.hpp',
@@ -417,6 +418,8 @@ some_sources = files(
     'util/item_key_event_filter.hpp',
     'util/flickable_scroll_handler.cpp',
     'util/flickable_scroll_handler.hpp',
+    'util/hover_handler_rev11.cpp',
+    'util/hover_handler_rev11.hpp',
     'util/qt_dirs.cpp',
     'util/qt_dirs.hpp',
     'util/qvlcapp.hpp',
@@ -534,7 +537,8 @@ if qt5_dep.found()
     qt5pre_files = qt5.preprocess(ui_files: ui_sources,
         moc_headers: moc_headers,
         qresources: qrc_files,
-        include_directories: qt_include_dir)
+        include_directories: qt_include_dir,
+        dependencies: qt5_dep)
 
     qt_sources = files('qt.cpp')
 


=====================================
modules/gui/qt/util/hover_handler_rev11.cpp
=====================================
@@ -0,0 +1,79 @@
+/*****************************************************************************
+ * Copyright (C) 2023 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 "hover_handler_rev11.hpp"
+
+HoverHandlerRev11::HoverHandlerRev11(QObject *parent)
+    : QObject(parent)
+{
+}
+
+HoverHandlerRev11::~HoverHandlerRev11()
+{
+    setTarget(nullptr);
+}
+
+void HoverHandlerRev11::setTarget(QQuickItem* target)
+{
+    if (m_target)
+        m_target->removeEventFilter(this);
+
+    m_target = target;
+
+    if (m_target)
+    {
+        m_target->setAcceptHoverEvents(true);
+        m_target->installEventFilter(this);
+    }
+}
+
+bool HoverHandlerRev11::eventFilter(QObject*, QEvent* event)
+{
+    bool changed = true;
+
+    switch (event->type())
+    {
+    case QEvent::HoverEnter:
+        m_hovered = true;
+        break;
+    case QEvent::HoverLeave:
+        m_hovered = false;
+        break;
+    default:
+        changed = false;
+        break;
+    }
+
+    if (changed)
+        emit hoveredChanged();
+
+    return changed;
+}
+
+void HoverHandlerRev11::classBegin()
+{
+}
+
+void HoverHandlerRev11::componentComplete()
+{
+    if (!m_target)
+    {
+        auto parentItem = qobject_cast<QQuickItem*>(QObject::parent());
+        if (parentItem)
+            setTarget(parentItem);
+    }
+}


=====================================
modules/gui/qt/util/hover_handler_rev11.hpp
=====================================
@@ -0,0 +1,56 @@
+/*****************************************************************************
+ * Copyright (C) 2023 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 HOVERHANDLERREV11_HPP
+#define HOVERHANDLERREV11_HPP
+
+#include <QQuickItem>
+#include <QQmlParserStatus>
+
+class HoverHandlerRev11 : public QObject, public QQmlParserStatus
+{
+    Q_OBJECT
+    Q_INTERFACES(QQmlParserStatus)
+
+public:
+    Q_PROPERTY(QQuickItem * target MEMBER m_target WRITE setTarget FINAL)
+    Q_PROPERTY(bool hovered READ isHovered NOTIFY hoveredChanged FINAL)
+
+public:
+    HoverHandlerRev11(QObject *parent = nullptr);
+    ~HoverHandlerRev11();
+
+    void setTarget(QQuickItem *target);
+
+    inline bool isHovered() const { return m_hovered; }
+
+signals:
+    void hoveredChanged();
+
+private:
+    bool eventFilter(QObject *obj, QEvent *event) override;
+
+protected:
+    void classBegin() override;
+    void componentComplete() override;
+
+private:
+    QQuickItem *m_target = nullptr;
+    bool m_hovered = false;
+};
+
+#endif


=====================================
modules/gui/qt/util/qml/MouseHoverHandlerRev12.qml
=====================================
@@ -0,0 +1,26 @@
+/*****************************************************************************
+ * Copyright (C) 2022 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.
+ *****************************************************************************/
+
+import QtQuick 2.12
+
+// Due to a bug ( https://bugreports.qt.io/browse/QTBUG-85427 )
+// this handler might react to touch events
+
+HoverHandler {
+    acceptedDevices: PointerDevice.Mouse
+}


=====================================
modules/gui/qt/vlc.qrc
=====================================
@@ -76,6 +76,7 @@
         <file alias="ViewDragAutoScrollHandler.qml">util/qml/ViewDragAutoScrollHandler.qml</file>
         <file alias="BindingRev8.qml">util/qml/BindingRev8.qml</file>
         <file alias="BindingRev14.qml">util/qml/BindingRev14.qml</file>
+        <file alias="MouseHoverHandlerRev12.qml">util/qml/MouseHoverHandlerRev12.qml</file>
         <file alias="TouchScreenTapHandlerRev11.qml">util/qml/TouchScreenTapHandlerRev11.qml</file>
         <file alias="TouchScreenTapHandlerRev12.qml">util/qml/TouchScreenTapHandlerRev12.qml</file>
         <file alias="VanillaObject.qml">util/qml/VanillaObject.qml</file>


=====================================
modules/gui/qt/widgets/qml/GridItem.qml
=====================================
@@ -38,7 +38,7 @@ T.Control {
     property int titleMargin: VLCStyle.margin_xsmall
     property Item dragItem: null
 
-    readonly property bool highlighted: (contentItem.containsMouse || visualFocus)
+    readonly property bool highlighted: (mouseHoverHandler.hovered || visualFocus)
 
     readonly property int selectedBorderWidth: VLCStyle.gridItemSelectedBorder
 
@@ -172,8 +172,6 @@ T.Control {
 
         acceptedButtons: Qt.RightButton | Qt.LeftButton
 
-        hoverEnabled: true
-
         drag.target: root.dragItem
 
         drag.axis: Drag.XAndYAxis
@@ -219,6 +217,10 @@ T.Control {
             }
         }
 
+        MouseHoverHandlerCompat {
+            id: mouseHoverHandler
+        }
+
         ColumnLayout {
             id: layout
 
@@ -329,14 +331,10 @@ T.Control {
 
                 ToolTip.delay: VLCStyle.delayToolTipAppear
                 ToolTip.text: subtitleTxt.text
-                ToolTip.visible: subtitleTxtMouseArea.containsMouse
+                ToolTip.visible: subtitleTxtMouseHandler.hovered
 
-                MouseArea {
-                    id: subtitleTxtMouseArea
-
-                    anchors.fill: parent
-                    hoverEnabled: true
-                    acceptedButtons: Qt.NoButton
+                MouseHoverHandlerCompat {
+                    id: subtitleTxtMouseHandler
                 }
             }
         }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ab1409774462f06e7eecf75af9229639fd4ca9ee...39e7bc0f52c6ac8516aa523bdb829cc7f390fd51

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ab1409774462f06e7eecf75af9229639fd4ca9ee...39e7bc0f52c6ac8516aa523bdb829cc7f390fd51
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