main.qml 12.7 KB
Newer Older
Marco Martin's avatar
Marco Martin committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
 *  Copyright 2015 Marco Martin <mart@kde.org>
 *
 *  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  2.010-1301, USA.
 */

19
import QtQuick 2.12
20
import QtQuick.Layouts 1.3
21
import QtQml.Models 2.12
Marco Martin's avatar
Marco Martin committed
22
import QtGraphicalEffects 1.12
Marco Martin's avatar
Marco Martin committed
23
24
25

import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
26
import org.kde.plasma.components 3.0 as PlasmaComponents
Marco Martin's avatar
Marco Martin committed
27
28

import org.kde.plasma.workspace.components 2.0 as PlasmaWorkspace
Marco Martin's avatar
Marco Martin committed
29
import org.kde.taskmanager 0.1 as TaskManager
Marco Martin's avatar
Marco Martin committed
30

31
import org.kde.plasma.private.nanoshell 2.0 as NanoShell
Marco Martin's avatar
Marco Martin committed
32
import org.kde.plasma.private.mobileshell 1.0 as MobileShell
33

34
import "LayoutManager.js" as LayoutManager
Marco Martin's avatar
Marco Martin committed
35

36
import "quicksettings"
37
import "indicators" as Indicators
38

Marco Martin's avatar
Marco Martin committed
39

Marco Martin's avatar
Marco Martin committed
40
Item {
Marco Martin's avatar
Marco Martin committed
41
42
    id: root
    width: 480
Marco Martin's avatar
Marco Martin committed
43
    height: 30
Marco Martin's avatar
Marco Martin committed
44

Marco Martin's avatar
Marco Martin committed
45
46
    Plasmoid.backgroundHints: showingApp ? PlasmaCore.Types.StandardBackground : PlasmaCore.Types.NoBackground

Marco Martin's avatar
Marco Martin committed
47
48
49
    property Item toolBox
    property int buttonHeight: width/4
    property bool reorderingApps: false
50
    property var layoutManager: LayoutManager
Marco Martin's avatar
Marco Martin committed
51

52
53
    readonly property color backgroundColor: NanoShell.StartupFeedback.visible ? NanoShell.StartupFeedback.backgroundColor : icons.backgroundColor
    readonly property bool showingApp: !MobileShell.HomeScreenControls.homeScreenVisible
54
55

    readonly property bool hasTasks: tasksModel.count > 0
Marco Martin's avatar
Marco Martin committed
56

Marco Martin's avatar
Marco Martin committed
57
58
59
60
61
62
    Containment.onAppletAdded: {
        addApplet(applet, x, y);
        LayoutManager.save();
    }

    function addApplet(applet, x, y) {
63
        var compactContainer = compactContainerComponent.createObject(appletIconsRow)
64
        print("Applet added: " + applet + " " + applet.title)
Marco Martin's avatar
Marco Martin committed
65

66
67
68
        applet.parent = compactContainer;
        compactContainer.applet = applet;
        applet.anchors.fill = compactContainer;
Marco Martin's avatar
Marco Martin committed
69
        applet.visible = true;
70

71
72
73
74
        //FIXME: make a way to instantiate fullRepresentationItem without the open/close dance
        applet.expanded = true
        applet.expanded = false

75
76
77
78
79
80
        var fullContainer = null;
        if (applet.pluginName == "org.kde.plasma.notifications") {
            fullContainer = fullNotificationsContainerComponent.createObject(fullRepresentationView.contentItem, {"fullRepresentationModel": fullRepresentationModel, "fullRepresentationView": fullRepresentationView});
        } else {
            fullContainer = fullContainerComponent.createObject(fullRepresentationView.contentItem, {"fullRepresentationModel": fullRepresentationModel, "fullRepresentationView": fullRepresentationView});
        }
Marco Martin's avatar
Marco Martin committed
81

82
83
        applet.fullRepresentationItem.parent = fullContainer;
        fullContainer.applet = applet;
Marco Martin's avatar
Marco Martin committed
84
85
        fullContainer.contentItem = applet.fullRepresentationItem;
        //applet.fullRepresentationItem.anchors.fill = fullContainer;
Marco Martin's avatar
Marco Martin committed
86
87
88
89
90
    }

    Component.onCompleted: {
        LayoutManager.plasmoid = plasmoid;
        LayoutManager.root = root;
91
        LayoutManager.layout = appletsLayout;
Marco Martin's avatar
Marco Martin committed
92
93
94
        LayoutManager.restore();
    }

Marco Martin's avatar
Marco Martin committed
95
96
97
98
99
100
101
    TaskManager.TasksModel {
        id: tasksModel
        sortMode: TaskManager.TasksModel.SortVirtualDesktop
        groupMode: TaskManager.TasksModel.GroupDisabled

        screenGeometry: plasmoid.screenGeometry
        filterByScreen: plasmoid.configuration.showForCurrentScreenOnly
102
103
        //FIXME: workaround
        Component.onCompleted: tasksModel.countChanged();
Marco Martin's avatar
Marco Martin committed
104
105
    }

Marco Martin's avatar
Marco Martin committed
106
107
108
109
110
111
112
113
114
115
116
117
    PlasmaCore.DataSource {
        id: statusNotifierSource
        engine: "statusnotifieritem"
        interval: 0
        onSourceAdded: {
            connectSource(source)
        }
        Component.onCompleted: {
            connectedSources = sources
        }
    }

Marco Martin's avatar
Marco Martin committed
118
119
120
121
122
    RowLayout {
        id: appletsLayout
        Layout.minimumHeight: Math.max(root.height, Math.round(Layout.preferredHeight / root.height) * root.height)
    }
 
123
    //todo: REMOVE?
Marco Martin's avatar
Marco Martin committed
124
    Component {
125
        id: compactContainerComponent
126
        Item {
Marco Martin's avatar
Marco Martin committed
127
            property Item applet
128
            visible: applet && (applet.status != PlasmaCore.Types.HiddenStatus && applet.status != PlasmaCore.Types.PassiveStatus)
129
            Layout.fillHeight: true
Marco Martin's avatar
Marco Martin committed
130
131
            Layout.minimumWidth: applet && applet.compactRepresentationItem ? Math.max(applet.compactRepresentationItem.Layout.minimumWidth, appletIconsRow.height) : appletIconsRow.height
            Layout.maximumWidth: Layout.minimumWidth
Marco Martin's avatar
Marco Martin committed
132
133
        }
    }
134

135
136
    Component {
        id: fullContainerComponent
137
138
139
140
141
142
143
        FullContainer {
        }
    }

    Component {
        id: fullNotificationsContainerComponent
        FullNotificationsContainer {
144
145
        }
    }
Marco Martin's avatar
Marco Martin committed
146
147
148
149
150
151
152
153

    PlasmaCore.DataSource {
        id: timeSource
        engine: "time"
        connectedSources: ["Local"]
        interval: 60 * 1000
    }

Marco Martin's avatar
Marco Martin committed
154
155
    DropShadow {
        anchors.fill: icons
Jonah Brüchert's avatar
Jonah Brüchert committed
156
        visible: !showingApp
Marco Martin's avatar
Marco Martin committed
157
        cached: true
Marco Martin's avatar
Marco Martin committed
158
159
160
161
162
163
164
165
166
167
        horizontalOffset: 0
        verticalOffset: 1
        radius: 4.0
        samples: 17
        color: Qt.rgba(0,0,0,0.8)
        source: icons
    }

    PlasmaCore.ColorScope {
        id: icons
Marco Martin's avatar
Marco Martin committed
168
        z: 1
Marco Martin's avatar
Marco Martin committed
169
        colorGroup: showingApp ? PlasmaCore.Theme.NormalColorGroup : PlasmaCore.Theme.ComplementaryColorGroup
Marco Martin's avatar
Marco Martin committed
170
        //parent: slidingPanel.visible && !slidingPanel.wideScreen ? panelContents : root
Marco Martin's avatar
Marco Martin committed
171
172
173
174
175
176
        anchors {
            left: parent.left
            right: parent.right
            bottom: parent.bottom
        }
        height: root.height
Marco Martin's avatar
Marco Martin committed
177
178
        Rectangle {
            anchors.fill: parent
Marco Martin's avatar
Marco Martin committed
179
180
181
            gradient: Gradient {
                GradientStop {
                    position: 1.0
182
                    color: showingApp ? root.backgroundColor : "transparent"
Marco Martin's avatar
Marco Martin committed
183
184
185
                }
                GradientStop {
                    position: 0.0
186
                    color: showingApp ? root.backgroundColor : Qt.rgba(0, 0, 0, 0.1)
Marco Martin's avatar
Marco Martin committed
187
188
                }
            }
Marco Martin's avatar
Marco Martin committed
189
        }
Marco Martin's avatar
Marco Martin committed
190

191
        Loader {
Marco Martin's avatar
Marco Martin committed
192
            id: strengthLoader
Marco Martin's avatar
Marco Martin committed
193
            height: parent.height
Marco Martin's avatar
Marco Martin committed
194
            width: item ? item.width : 0
195
            source: Qt.resolvedUrl("indicators/SignalStrength.qml")
Marco Martin's avatar
Marco Martin committed
196
        }
Marco Martin's avatar
Marco Martin committed
197
198

        Row {
Marco Martin's avatar
Marco Martin committed
199
200
            id: sniRow
            anchors.left: strengthLoader.right
Marco Martin's avatar
Marco Martin committed
201
202
203
204
205
206
207
208
            height: parent.height
            Repeater {
                id: statusNotifierRepeater
                model: PlasmaCore.SortFilterModel {
                    id: filteredStatusNotifiers
                    filterRole: "Title"
                    sourceModel: PlasmaCore.DataModel {
                        dataSource: statusNotifierSource
Marco Martin's avatar
Marco Martin committed
209
210
                    }
                }
Marco Martin's avatar
Marco Martin committed
211
212

                delegate: TaskWidget {
Marco Martin's avatar
Marco Martin committed
213
214
215
216
                }
            }
        }

Marco Martin's avatar
Marco Martin committed
217
218
219
220
221
222
223
224
225
226
227
228
        PlasmaComponents.Label {
            id: clock
            anchors.fill: parent
            text: Qt.formatTime(timeSource.data.Local.DateTime, "hh:mm")
            color: PlasmaCore.ColorScope.textColor
            horizontalAlignment: Qt.AlignHCenter
            verticalAlignment: Qt.AlignVCenter
            font.pixelSize: height / 2
        }

        RowLayout {
            id: appletIconsRow
Marco Martin's avatar
Marco Martin committed
229
            anchors {
Marco Martin's avatar
Marco Martin committed
230
                bottom: parent.bottom
231
                right: simpleIndicatorsLayout.left
Marco Martin's avatar
Marco Martin committed
232
            }
233
            height: parent.height
Marco Martin's avatar
Marco Martin committed
234
        }
235
236
237
238
239
240
241
242
243
244
245
246

        //TODO: pluggable
        RowLayout {
            id: simpleIndicatorsLayout
            anchors {
                top: parent.top
                bottom: parent.bottom
                right: parent.right
                rightMargin: units.smallSpacing
            }
            Indicators.Bluetooth {}
            Indicators.Wifi {}
Marco Martin's avatar
Marco Martin committed
247
            Indicators.Volume {}
248
249
            Indicators.Battery {}
        }
Marco Martin's avatar
Marco Martin committed
250
251
    }
    MouseArea {
Marco Martin's avatar
Marco Martin committed
252
        z: 99
Marco Martin's avatar
Marco Martin committed
253
        property int oldMouseY: 0
Marco Martin's avatar
Marco Martin committed
254

Marco Martin's avatar
Marco Martin committed
255
256
        anchors.fill: parent
        onPressed: {
257
            slidingPanel.drawerX = Math.min(Math.max(0, mouse.x - slidingPanel.drawerWidth/2), slidingPanel.width - slidingPanel.drawerWidth)
258
            slidingPanel.userInteracting = true;
Marco Martin's avatar
Marco Martin committed
259
            oldMouseY = mouse.y;
Marco Martin's avatar
Marco Martin committed
260
            slidingPanel.offset = 0//units.gridUnit * 2;
261
            slidingPanel.showFullScreen();
Marco Martin's avatar
Marco Martin committed
262
263
        }
        onPositionChanged: {
264
            slidingPanel.offset = Math.min(slidingPanel.contentItem.height, slidingPanel.offset + (mouse.y - oldMouseY));
Marco Martin's avatar
Marco Martin committed
265
266
            oldMouseY = mouse.y;
        }
267
268
269
270
        onReleased: {
            slidingPanel.userInteracting = false;
            slidingPanel.updateState();
        }
Marco Martin's avatar
Marco Martin committed
271
    }
Marco Martin's avatar
Marco Martin committed
272

Marco Martin's avatar
Marco Martin committed
273
274
275
276
    SlidingPanel {
        id: slidingPanel
        width: plasmoid.availableScreenRect.width
        height: plasmoid.availableScreenRect.height
Marco Martin's avatar
Marco Martin committed
277
        openThreshold: units.gridUnit * 10
Marco Martin's avatar
Marco Martin committed
278
        headerHeight: root.height
Marco Martin's avatar
Marco Martin committed
279

Marco Martin's avatar
Marco Martin committed
280
281
        onClosed: quickSettings.closed()

Marco Martin's avatar
Marco Martin committed
282
        contentItem: Item {
Marco Martin's avatar
Marco Martin committed
283
284
            id: panelContents
            anchors.fill: parent
Marco Martin's avatar
Marco Martin committed
285
286
            implicitWidth: quickSettingsParent.implicitWidth
            implicitHeight: quickSettingsParent.implicitHeight
Marco Martin's avatar
Marco Martin committed
287
288

            DrawerBackground {
Marco Martin's avatar
Marco Martin committed
289
290
                id: quickSettingsParent
                anchors.fill: parent
291
                z: 4
Marco Martin's avatar
Marco Martin committed
292
                contentItem: QuickSettings {
293
                    id: quickSettings
Marco Martin's avatar
Marco Martin committed
294
295
296
                    onCloseRequested: {
                        slidingPanel.hide()
                    }
297
                }
Marco Martin's avatar
Marco Martin committed
298
            }
Marco Martin's avatar
Marco Martin committed
299

Marco Martin's avatar
Marco Martin committed
300
301
302

            ListView {
                id: fullRepresentationView
303
                z: 1
Marco Martin's avatar
Marco Martin committed
304
                parent: slidingPanel.wideScreen ? slidingPanel.flickable.contentItem : panelContents
Marco Martin's avatar
Marco Martin committed
305
306
307
308
309
                anchors {
                    left: parent.left
                    right: parent.right
                }
                y: quickSettingsParent.height - height * (1-opacity)
Marco Martin's avatar
Marco Martin committed
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
                opacity: fullRepresentationModel.count > 0 && slidingPanel.offset/panelContents.height
                height: Math.min(plasmoid.screenGeometry.height - slidingPanel.headerHeight - quickSettingsParent.height - bottomBar.height, implicitHeight)
                leftMargin: slidingPanel.drawerX
                preferredHighlightBegin: slidingPanel.drawerX
                
                implicitHeight: units.gridUnit * 20
                cacheBuffer: width * 100
                highlightFollowsCurrentItem: true
                highlightRangeMode: ListView.StrictlyEnforceRange
                highlightMoveDuration: units.longDuration
                snapMode: slidingPanel.wideScreen ? ListView.NoSnap : ListView.SnapOneItem
                model: ObjectModel {
                    id: fullRepresentationModel
                }
                orientation: ListView.Horizontal
325

Marco Martin's avatar
Marco Martin committed
326
327
328
329
330
331
332
                MouseArea {
                    //parent: fullRepresentationView.contentItem
                    anchors.fill: parent
                    z: -1
                    
                    onClicked: slidingPanel.close()
                }
333

Marco Martin's avatar
Marco Martin committed
334
335
                //implicitHeight: fullRepresentationLayout.implicitHeight
                //clip: true
336

337
338
339
            }
            
        }
Marco Martin's avatar
Marco Martin committed
340
        DrawerBackground {
341
342
343
344
345
346
            id: bottomBar
            anchors {
                left: parent.left
                right: parent.right
                bottom: parent.bottom
            }
Marco Martin's avatar
Marco Martin committed
347
348
349
350

            parent: slidingPanel.fixedArea
            opacity: fullRepresentationView.opacity
            visible: !slidingPanel.wideScreen && fullRepresentationModel.count > 1
351
352
353
354
355
356
357
            //height: 40
            z: 100
            contentItem: RowLayout {
                PlasmaComponents.TabBar {
                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    position: PlasmaComponents.TabBar.Footer
Marco Martin's avatar
Marco Martin committed
358
359
360
                    Text {
                        text:fullRepresentationModel.count
                    }
361
362
363
364
365
366
367
368
369
                    Repeater {
                        model: fullRepresentationView.count
                        delegate: PlasmaComponents.TabButton {
                            implicitHeight: parent.height
                            text: fullRepresentationModel.get(index).applet.title
                            checked: fullRepresentationView.currentIndex === index
                        
                            onClicked: fullRepresentationView.currentIndex = index
                        }
370
                    }
371
                }
372
373
374
375
376
377
                PlasmaComponents.ToolButton {
                    Layout.fillHeight: true
                    Layout.preferredWidth: height
                    icon.name: "paint-none"
                    onClicked: slidingPanel.close();
                }
378
379
            }
        }
Marco Martin's avatar
Marco Martin committed
380
    }
Marco Martin's avatar
Marco Martin committed
381
}