~zsombi/ubuntu-ui-toolkit/78-action-property

« back to all changes in this revision

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

prereq sync

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
    if (!snap) {
88
88
        // no animation, so we simply position the component
89
89
        listItem->contentItem->setX(to);
 
90
        // lock contentItem left/right edges
 
91
        listItem->lockContentItem(true);
90
92
        return false;
91
93
    }
92
94
    snap->setTargetObject(listItem->contentItem);
133
135
        QObject::disconnect(snap, 0, 0, 0);
134
136
    }
135
137
    UCListItemPrivate *listItem = UCListItemPrivate::get(item);
136
 
    if (listItem->attachedProperties) {
 
138
    if (listItem->parentAttached) {
137
139
        // restore flickable's interactive and cleanup
138
 
        listItem->attachedProperties->disableInteractive(item, false);
 
140
        listItem->parentAttached->disableInteractive(item, false);
139
141
        // no need to listen flickables any longer
140
142
        listItem->listenToRebind(false);
141
143
    }
144
146
    UCActionPanel::ungrabPanel(listItem->trailingPanel);
145
147
    // set contentMoved to false
146
148
    listItem->setContentMoving(false);
 
149
    // lock contentItem left/right edges
 
150
    listItem->lockContentItem(true);
147
151
}
148
152
 
149
153
/*
212
216
        m_rightMargin = UCUnits::instance().dp(2);
213
217
    }
214
218
    if (m_listItem) {
 
219
        m_listItem->adjustContentItemHeight();
215
220
        m_listItem->update();
216
221
    }
217
222
}
275
280
        return;
276
281
    }
277
282
    m_visible = visible;
278
 
    m_listItem->resize();
279
 
    m_listItem->update();
280
283
    Q_EMIT visibleChanged();
 
284
    // set/reset contentItem's bottomMargin
 
285
    m_listItem->adjustContentItemHeight();
281
286
}
282
287
 
283
288
void UCListItemDivider::setLeftMargin(qreal leftMargin)
343
348
    , overshoot(0)
344
349
    , color(Qt::transparent)
345
350
    , highlightColor(Qt::transparent)
346
 
    , attachedProperties(0)
 
351
    , parentAttached(0)
347
352
    , contentItem(new QQuickItem)
348
353
    , divider(new UCListItemDivider)
349
354
    , leadingActions(0)
602
607
// connects/disconnects from the Flickable anchestor to get notified when to do rebound
603
608
void UCListItemPrivate::listenToRebind(bool listen)
604
609
{
605
 
    if (attachedProperties) {
 
610
    if (parentAttached) {
606
611
        Q_Q(UCListItem);
607
 
        attachedProperties->listenToRebind(q, listen);
608
 
    }
609
 
}
610
 
 
611
 
void UCListItemPrivate::resize()
612
 
{
613
 
    Q_Q(UCListItem);
614
 
    QRectF rect(q->boundingRect());
615
 
    if (divider && divider->m_visible) {
616
 
        rect.setHeight(rect.height() - divider->m_thickness);
617
 
    }
618
 
    contentItem->setSize(rect.size());
 
612
        parentAttached->listenToRebind(q, listen);
 
613
    }
 
614
}
 
615
 
 
616
// lock/unlock contentItem's left and right anchors to the ListItem's left and right
 
617
void UCListItemPrivate::lockContentItem(bool lock)
 
618
{
 
619
    QQuickAnchors *contentAnchors = QQuickItemPrivate::get(contentItem)->anchors();
 
620
    if (lock) {
 
621
        contentAnchors->setLeft(left());
 
622
        contentAnchors->setRight(right());
 
623
    } else {
 
624
        contentAnchors->resetLeft();
 
625
        contentAnchors->resetRight();
 
626
    }
 
627
}
 
628
 
 
629
// adjust contentItem height depending on teh divider's visibility
 
630
void UCListItemPrivate::adjustContentItemHeight()
 
631
{
 
632
    QQuickAnchors *contentAnchors = QQuickItemPrivate::get(contentItem)->anchors();
 
633
    if (divider->m_visible) {
 
634
        contentAnchors->setBottomMargin(divider->m_thickness);
 
635
    } else {
 
636
        contentAnchors->resetBottomMargin();
 
637
    }
619
638
}
620
639
 
621
640
void UCListItemPrivate::update()
844
863
{
845
864
    UCStyledItemBase::componentComplete();
846
865
    Q_D(UCListItem);
 
866
    // anchor contentItem prior doing anything else
 
867
    QQuickAnchors *contentAnchors = QQuickItemPrivate::get(d->contentItem)->anchors();
 
868
    contentAnchors->setTop(d->top());
 
869
    contentAnchors->setBottom(d->bottom());
 
870
    d->adjustContentItemHeight();
 
871
    d->lockContentItem(true);
 
872
 
847
873
    d->ready = true;
848
874
    /* We only deal with ListView, as for other cases we would need to check the children
849
875
     * changes, which would have an enormous impact on performance in case of huge amount
879
905
        // attach ListItem properties to the flickable or to the parent item
880
906
        if (d->flickable) {
881
907
            // connect to flickable to get width changes
882
 
            d->attachedProperties = static_cast<UCViewItemsAttached*>(qmlAttachedPropertiesObject<UCViewItemsAttached>(d->flickable));
 
908
            d->parentAttached = static_cast<UCViewItemsAttached*>(qmlAttachedPropertiesObject<UCViewItemsAttached>(d->flickable));
883
909
        } else if (data.item) {
884
 
            d->attachedProperties = static_cast<UCViewItemsAttached*>(qmlAttachedPropertiesObject<UCViewItemsAttached>(data.item));
 
910
            d->parentAttached = static_cast<UCViewItemsAttached*>(qmlAttachedPropertiesObject<UCViewItemsAttached>(data.item));
885
911
        } else {
886
912
            // mark as not ready, so no action should be performed which depends on readyness
887
913
            d->ready = false;
888
914
            // about to be deleted or reparented, disable attached
889
 
            d->attachedProperties = 0;
 
915
            d->parentAttached = 0;
890
916
        }
891
917
 
892
918
        if (data.item) {
898
924
    }
899
925
}
900
926
 
901
 
void UCListItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
902
 
{
903
 
    UCStyledItemBase::geometryChanged(newGeometry, oldGeometry);
904
 
    // resize contentItem item
905
 
    Q_D(UCListItem);
906
 
    d->resize();
907
 
}
908
 
 
909
927
QSGNode *UCListItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data)
910
928
{
911
929
    Q_UNUSED(data);
962
980
{
963
981
    UCStyledItemBase::mousePressEvent(event);
964
982
    Q_D(UCListItem);
965
 
    if (d->attachedProperties && d->attachedProperties->isMoving()) {
 
983
    if (d->parentAttached && d->parentAttached->isMoving()) {
966
984
        // while moving, we cannot select any items
967
985
        return;
968
986
    }
975
993
        if (d->swiped) {
976
994
            UCActionPanel::grabPanel(&d->leadingPanel, this, true);
977
995
            UCActionPanel::grabPanel(&d->trailingPanel, this, false);
978
 
            if (d->attachedProperties) {
979
 
                d->attachedProperties->disableInteractive(this, true);
 
996
            if (d->parentAttached) {
 
997
                d->parentAttached->disableInteractive(this, true);
980
998
            }
981
999
        }
982
1000
    }
991
1009
    // set released
992
1010
    if (d->highlighted) {
993
1011
        d->listenToRebind(false);
994
 
        if (d->attachedProperties) {
995
 
            d->attachedProperties->disableInteractive(this, false);
 
1012
        if (d->parentAttached) {
 
1013
            d->parentAttached->disableInteractive(this, false);
996
1014
        }
997
1015
 
998
1016
        if (!d->suppressClick) {
1027
1045
            // still in use in other panels. See UCListItemActionsPrivate::connectToListItem
1028
1046
            leadingAttached = UCActionPanel::grabPanel(&d->leadingPanel, this, true);
1029
1047
            trailingAttached = UCActionPanel::grabPanel(&d->trailingPanel, this, false);
1030
 
            if (d->attachedProperties) {
1031
 
                d->attachedProperties->disableInteractive(this, true);
 
1048
            // unlock contentItem's left/right edges
 
1049
            d->lockContentItem(false);
 
1050
            if (d->parentAttached) {
 
1051
                d->parentAttached->disableInteractive(this, true);
1032
1052
            }
1033
1053
            // create animator if not created yet
1034
1054
            if (!d->animator) {