Debian Codegraph @

src/imports/Components/ListItems/1.3/Base.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 Base
22 \inqmlmodule Lomiri.Components.ListItems 1.0
23 \ingroup lomiri-listitems
24 \brief Parent class of various list item classes that can have
25 an icon and a progression symbol.
26 \note \b{The component is deprecated. Use ListItem component instead.}
27
28 Examples: See subclasses
29 */
30 Empty {
31 id: baseListItem
32
33 /*!
34 \deprecated
35
36 \b{Use iconName or iconSource instead.}
37
38 The location of the icon to show in the list item (optional), or an Item that is
39 shown on the left side inside the list item. The icon will automatically be
40 anchored to the left side of the list item, and if its height is undefined, to the top
41 and bottom of the list item.
42 \qmlproperty variant icon
43 */
44 property variant icon: iconSource != "" ? iconSource : undefined
45
46 /*!
47 The location of the icon to show in the list item if iconSource failed to load (optional).
48 \qmlproperty url fallbackIconSource
49 */
50 property alias fallbackIconSource: iconHelper.fallbackSource
51
52 /*!
53 The icon shown in the list item if iconName failed to load (optional).
54
55 \qmlproperty string fallbackIconName
56
57 If both fallbackIconSource and fallbackIconName are defined, fallbackIconName will be ignored.
58
59 \note The complete list of icons available in Lomiri is not published yet.
60 For now please refer to the folders where the icon themes are installed:
61 \list
62 \li Lomiri Touch: \l file:/usr/share/icons/suru
63 \li Lomiri Desktop: \l file:/usr/share/icons/lomiri-mono-dark
64 \endlist
65 These 2 separate icon themes will be merged soon.
66 */
67 property alias fallbackIconName: iconHelper.fallbackIconName
68
69 /*!
70 Show or hide the progression symbol.
71 */
72 property bool progression: false
73
74 /*!
75 Show or hide the frame around the icon
76 \qmlproperty bool iconFrame
77 */
78 property alias iconFrame: iconHelper.hasFrame
79
80 /*!
81 \internal
82 Width of the icon to be displayed
83 */
84 property real __iconWidth
85
86 /*!
87 \internal
88 Height of the icon to be displayed
89 */
90 property real __iconHeight
91
92 /*!
93 \internal
94 The margin on the left side of the icon.
95 */
96 property real __leftIconMargin
97
98 /*!
99 \internal
100 The margin on the right side of the icon.
101 */
102 property real __rightIconMargin
103
104
105 IconVisual {
106 id: iconHelper
107
108 width: height
109 height: Math.min(units.gu(5), parent.height - units.gu(1))
110 anchors {
111 left: parent.left
112 leftMargin: baseListItem.__contentsMargins
113 verticalCenter: parent.verticalCenter
114 }
115 }
116
117 /*!
118 \internal
119 The \l icon property is an Item. The value is false if \l icon is a string,
120 or when no icon was set.
121 */
122 property bool __iconIsItem: false
123
124 /*!
125 \internal
126 */
127 onIconChanged: {
128 if (icon == undefined) return;
129 if (icon != iconSource) {
130 console.warn("WARNING: ListItems.Base.icon is DEPRECATED. " +
131 "Use iconName and iconSource instead.")
132 }
133 if (typeof icon == "string" || typeof icon == typeof iconSource) {
134 // icon is the url of an image
135 iconHelper.source = icon;
136 __iconIsItem = false;
137 } else {
138 // icon is an Item.
139 __iconIsItem = true;
140 iconHelper.source = "";
141
142 icon.parent = baseListItem;
143 icon.anchors.left = baseListItem.left;
144 icon.anchors.margins = Qt.binding(function() { return baseListItem.__contentsMargins });
145 if (!icon.height) {
146 icon.anchors.top = baseListItem.top;
147 icon.anchors.bottom = baseListItem.bottom;
148 }
149 }
150 }
151
152 /*!
153 \internal
154 */
155 default property alias children: middle.data
156 Item {
157 id: middle
158 property bool anchorToIconHelper: !__iconIsItem && iconHelper.source != ""
159 anchors {
160 top: parent.top
161 bottom: parent.bottom
162 left: anchorToIconHelper ? iconHelper.right : parent.left
163 right: baseListItem.progression ? progressionHelper.left : parent.right
164 rightMargin: baseListItem.__contentsMargins
165 leftMargin: __iconIsItem ? icon.width + 2 * baseListItem.__contentsMargins : baseListItem.__contentsMargins
166 }
167 }
168
169 ProgressionVisual {
170 id: progressionHelper
171 visible: baseListItem.progression
172 anchors {
173 right: parent.right
174 rightMargin: baseListItem.__contentsMargins
175 top: parent.top
176 bottom: parent.bottom
177 }
178 }
179 }