forked from Panorama/panorama
/
CategoryView.qml
134 lines (115 loc) · 3.47 KB
/
CategoryView.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import QtQuick 1.1
import "util.js" as Utils
import "theme.js" as Theme
View {
id: view
property string categories
property QtObject pndManager
property bool sortByTitle: true
property QtObject filteredPackages: pndManager.packages.inCategory(categories).notInstalled()
property QtObject filteredAndSortedPackages: sortByTitle ? filteredPackages.copy().sortedByTitle() : filteredPackages.copy().sortedByLastUpdated()
Keys.forwardTo: packageList
onOkButton: packageList.openCurrent()
onSelectButton: view.sortByTitle = !view.sortByTitle
PackageList {
id: packageList
columns: 2
pndManager: view.pndManager
model: filteredAndSortedPackages.copy().titleContains(search.text).packages
anchors.fill: parent
Keys.priority: Keys.AfterItem
Keys.forwardTo: [ui, search]
onCurrentIndexChanged: if(currentIndex < columns) positionViewAtBeginning()
header: Item {
height: 64
width: packageList.width
Row {
spacing: 32
anchors.centerIn: parent
Text {
text: "Sorting:"
anchors.verticalCenter: parent.verticalCenter
font.pixelSize: 16
}
Rectangle {
property bool selected: view.sortByTitle
width: sortByTitleText.paintedWidth + 32
height: 48
color: selected ? "#555" : "#eee"
radius: 8
Text {
anchors.centerIn: parent
id: sortByTitleText
text: "alphabetical"
color: parent.selected ? "white" : "black"
font.pixelSize: 16
}
MouseArea {
anchors.fill: parent
onClicked: view.sortByTitle = true
}
}
Rectangle {
property bool selected: !view.sortByTitle
width: sortByDateText.paintedWidth + 32
height: 48
color: selected ? "#555" : "#eee"
radius: 8
Text {
anchors.centerIn: parent
id: sortByDateText
text: "last updated"
color: parent.selected ? "white" : "black"
font.pixelSize: 16
}
MouseArea {
anchors.fill: parent
onClicked: view.sortByTitle = false
}
}
GuiHint {
control: "select"
anchors.verticalCenter: parent.verticalCenter
}
}
}
delegate: PackageDelegate {
pnd: modelData
height: packageList.cellHeight
width: packageList.cellWidth
onClicked: {
packageList.currentIndex = index;
packageList.openCurrent();
}
Text {
text: Utils.cropText(modelData.author.name, 40) + "\n" + (view.sortByTitle ? Utils.prettySize(modelData.size) : Utils.prettySize(modelData.size) + " (updated " + Utils.prettyLastUpdatedString(modelData.modified) + ")")
font.pixelSize: 14
}
}
}
Rectangle {
opacity: 0.8
height: 32
anchors.bottomMargin: search.text != "" ? 0 : -(height+1)
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
color: "#eee"
border {
color: "#444"
width: 1
}
TextInput {
id: search
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.right: parent.right
anchors.margins: 4
font.pixelSize: 14
activeFocusOnPress: false
cursorVisible: true
Keys.onRightPressed: event.accepted = true
Keys.onLeftPressed: event.accepted = true
}
}
}