DiscoverDrawer.qml 7.29 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/***************************************************************************
 *   Copyright © 2015 Aleix Pol Gonzalez <aleixpol@blue-systems.com>       *
 *                                                                         *
 *   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) version 3 or any later version        *
 *   accepted by the membership of KDE e.V. (or its successor approved     *
 *   by the membership of KDE e.V.), which shall act as a proxy            *
 *   defined in Section 14 of version 3 of the license.                    *
 *                                                                         *
 *   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, see <http://www.gnu.org/licenses/>. *
 ***************************************************************************/

Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
21
import QtQuick 2.5
22
import QtQuick.Layouts 1.1
23
import QtQuick.Controls 2.1
24
import org.kde.discover 2.0
25
import org.kde.discover.app 1.0
26
import org.kde.kirigami 2.8 as Kirigami
27
import "navigation.js" as Navigation
28

29
Kirigami.GlobalDrawer {
30
    id: drawer
Nate Graham's avatar
Nate Graham committed
31

32
33
34
    leftPadding: 0
    rightPadding: 0
    topPadding: 0
35
    bottomPadding: 0
36

Nate Graham's avatar
Nate Graham committed
37
38
39
    // FIXME: Dirty workaround for 385992
    width: Kirigami.Units.gridUnit * 14

40
    property bool wideScreen: false
41
    bannerImageSource: modal ? "qrc:/banners/banner.svg" : ""
42

43
44
45
    // In desktop view, it's a sidebar, and sidebars get the view BG color
    Kirigami.Theme.colorSet: modal ? Kirigami.Theme.Window : Kirigami.Theme.View

46
47
    resetMenuOnTriggered: false

48
49
    onBannerClicked: {
        Navigation.openHome();
50
        drawerOpen = false
51
52
    }

53
54
    property string currentSearchText

55
56
57
    onCurrentSubMenuChanged: {
        if (currentSubMenu)
            currentSubMenu.trigger()
58
        else if (currentSearchText.length > 0)
59
60
61
62
63
            window.leftPage.category = null
        else
            Navigation.openHome()
    }

64
65
66
67
    function suggestSearchText(text) {
        toploader.item.text = text
        toploader.item.forceActiveFocus()
    }
68
69
    topContent: ConditionalLoader {
        id: toploader
70
        condition: !modal
71
        Layout.fillWidth: true
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
72
73
74
        componentFalse: Item {
            Layout.minimumHeight: 1
        }
75
76
77
78
        componentTrue: Kirigami.AbstractApplicationHeader {
            preferredHeight: 40 // Match Kirigami.ToolBarApplicationHeader, which is hardcoded to this

            RowLayout {
79
80
81
                anchors.fill: parent
                anchors.leftMargin: Kirigami.Units.smallSpacing
                anchors.rightMargin: Kirigami.Units.smallSpacing
82
83
84
85
86

                SearchField {
                    id: searchField

                    Layout.fillWidth: true
87

88
                    visible: window.leftPage && (window.leftPage.searchFor !== null || window.leftPage.hasOwnProperty("search"))
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
89

90
                    page: window.leftPage
91

92
93
                    onCurrentSearchTextChanged: {
                        var curr = window.leftPage;
94

95
96
                        if (pageStack.depth>1)
                            pageStack.pop()
97

98
99
100
101
102
103
104
105
106
107
108
                        if (currentSearchText === "" && window.currentTopLevel === "" && !window.leftPage.category) {
                            Navigation.openHome()
                        } else if (!curr.hasOwnProperty("search")) {
                            if (currentSearchText) {
                                Navigation.clearStack()
                                Navigation.openApplicationList( { search: currentSearchText })
                            }
                        } else {
                            curr.search = currentSearchText;
                            curr.forceActiveFocus()
                        }
109
                    }
110
                }
111
112
113
114
115
116
117
118
119
120

                ToolButton {

                    icon.name: "go-home"
                    onClicked: Navigation.openHome()

                    ToolTip {
                        text: i18n("Return to the Featured page")
                    }
                }
121
122
123
124
            }
        }
    }

125
    ColumnLayout {
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
126
127
        spacing: 0
        Layout.fillWidth: true
Marco Martin's avatar
Marco Martin committed
128
129
        Layout.leftMargin: -drawer.leftPadding
        Layout.rightMargin: -drawer.rightPadding
130

131
132
133
        Kirigami.Separator {
            Layout.fillWidth: true
        }
134
135
136
137
138

        ProgressView {
            separatorVisible: false
        }

139
140
141
        ActionListItem {
            action: searchAction
        }
142
143
        ActionListItem {
            action: installedAction
144
        }
145
        ActionListItem {
146
            action: sourcesAction
147
        }
148
149

        ActionListItem {
150
            action: aboutAction
151
152
        }

153
        ActionListItem {
154
            objectName: "updateButton"
155
            action: updateAction
156

Nate Graham's avatar
Nate Graham committed
157
            backgroundColor: ResourcesModel.updatesCount>0 ? "orange" : Kirigami.Theme.backgroundColor
158
        }
Aleix Pol Gonzalez's avatar
Port    
Aleix Pol Gonzalez committed
159
160
161
162

        states: [
            State {
                name: "full"
163
                when: drawer.wideScreen
Aleix Pol Gonzalez's avatar
Port    
Aleix Pol Gonzalez committed
164
                PropertyChanges { target: drawer; drawerOpen: true }
165
166
167
            },
            State {
                name: "compact"
168
                when: !drawer.wideScreen
169
                PropertyChanges { target: drawer; drawerOpen: false }
Aleix Pol Gonzalez's avatar
Port    
Aleix Pol Gonzalez committed
170
171
            }
        ]
172
173
    }

174
175
    Component {
        id: categoryActionComponent
176
177
        Kirigami.Action {
            property QtObject category
Laurent Montel's avatar
Laurent Montel committed
178
            readonly property bool itsMe: window.leftPage && window.leftPage.hasOwnProperty("category") && (window.leftPage.category === category)
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
179
            text: category ? category.name : ""
180
            iconName: category ? category.icon : ""
181
            checked: itsMe
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
182
            visible: (!window.leftPage
183
184
                   || !window.leftPage.subcategories
                   || window.leftPage.subcategories === undefined
185
                   || currentSearchText.length === 0
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
186
                   || (category && category.contains(window.leftPage.subcategories))
187
188
                     )
            onTriggered: {
189
                if (!window.leftPage.canNavigate)
190
                    Navigation.openCategory(category, currentSearchText)
191
                else {
192
193
                    if (pageStack.depth>1)
                        pageStack.pop()
194
                    pageStack.currentIndex = 0
195
                    window.leftPage.category = category
196
                }
197
            }
198
        }
199
    }
200

201
    function createCategoryActions(categories) {
202
203
204
        var actions = []
        for(var i in categories) {
            var cat = categories[i];
205
            var catAction = categoryActionComponent.createObject(drawer, {category: cat, children: createCategoryActions(cat.subcategories)});
206
            actions.push(catAction)
207
        }
208
209
210
        return actions;
    }

211
    actions: createCategoryActions(CategoryModel.rootCategories)
212

213
214
    modal: !drawer.wideScreen
    handleVisible: !drawer.wideScreen
215
}