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

« back to all changes in this revision

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

  • Committer: Zsombor Egri
  • Date: 2015-01-08 12:08:22 UTC
  • mfrom: (1363.3.13 77-pressandhold)
  • Revision ID: zsombor.egri@canonical.com-20150108120822-gsld0der0d7pcetz
prereq sync

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
    if (!snap) {
89
89
        // no animation, so we simply position the component
90
90
        listItem->contentItem->setX(to);
 
91
        // lock contentItem left/right edges
 
92
        listItem->lockContentItem(true);
91
93
        return false;
92
94
    }
93
95
    snap->setTargetObject(listItem->contentItem);
134
136
        QObject::disconnect(snap, 0, 0, 0);
135
137
    }
136
138
    UCListItemPrivate *listItem = UCListItemPrivate::get(item);
137
 
    if (listItem->attachedProperties) {
 
139
    if (listItem->parentAttached) {
138
140
        // restore flickable's interactive and cleanup
139
 
        listItem->attachedProperties->disableInteractive(item, false);
 
141
        listItem->parentAttached->disableInteractive(item, false);
140
142
        // no need to listen flickables any longer
141
143
        listItem->listenToRebind(false);
142
144
    }
145
147
    UCActionPanel::ungrabPanel(listItem->trailingPanel);
146
148
    // set contentMoved to false
147
149
    listItem->setContentMoving(false);
 
150
    // lock contentItem left/right edges
 
151
    listItem->lockContentItem(true);
148
152
}
149
153
 
150
154
/*
213
217
        m_rightMargin = UCUnits::instance().dp(2);
214
218
    }
215
219
    if (m_listItem) {
 
220
        m_listItem->adjustContentItemHeight();
216
221
        m_listItem->update();
217
222
    }
218
223
}
276
281
        return;
277
282
    }
278
283
    m_visible = visible;
279
 
    m_listItem->resize();
280
 
    m_listItem->update();
281
284
    Q_EMIT visibleChanged();
 
285
    // set/reset contentItem's bottomMargin
 
286
    m_listItem->adjustContentItemHeight();
282
287
}
283
288
 
284
289
void UCListItemDivider::setLeftMargin(qreal leftMargin)
344
349
    , overshoot(0)
345
350
    , color(Qt::transparent)
346
351
    , highlightColor(Qt::transparent)
347
 
    , attachedProperties(0)
 
352
    , parentAttached(0)
348
353
    , contentItem(new QQuickItem)
349
354
    , divider(new UCListItemDivider)
350
355
    , leadingActions(0)
605
610
// connects/disconnects from the Flickable anchestor to get notified when to do rebound
606
611
void UCListItemPrivate::listenToRebind(bool listen)
607
612
{
608
 
    if (attachedProperties) {
 
613
    if (parentAttached) {
609
614
        Q_Q(UCListItem);
610
 
        attachedProperties->listenToRebind(q, listen);
611
 
    }
612
 
}
613
 
 
614
 
void UCListItemPrivate::resize()
615
 
{
616
 
    Q_Q(UCListItem);
617
 
    QRectF rect(q->boundingRect());
618
 
    if (divider && divider->m_visible) {
619
 
        rect.setHeight(rect.height() - divider->m_thickness);
620
 
    }
621
 
    contentItem->setSize(rect.size());
 
615
        parentAttached->listenToRebind(q, listen);
 
616
    }
 
617
}
 
618
 
 
619
// lock/unlock contentItem's left and right anchors to the ListItem's left and right
 
620
void UCListItemPrivate::lockContentItem(bool lock)
 
621
{
 
622
    QQuickAnchors *contentAnchors = QQuickItemPrivate::get(contentItem)->anchors();
 
623
    if (lock) {
 
624
        contentAnchors->setLeft(left());
 
625
        contentAnchors->setRight(right());
 
626
    } else {
 
627
        contentAnchors->resetLeft();
 
628
        contentAnchors->resetRight();
 
629
    }
 
630
}
 
631
 
 
632
// adjust contentItem height depending on teh divider's visibility
 
633
void UCListItemPrivate::adjustContentItemHeight()
 
634
{
 
635
    QQuickAnchors *contentAnchors = QQuickItemPrivate::get(contentItem)->anchors();
 
636
    if (divider->m_visible) {
 
637
        contentAnchors->setBottomMargin(divider->m_thickness);
 
638
    } else {
 
639
        contentAnchors->resetBottomMargin();
 
640
    }
622
641
}
623
642
 
624
643
void UCListItemPrivate::update()
847
866
{
848
867
    UCStyledItemBase::componentComplete();
849
868
    Q_D(UCListItem);
 
869
    // anchor contentItem prior doing anything else
 
870
    QQuickAnchors *contentAnchors = QQuickItemPrivate::get(d->contentItem)->anchors();
 
871
    contentAnchors->setTop(d->top());
 
872
    contentAnchors->setBottom(d->bottom());
 
873
    d->adjustContentItemHeight();
 
874
    d->lockContentItem(true);
 
875
 
850
876
    d->ready = true;
851
877
    /* We only deal with ListView, as for other cases we would need to check the children
852
878
     * changes, which would have an enormous impact on performance in case of huge amount
882
908
        // attach ListItem properties to the flickable or to the parent item
883
909
        if (d->flickable) {
884
910
            // connect to flickable to get width changes
885
 
            d->attachedProperties = static_cast<UCViewItemsAttached*>(qmlAttachedPropertiesObject<UCViewItemsAttached>(d->flickable));
 
911
            d->parentAttached = static_cast<UCViewItemsAttached*>(qmlAttachedPropertiesObject<UCViewItemsAttached>(d->flickable));
886
912
        } else if (data.item) {
887
 
            d->attachedProperties = static_cast<UCViewItemsAttached*>(qmlAttachedPropertiesObject<UCViewItemsAttached>(data.item));
 
913
            d->parentAttached = static_cast<UCViewItemsAttached*>(qmlAttachedPropertiesObject<UCViewItemsAttached>(data.item));
888
914
        } else {
889
915
            // mark as not ready, so no action should be performed which depends on readyness
890
916
            d->ready = false;
891
917
            // about to be deleted or reparented, disable attached
892
 
            d->attachedProperties = 0;
 
918
            d->parentAttached = 0;
893
919
        }
894
920
 
895
921
        if (data.item) {
901
927
    }
902
928
}
903
929
 
904
 
void UCListItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
905
 
{
906
 
    UCStyledItemBase::geometryChanged(newGeometry, oldGeometry);
907
 
    // resize contentItem item
908
 
    Q_D(UCListItem);
909
 
    d->resize();
910
 
}
911
 
 
912
930
QSGNode *UCListItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data)
913
931
{
914
932
    Q_UNUSED(data);
965
983
{
966
984
    UCStyledItemBase::mousePressEvent(event);
967
985
    Q_D(UCListItem);
968
 
    if (d->attachedProperties && d->attachedProperties->isMoving()) {
 
986
    if (d->parentAttached && d->parentAttached->isMoving()) {
969
987
        // while moving, we cannot select any items
970
988
        return;
971
989
    }
979
997
        if (d->swiped) {
980
998
            UCActionPanel::grabPanel(&d->leadingPanel, this, true);
981
999
            UCActionPanel::grabPanel(&d->trailingPanel, this, false);
982
 
            if (d->attachedProperties) {
983
 
                d->attachedProperties->disableInteractive(this, true);
 
1000
            if (d->parentAttached) {
 
1001
                d->parentAttached->disableInteractive(this, true);
984
1002
            }
985
1003
        }
986
1004
    }
995
1013
    // set released
996
1014
    if (d->highlighted) {
997
1015
        d->listenToRebind(false);
998
 
        if (d->attachedProperties) {
999
 
            d->attachedProperties->disableInteractive(this, false);
 
1016
        if (d->parentAttached) {
 
1017
            d->parentAttached->disableInteractive(this, false);
1000
1018
        }
1001
1019
 
1002
1020
        if (!d->suppressClick) {
1036
1054
            // still in use in other panels. See UCListItemActionsPrivate::connectToListItem
1037
1055
            leadingAttached = UCActionPanel::grabPanel(&d->leadingPanel, this, true);
1038
1056
            trailingAttached = UCActionPanel::grabPanel(&d->trailingPanel, this, false);
1039
 
            if (d->attachedProperties) {
1040
 
                d->attachedProperties->disableInteractive(this, true);
 
1057
            // unlock contentItem's left/right edges
 
1058
            d->lockContentItem(false);
 
1059
            if (d->parentAttached) {
 
1060
                d->parentAttached->disableInteractive(this, true);
1041
1061
            }
1042
1062
            // create animator if not created yet
1043
1063
            if (!d->animator) {