diff options
Diffstat (limited to 'src/declarative/graphicsitems')
8 files changed, 163 insertions, 45 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicsanchors.cpp b/src/declarative/graphicsitems/qmlgraphicsanchors.cpp index 404daad..f6dc5fd 100644 --- a/src/declarative/graphicsitems/qmlgraphicsanchors.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsanchors.cpp @@ -152,13 +152,23 @@ void QmlGraphicsAnchorsPrivate::fillChanged() if (!fill || !isItemComplete()) return; - if (fill == item->parentItem()) { //child-parent - setItemPos(QPointF(leftMargin, topMargin)); - } else if (fill->parentItem() == item->parentItem()) { //siblings - setItemPos(QPointF(fill->x()+leftMargin, fill->y()+topMargin)); + if (updatingFill < 2) { + ++updatingFill; + + if (fill == item->parentItem()) { //child-parent + setItemPos(QPointF(leftMargin, topMargin)); + } else if (fill->parentItem() == item->parentItem()) { //siblings + setItemPos(QPointF(fill->x()+leftMargin, fill->y()+topMargin)); + } + setItemWidth(fill->width()-leftMargin-rightMargin); + setItemHeight(fill->height()-topMargin-bottomMargin); + + --updatingFill; + } else { + // ### Make this certain :) + qmlInfo(QmlGraphicsAnchors::tr("Possible anchor loop detected on fill."), item); } - setItemWidth(fill->width()-leftMargin-rightMargin); - setItemHeight(fill->height()-topMargin-bottomMargin); + } void QmlGraphicsAnchorsPrivate::centerInChanged() @@ -166,16 +176,25 @@ void QmlGraphicsAnchorsPrivate::centerInChanged() if (!centerIn || fill || !isItemComplete()) return; - if (centerIn == item->parentItem()) { - QPointF p((item->parentItem()->width() - item->width()) / 2., - (item->parentItem()->height() - item->height()) / 2.); - setItemPos(p); + if (updatingCenterIn < 2) { + ++updatingCenterIn; - } else if (centerIn->parentItem() == item->parentItem()) { + if (centerIn == item->parentItem()) { + QPointF p((item->parentItem()->width() - item->width()) / 2., + (item->parentItem()->height() - item->height()) / 2.); + setItemPos(p); - QPointF p(centerIn->x() + (centerIn->width() - item->width()) / 2., - centerIn->y() + (centerIn->height() - item->height()) / 2.); - setItemPos(p); + } else if (centerIn->parentItem() == item->parentItem()) { + + QPointF p(centerIn->x() + (centerIn->width() - item->width()) / 2., + centerIn->y() + (centerIn->height() - item->height()) / 2.); + setItemPos(p); + } + + --updatingCenterIn; + } else { + // ### Make this certain :) + qmlInfo(QmlGraphicsAnchors::tr("Possible anchor loop detected on centerIn."), item); } } diff --git a/src/declarative/graphicsitems/qmlgraphicsanchors_p_p.h b/src/declarative/graphicsitems/qmlgraphicsanchors_p_p.h index 5f8b2c1..d21d9c5 100644 --- a/src/declarative/graphicsitems/qmlgraphicsanchors_p_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsanchors_p_p.h @@ -89,7 +89,7 @@ class QmlGraphicsAnchorsPrivate : public QObjectPrivate public: QmlGraphicsAnchorsPrivate() : updatingMe(false), updatingHorizontalAnchor(0), - updatingVerticalAnchor(0), item(0), usedAnchors(0), fill(0), + updatingVerticalAnchor(0), updatingFill(0), updatingCenterIn(0), item(0), usedAnchors(0), fill(0), centerIn(0), leftMargin(0), rightMargin(0), topMargin(0), bottomMargin(0), vCenterOffset(0), hCenterOffset(0), baselineOffset(0), componentComplete(true) @@ -109,6 +109,8 @@ public: bool updatingMe; int updatingHorizontalAnchor; int updatingVerticalAnchor; + int updatingFill; + int updatingCenterIn; void setItemHeight(qreal); void setItemWidth(qreal); diff --git a/src/declarative/graphicsitems/qmlgraphicsflickable.cpp b/src/declarative/graphicsitems/qmlgraphicsflickable.cpp index b030495..ea9c173 100644 --- a/src/declarative/graphicsitems/qmlgraphicsflickable.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsflickable.cpp @@ -1177,7 +1177,7 @@ void QmlGraphicsFlickable::setMaximumFlickVelocity(qreal v) } /*! - \qmlproperty real Flickable::maximumFlickVelocity + \qmlproperty real Flickable::flickDeceleration This property holds the rate at which a flick will decelerate. The default is 500. diff --git a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp index 7427266..f39f5c7 100644 --- a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp @@ -1154,7 +1154,7 @@ void QmlGraphicsGridView::keyPressEvent(QKeyEvent *event) } /*! - \qmlmethod GridView::moveCurrentIndexUp + \qmlmethod GridView::moveCurrentIndexUp() Move the currentIndex up one item in the view. The current index will wrap if keyNavigationWraps is true and it @@ -1177,7 +1177,7 @@ void QmlGraphicsGridView::moveCurrentIndexUp() } /*! - \qmlmethod GridView::moveCurrentIndexDown + \qmlmethod GridView::moveCurrentIndexDown() Move the currentIndex down one item in the view. The current index will wrap if keyNavigationWraps is true and it @@ -1200,7 +1200,7 @@ void QmlGraphicsGridView::moveCurrentIndexDown() } /*! - \qmlmethod GridView::moveCurrentIndexLeft + \qmlmethod GridView::moveCurrentIndexLeft() Move the currentIndex left one item in the view. The current index will wrap if keyNavigationWraps is true and it @@ -1223,7 +1223,7 @@ void QmlGraphicsGridView::moveCurrentIndexLeft() } /*! - \qmlmethod GridView::moveCurrentIndexRight + \qmlmethod GridView::moveCurrentIndexRight() Move the currentIndex right one item in the view. The current index will wrap if keyNavigationWraps is true and it diff --git a/src/declarative/graphicsitems/qmlgraphicsitem.cpp b/src/declarative/graphicsitems/qmlgraphicsitem.cpp index 77e6db8..572aa98 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsitem.cpp @@ -389,6 +389,76 @@ void QmlGraphicsItemKeyFilter::componentComplete() if (m_next) m_next->componentComplete(); } + +/*! + \qmlclass KeyNavigation + \brief The KeyNavigation attached property supports key navigation by arrow keys. + + It is common in key-based UIs to use arrow keys to navigate + between focussed items. The KeyNavigation property provides a + convenient way of specifying which item will gain focus + when an arrow key is pressed. The following example provides + key navigation for a 2x2 grid of items. + + \code + Grid { + columns: 2 + width: 100; height: 100 + Rectangle { + id: item1 + focus: true + width: 50; height: 50 + color: focus ? "red" : "lightgray" + KeyNavigation.right: item2 + KeyNavigation.down: item3 + } + Rectangle { + id: item2 + width: 50; height: 50 + color: focus ? "red" : "lightgray" + KeyNavigation.left: item1 + KeyNavigation.down: item4 + } + Rectangle { + id: item3 + width: 50; height: 50 + color: focus ? "red" : "lightgray" + KeyNavigation.right: item4 + KeyNavigation.up: item1 + } + Rectangle { + id: item4 + width: 50; height: 50 + color: focus ? "red" : "lightgray" + KeyNavigation.left: item3 + KeyNavigation.up: item2 + } + } + \endcode + + KeyNavigation receives key events after the item it is attached to. + If the item accepts an arrow key event, the KeyNavigation + attached property will not receive an event for that key. + + If an item has been set for a direction and the KeyNavigation + attached property receives the corresponding + key press and release events, the events will be accepted by + KeyNaviagtion and will not propagate any further. + + \sa {Keys}{Keys attached property} +*/ + +/*! + \qmlproperty Item KeyNavigation::left + \qmlproperty Item KeyNavigation::right + \qmlproperty Item KeyNavigation::up + \qmlproperty Item KeyNavigation::down + + These properties hold the item to assign focus to + when Key_Left, Key_Right, Key_Up or Key_Down are + pressed. +*/ + class QmlGraphicsKeyNavigationAttachedPrivate : public QObjectPrivate { public: @@ -606,7 +676,7 @@ void QmlGraphicsKeyNavigationAttached::keyReleased(QKeyEvent *event) See \l {Qt::Key}{Qt.Key} for the list of keyboard codes. - \sa KeyEvent + \sa KeyEvent, {KeyNavigation}{KeyNavigation attached property} */ /*! @@ -1119,7 +1189,7 @@ void QmlGraphicsKeysAttached::keyPressed(QKeyEvent *event) // If we specifically handle a key then default to accepted ke.setAccepted(true); int idx = QmlGraphicsKeysAttached::staticMetaObject.indexOfSignal(keySignal); - metaObject()->method(idx).invoke(this, Q_ARG(QmlGraphicsKeysAttached, &ke)); + metaObject()->method(idx).invoke(this, Qt::DirectConnection, Q_ARG(QmlGraphicsKeyEvent*, &ke)); } } if (!ke.isAccepted()) @@ -1838,6 +1908,17 @@ void QmlGraphicsItem::setClip(bool c) */ /*! + \qmlproperty bool Item::visible + + Whether the item is visible. By default this is true. + + \note visible is not linked to actual visibility; if you item + goes off screen, or the opacity changes to 0, etc this will + not affect the visible property. +*/ + + +/*! This function is called to handle this item's changes in geometry from \a oldGeometry to \a newGeometry. If the two geometries are the same, it doesn't do anything. diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index 1f5d51d..53287a6 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -434,7 +434,6 @@ void QmlGraphicsListViewPrivate::clear() visibleIndex = 0; releaseItem(currentItem); currentItem = 0; - currentIndex = -1; createHighlight(); trackedItem = 0; } @@ -746,7 +745,7 @@ void QmlGraphicsListViewPrivate::updateCurrentSection() void QmlGraphicsListViewPrivate::updateCurrent(int modelIndex) { Q_Q(QmlGraphicsListView); - if (!isValid() || modelIndex < 0 || modelIndex >= model->count()) { + if (!q->isComponentComplete() || !isValid() || modelIndex < 0 || modelIndex >= model->count()) { if (currentItem) { currentItem->attached->setIsCurrentItem(false); releaseItem(currentItem); @@ -1114,16 +1113,20 @@ void QmlGraphicsListView::setModel(const QVariant &model) dataModel->setModel(model); } if (d->model) { - if (d->currentIndex >= d->model->count() || d->currentIndex < 0) - setCurrentIndex(0); - else - d->updateCurrent(d->currentIndex); + if (isComponentComplete()) { + refill(); + if (d->currentIndex >= d->model->count() || d->currentIndex < 0) { + setCurrentIndex(0); + } else { + d->moveReason = QmlGraphicsListViewPrivate::SetIndex; + d->updateCurrent(d->currentIndex); + } + } connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int))); connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int))); connect(d->model, SIGNAL(itemsMoved(int,int,int)), this, SLOT(itemsMoved(int,int,int))); connect(d->model, SIGNAL(createdItem(int, QmlGraphicsItem*)), this, SLOT(createdItem(int,QmlGraphicsItem*))); connect(d->model, SIGNAL(destroyingItem(QmlGraphicsItem*)), this, SLOT(destroyingItem(QmlGraphicsItem*))); - refill(); emit countChanged(); } } @@ -1156,8 +1159,11 @@ void QmlGraphicsListView::setDelegate(QmlComponent *delegate) } if (QmlGraphicsVisualDataModel *dataModel = qobject_cast<QmlGraphicsVisualDataModel*>(d->model)) { dataModel->setDelegate(delegate); - d->updateCurrent(d->currentIndex); - refill(); + if (isComponentComplete()) { + refill(); + d->moveReason = QmlGraphicsListViewPrivate::SetIndex; + d->updateCurrent(d->currentIndex); + } } } @@ -1178,7 +1184,7 @@ int QmlGraphicsListView::currentIndex() const void QmlGraphicsListView::setCurrentIndex(int index) { Q_D(QmlGraphicsListView); - if (d->isValid() && index != d->currentIndex && index < d->model->count() && index >= 0) { + if (isComponentComplete() && d->isValid() && index != d->currentIndex && index < d->model->count() && index >= 0) { d->moveReason = QmlGraphicsListViewPrivate::SetIndex; cancelFlick(); d->updateCurrent(index); @@ -1254,7 +1260,7 @@ void QmlGraphicsListView::setHighlight(QmlComponent *highlight) is scrolled. This is because the view moves to maintain the highlight within the preferred highlight range (or visible viewport). - \sa highlight + \sa highlight, highlightMoveSpeed */ bool QmlGraphicsListView::highlightFollowsCurrentItem() const { @@ -1473,8 +1479,13 @@ QString QmlGraphicsListView::currentSection() const /*! \qmlproperty real ListView::highlightMoveSpeed + \qmlproperty real ListView::highlightResizeSpeed + These properties hold the move and resize animation speed of the highlight delegate. + + highlightFollowsCurrentItem must be true for these properties + to have effect. - This property holds the moving animation speed of the highlight delegate. + \sa highlightFollowsCurrentItem */ qreal QmlGraphicsListView::highlightMoveSpeed() const { @@ -1488,15 +1499,12 @@ void QmlGraphicsListView::setHighlightMoveSpeed(qreal speed) if (d->highlightMoveSpeed != speed) { d->highlightMoveSpeed = speed; + if (d->highlightPosAnimator) + d->highlightPosAnimator->setVelocity(d->highlightMoveSpeed); emit highlightMoveSpeedChanged(); } } -/*! - \qmlproperty real ListView::highlightResizeSpeed - - This property holds the resizing animation speed of the highlight delegate. -*/ qreal QmlGraphicsListView::highlightResizeSpeed() const { Q_D(const QmlGraphicsListView);\ @@ -1509,6 +1517,8 @@ void QmlGraphicsListView::setHighlightResizeSpeed(qreal speed) if (d->highlightResizeSpeed != speed) { d->highlightResizeSpeed = speed; + if (d->highlightSizeAnimator) + d->highlightSizeAnimator->setVelocity(d->highlightResizeSpeed); emit highlightResizeSpeedChanged(); } } @@ -1666,9 +1676,11 @@ void QmlGraphicsListView::componentComplete() { Q_D(QmlGraphicsListView); QmlGraphicsFlickable::componentComplete(); + refill(); if (d->currentIndex < 0) d->updateCurrent(0); - refill(); + else + d->updateCurrent(d->currentIndex); d->fixupPosition(); } @@ -1748,6 +1760,7 @@ void QmlGraphicsListView::itemsInserted(int modelIndex, int count) d->updateUnrequestedIndexes(); if (!d->visibleItems.count() || d->model->count() <= 1) { d->layout(); + d->updateSections(); d->updateCurrent(qMax(0, qMin(d->currentIndex, d->model->count()-1))); emit countChanged(); return; @@ -1827,6 +1840,7 @@ void QmlGraphicsListView::itemsInserted(int modelIndex, int count) added.at(j)->attached->emitAdd(); d->updateUnrequestedPositions(); d->updateViewport(); + d->updateSections(); emit countChanged(); } @@ -2009,6 +2023,7 @@ void QmlGraphicsListView::itemsMoved(int from, int to, int count) d->visibleItems.first()->setPosition(firstItemPos); d->layout(); + d->updateSections(); } void QmlGraphicsListView::createdItem(int index, QmlGraphicsItem *item) diff --git a/src/declarative/graphicsitems/qmlgraphicslistview_p.h b/src/declarative/graphicsitems/qmlgraphicslistview_p.h index 446d71a..3f46434 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview_p.h +++ b/src/declarative/graphicsitems/qmlgraphicslistview_p.h @@ -64,8 +64,11 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsListView : public QmlGraphicsFlickable Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) Q_PROPERTY(QmlGraphicsItem *currentItem READ currentItem NOTIFY currentIndexChanged) Q_PROPERTY(int count READ count NOTIFY countChanged) + Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem) + Q_PROPERTY(qreal highlightMoveSpeed READ highlightMoveSpeed WRITE setHighlightMoveSpeed NOTIFY highlightMoveSpeedChanged) + Q_PROPERTY(qreal highlightResizeSpeed READ highlightResizeSpeed WRITE setHighlightResizeSpeed NOTIFY highlightResizeSpeedChanged) Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin) Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd) @@ -78,8 +81,6 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsListView : public QmlGraphicsFlickable Q_PROPERTY(QString sectionExpression READ sectionExpression WRITE setSectionExpression NOTIFY sectionExpressionChanged) Q_PROPERTY(QString currentSection READ currentSection NOTIFY currentSectionChanged) - Q_PROPERTY(qreal highlightMoveSpeed READ highlightMoveSpeed WRITE setHighlightMoveSpeed NOTIFY highlightMoveSpeedChanged) - Q_PROPERTY(qreal highlightResizeSpeed READ highlightResizeSpeed WRITE setHighlightResizeSpeed NOTIFY highlightResizeSpeedChanged) Q_ENUMS(HighlightRangeMode) Q_ENUMS(Orientation) Q_CLASSINFO("DefaultProperty", "data") diff --git a/src/declarative/graphicsitems/qmlgraphicsmouseregion.cpp b/src/declarative/graphicsitems/qmlgraphicsmouseregion.cpp index 196cdf2..22c2c0a 100644 --- a/src/declarative/graphicsitems/qmlgraphicsmouseregion.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsmouseregion.cpp @@ -146,19 +146,19 @@ void QmlGraphicsDrag::setYmax(qreal m) */ /*! - \qmlsignal MouseRegion::onEntered + \qmlsignal MouseRegion::onEntered() This handler is called when the mouse enters the mouse region. */ /*! - \qmlsignal MouseRegion::onExited + \qmlsignal MouseRegion::onExited() This handler is called when the mouse exists the mouse region. */ /*! - \qmlsignal MouseRegion::onPositionChanged(mouse) + \qmlsignal MouseRegion::onPositionChanged(MouseEvent mouse) This handler is called when the mouse position changes. |