Debian Codegraph @

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