593
595
// returns true if the highlight is possible
594
596
bool UCListItemPrivate::canHighlight(QMouseEvent *event)
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
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);
610
613
// set highlighted flag and update contentItem
929
932
UCStyledItemBase::itemChange(change, data);
930
933
if (change == ItemParentHasChanged) {
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
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();
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.
1313
* Configures the color when highlighted. Defaults to the theme palette's background
1316
* An item is highlighted, thus highlight state toggled, when pressed and it has
1317
* one of the following conditions fulfilled:
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
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
1327
* \li * \l pressAndHold signal handler is implemented or there is a slot or
1328
* function connected to it.
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.
1337
* text: "This is a label"
1341
* anchors.right: parent.right
1343
* Component.onCompleted: clicked.connect(toggle.clicked)
1347
* \sa action, leadingActions, trailingActions
1303
1349
bool UCListItem::highlighted() const
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.
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.
1455
UCAction *UCListItemPrivate::action() const
1459
void UCListItemPrivate::setAction(UCAction *action)
1462
if (mainAction == action) {
1465
mainAction = action;
1466
if (mainAction && (mainAction->m_parameterType == UCAction::None)) {
1467
// call setProperty to invoke notify signal
1468
mainAction->setProperty("parameterType", UCAction::Integer);
1470
Q_EMIT q->actionChanged();
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