[vlc-devel] [RFC 64/82] qml: extend and customize StackView
Pierre Lamot
pierre at videolabs.io
Fri Feb 1 14:02:08 CET 2019
shorten transition and provide a method to load an setup a view
see NavigationHistory
---
modules/gui/qt/Makefile.am | 1 +
modules/gui/qt/qml/utils/StackViewExt.qml | 89 +++++++++++++++++++++++
modules/gui/qt/vlc.qrc | 1 +
3 files changed, 91 insertions(+)
create mode 100644 modules/gui/qt/qml/utils/StackViewExt.qml
diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index ab2ffcf636..af84ec6dee 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -527,6 +527,7 @@ libqt_plugin_la_RES = \
gui/qt/qml/utils/KeyNavigableListView.qml \
gui/qt/qml/utils/KeyNavigableTableView.qml \
gui/qt/qml/utils/SelectableDelegateModel.qml \
+ gui/qt/qml/utils/StackViewExt.qml \
gui/qt/qml/style/qmldir \
gui/qt/qml/style/VLCIcons.qml \
gui/qt/qml/style/VLCStyle.qml \
diff --git a/modules/gui/qt/qml/utils/StackViewExt.qml b/modules/gui/qt/qml/utils/StackViewExt.qml
new file mode 100644
index 0000000000..61fec72e87
--- /dev/null
+++ b/modules/gui/qt/qml/utils/StackViewExt.qml
@@ -0,0 +1,89 @@
+/*****************************************************************************
+ * Copyright (C) 2019 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.11
+import QtQuick.Controls 2.4
+
+/*
+ * Custom StackView with brief transitions and helper to load view from the history
+ */
+StackView {
+ id: root
+
+ replaceEnter: Transition {
+ PropertyAnimation {
+ property: "opacity"
+ from: 0
+ to:1
+ duration: 500
+ }
+ }
+
+ replaceExit: Transition {
+ PropertyAnimation {
+ property: "opacity"
+ from: 1
+ to:0
+ duration: 500
+ }
+ }
+
+ /**
+ * viewModel: model with the definition of the available view
+ * elemements should contains at least :
+ * name: name of the view
+ * url or component: the url of the Component or the component to load
+ * view: string (name of the view to load)
+ * viewProperties: map of the propertes to apply to the view
+ */
+ function loadView(viewModel, view, viewProperties)
+ {
+ var found = false
+ for (var tab = 0; tab < viewModel.length; tab++ )
+ {
+ var model = viewModel[tab]
+ if (model.name === view) {
+ //we can't use push(url, properties) as Qt interprets viewProperties
+ //as a second component to load
+ var component = undefined
+ if (model.component) {
+ component = model.component
+ } else if ( model.url ) {
+ component = Qt.createComponent(model.url)
+ } else {
+ console.warn( "you should define either component or url of the view to load" )
+ return false
+ }
+
+ if (component.status === Component.Ready ) {
+ //note doesn't work with qt 5.9, you have to do the following, and beware
+ //that page won 't be released when poped out
+ //var page = component.createObject(root, viewProperties)
+ //root.replace(page)
+ root.replace(null, component, viewProperties)
+ found = true
+ break;
+ } else {
+ console.warn("component is not ready")
+ }
+ }
+ }
+ if (!found)
+ console.warn("unable to load view " + view)
+ return found
+ }
+}
diff --git a/modules/gui/qt/vlc.qrc b/modules/gui/qt/vlc.qrc
index 9050996514..914c0d49bf 100644
--- a/modules/gui/qt/vlc.qrc
+++ b/modules/gui/qt/vlc.qrc
@@ -164,6 +164,7 @@
<file alias="KeyNavigableListView.qml">qml/utils/KeyNavigableListView.qml</file>
<file alias="KeyNavigableTableView.qml">qml/utils/KeyNavigableTableView.qml</file>
<file alias="NavigableFocusScope.qml">qml/utils/NavigableFocusScope.qml</file>
+ <file alias="StackViewExt.qml">qml/utils/StackViewExt.qml</file>
</qresource>
<qresource prefix="/style">
<file alias="qmldir">qml/style/qmldir</file>
--
2.19.1
More information about the vlc-devel
mailing list