[vlc-commits] [Git][videolan/vlc][master] 3 commits: qt: add C++ KeyHelper wrapper for QML
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Sun Jul 11 15:35:48 UTC 2021
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
28776845 by Pierre Lamot at 2021-07-11T14:15:56+00:00
qt: add C++ KeyHelper wrapper for QML
this allows to avoid code duplication between C++ and QML
- - - - -
33b1fb29 by Pierre Lamot at 2021-07-11T14:15:56+00:00
qml: use C++ version of KeyHelper
- - - - -
7f6e6a76 by Pierre Lamot at 2021-07-11T14:15:56+00:00
qml: remove js implementation of KeyHelper
- - - - -
28 changed files:
- modules/gui/qt/Makefile.am
- modules/gui/qt/dialogs/help/qml/About.qml
- modules/gui/qt/maininterface/mainui.cpp
- modules/gui/qt/maininterface/qml/BannerSources.qml
- modules/gui/qt/maininterface/qml/MainDisplay.qml
- modules/gui/qt/medialibrary/qml/EmptyLabel.qml
- modules/gui/qt/medialibrary/qml/UrlListDisplay.qml
- modules/gui/qt/medialibrary/qml/VideoInfoExpandPanel.qml
- modules/gui/qt/network/qml/DiscoverUrlDisplay.qml
- modules/gui/qt/player/qml/ControlButtons.qml
- modules/gui/qt/player/qml/LanguageMenu.qml
- modules/gui/qt/player/qml/MiniPlayer.qml
- modules/gui/qt/player/qml/Player.qml
- modules/gui/qt/player/qml/PlayerMenuItem.qml
- modules/gui/qt/player/qml/VolumeWidget.qml
- modules/gui/qt/playlist/qml/PlaylistListView.qml
- modules/gui/qt/playlist/qml/PlaylistToolbar.qml
- modules/gui/qt/util/qml/KeyHelper.js â modules/gui/qt/util/keyhelper.cpp
- + modules/gui/qt/util/keyhelper.hpp
- modules/gui/qt/vlc.qrc
- modules/gui/qt/widgets/native/navigation_attached.cpp
- modules/gui/qt/widgets/qml/CheckedDelegate.qml
- modules/gui/qt/widgets/qml/ExpandGridView.qml
- modules/gui/qt/widgets/qml/KeyNavigableGridView.qml
- modules/gui/qt/widgets/qml/KeyNavigableListView.qml
- modules/gui/qt/widgets/qml/ListCoverShadow.qml
- modules/gui/qt/widgets/qml/ListItem.qml
- modules/gui/qt/widgets/qml/OverlayMenu.qml
Changes:
=====================================
modules/gui/qt/Makefile.am
=====================================
@@ -225,6 +225,7 @@ libqt_plugin_la_SOURCES = \
gui/qt/util/imageluminanceextractor.cpp gui/qt/util/imageluminanceextractor.hpp \
gui/qt/util/imagehelper.cpp gui/qt/util/imagehelper.hpp \
gui/qt/util/i18n.cpp gui/qt/util/i18n.hpp \
+ gui/qt/util/keyhelper.cpp gui/qt/util/keyhelper.hpp \
gui/qt/util/listcache.hpp \
gui/qt/util/listcacheloader.hpp \
gui/qt/util/navigation_history.cpp gui/qt/util/navigation_history.hpp \
@@ -382,6 +383,7 @@ nodist_libqt_plugin_la_SOURCES = \
gui/qt/util/covergenerator.moc.cpp \
gui/qt/util/imageluminanceextractor.moc.cpp \
gui/qt/util/i18n.moc.cpp \
+ gui/qt/util/keyhelper.moc.cpp \
gui/qt/util/listcache.moc.cpp \
gui/qt/util/navigation_history.moc.cpp \
gui/qt/util/qml_main_context.moc.cpp \
@@ -752,7 +754,6 @@ libqt_plugin_la_QML = \
gui/qt/style/VLCStyle.qml \
gui/qt/style/qmldir \
gui/qt/util/qml/Helpers.js \
- gui/qt/util/qml/KeyHelper.js \
gui/qt/util/qml/SelectableDelegateModel.qml \
gui/qt/widgets/qml/ActionButtonOverlay.qml \
gui/qt/widgets/qml/ActionButtonPrimary.qml \
=====================================
modules/gui/qt/dialogs/help/qml/About.qml
=====================================
@@ -22,7 +22,6 @@ import org.videolan.vlc 0.1
import "qrc:///style/"
import "qrc:///widgets/" as Widgets
-import "qrc:///util/KeyHelper.js" as KeyHelper
FocusScope {
id: root
=====================================
modules/gui/qt/maininterface/mainui.cpp
=====================================
@@ -32,6 +32,7 @@
#include "util/qmleventfilter.hpp"
#include "util/imageluminanceextractor.hpp"
#include "util/i18n.hpp"
+#include "util/keyhelper.hpp"
#include "util/systempalette.hpp"
#include "util/sortfilterproxymodel.hpp"
#include "util/navigation_history.hpp"
@@ -265,7 +266,7 @@ void MainUI::registerQMLTypes()
qRegisterMetaType<QList<QQmlError>>("QList<QQmlError>");
qmlRegisterUncreatableType<NavigationAttached>( "org.videolan.vlc", 0, 1, "Navigation", "Navigation is only available via attached properties");
-
+ qmlRegisterSingletonType<QmlKeyHelper>("org.videolan.vlc", 0, 1, "KeyHelper", &QmlKeyHelper::getSingletonInstance);
}
void MainUI::onQmlWarning(const QList<QQmlError>& qmlErrors)
=====================================
modules/gui/qt/maininterface/qml/BannerSources.qml
=====================================
@@ -26,7 +26,6 @@ import QtQml.Models 2.11
import "qrc:///style/"
import "qrc:///widgets/" as Widgets
import "qrc:///menus/" as Menus
-import "qrc:///util/KeyHelper.js" as KeyHelper
import "qrc:///util/Helpers.js" as Helpers
FocusScope {
=====================================
modules/gui/qt/maininterface/qml/MainDisplay.qml
=====================================
@@ -24,11 +24,11 @@ import org.videolan.vlc 0.1
import "qrc:///style/"
import "qrc:///main/" as Main
import "qrc:///widgets/" as Widgets
-import "qrc:///util/KeyHelper.js" as KeyHelper
-import "qrc:///util/Helpers.js" as Helpers
import "qrc:///playlist/" as PL
import "qrc:///player/" as Player
+import "qrc:///util/Helpers.js" as Helpers
+
FocusScope {
id: root
=====================================
modules/gui/qt/medialibrary/qml/EmptyLabel.qml
=====================================
@@ -22,7 +22,6 @@ import org.videolan.vlc 0.1
import "qrc:///style/"
import "qrc:///widgets/" as Widgets
-import "qrc:///util/KeyHelper.js" as KeyHelper
FocusScope {
id: root
=====================================
modules/gui/qt/medialibrary/qml/UrlListDisplay.qml
=====================================
@@ -25,7 +25,6 @@ import org.videolan.medialib 0.1
import "qrc:///util" as Util
import "qrc:///widgets/" as Widgets
-import "qrc:///util/KeyHelper.js" as KeyHelper
import "qrc:///style/"
=====================================
modules/gui/qt/medialibrary/qml/VideoInfoExpandPanel.qml
=====================================
@@ -26,7 +26,6 @@ import org.videolan.controls 0.1
import org.videolan.vlc 0.1
import "qrc:///widgets/" as Widgets
-import "qrc:///util/KeyHelper.js" as KeyHelper
import "qrc:///util/Helpers.js" as Helpers
import "qrc:///style/"
=====================================
modules/gui/qt/network/qml/DiscoverUrlDisplay.qml
=====================================
@@ -23,7 +23,6 @@ import org.videolan.vlc 0.1
import "qrc:///util" as Util
import "qrc:///widgets/" as Widgets
-import "qrc:///util/KeyHelper.js" as KeyHelper
import "qrc:///style/"
FocusScope {
=====================================
modules/gui/qt/player/qml/ControlButtons.qml
=====================================
@@ -25,8 +25,6 @@ import org.videolan.vlc 0.1
import "qrc:///widgets/" as Widgets
import "qrc:///style/"
-import "qrc:///util/KeyHelper.js" as KeyHelper
-import "qrc:///util/Helpers.js" as Helpers
Item{
id: controlButtons
=====================================
modules/gui/qt/player/qml/LanguageMenu.qml
=====================================
@@ -27,7 +27,6 @@ import org.videolan.vlc 0.1
import "qrc:///style/"
import "qrc:///widgets/" as Widgets
import "qrc:///util/" as Util
-import "qrc:///util/KeyHelper.js" as KeyHelper
T.Popup {
id: control
=====================================
modules/gui/qt/player/qml/MiniPlayer.qml
=====================================
@@ -6,7 +6,6 @@ import QtGraphicalEffects 1.0
import org.videolan.vlc 0.1
import "qrc:///widgets/" as Widgets
-import "qrc:///util/KeyHelper.js" as KeyHelper
import "qrc:///style/"
FocusScope {
=====================================
modules/gui/qt/player/qml/Player.qml
=====================================
@@ -25,7 +25,6 @@ import org.videolan.vlc 0.1
import "qrc:///style/"
import "qrc:///widgets/" as Widgets
-import "qrc:///util/KeyHelper.js" as KeyHelper
import "qrc:///playlist/" as PL
FocusScope {
=====================================
modules/gui/qt/player/qml/PlayerMenuItem.qml
=====================================
@@ -27,7 +27,6 @@ import org.videolan.vlc 0.1
import "qrc:///style/"
import "qrc:///widgets/" as Widgets
-import "qrc:///util/KeyHelper.js" as KeyHelper
T.MenuItem {
id: control
=====================================
modules/gui/qt/player/qml/VolumeWidget.qml
=====================================
@@ -23,7 +23,6 @@ import org.videolan.vlc 0.1
import "qrc:///widgets/" as Widgets
import "qrc:///style/"
-import "qrc:///util/KeyHelper.js" as KeyHelper
FocusScope{
id: widgetfscope
=====================================
modules/gui/qt/playlist/qml/PlaylistListView.qml
=====================================
@@ -24,7 +24,6 @@ import QtGraphicalEffects 1.0
import org.videolan.vlc 0.1
import "qrc:///widgets/" as Widgets
-import "qrc:///util/KeyHelper.js" as KeyHelper
import "qrc:///util/Helpers.js" as Helpers
import "qrc:///style/"
=====================================
modules/gui/qt/playlist/qml/PlaylistToolbar.qml
=====================================
@@ -22,7 +22,6 @@ import QtQuick.Layouts 1.3
import org.videolan.vlc 0.1
import "qrc:///widgets/" as Widgets
-import "qrc:///util/KeyHelper.js" as KeyHelper
import "qrc:///style/"
=====================================
modules/gui/qt/util/qml/KeyHelper.js â modules/gui/qt/util/keyhelper.cpp
=====================================
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (C) 2019 VLC authors and VideoLAN
+ * 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
@@ -15,56 +15,34 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
+#include "keyhelper.hpp"
-.pragma library
+#include <QQmlEngine>
-.import QtQuick 2.11 as QtQuick
+QmlKeyHelper* QmlKeyHelper::M_instance = nullptr;
-function matchLeft(event) {
- return event.key === Qt.Key_Left
- || event.matches(QtQuick.StandardKey.MoveToPreviousChar)
-}
-
-function matchRight(event) {
- return event.key === Qt.Key_Right
- || event.matches(QtQuick.StandardKey.MoveToNextChar)
-}
-
-function matchUp(event) {
- return event.key === Qt.Key_Up
- || event.matches(QtQuick.StandardKey.MoveToPreviousLine)
-}
-
-function matchDown(event) {
- return event.key === Qt.Key_Down
- || event.matches(QtQuick.StandardKey.MoveToNextLine)
-}
-
-function matchPageDown(event) {
- return event.key === Qt.Key_PageDown
- || event.matches(QtQuick.StandardKey.MoveToNextPage)
-}
+QmlKeyHelper::QmlKeyHelper(QObject* parent)
+ : QObject(parent)
+{}
-function matchPageUp(event) {
- return event.key === Qt.Key_PageUp
- || event.matches(QtQuick.StandardKey.MoveToPreviousPage)
+QObject* QmlKeyHelper::getSingletonInstance(QQmlEngine *engine, QJSEngine *)
+{
+ if (M_instance == nullptr)
+ {
+ M_instance = new QmlKeyHelper(engine);
+ }
+ return M_instance;
}
-function matchOk( event ) {
- return event.key === Qt.Key_Space
- || event.matches(QtQuick.StandardKey.InsertParagraphSeparator)
-}
-
-function matchSearch( event ) {
- return event.key === Qt.Key_Search
- || event.key === Qt.Key_Slash
- || ( (event.modifiers & Qt.ControlModifier) && event.key === Qt.Key_F )
-}
+bool QmlKeyHelper::call(bool (*fun)(const QKeyEvent *), const QObject *event)
+{
+ QKeyEvent fakeEvent(QKeyEvent::KeyPress,
+ event->property("key").toInt(),
+ static_cast<Qt::KeyboardModifiers>(event->property("modifiers").toInt()),
+ event->property("text").toString(),
+ event->property("isAutoRepeat").toBool(),
+ event->property("count").toInt()
+ );
-function matchCancel(event) {
- return event.key === Qt.Key_Backspace
- || event.key === Qt.Key_Back
- || event.key === Qt.Key_Cancel
- || event.matches(QtQuick.StandardKey.Back)
- || event.matches(QtQuick.StandardKey.Cancel)
+ return fun(&fakeEvent);
}
=====================================
modules/gui/qt/util/keyhelper.hpp
=====================================
@@ -0,0 +1,121 @@
+/*****************************************************************************
+ * 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 KEYHELPER_HPP
+#define KEYHELPER_HPP
+
+#include <QKeyEvent>
+
+class QJSEngine;
+class QQmlEngine;
+class QQuickKeyEvent;
+
+//provide basic key matching
+class KeyHelper
+{
+public:
+ static bool matchLeft(const QKeyEvent* event)
+ {
+ return event->key() == Qt::Key_Left
+ || event->matches(QKeySequence::MoveToPreviousChar);
+ }
+
+ static bool matchRight(const QKeyEvent* event)
+ {
+ return event->key() == Qt::Key_Right
+ || event->matches(QKeySequence::MoveToNextChar);
+ }
+
+ static bool matchUp(const QKeyEvent* event)
+ {
+ return event->key() == Qt::Key_Up
+ || event->matches(QKeySequence::MoveToPreviousLine);
+ }
+
+ static bool matchDown(const QKeyEvent* event)
+ {
+ return event->key() == Qt::Key_Down
+ || event->matches(QKeySequence::MoveToNextLine);
+ }
+
+
+ static bool matchPageDown(const QKeyEvent* event)
+ {
+ return event->key() == Qt::Key_PageDown
+ || event->matches(QKeySequence::MoveToNextPage);
+ }
+
+ static bool matchPageUp(const QKeyEvent* event)
+ {
+ return event->key() == Qt::Key_PageUp
+ || event->matches(QKeySequence::MoveToPreviousPage);
+ }
+
+ static bool matchOk( const QKeyEvent* event )
+ {
+ return event->key() == Qt::Key_Space
+ || event->matches(QKeySequence::InsertParagraphSeparator);
+ }
+
+ static bool matchSearch( const QKeyEvent* event )
+ {
+ return event->key() == Qt::Key_Search
+ || event->key() == Qt::Key_Slash
+ || ( (event->modifiers() & Qt::ControlModifier) && event->key() == Qt::Key_F );
+ }
+
+ static bool matchCancel(const QKeyEvent* event)
+ {
+ return event->key() == Qt::Key_Backspace
+ || event->key() == Qt::Key_Back
+ || event->key() == Qt::Key_Cancel
+ || event->matches(QKeySequence::Back)
+ || event->matches(QKeySequence::Cancel);
+ }
+
+private:
+ KeyHelper() = delete;
+};
+
+
+//expose KeyHelper to QML
+class QmlKeyHelper : public QObject
+{
+ Q_OBJECT
+public:
+ QmlKeyHelper(QObject* parent = nullptr);
+
+ Q_INVOKABLE bool matchLeft(QObject* event) { return call(&KeyHelper::matchLeft, event); }
+ Q_INVOKABLE bool matchRight(QObject* event) { return call(&KeyHelper::matchRight, event); }
+ Q_INVOKABLE bool matchUp(QObject* event) { return call(&KeyHelper::matchUp, event); }
+ Q_INVOKABLE bool matchDown(QObject* event) { return call(&KeyHelper::matchDown, event); }
+ Q_INVOKABLE bool matchPageDown(QObject* event) { return call(&KeyHelper::matchPageDown, event); }
+ Q_INVOKABLE bool matchPageUp(QObject* event) { return call(&KeyHelper::matchPageUp, event); }
+ Q_INVOKABLE bool matchOk( QObject* event ) { return call(&KeyHelper::matchOk, event); }
+ Q_INVOKABLE bool matchSearch( QObject* event ) { return call(&KeyHelper::matchSearch, event); }
+ Q_INVOKABLE bool matchCancel(QObject* event) { return call(&KeyHelper::matchCancel, event); }
+
+ static QObject* getSingletonInstance(QQmlEngine* engine, QJSEngine*);
+
+private:
+ //convert arguments and call the right function
+ bool call(bool (*fun)(const QKeyEvent*), const QObject *event);
+
+ static QmlKeyHelper* M_instance;
+};
+
+#endif // KEYHELPER_HPP
=====================================
modules/gui/qt/vlc.qrc
=====================================
@@ -25,7 +25,6 @@
<file alias="wait3.svg">pixmaps/util/wait3.svg</file>
<file alias="wait4.svg">pixmaps/util/wait4.svg</file>
<file alias="SelectableDelegateModel.qml">util/qml/SelectableDelegateModel.qml</file>
- <file alias="KeyHelper.js">util/qml/KeyHelper.js</file>
<file alias="Helpers.js">util/qml/Helpers.js</file>
</qresource>
<qresource prefix="/toolbar">
=====================================
modules/gui/qt/widgets/native/navigation_attached.cpp
=====================================
@@ -16,69 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "navigation_attached.hpp"
-
-class KeyHelper
-{
-public:
- static bool matchLeft(const QKeyEvent* event)
- {
- return event->key() == Qt::Key_Left
- || event->matches(QKeySequence::MoveToPreviousChar);
- }
-
- static bool matchRight(const QKeyEvent* event)
- {
- return event->key() == Qt::Key_Right
- || event->matches(QKeySequence::MoveToNextChar);
- }
-
- static bool matchUp(const QKeyEvent* event)
- {
- return event->key() == Qt::Key_Up
- || event->matches(QKeySequence::MoveToPreviousLine);
- }
-
- static bool matchDown(const QKeyEvent* event)
- {
- return event->key() == Qt::Key_Down
- || event->matches(QKeySequence::MoveToNextLine);
- }
-
-
- static bool matchPageDown(const QKeyEvent* event)
- {
- return event->key() == Qt::Key_PageDown
- || event->matches(QKeySequence::MoveToNextPage);
- }
-
- static bool matchPageUp(const QKeyEvent* event)
- {
- return event->key() == Qt::Key_PageUp
- || event->matches(QKeySequence::MoveToPreviousPage);
- }
-
- static bool matchOk( const QKeyEvent* event )
- {
- return event->key() == Qt::Key_Space
- || event->matches(QKeySequence::InsertParagraphSeparator);
- }
-
- static bool matchSearch( const QKeyEvent* event )
- {
- return event->key() == Qt::Key_Search
- || event->key() == Qt::Key_Slash
- || ( (event->modifiers() & Qt::ControlModifier) && event->key() == Qt::Key_F );
- }
-
- static bool matchCancel(const QKeyEvent* event)
- {
- return event->key() == Qt::Key_Backspace
- || event->key() == Qt::Key_Back
- || event->key() == Qt::Key_Cancel
- || event->matches(QKeySequence::Back)
- || event->matches(QKeySequence::Cancel);
- }
-};
+#include "util/keyhelper.hpp"
NavigationAttached::NavigationAttached(QObject *parent)
: QObject(parent)
=====================================
modules/gui/qt/widgets/qml/CheckedDelegate.qml
=====================================
@@ -19,9 +19,9 @@
import QtQuick 2.11
import QtQuick.Controls 2.4
import QtQuick.Templates 2.4 as T
+import org.videolan.vlc 0.1
import "qrc:///style/"
-import "qrc:///util/KeyHelper.js" as KeyHelper
T.ItemDelegate {
id: control
=====================================
modules/gui/qt/widgets/qml/ExpandGridView.qml
=====================================
@@ -18,7 +18,7 @@
import QtQuick 2.11
import QtQuick.Controls 2.4
import org.videolan.vlc 0.1
-import "qrc:///util/KeyHelper.js" as KeyHelper
+
import "qrc:///style/"
FocusScope {
=====================================
modules/gui/qt/widgets/qml/KeyNavigableGridView.qml
=====================================
@@ -17,7 +17,6 @@
*****************************************************************************/
import QtQuick 2.11
import QtQuick.Controls 2.4
-import "qrc:///util/KeyHelper.js" as KeyHelper
import org.videolan.vlc 0.1
=====================================
modules/gui/qt/widgets/qml/KeyNavigableListView.qml
=====================================
@@ -20,7 +20,6 @@ import QtQuick.Controls 2.4
import org.videolan.vlc 0.1
import "qrc:///style/"
-import "qrc:///util/KeyHelper.js" as KeyHelper
FocusScope {
id: listview_id
=====================================
modules/gui/qt/widgets/qml/ListCoverShadow.qml
=====================================
@@ -20,7 +20,6 @@ import QtQuick 2.11
import QtGraphicalEffects 1.0
import "qrc:///style/"
-import "qrc:///util/KeyHelper.js" as KeyHelper
CoverShadow {
id: root
=====================================
modules/gui/qt/widgets/qml/ListItem.qml
=====================================
@@ -24,7 +24,6 @@ import org.videolan.vlc 0.1
import "qrc:///style/"
import "qrc:///widgets/" as Widgets
-import "qrc:///util/KeyHelper.js" as KeyHelper
FocusScope {
id: root
=====================================
modules/gui/qt/widgets/qml/OverlayMenu.qml
=====================================
@@ -18,8 +18,8 @@
import QtQuick 2.11
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.3
+import org.videolan.vlc 0.1
-import "qrc:///util/KeyHelper.js" as KeyHelper
import "qrc:///style/"
Item {
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/736be1eb0c4f9a6debd5ca77fc36cdb04f2e967b...7f6e6a7603402fcaf29a9570bbfca58026ef2ff7
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/736be1eb0c4f9a6debd5ca77fc36cdb04f2e967b...7f6e6a7603402fcaf29a9570bbfca58026ef2ff7
You're receiving this email because of your account on code.videolan.org.
More information about the vlc-commits
mailing list