WidgetExplorer.qml 6.79 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
19
20
/*
 *   Copyright 2011 Marco Martin <mart@kde.org>
 *
 *   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.2
21
import QtQuick.Layouts 1.4
Marco Martin's avatar
Marco Martin committed
22
23

import org.kde.plasma.core 2.0 as PlasmaCore
24
import org.kde.plasma.components 3.0 as PC3
25
import org.kde.plasma.extras 2.0 as PlasmaExtras
Marco Martin's avatar
Marco Martin committed
26
import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddons
27
import org.kde.kirigami 2.6 as Kirigami
Marco Martin's avatar
Marco Martin committed
28
29

import QtQuick.Window 2.1
30

Marco Martin's avatar
Marco Martin committed
31
32
33

import org.kde.plasma.private.shell 2.0

34
PC3.Drawer {
Marco Martin's avatar
Marco Martin committed
35
36
    id: root

37
38
39
    property QtObject containment
    property Item containmentInterface
    readonly property bool horizontal: containmentInterface.width <= containmentInterface.height
40
    readonly property int delegateSize: units.gridUnit * 8
Marco Martin's avatar
Marco Martin committed
41

42
43
44
45
    property int topPanelHeight
    property int bottomPanelHeight
    property int leftPanelWidth
    property int rightPanelWidth
46

47
    visible: true
Marco Martin's avatar
Marco Martin committed
48

49
50
    width: horizontal ? containmentInterface.screenGeometry.width : implicitWidth + leftPadding
    height: horizontal ? implicitHeight + bottomPadding : containmentInterface.screenGeometry.height
51
52
    edge: horizontal ? Qt.BottomEdge : Qt.LeftEdge

53
54
55
56
    leftPadding: containmentInterface.availableScreenRect.x
    topPadding: horizontal ? units.smallSpacing : containmentInterface.availableScreenRect.y
    rightPadding: horizontal ? containmentInterface.screenGeometry.width - containmentInterface.availableScreenRect.width - containmentInterface.availableScreenRect.x : 0
    bottomPadding: containmentInterface.screenGeometry.height - containmentInterface.availableScreenRect.height - containmentInterface.availableScreenRect.y
57

58
59
    implicitWidth: categoriesView.shouldBeVisible ? layout.implicitWidth : view.implicitWidth + units.smallSpacing
    implicitHeight: categoriesView.shouldBeVisible ? layout.implicitHeight : view.implicitHeight + units.smallSpacing
60

61
62
63
64
65
66
67
68
69
70
71
72
    Behavior on implicitWidth {
        NumberAnimation {
            duration: units.longDuration
            easing.type: Easing.InOutQuad
        }
    }
    Behavior on implicitHeight {
        NumberAnimation {
            duration: units.longDuration
            easing.type: Easing.InOutQuad
        }
    }
73
74
75
76
77
    contentItem: Item {
        implicitWidth: layout.implicitWidth
        implicitHeight: layout.implicitHeight
        clip: false

78
        PC3.RoundButton {
79
80
81
            z: 1
            anchors.bottom: parent.bottom
            x: root.horizontal ? parent.width - width : 0
Marco Martin's avatar
Marco Martin committed
82
            width: units.iconSizes.large
83
            height: width
84
85

            icon.name: "view-filter"
86
87
            checked: categoriesView.shouldBeVisible
            onClicked: categoriesView.shouldBeVisible = !categoriesView.shouldBeVisible
88
        }
Marco Martin's avatar
Marco Martin committed
89

90
91
        GridLayout {
            id: layout
92
93
94
95
96
97
98
            anchors {
                top: parent.top
                right: parent.right

                bottom: root.horizontal ? undefined : parent.bottom
                left: root.horizontal ? parent.left : undefined
            }
99
100
            rows: root.horizontal ? 2 : 1
            columns: root.horizontal ? 1 : 2
Marco Martin's avatar
Marco Martin committed
101
            
102
            PlasmaExtras.ScrollArea {
103
                id: categoriesView
104
                property bool shouldBeVisible: false
105
106
107
                clip: false
                Layout.fillWidth: root.horizontal
                Layout.fillHeight: !root.horizontal
Marco Martin's avatar
Marco Martin committed
108
109
                Layout.column: 0
                Layout.row: root.horizontal ? 1 : 0
110
                implicitHeight: units.gridUnit * 2
Marco Martin's avatar
Marco Martin committed
111
                implicitWidth: units.gridUnit * 8
Marco Martin's avatar
Marco Martin committed
112
113
114
115
116
117
118
119
                opacity: categoriesView.shouldBeVisible

                Behavior on opacity {
                    NumberAnimation {
                        duration: units.longDuration
                        easing.type: Easing.InOutQuad
                    }
                }
120

121
122
123
124
                ListView {
                    clip: false
                    model: widgetExplorer.filterModel
                    orientation: root.horizontal ? ListView.Horizontal : ListView.Vertical
125
                    topMargin: root.horizontal ? 0 : root.topPanelHeight
126
127
128
129
130
131
132
133
134
135
136
                    delegate: Kirigami.BasicListItem {
                        height: model.separator ? 1 : implicitHeight
                        width: root.horizontal ? implicitWidth : parent.width
                        text: model.separator ? "" : model.display
                        separatorVisible: false
                        reserveSpaceForIcon: false
                        checked: widgetExplorer.widgetsModel.filterType == model.filterType && widgetExplorer.widgetsModel.filterQuery == model.filterData

                        onClicked: {
                            widgetExplorer.widgetsModel.filterQuery = model.filterData
                            widgetExplorer.widgetsModel.filterType = model.filterType
Marco Martin's avatar
Marco Martin committed
137
138
                        }
                    }
139
140
                }
            }
Marco Martin's avatar
Marco Martin committed
141

142
            PlasmaExtras.ScrollArea {
143
144
                id: view
                clip: false
145
146
                Layout.fillWidth: root.horizontal
                Layout.fillHeight: !root.horizontal
Marco Martin's avatar
Marco Martin committed
147
148
                Layout.row: 0
                Layout.column: root.horizontal ? 0 : 1
149
                implicitWidth: delegateSize + units.gridUnit
Marco Martin's avatar
Marco Martin committed
150
                implicitHeight: delegateSize + units.gridUnit * 3
151
152

                ListView {
153
                    id: appletsList
154
                    clip: false
155
                    topMargin: root.horizontal ? 0 : root.topPanelHeight
156
                    header: PlasmaExtras.Heading {
157
158
159
160
                        text: i18n("Widgets")
                        visible: !root.horizontal
                        width: visible ? implicitWidth : 0
                        height: visible ? implicitHeight : 0
Marco Martin's avatar
Marco Martin committed
161
                    }
162
163
164
                    orientation: root.horizontal ? ListView.Horizontal : ListView.Vertical
                    model: widgetExplorer.widgetsModel
                    delegate: AppletDelegate {}
165
                    Component.onCompleted: appletsList.contentY = -appletsList.topMargin - headerItem.height
Marco Martin's avatar
Marco Martin committed
166
167
168
169
                }
            }
        }
    }
170
171
172

    WidgetExplorer {
        id: widgetExplorer
173
        containment: root.containment
174
175
176
        //view: desktop
        onShouldClose: root.close();
    }
Marco Martin's avatar
Marco Martin committed
177
}