~zsombi/ubuntu-ui-toolkit/alarm-regression-fix

« back to all changes in this revision

Viewing changes to modules/Ubuntu/Components/plugin/uclistitem.cpp

  • Committer: Tarmac
  • Author(s): Zsombor Egri
  • Date: 2015-02-05 15:36:14 UTC
  • mfrom: (1366.1.18 78-action-property)
  • Revision ID: tarmac-20150205153614-e30jwjhh1a7aheif
Introducing action property in ListItem. Fixes: https://bugs.launchpad.net/bugs/1362305, https://bugs.launchpad.net/bugs/1369935.

Approved by PS Jenkins bot, Tim Peeters.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include "propertychange_p.h"
25
25
#include "i18n.h"
26
26
#include "quickutils.h"
 
27
#include "ucaction.h"
27
28
#include <QtQml/QQmlInfo>
28
29
#include <QtQuick/private/qquickitem_p.h>
29
30
#include <QtQuick/private/qquickflickable_p.h>
354
355
    , leadingPanel(0)
355
356
    , trailingPanel(0)
356
357
    , animator(0)
 
358
    , mainAction(0)
357
359
    , styleComponent(0)
358
360
    , implicitStyleComponent(0)
359
361
    , styleItem(0)
593
595
// returns true if the highlight is possible
594
596
bool UCListItemPrivate::canHighlight(QMouseEvent *event)
595
597
{
 
598
    // if automatic, the highlight should not happen if we clicked on an active component;
596
599
    // localPos is a position relative to ListItem which will give us a child from
597
600
    // from the original coordinates; therefore we must map the position to the contentItem
598
601
   Q_Q(UCListItem);
604
607
   QQuickMouseArea *ma = q->findChild<QQuickMouseArea*>();
605
608
   bool activeMouseArea = ma && ma->isEnabled();
606
609
   return !activeComponent && (isClickedConnected() || isPressAndHoldConnected() ||
607
 
                               leadingActions || trailingActions || activeMouseArea);
 
610
                               mainAction || leadingActions || trailingActions || activeMouseArea);
608
611
}
609
612
 
610
613
// set highlighted flag and update contentItem
929
932
    UCStyledItemBase::itemChange(change, data);
930
933
    if (change == ItemParentHasChanged) {
931
934
        Q_D(UCListItem);
932
 
        // make sure we are not connected to the previous Flickable
 
935
        // make sure we are not connected to any previous Flickable
933
936
        d->listenToRebind(false);
934
937
        // check if we are in a positioner, and if that positioner is in a Flickable
935
938
        QQuickBasePositioner *positioner = qobject_cast<QQuickBasePositioner*>(data.item);
1024
1027
        // while moving, we cannot select any items
1025
1028
        return;
1026
1029
    }
1027
 
    if (event->button() == Qt::LeftButton && d->canHighlight(event)) {
 
1030
    if (d->canHighlight(event) && !d->suppressClick
 
1031
            && !d->highlighted && event->button() == Qt::LeftButton) {
1028
1032
        // stop any ongoing animation!
1029
1033
        if (d->animator) {
1030
1034
            d->animator->stop();
1059
1063
 
1060
1064
        if (!d->suppressClick) {
1061
1065
            Q_EMIT clicked();
 
1066
            if (d->mainAction) {
 
1067
                Q_EMIT d->mainAction->trigger(d->index());
 
1068
            }
1062
1069
            d->_q_rebound();
 
1070
        } else {
 
1071
            d->suppressClick = false;
1063
1072
        }
1064
1073
    }
1065
1074
    d->setHighlighted(false);
1145
1154
        QMouseEvent *mouse = static_cast<QMouseEvent*>(event);
1146
1155
        if (child->isEnabled() && (child->acceptedMouseButtons() & mouse->button()) && !qobject_cast<QQuickText*>(child)) {
1147
1156
            Q_D(UCListItem);
 
1157
            // suppress click
1148
1158
            d->suppressClick = true;
1149
1159
            // listen for flickable to be able to rebind if movement started there!
1150
1160
            d->listenToRebind(true);
1299
1309
 * is moved horizontally. When in Flickable (or ListView), the item gets un-highlighted
1300
1310
 * (false) when the mouse or touch is moved towards the vertical direction causing
1301
1311
 * the flickable to move.
 
1312
 *
 
1313
 * Configures the color when highlighted. Defaults to the theme palette's background
 
1314
 * color.
 
1315
 *
 
1316
 * An item is highlighted, thus highlight state toggled, when pressed and it has
 
1317
 * one of the following conditions fulfilled:
 
1318
 * \list
 
1319
 *  \li * \l leadingActions or \l trailingActions set,
 
1320
 *  \li * it has an \l action attached
 
1321
 *  \li * if the ListItem has an active child component, such as a \l Button, a
 
1322
 *      \l Switch, etc.
 
1323
 *  \li * in general, if an active (enabled and visible) \c MouseArea is added
 
1324
 *      as a child component
 
1325
 *  \li * \l clicked signal handler is implemented or there is a slot or function
 
1326
 *      connected to it
 
1327
 *  \li * \l pressAndHold signal handler is implemented or there is a slot or
 
1328
 *      function connected to it.
 
1329
 * \endlist
 
1330
 *
 
1331
 * \note Adding an active component does not mean the component will be activated
 
1332
 * when the ListItem will be tapped/clicked outside of the component area. If
 
1333
 * such a behavior is needed, that must be done explicitly.
 
1334
 * \qml
 
1335
 * ListItem {
 
1336
 *     Label {
 
1337
 *         text: "This is a label"
 
1338
 *     }
 
1339
 *     Switch {
 
1340
 *         id: toggle
 
1341
 *         anchors.right: parent.right
 
1342
 *     }
 
1343
 *     Component.onCompleted: clicked.connect(toggle.clicked)
 
1344
 * }
 
1345
 * \endqml
 
1346
 *
 
1347
 * \sa action, leadingActions, trailingActions
1302
1348
 */
1303
1349
bool UCListItem::highlighted() const
1304
1350
{
1340
1386
        Q_EMIT q->contentMovementEnded();
1341
1387
    }
1342
1388
    Q_EMIT q->contentMovingChanged();
1343
 
 
1344
1389
}
1345
1390
 
1346
1391
/*!
1395
1440
}
1396
1441
 
1397
1442
/*!
 
1443
 * \qmlproperty Action ListItem::action
 
1444
 * The property holds the action which will be triggered when the ListItem is
 
1445
 * clicked. ListItem will not visualize the action, that is the responsibility
 
1446
 * of the components placed inside the list item. However, when set, the ListItem
 
1447
 * will be highlighted on press.
 
1448
 *
 
1449
 * If the action set has no value type set, ListItem will set its type to \c
 
1450
 * Action.Integer and the \l {Action::triggered}{triggered} signal will be getting
 
1451
 * the ListItem index as \e value parameter.
 
1452
 *
 
1453
 * Defaults no null.
 
1454
 */
 
1455
UCAction *UCListItemPrivate::action() const
 
1456
{
 
1457
    return mainAction;
 
1458
}
 
1459
void UCListItemPrivate::setAction(UCAction *action)
 
1460
{
 
1461
    Q_Q(UCListItem);
 
1462
    if (mainAction == action) {
 
1463
        return;
 
1464
    }
 
1465
    mainAction = action;
 
1466
    if (mainAction && (mainAction->m_parameterType == UCAction::None)) {
 
1467
        // call setProperty to invoke notify signal
 
1468
        mainAction->setProperty("parameterType", UCAction::Integer);
 
1469
    }
 
1470
    Q_EMIT q->actionChanged();
 
1471
}
 
1472
 
 
1473
/*!
1398
1474
 * \qmlproperty real ListItem::swipeOvershoot
1399
1475
 * The property configures the overshoot value on swiping. Its default value is
1400
1476
 * configured by the \l {ListItemStyle}{style}. Any positive value overrides the