2 * Copyright (C) 2013-2014 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18import Ubuntu.Components 0.1
21import Unity.Application 0.1
24import "../Components/ListItems" as ListItems
29 property var scope: null
30 property SortFilterProxyModel categories: categoryFilter
31 property bool isCurrent: false
32 property alias moving: categoryView.moving
33 property bool hasBackAction: false
34 property bool enableHeightBehaviorOnNextCreation: false
35 property var categoryView: categoryView
37 property var scopeStyle: ScopeStyle {
38 style: scope ? scope.customizations : {}
45 scope.activateApplication.connect(activateApp);
49 function activateApp(appId) {
50 shell.activateApplication(appId);
53 function positionAtBeginning() {
54 categoryView.positionAtBeginning()
57 function showHeader() {
58 categoryView.showHeader()
61 function closePreview() {
62 previewListView.open = false;
68 value: isCurrent && !previewListView.open
71 SortFilterProxyModel {
73 model: scope ? scope.categories : null
74 dynamicSortFilter: true
75 filterRole: Categories.RoleCount
81 pageHeader.resetSearch();
82 previewListView.open = false;
86 target: scopeView.scope
87 property: "searchQuery"
88 value: pageHeader.searchQuery
94 property: "searchQuery"
95 value: scopeView.scope ? scopeView.scope.searchQuery : ""
100 target: scopeView.scope
101 onShowDash: previewListView.open = false;
102 onHideDash: previewListView.open = false;
107 color: scopeView.scopeStyle ? scopeView.scopeStyle.background : "transparent"
108 visible: color != "transparent"
113 objectName: "categoryListView"
115 x: previewListView.open ? -width : 0
116 Behavior on x { UbuntuNumberAnimation { } }
118 height: parent.height
120 model: scopeView.categories
121 forceNoClip: previewListView.open
124 property string expandedCategoryId: ""
126 delegate: ListItems.Base {
128 objectName: "dashCategory" + category
129 highlightWhenPressed: false
132 readonly property bool expandable: {
133 if (categoryView.model.count === 1) return false;
134 if (cardTool.template && cardTool.template["collapsed-rows"] === 0) return false;
135 if (item && item.expandedHeight > item.collapsedHeight) return true;
138 property bool expanded: false
139 readonly property string category: categoryId
140 readonly property string headerLink: model.headerLink
141 readonly property var item: rendererLoader.item
143 function expand(expand, animate) {
144 heightBehaviour.enabled = animate;
150 objectName: "cardTool"
152 template: model.renderer
153 components: model.components
154 viewWidth: parent.width
157 onExpandableChanged: {
158 // This can happen with the VJ that doesn't know how height it will be on creation
159 // so doesn't set expandable until a bit too late for onLoaded
161 var shouldExpand = baseItem.category === categoryView.expandedCategoryId;
162 baseItem.expand(shouldExpand, false /*animate*/);
166 onHeightChanged: rendererLoader.updateDelegateCreationRange();
167 onYChanged: rendererLoader.updateDelegateCreationRange();
175 topMargin: name != "" ? 0 : units.gu(2)
181 animation: UbuntuNumberAnimation {
184 heightBehaviour.enabled = false
190 readonly property bool expanded: baseItem.expanded || !baseItem.expandable
191 height: expanded ? item.expandedHeight : item.collapsedHeight
194 switch (cardTool.categoryLayout) {
195 case "carousel": return "CardCarousel.qml";
196 case "vertical-journal": return "CardVerticalJournal.qml";
197 case "running-apps": return "Apps/RunningApplicationsGrid.qml";
199 default: return "CardGrid.qml";
204 if (item.enableHeightBehavior !== undefined && item.enableHeightBehaviorOnNextCreation !== undefined) {
205 item.enableHeightBehavior = scopeView.enableHeightBehaviorOnNextCreation;
206 scopeView.enableHeightBehaviorOnNextCreation = false;
208 if (source.toString().indexOf("Apps/RunningApplicationsGrid.qml") != -1) {
209 // TODO: this is still a kludge :D Ideally add some kind of hook so that we
210 // can do this from DashApps.qml or think a better way that needs no special casing
211 item.model = Qt.binding(function() { return runningApps; })
212 item.canEnableTerminationMode = Qt.binding(function() { return scopeView.isCurrent })
214 item.model = Qt.binding(function() { return results })
216 item.objectName = Qt.binding(function() { return categoryId })
217 item.scopeStyle = scopeView.scopeStyle;
218 if (baseItem.expandable) {
219 var shouldExpand = categoryId === categoryView.expandedCategoryId;
220 baseItem.expand(shouldExpand, false /*animate*/);
222 updateDelegateCreationRange();
223 item.cardTool = cardTool;
226 Component.onDestruction: {
227 if (item.enableHeightBehavior !== undefined && item.enableHeightBehaviorOnNextCreation !== undefined) {
228 scopeView.enableHeightBehaviorOnNextCreation = item.enableHeightBehaviorOnNextCreation;
233 target: rendererLoader.item
235 if (scopeView.scope.id === "scopes" || scopeView.scope.id == "clickscope") {
236 // TODO Technically it is possible that calling activate() will make the scope emit
237 // previewRequested so that we show a preview but there's no scope that does that yet
238 // so it's not implemented
239 scopeView.scope.activate(result)
244 onPressAndHold: openPreview(index)
246 function openPreview(index) {
247 if (!rendererLoader.expanded && !seeAllLabel.visible && target.collapsedItemCount > 0) {
248 previewLimitModel.model = target.model;
249 previewLimitModel.limit = target.collapsedItemCount;
250 previewListView.model = previewLimitModel;
252 previewListView.model = target.model;
254 previewListView.currentIndex = -1;
255 previewListView.currentIndex = index;
256 previewListView.open = true;
261 onExpandedCategoryIdChanged: {
262 collapseAllButExpandedCategory();
264 function collapseAllButExpandedCategory() {
265 var item = rendererLoader.item;
266 if (baseItem.expandable) {
267 var shouldExpand = categoryId === categoryView.expandedCategoryId;
268 if (shouldExpand != baseItem.expanded) {
269 // If the filter animation will be seen start it, otherwise, just flip the switch
270 var shrinkingVisible = !shouldExpand && y + item.collapsedHeight + seeAll.height < categoryView.height;
271 var growingVisible = shouldExpand && y + height < categoryView.height;
272 if (!previewListView.open || shouldExpand) {
273 var animate = shrinkingVisible || growingVisible;
274 baseItem.expand(shouldExpand, animate)
275 if (shouldExpand && !previewListView.open) {
276 categoryView.maximizeVisibleArea(index, item.expandedHeight + seeAll.height);
282 onOriginYChanged: rendererLoader.updateDelegateCreationRange();
283 onContentYChanged: rendererLoader.updateDelegateCreationRange();
284 onHeightChanged: rendererLoader.updateDelegateCreationRange();
285 onContentHeightChanged: rendererLoader.updateDelegateCreationRange();
288 function updateDelegateCreationRange() {
289 if (categoryView.moving) {
290 // Do not update the range if we are overshooting up or down, since we'll come back
291 // to the stable position and delete/create items without any reason
292 if (categoryView.contentY < categoryView.originY) {
294 } else if (categoryView.contentHeight - categoryView.originY > categoryView.height &&
295 categoryView.contentY + categoryView.height > categoryView.contentHeight) {
300 if (item && item.hasOwnProperty("displayMarginBeginning")) {
301 // TODO do we need item.originY here, test 1300302 once we have a silo
302 // and we can run it on the phone
303 if (baseItem.y + baseItem.height <= 0) {
304 // Not visible (item at top of the list viewport)
305 item.displayMarginBeginning = -baseItem.height;
306 item.displayMarginEnd = 0;
307 } else if (baseItem.y >= categoryView.height) {
308 // Not visible (item at bottom of the list viewport)
309 item.displayMarginBeginning = 0;
310 item.displayMarginEnd = -baseItem.height;
312 item.displayMarginBeginning = -Math.max(-baseItem.y, 0);
313 item.displayMarginEnd = -Math.max(baseItem.height - seeAll.height
314 - categoryView.height + baseItem.y, 0)
324 top: rendererLoader.bottom
328 height: seeAllLabel.visible ? seeAllLabel.font.pixelSize + units.gu(6) : 0
331 if (categoryView.expandedCategoryId != baseItem.category) {
332 categoryView.expandedCategoryId = baseItem.category;
334 categoryView.expandedCategoryId = "";
340 text: baseItem.expanded ? i18n.tr("See less") : i18n.tr("See all")
343 verticalCenterOffset: units.gu(-0.5)
346 font.weight: Font.Bold
347 color: scopeStyle ? scopeStyle.foreground : "grey"
348 visible: baseItem.expandable && !baseItem.headerLink
359 fillMode: Image.Stretch
360 source: "graphics/dash_divider_top_lightgrad.png"
365 // FIXME Should not rely on model.count but view.count, but ListViewWithPageHeader doesn't expose it yet.
366 visible: index != categoryView.model.count - 1
368 bottom: seeAll.bottom
372 fillMode: Image.Stretch
373 source: "graphics/dash_divider_top_darkgrad.png"
378 sectionProperty: "name"
379 sectionDelegate: ListItems.Header {
380 objectName: "dashSectionHeader" + (delegate ? delegate.category : "")
381 readonly property var delegate: categoryView.item(delegateIndex)
382 width: categoryView.width
383 height: section != "" ? units.gu(5) : 0
385 color: scopeStyle ? scopeStyle.foreground : "grey"
386 iconName: delegate && delegate.headerLink ? "go-next" : ""
388 if (delegate.headerLink) scopeView.scope.performQuery(delegate.headerLink);
392 pageHeader: PageHeader {
394 objectName: "scopePageHeader"
396 title: scopeView.scope ? scopeView.scope.name : ""
397 searchHint: scopeView.scope && scopeView.scope.searchHint || i18n.tr("Search")
398 showBackButton: scopeView.hasBackAction
399 searchEntryEnabled: true
400 searchInProgress: scopeView.scope ? scopeView.scope.searchInProgress : false
401 scopeStyle: scopeView.scopeStyle
403 bottomItem: DashDepartments {
404 scope: scopeView.scope
405 width: parent.width <= units.gu(60) ? parent.width : units.gu(40)
406 anchors.right: parent.right
407 windowHeight: scopeView.height
408 windowWidth: scopeView.width
409 scopeStyle: scopeView.scopeStyle
412 onBackClicked: scopeView.backClicked()
417 id: previewLimitModel
422 objectName: "previewListView"
424 scope: scopeView.scope
425 scopeStyle: scopeView.scopeStyle
427 height: parent.height
428 anchors.left: categoryView.right
431 pageHeader.unfocus();
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list