Warning, /system/mycroft-gui/import/qml/SkillView.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * Copyright 2018 by Marco Martin <mart@kde.org>
0003 * Copyright 2018 David Edmundson <davidedmundson@kde.org>
0004 *
0005 * Licensed under the Apache License, Version 2.0 (the "License");
0006 * you may not use this file except in compliance with the License.
0007 * You may obtain a copy of the License at
0008 *
0009 * http://www.apache.org/licenses/LICENSE-2.0
0010 *
0011 * Unless required by applicable law or agreed to in writing, software
0012 * distributed under the License is distributed on an "AS IS" BASIS,
0013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014 * See the License for the specific language governing permissions and
0015 * limitations under the License.
0016 *
0017 */
0018
0019 import QtQuick 2.15
0020 import QtQuick.Layouts 1.15
0021 import QtQuick.Controls 2.15 as Controls
0022 import org.kde.kirigami 2.19 as Kirigami
0023 import Mycroft 1.0 as Mycroft
0024 import Qt5Compat.GraphicalEffects
0025
0026 import "private" as Private
0027
0028 Mycroft.AbstractSkillView {
0029 id: root
0030
0031 Kirigami.Theme.colorSet: Kirigami.Theme.Complementary
0032
0033 readonly property Item currentItem: activeSkillsRepeater.currentDelegate ? activeSkillsRepeater.currentDelegate.view.currentItem : null
0034
0035 property int switchWidth: Kirigami.Units.gridUnit * 45
0036 property alias backgroundVisible: background.visible
0037
0038 property int leftPadding: 0
0039 property int topPadding: 0
0040 property int rightPadding: 0
0041 property int bottomPadding: 0
0042
0043 property bool open: true
0044
0045 onOpenChanged: {
0046 if (open) {
0047 if(Mycroft.GlobalSettings.useExitNameSpaceAnimation) {
0048 closeAnimation.running = false;
0049 }
0050 if(Mycroft.GlobalSettings.useEntryNameSpaceAnimation) {
0051 openAnimation.restart();
0052 }
0053 } else {
0054 if(Mycroft.GlobalSettings.useEntryNameSpaceAnimation) {
0055 openAnimation.running = false;
0056 }
0057 if(Mycroft.GlobalSettings.useExitNameSpaceAnimation) {
0058 closeAnimation.restart();
0059 }
0060 }
0061 }
0062
0063 Connections {
0064 target: root.activeSkills
0065 function onSkillActivated() {
0066 root.open = true;
0067 }
0068 }
0069
0070 SequentialAnimation {
0071 id: openAnimation
0072 ScriptAction {
0073 script: {
0074 root.visible = true
0075 }
0076 }
0077 ParallelAnimation {
0078 NumberAnimation {
0079 target: root
0080 property: "opacity"
0081 from: 0
0082 to: 1
0083 duration: Kirigami.Units.longDuration
0084 easing.type: Easing.InOutQuad
0085 }
0086 YAnimator {
0087 target: delegatesContainer
0088 from: root.height / 4
0089 to: root.topPadding
0090 duration: Kirigami.Units.longDuration
0091 easing.type: Easing.InOutQuad
0092 }
0093 }
0094 }
0095
0096 SequentialAnimation {
0097 id: closeAnimation
0098 ParallelAnimation {
0099 OpacityAnimator {
0100 target: root
0101 from: 1
0102 to: 0
0103 duration: Kirigami.Units.longDuration
0104 easing.type: Easing.InOutQuad
0105 }
0106 YAnimator {
0107 target: delegatesContainer
0108 from: root.topPadding
0109 to: root.height / 4
0110 duration: Kirigami.Units.longDuration
0111 easing.type: Easing.InOutQuad
0112 }
0113 }
0114 ScriptAction {
0115 script: {
0116 root.visible = false;
0117 }
0118 }
0119 }
0120
0121 Private.ImageBackground {
0122 id: background
0123 delegatesView: activeSkillsRepeater.currentDelegate ? activeSkillsRepeater.currentDelegate.view : null
0124 Behavior on opacity {
0125 OpacityAnimator {
0126 duration: Kirigami.Units.longDuration
0127 easing.type: Easing.InOutQuad
0128 }
0129 }
0130 }
0131
0132 Item {
0133 id: delegatesContainer
0134 width: root.width - root.leftPadding - root.rightPadding
0135 height: root.height - root.topPadding - root.bottomPadding
0136 x: root.leftPadding
0137 y: root.topPadding
0138
0139 Repeater {
0140 id: activeSkillsRepeater
0141 property Item currentDelegate
0142 property Item oldDelegate
0143 model: activeSkills
0144
0145 delegate: Item {
0146 id: delegate
0147 readonly property bool current: index == activeSkills.activeIndex
0148 property alias view: delegatesView
0149
0150 width: parent.width
0151 height: parent.height
0152
0153 visible: current || opacityAnim.running
0154 enabled: current && visible
0155 opacity: current
0156 z: current ? 1 : 0
0157
0158 onCurrentChanged: {
0159 activeSkillsRepeater.currentDelegate = delegate;
0160
0161 if (current && delegatesView.count === 0) {
0162 root.open = false;
0163 }
0164 }
0165 Behavior on opacity {
0166 OpacityAnimator {
0167 id: opacityAnim
0168 duration: Kirigami.Units.longDuration
0169 easing.type: Easing.InOutQuad
0170 }
0171 }
0172 YAnimator {
0173 id: enterAnim
0174 target: delegate
0175 from: root.height / 4
0176 to: root.topPadding
0177 duration: Kirigami.Units.longDuration
0178 easing.type: Easing.InOutQuad
0179 }
0180
0181 Kirigami.ColumnView {
0182 id: delegatesView
0183 interactive: true
0184 clip: true
0185
0186 columnWidth: Math.max(Math.floor(width / Math.floor(width/(switchWidth / 2))), Math.floor(width / count))
0187 columnResizeMode: width < root.switchWidth ? Kirigami.ColumnView.SingleColumn : Kirigami.ColumnView.FixedColumns
0188 separatorVisible: false
0189 anchors.fill: parent
0190
0191 onCountChanged: {
0192 if (delegate.current && delegatesView.count > 0) {
0193 activeSkillsRepeater.currentDelegate = delegate;
0194 if (root.open === false) {
0195 root.open = true;
0196 if(Mycroft.GlobalSettings.useDelegateAnimation) {
0197 enterAnim.restart();
0198 }
0199 }
0200 }
0201
0202 if (count > 0 && currentIndex < 0) {
0203 currentIndex = 0;
0204 }
0205 }
0206 onCurrentIndexChanged: {
0207 delegates.currentIndex = currentIndex
0208 }
0209
0210 Keys.onLeftPressed: {
0211 delegatesView.currentIndex--
0212 delegatesView.currentItem.contentItem.forceActiveFocus()
0213 }
0214 Keys.onRightPressed: {
0215 delegatesView.currentIndex++
0216 delegatesView.currentItem.contentItem.forceActiveFocus()
0217 }
0218
0219 function globalBackRequest(){
0220 if(delegatesView.currentIndex !== 0){
0221 delegatesView.currentIndex--
0222 delegatesView.currentItem.contentItem.forceActiveFocus()
0223 } else {
0224 Mycroft.MycroftController.sendRequest("mycroft.gui.screen.close", {})
0225 }
0226 }
0227
0228 Connections {
0229 target: delegates
0230 function onCurrentIndexChanged() {
0231 delegatesView.currentIndex = delegates.currentIndex
0232 }
0233 }
0234
0235 Repeater {
0236 model: delegates
0237
0238 delegate: Controls.Control {
0239 id: delegate
0240
0241 Kirigami.ColumnView.reservedSpace: 0
0242 Kirigami.ColumnView.fillWidth: model.delegateUi ? model.delegateUi.fillWidth : false
0243
0244 leftPadding: 0
0245 rightPadding: 0
0246 topPadding: 0
0247 bottomPadding: 0
0248 width: Math.max(0, delegatesView.width / Math.min(delegatesView.count, Math.ceil(delegatesView.width / root.switchWidth)))
0249 height: parent.height
0250 z: delegatesView.currentIndex == index ? 1 : 0
0251 contentItem: model.delegateUi
0252 padding: 0
0253 visible: x + width >= delegatesView.contentX || x >= delegatesView.contentX + delegatesView.width
0254 property int extraBottomPadding: pageIndicator.visible ? Kirigami.Units.largeSpacing * 2 + pageIndicator.height : 0
0255 signal backRequested
0256
0257 Component.onCompleted: {
0258 backRequested.connect(delegatesView.globalBackRequest)
0259 }
0260
0261 Connections {
0262 target: model.delegateUi
0263 function onFocusChanged() {
0264 if (model.delegateUi.focus) {
0265 delegatesView.currentIndex = index;
0266 if (root.width >= root.switchWidth) {
0267 if(Mycroft.GlobalSettings.useFocusAnimation) {
0268 focusAnim.restart();
0269 }
0270 }
0271 }
0272 }
0273 }
0274
0275 SequentialAnimation {
0276 id: focusAnim
0277 NumberAnimation {
0278 target: model.delegateUi
0279 property: "scale"
0280 from: 1
0281 to: 1.1
0282 duration: Kirigami.Units.longDuration
0283 easing.type: Easing.InOutQuad
0284 }
0285 NumberAnimation {
0286 target: model.delegateUi
0287 property: "scale"
0288 from: 1.1
0289 to: 1
0290 duration: Kirigami.Units.longDuration
0291 easing.type: Easing.InOutQuad
0292 }
0293 }
0294 }
0295 }
0296 }
0297 Controls.PageIndicator {
0298 id: pageIndicator
0299 visible: delegatesView.count > 1
0300 z: 999
0301 anchors {
0302 horizontalCenter: parent.horizontalCenter
0303 bottom: parent.bottom
0304 margins: Kirigami.Units.largeSpacing
0305 }
0306 count: delegatesView.count
0307 currentIndex: delegatesView.currentIndex
0308 }
0309 }
0310 }
0311 }
0312 }