Merge lp:~zsombi/ubuntu-ui-toolkit/32-listitemactions-attached into lp:~zsombi/ubuntu-ui-toolkit/listitem-master
- 32-listitemactions-attached
- Merge into listitem-master
Status: | Merged |
---|---|
Approved by: | Zsombor Egri |
Approved revision: | 1331 |
Merged at revision: | 1269 |
Proposed branch: | lp:~zsombi/ubuntu-ui-toolkit/32-listitemactions-attached |
Merge into: | lp:~zsombi/ubuntu-ui-toolkit/listitem-master |
Prerequisite: | lp:~zsombi/ubuntu-ui-toolkit/30-options |
Diff against target: |
928 lines (+614/-69) 10 files modified
components.api (+20/-0) modules/Ubuntu/Components/plugin/plugin.pro (+2/-1) modules/Ubuntu/Components/plugin/ucaction.h (+1/-0) modules/Ubuntu/Components/plugin/uclistitem.cpp (+68/-20) modules/Ubuntu/Components/plugin/uclistitem.h (+5/-0) modules/Ubuntu/Components/plugin/uclistitem_p.h (+7/-0) modules/Ubuntu/Components/plugin/uclistitemactions.cpp (+176/-42) modules/Ubuntu/Components/plugin/uclistitemactions.h (+66/-0) modules/Ubuntu/Components/plugin/uclistitemactions_p.h (+2/-6) modules/Ubuntu/Components/plugin/uclistitemactionsattached.cpp (+267/-0) |
To merge this branch: | bzr merge lp:~zsombi/ubuntu-ui-toolkit/32-listitemactions-attached |
Related bugs: | |
Related blueprints: |
SDK: Design a new ListItem and layouts
(Undefined)
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tim Peeters | Approve | ||
Zsombor Egri | Pending | ||
Review via email: mp+240820@code.launchpad.net |
Commit message
Description of the change
Introducing ListItemActions attached properties, which will be attached automatically to action visualization panels.
- 1320. By Zsombor Egri
-
adding missing connects
Tim Peeters (tpeeters) wrote : | # |
- 1321. By Zsombor Egri
-
dragging event renamed to flicking, as dragging is planned to name a different thing; visibleActions attached property added
Zsombor Egri (zsombi) wrote : | # |
> 53 + , overshootGU(2)
>
> would overshoot(
It could. I'll move to that.
Zsombor Egri (zsombi) wrote : | # |
> > 53 + , overshootGU(2)
> >
> > would overshoot(
>
> It could. I'll move to that.
Though I woudl need slightly more code, but it's much better to use that approach.
- 1322. By Zsombor Egri
-
overshoot property fix
- 1323. By Zsombor Egri
-
API fixes
- 1324. By Zsombor Egri
-
swiping fix
Tim Peeters (tpeeters) wrote : | # |
Instead of speaking of "tugged", I'd use "swiped", or "swiped horizontally" if you want to be even more specific. "Swiping" of list items is becoming pretty common language for list items in various other softwares.
Tim Peeters (tpeeters) wrote : | # |
This is funny in the generated docs file://
Import Statement: import Ubuntu.Components 1.1
Since: Ubuntu.Components 1.2
The first one should be 1.2. But if that is difficult to fix, leave it until we release 1.2.
Tim Peeters (tpeeters) wrote : | # |
> The component is dedicated to be used in designs with static or dynamic lists (i.e. list views
> where each item's layout differs or in lists where the content is determined by a given model,
> thus each element has the same layout)
> The element does not define any specific layout, components can be placed in any ways on it.
> However, when used in list views, the content must be carefully chosen to in order to keep the
> kinetic behavior and the highest FPS possible.
That's all very abstract, I don't know what a developer can do with this information.
What about this?
The ListItem component was designed to be used in a list view. It does not define any specific layout, but while its contents can be freely chosen by the developer, care must be taken to keep the contents light in order to ensure good performance when used in long list views.
Tim Peeters (tpeeters) wrote : | # |
> The component provides two color properties which configures the item's background
> when normal or pressed.
> This can be configures through color and highlightColor properties.
configureD
highlightColor only applies when pressed? With previous list items that color was used when pressed || selected.
> void UCListItemPriva
> {
> Q_Q(UCListItem);
> highlightColor = getPaletteColor
> q->update();
> }
should this also update color?
Tim Peeters (tpeeters) wrote : | # |
> contentItem holds all components and resources declared as child to ListItem.
> Being an Item, all other properties can be accessed or altered, with the exception of some:
> 1. do not alter x, y, width or height properties as those are controlled by the ListItem
> itself when leading or trailing actions are revealed and thus will destroy your logic
> 2. never anchor left or right anchor lines as it will block revealing the actions.
Can we say never to alter x,y,width,height or the anchors? The way it is written now it leaves the option to change top and bottom anchors (which will change the height), and margins (which may mess up the visuals, for example by using negative margins).
Tim Peeters (tpeeters) wrote : | # |
> Each ListItem has a thin divider shown on the bottom of the component. This divider can be
> configured through the divider grouped property, which can configure its margins from the
> edges of the ListItem as well as its visibility.
"divider" links to ListItems.divider instead of the grouped property.
Tim Peeters (tpeeters) wrote : | # |
The documentation needs example code
Tim Peeters (tpeeters) wrote : | # |
^I was looking at the wrong MR I guess.. There is example code :)
but adding more won't hurt ;)
ListItemActions {
id: cacedActions
actions: [
copyAction, searchAction, cutAction
]
}
cacedActions == cachedActions
Tim Peeters (tpeeters) wrote : | # |
How do I enable the swiping in a list item?
I created a small test program here - https:/
It has a ListView with the new ListItems that have leading and trailing actions, but I cannot swipe to show them.
Tim Peeters (tpeeters) wrote : | # |
^ I guess they come in a later MR. But how can I test it now?
Zsombor Egri (zsombi) wrote : | # |
> Instead of speaking of "tugged", I'd use "swiped", or "swiped horizontally" if
> you want to be even more specific. "Swiping" of list items is becoming pretty
> common language for list items in various other softwares.
Fixed in revno 1325.
Zsombor Egri (zsombi) wrote : | # |
> This is funny in the generated docs file://
> toolkit/
> components-
>
>
> Import Statement: import Ubuntu.Components 1.1
> Since: Ubuntu.Components 1.2
>
>
> The first one should be 1.2. But if that is difficult to fix, leave it until
> we release 1.2.
It's a qdoc behavior we cannot really do much about. You cannot document two versions of a framework in the same set. Let's fix this once we close 1.1. Anyways, the whole documentation is under Unstable section, and we must move them outa there.
Zsombor Egri (zsombi) wrote : | # |
> > The component is dedicated to be used in designs with static or dynamic
> lists (i.e. list views
> > where each item's layout differs or in lists where the content is determined
> by a given model,
> > thus each element has the same layout)
>
> > The element does not define any specific layout, components can be placed in
> any ways on it.
> > However, when used in list views, the content must be carefully chosen to in
> order to keep the
> > kinetic behavior and the highest FPS possible.
>
> That's all very abstract, I don't know what a developer can do with this
> information.
>
> What about this?
>
> The ListItem component was designed to be used in a list view. It does not
> define any specific layout, but while its contents can be freely chosen by the
> developer, care must be taken to keep the contents light in order to ensure
> good performance when used in long list views.
Sounds indeed better. Revno 1326.
Zsombor Egri (zsombi) wrote : | # |
> > The component provides two color properties which configures the item's
> background
> > when normal or pressed.
>
> > This can be configures through color and highlightColor properties.
>
> configureD
ehh...
>
>
> highlightColor only applies when pressed? With previous list items that color
> was used when pressed || selected.
Will be applied also when selected, just did not wanted to add it here yet, will come when the selection mode will be implemented, in MR #80
>
>
>
> > void UCListItemPriva
> > {
> > Q_Q(UCListItem);
> > highlightColor = getPaletteColor
> > q->update();
> > }
>
> should this also update color?
Not yet, as the color is transparent and not themed. If we'll theme that as well, we'll have to update that as well.
Typo fix in revno 1327.
Zsombor Egri (zsombi) wrote : | # |
> > contentItem holds all components and resources declared as child to
> ListItem.
> > Being an Item, all other properties can be accessed or altered, with the
> exception of some:
>
> > 1. do not alter x, y, width or height properties as those are controlled by
> the ListItem
> > itself when leading or trailing actions are revealed and thus will destroy
> your logic
> > 2. never anchor left or right anchor lines as it will block revealing the
> actions.
>
> Can we say never to alter x,y,width,height or the anchors? The way it is
> written now it leaves the option to change top and bottom anchors (which will
> change the height), and margins (which may mess up the visuals, for example by
> using negative margins).
Is revno change 1328 any better?
Zsombor Egri (zsombi) wrote : | # |
> > Each ListItem has a thin divider shown on the bottom of the component. This
> divider can be
> > configured through the divider grouped property, which can configure its
> margins from the
> > edges of the ListItem as well as its visibility.
>
> "divider" links to ListItems.divider instead of the grouped property.
I cannot make it to link to the group property... qdoc simply doesn't take it... I fixed for now as \c. revno 1329
Zsombor Egri (zsombi) wrote : | # |
> The documentation needs example code
I did not see any reasons yet to give example code, there will be later some. Yet, the documentation is focusing on the stuff we have implemented, and these are pretty obvious. If you see the need still, let me know what examples you'd like to see.
Zsombor Egri (zsombi) wrote : | # |
> How do I enable the swiping in a list item?
>
> I created a small test program here -
> https:/
> It has a ListView with the new ListItems that have leading and trailing
> actions, but I cannot swipe to show them.
This will come in #35, there's no panel at this moment. This MR introduces the attached property, and would be too much to get the styling and the minimal panel implementation introduced.
Zsombor Egri (zsombi) wrote : | # |
> ^ I guess they come in a later MR. But how can I test it now?
Yes, as said previously. The whole logic - the final version - is done til #67. After that will come the selectionMode.
Zsombor Egri (zsombi) wrote : | # |
> > ^ I guess they come in a later MR. But how can I test it now?
>
> Yes, as said previously. The whole logic - the final version - is done til
> #67. After that will come the selectionMode.
Also, please check revno 1330, I rewrote a section in ListItemAttached main documentation, section Using with ListView.
- 1325. By Zsombor Egri
-
fixing tug->swipe
- 1326. By Zsombor Egri
-
ListItem documentation headline fixed
- 1327. By Zsombor Egri
-
small typo fix
- 1328. By Zsombor Egri
-
reformulate contentItem property access
- 1329. By Zsombor Egri
-
bad linking on divider, qdoc doesn't link to the group property
- 1330. By Zsombor Egri
-
rewrite ListItemActions section Using with ListView documentation
Tim Peeters (tpeeters) wrote : | # |
> > > void UCListItemPriva
> > > {
> > > Q_Q(UCListItem);
> > > highlightColor = getPaletteColor
> > > q->update();
> > > }
> >
> > should this also update color?
> Not yet, as the color is transparent and not themed. If we'll theme that as
> well, we'll have to update that as well.
But the developer can just set color = "red" in the ListItem code. For that you don't need to update it here? And for highlightColor, if the developer sets it to "yellow" will the function here override that?
Tim Peeters (tpeeters) wrote : | # |
> > > contentItem holds all components and resources declared as child to
> > ListItem.
> > > Being an Item, all other properties can be accessed or altered, with the
> > exception of some:
> >
> > > 1. do not alter x, y, width or height properties as those are controlled
> by
> > the ListItem
> > > itself when leading or trailing actions are revealed and thus will destroy
> > your logic
> > > 2. never anchor left or right anchor lines as it will block revealing the
> > actions.
> >
> > Can we say never to alter x,y,width,height or the anchors? The way it is
> > written now it leaves the option to change top and bottom anchors (which
> will
> > change the height), and margins (which may mess up the visuals, for example
> by
> > using negative margins).
>
> Is revno change 1328 any better?
yep :)
Tim Peeters (tpeeters) wrote : | # |
923 + // FIXME: implement snaping
snapping ;)
Tim Peeters (tpeeters) wrote : | # |
> (rebount)
rebound?
Tim Peeters (tpeeters) wrote : | # |
> On the other hand, memory consumption will increase signifficantly doe to separate panel creation
due to*
Tim Peeters (tpeeters) wrote : | # |
> > On the other hand, memory consumption will increase signifficantly doe to
> separate panel creation
>
> due to*
*significantly
Tim Peeters (tpeeters) wrote : | # |
> depending on how "badly" are the actions declared, within the ListItemActions or as shared actions.
I don't know what you mean with that sentence
Tim Peeters (tpeeters) wrote : | # |
In the new "optimized" code example, you define list<Action>:... Why not pre-define the full ListItemActions that you re-use in all of that ListItems? That is what you describe above to save memory. Perhaps you can say that with the code you show you do not have the disadvantages of that method
Zsombor Egri (zsombi) wrote : | # |
>
> > > > void UCListItemPriva
> > > > {
> > > > Q_Q(UCListItem);
> > > > highlightColor = getPaletteColor
> > > > q->update();
> > > > }
> > >
> > > should this also update color?
> > Not yet, as the color is transparent and not themed. If we'll theme that as
> > well, we'll have to update that as well.
>
> But the developer can just set color = "red" in the ListItem code. For that
> you don't need to update it here? And for highlightColor, if the developer
> sets it to "yellow" will the function here override that?
If the user changes the color, that won't be subject of theming update, right? This function does the theming update. If the hightlightColor will be set to any color different than the "stock" color (theme color), that will also be omitted. See setHighlightColor, where we disconnect the slot.
Zsombor Egri (zsombi) wrote : | # |
> 923 + // FIXME: implement snaping
>
> snapping ;)
Won't bother, will be removed in #35
Tim Peeters (tpeeters) wrote : | # |
I think for the ListItemActions docs, we can have a section
*potential pitfalls* where you give two (short) code examples how it should not be done and say why it is wrong. Then we can give the *recommended solution* with a short code example.
Zsombor Egri (zsombi) wrote : | # |
> > depending on how "badly" are the actions declared, within the
> ListItemActions or as shared actions.
>
>
> I don't know what you mean with that sentence
Reformulated.
Zsombor Egri (zsombi) wrote : | # |
> In the new "optimized" code example, you define list<Action>:... Why not pre-
> define the full ListItemActions that you re-use in all of that ListItems? That
> is what you describe above to save memory. Perhaps you can say that with the
> code you show you do not have the disadvantages of that method
In the paragraph I was talking about a more responsive UI. That one requires to have separate ListItemActions instances per ListItem.
- 1331. By Zsombor Egri
-
review comments applied
- 1332. By Zsombor Egri
-
prereq sync
Preview Diff
1 | === modified file 'components.api' |
2 | --- components.api 2014-11-19 15:10:15 +0000 |
3 | +++ components.api 2014-11-19 15:10:18 +0000 |
4 | @@ -871,17 +871,37 @@ |
5 | Property { name: "leadingActions"; type: "UCListItemActions"; isPointer: true } |
6 | Property { name: "trailingActions"; type: "UCListItemActions"; isPointer: true } |
7 | Property { name: "pressed"; type: "bool"; isReadonly: true } |
8 | + Property { name: "contentMoving"; type: "bool"; isReadonly: true } |
9 | Property { name: "color"; type: "QColor" } |
10 | Property { name: "highlightColor"; type: "QColor" } |
11 | Property { name: "data"; type: "QObject"; isList: true; isReadonly: true } |
12 | Property { name: "children"; type: "QQuickItem"; isList: true; isReadonly: true } |
13 | Signal { name: "clicked" } |
14 | + Signal { name: "contentMovementStarted" } |
15 | + Signal { name: "contentMovementEnded" } |
16 | name: "UCListItemActions" |
17 | prototype: "QObject" |
18 | exports: ["ListItemActions 1.2"] |
19 | + name: "Status" |
20 | Property { name: "delegate"; type: "QQmlComponent"; isPointer: true } |
21 | Property { name: "actions"; type: "UCAction"; isList: true; isReadonly: true } |
22 | Property { name: "data"; type: "QObject"; isList: true; isReadonly: true } |
23 | + Signal { |
24 | + name: "statusChanged" |
25 | + Parameter { name: "status"; type: "Status" } |
26 | + name: "UCListItemActionsAttached" |
27 | + prototype: "QObject" |
28 | + Property { name: "container"; type: "UCListItemActions"; isReadonly: true; isPointer: true } |
29 | + Property { name: "visibleActions"; type: "UCAction"; isList: true; isReadonly: true } |
30 | + Property { name: "listItem"; type: "UCListItem"; isReadonly: true; isPointer: true } |
31 | + Property { name: "listItemIndex"; type: "int"; isReadonly: true } |
32 | + Property { name: "offset"; type: "double"; isReadonly: true } |
33 | + Property { name: "status"; type: "UCListItemActions::Status"; isReadonly: true } |
34 | + Property { name: "swiping"; type: "bool"; isReadonly: true } |
35 | + Property { name: "overshoot"; type: "double"; isReadonly: true } |
36 | + Method { |
37 | + name: "snapToPosition" |
38 | + Parameter { name: "position"; type: "double" } |
39 | name: "UCListItemDivider" |
40 | prototype: "QObject" |
41 | Property { name: "visible"; type: "bool" } |
42 | |
43 | === modified file 'modules/Ubuntu/Components/plugin/plugin.pro' |
44 | --- modules/Ubuntu/Components/plugin/plugin.pro 2014-11-19 15:10:15 +0000 |
45 | +++ modules/Ubuntu/Components/plugin/plugin.pro 2014-11-19 15:10:18 +0000 |
46 | @@ -111,7 +111,8 @@ |
47 | ucactionmanager.cpp \ |
48 | adapters/actionsproxy_p.cpp \ |
49 | uclistitem.cpp \ |
50 | - uclistitemactions.cpp |
51 | + uclistitemactions.cpp \ |
52 | + uclistitemactionsattached.cpp |
53 | |
54 | # adapters |
55 | SOURCES += adapters/alarmsadapter_organizer.cpp |
56 | |
57 | === modified file 'modules/Ubuntu/Components/plugin/ucaction.h' |
58 | --- modules/Ubuntu/Components/plugin/ucaction.h 2014-09-01 06:56:39 +0000 |
59 | +++ modules/Ubuntu/Components/plugin/ucaction.h 2014-11-19 15:10:18 +0000 |
60 | @@ -87,6 +87,7 @@ |
61 | Type m_parameterType; |
62 | |
63 | friend class UCActionContext; |
64 | + friend class UCListItemActionsAttached; |
65 | |
66 | bool isValidType(QVariant::Type valueType); |
67 | void generateName(); |
68 | |
69 | === modified file 'modules/Ubuntu/Components/plugin/uclistitem.cpp' |
70 | --- modules/Ubuntu/Components/plugin/uclistitem.cpp 2014-11-19 15:10:15 +0000 |
71 | +++ modules/Ubuntu/Components/plugin/uclistitem.cpp 2014-11-19 15:10:18 +0000 |
72 | @@ -191,7 +191,10 @@ |
73 | UCListItemPrivate::UCListItemPrivate() |
74 | : UCStyledItemBasePrivate() |
75 | , pressed(false) |
76 | + , contentMoved(false) |
77 | , highlightColorChanged(false) |
78 | + , ready(false) |
79 | + , overshoot(UCUnits::instance().gu(2)) |
80 | , color(Qt::transparent) |
81 | , highlightColor(Qt::transparent) |
82 | , contentItem(new QQuickItem) |
83 | @@ -249,6 +252,21 @@ |
84 | QQuickItem *owner = flickable ? flickable : parentItem; |
85 | q->setImplicitWidth(owner ? owner->width() : UCUnits::instance().gu(40)); |
86 | q->setImplicitHeight(UCUnits::instance().gu(7)); |
87 | + // update overshoot value |
88 | + overshoot = UCUnits::instance().gu(2); |
89 | +} |
90 | + |
91 | +// returns the index of the list item when used in model driven views, |
92 | +// and the child index in other cases |
93 | +int UCListItemPrivate::index() |
94 | +{ |
95 | + Q_Q(UCListItem); |
96 | + // is there an index context property? |
97 | + QQmlContext *context = qmlContext(q); |
98 | + QVariant index = context->contextProperty("index"); |
99 | + return index.isValid() ? |
100 | + index.toInt() : |
101 | + (parentItem ? QQuickItemPrivate::get(parentItem)->childItems.indexOf(q) : -1); |
102 | } |
103 | |
104 | // set pressed flag and update contentItem |
105 | @@ -303,30 +321,23 @@ |
106 | * \since Ubuntu.Components 1.2 |
107 | * \brief The ListItem element provides Ubuntu design standards for list or grid |
108 | * views. |
109 | - * |
110 | - * The component is dedicated to be used in designs with static or dynamic lists |
111 | - * (i.e. list views where each item's layout differs or in lists where the content |
112 | - * is determined by a given model, thus each element has the same layout). The |
113 | - * element does not define any specific layout, components can be placed in any |
114 | - * ways on it. However, when used in list views, the content must be carefully |
115 | - * chosen to in order to keep the kinetic behavior and the highest FPS possible. |
116 | + * The ListItem component was designed to be used in a list view. It does not |
117 | + * define any specific layout, but while its contents can be freely chosen by |
118 | + * the developer, care must be taken to keep the contents light in order to ensure |
119 | + * good performance when used in long list views. |
120 | * |
121 | * The component provides two color properties which configures the item's background |
122 | - * when normal or pressed. This can be configures through \l color and \l highlightColor |
123 | + * when normal or pressed. This can be configured through \l color and \l highlightColor |
124 | * properties. |
125 | * |
126 | * \c contentItem holds all components and resources declared as child to ListItem. |
127 | - * Being an Item, all other properties can be accessed or altered, with the exception |
128 | - * of some: |
129 | - * \list A |
130 | - * \li do not alter \c x, \c y, \c width or \c height properties as those are |
131 | - * controlled by the ListItem itself when leading or trailing actions are |
132 | - * revealed and thus will destroy your logic |
133 | - * \li never anchor left or right anchor lines as it will block revealing the actions. |
134 | - * \endlist |
135 | + * Being an Item, all properties can be accessed or altered. However, make sure you |
136 | + * never change \c x, \c y, \c width, \c height or \c anchors properties as those are |
137 | + * controlled by the ListItem itself when leading or trailing actions are revealed |
138 | + * and thus might cause the component to misbehave. |
139 | * |
140 | * Each ListItem has a thin divider shown on the bottom of the component. This |
141 | - * divider can be configured through the \l divider grouped property, which can |
142 | + * divider can be configured through the \c divider grouped property, which can |
143 | * configure its margins from the edges of the ListItem as well as its visibility. |
144 | */ |
145 | |
146 | @@ -334,7 +345,7 @@ |
147 | * \qmlsignal ListItem::clicked() |
148 | * |
149 | * The signal is emitted when the component gets released while the \l pressed property |
150 | - * is set. The signal is not emitted if the ListItem content is tugged or when used in |
151 | + * is set. The signal is not emitted if the ListItem content is swiped or when used in |
152 | * Flickable (or ListView, GridView) and the Flickable gets moved. |
153 | */ |
154 | UCListItem::UCListItem(QQuickItem *parent) |
155 | @@ -516,8 +527,8 @@ |
156 | * |
157 | * This grouped property configures the thin divider shown in the bottom of the |
158 | * component. Configures the visibility and the margins from the left and right |
159 | - * of the ListItem. When tugged (swiped left or right to reveal the actions), |
160 | - * it is not moved together with the content. \c colorFrom and \c colorTo configure |
161 | + * of the ListItem. When swiped left or right to reveal the actions, it is not |
162 | + * moved together with the content. \c colorFrom and \c colorTo configure |
163 | * the starting and ending colors of the divider. |
164 | * |
165 | * When \c visible is true, the ListItem's content size gets thinner with the |
166 | @@ -550,6 +561,43 @@ |
167 | } |
168 | |
169 | /*! |
170 | + * \qmlproperty bool ListItem::contentMoving |
171 | + * \readonly |
172 | + * The property describes whether the content is moving or not. The content is |
173 | + * moved when swiped or when snapping in or out, and lasts till the snapping |
174 | + * animation completes. |
175 | + */ |
176 | + |
177 | +/*! |
178 | + * \qmlsignal ListItem::contentMovementStarted() |
179 | + * The signal is emitted when the content movement has started. |
180 | + */ |
181 | + |
182 | +/*! |
183 | + * \qmlsignal UCListItemPrivate::contentMovementEnded |
184 | + * The signal is emitted when the content movement has ended. |
185 | + */ |
186 | +bool UCListItemPrivate::contentMoving() const |
187 | +{ |
188 | + return contentMoved; |
189 | +} |
190 | +void UCListItemPrivate::setContentMoving(bool moved) |
191 | +{ |
192 | + if (contentMoved == moved) { |
193 | + return; |
194 | + } |
195 | + contentMoved = moved; |
196 | + Q_Q(UCListItem); |
197 | + if (contentMoved) { |
198 | + Q_EMIT q->contentMovementStarted(); |
199 | + } else { |
200 | + Q_EMIT q->contentMovementEnded(); |
201 | + } |
202 | + Q_EMIT q->contentMovingChanged(); |
203 | + |
204 | +} |
205 | + |
206 | +/*! |
207 | * \qmlproperty color ListItem::color |
208 | * Configures the color of the normal background. The default value is transparent. |
209 | */ |
210 | |
211 | === modified file 'modules/Ubuntu/Components/plugin/uclistitem.h' |
212 | --- modules/Ubuntu/Components/plugin/uclistitem.h 2014-11-19 15:10:15 +0000 |
213 | +++ modules/Ubuntu/Components/plugin/uclistitem.h 2014-11-19 15:10:18 +0000 |
214 | @@ -32,6 +32,7 @@ |
215 | Q_PROPERTY(UCListItemActions *leadingActions READ leadingActions WRITE setLeadingActions NOTIFY leadingActionsChanged DESIGNABLE false) |
216 | Q_PROPERTY(UCListItemActions *trailingActions READ trailingActions WRITE setTrailingActions NOTIFY trailingActionsChanged DESIGNABLE false) |
217 | Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged) |
218 | + Q_PRIVATE_PROPERTY(UCListItem::d_func(), bool contentMoving READ contentMoving NOTIFY contentMovingChanged) |
219 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
220 | Q_PROPERTY(QColor highlightColor READ highlightColor WRITE setHighlightColor NOTIFY highlightColorChanged) |
221 | Q_PROPERTY(QQmlListProperty<QObject> data READ data DESIGNABLE false) |
222 | @@ -65,12 +66,16 @@ |
223 | void leadingActionsChanged(); |
224 | void trailingActionsChanged(); |
225 | void pressedChanged(); |
226 | + void contentMovingChanged(); |
227 | void colorChanged(); |
228 | void highlightColorChanged(); |
229 | void childrenChanged(); |
230 | |
231 | void clicked(); |
232 | |
233 | + void contentMovementStarted(); |
234 | + void contentMovementEnded(); |
235 | + |
236 | public Q_SLOTS: |
237 | |
238 | private: |
239 | |
240 | === modified file 'modules/Ubuntu/Components/plugin/uclistitem_p.h' |
241 | --- modules/Ubuntu/Components/plugin/uclistitem_p.h 2014-11-19 15:10:15 +0000 |
242 | +++ modules/Ubuntu/Components/plugin/uclistitem_p.h 2014-11-19 15:10:18 +0000 |
243 | @@ -43,14 +43,17 @@ |
244 | void _q_updateColors(); |
245 | void _q_rebound(); |
246 | void _q_updateSize(); |
247 | + int index(); |
248 | void setPressed(bool pressed); |
249 | void listenToRebind(bool listen); |
250 | void resize(); |
251 | void update(); |
252 | |
253 | bool pressed:1; |
254 | + bool contentMoved:1; |
255 | bool highlightColorChanged:1; |
256 | bool ready:1; |
257 | + qreal overshoot; |
258 | QColor color; |
259 | QColor highlightColor; |
260 | QPointer<QQuickFlickable> flickable; |
261 | @@ -58,6 +61,10 @@ |
262 | UCListItemDivider *divider; |
263 | UCListItemActions *leadingActions; |
264 | UCListItemActions *trailingActions; |
265 | + |
266 | + // getter/setters |
267 | + bool contentMoving() const; |
268 | + void setContentMoving(bool moved); |
269 | }; |
270 | |
271 | class UCListItemDivider : public QObject |
272 | |
273 | === modified file 'modules/Ubuntu/Components/plugin/uclistitemactions.cpp' |
274 | --- modules/Ubuntu/Components/plugin/uclistitemactions.cpp 2014-11-19 15:10:15 +0000 |
275 | +++ modules/Ubuntu/Components/plugin/uclistitemactions.cpp 2014-11-19 15:10:18 +0000 |
276 | @@ -23,6 +23,8 @@ |
277 | |
278 | UCListItemActionsPrivate::UCListItemActionsPrivate() |
279 | : QObjectPrivate() |
280 | + , status(UCListItemActions::Disconnected) |
281 | + , offsetDragged(0) |
282 | , delegate(0) |
283 | , panelItem(0) |
284 | { |
285 | @@ -31,6 +33,7 @@ |
286 | { |
287 | } |
288 | |
289 | +// FIXME - fis ListItemStyle::snapAnimation to a link when property available |
290 | /*! |
291 | * \qmltype ListItemActions |
292 | * \instantiates UCListItemActions |
293 | @@ -40,7 +43,7 @@ |
294 | * \ingroup unstable-ubuntu-listitems |
295 | * \brief Provides configuration for actions to be added to a ListItem. |
296 | * |
297 | - * ListItem accepts actions that can be configured to appear when tugged to left |
298 | + * ListItem accepts actions that can be configured to appear when swiped to left |
299 | * or right. The API does not limit the number of actions to be assigned for leading |
300 | * or trailing actions, however the design constrains are allowing a maximum of |
301 | * 1 action on leading- and a maximum of 3 actions on trailing side of the ListItem. |
302 | @@ -53,46 +56,155 @@ |
303 | * the first time the actions are accessed. The colors of the panel is taken from |
304 | * the theme's palette. |
305 | * |
306 | - * When tugged, panels reveal the actions one by one. In case an option is revealed |
307 | - * more than 50%, the option will be snapped and revealed completely. This is also |
308 | - * valid for the case when the option is visibl eless than 50%, in which case the |
309 | - * option is hidden. Actions can be triggered by tapping. |
310 | - * |
311 | - * \section3 Notes on performance |
312 | - * When used with views, or when the amount of items of same kind to be created |
313 | - * is huge, it is recommended to use cached actions as well as cached ListItemActions |
314 | - * instances. In this way we can reduce the creation time of the items: |
315 | - * \qml |
316 | - * import QtQuick 2.2 |
317 | - * import Ubuntu.Components 1.2 |
318 | - * |
319 | - * MainView { |
320 | - * width: units.gu(40) |
321 | - * height: units.gu(71) |
322 | - * |
323 | - * UbuntuListView { |
324 | - * anchors.fill: parent |
325 | - * model: 10000 |
326 | - * ListItemActions { |
327 | - * id: commonActions |
328 | - * actions: [ |
329 | - * Action { |
330 | - * iconName: "search" |
331 | - * }, |
332 | - * Action { |
333 | - * iconName: "edit" |
334 | - * }, |
335 | - * Action { |
336 | - * iconName: "copy" |
337 | - * } |
338 | - * ] |
339 | - * } |
340 | - * delegate: ListItem { |
341 | - * trailingActions: commonActions |
342 | - * } |
343 | - * } |
344 | - * } |
345 | - * \endqml |
346 | + * When swiped, panels reveal the actions one by one. In case an action is revealed |
347 | + * more than 50%, the action will be snapped and revealed completely. This is also |
348 | + * valid for the case when the action is visible less than 50%, in which case the |
349 | + * action is hidden. Actions can be triggered by tapping. |
350 | + * |
351 | + * \note You can use the same ListItemActions for leading and for trailing actions |
352 | + * the same time only if the instance is used by different groups of list items, |
353 | + * where one group uses it as leading and other group as trailing. In any other |
354 | + * circumstances use separate ListItemActions for leading and trailing actions. |
355 | + * \qml |
356 | + * import QtQuick 2.2 |
357 | + * import Ubuntu.Components 1.2 |
358 | + * MainView { |
359 | + * width: units.gu(40) |
360 | + * height: units.gu(71) |
361 | + * |
362 | + * ListItemActions { |
363 | + * id: sharedActions |
364 | + * actions: [ |
365 | + * Action { |
366 | + * iconName: "search" |
367 | + * }, |
368 | + * Action { |
369 | + * iconName: "edit" |
370 | + * }, |
371 | + * Action { |
372 | + * iconName: "copy" |
373 | + * } |
374 | + * ] |
375 | + * } |
376 | + * |
377 | + * Column { |
378 | + * ListItem { |
379 | + * leadingActions: sharedActions |
380 | + * } |
381 | + * UbuntuListView { |
382 | + * anchors.fill: parent |
383 | + * model: 10000 |
384 | + * delegate: ListItem { |
385 | + * trailingActions: sharedActions |
386 | + * } |
387 | + * } |
388 | + * } |
389 | + * } |
390 | + * \endqml |
391 | + * |
392 | + * \section3 Using with ListViews |
393 | + * ListItemActions instances can be shared between ListItem instances within the |
394 | + * same view. When shared, the memory footprint of the view will be lot smaller, |
395 | + * as there will be no individual panel created for each list's actions visualization. |
396 | + * Depending on how long the initialization of the component used in \c ListItem::actionsDelegate |
397 | + * takes, creation time will be also reduced to one time per view. |
398 | + * However, this implies that swiping a new ListItem content while another one is |
399 | + * swiped will result in showing the newly swiped item's panel delayed, as the |
400 | + * panel can be shown only after the previous item's snapping is completed. Depending |
401 | + * on the \c ListItemStyle::snapAnimation duration, this may take some time, and the |
402 | + * response time of the UI can become unacceptable. |
403 | + * |
404 | + * Having individual ListItemActions instances increases the memory footprint, |
405 | + * however the UI will be more responsive as swiping individual ListItems will |
406 | + * not have to wait till the previous ListItem's panel is snapped out (rebound). |
407 | + * On the other hand, memory consumption will increase significantly due to |
408 | + * separate panel creation, and performance may decrease with up to 40%, depending |
409 | + * on what way are the actions declared, within the ListItemActions or as shared |
410 | + * actions. |
411 | + * |
412 | + * The example above illustrates how to share ListItemActions between ListItem |
413 | + * delegates, which can be the worst-performant but most lightwaight memory consumer |
414 | + * setup. The following example illustrates the worst case: |
415 | + * \qml |
416 | + * import QtQuick 2.2 |
417 | + * import Ubuntu.Components 1.2 |
418 | + * MainView { |
419 | + * width: units.gu(40) |
420 | + * height: units.gu(71) |
421 | + * |
422 | + * UbuntuListView { |
423 | + * anchors.fill: parent |
424 | + * model: 10000 |
425 | + * delegate: ListItem { |
426 | + * leadingActions: ListItemActions { |
427 | + * actions: [ |
428 | + * Action { |
429 | + * iconName: "delete" |
430 | + * } |
431 | + * ] |
432 | + * } |
433 | + * trailingActions: ListItemActions { |
434 | + * actions: [ |
435 | + * Action { |
436 | + * iconName: "search" |
437 | + * }, |
438 | + * Action { |
439 | + * iconName: "edit" |
440 | + * }, |
441 | + * Action { |
442 | + * iconName: "copy" |
443 | + * } |
444 | + * ] |
445 | + * } |
446 | + * } |
447 | + * } |
448 | + * } |
449 | + * \endqml |
450 | + * |
451 | + * This example can be optimized by sharing the action arrays between the items: |
452 | + * \qml |
453 | + * import QtQuick 2.2 |
454 | + * import Ubuntu.Components 1.2 |
455 | + * MainView { |
456 | + * width: units.gu(40) |
457 | + * height: units.gu(71) |
458 | + * |
459 | + * property list<Action> leading: [ |
460 | + * Action { |
461 | + * iconName: "delete" |
462 | + * } |
463 | + * ] |
464 | + * property list<Action> trailing: [ |
465 | + * Action { |
466 | + * iconName: "search" |
467 | + * }, |
468 | + * Action { |
469 | + * iconName: "edit" |
470 | + * }, |
471 | + * Action { |
472 | + * iconName: "copy" |
473 | + * } |
474 | + * ] |
475 | + * |
476 | + * UbuntuListView { |
477 | + * anchors.fill: parent |
478 | + * model: 10000 |
479 | + * delegate: ListItem { |
480 | + * leadingActions: ListItemActions { |
481 | + * actions: leading |
482 | + * } |
483 | + * trailingActions: ListItemActions { |
484 | + * actions: trailing |
485 | + * } |
486 | + * } |
487 | + * } |
488 | + * } |
489 | + * \endqml |
490 | + * |
491 | + * \section3 Attached properties |
492 | + * ListItemActions provides a set of attached properties to the panels visualizing |
493 | + * the actions. These properties can be used by implementations visualizing the |
494 | + * actions. |
495 | */ |
496 | |
497 | UCListItemActions::UCListItemActions(QObject *parent) |
498 | @@ -103,6 +215,28 @@ |
499 | { |
500 | } |
501 | |
502 | +UCListItemActionsAttached *UCListItemActions::qmlAttachedProperties(QObject *owner) |
503 | +{ |
504 | + /* |
505 | + * Detect the attachee, whether is it a child item of the panelItem. The panelItem |
506 | + * itself cannot be detected, as the object can be attached during the call of |
507 | + * component.beginCreate(). |
508 | + */ |
509 | + UCListItemActionsAttached *attached = new UCListItemActionsAttached(owner); |
510 | + QQuickItem *item = qobject_cast<QQuickItem*>(owner); |
511 | + while (item) { |
512 | + // has item our attached property? |
513 | + UCListItemActionsAttached *itemAttached = static_cast<UCListItemActionsAttached*>( |
514 | + qmlAttachedPropertiesObject<UCListItemActions>(item, false)); |
515 | + if (itemAttached) { |
516 | + attached->setList(itemAttached->container()); |
517 | + break; |
518 | + } |
519 | + item = item->parentItem(); |
520 | + } |
521 | + return attached; |
522 | +} |
523 | + |
524 | /*! |
525 | * \qmlproperty Component ListItemActions::delegate |
526 | * Custom delegate which overrides the default one used by the ListItem. If the |
527 | @@ -132,7 +266,7 @@ |
528 | * declared in place. An example of cached actions: |
529 | * \qml |
530 | * ListItemActions { |
531 | - * id: cacedActions |
532 | + * id: cachedActions |
533 | * actions: [ |
534 | * copyAction, searchAction, cutAction |
535 | * ] |
536 | |
537 | === modified file 'modules/Ubuntu/Components/plugin/uclistitemactions.h' |
538 | --- modules/Ubuntu/Components/plugin/uclistitemactions.h 2014-11-19 15:10:15 +0000 |
539 | +++ modules/Ubuntu/Components/plugin/uclistitemactions.h 2014-11-19 15:10:18 +0000 |
540 | @@ -22,6 +22,7 @@ |
541 | |
542 | class QQmlComponent; |
543 | class UCAction; |
544 | +class UCListItemActionsAttached; |
545 | class UCListItemActionsPrivate; |
546 | class UCListItemActions : public QObject |
547 | { |
548 | @@ -30,10 +31,18 @@ |
549 | Q_PROPERTY(QQmlListProperty<UCAction> actions READ actions CONSTANT) |
550 | Q_PROPERTY(QQmlListProperty<QObject> data READ data) |
551 | Q_CLASSINFO("DefaultProperty", "data") |
552 | + Q_ENUMS(Status) |
553 | public: |
554 | + enum Status { |
555 | + Disconnected, |
556 | + Leading, |
557 | + Trailing |
558 | + }; |
559 | explicit UCListItemActions(QObject *parent = 0); |
560 | ~UCListItemActions(); |
561 | |
562 | + static UCListItemActionsAttached *qmlAttachedProperties(QObject *owner); |
563 | + |
564 | QQmlComponent *delegate() const; |
565 | void setDelegate(QQmlComponent *delegate); |
566 | QQmlListProperty<UCAction> actions(); |
567 | @@ -41,9 +50,66 @@ |
568 | |
569 | Q_SIGNALS: |
570 | void delegateChanged(); |
571 | + void statusChanged(Status status); |
572 | |
573 | private: |
574 | Q_DECLARE_PRIVATE(UCListItemActions) |
575 | }; |
576 | |
577 | +class UCListItemActionsAttached : public QObject |
578 | +{ |
579 | + Q_OBJECT |
580 | + Q_PROPERTY(UCListItemActions *container READ container NOTIFY containerChanged) |
581 | + Q_PROPERTY(QQmlListProperty<UCAction> visibleActions READ visibleActions NOTIFY visibleActionsChanged) |
582 | + Q_PROPERTY(UCListItem *listItem READ listItem NOTIFY listItemChanged) |
583 | + Q_PROPERTY(int listItemIndex READ listItemIndex NOTIFY listItemIndexChanged) |
584 | + Q_PROPERTY(qreal offset READ offset NOTIFY offsetChanged) |
585 | + Q_PROPERTY(UCListItemActions::Status status READ status NOTIFY statusChanged) |
586 | + Q_PROPERTY(bool swiping READ swiping NOTIFY swipingChanged) |
587 | + Q_PROPERTY(qreal overshoot READ overshoot NOTIFY overshootChanged) |
588 | +public: |
589 | + UCListItemActionsAttached(QObject *parent = 0); |
590 | + ~UCListItemActionsAttached(); |
591 | + void setList(UCListItemActions *list); |
592 | + void connectListItem(UCListItem *item, bool connect); |
593 | + |
594 | + UCListItemActions *container() const |
595 | + { |
596 | + return m_container.data(); |
597 | + } |
598 | + QQmlListProperty<UCAction> visibleActions(); |
599 | + UCListItem *listItem(); |
600 | + int listItemIndex(); |
601 | + bool swiping(); |
602 | + qreal offset(); |
603 | + UCListItemActions::Status status(); |
604 | + qreal overshoot(); |
605 | + |
606 | + |
607 | +public Q_SLOTS: |
608 | + void snapToPosition(qreal position); |
609 | + |
610 | +Q_SIGNALS: |
611 | + void containerChanged(); |
612 | + void visibleActionsChanged(); |
613 | + void listItemChanged(); |
614 | + void listItemIndexChanged(); |
615 | + void offsetChanged(); |
616 | + void statusChanged(); |
617 | + void swipingChanged(); |
618 | + void overshootChanged(); |
619 | + |
620 | +private: |
621 | + QPointer<UCListItemActions> m_container; |
622 | + QList<UCAction*> m_visibleActions; |
623 | + bool m_swiping; |
624 | + friend class UCListItemAction; |
625 | + |
626 | +private Q_SLOTS: |
627 | + void updateVisibleActions(); |
628 | + void updateSwipeState(); |
629 | +}; |
630 | + |
631 | +QML_DECLARE_TYPEINFO(UCListItemActions, QML_HAS_ATTACHED_PROPERTIES) |
632 | + |
633 | #endif // UCLISTITEMACTIONS_H |
634 | |
635 | === modified file 'modules/Ubuntu/Components/plugin/uclistitemactions_p.h' |
636 | --- modules/Ubuntu/Components/plugin/uclistitemactions_p.h 2014-11-19 15:10:15 +0000 |
637 | +++ modules/Ubuntu/Components/plugin/uclistitemactions_p.h 2014-11-19 15:10:18 +0000 |
638 | @@ -31,16 +31,12 @@ |
639 | return actions->d_func(); |
640 | } |
641 | |
642 | + UCListItemActions::Status status; |
643 | + qreal offsetDragged; |
644 | QQmlComponent *delegate; |
645 | QQuickItem *panelItem; |
646 | QList<UCAction*> actions; |
647 | QList<QObject*> data; |
648 | - |
649 | - // options list property functions |
650 | - static void funcAppend(QQmlListProperty<UCAction>*, UCAction*); |
651 | - static int funcCount(QQmlListProperty<UCAction>*); |
652 | - static QObject *funcAt(QQmlListProperty<UCAction>*, int); |
653 | - static void funcClear(QQmlListProperty<UCAction>*); |
654 | }; |
655 | |
656 | #endif // UCLISTITEMACTIONS_P_H |
657 | |
658 | === added file 'modules/Ubuntu/Components/plugin/uclistitemactionsattached.cpp' |
659 | --- modules/Ubuntu/Components/plugin/uclistitemactionsattached.cpp 1970-01-01 00:00:00 +0000 |
660 | +++ modules/Ubuntu/Components/plugin/uclistitemactionsattached.cpp 2014-11-19 15:10:18 +0000 |
661 | @@ -0,0 +1,267 @@ |
662 | +/* |
663 | + * Copyright 2014 Canonical Ltd. |
664 | + * |
665 | + * This program is free software; you can redistribute it and/or modify |
666 | + * it under the terms of the GNU Lesser General Public License as published by |
667 | + * the Free Software Foundation; version 3. |
668 | + * |
669 | + * This program is distributed in the hope that it will be useful, |
670 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
671 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
672 | + * GNU Lesser General Public License for more details. |
673 | + * |
674 | + * You should have received a copy of the GNU Lesser General Public License |
675 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
676 | + */ |
677 | + |
678 | +#include "uclistitem.h" |
679 | +#include "uclistitem_p.h" |
680 | +#include "uclistitemactions.h" |
681 | +#include "uclistitemactions_p.h" |
682 | +#include "ucunits.h" |
683 | +#include "ucaction.h" |
684 | + |
685 | +UCListItemActionsAttached::UCListItemActionsAttached(QObject *parent) |
686 | + : QObject(parent) |
687 | + , m_swiping(false) |
688 | +{ |
689 | +} |
690 | + |
691 | +UCListItemActionsAttached::~UCListItemActionsAttached() |
692 | +{ |
693 | +} |
694 | + |
695 | +/*! |
696 | + * \qmlattachedproperty ListItemActions ListItemActions::container |
697 | + * \readonly |
698 | + * The property holds the instance of the \l ListItemActions the ListItem's actions |
699 | + * panel is visualizing. |
700 | + */ |
701 | +void UCListItemActionsAttached::setList(UCListItemActions *list) |
702 | +{ |
703 | + if (list == m_container) { |
704 | + return; |
705 | + } |
706 | + m_container = list; |
707 | + if (!m_container.isNull()) { |
708 | + // connect statusChanged() to update status, listItem, listItemIndex and overshoot values |
709 | + QObject::connect(m_container.data(), &UCListItemActions::statusChanged, |
710 | + this, &UCListItemActionsAttached::statusChanged); |
711 | + QObject::connect(m_container.data(), &UCListItemActions::statusChanged, |
712 | + this, &UCListItemActionsAttached::listItemChanged); |
713 | + QObject::connect(m_container.data(), &UCListItemActions::statusChanged, |
714 | + this, &UCListItemActionsAttached::listItemIndexChanged); |
715 | + QObject::connect(m_container.data(), &UCListItemActions::statusChanged, |
716 | + this, &UCListItemActionsAttached::overshootChanged); |
717 | + |
718 | + UCListItemActionsPrivate *actions = UCListItemActionsPrivate::get(m_container.data()); |
719 | + // connect panel's xChanged to update the dragged offset |
720 | + QObject::connect(actions->panelItem, &QQuickItem::xChanged, |
721 | + this, &UCListItemActionsAttached::offsetChanged); |
722 | + |
723 | + // connect actions to get updates about visible changes |
724 | + Q_FOREACH(UCAction *action, UCListItemActionsPrivate::get(m_container)->actions) { |
725 | + QObject::connect(action, &UCAction::visibleChanged, |
726 | + this, &UCListItemActionsAttached::updateVisibleActions); |
727 | + } |
728 | + } |
729 | + Q_EMIT containerChanged(); |
730 | + Q_EMIT visibleActionsChanged(); |
731 | +} |
732 | + |
733 | +void UCListItemActionsAttached::connectListItem(UCListItem *item, bool connect) |
734 | +{ |
735 | + if (!item) { |
736 | + return; |
737 | + } |
738 | + if (connect) { |
739 | + QObject::connect(item, &UCListItem::pressedChanged, |
740 | + this, &UCListItemActionsAttached::updateSwipeState); |
741 | + QObject::connect(item, &UCListItem::contentMovingChanged, |
742 | + this, &UCListItemActionsAttached::updateSwipeState); |
743 | + } else { |
744 | + QObject::disconnect(item, &UCListItem::pressedChanged, |
745 | + this, &UCListItemActionsAttached::updateSwipeState); |
746 | + QObject::disconnect(item, &UCListItem::contentMovingChanged, |
747 | + this, &UCListItemActionsAttached::updateSwipeState); |
748 | + } |
749 | +} |
750 | + |
751 | +// private slot to update visible actions |
752 | +void UCListItemActionsAttached::updateVisibleActions() |
753 | +{ |
754 | + m_visibleActions.clear(); |
755 | + if (!m_container.isNull()) { |
756 | + Q_FOREACH(UCAction *action, UCListItemActionsPrivate::get(m_container)->actions) { |
757 | + if (action->m_visible) { |
758 | + m_visibleActions << action; |
759 | + } |
760 | + } |
761 | + } |
762 | + Q_EMIT visibleActionsChanged(); |
763 | +} |
764 | + |
765 | +// private slot updating swipe state |
766 | +void UCListItemActionsAttached::updateSwipeState() |
767 | +{ |
768 | + if (m_container.isNull()) { |
769 | + return; |
770 | + } |
771 | + QQuickItem *panelItem = UCListItemActionsPrivate::get(m_container)->panelItem; |
772 | + if (!panelItem || !panelItem->parentItem()) { |
773 | + return; |
774 | + } |
775 | + UCListItem *item = static_cast<UCListItem*>(panelItem->parentItem()); |
776 | + UCListItemPrivate *listItem = UCListItemPrivate::get(item); |
777 | + bool swiped = listItem->pressed && listItem->contentMoved; |
778 | + if (swiped != m_swiping) { |
779 | + m_swiping = swiped; |
780 | + Q_EMIT swipingChanged(); |
781 | + } |
782 | +} |
783 | + |
784 | +/*! |
785 | + * \qmlproperty list<Action> ListItemActions::visibleActions |
786 | + * Holds the list of visible actions. This is a convenience property to help action |
787 | + * visualization panel implementations to consider only visible actions. |
788 | + */ |
789 | +QQmlListProperty<UCAction> UCListItemActionsAttached::visibleActions() |
790 | +{ |
791 | + return QQmlListProperty<UCAction>(this, m_visibleActions); |
792 | +} |
793 | + |
794 | +/*! |
795 | + * \qmlattachedproperty ListItem ListItemActions::listItem |
796 | + * \readonly |
797 | + * The property reports the connected \l ListItem to the list of actions. |
798 | + */ |
799 | +UCListItem *UCListItemActionsAttached::listItem() |
800 | +{ |
801 | + if (m_container.isNull()) { |
802 | + return NULL; |
803 | + } |
804 | + QQuickItem *panelItem = UCListItemActionsPrivate::get(m_container)->panelItem; |
805 | + if (!panelItem) { |
806 | + return NULL; |
807 | + } |
808 | + QQuickItem *listItem = panelItem->parentItem(); |
809 | + return static_cast<UCListItem*>(listItem); |
810 | +} |
811 | + |
812 | +/*! |
813 | + * \qmlattachedproperty int ListItemActions::listItemIndex |
814 | + * \readonly |
815 | + * Holds the index of the \l ListItem within a view, if the \l ListItem is used |
816 | + * in a model driven view. Otherwise it is set to -1. |
817 | + */ |
818 | +int UCListItemActionsAttached::listItemIndex() { |
819 | + if (m_container.isNull()) { |
820 | + return -1; |
821 | + } |
822 | + QQuickItem *panelItem = UCListItemActionsPrivate::get(m_container)->panelItem; |
823 | + if (!panelItem) { |
824 | + return -1; |
825 | + } |
826 | + QQuickItem *listItem = panelItem->parentItem(); |
827 | + return listItem ? UCListItemPrivate::get(static_cast<UCListItem*>(listItem))->index() : -1; |
828 | +} |
829 | + |
830 | +/*! |
831 | + * \qmlattachedproperty bool ListItemActions::swiping |
832 | + * \readonly |
833 | + * The property notifies whether the panel is swiped or not. The property does |
834 | + * not notify the rebounding. |
835 | + */ |
836 | +bool UCListItemActionsAttached::swiping() |
837 | +{ |
838 | + return m_swiping; |
839 | +} |
840 | + |
841 | +/*! |
842 | + * \qmlattachedproperty real ListItemActions::offset |
843 | + * The property returns the offset the panel item holding the visualized actions |
844 | + * is visible. This can be used to do different animations on the panel and on |
845 | + * the action visualizations. |
846 | + */ |
847 | +qreal UCListItemActionsAttached::offset() |
848 | +{ |
849 | + if (m_container.isNull()) { |
850 | + return 0.0; |
851 | + } |
852 | + return UCListItemActionsPrivate::get(m_container)->offsetDragged; |
853 | +} |
854 | + |
855 | +/*! |
856 | + * \qmlattachedproperty enum ListItemActions::status |
857 | + * \readonly |
858 | + * The property holds the status of the ListItemActions, whether is connected |
859 | + * as leading or as trailing action list to a \l ListItem. Possible valueas are: |
860 | + * \list A |
861 | + * \li \b Disconnected - default, the actions list is not connected to any \l ListItem |
862 | + * \li \b Leading - the actions list is connected as leading list |
863 | + * \li \b Trailing - the actions list is connected as trailing list |
864 | + * \endlist |
865 | + */ |
866 | +UCListItemActions::Status UCListItemActionsAttached::status() |
867 | +{ |
868 | + if (m_container.isNull()) { |
869 | + return UCListItemActions::Disconnected; |
870 | + } |
871 | + return UCListItemActionsPrivate::get(m_container)->status; |
872 | +} |
873 | + |
874 | +/*! |
875 | + * \qmlproperty real ListItemActions::overshoot |
876 | + * The property holds the overshoot value set for the list item. |
877 | + */ |
878 | +qreal UCListItemActionsAttached::overshoot() |
879 | +{ |
880 | + if (status() == UCListItemActions::Disconnected) { |
881 | + return 0.0; |
882 | + } |
883 | + QQuickItem *panelItem = UCListItemActionsPrivate::get(m_container)->panelItem; |
884 | + if (!panelItem) { |
885 | + // we don't have the panel created yet |
886 | + return 0.0; |
887 | + } |
888 | + UCListItem *item = static_cast<UCListItem*>(panelItem->parentItem()); |
889 | + if (!item) { |
890 | + // no ListItem attached |
891 | + return 0.0; |
892 | + } |
893 | + return UCListItemPrivate::get(item)->overshoot; |
894 | +} |
895 | + |
896 | +/*! |
897 | + * \qmlattachedmethod void ListItemActions::snapToPosition(real position) |
898 | + * The function can be used to perform custom snapping, or to execute rebounding |
899 | + * and also disconnecting from the connected \l ListItem. This can be achieved by |
900 | + * calling the function with 0.0 value. |
901 | + */ |
902 | +void UCListItemActionsAttached::snapToPosition(qreal position) |
903 | +{ |
904 | + //if it is disconnected, leave (this also includes the case when m_container is null) |
905 | + if (status() == UCListItemActions::Disconnected) { |
906 | + return; |
907 | + } |
908 | + QQuickItem *panelItem = UCListItemActionsPrivate::get(m_container)->panelItem; |
909 | + if (!panelItem) { |
910 | + // we don't have the panel created yet |
911 | + return; |
912 | + } |
913 | + UCListItem *item = static_cast<UCListItem*>(panelItem->parentItem()); |
914 | + if (!item) { |
915 | + // no ListItem attached |
916 | + return; |
917 | + } |
918 | + UCListItemPrivate *listItem = UCListItemPrivate::get(item); |
919 | + position *= (status() == UCListItemActions::Leading) ? 1 : -1; |
920 | + if (position == 0.0) { |
921 | + listItem->_q_rebound(); |
922 | + } else { |
923 | + // FIXME: implement snaping |
924 | + listItem->contentItem->setX(position); |
925 | + } |
926 | +} |
927 | + |
928 | + |
53 + , overshootGU(2)
would overshoot( units.gu( 2)) work instead of this?