diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-12-02 01:09:30 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-12-02 01:09:30 (GMT) |
commit | b19da8b1a46d1de3a1a13c150adbc316da3e12b6 (patch) | |
tree | f7f64932cac89e42ff16fceb622287b3469ceeeb /src/declarative | |
parent | 0eb70ae512c68fed6caf6f9b4bc8675b90100acf (diff) | |
parent | f2cb650fd28d8bb67666de409f26807a2cf1d852 (diff) | |
download | Qt-b19da8b1a46d1de3a1a13c150adbc316da3e12b6.zip Qt-b19da8b1a46d1de3a1a13c150adbc316da3e12b6.tar.gz Qt-b19da8b1a46d1de3a1a13c150adbc316da3e12b6.tar.bz2 |
Merge branch 'kinetic-declarativeui' of scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/declarative')
8 files changed, 204 insertions, 13 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicsflickable.cpp b/src/declarative/graphicsitems/qmlgraphicsflickable.cpp index e010081..d827cda 100644 --- a/src/declarative/graphicsitems/qmlgraphicsflickable.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsflickable.cpp @@ -162,6 +162,7 @@ QmlGraphicsFlickablePrivate::QmlGraphicsFlickablePrivate() , interactive(true), deceleration(500), maxVelocity(5000), reportedVelocitySmoothing(100) , delayedPressEvent(0), delayedPressTarget(0), pressDelay(0) , horizontalVelocity(this), verticalVelocity(this), vTime(0), visibleArea(0) + , flickDirection(QmlGraphicsFlickable::AutoFlickDirection) { fixupXEvent = QmlTimeLineEvent::timeLineEvent<QmlGraphicsFlickablePrivate, &QmlGraphicsFlickablePrivate::fixupX>(&_moveX, this); fixupYEvent = QmlTimeLineEvent::timeLineEvent<QmlGraphicsFlickablePrivate, &QmlGraphicsFlickablePrivate::fixupY>(&_moveY, this); @@ -576,6 +577,36 @@ QmlGraphicsFlickableVisibleArea *QmlGraphicsFlickable::visibleArea() return d->visibleArea; } +/*! + \qmlproperty enumeration Flickable::flickDirection + + This property determines which directions the view can be flicked. + + \list + \o AutoFlickDirection (default) - allows flicking vertically if the + \e viewportHeight is not equal to the \e height of the Flickable. + Allows flicking horizontally if the \e viewportWidth is not equal + to the \e width of the Flickable. + \o HorizontalFlick - allows flicking horizontally. + \o VerticalFlick - allows flicking vertically. + \o HorizontalAndVerticalFlick - allows flicking in both directions. + \endlist +*/ +QmlGraphicsFlickable::FlickDirection QmlGraphicsFlickable::flickDirection() const +{ + Q_D(const QmlGraphicsFlickable); + return d->flickDirection; +} + +void QmlGraphicsFlickable::setFlickDirection(FlickDirection direction) +{ + Q_D(QmlGraphicsFlickable); + if (direction != d->flickDirection) { + d->flickDirection = direction; + emit flickDirectionChanged(); + } +} + void QmlGraphicsFlickablePrivate::handleMousePressEvent(QGraphicsSceneMouseEvent *event) { if (interactive && timeline.isActive() && (qAbs(velocityX) > 10 || qAbs(velocityY) > 10)) @@ -1039,12 +1070,18 @@ qreal QmlGraphicsFlickable::vHeight() const bool QmlGraphicsFlickable::xflick() const { - return vWidth() != width(); + Q_D(const QmlGraphicsFlickable); + if (d->flickDirection == QmlGraphicsFlickable::AutoFlickDirection) + return vWidth() != width(); + return d->flickDirection & QmlGraphicsFlickable::HorizontalFlick; } bool QmlGraphicsFlickable::yflick() const { - return vHeight() != height(); + Q_D(const QmlGraphicsFlickable); + if (d->flickDirection == QmlGraphicsFlickable::AutoFlickDirection) + return vHeight() != height(); + return d->flickDirection & QmlGraphicsFlickable::VerticalFlick; } bool QmlGraphicsFlickable::sendMouseEvent(QGraphicsSceneMouseEvent *event) diff --git a/src/declarative/graphicsitems/qmlgraphicsflickable_p.h b/src/declarative/graphicsitems/qmlgraphicsflickable_p.h index 50248e1..9610ac1 100644 --- a/src/declarative/graphicsitems/qmlgraphicsflickable_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsflickable_p.h @@ -70,6 +70,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsFlickable : public QmlGraphicsItem Q_PROPERTY(qreal flickDeceleration READ flickDeceleration WRITE setFlickDeceleration) Q_PROPERTY(bool moving READ isMoving NOTIFY movingChanged) Q_PROPERTY(bool flicking READ isFlicking NOTIFY flickingChanged) + Q_PROPERTY(FlickDirection flickDirection READ flickDirection WRITE setFlickDirection NOTIFY flickDirectionChanged) Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive) Q_PROPERTY(int pressDelay READ pressDelay WRITE setPressDelay) @@ -85,6 +86,8 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsFlickable : public QmlGraphicsItem Q_PROPERTY(QmlList<QmlGraphicsItem *>* flickableChildren READ flickableChildren) Q_CLASSINFO("DefaultProperty", "flickableData") + Q_ENUMS(FlickDirection) + public: QmlGraphicsFlickable(QmlGraphicsItem *parent=0); ~QmlGraphicsFlickable(); @@ -135,6 +138,10 @@ public: QmlGraphicsItem *viewport(); + enum FlickDirection { AutoFlickDirection=0x00, HorizontalFlick=0x01, VerticalFlick=0x02, HorizontalAndVerticalFlick=0x03 }; + FlickDirection flickDirection() const; + void setFlickDirection(FlickDirection); + Q_SIGNALS: void viewportWidthChanged(); void viewportHeightChanged(); @@ -151,6 +158,7 @@ Q_SIGNALS: void verticalVelocityChanged(); void isAtBoundaryChanged(); void pageChanged(); + void flickDirectionChanged(); protected: virtual bool sceneEventFilter(QGraphicsItem *, QEvent *); diff --git a/src/declarative/graphicsitems/qmlgraphicsflickable_p_p.h b/src/declarative/graphicsitems/qmlgraphicsflickable_p_p.h index 8044ba7..5ccdaad 100644 --- a/src/declarative/graphicsitems/qmlgraphicsflickable_p_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsflickable_p_p.h @@ -134,6 +134,7 @@ public: int vTime; QmlTimeLine velocityTimeline; QmlGraphicsFlickableVisibleArea *visibleArea; + QmlGraphicsFlickable::FlickDirection flickDirection; void handleMousePressEvent(QGraphicsSceneMouseEvent *); void handleMouseMoveEvent(QGraphicsSceneMouseEvent *); diff --git a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp index 81128e7..4e2a366 100644 --- a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp @@ -327,6 +327,7 @@ void QmlGraphicsGridViewPrivate::init() q->setFlag(QGraphicsItem::ItemIsFocusScope); QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(sizeChange())); QObject::connect(q, SIGNAL(heightChanged()), q, SLOT(sizeChange())); + q->setFlickDirection(QmlGraphicsFlickable::VerticalFlick); } void QmlGraphicsGridViewPrivate::clear() @@ -1014,10 +1015,13 @@ void QmlGraphicsGridView::setFlow(Flow flow) Q_D(QmlGraphicsGridView); if (d->flow != flow) { d->flow = flow; - if (d->flow == LeftToRight) + if (d->flow == LeftToRight) { setViewportWidth(-1); - else + setFlickDirection(QmlGraphicsFlickable::VerticalFlick); + } else { setViewportHeight(-1); + setFlickDirection(QmlGraphicsFlickable::HorizontalFlick); + } d->clear(); d->updateGrid(); refill(); diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index 9dd2ab4..6958f7f 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -178,6 +178,7 @@ public: , moveReason(Other), buffer(0), highlightPosAnimator(0), highlightSizeAnimator(0), spacing(0.0) , highlightMoveSpeed(400), highlightResizeSpeed(400), highlightRange(QmlGraphicsListView::NoHighlightRange) , snapMode(QmlGraphicsListView::NoSnap), overshootDist(0.0) + , footerComponent(0), footer(0), headerComponent(0), header(0) , ownModel(false), wrap(false), autoHighlight(true), haveHighlightRange(false) , correctFlick(true) {} @@ -209,7 +210,6 @@ public: } FxListItem *nextVisibleItem() const { - qDebug() << "last vis"; const qreal pos = position(); bool foundFirst = false; for (int i = 0; i < visibleItems.count(); ++i) { @@ -404,9 +404,9 @@ public: void updateViewport() { Q_Q(QmlGraphicsListView); if (orient == QmlGraphicsListView::Vertical) - q->setViewportHeight(endPosition() - startPosition()); + q->setViewportHeight(q->minYExtent() - q->maxYExtent()); else - q->setViewportWidth(endPosition() - startPosition()); + q->setViewportWidth(q->minXExtent() - q->maxXExtent()); } @@ -434,6 +434,8 @@ public: void updateCurrentSection(); void updateCurrent(int); void updateAverage(); + void updateHeader(); + void updateFooter(); void fixupPosition(); virtual void fixupY(); virtual void fixupX(); @@ -469,6 +471,10 @@ public: QmlGraphicsListView::HighlightRangeMode highlightRange; QmlGraphicsListView::SnapMode snapMode; qreal overshootDist; + QmlComponent *footerComponent; + FxListItem *footer; + QmlComponent *headerComponent; + FxListItem *header; bool ownModel : 1; bool wrap : 1; @@ -484,6 +490,7 @@ void QmlGraphicsListViewPrivate::init() QObject::connect(q, SIGNAL(heightChanged()), q, SLOT(refill())); QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(refill())); QObject::connect(q, SIGNAL(movementEnded()), q, SLOT(animStopped())); + q->setFlickDirection(QmlGraphicsFlickable::VerticalFlick); } void QmlGraphicsListViewPrivate::clear() @@ -491,7 +498,7 @@ void QmlGraphicsListViewPrivate::clear() for (int i = 0; i < visibleItems.count(); ++i) releaseItem(visibleItems.at(i)); visibleItems.clear(); - visiblePos = 0; + visiblePos = header ? header->size() : 0; visibleIndex = 0; releaseItem(currentItem); currentItem = 0; @@ -623,6 +630,10 @@ void QmlGraphicsListViewPrivate::refill(qreal from, qreal to) updateAverage(); if (!sectionExpression.isEmpty()) updateCurrentSection(); + if (header) + updateHeader(); + if (footer) + updateFooter(); updateViewport(); } } @@ -647,6 +658,10 @@ void QmlGraphicsListViewPrivate::layout() q->refill(); updateHighlight(); fixupPosition(); + if (header) + updateHeader(); + if (footer) + updateFooter(); updateUnrequestedPositions(); updateViewport(); } @@ -860,6 +875,66 @@ void QmlGraphicsListViewPrivate::updateAverage() averageSize = sum / visibleItems.count(); } +void QmlGraphicsListViewPrivate::updateFooter() +{ + Q_Q(QmlGraphicsListView); + if (!footer && footerComponent) { + QmlGraphicsItem *item = 0; + QmlContext *context = new QmlContext(qmlContext(q)); + QObject *nobj = footerComponent->create(context); + if (nobj) { + context->setParent(nobj); + item = qobject_cast<QmlGraphicsItem *>(nobj); + if (!item) + delete nobj; + } else { + delete context; + } + if (item) { + item->setParent(q->viewport()); + item->setZValue(1); + footer = new FxListItem(item, q); + } + } + if (footer) { + if (visibleItems.count()) + footer->setPosition(endPosition()); + else + footer->setPosition(visiblePos); + } +} + +void QmlGraphicsListViewPrivate::updateHeader() +{ + Q_Q(QmlGraphicsListView); + if (!header && headerComponent) { + QmlGraphicsItem *item = 0; + QmlContext *context = new QmlContext(qmlContext(q)); + QObject *nobj = headerComponent->create(context); + if (nobj) { + context->setParent(nobj); + item = qobject_cast<QmlGraphicsItem *>(nobj); + if (!item) + delete nobj; + } else { + delete context; + } + if (item) { + item->setParent(q->viewport()); + item->setZValue(1); + header = new FxListItem(item, q); + if (visibleItems.isEmpty()) + visiblePos = header->size(); + } + } + if (header) { + if (visibleItems.count()) + header->setPosition(startPosition() - header->size()); + else + header->setPosition(0); + } +} + void QmlGraphicsListViewPrivate::fixupPosition() { if (orient == QmlGraphicsListView::Vertical) @@ -1593,10 +1668,13 @@ void QmlGraphicsListView::setOrientation(QmlGraphicsListView::Orientation orient Q_D(QmlGraphicsListView); if (d->orient != orientation) { d->orient = orientation; - if (d->orient == QmlGraphicsListView::Vertical) + if (d->orient == QmlGraphicsListView::Vertical) { setViewportWidth(-1); - else + setFlickDirection(VerticalFlick); + } else { setViewportHeight(-1); + setFlickDirection(HorizontalFlick); + } d->clear(); refill(); emit orientationChanged(); @@ -1759,6 +1837,47 @@ void QmlGraphicsListView::setSnapMode(SnapMode mode) } } +QmlComponent *QmlGraphicsListView::footer() const +{ + Q_D(const QmlGraphicsListView); + return d->footerComponent; +} + +void QmlGraphicsListView::setFooter(QmlComponent *footer) +{ + Q_D(QmlGraphicsListView); + if (d->footerComponent != footer) { + if (d->footer) { + delete d->footer; + d->footer = 0; + } + d->footerComponent = footer; + d->updateFooter(); + d->updateViewport(); + } +} + +QmlComponent *QmlGraphicsListView::header() const +{ + Q_D(const QmlGraphicsListView); + return d->headerComponent; +} + +void QmlGraphicsListView::setHeader(QmlComponent *header) +{ + Q_D(QmlGraphicsListView); + if (d->headerComponent != header) { + if (d->header) { + delete d->header; + d->header = 0; + } + d->headerComponent = header; + d->updateHeader(); + d->updateFooter(); + d->updateViewport(); + } +} + void QmlGraphicsListView::viewportMoved() { Q_D(QmlGraphicsListView); @@ -1813,6 +1932,8 @@ qreal QmlGraphicsListView::minYExtent() const if (d->orient == QmlGraphicsListView::Horizontal) return QmlGraphicsFlickable::minYExtent(); qreal extent = -d->startPosition(); + if (d->header && d->visibleItems.count()) + extent += d->header->size(); if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) extent += d->highlightRangeStart; @@ -1829,6 +1950,8 @@ qreal QmlGraphicsListView::maxYExtent() const extent = -(d->positionAt(count()-1) - d->highlightRangeEnd); else extent = -(d->endPosition() - height() + 1); + if (d->footer) + extent -= d->footer->size(); qreal minY = minYExtent(); if (extent > minY) extent = minY; @@ -1841,6 +1964,8 @@ qreal QmlGraphicsListView::minXExtent() const if (d->orient == QmlGraphicsListView::Vertical) return QmlGraphicsFlickable::minXExtent(); qreal extent = -d->startPosition(); + if (d->header) + extent += d->header->size(); if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) extent += d->highlightRangeStart; @@ -1857,6 +1982,8 @@ qreal QmlGraphicsListView::maxXExtent() const extent = -(d->positionAt(count()-1) - d->highlightRangeEnd); else extent = -(d->endPosition() - width() + 1); + if (d->footer) + extent -= d->footer->size(); qreal minX = minXExtent(); if (extent > minX) extent = minX; @@ -2008,6 +2135,8 @@ void QmlGraphicsListView::trackedPositionChanged() pos = d->startPosition(); } else if (d->trackedItem->endPosition() > d->endPosition() - d->size() + d->highlightRangeEnd) { pos = d->endPosition() - d->size(); + if (pos < d->startPosition()) + pos = d->startPosition(); } else { if (trackedPos < viewPos + d->highlightRangeStart) { pos = trackedPos - d->highlightRangeStart; @@ -2221,7 +2350,7 @@ void QmlGraphicsListView::itemsRemoved(int modelIndex, int count) if (d->visibleItems.isEmpty()) { d->visibleIndex = 0; - d->visiblePos = 0; + d->visiblePos = d->header ? d->header->size() : 0; d->timeline.clear(); d->setPosition(0); if (d->model->count() == 0) diff --git a/src/declarative/graphicsitems/qmlgraphicslistview_p.h b/src/declarative/graphicsitems/qmlgraphicslistview_p.h index cc74056..241fb05 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview_p.h +++ b/src/declarative/graphicsitems/qmlgraphicslistview_p.h @@ -84,6 +84,9 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsListView : public QmlGraphicsFlickable Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode) + Q_PROPERTY(QmlComponent *header READ header WRITE setHeader) + Q_PROPERTY(QmlComponent *footer READ footer WRITE setFooter) + Q_ENUMS(HighlightRangeMode) Q_ENUMS(Orientation) Q_ENUMS(SnapMode) @@ -149,6 +152,12 @@ public: SnapMode snapMode() const; void setSnapMode(SnapMode mode); + QmlComponent *footer() const; + void setFooter(QmlComponent *); + + QmlComponent *header() const; + void setHeader(QmlComponent *); + static QmlGraphicsListViewAttached *qmlAttachedProperties(QObject *); public Q_SLOTS: diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 8429232..9afb81e 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -160,6 +160,10 @@ QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) scriptEngine.globalObject().setProperty(QLatin1String("createComponent"), scriptEngine.newFunction(QmlEnginePrivate::createComponent, 1)); + // translation functions need to be installed + // before the global script class is constructed (QTBUG-6437) + scriptEngine.installTranslatorFunctions(); + globalClass = new QmlGlobalScriptClass(&scriptEngine); } @@ -228,7 +232,6 @@ void QmlEnginePrivate::init() qRegisterMetaType<QmlScriptString>("QmlScriptString"); qRegisterMetaType<QScriptValue>("QScriptValue"); - scriptEngine.installTranslatorFunctions(); contextClass = new QmlContextScriptClass(q); objectClass = new QmlObjectScriptClass(q); valueTypeClass = new QmlValueTypeScriptClass(q); diff --git a/src/declarative/util/qmleasefollow.cpp b/src/declarative/util/qmleasefollow.cpp index b326f63..50758f4 100644 --- a/src/declarative/util/qmleasefollow.cpp +++ b/src/declarative/util/qmleasefollow.cpp @@ -124,7 +124,7 @@ bool QmlEaseFollowPrivate::recalc() vp = velocity; sp = 0; sd = s; - } else if (tf > (maximumEasingTime / 1000.)) { + } else if (maximumEasingTime != -1 && tf > (maximumEasingTime / 1000.)) { qreal met = maximumEasingTime / 1000.; td = tf - met; |