Unity 8
FiltersPopover.qml
1 /*
2  * Copyright (C) 2013-2015 Canonical, Ltd.
3  *
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.
7  *
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.
12  *
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/>.
15  */
16 
17 import QtQuick 2.4
18 import Ubuntu.Components 1.3
19 import Ubuntu.Components.Popups 1.3
20 import Ubuntu.Components.ListItems 1.3 as ListItems
21 import "Filters" as Filters
22 
23 Popover {
24  id: root
25  objectName: "filtersPopover"
26 
27  Flickable {
28  id: flickable
29  anchors {
30  top: parent.top
31  left: parent.left
32  right: parent.right
33  }
34  height: {
35  // Popover doesn't like being 75% or bigger than the screen (counting the "empty" part on top)
36  var posToRootParent = flickable.mapToItem(null, 0, 0).y;
37  var threeQuartersParent = root.parent.height * 3 / 4 - posToRootParent - 1;
38  var parentAndKeyboard = root.parent.height - posToRootParent - (Qt.inputMethod.visible ? Qt.inputMethod.keyboardRectangle.height + units.gu(3) : 0)
39  return Math.min(parentAndKeyboard, Math.min(threeQuartersParent, column.height));
40  }
41  clip: true
42  contentHeight: column.height
43  contentWidth: width
44 
45  Column {
46  id: column
47  width: parent.width
48 
49  Item {
50  width: parent.width
51  height: resetLabel.height + units.gu(3)
52 
53  Label {
54  anchors {
55  left: parent.left
56  right: resetLabel.left
57  margins: units.gu(2)
58  verticalCenter: parent.verticalCenter
59  }
60  text: i18n.tr("Refine your results")
61  }
62  Label {
63  id: resetLabel
64  anchors {
65  right: parent.right
66  rightMargin: units.gu(2)
67  verticalCenter: parent.verticalCenter
68  }
69  text: i18n.tr("Reset")
70 
71  AbstractButton {
72  anchors {
73  fill: parent
74  rightMargin: units.gu(-2)
75  leftMargin: units.gu(-2)
76  topMargin: units.gu(-1)
77  bottomMargin: units.gu(-1)
78  }
79  onClicked: {
80  scopeView.scope.resetFilters();
81  }
82  }
83  }
84  }
85 
86  Repeater {
87  id: repeater
88  model: scopeView.scope.filters
89 
90  delegate: Filters.FilterWidgetFactory {
91  width: parent.width
92 
93  widgetId: id
94  widgetType: type
95  widgetData: filter
96 
97  ListItems.ThinDivider {
98  anchors.bottom: parent.bottom
99  visible: index != repeater.count - 1
100  }
101  }
102  }
103  }
104  }
105 }