Unity 8
FilterOptionSelector.qml
1 /*
2  * Copyright (C) 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.ListItems 1.3 as ListItems
20 
21 /*! Option Selector Filter Widget. */
22 
23 FilterWidget {
24  id: root
25 
26  implicitHeight: expandingItem.height
27 
28  signal filterSelected()
29 
30  ListItems.Expandable {
31  id: expandingItem
32  objectName: "expandingItem"
33 
34  expandedHeight: collapsedHeight + column.height
35  width: parent.width
36  showDivider: false
37 
38  onClicked: {
39  expanded = !expanded;
40  forceActiveFocus();
41  }
42 
43  Item {
44  id: holder
45  anchors.top: parent.top
46  height: expandingItem.collapsedHeight
47  width: parent.width
48 
49  Label {
50  anchors.left: parent.left
51  anchors.right: dropDown.left
52  anchors.verticalCenter: parent.verticalCenter
53  text: widgetData.label || ""
54  }
55 
56  Image {
57  id: dropDown
58  height: units.gu(3)
59  fillMode: Image.PreserveAspectFit
60  anchors.right: parent.right
61  anchors.verticalCenter: parent.verticalCenter
62  source: expandingItem.expanded ? "image://theme/up" : "image://theme/down"
63  }
64  }
65 
66  Column {
67  id: column
68  anchors.top: holder.bottom
69  width: parent.width
70  Repeater {
71  model: widgetData.options
72  objectName: "optionsRepeater"
73 
74  ListItems.Standard {
75  text: label
76  objectName: root.objectName + "label" + index;
77 
78  Image {
79  height: units.gu(3)
80  fillMode: Image.PreserveAspectFit
81  anchors.right: parent.right
82  anchors.verticalCenter: parent.verticalCenter
83  source: "image://theme/tick"
84  visible: checked
85  }
86 
87  onClicked: {
88  widgetData.options.setChecked(index, !checked);
89  root.filterSelected()
90  }
91  }
92  }
93  }
94  }
95 }