Merge lp:~zsombi/ubuntu-ui-toolkit/34-snap-animator into lp:~zsombi/ubuntu-ui-toolkit/listitem-master

Proposed by Zsombor Egri
Status: Merged
Approved by: Zsombor Egri
Approved revision: 1333
Merged at revision: 1271
Proposed branch: lp:~zsombi/ubuntu-ui-toolkit/34-snap-animator
Merge into: lp:~zsombi/ubuntu-ui-toolkit/listitem-master
Prerequisite: lp:~zsombi/ubuntu-ui-toolkit/33-listitem-attached
Diff against target: 214 lines (+152/-0)
3 files modified
modules/Ubuntu/Components/plugin/uclistitem.cpp (+125/-0)
modules/Ubuntu/Components/plugin/uclistitem.h (+1/-0)
modules/Ubuntu/Components/plugin/uclistitem_p.h (+26/-0)
To merge this branch: bzr merge lp:~zsombi/ubuntu-ui-toolkit/34-snap-animator
Reviewer Review Type Date Requested Status
Tim Peeters Approve
Zsombor Egri Pending
Review via email: mp+240853@code.launchpad.net

Description of the change

Adding UCListItemSnapAnimator.

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

prereq sync

1320. By Zsombor Egri

adjustments

1321. By Zsombor Egri

prereq sync

1322. By Zsombor Egri

prereq sync

1323. By Zsombor Egri

removing custom code

1324. By Zsombor Egri

prereq sync

1325. By Zsombor Egri

prereq sync

1326. By Zsombor Egri

remove custom snapAnimation property for now

1327. By Zsombor Egri

prereq sync

1328. By Zsombor Egri

prereq sync

1329. By Zsombor Egri

prereq sync

1330. By Zsombor Egri

adding animation comletion function; fix snapOut() snapIn() calls to disconnect the signal only if those were invoked by the signal

1331. By Zsombor Egri

prereq sync

1332. By Zsombor Egri

documentation added

1333. By Zsombor Egri

prereq sync

Revision history for this message
Tim Peeters (tpeeters) wrote :

Good, next!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'modules/Ubuntu/Components/plugin/uclistitem.cpp'
2--- modules/Ubuntu/Components/plugin/uclistitem.cpp 2014-11-19 15:10:50 +0000
3+++ modules/Ubuntu/Components/plugin/uclistitem.cpp 2014-11-19 15:10:51 +0000
4@@ -22,6 +22,8 @@
5 #include <QtQuick/private/qquickitem_p.h>
6 #include <QtQuick/private/qquickflickable_p.h>
7 #include <QtQuick/private/qquickpositioners_p.h>
8+#include <QtQuick/private/qquickanimation_p.h>
9+#include "ucubuntuanimation.h"
10
11 QColor getPaletteColor(const char *profile, const char *color)
12 {
13@@ -36,6 +38,128 @@
14 return result;
15 }
16 /******************************************************************************
17+ * SnapAnimator
18+ *
19+ * The class handles the animation executed when the ListItemAction panel is
20+ * swiped. The animation is executed from the swipe position the mouse/touch is
21+ * released to the desired position given in snap(). The action panel is assumed
22+ * to be anchored to the ListItem.contentItem left or right, depending on which
23+ * action list is swiped in. Therefore the animator only changes the ListItem.contentItem
24+ * x coordinate.
25+ * The animation is defined by the style.
26+ */
27+UCListItemSnapAnimator::UCListItemSnapAnimator(UCListItem *item)
28+ : QObject(item)
29+ , item(item)
30+{
31+}
32+UCListItemSnapAnimator::~UCListItemSnapAnimator()
33+{
34+ // make sure we cannot animate anymore, for safety
35+ item = 0;
36+}
37+
38+/*
39+ * Snap the ListItem.contentItem in or out, depending on the position specified
40+ * in "to" parameter. If the position is 0, a snap out will be executed - see
41+ * snapOut(). In any other cases a snap in action will be performed - see snapIn().
42+ */
43+bool UCListItemSnapAnimator::snap(qreal to)
44+{
45+ if (!item) {
46+ return false;
47+ }
48+ UCListItemPrivate *listItem = UCListItemPrivate::get(item);
49+ QQuickPropertyAnimation *snap = getDefaultAnimation();
50+ if (!snap) {
51+ // no animation, so we simply position the component
52+ listItem->contentItem->setX(to);
53+ return false;
54+ }
55+ snap->setTargetObject(listItem->contentItem);
56+ if (to == 0.0) {
57+ QObject::connect(snap, &QQuickAbstractAnimation::stopped,
58+ this, &UCListItemSnapAnimator::snapOut);
59+ } else {
60+ QObject::connect(snap, &QQuickAbstractAnimation::stopped,
61+ this, &UCListItemSnapAnimator::snapIn);
62+ }
63+ if (snap->properties().isEmpty() && snap->property().isEmpty()) {
64+ snap->setProperty("x");
65+ }
66+ snap->setFrom(listItem->contentItem->property(snap->property().toLocal8Bit().constData()));
67+ snap->setTo(to);
68+ snap->setAlwaysRunToEnd(true);
69+ // FIXME - this will be used later
70+// listItem->setContentMoved(true);
71+ snap->start();
72+ return true;
73+}
74+
75+/*
76+ * The function completes a running snap animation.
77+ */
78+void UCListItemSnapAnimator::complete()
79+{
80+ QQuickPropertyAnimation *snap = getDefaultAnimation();
81+ if (snap && snap->isRunning()) {
82+ snap->complete();
83+ }
84+}
85+
86+/*
87+ * Snap out is performed when the ListItem.contentItem returns back to its original
88+ * X coordinates (0). At this point both leading and trailing action panels will
89+ * be disconnected, ascending Flickables will get unlocked (interactive value restored
90+ * to the state before they were locked) and ListItem.contentMoving will be reset.
91+ */
92+void UCListItemSnapAnimator::snapOut()
93+{
94+ if (senderSignalIndex() >= 0) {
95+ // disconnect animation, otherwise snapping will disconnect the panel
96+ QQuickAbstractAnimation *snap = getDefaultAnimation();
97+ QObject::disconnect(snap, 0, 0, 0);
98+ }
99+ UCListItemPrivate *listItem = UCListItemPrivate::get(item);
100+ if (listItem->attachedProperties) {
101+ // restore flickable's interactive and cleanup
102+ listItem->attachedProperties->disableInteractive(item, false);
103+ // no need to listen flickables any longer
104+ listItem->attachedProperties->listenToRebind(item, false);
105+ }
106+ // disconnect actions - FIXME this will be used later
107+// listItem->grabPanel(listItem->leadingActions, false);
108+// listItem->grabPanel(listItem->trailingActions, false);
109+ // set contentMoving to false - FIXME used later
110+// listItem->setContentMoving(false);
111+}
112+
113+/*
114+ * Snap in only resets the ListItem.contentMoving property, but will keep leading/trailing
115+ * actions connected as well as all ascendant Flickables locked (interactive = false).
116+ */
117+void UCListItemSnapAnimator::snapIn()
118+{
119+ if (senderSignalIndex() >= 0) {
120+ // disconnect animation
121+ QQuickAbstractAnimation *snap = getDefaultAnimation();
122+ QObject::disconnect(snap, 0, 0, 0);
123+ }
124+ // turn content moving off - FIXME used later
125+// UCListItemPrivate *listItem = UCListItemPrivate::get(item);
126+// listItem->setContentMoving(false);
127+}
128+
129+/*
130+ * Returns the animation specified by the style.
131+ */
132+QQuickPropertyAnimation *UCListItemSnapAnimator::getDefaultAnimation()
133+{
134+ // FIXME - return the animation from the style
135+ return 0;
136+}
137+
138+/******************************************************************************
139 * Divider
140 */
141 UCListItemDivider::UCListItemDivider(QObject *parent)
142@@ -202,6 +326,7 @@
143 , divider(new UCListItemDivider)
144 , leadingActions(0)
145 , trailingActions(0)
146+ , animator(0)
147 {
148 }
149 UCListItemPrivate::~UCListItemPrivate()
150
151=== modified file 'modules/Ubuntu/Components/plugin/uclistitem.h'
152--- modules/Ubuntu/Components/plugin/uclistitem.h 2014-11-19 15:10:50 +0000
153+++ modules/Ubuntu/Components/plugin/uclistitem.h 2014-11-19 15:10:51 +0000
154@@ -24,6 +24,7 @@
155 class UCListItemDivider;
156 class UCListItemActions;
157 class UCListItemAttached;
158+class QQuickPropertyAnimation;
159 class UCListItemPrivate;
160 class UCListItem : public UCStyledItemBase
161 {
162
163=== modified file 'modules/Ubuntu/Components/plugin/uclistitem_p.h'
164--- modules/Ubuntu/Components/plugin/uclistitem_p.h 2014-11-19 15:10:50 +0000
165+++ modules/Ubuntu/Components/plugin/uclistitem_p.h 2014-11-19 15:10:51 +0000
166@@ -26,6 +26,7 @@
167 class UCListItemContent;
168 class UCListItemDivider;
169 class UCListItemActions;
170+class UCListItemSnapAnimator;
171 class UCListItemPrivate : public UCStyledItemBasePrivate
172 {
173 Q_DECLARE_PUBLIC(UCListItem)
174@@ -63,10 +64,13 @@
175 UCListItemDivider *divider;
176 UCListItemActions *leadingActions;
177 UCListItemActions *trailingActions;
178+ UCListItemSnapAnimator *animator;
179
180 // getter/setters
181 bool contentMoving() const;
182 void setContentMoving(bool moved);
183+ QQuickPropertyAnimation *snapAnimation() const;
184+ void setSnapAnimation(QQuickPropertyAnimation *animation);
185 };
186
187 class PropertyChange;
188@@ -145,4 +149,26 @@
189
190 QML_DECLARE_TYPE(UCListItemDivider)
191
192+class QQuickPropertyAnimation;
193+class UCListItemSnapAnimator : public QObject
194+{
195+ Q_OBJECT
196+public:
197+ UCListItemSnapAnimator(UCListItem *item);
198+ ~UCListItemSnapAnimator();
199+
200+ bool snap(qreal to);
201+ void complete();
202+
203+public Q_SLOTS:
204+ void snapOut();
205+ void snapIn();
206+
207+ QQuickPropertyAnimation *getDefaultAnimation();
208+
209+private:
210+ bool active;
211+ UCListItem *item;
212+};
213+
214 #endif // UCVIEWITEM_P_H

Subscribers

People subscribed via source and target branches

to all changes: