Debian Codegraph @

src/imports/Components/ListItems/1.3/MultiValue.qml

raw
1 /*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser 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 Lomiri.Components 1.3
19
20 /*!
21 \qmltype MultiValue
22 \inqmlmodule Lomiri.Components.ListItems 1.0
23 \ingroup lomiri-listitems
24 \brief List item displaying multiple values.
25 \note \b{The component is deprecated. Use ListItem component instead.}
26
27 Examples:
28 \qml
29 import Lomiri.Components.ListItems 1.3 as ListItem
30 Column {
31 ListItem.MultiValue {
32 text: "Label"
33 values: ["Value 1", "Value 2", "Value 3", "Value 4"]
34 onClicked: selected = !selected
35 }
36 ListItem.MultiValue {
37 text: "Label"
38 iconName: "compose"
39 values: ["Value 1", "Value 2", "Value 3", "Value 4"]
40 progression: true
41 onClicked: print("clicked")
42 }
43 }
44 \endqml
45 */
46 Base {
47 id: multiValueListItem
48
49 /*!
50 The list of values that will be shown under the label text
51 */
52 property variant values
53
54 Item {
55 height: label.height + valueLabel.height
56 anchors {
57 verticalCenter: parent.verticalCenter
58 left: parent.left
59 right: parent.right
60 }
61 LabelVisual {
62 id: label
63 selected: multiValueListItem.selected
64 anchors {
65 top: parent.top
66 left: parent.left
67 right: parent.right
68 }
69 text: multiValueListItem.text
70 }
71 LabelVisual {
72 id: valueLabel
73 selected: multiValueListItem.selected
74 secondary: true
75 anchors {
76 top: label.bottom
77 left: parent.left
78 right: parent.right
79 }
80 textSize: Label.Small
81 text: concatenatedValues(multiValueListItem.values)
82
83 function concatenatedValues(values) {
84 var n = values.length;
85 var result = "";
86 if (n > 0) {
87 result = values[0];
88 for (var i = 1; i < n; i++) {
89 result = result + ", " + values[i];
90 }
91 }
92 return result;
93 }
94 }
95 }
96 }