18 import Ubuntu.Components 0.1
21 import Unity.Application 0.1
23 import
"../Components"
24 import "../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
123 property string expandedCategoryId:
""
125 delegate: ListItems.Base {
127 objectName:
"dashCategory" + category
128 highlightWhenPressed:
false
131 readonly
property bool expandable: rendererLoader.item ? rendererLoader.item.expandable :
false
132 readonly
property bool filtered: rendererLoader.item ? rendererLoader.item.filtered :
true
133 readonly
property string category: categoryId
134 readonly
property var item: rendererLoader.item
138 objectName:
"cardTool"
140 template: model.renderer
141 components: model.components
142 viewWidth: parent.width
151 topMargin: hasSectionHeader ? 0 : units.gu(2)
155 switch (cardTool.categoryLayout) {
156 case "carousel":
return "CardCarousel.qml";
157 case "vertical-journal":
return "CardVerticalJournal.qml";
158 case "running-apps":
return "Apps/RunningApplicationsGrid.qml";
160 default:
return "CardFilterGrid.qml";
165 if (item.enableHeightBehavior !== undefined && item.enableHeightBehaviorOnNextCreation !== undefined) {
166 item.enableHeightBehavior = scopeView.enableHeightBehaviorOnNextCreation;
167 scopeView.enableHeightBehaviorOnNextCreation =
false;
169 if (source.toString().indexOf(
"Apps/RunningApplicationsGrid.qml") != -1) {
172 item.model = Qt.binding(
function() {
return runningApps; })
173 item.canEnableTerminationMode = Qt.binding(
function() { return scopeView.isCurrent })
175 item.model = Qt.binding(
function() {
return results })
177 item.objectName = Qt.binding(
function() { return categoryId })
178 item.scopeStyle = scopeView.scopeStyle;
179 if (item.expandable) {
180 var shouldFilter = categoryId != categoryView.expandedCategoryId;
181 item.setFilter(shouldFilter,
false );
183 updateDelegateCreationRange();
184 item.cardTool = cardTool;
187 Component.onDestruction: {
188 if (item.enableHeightBehavior !== undefined && item.enableHeightBehaviorOnNextCreation !== undefined) {
189 scopeView.enableHeightBehaviorOnNextCreation = item.enableHeightBehaviorOnNextCreation;
194 target: rendererLoader.item
196 if (scopeView.scope.id ===
"scopes" || scopeView.scope.id ==
"clickscope") {
200 scopeView.scope.activate(result)
202 previewListView.model = target.model;
203 previewListView.currentIndex = -1
204 previewListView.currentIndex = index;
205 previewListView.open =
true
209 previewListView.model = target.model;
210 previewListView.currentIndex = -1
211 previewListView.currentIndex = index;
212 previewListView.open =
true
214 onExpandableChanged: {
217 if (rendererLoader.item.expandable) {
218 var shouldFilter = baseItem.category != categoryView.expandedCategoryId;
219 rendererLoader.item.setFilter(shouldFilter,
false );
225 onExpandedCategoryIdChanged: {
226 collapseAllButExpandedCategory();
228 function collapseAllButExpandedCategory() {
229 var item = rendererLoader.item;
230 if (item.expandable) {
231 var shouldFilter = categoryId != categoryView.expandedCategoryId;
232 if (shouldFilter != item.filter) {
234 var shrinkingVisible = shouldFilter && y + item.collapsedHeight < categoryView.height;
235 var growingVisible = !shouldFilter && y + height < categoryView.height;
236 if (!previewListView.open || !shouldFilter) {
237 var animate = shrinkingVisible || growingVisible;
238 item.setFilter(shouldFilter, animate)
239 if (!shouldFilter && !previewListView.open) {
240 categoryView.maximizeVisibleArea(index, item.uncollapsedHeight);
246 onOriginYChanged: rendererLoader.updateDelegateCreationRange();
247 onContentYChanged: rendererLoader.updateDelegateCreationRange();
248 onHeightChanged: rendererLoader.updateDelegateCreationRange();
249 onContentHeightChanged: rendererLoader.updateDelegateCreationRange();
252 function updateDelegateCreationRange() {
253 if (categoryView.moving) {
256 if (categoryView.contentY < categoryView.originY) {
258 }
else if (categoryView.contentHeight - categoryView.originY > categoryView.height &&
259 categoryView.contentY + categoryView.height > categoryView.contentHeight) {
264 if (item && item.hasOwnProperty(
"displayMarginBeginning")) {
267 if (baseItem.y + baseItem.height <= 0) {
269 item.displayMarginBeginning = -baseItem.height;
270 item.displayMarginEnd = 0;
271 }
else if (baseItem.y >= categoryView.height) {
273 item.displayMarginBeginning = 0;
274 item.displayMarginEnd = -baseItem.height;
276 item.displayMarginBeginning = -Math.max(-baseItem.y, 0);
277 item.displayMarginEnd = -Math.max(baseItem.height - categoryView.height + baseItem.y, 0)
289 fillMode: Image.Stretch
290 source:
"graphics/dash_divider_top_lightgrad.png"
296 visible: index != categoryView.model.count - 1
298 bottom: parent.bottom
302 fillMode: Image.Stretch
303 source:
"graphics/dash_divider_top_darkgrad.png"
308 onHeightChanged: rendererLoader.updateDelegateCreationRange();
309 onYChanged: rendererLoader.updateDelegateCreationRange();
312 sectionProperty:
"name"
313 sectionDelegate: ListItems.Header {
314 objectName:
"dashSectionHeader" + (delegate ? delegate.category :
"")
315 property var delegate: categoryView.item(delegateIndex)
316 width: categoryView.width
318 textColor: scopeStyle ? scopeStyle.foreground :
"grey"
320 if (delegate && delegate.expandable)
321 return delegate.filtered ?
"graphics/header_handlearrow.png" :
"graphics/header_handlearrow2.png"
325 if (categoryView.expandedCategoryId != delegate.category)
326 categoryView.expandedCategoryId = delegate.category;
328 categoryView.expandedCategoryId =
"";
332 pageHeader: PageHeader {
334 objectName:
"scopePageHeader"
336 title: scopeView.scope ? scopeView.scope.name :
""
337 showBackButton: scopeView.hasBackAction
338 searchEntryEnabled:
true
339 searchInProgress: scopeView.scope ? scopeView.scope.searchInProgress :
false
340 scopeStyle: scopeView.scopeStyle
342 bottomItem: DashDepartments {
343 scope: scopeView.scope
344 width: parent.width <= units.gu(60) ? parent.width : units.gu(40)
345 anchors.right: parent.right
346 windowHeight: scopeView.height
347 windowWidth: scopeView.width
348 scopeStyle: scopeView.scopeStyle
351 onBackClicked: scopeView.backClicked()
357 objectName:
"previewListView"
359 scope: scopeView.scope
360 scopeStyle: scopeView.scopeStyle
362 height: parent.height
363 anchors.left: categoryView.right
366 pageHeader.unfocus();