Debian Codegraph @

src/context/context_qml_package/contents/ui/Main.qml

raw
1 /****************************************************************************************
2 * Copyright (c) 2017 Malte Veerman <[email protected]> *
3 * *
4 * This program is free software; you can redistribute it and/or modify it under *
5 * the terms of the GNU General Public License as published by the Free Software *
6 * Foundation; either version 2 of the License, or (at your option) any later *
7 * version. *
8 * *
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY *
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
11 * PARTICULAR PURPOSE. See the GNU General Public License for more details. *
12 * *
13 * You should have received a copy of the GNU General Public License along with *
14 * this program. If not, see <http://www.gnu.org/licenses/>. *
15 ****************************************************************************************/
16
17 import QtQuick 2.15
18 import QtQuick.Controls 2.15
19 import QtQuick.Layouts 1.15
20 import QtQml.Models 2.15
21 import org.kde.kirigami 2.14 as Kirigami
22 import "toolbar"
23
24 Item {
25 id: root
26
27 Component.onCompleted: Context.debug("Context created")
28
29 ColumnLayout {
30 anchors.fill: parent
31
32 Flickable {
33 id: appletFlickable
34
35 signal scrollToApplet(string id)
36
37 Layout.alignment: Qt.AlignTop
38 Layout.fillHeight: true
39 Layout.fillWidth: true
40 contentWidth: scrollBar.visible ? width - scrollBar.width : width
41 contentHeight: appletColumn.height
42 flickableDirection: Flickable.VerticalFlick
43 focus: true
44
45 Keys.onUpPressed: scrollBar.decrease()
46 Keys.onDownPressed: scrollBar.increase()
47
48 ScrollBar.vertical: ScrollBar { id: scrollBar }
49
50 Column {
51 id: appletColumn
52
53 width: parent.width
54 spacing: Kirigami.Units.smallSpacing
55
56 Repeater {
57 model: AppletProxyModel
58
59 delegate: Loader {
60 width: appletColumn.width
61 active: true
62 asynchronous: false
63
64 function initialize() {
65 setSource(mainscript, {
66 "name": name,
67 "appletId": appletId,
68 "iconSource": icon,
69 "collapsed": collapsed,
70 "contentHeight": contentHeight,
71 "configEnabled": Qt.binding(function() { return appletToolbar.configEnabled; } )
72 });
73 }
74
75 Component.onCompleted: initialize()
76
77 onStatusChanged: {
78 if (status == Loader.Error) {
79 Context.error("Error loading applet: " + appletId);
80 Context.error(sourceComponent.errorString());
81 }
82 if (status == Loader.Ready) {
83 Context.debug("Applet loaded: " + appletId);
84 }
85 }
86
87 Connections {
88 target: AppletProxyModel
89
90 function onDataChanged() {
91 if (!!mainscript && mainscript != source) {
92 Context.debug("Data changed for applet " + appletId);
93 initialize();
94 }
95 }
96 }
97 Connections {
98 target: appletFlickable
99
100 function onScrollToApplet(id) {
101 if (id == appletId) {
102 appletFlickable.contentY = y;
103 Context.debug("Scroll to applet: " + appletId);
104 }
105 }
106 }
107 }
108 }
109 }
110 }
111 AppletToolbarAddItem {
112 id: appletToolbarAddItem
113
114 Layout.fillWidth: true
115 height: Kirigami.Units.iconSizes.enormous
116 visible: appletToolbar.configEnabled
117 }
118 AppletToolbar {
119 id: appletToolbar
120
121 contextRoot: root
122 addItem: appletToolbarAddItem
123 flickable: appletFlickable
124 Layout.alignment: Qt.AlignBottom
125 Layout.fillWidth: true
126 }
127 }
128 }