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