diff --git a/src/controls/labs/AltBrowser.qml b/src/controls/labs/AltBrowser.qml index ff1743c..cff2283 100644 --- a/src/controls/labs/AltBrowser.qml +++ b/src/controls/labs/AltBrowser.qml @@ -1,146 +1,151 @@ import QtQuick 2.13 import QtQuick.Controls 2.13 import QtQuick.Layouts 1.3 import org.kde.kirigami 2.7 as Kirigami import org.kde.mauikit 1.0 as Maui Maui.Page { id: control readonly property alias currentView : viewLoader.item enum ViewType { Grid, List } property int viewType: AltBrowser.ViewType.List property int currentIndex : -1 + Binding on currentIndex + { + when: control.currentView + value: control.currentView.currentIndex + } property Component listDelegate : null property Component gridDelegate : null property var model : null property bool enableLassoSelection: false property alias holder : _holder readonly property alias gridView : private_.gridView readonly property alias listView : private_.listView // readonly property var section : listView.section flickable: viewLoader.item ? viewLoader.item.flickable : null QtObject { //before loading the view we use a dummy representation of the possible views, in order to store the properties data. Once the actual view has been loaded then the exposed properties are changed from the dummy representation to the actual view loaded, this allows to preserve and use the bindings for the actual view. The dummy representations are within a private object and exposed as readonly properties to avoid those being changed externally id: private_ property Maui.GridView gridView : Maui.GridView { id: _dummyGridView } Binding on gridView { delayed: true value: control.viewType === AltBrowser.ViewType.Grid ? control.currentView : _dummyGridView } property Maui.ListBrowser listView : Maui.ListBrowser { id: _dummyListBrowser } Binding on listView { delayed: true value: control.viewType === AltBrowser.ViewType.List ? control.currentView : _dummyListBrowser } } Loader { id: viewLoader anchors.fill: parent focus: true sourceComponent: switch(control.viewType) { case AltBrowser.ViewType.Grid: return gridViewComponent case AltBrowser.ViewType.List: return listViewComponent } // onLoaded: // { // if(control.currentView) // { // switch(control.viewType) // { // case AltBrowser.ViewType.Grid: // { // private_.gridView = control.currentView // private_.listView = _dummyListBrowser // // break // } // case AltBrowser.ViewType.List: // { // private_.listView = control.currentView // private_.gridView = _dummyGridView // break // } // } // } // } } Maui.Holder { id: _holder anchors.fill: parent } Component { id: gridViewComponent Maui.GridView { currentIndex: control.currentIndex model: control.model delegate: control.gridDelegate enableLassoSelection: control.enableLassoSelection cellHeight: _dummyGridView.cellHeight cellWidth: _dummyGridView.cellWidth itemSize: _dummyGridView.itemSize margins: _dummyGridView.margins topMargin: _dummyGridView.topMargin adaptContent: true } } Component { id: listViewComponent Maui.ListBrowser { currentIndex: control.currentIndex model: control.model delegate: control.listDelegate enableLassoSelection: control.enableLassoSelection itemSize: _dummyListBrowser.itemSize section.delegate: _dummyListBrowser.section.delegate section.property: _dummyListBrowser.section.property section.criteria: _dummyListBrowser.section.criteria section.labelPositioning: _dummyListBrowser.section.labelPositioning margins: _dummyListBrowser.margins spacing: _dummyListBrowser.spacing topMargin: _dummyListBrowser.topMargin } } } diff --git a/src/controls/labs/AppViews.qml b/src/controls/labs/AppViews.qml index 700be25..58d6247 100644 --- a/src/controls/labs/AppViews.qml +++ b/src/controls/labs/AppViews.qml @@ -1,152 +1,186 @@ /* * Copyright 2020 Camilo Higuita * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, 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 Library 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.10 import QtQuick.Controls 2.10 import org.kde.mauikit 1.0 as Maui import org.kde.mauikit 1.1 as MauiLab import "../private" as Private SwipeView { - id: control - interactive: Maui.Handy.isTouch + id: control + interactive: Maui.Handy.isTouch clip: true focus: true - property int maxViews : 4 - property Maui.ToolBar toolbar : window().headBar - - readonly property int index : -1 - - readonly property QtObject actionGroup : Private.ActionGroup - { - id: _actionGroup - currentIndex : control.currentIndex - onCurrentIndexChanged: - { - control.currentIndex = currentIndex - _actionGroup.currentIndex = control.currentIndex - } - -// onPressAndHold: control.pressAndHold(index) -// onDoubleClicked: control.doubleClicked(index) - - Component.onCompleted: - { + property int maxViews : 4 + property Maui.ToolBar toolbar : window().headBar + + readonly property int index : -1 + + readonly property QtObject actionGroup : Private.ActionGroup + { + id: _actionGroup + currentIndex : control.currentIndex + onCurrentIndexChanged: + { + control.currentIndex = currentIndex + _actionGroup.currentIndex = control.currentIndex + } + + Component.onCompleted: + { control.toolbar.middleContent.push(_actionGroup) - } - } - - currentIndex: _actionGroup.currentIndex - onCurrentIndexChanged: + } + } + + currentIndex: _actionGroup.currentIndex + onCurrentIndexChanged: { _actionGroup.currentIndex = currentIndex control.currentIndex = _actionGroup.currentIndex - } - - onCurrentItemChanged: - { - currentItem.forceActiveFocus() - _listView.positionViewAtIndex(control.currentIndex , ListView.SnapPosition) + } + + onCurrentItemChanged: + { + currentItem.forceActiveFocus() + _listView.positionViewAtIndex(control.currentIndex , ListView.SnapPosition) history.push(control.currentIndex) } - + Keys.onBackPressed: { control.goBack() } - + Shortcut { sequence: StandardKey.Back onActivated: control.goBack() } - - contentItem: ListView - { - id: _listView - model: control.contentModel - interactive: control.interactive - currentIndex: control.currentIndex - spacing: control.spacing - orientation: control.orientation - snapMode: ListView.SnapOneItem - boundsBehavior: Flickable.StopAtBounds - - highlightRangeMode: ListView.StrictlyEnforceRange - preferredHighlightBegin: 0 - highlightMoveDuration: 0 - highlightFollowsCurrentItem: true - highlightResizeDuration: 0 - - preferredHighlightEnd: width -// highlight: Item {} - highlightMoveVelocity: -1 - highlightResizeVelocity: -1 - - maximumFlickVelocity: 4 * (control.orientation === Qt.Horizontal ? width : height) - } - - Component.onCompleted: - { - for(var i in control.contentChildren) - { - const obj = control.contentChildren[i] - - if(obj.MauiLab.AppView.title || obj.MauiLab.AppView.iconName) - { - if(control.actionGroup.items.length < control.maxViews) - { - control.actionGroup.items.push(obj) - }else - { - control.actionGroup.hiddenItems.push(obj) - } - } - } - } - + + contentItem: ListView + { + id: _listView + model: control.contentModel + interactive: control.interactive + currentIndex: control.currentIndex + spacing: control.spacing + orientation: control.orientation + snapMode: ListView.SnapOneItem + boundsBehavior: Flickable.StopAtBounds + + highlightRangeMode: ListView.StrictlyEnforceRange + preferredHighlightBegin: 0 + highlightMoveDuration: 0 + highlightFollowsCurrentItem: true + highlightResizeDuration: 0 + + preferredHighlightEnd: width + // highlight: Item {} + highlightMoveVelocity: -1 + highlightResizeVelocity: -1 + + maximumFlickVelocity: 4 * (control.orientation === Qt.Horizontal ? width : height) + } + + Keys.enabled: true + Keys.onPressed: + { + if((event.key == Qt.Key_1) && (event.modifiers & Qt.ControlModifier)) + { + if(control.count > -1 ) + { + control.currentIndex = 0 + } + } + + if((event.key == Qt.Key_2) && (event.modifiers & Qt.ControlModifier)) + { + if(control.count > 0 ) + { + control.currentIndex = 1 + } + } + + if((event.key == Qt.Key_3) && (event.modifiers & Qt.ControlModifier)) + { + if(control.count > 1 ) + { + control.currentIndex = 2 + } + } + + if((event.key == Qt.Key_4) && (event.modifiers & Qt.ControlModifier)) + { + if(control.count > 2 ) + { + control.currentIndex = 3 + } + } + + } + + Component.onCompleted: + { + for(var i in control.contentChildren) + { + const obj = control.contentChildren[i] + + if(obj.MauiLab.AppView.title || obj.MauiLab.AppView.iconName) + { + if(control.actionGroup.items.length < control.maxViews) + { + control.actionGroup.items.push(obj) + }else + { + control.actionGroup.hiddenItems.push(obj) + } + } + } + } + readonly property QtObject history : QtObject { property var historyIndexes : [] - + function pop() { historyIndexes.pop() - return historyIndexes.pop() + return historyIndexes.pop() } - + function push(index) { historyIndexes.push(index) } - + function indexes() { return historyIndexes } } - + function goBack() { console.log("TRYING TO GO BACK", history.indexes()) control.setCurrentIndex(history.pop()) } }