Warning, /maui/mauikit/src/controls.5/AppViews.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * Copyright 2020 Camilo Higuita <milo.h@aol.com>
0003 *
0004 * This program is free software; you can redistribute it and/or modify
0005 * it under the terms of the GNU Library General Public License as
0006 * published by the Free Software Foundation; either version 2, or
0007 * (at your option) any later version.
0008 *
0009 * This program is distributed in the hope that it will be useful,
0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0012 * GNU General Public License for more details
0013 *
0014 * You should have received a copy of the GNU Library General Public
0015 * License along with this program; if not, write to the
0016 * Free Software Foundation, Inc.,
0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0018 */
0019
0020 import QtQuick 2.15
0021 import QtQml 2.15
0022 import QtQuick.Controls 2.15
0023 import QtQuick.Layouts 1.3
0024 import QtQuick.Templates 2.15 as T
0025
0026 import org.mauikit.controls 1.2 as Maui
0027
0028 import "private" as Private
0029
0030 /*!
0031 * \since org.mauikit.controls 1.2
0032 * \inqmlmodule org.mauikit.controls
0033 * \brief View switcher component
0034 *
0035 * Lists the different views declared into a swipe view, that does not jump around
0036 * when resizing the application window and that takes care of different gestures for switching the views.
0037 *
0038 * This component takes care of creating the app views port as buttons in the application main header
0039 * for switching the views.
0040 *
0041 * By default this component is not interactive when using touch gesture, to not steal fcous from other horizontal
0042 * flickable gestures.
0043 */
0044 Maui.Page
0045 {
0046 id: control
0047
0048 default property alias content: _swipeView.contentData
0049
0050 property alias currentIndex : _swipeView.currentIndex
0051 property alias currentItem : _swipeView.currentItem
0052 property alias count : _swipeView.count
0053 property alias interactive : _swipeView.interactive
0054
0055 focus: true
0056
0057 /*!
0058 * Maximum number of views to be shown in the app* view port in the header.
0059 * The rest of views buttons will be collapsed into a menu button.
0060 */
0061 property int maxViews : 4
0062
0063 /*!
0064 * The toolbar where the app view buttons will be* added.
0065 */
0066 headBar.forceCenterMiddleContent: !isWide
0067 headBar.middleContent: Loader
0068 {
0069 asynchronous: true
0070 Layout.alignment: Qt.AlignCenter
0071
0072 sourceComponent: Private.ActionGroup
0073 {
0074 id: _actionGroup
0075 currentIndex : _swipeView.currentIndex
0076 display: ToolButton.TextUnderIcon
0077 Binding on currentIndex
0078 {
0079 value: _swipeView.currentIndex
0080 restoreMode: Binding.RestoreValue
0081 }
0082
0083 onCurrentIndexChanged:
0084 {
0085 _swipeView.currentIndex = currentIndex
0086 // _actionGroup.currentIndex = control.currentIndex
0087 }
0088
0089 Component.onCompleted:
0090 {
0091 for(var i in _swipeView.contentChildren)
0092 {
0093 const obj = _swipeView.contentChildren[i]
0094
0095 if(obj.Maui.AppView.title || obj.Maui.AppView.iconName)
0096 {
0097 if(_actionGroup.items.length < control.maxViews)
0098 {
0099 _actionGroup.items.push(obj)
0100 }else
0101 {
0102 _actionGroup.hiddenItems.push(obj)
0103 }
0104 }
0105 }
0106 }
0107 }
0108 }
0109
0110 T.SwipeView
0111 {
0112 id:_swipeView
0113 anchors.fill: parent
0114 interactive: false
0115
0116 onCurrentItemChanged:
0117 {
0118 currentItem.forceActiveFocus()
0119 _listView.positionViewAtIndex(control.currentIndex , ListView.SnapPosition)
0120 history.push(_swipeView.currentIndex)
0121 }
0122
0123 Keys.onBackPressed:
0124 {
0125 control.goBack()
0126 }
0127
0128 Shortcut
0129 {
0130 sequence: StandardKey.Back
0131 onActivated: control.goBack()
0132 }
0133
0134 background: null
0135
0136 contentItem: ListView
0137 {
0138 id: _listView
0139 model: _swipeView.contentModel
0140 interactive: _swipeView.interactive
0141 currentIndex: _swipeView.currentIndex
0142 spacing: _swipeView.spacing
0143 orientation: _swipeView.orientation
0144 snapMode: ListView.SnapOneItem
0145 boundsBehavior: Flickable.StopAtBounds
0146 clip: _swipeView.clip
0147
0148 preferredHighlightBegin: 0
0149 preferredHighlightEnd: width
0150
0151 highlightRangeMode: ListView.StrictlyEnforceRange
0152 highlightMoveDuration: 0
0153 highlightFollowsCurrentItem: true
0154 highlightResizeDuration: 0
0155 highlightMoveVelocity: -1
0156 highlightResizeVelocity: -1
0157
0158 maximumFlickVelocity: 4 * (_swipeView.orientation === Qt.Horizontal ? width : height)
0159
0160 property int lastPos: 0
0161
0162 onCurrentIndexChanged:
0163 {
0164 _listView.lastPos = _listView.contentX
0165 }
0166
0167 }
0168
0169 Keys.enabled: true
0170 // Keys.forwardTo:_listView
0171 Keys.onPressed:
0172 {
0173 if((event.key == Qt.Key_1) && (event.modifiers & Qt.ControlModifier))
0174 {
0175 if(_swipeView.count > -1 )
0176 {
0177 _swipeView.currentIndex = 0
0178 }
0179 }
0180
0181 if((event.key == Qt.Key_2) && (event.modifiers & Qt.ControlModifier))
0182 {
0183 if(_swipeView.count > 0 )
0184 {
0185 _swipeView.currentIndex = 1
0186 }
0187 }
0188
0189 if((event.key == Qt.Key_3) && (event.modifiers & Qt.ControlModifier))
0190 {
0191 if(_swipeView.count > 1 )
0192 {
0193 _swipeView.currentIndex = 2
0194 }
0195 }
0196
0197 if((event.key == Qt.Key_4) && (event.modifiers & Qt.ControlModifier))
0198 {
0199 if(_swipeView.count > 2 )
0200 {
0201 _swipeView.currentIndex = 3
0202 }
0203 }
0204 }
0205
0206 }
0207
0208
0209 property QtObject history : QtObject
0210 {
0211 property var historyIndexes : []
0212
0213 function pop()
0214 {
0215 historyIndexes.pop()
0216 return historyIndexes.pop()
0217 }
0218
0219 function push(index)
0220 {
0221 historyIndexes.push(index)
0222 }
0223
0224 function indexes()
0225 {
0226 return historyIndexes
0227 }
0228 }
0229
0230 /**
0231 *
0232 */
0233 function goBack()
0234 {
0235 _swipeView.setCurrentIndex(history.pop())
0236 }
0237
0238 }