Merge lp:~zsombi/ubuntu-ui-toolkit/20-divider into lp:~bzoltan/ubuntu-ui-toolkit/new_list_item

Proposed by Zsombor Egri
Status: Superseded
Proposed branch: lp:~zsombi/ubuntu-ui-toolkit/20-divider
Merge into: lp:~bzoltan/ubuntu-ui-toolkit/new_list_item
Prerequisite: lp:~zsombi/ubuntu-ui-toolkit/10-viewitem
Diff against target: 551 lines (+332/-11)
7 files modified
components.api (+8/-0)
modules/Ubuntu/Components/plugin/plugin.cpp (+1/-0)
modules/Ubuntu/Components/plugin/uclistitem.cpp (+231/-9)
modules/Ubuntu/Components/plugin/uclistitem.h (+5/-0)
modules/Ubuntu/Components/plugin/uclistitem_p.h (+58/-0)
tests/resources/listitems/ListItemTest.qml (+13/-2)
tests/unit_x11/tst_components/tst_listitem.qml (+16/-0)
To merge this branch: bzr merge lp:~zsombi/ubuntu-ui-toolkit/20-divider
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Pending
Tim Peeters Pending
MichaƂ Sawicz Pending
Review via email: mp+234630@code.launchpad.net

Commit message

Adding divider to ListItem.

To post a comment you must log in.
1220. By Zsombor Egri

prereq

1221. By Zsombor Egri

prereq merge

1222. By Zsombor Egri

prereq updated

1223. By Zsombor Egri

prereq merge

1224. By Zsombor Egri

divider paint fixed

1225. By Zsombor Egri

prereq

1226. By Zsombor Egri

colroFrom and colorTo documented

1227. By Zsombor Egri

background colored only on the contentItem area

1228. By Zsombor Egri

divider to paint edge-to-edge when pressed

1229. By Zsombor Egri

prereq sync

1230. By Zsombor Egri

prereq sync

1231. By Zsombor Egri

prereq sync

1232. By Zsombor Egri

prereq sync

1233. By Zsombor Egri

prereq sync

1234. By Zsombor Egri

2GU to 2DP teft and rigth margins on divider

1235. By Zsombor Egri

prereq sync

1236. By Zsombor Egri

prereq sync

1237. By Zsombor Egri

prereq sync

1238. By Zsombor Egri

prereq sync

Unmerged revisions

1238. By Zsombor Egri

prereq sync

1237. By Zsombor Egri

prereq sync

1236. By Zsombor Egri

prereq sync

1235. By Zsombor Egri

prereq sync

1234. By Zsombor Egri

2GU to 2DP teft and rigth margins on divider

1233. By Zsombor Egri

prereq sync

1232. By Zsombor Egri

prereq sync

1231. By Zsombor Egri

prereq sync

1230. By Zsombor Egri

prereq sync

1229. By Zsombor Egri

prereq sync

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'components.api'
--- components.api 2014-09-15 08:22:13 +0000
+++ components.api 2014-09-15 08:22:15 +0000
@@ -818,6 +818,7 @@
818 prototype: "UCStyledItemBase"818 prototype: "UCStyledItemBase"
819 exports: ["ListItem 1.1"]819 exports: ["ListItem 1.1"]
820 Property { name: "contentItem"; type: "UCListItemContent"; isReadonly: true; isPointer: true }820 Property { name: "contentItem"; type: "UCListItemContent"; isReadonly: true; isPointer: true }
821 Property { name: "divider"; type: "UCListItemDivider"; isReadonly: true; isPointer: true }
821 Property { name: "pressed"; type: "bool"; isReadonly: true }822 Property { name: "pressed"; type: "bool"; isReadonly: true }
822 Property { name: "data"; type: "QObject"; isList: true; isReadonly: true }823 Property { name: "data"; type: "QObject"; isList: true; isReadonly: true }
823 Property { name: "children"; type: "QQuickItem"; isList: true; isReadonly: true }824 Property { name: "children"; type: "QQuickItem"; isList: true; isReadonly: true }
@@ -826,6 +827,13 @@
826 prototype: "QQuickItem"827 prototype: "QQuickItem"
827 Property { name: "color"; type: "QColor" }828 Property { name: "color"; type: "QColor" }
828 Property { name: "pressedColor"; type: "QColor" }829 Property { name: "pressedColor"; type: "QColor" }
830 name: "UCListItemDivider"
831 prototype: "QObject"
832 Property { name: "visible"; type: "bool" }
833 Property { name: "leftMargin"; type: "double" }
834 Property { name: "rightMargin"; type: "double" }
835 Property { name: "colorFrom"; type: "QColor" }
836 Property { name: "colorTo"; type: "QColor" }
829 name: "UCMouse"837 name: "UCMouse"
830 prototype: "QObject"838 prototype: "QObject"
831 exports: ["Mouse 0.1", "Mouse 1.0"]839 exports: ["Mouse 0.1", "Mouse 1.0"]
832840
=== modified file 'modules/Ubuntu/Components/plugin/plugin.cpp'
--- modules/Ubuntu/Components/plugin/plugin.cpp 2014-09-15 08:22:13 +0000
+++ modules/Ubuntu/Components/plugin/plugin.cpp 2014-09-15 08:22:15 +0000
@@ -162,6 +162,7 @@
162 // ListItem and related types162 // ListItem and related types
163 qmlRegisterType<UCListItem, 1>(uri, 1, 1, "ListItem");163 qmlRegisterType<UCListItem, 1>(uri, 1, 1, "ListItem");
164 qmlRegisterType<UCListItemContent>();164 qmlRegisterType<UCListItemContent>();
165 qmlRegisterType<UCListItemDivider>();
165}166}
166167
167void UbuntuComponentsPlugin::initializeEngine(QQmlEngine *engine, const char *uri)168void UbuntuComponentsPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
168169
=== modified file 'modules/Ubuntu/Components/plugin/uclistitem.cpp'
--- modules/Ubuntu/Components/plugin/uclistitem.cpp 2014-09-15 08:22:13 +0000
+++ modules/Ubuntu/Components/plugin/uclistitem.cpp 2014-09-15 08:22:15 +0000
@@ -35,7 +35,155 @@
35 }35 }
36 return result;36 return result;
37}37}
3838/******************************************************************************
39 * Divider
40 */
41UCListItemDivider::UCListItemDivider(QObject *parent)
42 : QObject(parent)
43 , m_visible(true)
44 , m_leftMarginChanged(false)
45 , m_rightMarginChanged(false)
46 , m_colorFromChanged(false)
47 , m_colorToChanged(false)
48 , m_thickness(0)
49 , m_leftMargin(0)
50 , m_rightMargin(0)
51 , m_listItem(0)
52{
53 connect(&UCUnits::instance(), &UCUnits::gridUnitChanged, this, &UCListItemDivider::unitsChanged);
54 connect(&UCTheme::instance(), &UCTheme::paletteChanged, this, &UCListItemDivider::paletteChanged);
55 unitsChanged();
56 paletteChanged();
57}
58UCListItemDivider::~UCListItemDivider()
59{
60}
61
62void UCListItemDivider::init(UCListItem *listItem)
63{
64 QQml_setParent_noEvent(this, listItem);
65 m_listItem = UCListItemPrivate::get(listItem);
66}
67
68void UCListItemDivider::unitsChanged()
69{
70 m_thickness = UCUnits::instance().dp(2);
71 if (!m_leftMarginChanged) {
72 m_leftMargin = UCUnits::instance().gu(2);
73 }
74 if (!m_rightMarginChanged) {
75 m_rightMargin = UCUnits::instance().gu(2);
76 }
77 if (m_listItem) {
78 m_listItem->update();
79 }
80}
81
82void UCListItemDivider::paletteChanged()
83{
84 QColor background = getPaletteColor("normal", "background");
85 if (!background.isValid()) {
86 return;
87 }
88 // FIXME: we need a palette value for divider colors, till then base on the background
89 // luminance
90 if (!m_colorFromChanged || !m_colorToChanged) {
91 qreal luminance = (background.red()*212 + background.green()*715 + background.blue()*73)/1000.0/255.0;
92 bool lightBackground = (luminance > 0.85);
93 if (!m_colorFromChanged) {
94 m_colorFrom = lightBackground ? QColor("#26000000") : QColor("#26FFFFFF");
95 }
96 if (!m_colorToChanged) {
97 m_colorTo = lightBackground ? QColor("#14FFFFFF") : QColor("#14000000");
98 }
99 updateGradient();
100 }
101}
102
103void UCListItemDivider::updateGradient()
104{
105 m_gradient.clear();
106 m_gradient.append(QGradientStop(0.0, m_colorFrom));
107 m_gradient.append(QGradientStop(0.49, m_colorFrom));
108 m_gradient.append(QGradientStop(0.5, m_colorTo));
109 m_gradient.append(QGradientStop(1.0, m_colorTo));
110 if (m_listItem) {
111 m_listItem->update();
112 }
113}
114
115QSGNode *UCListItemDivider::paint(QSGNode *paintNode, const QRectF &rect)
116{
117 if (m_visible && (m_gradient.size() > 0)) {
118 QSGRectangleNode *rectNode = static_cast<QSGRectangleNode *>(paintNode);
119 if (!rectNode) {
120 rectNode = m_listItem->sceneGraphContext()->createRectangleNode();
121 }
122 rectNode->setRect(QRectF(m_leftMargin, rect.height() - m_thickness,
123 rect.width() - m_leftMargin - m_rightMargin, m_thickness));
124 rectNode->setGradientStops(m_gradient);
125 rectNode->update();
126 return rectNode;
127 } else {
128 delete paintNode;
129 return 0;
130 }
131}
132
133void UCListItemDivider::setVisible(bool visible)
134{
135 if (m_visible == visible) {
136 return;
137 }
138 m_visible = visible;
139 m_listItem->resize();
140 m_listItem->update();
141 Q_EMIT visibleChanged();
142}
143
144void UCListItemDivider::setLeftMargin(qreal leftMargin)
145{
146 if (m_leftMargin == leftMargin) {
147 return;
148 }
149 m_leftMargin = leftMargin;
150 m_leftMarginChanged = true;
151 m_listItem->update();
152 Q_EMIT leftMarginChanged();
153}
154
155void UCListItemDivider::setRightMargin(qreal rightMargin)
156{
157 if (m_rightMargin == rightMargin) {
158 return;
159 }
160 m_rightMargin = rightMargin;
161 m_rightMarginChanged = true;
162 m_listItem->update();
163 Q_EMIT rightMarginChanged();
164}
165
166void UCListItemDivider::setColorFrom(const QColor &color)
167{
168 if (m_colorFrom == color) {
169 return;
170 }
171 m_colorFrom = color;
172 m_colorFromChanged = true;
173 updateGradient();
174 Q_EMIT colorFromChanged();
175}
176
177void UCListItemDivider::setColorTo(const QColor &color)
178{
179 if (m_colorTo == color) {
180 return;
181 }
182 m_colorTo = color;
183 m_colorToChanged = true;
184 updateGradient();
185 Q_EMIT colorToChanged();
186}
39187
40/******************************************************************************188/******************************************************************************
41 * ListItemContent189 * ListItemContent
@@ -114,10 +262,14 @@
114}262}
115263
116264
265/******************************************************************************
266 * ListItemBasePrivate
267 */
117UCListItemPrivate::UCListItemPrivate()268UCListItemPrivate::UCListItemPrivate()
118 : UCStyledItemBasePrivate()269 : UCStyledItemBasePrivate()
119 , pressed(false)270 , pressed(false)
120 , contentItem(new UCListItemContent)271 , contentItem(new UCListItemContent)
272 , divider(new UCListItemDivider)
121{273{
122}274}
123UCListItemPrivate::~UCListItemPrivate()275UCListItemPrivate::~UCListItemPrivate()
@@ -130,6 +282,7 @@
130 contentItem->setObjectName("ListItemHolder");282 contentItem->setObjectName("ListItemHolder");
131 QQml_setParent_noEvent(contentItem, q);283 QQml_setParent_noEvent(contentItem, q);
132 contentItem->setParentItem(q);284 contentItem->setParentItem(q);
285 divider->init(q);
133 // content will be redirected to the contentItem, therefore we must report286 // content will be redirected to the contentItem, therefore we must report
134 // children changes as it would come from the main component287 // children changes as it would come from the main component
135 QObject::connect(contentItem, &UCListItemContent::childrenChanged,288 QObject::connect(contentItem, &UCListItemContent::childrenChanged,
@@ -185,11 +338,31 @@
185 if (flickable.isNull()) {338 if (flickable.isNull()) {
186 return;339 return;
187 }340 }
341 Q_Q(UCListItem);
188 if (listen) {342 if (listen) {
189 QObject::connect(flickable.data(), SIGNAL(movementStarted()), q_ptr, SLOT(_q_rebound()));343 QObject::connect(flickable.data(), SIGNAL(movementStarted()), q, SLOT(_q_rebound()));
190 } else {344 } else {
191 QObject::disconnect(flickable.data(), SIGNAL(movementStarted()), q_ptr, SLOT(_q_rebound()));345 QObject::disconnect(flickable.data(), SIGNAL(movementStarted()), q, SLOT(_q_rebound()));
192 }346 }
347}
348
349void UCListItemPrivate::resize()
350{
351 Q_Q(UCListItem);
352 QRectF rect(q->boundingRect());
353 if (divider && divider->m_visible) {
354 rect.setHeight(rect.height() - divider->m_thickness);
355 }
356 contentItem->setSize(rect.size());
357}
358
359void UCListItemPrivate::update()
360{
361 if (!ready) {
362 return;
363 }
364 Q_Q(UCListItem);
365 q->update();
193}366}
194367
195/*!368/*!
@@ -218,6 +391,10 @@
218 * revealed and thus will destroy your logic391 * revealed and thus will destroy your logic
219 * \li never anchor left or right anchor lines as it will block revealing the options.392 * \li never anchor left or right anchor lines as it will block revealing the options.
220 * \endlist393 * \endlist
394 *
395 * Each ListItem has a thin divider shown on the bottom of the component. This
396 * divider can be configured through the \l divider grouped property, which can
397 * configure its margins from the edges of the ListItem as well as its visibility.
221 */398 */
222399
223/*!400/*!
@@ -238,6 +415,12 @@
238{415{
239}416}
240417
418void UCListItem::componentComplete()
419{
420 UCStyledItemBase::componentComplete();
421 d_func()->ready = true;
422}
423
241void UCListItem::itemChange(ItemChange change, const ItemChangeData &data)424void UCListItem::itemChange(ItemChange change, const ItemChangeData &data)
242{425{
243 UCStyledItemBase::itemChange(change, data);426 UCStyledItemBase::itemChange(change, data);
@@ -269,11 +452,23 @@
269void UCListItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)452void UCListItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
270{453{
271 UCStyledItemBase::geometryChanged(newGeometry, oldGeometry);454 UCStyledItemBase::geometryChanged(newGeometry, oldGeometry);
272 // resize contentItem item455 // resize background item
273 Q_D(UCListItem);456 Q_D(UCListItem);
274 QRectF rect(boundingRect());457 d->resize();
275 d->contentItem->setSize(rect.size());458}
276}459
460QSGNode *UCListItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data)
461{
462 Q_UNUSED(data);
463 Q_D(UCListItem);
464 if (width() <= 0 || height() <= 0 || !d->divider) {
465 delete oldNode;
466 return 0;
467 }
468 // paint divider
469 return d->divider->paint(oldNode, boundingRect());
470}
471
277void UCListItem::mousePressEvent(QMouseEvent *event)472void UCListItem::mousePressEvent(QMouseEvent *event)
278{473{
279 UCStyledItemBase::mousePressEvent(event);474 UCStyledItemBase::mousePressEvent(event);
@@ -319,6 +514,33 @@
319}514}
320515
321/*!516/*!
517 * \qmlpropertygroup ::ListItem::divider
518 * \qmlproperty bool ListItem::divider.visible
519 * \qmlproperty real ListItem::divider.leftMargin
520 * \qmlproperty real ListItem::divider.rightMargin
521 *
522 * This grouped property configures the thin divider shown in the bottom of the
523 * component. Configures the visibility and the margins from the left and right
524 * of the ListItem. When tugged (swiped left or right to reveal the options),
525 * it is not moved together with the content.
526 *
527 * When \c visible is true, the ListItem's content size gets thinner with the
528 * divider's \c thickness.
529 *
530 * The default values for the properties are:
531 * \list
532 * \li \c visible: true
533 * \li \c leftMargin: 2 GU
534 * \li \c rightMargin: 2 GU
535 * \endlist
536 */
537UCListItemDivider* UCListItem::divider() const
538{
539 Q_D(const UCListItem);
540 return d->divider;
541}
542
543/*!
322 * \qmlproperty bool ListItem::pressed544 * \qmlproperty bool ListItem::pressed
323 * True when the item is pressed. The items stays pressed when the mouse or touch545 * True when the item is pressed. The items stays pressed when the mouse or touch
324 * is moved horizontally. When in Flickable (or ListView), the item gets un-pressed546 * is moved horizontally. When in Flickable (or ListView), the item gets un-pressed
325547
=== modified file 'modules/Ubuntu/Components/plugin/uclistitem.h'
--- modules/Ubuntu/Components/plugin/uclistitem.h 2014-09-15 08:22:13 +0000
+++ modules/Ubuntu/Components/plugin/uclistitem.h 2014-09-15 08:22:15 +0000
@@ -21,11 +21,13 @@
21#include "ucstyleditembase.h"21#include "ucstyleditembase.h"
2222
23class UCListItemContent;23class UCListItemContent;
24class UCListItemDivider;
24class UCListItemPrivate;25class UCListItemPrivate;
25class UCListItem : public UCStyledItemBase26class UCListItem : public UCStyledItemBase
26{27{
27 Q_OBJECT28 Q_OBJECT
28 Q_PROPERTY(UCListItemContent *contentItem READ contentItem CONSTANT)29 Q_PROPERTY(UCListItemContent *contentItem READ contentItem CONSTANT)
30 Q_PROPERTY(UCListItemDivider *divider READ divider CONSTANT)
29 Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged)31 Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged)
30 Q_PROPERTY(QQmlListProperty<QObject> data READ data DESIGNABLE false)32 Q_PROPERTY(QQmlListProperty<QObject> data READ data DESIGNABLE false)
31 Q_PROPERTY(QQmlListProperty<QQuickItem> children READ children NOTIFY childrenChanged DESIGNABLE false)33 Q_PROPERTY(QQmlListProperty<QQuickItem> children READ children NOTIFY childrenChanged DESIGNABLE false)
@@ -35,10 +37,13 @@
35 ~UCListItem();37 ~UCListItem();
3638
37 UCListItemContent *contentItem() const;39 UCListItemContent *contentItem() const;
40 UCListItemDivider *divider() const;
38 bool pressed() const;41 bool pressed() const;
3942
40protected:43protected:
44 void componentComplete();
41 void itemChange(ItemChange change, const ItemChangeData &data);45 void itemChange(ItemChange change, const ItemChangeData &data);
46 QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data);
42 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);47 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
43 void mousePressEvent(QMouseEvent *event);48 void mousePressEvent(QMouseEvent *event);
44 void mouseReleaseEvent(QMouseEvent *event);49 void mouseReleaseEvent(QMouseEvent *event);
4550
=== modified file 'modules/Ubuntu/Components/plugin/uclistitem_p.h'
--- modules/Ubuntu/Components/plugin/uclistitem_p.h 2014-09-15 08:22:13 +0000
+++ modules/Ubuntu/Components/plugin/uclistitem_p.h 2014-09-15 08:22:15 +0000
@@ -20,9 +20,11 @@
20#include "uclistitem.h"20#include "uclistitem.h"
21#include "ucstyleditembase_p.h"21#include "ucstyleditembase_p.h"
22#include <QtCore/QPointer>22#include <QtCore/QPointer>
23#include <QtQuick/private/qquickrectangle_p.h>
2324
24class QQuickFlickable;25class QQuickFlickable;
25class UCListItemContent;26class UCListItemContent;
27class UCListItemDivider;
26class UCListItemPrivate : public UCStyledItemBasePrivate28class UCListItemPrivate : public UCStyledItemBasePrivate
27{29{
28 Q_DECLARE_PUBLIC(UCListItem)30 Q_DECLARE_PUBLIC(UCListItem)
@@ -44,10 +46,14 @@
44 void _q_updateSize();46 void _q_updateSize();
45 void setPressed(bool pressed);47 void setPressed(bool pressed);
46 void listenToRebind(bool listen);48 void listenToRebind(bool listen);
49 void resize();
50 void update();
4751
48 bool pressed:1;52 bool pressed:1;
53 bool ready:1;
49 QPointer<QQuickFlickable> flickable;54 QPointer<QQuickFlickable> flickable;
50 UCListItemContent *contentItem;55 UCListItemContent *contentItem;
56 UCListItemDivider *divider;
51};57};
5258
53class UCListItemContent : public QQuickItem59class UCListItemContent : public QQuickItem
@@ -80,8 +86,60 @@
80 bool m_pressedColorChanged:1;86 bool m_pressedColorChanged:1;
81};87};
8288
89class UCListItemDivider : public QObject
90{
91 Q_OBJECT
92 Q_PROPERTY(bool visible MEMBER m_visible WRITE setVisible NOTIFY visibleChanged)
93 Q_PROPERTY(qreal leftMargin MEMBER m_leftMargin WRITE setLeftMargin NOTIFY leftMarginChanged)
94 Q_PROPERTY(qreal rightMargin MEMBER m_rightMargin WRITE setRightMargin NOTIFY rightMarginChanged)
95 Q_PROPERTY(QColor colorFrom MEMBER m_colorFrom WRITE setColorFrom NOTIFY colorFromChanged)
96 Q_PROPERTY(QColor colorTo MEMBER m_colorTo WRITE setColorTo NOTIFY colorToChanged)
97public:
98 explicit UCListItemDivider(QObject *parent = 0);
99 ~UCListItemDivider();
100 void init(UCListItem *listItem);
101
102Q_SIGNALS:
103 void visibleChanged();
104 void leftMarginChanged();
105 void rightMarginChanged();
106 void colorFromChanged();
107 void colorToChanged();
108
109protected:
110 QSGNode *paint(QSGNode *paintNode, const QRectF &rect);
111
112private Q_SLOTS:
113 void unitsChanged();
114 void paletteChanged();
115
116private:
117 void updateGradient();
118 void setVisible(bool visible);
119 void setLeftMargin(qreal leftMargin);
120 void setRightMargin(qreal rightMargin);
121 void setColorFrom(const QColor &color);
122 void setColorTo(const QColor &color);
123
124 bool m_visible:1;
125 bool m_leftMarginChanged:1;
126 bool m_rightMarginChanged:1;
127 bool m_colorFromChanged:1;
128 bool m_colorToChanged:1;
129 qreal m_thickness;
130 qreal m_leftMargin;
131 qreal m_rightMargin;
132 QColor m_colorFrom;
133 QColor m_colorTo;
134 QGradientStops m_gradient;
135 UCListItemPrivate *m_listItem;
136 friend class UCListItem;
137 friend class UCListItemPrivate;
138};
139
83QColor getPaletteColor(const char *profile, const char *color);140QColor getPaletteColor(const char *profile, const char *color);
84141
85QML_DECLARE_TYPE(UCListItemContent)142QML_DECLARE_TYPE(UCListItemContent)
143QML_DECLARE_TYPE(UCListItemDivider)
86144
87#endif // UCVIEWITEM_P_H145#endif // UCVIEWITEM_P_H
88146
=== modified file 'tests/resources/listitems/ListItemTest.qml'
--- tests/resources/listitems/ListItemTest.qml 2014-09-15 08:22:13 +0000
+++ tests/resources/listitems/ListItemTest.qml 2014-09-15 08:22:15 +0000
@@ -37,18 +37,23 @@
37 print("click")37 print("click")
38 main.override = !main.override38 main.override = !main.override
39 }39 }
40 Label {
41 anchors.fill: parent
42 text: units.gridUnit + "PX/unit"
43 }
40 }44 }
4145
42 ListView {46 ListView {
43 id: view47 id: view
44 clip: true48 clip: true
45 width: parent.width49 width: parent.width
46 height: units.gu(40)50 height: units.gu(20)
47 model: 10051 model: 100
48 pressDelay: 052 pressDelay: 0
49 delegate: ListItem {53 delegate: ListItem {
50 id: listItem54 id: listItem
51 onClicked: print(" clicked")55 onClicked: print(" clicked")
56
52 Label {57 Label {
53 text: modelData + " item"58 text: modelData + " item"
54 }59 }
@@ -65,7 +70,7 @@
65 Flickable {70 Flickable {
66 id: flicker71 id: flicker
67 width: parent.width72 width: parent.width
68 height: units.gu(40)73 height: units.gu(20)
69 clip: true74 clip: true
70 contentHeight: column.childrenRect.height75 contentHeight: column.childrenRect.height
71 Column {76 Column {
@@ -78,6 +83,12 @@
78 color: "red"83 color: "red"
79 pressedColor: "lime"84 pressedColor: "lime"
80 }85 }
86 divider.colorFrom: UbuntuColors.green
87
88 Label {
89 text: modelData + " Flickable item"
90 }
91 onClicked: divider.visible = !divider.visible
81 }92 }
82 }93 }
83 }94 }
8495
=== modified file 'tests/unit_x11/tst_components/tst_listitem.qml'
--- tests/unit_x11/tst_components/tst_listitem.qml 2014-09-15 08:22:13 +0000
+++ tests/unit_x11/tst_components/tst_listitem.qml 2014-09-15 08:22:15 +0000
@@ -87,6 +87,13 @@
87 compare(defaults.contentItem.color, "#000000", "Transparent by default");87 compare(defaults.contentItem.color, "#000000", "Transparent by default");
88 compare(defaults.contentItem.pressedColor, Theme.palette.selected.background, "Theme.palette.selected.background color by default")88 compare(defaults.contentItem.pressedColor, Theme.palette.selected.background, "Theme.palette.selected.background color by default")
89 compare(defaults.pressed, false, "Not pressed buy default");89 compare(defaults.pressed, false, "Not pressed buy default");
90 compare(defaults.divider.visible, true, "divider is visible by default");
91 compare(defaults.divider.leftMargin, units.gu(2), "divider's left margin is 2GU");
92 compare(defaults.divider.rightMargin, units.gu(2), "divider's right margin is 2GU");
93 compare(defaults.divider.colorFrom, "#000000", "colorFrom differs.");
94 fuzzyCompare(defaults.divider.colorFrom.a, 0.14, 0.01, "colorFrom alpha differs");
95 compare(defaults.divider.colorTo, "#ffffff", "colorTo differs.");
96 fuzzyCompare(defaults.divider.colorTo.a, 0.07, 0.01, "colorTo alpha differs");
90 }97 }
9198
92 function test_children_in_content_item() {99 function test_children_in_content_item() {
@@ -145,5 +152,14 @@
145 compare(listItem.pressed, false, "Item is pressed still!");152 compare(listItem.pressed, false, "Item is pressed still!");
146 TestExtras.touchRelease(0, listItem, Qt.point(listItem.width / 2, dy));153 TestExtras.touchRelease(0, listItem, Qt.point(listItem.width / 2, dy));
147 }154 }
155
156 function test_background_height_change_on_divider_visible() {
157 // make sure the testItem's divider is shown
158 testItem.divider.visible = true;
159 verify(testItem.contentItem.height < testItem.height, "ListItem's background height must be less than the item itself.");
160 testItem.divider.visible = false;
161 compare(testItem.contentItem.height, testItem.height, "ListItem's background height must be the same as the item itself.");
162 testItem.divider.visible = true;
163 }
148 }164 }
149}165}

Subscribers

People subscribed via source and target branches

to all changes: