Merge lp:~zsombi/ubuntu-ui-toolkit/32-listitemactions-attached into lp:~zsombi/ubuntu-ui-toolkit/listitem-master

Proposed by Zsombor Egri
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
Reviewer Review Type Date Requested Status
Tim Peeters Approve
Zsombor Egri Pending
Review via email: mp+240820@code.launchpad.net

Description of the change

Introducing ListItemActions attached properties, which will be attached automatically to action visualization panels.

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

adding missing connects

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

53 + , overshootGU(2)

would overshoot(units.gu(2)) work instead of this?

1321. By Zsombor Egri

dragging event renamed to flicking, as dragging is planned to name a different thing; visibleActions attached property added

Revision history for this message
Zsombor Egri (zsombi) wrote :

> 53 + , overshootGU(2)
>
> would overshoot(units.gu(2)) work instead of this?

It could. I'll move to that.

Revision history for this message
Zsombor Egri (zsombi) wrote :

> > 53 + , overshootGU(2)
> >
> > would overshoot(units.gu(2)) work instead of this?
>
> 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

Revision history for this message
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.

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

This is funny in the generated docs file:///home/tim/dev/ubuntu-ui-toolkit/r/32-listitemactions-attached/documentation/html/qml-ubuntu-components-listitem.html :

 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.

Revision history for this message
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.

Revision history for this message
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 UCListItemPrivate::_q_updateColors()
> {
> Q_Q(UCListItem);
> highlightColor = getPaletteColor("selected", "background");
> q->update();
> }

should this also update color?

Revision history for this message
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).

Revision history for this message
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.

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

The documentation needs example code

review: Needs Fixing
Revision history for this message
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

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

How do I enable the swiping in a list item?

I created a small test program here - https://code.launchpad.net/~tpeeters/+junk/lists
It has a ListView with the new ListItems that have leading and trailing actions, but I cannot swipe to show them.

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

^ I guess they come in a later MR. But how can I test it now?

Revision history for this message
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.

Revision history for this message
Zsombor Egri (zsombi) wrote :

> This is funny in the generated docs file:///home/tim/dev/ubuntu-ui-
> toolkit/r/32-listitemactions-attached/documentation/html/qml-ubuntu-
> components-listitem.html :
>
>
> 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.

Revision history for this message
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.

Revision history for this message
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 UCListItemPrivate::_q_updateColors()
> > {
> > Q_Q(UCListItem);
> > highlightColor = getPaletteColor("selected", "background");
> > 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.

Revision history for this message
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?

Revision history for this message
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

Revision history for this message
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.

Revision history for this message
Zsombor Egri (zsombi) wrote :

> How do I enable the swiping in a list item?
>
> I created a small test program here -
> https://code.launchpad.net/~tpeeters/+junk/lists
> 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.

Revision history for this message
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.

Revision history for this message
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

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

> > > void UCListItemPrivate::_q_updateColors()
> > > {
> > > Q_Q(UCListItem);
> > > highlightColor = getPaletteColor("selected", "background");
> > > 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?

Revision history for this message
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 :)

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

923 + // FIXME: implement snaping

snapping ;)

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

> (rebount)

rebound?

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

> On the other hand, memory consumption will increase signifficantly doe to separate panel creation

due to*

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

> > On the other hand, memory consumption will increase signifficantly doe to
> separate panel creation
>
> due to*

*significantly

Revision history for this message
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

Revision history for this message
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

Revision history for this message
Zsombor Egri (zsombi) wrote :

>
> > > > void UCListItemPrivate::_q_updateColors()
> > > > {
> > > > Q_Q(UCListItem);
> > > > highlightColor = getPaletteColor("selected", "background");
> > > > 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.

Revision history for this message
Zsombor Egri (zsombi) wrote :

> 923 + // FIXME: implement snaping
>
> snapping ;)

Won't bother, will be removed in #35

Revision history for this message
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.

Revision history for this message
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.

Revision history for this message
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

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

Good. Next!

review: Approve
1332. 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-11-19 15:10:15 +0000
+++ components.api 2014-11-19 15:10:18 +0000
@@ -871,17 +871,37 @@
871 Property { name: "leadingActions"; type: "UCListItemActions"; isPointer: true }871 Property { name: "leadingActions"; type: "UCListItemActions"; isPointer: true }
872 Property { name: "trailingActions"; type: "UCListItemActions"; isPointer: true }872 Property { name: "trailingActions"; type: "UCListItemActions"; isPointer: true }
873 Property { name: "pressed"; type: "bool"; isReadonly: true }873 Property { name: "pressed"; type: "bool"; isReadonly: true }
874 Property { name: "contentMoving"; type: "bool"; isReadonly: true }
874 Property { name: "color"; type: "QColor" }875 Property { name: "color"; type: "QColor" }
875 Property { name: "highlightColor"; type: "QColor" }876 Property { name: "highlightColor"; type: "QColor" }
876 Property { name: "data"; type: "QObject"; isList: true; isReadonly: true }877 Property { name: "data"; type: "QObject"; isList: true; isReadonly: true }
877 Property { name: "children"; type: "QQuickItem"; isList: true; isReadonly: true }878 Property { name: "children"; type: "QQuickItem"; isList: true; isReadonly: true }
878 Signal { name: "clicked" }879 Signal { name: "clicked" }
880 Signal { name: "contentMovementStarted" }
881 Signal { name: "contentMovementEnded" }
879 name: "UCListItemActions"882 name: "UCListItemActions"
880 prototype: "QObject"883 prototype: "QObject"
881 exports: ["ListItemActions 1.2"]884 exports: ["ListItemActions 1.2"]
885 name: "Status"
882 Property { name: "delegate"; type: "QQmlComponent"; isPointer: true }886 Property { name: "delegate"; type: "QQmlComponent"; isPointer: true }
883 Property { name: "actions"; type: "UCAction"; isList: true; isReadonly: true }887 Property { name: "actions"; type: "UCAction"; isList: true; isReadonly: true }
884 Property { name: "data"; type: "QObject"; isList: true; isReadonly: true }888 Property { name: "data"; type: "QObject"; isList: true; isReadonly: true }
889 Signal {
890 name: "statusChanged"
891 Parameter { name: "status"; type: "Status" }
892 name: "UCListItemActionsAttached"
893 prototype: "QObject"
894 Property { name: "container"; type: "UCListItemActions"; isReadonly: true; isPointer: true }
895 Property { name: "visibleActions"; type: "UCAction"; isList: true; isReadonly: true }
896 Property { name: "listItem"; type: "UCListItem"; isReadonly: true; isPointer: true }
897 Property { name: "listItemIndex"; type: "int"; isReadonly: true }
898 Property { name: "offset"; type: "double"; isReadonly: true }
899 Property { name: "status"; type: "UCListItemActions::Status"; isReadonly: true }
900 Property { name: "swiping"; type: "bool"; isReadonly: true }
901 Property { name: "overshoot"; type: "double"; isReadonly: true }
902 Method {
903 name: "snapToPosition"
904 Parameter { name: "position"; type: "double" }
885 name: "UCListItemDivider"905 name: "UCListItemDivider"
886 prototype: "QObject"906 prototype: "QObject"
887 Property { name: "visible"; type: "bool" }907 Property { name: "visible"; type: "bool" }
888908
=== modified file 'modules/Ubuntu/Components/plugin/plugin.pro'
--- modules/Ubuntu/Components/plugin/plugin.pro 2014-11-19 15:10:15 +0000
+++ modules/Ubuntu/Components/plugin/plugin.pro 2014-11-19 15:10:18 +0000
@@ -111,7 +111,8 @@
111 ucactionmanager.cpp \111 ucactionmanager.cpp \
112 adapters/actionsproxy_p.cpp \112 adapters/actionsproxy_p.cpp \
113 uclistitem.cpp \113 uclistitem.cpp \
114 uclistitemactions.cpp114 uclistitemactions.cpp \
115 uclistitemactionsattached.cpp
115116
116# adapters117# adapters
117SOURCES += adapters/alarmsadapter_organizer.cpp118SOURCES += adapters/alarmsadapter_organizer.cpp
118119
=== modified file 'modules/Ubuntu/Components/plugin/ucaction.h'
--- modules/Ubuntu/Components/plugin/ucaction.h 2014-09-01 06:56:39 +0000
+++ modules/Ubuntu/Components/plugin/ucaction.h 2014-11-19 15:10:18 +0000
@@ -87,6 +87,7 @@
87 Type m_parameterType;87 Type m_parameterType;
8888
89 friend class UCActionContext;89 friend class UCActionContext;
90 friend class UCListItemActionsAttached;
9091
91 bool isValidType(QVariant::Type valueType);92 bool isValidType(QVariant::Type valueType);
92 void generateName();93 void generateName();
9394
=== modified file 'modules/Ubuntu/Components/plugin/uclistitem.cpp'
--- modules/Ubuntu/Components/plugin/uclistitem.cpp 2014-11-19 15:10:15 +0000
+++ modules/Ubuntu/Components/plugin/uclistitem.cpp 2014-11-19 15:10:18 +0000
@@ -191,7 +191,10 @@
191UCListItemPrivate::UCListItemPrivate()191UCListItemPrivate::UCListItemPrivate()
192 : UCStyledItemBasePrivate()192 : UCStyledItemBasePrivate()
193 , pressed(false)193 , pressed(false)
194 , contentMoved(false)
194 , highlightColorChanged(false)195 , highlightColorChanged(false)
196 , ready(false)
197 , overshoot(UCUnits::instance().gu(2))
195 , color(Qt::transparent)198 , color(Qt::transparent)
196 , highlightColor(Qt::transparent)199 , highlightColor(Qt::transparent)
197 , contentItem(new QQuickItem)200 , contentItem(new QQuickItem)
@@ -249,6 +252,21 @@
249 QQuickItem *owner = flickable ? flickable : parentItem;252 QQuickItem *owner = flickable ? flickable : parentItem;
250 q->setImplicitWidth(owner ? owner->width() : UCUnits::instance().gu(40));253 q->setImplicitWidth(owner ? owner->width() : UCUnits::instance().gu(40));
251 q->setImplicitHeight(UCUnits::instance().gu(7));254 q->setImplicitHeight(UCUnits::instance().gu(7));
255 // update overshoot value
256 overshoot = UCUnits::instance().gu(2);
257}
258
259// returns the index of the list item when used in model driven views,
260// and the child index in other cases
261int UCListItemPrivate::index()
262{
263 Q_Q(UCListItem);
264 // is there an index context property?
265 QQmlContext *context = qmlContext(q);
266 QVariant index = context->contextProperty("index");
267 return index.isValid() ?
268 index.toInt() :
269 (parentItem ? QQuickItemPrivate::get(parentItem)->childItems.indexOf(q) : -1);
252}270}
253271
254// set pressed flag and update contentItem272// set pressed flag and update contentItem
@@ -303,30 +321,23 @@
303 * \since Ubuntu.Components 1.2321 * \since Ubuntu.Components 1.2
304 * \brief The ListItem element provides Ubuntu design standards for list or grid322 * \brief The ListItem element provides Ubuntu design standards for list or grid
305 * views.323 * views.
306 *324 * The ListItem component was designed to be used in a list view. It does not
307 * The component is dedicated to be used in designs with static or dynamic lists325 * define any specific layout, but while its contents can be freely chosen by
308 * (i.e. list views where each item's layout differs or in lists where the content326 * the developer, care must be taken to keep the contents light in order to ensure
309 * is determined by a given model, thus each element has the same layout). The327 * good performance when used in long list views.
310 * element does not define any specific layout, components can be placed in any
311 * ways on it. However, when used in list views, the content must be carefully
312 * chosen to in order to keep the kinetic behavior and the highest FPS possible.
313 *328 *
314 * The component provides two color properties which configures the item's background329 * The component provides two color properties which configures the item's background
315 * when normal or pressed. This can be configures through \l color and \l highlightColor330 * when normal or pressed. This can be configured through \l color and \l highlightColor
316 * properties.331 * properties.
317 *332 *
318 * \c contentItem holds all components and resources declared as child to ListItem.333 * \c contentItem holds all components and resources declared as child to ListItem.
319 * Being an Item, all other properties can be accessed or altered, with the exception334 * Being an Item, all properties can be accessed or altered. However, make sure you
320 * of some:335 * never change \c x, \c y, \c width, \c height or \c anchors properties as those are
321 * \list A336 * controlled by the ListItem itself when leading or trailing actions are revealed
322 * \li do not alter \c x, \c y, \c width or \c height properties as those are337 * and thus might cause the component to misbehave.
323 * controlled by the ListItem itself when leading or trailing actions are
324 * revealed and thus will destroy your logic
325 * \li never anchor left or right anchor lines as it will block revealing the actions.
326 * \endlist
327 *338 *
328 * Each ListItem has a thin divider shown on the bottom of the component. This339 * Each ListItem has a thin divider shown on the bottom of the component. This
329 * divider can be configured through the \l divider grouped property, which can340 * divider can be configured through the \c divider grouped property, which can
330 * configure its margins from the edges of the ListItem as well as its visibility.341 * configure its margins from the edges of the ListItem as well as its visibility.
331 */342 */
332343
@@ -334,7 +345,7 @@
334 * \qmlsignal ListItem::clicked()345 * \qmlsignal ListItem::clicked()
335 *346 *
336 * The signal is emitted when the component gets released while the \l pressed property347 * The signal is emitted when the component gets released while the \l pressed property
337 * is set. The signal is not emitted if the ListItem content is tugged or when used in348 * is set. The signal is not emitted if the ListItem content is swiped or when used in
338 * Flickable (or ListView, GridView) and the Flickable gets moved.349 * Flickable (or ListView, GridView) and the Flickable gets moved.
339 */350 */
340UCListItem::UCListItem(QQuickItem *parent)351UCListItem::UCListItem(QQuickItem *parent)
@@ -516,8 +527,8 @@
516 *527 *
517 * This grouped property configures the thin divider shown in the bottom of the528 * This grouped property configures the thin divider shown in the bottom of the
518 * component. Configures the visibility and the margins from the left and right529 * component. Configures the visibility and the margins from the left and right
519 * of the ListItem. When tugged (swiped left or right to reveal the actions),530 * of the ListItem. When swiped left or right to reveal the actions, it is not
520 * it is not moved together with the content. \c colorFrom and \c colorTo configure531 * moved together with the content. \c colorFrom and \c colorTo configure
521 * the starting and ending colors of the divider.532 * the starting and ending colors of the divider.
522 *533 *
523 * When \c visible is true, the ListItem's content size gets thinner with the534 * When \c visible is true, the ListItem's content size gets thinner with the
@@ -550,6 +561,43 @@
550}561}
551562
552/*!563/*!
564 * \qmlproperty bool ListItem::contentMoving
565 * \readonly
566 * The property describes whether the content is moving or not. The content is
567 * moved when swiped or when snapping in or out, and lasts till the snapping
568 * animation completes.
569 */
570
571/*!
572 * \qmlsignal ListItem::contentMovementStarted()
573 * The signal is emitted when the content movement has started.
574 */
575
576/*!
577 * \qmlsignal UCListItemPrivate::contentMovementEnded
578 * The signal is emitted when the content movement has ended.
579 */
580bool UCListItemPrivate::contentMoving() const
581{
582 return contentMoved;
583}
584void UCListItemPrivate::setContentMoving(bool moved)
585{
586 if (contentMoved == moved) {
587 return;
588 }
589 contentMoved = moved;
590 Q_Q(UCListItem);
591 if (contentMoved) {
592 Q_EMIT q->contentMovementStarted();
593 } else {
594 Q_EMIT q->contentMovementEnded();
595 }
596 Q_EMIT q->contentMovingChanged();
597
598}
599
600/*!
553 * \qmlproperty color ListItem::color601 * \qmlproperty color ListItem::color
554 * Configures the color of the normal background. The default value is transparent.602 * Configures the color of the normal background. The default value is transparent.
555 */603 */
556604
=== modified file 'modules/Ubuntu/Components/plugin/uclistitem.h'
--- modules/Ubuntu/Components/plugin/uclistitem.h 2014-11-19 15:10:15 +0000
+++ modules/Ubuntu/Components/plugin/uclistitem.h 2014-11-19 15:10:18 +0000
@@ -32,6 +32,7 @@
32 Q_PROPERTY(UCListItemActions *leadingActions READ leadingActions WRITE setLeadingActions NOTIFY leadingActionsChanged DESIGNABLE false)32 Q_PROPERTY(UCListItemActions *leadingActions READ leadingActions WRITE setLeadingActions NOTIFY leadingActionsChanged DESIGNABLE false)
33 Q_PROPERTY(UCListItemActions *trailingActions READ trailingActions WRITE setTrailingActions NOTIFY trailingActionsChanged DESIGNABLE false)33 Q_PROPERTY(UCListItemActions *trailingActions READ trailingActions WRITE setTrailingActions NOTIFY trailingActionsChanged DESIGNABLE false)
34 Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged)34 Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged)
35 Q_PRIVATE_PROPERTY(UCListItem::d_func(), bool contentMoving READ contentMoving NOTIFY contentMovingChanged)
35 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)36 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
36 Q_PROPERTY(QColor highlightColor READ highlightColor WRITE setHighlightColor NOTIFY highlightColorChanged)37 Q_PROPERTY(QColor highlightColor READ highlightColor WRITE setHighlightColor NOTIFY highlightColorChanged)
37 Q_PROPERTY(QQmlListProperty<QObject> data READ data DESIGNABLE false)38 Q_PROPERTY(QQmlListProperty<QObject> data READ data DESIGNABLE false)
@@ -65,12 +66,16 @@
65 void leadingActionsChanged();66 void leadingActionsChanged();
66 void trailingActionsChanged();67 void trailingActionsChanged();
67 void pressedChanged();68 void pressedChanged();
69 void contentMovingChanged();
68 void colorChanged();70 void colorChanged();
69 void highlightColorChanged();71 void highlightColorChanged();
70 void childrenChanged();72 void childrenChanged();
7173
72 void clicked();74 void clicked();
7375
76 void contentMovementStarted();
77 void contentMovementEnded();
78
74public Q_SLOTS:79public Q_SLOTS:
7580
76private:81private:
7782
=== modified file 'modules/Ubuntu/Components/plugin/uclistitem_p.h'
--- modules/Ubuntu/Components/plugin/uclistitem_p.h 2014-11-19 15:10:15 +0000
+++ modules/Ubuntu/Components/plugin/uclistitem_p.h 2014-11-19 15:10:18 +0000
@@ -43,14 +43,17 @@
43 void _q_updateColors();43 void _q_updateColors();
44 void _q_rebound();44 void _q_rebound();
45 void _q_updateSize();45 void _q_updateSize();
46 int index();
46 void setPressed(bool pressed);47 void setPressed(bool pressed);
47 void listenToRebind(bool listen);48 void listenToRebind(bool listen);
48 void resize();49 void resize();
49 void update();50 void update();
5051
51 bool pressed:1;52 bool pressed:1;
53 bool contentMoved:1;
52 bool highlightColorChanged:1;54 bool highlightColorChanged:1;
53 bool ready:1;55 bool ready:1;
56 qreal overshoot;
54 QColor color;57 QColor color;
55 QColor highlightColor;58 QColor highlightColor;
56 QPointer<QQuickFlickable> flickable;59 QPointer<QQuickFlickable> flickable;
@@ -58,6 +61,10 @@
58 UCListItemDivider *divider;61 UCListItemDivider *divider;
59 UCListItemActions *leadingActions;62 UCListItemActions *leadingActions;
60 UCListItemActions *trailingActions;63 UCListItemActions *trailingActions;
64
65 // getter/setters
66 bool contentMoving() const;
67 void setContentMoving(bool moved);
61};68};
6269
63class UCListItemDivider : public QObject70class UCListItemDivider : public QObject
6471
=== modified file 'modules/Ubuntu/Components/plugin/uclistitemactions.cpp'
--- modules/Ubuntu/Components/plugin/uclistitemactions.cpp 2014-11-19 15:10:15 +0000
+++ modules/Ubuntu/Components/plugin/uclistitemactions.cpp 2014-11-19 15:10:18 +0000
@@ -23,6 +23,8 @@
2323
24UCListItemActionsPrivate::UCListItemActionsPrivate()24UCListItemActionsPrivate::UCListItemActionsPrivate()
25 : QObjectPrivate()25 : QObjectPrivate()
26 , status(UCListItemActions::Disconnected)
27 , offsetDragged(0)
26 , delegate(0)28 , delegate(0)
27 , panelItem(0)29 , panelItem(0)
28{30{
@@ -31,6 +33,7 @@
31{33{
32}34}
3335
36// FIXME - fis ListItemStyle::snapAnimation to a link when property available
34/*!37/*!
35 * \qmltype ListItemActions38 * \qmltype ListItemActions
36 * \instantiates UCListItemActions39 * \instantiates UCListItemActions
@@ -40,7 +43,7 @@
40 * \ingroup unstable-ubuntu-listitems43 * \ingroup unstable-ubuntu-listitems
41 * \brief Provides configuration for actions to be added to a ListItem.44 * \brief Provides configuration for actions to be added to a ListItem.
42 *45 *
43 * ListItem accepts actions that can be configured to appear when tugged to left46 * ListItem accepts actions that can be configured to appear when swiped to left
44 * or right. The API does not limit the number of actions to be assigned for leading47 * or right. The API does not limit the number of actions to be assigned for leading
45 * or trailing actions, however the design constrains are allowing a maximum of48 * or trailing actions, however the design constrains are allowing a maximum of
46 * 1 action on leading- and a maximum of 3 actions on trailing side of the ListItem.49 * 1 action on leading- and a maximum of 3 actions on trailing side of the ListItem.
@@ -53,46 +56,155 @@
53 * the first time the actions are accessed. The colors of the panel is taken from56 * the first time the actions are accessed. The colors of the panel is taken from
54 * the theme's palette.57 * the theme's palette.
55 *58 *
56 * When tugged, panels reveal the actions one by one. In case an option is revealed59 * When swiped, panels reveal the actions one by one. In case an action is revealed
57 * more than 50%, the option will be snapped and revealed completely. This is also60 * more than 50%, the action will be snapped and revealed completely. This is also
58 * valid for the case when the option is visibl eless than 50%, in which case the61 * valid for the case when the action is visible less than 50%, in which case the
59 * option is hidden. Actions can be triggered by tapping.62 * action is hidden. Actions can be triggered by tapping.
60 *63 *
61 * \section3 Notes on performance64 * \note You can use the same ListItemActions for leading and for trailing actions
62 * When used with views, or when the amount of items of same kind to be created65 * the same time only if the instance is used by different groups of list items,
63 * is huge, it is recommended to use cached actions as well as cached ListItemActions66 * where one group uses it as leading and other group as trailing. In any other
64 * instances. In this way we can reduce the creation time of the items:67 * circumstances use separate ListItemActions for leading and trailing actions.
65 * \qml68 * \qml
66 * import QtQuick 2.269 * import QtQuick 2.2
67 * import Ubuntu.Components 1.270 * import Ubuntu.Components 1.2
68 *71 * MainView {
69 * MainView {72 * width: units.gu(40)
70 * width: units.gu(40)73 * height: units.gu(71)
71 * height: units.gu(71)74 *
72 *75 * ListItemActions {
73 * UbuntuListView {76 * id: sharedActions
74 * anchors.fill: parent77 * actions: [
75 * model: 1000078 * Action {
76 * ListItemActions {79 * iconName: "search"
77 * id: commonActions80 * },
78 * actions: [81 * Action {
79 * Action {82 * iconName: "edit"
80 * iconName: "search"83 * },
81 * },84 * Action {
82 * Action {85 * iconName: "copy"
83 * iconName: "edit"86 * }
84 * },87 * ]
85 * Action {88 * }
86 * iconName: "copy"89 *
87 * }90 * Column {
88 * ]91 * ListItem {
89 * }92 * leadingActions: sharedActions
90 * delegate: ListItem {93 * }
91 * trailingActions: commonActions94 * UbuntuListView {
92 * }95 * anchors.fill: parent
93 * }96 * model: 10000
94 * }97 * delegate: ListItem {
95 * \endqml98 * trailingActions: sharedActions
99 * }
100 * }
101 * }
102 * }
103 * \endqml
104 *
105 * \section3 Using with ListViews
106 * ListItemActions instances can be shared between ListItem instances within the
107 * same view. When shared, the memory footprint of the view will be lot smaller,
108 * as there will be no individual panel created for each list's actions visualization.
109 * Depending on how long the initialization of the component used in \c ListItem::actionsDelegate
110 * takes, creation time will be also reduced to one time per view.
111 * However, this implies that swiping a new ListItem content while another one is
112 * swiped will result in showing the newly swiped item's panel delayed, as the
113 * panel can be shown only after the previous item's snapping is completed. Depending
114 * on the \c ListItemStyle::snapAnimation duration, this may take some time, and the
115 * response time of the UI can become unacceptable.
116 *
117 * Having individual ListItemActions instances increases the memory footprint,
118 * however the UI will be more responsive as swiping individual ListItems will
119 * not have to wait till the previous ListItem's panel is snapped out (rebound).
120 * On the other hand, memory consumption will increase significantly due to
121 * separate panel creation, and performance may decrease with up to 40%, depending
122 * on what way are the actions declared, within the ListItemActions or as shared
123 * actions.
124 *
125 * The example above illustrates how to share ListItemActions between ListItem
126 * delegates, which can be the worst-performant but most lightwaight memory consumer
127 * setup. The following example illustrates the worst case:
128 * \qml
129 * import QtQuick 2.2
130 * import Ubuntu.Components 1.2
131 * MainView {
132 * width: units.gu(40)
133 * height: units.gu(71)
134 *
135 * UbuntuListView {
136 * anchors.fill: parent
137 * model: 10000
138 * delegate: ListItem {
139 * leadingActions: ListItemActions {
140 * actions: [
141 * Action {
142 * iconName: "delete"
143 * }
144 * ]
145 * }
146 * trailingActions: ListItemActions {
147 * actions: [
148 * Action {
149 * iconName: "search"
150 * },
151 * Action {
152 * iconName: "edit"
153 * },
154 * Action {
155 * iconName: "copy"
156 * }
157 * ]
158 * }
159 * }
160 * }
161 * }
162 * \endqml
163 *
164 * This example can be optimized by sharing the action arrays between the items:
165 * \qml
166 * import QtQuick 2.2
167 * import Ubuntu.Components 1.2
168 * MainView {
169 * width: units.gu(40)
170 * height: units.gu(71)
171 *
172 * property list<Action> leading: [
173 * Action {
174 * iconName: "delete"
175 * }
176 * ]
177 * property list<Action> trailing: [
178 * Action {
179 * iconName: "search"
180 * },
181 * Action {
182 * iconName: "edit"
183 * },
184 * Action {
185 * iconName: "copy"
186 * }
187 * ]
188 *
189 * UbuntuListView {
190 * anchors.fill: parent
191 * model: 10000
192 * delegate: ListItem {
193 * leadingActions: ListItemActions {
194 * actions: leading
195 * }
196 * trailingActions: ListItemActions {
197 * actions: trailing
198 * }
199 * }
200 * }
201 * }
202 * \endqml
203 *
204 * \section3 Attached properties
205 * ListItemActions provides a set of attached properties to the panels visualizing
206 * the actions. These properties can be used by implementations visualizing the
207 * actions.
96 */208 */
97209
98UCListItemActions::UCListItemActions(QObject *parent)210UCListItemActions::UCListItemActions(QObject *parent)
@@ -103,6 +215,28 @@
103{215{
104}216}
105217
218UCListItemActionsAttached *UCListItemActions::qmlAttachedProperties(QObject *owner)
219{
220 /*
221 * Detect the attachee, whether is it a child item of the panelItem. The panelItem
222 * itself cannot be detected, as the object can be attached during the call of
223 * component.beginCreate().
224 */
225 UCListItemActionsAttached *attached = new UCListItemActionsAttached(owner);
226 QQuickItem *item = qobject_cast<QQuickItem*>(owner);
227 while (item) {
228 // has item our attached property?
229 UCListItemActionsAttached *itemAttached = static_cast<UCListItemActionsAttached*>(
230 qmlAttachedPropertiesObject<UCListItemActions>(item, false));
231 if (itemAttached) {
232 attached->setList(itemAttached->container());
233 break;
234 }
235 item = item->parentItem();
236 }
237 return attached;
238}
239
106/*!240/*!
107 * \qmlproperty Component ListItemActions::delegate241 * \qmlproperty Component ListItemActions::delegate
108 * Custom delegate which overrides the default one used by the ListItem. If the242 * Custom delegate which overrides the default one used by the ListItem. If the
@@ -132,7 +266,7 @@
132 * declared in place. An example of cached actions:266 * declared in place. An example of cached actions:
133 * \qml267 * \qml
134 * ListItemActions {268 * ListItemActions {
135 * id: cacedActions269 * id: cachedActions
136 * actions: [270 * actions: [
137 * copyAction, searchAction, cutAction271 * copyAction, searchAction, cutAction
138 * ]272 * ]
139273
=== modified file 'modules/Ubuntu/Components/plugin/uclistitemactions.h'
--- modules/Ubuntu/Components/plugin/uclistitemactions.h 2014-11-19 15:10:15 +0000
+++ modules/Ubuntu/Components/plugin/uclistitemactions.h 2014-11-19 15:10:18 +0000
@@ -22,6 +22,7 @@
2222
23class QQmlComponent;23class QQmlComponent;
24class UCAction;24class UCAction;
25class UCListItemActionsAttached;
25class UCListItemActionsPrivate;26class UCListItemActionsPrivate;
26class UCListItemActions : public QObject27class UCListItemActions : public QObject
27{28{
@@ -30,10 +31,18 @@
30 Q_PROPERTY(QQmlListProperty<UCAction> actions READ actions CONSTANT)31 Q_PROPERTY(QQmlListProperty<UCAction> actions READ actions CONSTANT)
31 Q_PROPERTY(QQmlListProperty<QObject> data READ data)32 Q_PROPERTY(QQmlListProperty<QObject> data READ data)
32 Q_CLASSINFO("DefaultProperty", "data")33 Q_CLASSINFO("DefaultProperty", "data")
34 Q_ENUMS(Status)
33public:35public:
36 enum Status {
37 Disconnected,
38 Leading,
39 Trailing
40 };
34 explicit UCListItemActions(QObject *parent = 0);41 explicit UCListItemActions(QObject *parent = 0);
35 ~UCListItemActions();42 ~UCListItemActions();
3643
44 static UCListItemActionsAttached *qmlAttachedProperties(QObject *owner);
45
37 QQmlComponent *delegate() const;46 QQmlComponent *delegate() const;
38 void setDelegate(QQmlComponent *delegate);47 void setDelegate(QQmlComponent *delegate);
39 QQmlListProperty<UCAction> actions();48 QQmlListProperty<UCAction> actions();
@@ -41,9 +50,66 @@
4150
42Q_SIGNALS:51Q_SIGNALS:
43 void delegateChanged();52 void delegateChanged();
53 void statusChanged(Status status);
4454
45private:55private:
46 Q_DECLARE_PRIVATE(UCListItemActions)56 Q_DECLARE_PRIVATE(UCListItemActions)
47};57};
4858
59class UCListItemActionsAttached : public QObject
60{
61 Q_OBJECT
62 Q_PROPERTY(UCListItemActions *container READ container NOTIFY containerChanged)
63 Q_PROPERTY(QQmlListProperty<UCAction> visibleActions READ visibleActions NOTIFY visibleActionsChanged)
64 Q_PROPERTY(UCListItem *listItem READ listItem NOTIFY listItemChanged)
65 Q_PROPERTY(int listItemIndex READ listItemIndex NOTIFY listItemIndexChanged)
66 Q_PROPERTY(qreal offset READ offset NOTIFY offsetChanged)
67 Q_PROPERTY(UCListItemActions::Status status READ status NOTIFY statusChanged)
68 Q_PROPERTY(bool swiping READ swiping NOTIFY swipingChanged)
69 Q_PROPERTY(qreal overshoot READ overshoot NOTIFY overshootChanged)
70public:
71 UCListItemActionsAttached(QObject *parent = 0);
72 ~UCListItemActionsAttached();
73 void setList(UCListItemActions *list);
74 void connectListItem(UCListItem *item, bool connect);
75
76 UCListItemActions *container() const
77 {
78 return m_container.data();
79 }
80 QQmlListProperty<UCAction> visibleActions();
81 UCListItem *listItem();
82 int listItemIndex();
83 bool swiping();
84 qreal offset();
85 UCListItemActions::Status status();
86 qreal overshoot();
87
88
89public Q_SLOTS:
90 void snapToPosition(qreal position);
91
92Q_SIGNALS:
93 void containerChanged();
94 void visibleActionsChanged();
95 void listItemChanged();
96 void listItemIndexChanged();
97 void offsetChanged();
98 void statusChanged();
99 void swipingChanged();
100 void overshootChanged();
101
102private:
103 QPointer<UCListItemActions> m_container;
104 QList<UCAction*> m_visibleActions;
105 bool m_swiping;
106 friend class UCListItemAction;
107
108private Q_SLOTS:
109 void updateVisibleActions();
110 void updateSwipeState();
111};
112
113QML_DECLARE_TYPEINFO(UCListItemActions, QML_HAS_ATTACHED_PROPERTIES)
114
49#endif // UCLISTITEMACTIONS_H115#endif // UCLISTITEMACTIONS_H
50116
=== modified file 'modules/Ubuntu/Components/plugin/uclistitemactions_p.h'
--- modules/Ubuntu/Components/plugin/uclistitemactions_p.h 2014-11-19 15:10:15 +0000
+++ modules/Ubuntu/Components/plugin/uclistitemactions_p.h 2014-11-19 15:10:18 +0000
@@ -31,16 +31,12 @@
31 return actions->d_func();31 return actions->d_func();
32 }32 }
3333
34 UCListItemActions::Status status;
35 qreal offsetDragged;
34 QQmlComponent *delegate;36 QQmlComponent *delegate;
35 QQuickItem *panelItem;37 QQuickItem *panelItem;
36 QList<UCAction*> actions;38 QList<UCAction*> actions;
37 QList<QObject*> data;39 QList<QObject*> data;
38
39 // options list property functions
40 static void funcAppend(QQmlListProperty<UCAction>*, UCAction*);
41 static int funcCount(QQmlListProperty<UCAction>*);
42 static QObject *funcAt(QQmlListProperty<UCAction>*, int);
43 static void funcClear(QQmlListProperty<UCAction>*);
44};40};
4541
46#endif // UCLISTITEMACTIONS_P_H42#endif // UCLISTITEMACTIONS_P_H
4743
=== added file 'modules/Ubuntu/Components/plugin/uclistitemactionsattached.cpp'
--- modules/Ubuntu/Components/plugin/uclistitemactionsattached.cpp 1970-01-01 00:00:00 +0000
+++ modules/Ubuntu/Components/plugin/uclistitemactionsattached.cpp 2014-11-19 15:10:18 +0000
@@ -0,0 +1,267 @@
1/*
2 * Copyright 2014 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#include "uclistitem.h"
18#include "uclistitem_p.h"
19#include "uclistitemactions.h"
20#include "uclistitemactions_p.h"
21#include "ucunits.h"
22#include "ucaction.h"
23
24UCListItemActionsAttached::UCListItemActionsAttached(QObject *parent)
25 : QObject(parent)
26 , m_swiping(false)
27{
28}
29
30UCListItemActionsAttached::~UCListItemActionsAttached()
31{
32}
33
34/*!
35 * \qmlattachedproperty ListItemActions ListItemActions::container
36 * \readonly
37 * The property holds the instance of the \l ListItemActions the ListItem's actions
38 * panel is visualizing.
39 */
40void UCListItemActionsAttached::setList(UCListItemActions *list)
41{
42 if (list == m_container) {
43 return;
44 }
45 m_container = list;
46 if (!m_container.isNull()) {
47 // connect statusChanged() to update status, listItem, listItemIndex and overshoot values
48 QObject::connect(m_container.data(), &UCListItemActions::statusChanged,
49 this, &UCListItemActionsAttached::statusChanged);
50 QObject::connect(m_container.data(), &UCListItemActions::statusChanged,
51 this, &UCListItemActionsAttached::listItemChanged);
52 QObject::connect(m_container.data(), &UCListItemActions::statusChanged,
53 this, &UCListItemActionsAttached::listItemIndexChanged);
54 QObject::connect(m_container.data(), &UCListItemActions::statusChanged,
55 this, &UCListItemActionsAttached::overshootChanged);
56
57 UCListItemActionsPrivate *actions = UCListItemActionsPrivate::get(m_container.data());
58 // connect panel's xChanged to update the dragged offset
59 QObject::connect(actions->panelItem, &QQuickItem::xChanged,
60 this, &UCListItemActionsAttached::offsetChanged);
61
62 // connect actions to get updates about visible changes
63 Q_FOREACH(UCAction *action, UCListItemActionsPrivate::get(m_container)->actions) {
64 QObject::connect(action, &UCAction::visibleChanged,
65 this, &UCListItemActionsAttached::updateVisibleActions);
66 }
67 }
68 Q_EMIT containerChanged();
69 Q_EMIT visibleActionsChanged();
70}
71
72void UCListItemActionsAttached::connectListItem(UCListItem *item, bool connect)
73{
74 if (!item) {
75 return;
76 }
77 if (connect) {
78 QObject::connect(item, &UCListItem::pressedChanged,
79 this, &UCListItemActionsAttached::updateSwipeState);
80 QObject::connect(item, &UCListItem::contentMovingChanged,
81 this, &UCListItemActionsAttached::updateSwipeState);
82 } else {
83 QObject::disconnect(item, &UCListItem::pressedChanged,
84 this, &UCListItemActionsAttached::updateSwipeState);
85 QObject::disconnect(item, &UCListItem::contentMovingChanged,
86 this, &UCListItemActionsAttached::updateSwipeState);
87 }
88}
89
90// private slot to update visible actions
91void UCListItemActionsAttached::updateVisibleActions()
92{
93 m_visibleActions.clear();
94 if (!m_container.isNull()) {
95 Q_FOREACH(UCAction *action, UCListItemActionsPrivate::get(m_container)->actions) {
96 if (action->m_visible) {
97 m_visibleActions << action;
98 }
99 }
100 }
101 Q_EMIT visibleActionsChanged();
102}
103
104// private slot updating swipe state
105void UCListItemActionsAttached::updateSwipeState()
106{
107 if (m_container.isNull()) {
108 return;
109 }
110 QQuickItem *panelItem = UCListItemActionsPrivate::get(m_container)->panelItem;
111 if (!panelItem || !panelItem->parentItem()) {
112 return;
113 }
114 UCListItem *item = static_cast<UCListItem*>(panelItem->parentItem());
115 UCListItemPrivate *listItem = UCListItemPrivate::get(item);
116 bool swiped = listItem->pressed && listItem->contentMoved;
117 if (swiped != m_swiping) {
118 m_swiping = swiped;
119 Q_EMIT swipingChanged();
120 }
121}
122
123/*!
124 * \qmlproperty list<Action> ListItemActions::visibleActions
125 * Holds the list of visible actions. This is a convenience property to help action
126 * visualization panel implementations to consider only visible actions.
127 */
128QQmlListProperty<UCAction> UCListItemActionsAttached::visibleActions()
129{
130 return QQmlListProperty<UCAction>(this, m_visibleActions);
131}
132
133/*!
134 * \qmlattachedproperty ListItem ListItemActions::listItem
135 * \readonly
136 * The property reports the connected \l ListItem to the list of actions.
137 */
138UCListItem *UCListItemActionsAttached::listItem()
139{
140 if (m_container.isNull()) {
141 return NULL;
142 }
143 QQuickItem *panelItem = UCListItemActionsPrivate::get(m_container)->panelItem;
144 if (!panelItem) {
145 return NULL;
146 }
147 QQuickItem *listItem = panelItem->parentItem();
148 return static_cast<UCListItem*>(listItem);
149}
150
151/*!
152 * \qmlattachedproperty int ListItemActions::listItemIndex
153 * \readonly
154 * Holds the index of the \l ListItem within a view, if the \l ListItem is used
155 * in a model driven view. Otherwise it is set to -1.
156 */
157int UCListItemActionsAttached::listItemIndex() {
158 if (m_container.isNull()) {
159 return -1;
160 }
161 QQuickItem *panelItem = UCListItemActionsPrivate::get(m_container)->panelItem;
162 if (!panelItem) {
163 return -1;
164 }
165 QQuickItem *listItem = panelItem->parentItem();
166 return listItem ? UCListItemPrivate::get(static_cast<UCListItem*>(listItem))->index() : -1;
167}
168
169/*!
170 * \qmlattachedproperty bool ListItemActions::swiping
171 * \readonly
172 * The property notifies whether the panel is swiped or not. The property does
173 * not notify the rebounding.
174 */
175bool UCListItemActionsAttached::swiping()
176{
177 return m_swiping;
178}
179
180/*!
181 * \qmlattachedproperty real ListItemActions::offset
182 * The property returns the offset the panel item holding the visualized actions
183 * is visible. This can be used to do different animations on the panel and on
184 * the action visualizations.
185 */
186qreal UCListItemActionsAttached::offset()
187{
188 if (m_container.isNull()) {
189 return 0.0;
190 }
191 return UCListItemActionsPrivate::get(m_container)->offsetDragged;
192}
193
194/*!
195 * \qmlattachedproperty enum ListItemActions::status
196 * \readonly
197 * The property holds the status of the ListItemActions, whether is connected
198 * as leading or as trailing action list to a \l ListItem. Possible valueas are:
199 * \list A
200 * \li \b Disconnected - default, the actions list is not connected to any \l ListItem
201 * \li \b Leading - the actions list is connected as leading list
202 * \li \b Trailing - the actions list is connected as trailing list
203 * \endlist
204 */
205UCListItemActions::Status UCListItemActionsAttached::status()
206{
207 if (m_container.isNull()) {
208 return UCListItemActions::Disconnected;
209 }
210 return UCListItemActionsPrivate::get(m_container)->status;
211}
212
213/*!
214 * \qmlproperty real ListItemActions::overshoot
215 * The property holds the overshoot value set for the list item.
216 */
217qreal UCListItemActionsAttached::overshoot()
218{
219 if (status() == UCListItemActions::Disconnected) {
220 return 0.0;
221 }
222 QQuickItem *panelItem = UCListItemActionsPrivate::get(m_container)->panelItem;
223 if (!panelItem) {
224 // we don't have the panel created yet
225 return 0.0;
226 }
227 UCListItem *item = static_cast<UCListItem*>(panelItem->parentItem());
228 if (!item) {
229 // no ListItem attached
230 return 0.0;
231 }
232 return UCListItemPrivate::get(item)->overshoot;
233}
234
235/*!
236 * \qmlattachedmethod void ListItemActions::snapToPosition(real position)
237 * The function can be used to perform custom snapping, or to execute rebounding
238 * and also disconnecting from the connected \l ListItem. This can be achieved by
239 * calling the function with 0.0 value.
240 */
241void UCListItemActionsAttached::snapToPosition(qreal position)
242{
243 //if it is disconnected, leave (this also includes the case when m_container is null)
244 if (status() == UCListItemActions::Disconnected) {
245 return;
246 }
247 QQuickItem *panelItem = UCListItemActionsPrivate::get(m_container)->panelItem;
248 if (!panelItem) {
249 // we don't have the panel created yet
250 return;
251 }
252 UCListItem *item = static_cast<UCListItem*>(panelItem->parentItem());
253 if (!item) {
254 // no ListItem attached
255 return;
256 }
257 UCListItemPrivate *listItem = UCListItemPrivate::get(item);
258 position *= (status() == UCListItemActions::Leading) ? 1 : -1;
259 if (position == 0.0) {
260 listItem->_q_rebound();
261 } else {
262 // FIXME: implement snaping
263 listItem->contentItem->setX(position);
264 }
265}
266
267

Subscribers

People subscribed via source and target branches

to all changes: