| 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.2 |
| 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 |
\deprecated |
| 83 |
Width of the icon to be displayed |
| 84 |
*/ |
| 85 |
property real __iconWidth |
| 86 |
|
| 87 |
/*! |
| 88 |
\internal |
| 89 |
\deprecated |
| 90 |
Height of the icon to be displayed |
| 91 |
*/ |
| 92 |
property real __iconHeight |
| 93 |
|
| 94 |
/*! |
| 95 |
\internal |
| 96 |
\deprecated |
| 97 |
The margin on the left side of the icon. |
| 98 |
*/ |
| 99 |
property real __leftIconMargin |
| 100 |
|
| 101 |
/*! |
| 102 |
\internal |
| 103 |
\deprecated |
| 104 |
The margin on the right side of the icon. |
| 105 |
*/ |
| 106 |
property real __rightIconMargin |
| 107 |
|
| 108 |
|
| 109 |
IconVisual { |
| 110 |
id: iconHelper |
| 111 |
|
| 112 |
width: height |
| 113 |
height: Math.min(units.gu(5), parent.height - units.gu(1)) |
| 114 |
anchors { |
| 115 |
left: parent.left |
| 116 |
leftMargin: baseListItem.__contentsMargins |
| 117 |
verticalCenter: parent.verticalCenter |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
/*! |
| 122 |
\internal |
| 123 |
The \l icon property is an Item. The value is false if \l icon is a string, |
| 124 |
or when no icon was set. |
| 125 |
*/ |
| 126 |
property bool __iconIsItem: false |
| 127 |
|
| 128 |
/*! |
| 129 |
\internal |
| 130 |
*/ |
| 131 |
onIconChanged: { |
| 132 |
if (icon == undefined) return; |
| 133 |
if (icon != iconSource) { |
| 134 |
console.warn("WARNING: ListItems.Base.icon is DEPRECATED. " + |
| 135 |
"Use iconName and iconSource instead.") |
| 136 |
} |
| 137 |
if (typeof icon == "string" || typeof icon == typeof iconSource) { |
| 138 |
// icon is the url of an image |
| 139 |
iconHelper.source = icon; |
| 140 |
__iconIsItem = false; |
| 141 |
} else { |
| 142 |
// icon is an Item. |
| 143 |
__iconIsItem = true; |
| 144 |
iconHelper.source = ""; |
| 145 |
|
| 146 |
icon.parent = baseListItem; |
| 147 |
icon.anchors.left = baseListItem.left; |
| 148 |
icon.anchors.margins = Qt.binding(function() { return baseListItem.__contentsMargins }); |
| 149 |
if (!icon.height) { |
| 150 |
icon.anchors.top = baseListItem.top; |
| 151 |
icon.anchors.bottom = baseListItem.bottom; |
| 152 |
} |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
/*! |
| 157 |
\internal |
| 158 |
*/ |
| 159 |
default property alias children: middle.data |
| 160 |
Item { |
| 161 |
id: middle |
| 162 |
property bool anchorToIconHelper: !__iconIsItem && iconHelper.source != "" |
| 163 |
anchors { |
| 164 |
top: parent.top |
| 165 |
bottom: parent.bottom |
| 166 |
left: anchorToIconHelper ? iconHelper.right : parent.left |
| 167 |
right: baseListItem.progression ? progressionHelper.left : parent.right |
| 168 |
rightMargin: baseListItem.__contentsMargins |
| 169 |
leftMargin: __iconIsItem ? icon.width + 2 * baseListItem.__contentsMargins : baseListItem.__contentsMargins |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
ProgressionVisual { |
| 174 |
id: progressionHelper |
| 175 |
visible: baseListItem.progression |
| 176 |
anchors { |
| 177 |
right: parent.right |
| 178 |
rightMargin: baseListItem.__contentsMargins |
| 179 |
top: parent.top |
| 180 |
bottom: parent.bottom |
| 181 |
} |
| 182 |
} |
| 183 |
} |