diff options
Diffstat (limited to 'src/declarative/graphicsitems')
40 files changed, 648 insertions, 636 deletions
diff --git a/src/declarative/graphicsitems/graphicsitems.pri b/src/declarative/graphicsitems/graphicsitems.pri index ad7ccb5..d420595 100644 --- a/src/declarative/graphicsitems/graphicsitems.pri +++ b/src/declarative/graphicsitems/graphicsitems.pri @@ -5,7 +5,6 @@ HEADERS += \ $$PWD/qdeclarativeanchors_p.h \ $$PWD/qdeclarativeanchors_p_p.h \ $$PWD/qdeclarativeevents_p_p.h \ - $$PWD/qdeclarativeeffects_p.h \ $$PWD/qdeclarativeflickable_p.h \ $$PWD/qdeclarativeflickable_p_p.h \ $$PWD/qdeclarativeflipable_p.h \ @@ -50,7 +49,6 @@ HEADERS += \ $$PWD/qdeclarativelistview_p.h \ $$PWD/qdeclarativelayoutitem_p.h \ $$PWD/qdeclarativeitemchangelistener_p.h \ - $$PWD/qdeclarativeeffects.cpp \ $$PWD/qdeclarativegraphicswidget_p.h SOURCES += \ diff --git a/src/declarative/graphicsitems/qdeclarativeanchors.cpp b/src/declarative/graphicsitems/qdeclarativeanchors.cpp index 96d0867..f15316b 100644 --- a/src/declarative/graphicsitems/qdeclarativeanchors.cpp +++ b/src/declarative/graphicsitems/qdeclarativeanchors.cpp @@ -221,31 +221,31 @@ void QDeclarativeAnchorsPrivate::clearItem(QGraphicsObject *item) centerIn = 0; if (left.item == item) { left.item = 0; - usedAnchors &= ~QDeclarativeAnchors::HasLeftAnchor; + usedAnchors &= ~QDeclarativeAnchors::LeftAnchor; } if (right.item == item) { right.item = 0; - usedAnchors &= ~QDeclarativeAnchors::HasRightAnchor; + usedAnchors &= ~QDeclarativeAnchors::RightAnchor; } if (top.item == item) { top.item = 0; - usedAnchors &= ~QDeclarativeAnchors::HasTopAnchor; + usedAnchors &= ~QDeclarativeAnchors::TopAnchor; } if (bottom.item == item) { bottom.item = 0; - usedAnchors &= ~QDeclarativeAnchors::HasBottomAnchor; + usedAnchors &= ~QDeclarativeAnchors::BottomAnchor; } if (vCenter.item == item) { vCenter.item = 0; - usedAnchors &= ~QDeclarativeAnchors::HasVCenterAnchor; + usedAnchors &= ~QDeclarativeAnchors::VCenterAnchor; } if (hCenter.item == item) { hCenter.item = 0; - usedAnchors &= ~QDeclarativeAnchors::HasHCenterAnchor; + usedAnchors &= ~QDeclarativeAnchors::HCenterAnchor; } if (baseline.item == item) { baseline.item = 0; - usedAnchors &= ~QDeclarativeAnchors::HasBaselineAnchor; + usedAnchors &= ~QDeclarativeAnchors::BaselineAnchor; } } @@ -495,13 +495,13 @@ void QDeclarativeAnchorsPrivate::updateVerticalAnchors() if (updatingVerticalAnchor < 2) { ++updatingVerticalAnchor; QGraphicsItemPrivate *itemPrivate = QGraphicsItemPrivate::get(item); - if (usedAnchors & QDeclarativeAnchors::HasTopAnchor) { + if (usedAnchors & QDeclarativeAnchors::TopAnchor) { //Handle stretching bool invalid = true; int height = 0; - if (usedAnchors & QDeclarativeAnchors::HasBottomAnchor) { + if (usedAnchors & QDeclarativeAnchors::BottomAnchor) { invalid = calcStretch(top, bottom, topMargin, -bottomMargin, QDeclarativeAnchorLine::Top, height); - } else if (usedAnchors & QDeclarativeAnchors::HasVCenterAnchor) { + } else if (usedAnchors & QDeclarativeAnchors::VCenterAnchor) { invalid = calcStretch(top, vCenter, topMargin, vCenterOffset, QDeclarativeAnchorLine::Top, height); height *= 2; } @@ -514,9 +514,9 @@ void QDeclarativeAnchorsPrivate::updateVerticalAnchors() } else if (top.item->parentItem() == item->parentItem()) { setItemY(position(top.item, top.anchorLine) + topMargin); } - } else if (usedAnchors & QDeclarativeAnchors::HasBottomAnchor) { + } else if (usedAnchors & QDeclarativeAnchors::BottomAnchor) { //Handle stretching (top + bottom case is handled above) - if (usedAnchors & QDeclarativeAnchors::HasVCenterAnchor) { + if (usedAnchors & QDeclarativeAnchors::VCenterAnchor) { int height = 0; bool invalid = calcStretch(vCenter, bottom, vCenterOffset, -bottomMargin, QDeclarativeAnchorLine::Top, height); @@ -530,7 +530,7 @@ void QDeclarativeAnchorsPrivate::updateVerticalAnchors() } else if (bottom.item->parentItem() == item->parentItem()) { setItemY(position(bottom.item, bottom.anchorLine) - itemPrivate->height() - bottomMargin); } - } else if (usedAnchors & QDeclarativeAnchors::HasVCenterAnchor) { + } else if (usedAnchors & QDeclarativeAnchors::VCenterAnchor) { //(stetching handled above) //Handle vCenter @@ -540,7 +540,7 @@ void QDeclarativeAnchorsPrivate::updateVerticalAnchors() } else if (vCenter.item->parentItem() == item->parentItem()) { setItemY(position(vCenter.item, vCenter.anchorLine) - itemPrivate->height()/2 + vCenterOffset); } - } else if (usedAnchors & QDeclarativeAnchors::HasBaselineAnchor) { + } else if (usedAnchors & QDeclarativeAnchors::BaselineAnchor) { //Handle baseline if (baseline.item == item->parentItem()) { if (itemPrivate->isDeclarativeItem) @@ -567,13 +567,13 @@ void QDeclarativeAnchorsPrivate::updateHorizontalAnchors() if (updatingHorizontalAnchor < 2) { ++updatingHorizontalAnchor; QGraphicsItemPrivate *itemPrivate = QGraphicsItemPrivate::get(item); - if (usedAnchors & QDeclarativeAnchors::HasLeftAnchor) { + if (usedAnchors & QDeclarativeAnchors::LeftAnchor) { //Handle stretching bool invalid = true; int width = 0; - if (usedAnchors & QDeclarativeAnchors::HasRightAnchor) { + if (usedAnchors & QDeclarativeAnchors::RightAnchor) { invalid = calcStretch(left, right, leftMargin, -rightMargin, QDeclarativeAnchorLine::Left, width); - } else if (usedAnchors & QDeclarativeAnchors::HasHCenterAnchor) { + } else if (usedAnchors & QDeclarativeAnchors::HCenterAnchor) { invalid = calcStretch(left, hCenter, leftMargin, hCenterOffset, QDeclarativeAnchorLine::Left, width); width *= 2; } @@ -586,9 +586,9 @@ void QDeclarativeAnchorsPrivate::updateHorizontalAnchors() } else if (left.item->parentItem() == item->parentItem()) { setItemX(position(left.item, left.anchorLine) + leftMargin); } - } else if (usedAnchors & QDeclarativeAnchors::HasRightAnchor) { + } else if (usedAnchors & QDeclarativeAnchors::RightAnchor) { //Handle stretching (left + right case is handled in updateLeftAnchor) - if (usedAnchors & QDeclarativeAnchors::HasHCenterAnchor) { + if (usedAnchors & QDeclarativeAnchors::HCenterAnchor) { int width = 0; bool invalid = calcStretch(hCenter, right, hCenterOffset, -rightMargin, QDeclarativeAnchorLine::Left, width); @@ -602,7 +602,7 @@ void QDeclarativeAnchorsPrivate::updateHorizontalAnchors() } else if (right.item->parentItem() == item->parentItem()) { setItemX(position(right.item, right.anchorLine) - itemPrivate->width() - rightMargin); } - } else if (usedAnchors & QDeclarativeAnchors::HasHCenterAnchor) { + } else if (usedAnchors & QDeclarativeAnchors::HCenterAnchor) { //Handle hCenter if (hCenter.item == item->parentItem()) { setItemX(adjustedPosition(hCenter.item, hCenter.anchorLine) - itemPrivate->width()/2 + hCenterOffset); @@ -630,10 +630,10 @@ void QDeclarativeAnchors::setTop(const QDeclarativeAnchorLine &edge) if (!d->checkVAnchorValid(edge) || d->top == edge) return; - d->usedAnchors |= HasTopAnchor; + d->usedAnchors |= TopAnchor; if (!d->checkVValid()) { - d->usedAnchors &= ~HasTopAnchor; + d->usedAnchors &= ~TopAnchor; return; } @@ -647,7 +647,7 @@ void QDeclarativeAnchors::setTop(const QDeclarativeAnchorLine &edge) void QDeclarativeAnchors::resetTop() { Q_D(QDeclarativeAnchors); - d->usedAnchors &= ~HasTopAnchor; + d->usedAnchors &= ~TopAnchor; d->remDepend(d->top.item); d->top = QDeclarativeAnchorLine(); emit topChanged(); @@ -666,10 +666,10 @@ void QDeclarativeAnchors::setBottom(const QDeclarativeAnchorLine &edge) if (!d->checkVAnchorValid(edge) || d->bottom == edge) return; - d->usedAnchors |= HasBottomAnchor; + d->usedAnchors |= BottomAnchor; if (!d->checkVValid()) { - d->usedAnchors &= ~HasBottomAnchor; + d->usedAnchors &= ~BottomAnchor; return; } @@ -683,7 +683,7 @@ void QDeclarativeAnchors::setBottom(const QDeclarativeAnchorLine &edge) void QDeclarativeAnchors::resetBottom() { Q_D(QDeclarativeAnchors); - d->usedAnchors &= ~HasBottomAnchor; + d->usedAnchors &= ~BottomAnchor; d->remDepend(d->bottom.item); d->bottom = QDeclarativeAnchorLine(); emit bottomChanged(); @@ -702,10 +702,10 @@ void QDeclarativeAnchors::setVerticalCenter(const QDeclarativeAnchorLine &edge) if (!d->checkVAnchorValid(edge) || d->vCenter == edge) return; - d->usedAnchors |= HasVCenterAnchor; + d->usedAnchors |= VCenterAnchor; if (!d->checkVValid()) { - d->usedAnchors &= ~HasVCenterAnchor; + d->usedAnchors &= ~VCenterAnchor; return; } @@ -719,7 +719,7 @@ void QDeclarativeAnchors::setVerticalCenter(const QDeclarativeAnchorLine &edge) void QDeclarativeAnchors::resetVerticalCenter() { Q_D(QDeclarativeAnchors); - d->usedAnchors &= ~HasVCenterAnchor; + d->usedAnchors &= ~VCenterAnchor; d->remDepend(d->vCenter.item); d->vCenter = QDeclarativeAnchorLine(); emit verticalCenterChanged(); @@ -738,10 +738,10 @@ void QDeclarativeAnchors::setBaseline(const QDeclarativeAnchorLine &edge) if (!d->checkVAnchorValid(edge) || d->baseline == edge) return; - d->usedAnchors |= HasBaselineAnchor; + d->usedAnchors |= BaselineAnchor; if (!d->checkVValid()) { - d->usedAnchors &= ~HasBaselineAnchor; + d->usedAnchors &= ~BaselineAnchor; return; } @@ -755,7 +755,7 @@ void QDeclarativeAnchors::setBaseline(const QDeclarativeAnchorLine &edge) void QDeclarativeAnchors::resetBaseline() { Q_D(QDeclarativeAnchors); - d->usedAnchors &= ~HasBaselineAnchor; + d->usedAnchors &= ~BaselineAnchor; d->remDepend(d->baseline.item); d->baseline = QDeclarativeAnchorLine(); emit baselineChanged(); @@ -774,10 +774,10 @@ void QDeclarativeAnchors::setLeft(const QDeclarativeAnchorLine &edge) if (!d->checkHAnchorValid(edge) || d->left == edge) return; - d->usedAnchors |= HasLeftAnchor; + d->usedAnchors |= LeftAnchor; if (!d->checkHValid()) { - d->usedAnchors &= ~HasLeftAnchor; + d->usedAnchors &= ~LeftAnchor; return; } @@ -791,7 +791,7 @@ void QDeclarativeAnchors::setLeft(const QDeclarativeAnchorLine &edge) void QDeclarativeAnchors::resetLeft() { Q_D(QDeclarativeAnchors); - d->usedAnchors &= ~HasLeftAnchor; + d->usedAnchors &= ~LeftAnchor; d->remDepend(d->left.item); d->left = QDeclarativeAnchorLine(); emit leftChanged(); @@ -810,10 +810,10 @@ void QDeclarativeAnchors::setRight(const QDeclarativeAnchorLine &edge) if (!d->checkHAnchorValid(edge) || d->right == edge) return; - d->usedAnchors |= HasRightAnchor; + d->usedAnchors |= RightAnchor; if (!d->checkHValid()) { - d->usedAnchors &= ~HasRightAnchor; + d->usedAnchors &= ~RightAnchor; return; } @@ -827,7 +827,7 @@ void QDeclarativeAnchors::setRight(const QDeclarativeAnchorLine &edge) void QDeclarativeAnchors::resetRight() { Q_D(QDeclarativeAnchors); - d->usedAnchors &= ~HasRightAnchor; + d->usedAnchors &= ~RightAnchor; d->remDepend(d->right.item); d->right = QDeclarativeAnchorLine(); emit rightChanged(); @@ -846,10 +846,10 @@ void QDeclarativeAnchors::setHorizontalCenter(const QDeclarativeAnchorLine &edge if (!d->checkHAnchorValid(edge) || d->hCenter == edge) return; - d->usedAnchors |= HasHCenterAnchor; + d->usedAnchors |= HCenterAnchor; if (!d->checkHValid()) { - d->usedAnchors &= ~HasHCenterAnchor; + d->usedAnchors &= ~HCenterAnchor; return; } @@ -863,7 +863,7 @@ void QDeclarativeAnchors::setHorizontalCenter(const QDeclarativeAnchorLine &edge void QDeclarativeAnchors::resetHorizontalCenter() { Q_D(QDeclarativeAnchors); - d->usedAnchors &= ~HasHCenterAnchor; + d->usedAnchors &= ~HCenterAnchor; d->remDepend(d->hCenter.item); d->hCenter = QDeclarativeAnchorLine(); emit horizontalCenterChanged(); @@ -1025,7 +1025,7 @@ void QDeclarativeAnchors::setBaselineOffset(qreal offset) emit baselineOffsetChanged(); } -QDeclarativeAnchors::UsedAnchors QDeclarativeAnchors::usedAnchors() const +QDeclarativeAnchors::Anchors QDeclarativeAnchors::usedAnchors() const { Q_D(const QDeclarativeAnchors); return d->usedAnchors; @@ -1033,9 +1033,9 @@ QDeclarativeAnchors::UsedAnchors QDeclarativeAnchors::usedAnchors() const bool QDeclarativeAnchorsPrivate::checkHValid() const { - if (usedAnchors & QDeclarativeAnchors::HasLeftAnchor && - usedAnchors & QDeclarativeAnchors::HasRightAnchor && - usedAnchors & QDeclarativeAnchors::HasHCenterAnchor) { + if (usedAnchors & QDeclarativeAnchors::LeftAnchor && + usedAnchors & QDeclarativeAnchors::RightAnchor && + usedAnchors & QDeclarativeAnchors::HCenterAnchor) { qmlInfo(item) << QDeclarativeAnchors::tr("Cannot specify left, right, and hcenter anchors."); return false; } @@ -1064,15 +1064,15 @@ bool QDeclarativeAnchorsPrivate::checkHAnchorValid(QDeclarativeAnchorLine anchor bool QDeclarativeAnchorsPrivate::checkVValid() const { - if (usedAnchors & QDeclarativeAnchors::HasTopAnchor && - usedAnchors & QDeclarativeAnchors::HasBottomAnchor && - usedAnchors & QDeclarativeAnchors::HasVCenterAnchor) { + if (usedAnchors & QDeclarativeAnchors::TopAnchor && + usedAnchors & QDeclarativeAnchors::BottomAnchor && + usedAnchors & QDeclarativeAnchors::VCenterAnchor) { qmlInfo(item) << QDeclarativeAnchors::tr("Cannot specify top, bottom, and vcenter anchors."); return false; - } else if (usedAnchors & QDeclarativeAnchors::HasBaselineAnchor && - (usedAnchors & QDeclarativeAnchors::HasTopAnchor || - usedAnchors & QDeclarativeAnchors::HasBottomAnchor || - usedAnchors & QDeclarativeAnchors::HasVCenterAnchor)) { + } else if (usedAnchors & QDeclarativeAnchors::BaselineAnchor && + (usedAnchors & QDeclarativeAnchors::TopAnchor || + usedAnchors & QDeclarativeAnchors::BottomAnchor || + usedAnchors & QDeclarativeAnchors::VCenterAnchor)) { qmlInfo(item) << QDeclarativeAnchors::tr("Baseline anchor cannot be used in conjunction with top, bottom, or vcenter anchors."); return false; } diff --git a/src/declarative/graphicsitems/qdeclarativeanchors_p.h b/src/declarative/graphicsitems/qdeclarativeanchors_p.h index f2e57cc..1bd7608 100644 --- a/src/declarative/graphicsitems/qdeclarativeanchors_p.h +++ b/src/declarative/graphicsitems/qdeclarativeanchors_p.h @@ -83,18 +83,18 @@ public: QDeclarativeAnchors(QGraphicsObject *item, QObject *parent=0); virtual ~QDeclarativeAnchors(); - enum UsedAnchor { - HasLeftAnchor = 0x01, - HasRightAnchor = 0x02, - HasTopAnchor = 0x04, - HasBottomAnchor = 0x08, - HasHCenterAnchor = 0x10, - HasVCenterAnchor = 0x20, - HasBaselineAnchor = 0x40, - Horizontal_Mask = HasLeftAnchor | HasRightAnchor | HasHCenterAnchor, - Vertical_Mask = HasTopAnchor | HasBottomAnchor | HasVCenterAnchor | HasBaselineAnchor + enum Anchor { + LeftAnchor = 0x01, + RightAnchor = 0x02, + TopAnchor = 0x04, + BottomAnchor = 0x08, + HCenterAnchor = 0x10, + VCenterAnchor = 0x20, + BaselineAnchor = 0x40, + Horizontal_Mask = LeftAnchor | RightAnchor | HCenterAnchor, + Vertical_Mask = TopAnchor | BottomAnchor | VCenterAnchor | BaselineAnchor }; - Q_DECLARE_FLAGS(UsedAnchors, UsedAnchor) + Q_DECLARE_FLAGS(Anchors, Anchor) QDeclarativeAnchorLine left() const; void setLeft(const QDeclarativeAnchorLine &edge); @@ -156,7 +156,7 @@ public: void setCenterIn(QGraphicsObject *); void resetCenterIn(); - UsedAnchors usedAnchors() const; + Anchors usedAnchors() const; void classBegin(); void componentComplete(); @@ -188,7 +188,7 @@ private: Q_PRIVATE_SLOT(d_func(), void _q_widgetGeometryChanged()) Q_PRIVATE_SLOT(d_func(), void _q_widgetDestroyed(QObject *obj)) }; -Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeAnchors::UsedAnchors) +Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeAnchors::Anchors) QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qdeclarativeanchors_p_p.h b/src/declarative/graphicsitems/qdeclarativeanchors_p_p.h index f8489aa..05be6c5 100644 --- a/src/declarative/graphicsitems/qdeclarativeanchors_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativeanchors_p_p.h @@ -139,7 +139,7 @@ public: void centerInChanged(); QGraphicsObject *item; - QDeclarativeAnchors::UsedAnchors usedAnchors; + QDeclarativeAnchors::Anchors usedAnchors; QGraphicsObject *fill; QGraphicsObject *centerIn; diff --git a/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp b/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp index 6ab126d..c81c2d2 100644 --- a/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp @@ -44,6 +44,7 @@ #ifndef QT_NO_MOVIE +#include <qdeclarativeinfo.h> #include <qdeclarativeengine.h> #include <QMovie> @@ -213,7 +214,7 @@ void QDeclarativeAnimatedImage::setSource(const QUrl &url) //### should be unified with movieRequestFinished d->_movie = new QMovie(lf); if (!d->_movie->isValid()){ - qWarning() << "Error Reading Animated Image File" << d->url; + qmlInfo(this) << "Error Reading Animated Image File " << d->url.toString(); delete d->_movie; d->_movie = 0; return; @@ -270,7 +271,7 @@ void QDeclarativeAnimatedImage::movieRequestFinished() d->_movie = new QMovie(d->reply); if (!d->_movie->isValid()){ - qWarning() << "Error Reading Animated Image File " << d->url; + qmlInfo(this) << "Error Reading Animated Image File " << d->url; delete d->_movie; d->_movie = 0; return; diff --git a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp index be9d8bd..06f8363 100644 --- a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp @@ -82,7 +82,7 @@ QDeclarativeBorderImage::~QDeclarativeBorderImage() QDeclarativePixmapCache::cancel(d->sciurl, this); } /*! - \qmlproperty enum BorderImage::status + \qmlproperty enumeration BorderImage::status This property holds the status of image loading. It can be one of: \list @@ -264,9 +264,9 @@ void QDeclarativeBorderImage::load() When the image is scaled: \list \i the corners (sections 1, 3, 7, and 9) are not scaled at all - \i the middle (section 5) is scaled according to BorderImage::horizontalTileMode and BorderImage::verticalTileMode - \i sections 2 and 8 are scaled according to BorderImage::horizontalTileMode - \i sections 4 and 6 are scaled according to BorderImage::verticalTileMode + \i sections 2 and 8 are scaled according to \l{BorderImage::horizontalTileMode}{horizontalTileMode} + \i sections 4 and 6 are scaled according to \l{BorderImage::verticalTileMode}{verticalTileMode} + \i the middle (section 5) is scaled according to both \l{BorderImage::horizontalTileMode}{horizontalTileMode} and \l{BorderImage::verticalTileMode}{verticalTileMode} \endlist Each border line (left, right, top, and bottom) specifies an offset from the respective side. For example, \c{border.bottom: 10} sets the bottom line 10 pixels up from the bottom of the image. @@ -282,8 +282,8 @@ QDeclarativeScaleGrid *QDeclarativeBorderImage::border() } /*! - \qmlproperty TileMode BorderImage::horizontalTileMode - \qmlproperty TileMode BorderImage::verticalTileMode + \qmlproperty enumeration BorderImage::horizontalTileMode + \qmlproperty enumeration BorderImage::verticalTileMode This property describes how to repeat or stretch the middle parts of the border image. diff --git a/src/declarative/graphicsitems/qdeclarativeeffects.cpp b/src/declarative/graphicsitems/qdeclarativeeffects.cpp deleted file mode 100644 index ea1f9cc..0000000 --- a/src/declarative/graphicsitems/qdeclarativeeffects.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <qdeclarative.h> - -#include <QtGui/qgraphicseffect.h> - -/*! - \qmlclass Blur QGraphicsBlurEffect - \since 4.7 - \brief The Blur object provides a blur effect. - - A blur effect blurs the source item. This effect is useful for reducing details; - for example, when the a source loses focus and attention should be drawn to other - elements. Use blurRadius to control the level of detail and blurHint to control - the quality of the blur. - - By default, the blur radius is 5 pixels. - - \img graphicseffect-blur.png -*/ - -/*! - \qmlproperty real Blur::blurRadius - - This controls how blurry an item will appear. - - A smaller radius produces a sharper appearance, and a larger radius produces - a more blurred appearance. - - The default radius is 5 pixels. -*/ -/*! - \qmlproperty enumeration Blur::blurHint - - Use Qt.PerformanceHint to specify a faster blur or Qt.QualityHint hint - to specify a higher quality blur. - - If the blur radius is animated, it is recommended you use Qt.PerformanceHint. - - The default hint is Qt.PerformanceHint. -*/ - -/*! - \qmlclass Colorize QGraphicsColorizeEffect - \since 4.7 - \brief The Colorize object provides a colorize effect. - - A colorize effect renders the source item with a tint of its color. - - By default, the color is light blue. - - \img graphicseffect-colorize.png -*/ - -/*! - \qmlproperty color Colorize::color - The color of the effect. - - By default, the color is light blue. -*/ - -/*! - \qmlproperty real Colorize::strength - - To what extent the source item is "colored". A strength of 0.0 is equal to no effect, - while 1.0 means full colorization. By default, the strength is 1.0. -*/ - - -/*! - \qmlclass DropShadow QGraphicsDropShadowEffect - \since 4.7 - \brief The DropShadow object provides a drop shadow effect. - - A drop shadow effect renders the source item with a drop shadow. The color of - the drop shadow can be modified using the color property. The drop - shadow offset can be modified using the xOffset and yOffset properties and the blur - radius of the drop shadow can be changed with the blurRadius property. - - By default, the drop shadow is a semi-transparent dark gray shadow, - blurred with a radius of 1 at an offset of 8 pixels towards the lower right. - - \img graphicseffect-drop-shadow.png -*/ - -/*! - \qmlproperty real DropShadow::xOffset - \qmlproperty real DropShadow::yOffset - The shadow offset in pixels. - - By default, xOffset and yOffset are 8 pixels. -*/ - -/*! - \qmlproperty real DropShadow::blurRadius - The blur radius in pixels of the drop shadow. - - Using a smaller radius results in a sharper shadow, whereas using a bigger - radius results in a more blurred shadow. - - By default, the blur radius is 1 pixel. -*/ - -/*! - \qmlproperty color DropShadow::color - The color of the drop shadow. - - By default, the drop color is a semi-transparent dark gray. -*/ - - -/*! - \qmlclass Opacity QGraphicsOpacityEffect - \since 4.7 - \brief The Opacity object provides an opacity effect. - - An opacity effect renders the source with an opacity. This effect is useful - for making the source semi-transparent, similar to a fade-in/fade-out - sequence. The opacity can be modified using the opacity property. - - By default, the opacity is 0.7. - - \img graphicseffect-opacity.png -*/ - -/*! - \qmlproperty real Opacity::opacity - This property specifies how opaque an item should appear. - - The value should be in the range of 0.0 to 1.0, where 0.0 is - fully transparent and 1.0 is fully opaque. - - By default, the opacity is 0.7. -*/ - diff --git a/src/declarative/graphicsitems/qdeclarativeeffects_p.h b/src/declarative/graphicsitems/qdeclarativeeffects_p.h deleted file mode 100644 index 0de5854..0000000 --- a/src/declarative/graphicsitems/qdeclarativeeffects_p.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDECLARATIVEEFFECTS_P_H -#define QDECLARATIVEEFFECTS_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <qdeclarative.h> -#include <QtGui/qgraphicseffect.h> - -#ifndef QT_NO_GRAPHICSEFFECT -QML_DECLARE_TYPE(QGraphicsEffect) -QML_DECLARE_TYPE(QGraphicsBlurEffect) -QML_DECLARE_TYPE(QGraphicsColorizeEffect) -QML_DECLARE_TYPE(QGraphicsDropShadowEffect) -QML_DECLARE_TYPE(QGraphicsOpacityEffect) -#endif - -#endif // QDECLARATIVEEFFECTS_P_H diff --git a/src/declarative/graphicsitems/qdeclarativeevents.cpp b/src/declarative/graphicsitems/qdeclarativeevents.cpp index a181071..4425c97 100644 --- a/src/declarative/graphicsitems/qdeclarativeevents.cpp +++ b/src/declarative/graphicsitems/qdeclarativeevents.cpp @@ -145,7 +145,7 @@ Item { */ /*! - \qmlproperty enum MouseEvent::button + \qmlproperty enumeration MouseEvent::button This property holds the button that caused the event. It can be one of: \list diff --git a/src/declarative/graphicsitems/qdeclarativeevents_p_p.h b/src/declarative/graphicsitems/qdeclarativeevents_p_p.h index 65ac8de..0e0329e 100644 --- a/src/declarative/graphicsitems/qdeclarativeevents_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativeevents_p_p.h @@ -115,6 +115,10 @@ public: bool wasHeld() const { return _wasHeld; } bool isClick() const { return _isClick; } + // only for internal usage + void setX(int x) { _x = x; } + void setY(int y) { _y = y; } + bool isAccepted() { return _accepted; } void setAccepted(bool accepted) { _accepted = accepted; } diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index 951b171..b462443 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -41,7 +41,7 @@ #include "private/qdeclarativeflickable_p.h" #include "private/qdeclarativeflickable_p_p.h" - +#include <qdeclarativeinfo.h> #include <QGraphicsSceneMouseEvent> #include <QPointer> #include <QTimer> @@ -125,12 +125,13 @@ QDeclarativeFlickablePrivate::QDeclarativeFlickablePrivate() : viewport(new QDeclarativeItem) , hData(this, &QDeclarativeFlickablePrivate::setRoundedViewportX) , vData(this, &QDeclarativeFlickablePrivate::setRoundedViewportY) - , overShoot(true), flicked(false), moving(false), stealMouse(false) + , flicked(false), moving(false), stealMouse(false) , pressed(false) , interactive(true), deceleration(500), maxVelocity(2000), reportedVelocitySmoothing(100) , delayedPressEvent(0), delayedPressTarget(0), pressDelay(0), fixupDuration(600) , vTime(0), visibleArea(0) , flickDirection(QDeclarativeFlickable::AutoFlickDirection) + , boundsBehavior(QDeclarativeFlickable::DragAndOvershootBounds) { } @@ -203,6 +204,7 @@ void QDeclarativeFlickablePrivate::flick(AxisData &data, qreal minExtent, qreal { Q_Q(QDeclarativeFlickable); qreal maxDistance = -1; + bool overShoot = boundsBehavior == QDeclarativeFlickable::DragAndOvershootBounds; // -ve velocity means list is moving up if (velocity > 0) { if (data.move.value() < minExtent) @@ -248,18 +250,12 @@ void QDeclarativeFlickablePrivate::fixupX_callback(void *data) void QDeclarativeFlickablePrivate::fixupX() { Q_Q(QDeclarativeFlickable); - if (!q->xflick() || hData.move.timeLine()) - return; - fixup(hData, q->minXExtent(), q->maxXExtent()); } void QDeclarativeFlickablePrivate::fixupY() { Q_Q(QDeclarativeFlickable); - if (!q->yflick() || vData.move.timeLine()) - return; - fixup(vData, q->minYExtent(), q->maxYExtent()); } @@ -272,7 +268,7 @@ void QDeclarativeFlickablePrivate::fixup(AxisData &data, qreal minExtent, qreal if (fixupDuration) { qreal dist = minExtent - data.move; timeline.move(data.move, minExtent - dist/2, QEasingCurve(QEasingCurve::InQuad), fixupDuration/4); - timeline.move(data.move, minExtent, QEasingCurve(QEasingCurve::OutQuint), 3*fixupDuration/4); + timeline.move(data.move, minExtent, QEasingCurve(QEasingCurve::OutExpo), 3*fixupDuration/4); } else { data.move.setValue(minExtent); q->viewportMoved(); @@ -284,7 +280,7 @@ void QDeclarativeFlickablePrivate::fixup(AxisData &data, qreal minExtent, qreal if (fixupDuration) { qreal dist = maxExtent - data.move; timeline.move(data.move, maxExtent - dist/2, QEasingCurve(QEasingCurve::InQuad), fixupDuration/4); - timeline.move(data.move, maxExtent, QEasingCurve(QEasingCurve::OutQuint), 3*fixupDuration/4); + timeline.move(data.move, maxExtent, QEasingCurve(QEasingCurve::OutExpo), 3*fixupDuration/4); } else { data.move.setValue(maxExtent); q->viewportMoved(); @@ -652,7 +648,7 @@ void QDeclarativeFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent newY = minY + (newY - minY) / 2; if (newY < maxY && maxY - minY <= 0) newY = maxY + (newY - maxY) / 2; - if (!q->overShoot() && (newY > minY || newY < maxY)) { + if (boundsBehavior == QDeclarativeFlickable::StopAtBounds && (newY > minY || newY < maxY)) { if (newY > minY) newY = minY; else if (newY < maxY) @@ -661,7 +657,7 @@ void QDeclarativeFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent rejectY = true; } if (!rejectY && stealMouse) { - vData.move.setValue(newY); + vData.move.setValue(qRound(newY)); moved = true; } if (qAbs(dy) > QApplication::startDragDistance()) @@ -679,7 +675,7 @@ void QDeclarativeFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent newX = minX + (newX - minX) / 2; if (newX < maxX && maxX - minX <= 0) newX = maxX + (newX - maxX) / 2; - if (!q->overShoot() && (newX > minX || newX < maxX)) { + if (boundsBehavior == QDeclarativeFlickable::StopAtBounds && (newX > minX || newX < maxX)) { if (newX > minX) newX = minX; else if (newX < maxX) @@ -688,7 +684,7 @@ void QDeclarativeFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent rejectX = true; } if (!rejectX && stealMouse) { - hData.move.setValue(newX); + hData.move.setValue(qRound(newX)); moved = true; } @@ -1003,28 +999,58 @@ QDeclarativeListProperty<QGraphicsObject> QDeclarativeFlickable::flickableChildr return QGraphicsItemPrivate::get(d->viewport)->childrenList(); } +bool QDeclarativeFlickable::overShoot() const +{ + Q_D(const QDeclarativeFlickable); + return d->boundsBehavior == DragAndOvershootBounds; +} + +void QDeclarativeFlickable::setOverShoot(bool o) +{ + Q_D(QDeclarativeFlickable); + if ((o && d->boundsBehavior == DragAndOvershootBounds) + || (!o && d->boundsBehavior == StopAtBounds)) + return; + qmlInfo(this) << "overshoot is deprecated and will be removed imminently - use boundsBehavior."; + d->boundsBehavior = o ? DragAndOvershootBounds : StopAtBounds; + emit boundsBehaviorChanged(); + emit overShootChanged(); +} + /*! - \qmlproperty bool Flickable::overShoot - This property holds whether the surface may overshoot the + \qmlproperty enumeration Flickable::boundsBehavior + This property holds whether the surface may be dragged + beyond the Fickable's boundaries, or overshoot the Flickable's boundaries when flicked. - If overShoot is true the contents can be flicked beyond the boundary - of the Flickable before being moved back to the boundary. This provides - the feeling that the edges of the view are soft, rather than a hard - physical boundary. + This enables the feeling that the edges of the view are soft, + rather than a hard physical boundary. + + boundsBehavior can be one of: + + \list + \o \e StopAtBounds - the contents can not be dragged beyond the boundary + of the flickable, and flicks will not overshoot. + \o \e DragOverBounds - the contents can be dragged beyond the boundary + of the Flickable, but flicks will not overshoot. + \o \e DragAndOvershootBounds (default) - the contents can be dragged + beyond the boundary of the Flickable, and can overshoot the + boundary when flicked. + \endlist */ -bool QDeclarativeFlickable::overShoot() const +QDeclarativeFlickable::BoundsBehavior QDeclarativeFlickable::boundsBehavior() const { Q_D(const QDeclarativeFlickable); - return d->overShoot; + return d->boundsBehavior; } -void QDeclarativeFlickable::setOverShoot(bool o) +void QDeclarativeFlickable::setBoundsBehavior(BoundsBehavior b) { Q_D(QDeclarativeFlickable); - if (d->overShoot == o) + if (b == d->boundsBehavior) return; - d->overShoot = o; + d->boundsBehavior = b; + emit boundsBehaviorChanged(); emit overShootChanged(); } @@ -1059,8 +1085,12 @@ void QDeclarativeFlickable::setContentWidth(qreal w) else d->viewport->setWidth(w); // Make sure that we're entirely in view. - if (!d->pressed) + if (!d->pressed) { + int oldDuration = d->fixupDuration; + d->fixupDuration = 0; d->fixupX(); + d->fixupDuration = oldDuration; + } emit contentWidthChanged(); d->updateBeginningEnd(); } @@ -1082,8 +1112,12 @@ void QDeclarativeFlickable::setContentHeight(qreal h) else d->viewport->setHeight(h); // Make sure that we're entirely in view. - if (!d->pressed) + if (!d->pressed) { + int oldDuration = d->fixupDuration; + d->fixupDuration = 0; d->fixupY(); + d->fixupDuration = oldDuration; + } emit contentHeightChanged(); d->updateBeginningEnd(); } diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p.h index 1fa2c74..f031a24 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable_p.h +++ b/src/declarative/graphicsitems/qdeclarativeflickable_p.h @@ -64,7 +64,8 @@ class Q_DECLARATIVE_EXPORT QDeclarativeFlickable : public QDeclarativeItem Q_PROPERTY(qreal horizontalVelocity READ horizontalVelocity NOTIFY horizontalVelocityChanged) Q_PROPERTY(qreal verticalVelocity READ verticalVelocity NOTIFY verticalVelocityChanged) - Q_PROPERTY(bool overShoot READ overShoot WRITE setOverShoot NOTIFY overShootChanged) + Q_PROPERTY(bool overShoot READ overShoot WRITE setOverShoot NOTIFY overShootChanged) // deprecated + Q_PROPERTY(BoundsBehavior boundsBehavior READ boundsBehavior WRITE setBoundsBehavior NOTIFY boundsBehaviorChanged) Q_PROPERTY(qreal maximumFlickVelocity READ maximumFlickVelocity WRITE setMaximumFlickVelocity NOTIFY maximumFlickVelocityChanged) Q_PROPERTY(qreal flickDeceleration READ flickDeceleration WRITE setFlickDeceleration NOTIFY flickDecelerationChanged) Q_PROPERTY(bool moving READ isMoving NOTIFY movingChanged) @@ -86,6 +87,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeFlickable : public QDeclarativeItem Q_CLASSINFO("DefaultProperty", "flickableData") Q_ENUMS(FlickDirection) + Q_ENUMS(BoundsBehavior) public: QDeclarativeFlickable(QDeclarativeItem *parent=0); @@ -97,6 +99,10 @@ public: bool overShoot() const; void setOverShoot(bool); + enum BoundsBehavior { StopAtBounds, DragOverBounds, DragAndOvershootBounds }; + BoundsBehavior boundsBehavior() const; + void setBoundsBehavior(BoundsBehavior); + qreal contentWidth() const; void setContentWidth(qreal); @@ -156,6 +162,7 @@ Q_SIGNALS: void flickDirectionChanged(); void interactiveChanged(); void overShootChanged(); + void boundsBehaviorChanged(); void maximumFlickVelocityChanged(); void flickDecelerationChanged(); void pressDelayChanged(); diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h index 1a04091..01cfb18 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h @@ -131,7 +131,6 @@ public: AxisData vData; QDeclarativeTimeLine timeline; - bool overShoot : 1; bool flicked : 1; bool moving : 1; bool stealMouse : 1; @@ -160,6 +159,7 @@ public: QDeclarativeTimeLine velocityTimeline; QDeclarativeFlickableVisibleArea *visibleArea; QDeclarativeFlickable::FlickDirection flickDirection; + QDeclarativeFlickable::BoundsBehavior boundsBehavior; void handleMousePressEvent(QGraphicsSceneMouseEvent *); void handleMouseMoveEvent(QGraphicsSceneMouseEvent *); diff --git a/src/declarative/graphicsitems/qdeclarativeflipable.cpp b/src/declarative/graphicsitems/qdeclarativeflipable.cpp index 98e34a9..57045f1 100644 --- a/src/declarative/graphicsitems/qdeclarativeflipable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflipable.cpp @@ -57,10 +57,14 @@ public: QDeclarativeFlipablePrivate() : current(QDeclarativeFlipable::Front), front(0), back(0) {} void updateSceneTransformFromParent(); + void setBackTransform(); QDeclarativeFlipable::Side current; QDeclarativeGuard<QGraphicsObject> front; QDeclarativeGuard<QGraphicsObject> back; + + bool wantBackXFlipped; + bool wantBackYFlipped; }; /*! @@ -148,6 +152,17 @@ void QDeclarativeFlipable::setBack(QGraphicsObject *back) d->back->setParentItem(this); if (Front == d->current) d->back->setOpacity(0.); + connect(back, SIGNAL(widthChanged()), + this, SLOT(retransformBack())); + connect(back, SIGNAL(heightChanged()), + this, SLOT(retransformBack())); +} + +void QDeclarativeFlipable::retransformBack() +{ + Q_D(QDeclarativeFlipable); + if (d->current == QDeclarativeFlipable::Back && d->back) + d->setBackTransform(); } /*! @@ -184,26 +199,20 @@ void QDeclarativeFlipablePrivate::updateSceneTransformFromParent() qreal cross = (p1.x() - p2.x()) * (p3.y() - p2.y()) - (p1.y() - p2.y()) * (p3.x() - p2.x()); + wantBackYFlipped = p1.x() >= p2.x(); + wantBackXFlipped = p2.y() >= p3.y(); + QDeclarativeFlipable::Side newSide; if (cross > 0) { - newSide = QDeclarativeFlipable::Back; + newSide = QDeclarativeFlipable::Back; } else { newSide = QDeclarativeFlipable::Front; } if (newSide != current) { current = newSide; - if (current == QDeclarativeFlipable::Back && back) { - QTransform mat; - QGraphicsItemPrivate *dBack = QGraphicsItemPrivate::get(back); - mat.translate(dBack->width()/2,dBack->height()/2); - if (dBack->width() && p1.x() >= p2.x()) - mat.rotate(180, Qt::YAxis); - if (dBack->height() && p2.y() >= p3.y()) - mat.rotate(180, Qt::XAxis); - mat.translate(-dBack->width()/2,-dBack->height()/2); - back->setTransform(mat); - } + if (current == QDeclarativeFlipable::Back && back) + setBackTransform(); if (front) front->setOpacity((current==QDeclarativeFlipable::Front)?1.:0.); if (back) @@ -212,4 +221,20 @@ void QDeclarativeFlipablePrivate::updateSceneTransformFromParent() } } +/* Depends on the width/height of the back item, and so needs reevaulating + if those change. +*/ +void QDeclarativeFlipablePrivate::setBackTransform() +{ + QTransform mat; + QGraphicsItemPrivate *dBack = QGraphicsItemPrivate::get(back); + mat.translate(dBack->width()/2,dBack->height()/2); + if (dBack->width() && wantBackYFlipped) + mat.rotate(180, Qt::YAxis); + if (dBack->height() && wantBackXFlipped) + mat.rotate(180, Qt::XAxis); + mat.translate(-dBack->width()/2,-dBack->height()/2); + back->setTransform(mat); +} + QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qdeclarativeflipable_p.h b/src/declarative/graphicsitems/qdeclarativeflipable_p.h index 302f083..fd0119b 100644 --- a/src/declarative/graphicsitems/qdeclarativeflipable_p.h +++ b/src/declarative/graphicsitems/qdeclarativeflipable_p.h @@ -81,6 +81,9 @@ public: Q_SIGNALS: void sideChanged(); +private Q_SLOTS: + void retransformBack(); + private: Q_DISABLE_COPY(QDeclarativeFlipable) Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeFlipable) diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index 562ba2a..f8b773e 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -50,6 +50,7 @@ #include <qlistmodelinterface_p.h> #include <QKeyEvent> +#include <qmath.h> #include <math.h> QT_BEGIN_NAMESPACE @@ -346,6 +347,7 @@ public: void QDeclarativeGridViewPrivate::init() { Q_Q(QDeclarativeGridView); + QObject::connect(q, SIGNAL(movementEnded()), q, SLOT(animStopped())); q->setFlag(QGraphicsItem::ItemIsFocusScope); q->setFlickDirection(QDeclarativeFlickable::VerticalFlick); addItemChangeListener(this, Geometry); @@ -746,24 +748,31 @@ void QDeclarativeGridViewPrivate::fixupPosition() void QDeclarativeGridViewPrivate::fixup(AxisData &data, qreal minExtent, qreal maxExtent) { Q_Q(QDeclarativeGridView); - - if ((&data == &vData && !q->yflick()) - || (&data == &hData && !q->xflick()) - || data.move.timeLine()) + if ((flow == QDeclarativeGridView::TopToBottom && &data == &vData) + || (flow == QDeclarativeGridView::LeftToRight && &data == &hData)) return; int oldDuration = fixupDuration; fixupDuration = moveReason == Mouse ? fixupDuration : 0; if (haveHighlightRange && highlightRange == QDeclarativeGridView::StrictlyEnforceRange) { - if (currentItem && currentItem->rowPos() - position() != highlightRangeStart) { - qreal pos = currentItem->rowPos() - highlightRangeStart; + if (currentItem) { + updateHighlight(); + qreal pos = currentItem->rowPos(); + qreal viewPos = position(); + if (viewPos < pos + rowSize() - highlightRangeEnd) + viewPos = pos + rowSize() - highlightRangeEnd; + if (viewPos > pos - highlightRangeStart) + viewPos = pos - highlightRangeStart; + timeline.reset(data.move); - if (fixupDuration) { - timeline.move(data.move, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2); - } else { - data.move.setValue(-pos); - q->viewportMoved(); + if (viewPos != position()) { + if (fixupDuration) { + timeline.move(data.move, -viewPos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2); + } else { + data.move.setValue(-viewPos); + q->viewportMoved(); + } } vTime = timeline.time(); } @@ -808,7 +817,7 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m maxDistance = qAbs(minExtent - data.move.value()); } } - if (snapMode != QDeclarativeGridView::SnapToRow && highlightRange != QDeclarativeGridView::StrictlyEnforceRange) + if (snapMode == QDeclarativeGridView::NoSnap && highlightRange != QDeclarativeGridView::StrictlyEnforceRange) data.flickTarget = minExtent; } else { if (data.move.value() > maxExtent) { @@ -819,9 +828,10 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m maxDistance = qAbs(maxExtent - data.move.value()); } } - if (snapMode != QDeclarativeGridView::SnapToRow && highlightRange != QDeclarativeGridView::StrictlyEnforceRange) + if (snapMode == QDeclarativeGridView::NoSnap && highlightRange != QDeclarativeGridView::StrictlyEnforceRange) data.flickTarget = maxExtent; } + bool overShoot = boundsBehavior == QDeclarativeFlickable::DragAndOvershootBounds; if (maxDistance > 0 || overShoot) { // This mode requires the grid to stop exactly on a row boundary. qreal v = velocity; @@ -840,7 +850,15 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m if (v > 0) dist = -dist; data.flickTarget = -snapPosAt(-(data.move.value() - highlightRangeStart) + dist) + highlightRangeStart; - dist = -data.flickTarget + data.move.value(); + qreal adjDist = -data.flickTarget + data.move.value(); + if (qAbs(adjDist) > qAbs(dist)) { + // Prevent painfully slow flicking - adjust velocity to suit flickDeceleration + v2 = accel * 2.0f * qAbs(dist); + v = qSqrt(v2); + if (dist > 0) + v = -v; + } + dist = adjDist; accel = v2 / (2.0f * qAbs(dist)); } else { data.flickTarget = velocity > 0 ? minExtent : maxExtent; @@ -885,7 +903,7 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m In this case ListModel is a handy way for us to test our UI. In practice the model would be implemented in C++, or perhaps via a SQL data source. - Note that views do not enable \e clip automatically. If the view + \bold Note that views do not enable \e clip automatically. If the view is not clipped by another item or the screen, it will be necessary to set \e {clip: true} in order to have the out of view items clipped nicely. @@ -1507,12 +1525,12 @@ void QDeclarativeGridView::viewportMoved() if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange && d->highlight) { // reposition highlight qreal pos = d->highlight->rowPos(); - qreal viewPos = qRound(d->position()); - if (pos > viewPos + d->highlightRangeEnd - 1 - d->rowSize()) - pos = viewPos + d->highlightRangeEnd - 1 - d->rowSize(); + qreal viewPos = d->position(); + if (pos > viewPos + d->highlightRangeEnd - d->rowSize()) + pos = viewPos + d->highlightRangeEnd - d->rowSize(); if (pos < viewPos + d->highlightRangeStart) pos = viewPos + d->highlightRangeStart; - d->highlight->setPosition(d->highlight->colPos(), pos); + d->highlight->setPosition(d->highlight->colPos(), qRound(pos)); // update current index int idx = d->snapIndex(); @@ -1535,8 +1553,10 @@ qreal QDeclarativeGridView::minYExtent() const if (d->flow == QDeclarativeGridView::TopToBottom) return QDeclarativeFlickable::minYExtent(); qreal extent = -d->startPosition(); - if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) + if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) { extent += d->highlightRangeStart; + extent = qMax(extent, -(d->rowPosAt(0) + d->rowSize() - d->highlightRangeEnd)); + } return extent; } @@ -1547,8 +1567,9 @@ qreal QDeclarativeGridView::maxYExtent() const return QDeclarativeFlickable::maxYExtent(); qreal extent; if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) { - extent = -(d->endPosition() - d->highlightRangeEnd); - extent = qMax(extent, -(d->rowPosAt(d->model->count()-1) - d->highlightRangeStart)); + extent = -(d->rowPosAt(d->model->count()-1) - d->highlightRangeStart); + if (d->highlightRangeEnd != d->highlightRangeStart) + extent = qMin(extent, -(d->endPosition() - d->highlightRangeEnd + 1)); } else { extent = -(d->endPosition() - height()); } @@ -1564,8 +1585,10 @@ qreal QDeclarativeGridView::minXExtent() const if (d->flow == QDeclarativeGridView::LeftToRight) return QDeclarativeFlickable::minXExtent(); qreal extent = -d->startPosition(); - if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) + if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) { extent += d->highlightRangeStart; + extent = qMax(extent, -(d->rowPosAt(0) + d->rowSize() - d->highlightRangeEnd)); + } return extent; } @@ -1576,8 +1599,9 @@ qreal QDeclarativeGridView::maxXExtent() const return QDeclarativeFlickable::maxXExtent(); qreal extent; if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) { - extent = -(d->endPosition() - d->highlightRangeEnd); - extent = qMax(extent, -(d->rowPosAt(d->model->count()-1) - d->highlightRangeStart)); + extent = -(d->rowPosAt(d->model->count()-1) - d->highlightRangeStart); + if (d->highlightRangeEnd != d->highlightRangeStart) + extent = qMin(extent, -(d->endPosition() - d->highlightRangeEnd + 1)); } else { extent = -(d->endPosition() - height()); } @@ -2247,6 +2271,13 @@ void QDeclarativeGridView::destroyingItem(QDeclarativeItem *item) d->unrequestedItems.remove(item); } +void QDeclarativeGridView::animStopped() +{ + Q_D(QDeclarativeGridView); + d->bufferMode = QDeclarativeGridViewPrivate::NoBuffer; + if (d->haveHighlightRange && d->highlightRange == QDeclarativeGridView::StrictlyEnforceRange) + d->updateHighlight(); +} void QDeclarativeGridView::refill() { diff --git a/src/declarative/graphicsitems/qdeclarativegridview_p.h b/src/declarative/graphicsitems/qdeclarativegridview_p.h index 5baa1dd..c06879e 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview_p.h +++ b/src/declarative/graphicsitems/qdeclarativegridview_p.h @@ -192,6 +192,7 @@ private Q_SLOTS: void destroyRemoved(); void createdItem(int index, QDeclarativeItem *item); void destroyingItem(QDeclarativeItem *item); + void animStopped(); private: void refill(); diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp index ca86637..247e348 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp @@ -221,7 +221,7 @@ qreal QDeclarativeImage::paintedHeight() const } /*! - \qmlproperty enum Image::status + \qmlproperty enumeration Image::status This property holds the status of image loading. It can be one of: \list @@ -236,9 +236,12 @@ qreal QDeclarativeImage::paintedHeight() const to react to the change in status you need to do it yourself, for example in one of the following ways: \list - \o Create a state, so that a state change occurs, e.g. State{name: 'loaded'; when: image.status = Image.Ready;} - \o Do something inside the onStatusChanged signal handler, e.g. Image{id: image; onStatusChanged: if(image.status == Image.Ready) console.log('Loaded');} - \o Bind to the status variable somewhere, e.g. Text{text: if(image.status!=Image.Ready){'Not Loaded';}else{'Loaded';}} + \o Create a state, so that a state change occurs, e.g. + \qml State { name: 'loaded'; when: image.status = Image.Ready } \endqml + \o Do something inside the onStatusChanged signal handler, e.g. + \qml Image { id: image; onStatusChanged: if (image.status == Image.Ready) console.log('Loaded') } \endqml + \o Bind to the status variable somewhere, e.g. + \qml Text { text: if (image.status != Image.Ready) { 'Not Loaded' } else { 'Loaded' } } \endqml \endlist \sa progress @@ -366,12 +369,27 @@ void QDeclarativeImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWi if (width() != d->pix.width() || height() != d->pix.height()) { if (d->fillMode >= Tile) { - if (d->fillMode == Tile) + if (d->fillMode == Tile) { p->drawTiledPixmap(QRectF(0,0,width(),height()), d->pix); - else if (d->fillMode == TileVertically) - p->drawTiledPixmap(QRectF(0,0,d->pix.width(),height()), d->pix); - else - p->drawTiledPixmap(QRectF(0,0,width(),d->pix.height()), d->pix); + } else { + qreal widthScale = width() / qreal(d->pix.width()); + qreal heightScale = height() / qreal(d->pix.height()); + + QTransform scale; + if (d->fillMode == TileVertically) { + scale.scale(widthScale, 1.0); + QTransform old = p->transform(); + p->setWorldTransform(scale * old); + p->drawTiledPixmap(QRectF(0,0,d->pix.width(),height()), d->pix); + p->setWorldTransform(old); + } else { + scale.scale(1.0, heightScale); + QTransform old = p->transform(); + p->setWorldTransform(scale * old); + p->drawTiledPixmap(QRectF(0,0,width(),d->pix.height()), d->pix); + p->setWorldTransform(old); + } + } } else { qreal widthScale = width() / qreal(d->pix.width()); qreal heightScale = height() / qreal(d->pix.height()); diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 86dbaf0..bc0c65e 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -61,7 +61,6 @@ #include <QtCore/qnumeric.h> #include <QtScript/qscriptengine.h> #include <QtGui/qgraphicstransform.h> -#include <QtGui/qgraphicseffect.h> #include <qlistmodelinterface_p.h> QT_BEGIN_NAMESPACE @@ -70,8 +69,6 @@ QT_BEGIN_NAMESPACE #define FLT_MAX 1E+37 #endif -#include "qdeclarativeeffects.cpp" - /*! \qmlclass Transform QGraphicsTransform \since 4.7 @@ -234,11 +231,6 @@ QT_BEGIN_NAMESPACE */ /*! - \group group_effects - \title Effects -*/ - -/*! \group group_layouts \title Layouts */ @@ -275,17 +267,6 @@ QDeclarativeContents::QDeclarativeContents() : m_x(0), m_y(0), m_width(0), m_hei { } -/*! - \qmlproperty real Item::childrenRect.x - \qmlproperty real Item::childrenRect.y - \qmlproperty real Item::childrenRect.width - \qmlproperty real Item::childrenRect.height - - The childrenRect properties allow an item access to the geometry of its - children. This property is useful if you have an item that needs to be - sized to fit its children. -*/ - QRectF QDeclarativeContents::rectF() const { return QRectF(m_x, m_y, m_width, m_height); @@ -1415,7 +1396,7 @@ QDeclarativeItem::~QDeclarativeItem() } /*! - \qmlproperty enum Item::transformOrigin + \qmlproperty enumeration Item::transformOrigin This property holds the origin point around which scale and rotation transform. Nine transform origins are available, as shown in the image below. @@ -1457,6 +1438,18 @@ QDeclarativeItem *QDeclarativeItem::parentItem() const } /*! + \qmlproperty real Item::childrenRect.x + \qmlproperty real Item::childrenRect.y + \qmlproperty real Item::childrenRect.width + \qmlproperty real Item::childrenRect.height + + The childrenRect properties allow an item access to the geometry of its + children. This property is useful if you have an item that needs to be + sized to fit its children. +*/ + + +/*! \qmlproperty list<Item> Item::children \qmlproperty list<Object> Item::resources @@ -1594,10 +1587,10 @@ void QDeclarativeItemPrivate::transform_clear(QDeclarativeListProperty<QGraphics } } -void QDeclarativeItemPrivate::parentProperty(QObject *o, void *rv, QDeclarativeNotifierEndpoint *e) +void QDeclarativeItemPrivate::parentProperty(QObject *o, void *rv, QDeclarativeNotifierEndpoint *e) { QDeclarativeItem *item = static_cast<QDeclarativeItem*>(o); - if (e) + if (e) e->connect(&item->d_func()->parentNotifier); *((QDeclarativeItem **)rv) = item->parentItem(); } @@ -1794,9 +1787,13 @@ void QDeclarativeItem::geometryChanged(const QRectF &newGeometry, if (transformOrigin() != QDeclarativeItem::TopLeft && (newGeometry.width() != oldGeometry.width() || newGeometry.height() != oldGeometry.height())) { - QPointF origin = d->computeTransformOrigin(); - if (transformOriginPoint() != origin) - setTransformOriginPoint(origin); + if (d->transformData) { + QPointF origin = d->computeTransformOrigin(); + if (transformOriginPoint() != origin) + setTransformOriginPoint(origin); + } else { + d->transformOriginDirty = true; + } } if (newGeometry.x() != oldGeometry.x()) @@ -2149,8 +2146,8 @@ void QDeclarativeItem::setBaselineOffset(qreal offset) Opacity is an \e inherited attribute. That is, the opacity is also applied individually to child items. In almost all cases this - is what you want. If you can spot the issue in the following - example, you might need to use an \l Opacity effect instead. + is what you want, but in some cases (like the following example) + it may produce undesired results. \table \row @@ -2238,7 +2235,7 @@ QScriptValue QDeclarativeItem::mapFromItem(const QScriptValue &item, qreal x, qr QScriptValue sv = QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(this))->newObject(); QDeclarativeItem *itemObj = qobject_cast<QDeclarativeItem*>(item.toQObject()); if (!itemObj && !item.isNull()) { - qWarning().nospace() << "mapFromItem() given argument " << item.toString() << " which is neither null nor an Item"; + qmlInfo(this) << "mapFromItem() given argument \"" << item.toString() << "\" which is neither null nor an Item"; return 0; } @@ -2264,7 +2261,7 @@ QScriptValue QDeclarativeItem::mapToItem(const QScriptValue &item, qreal x, qrea QScriptValue sv = QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(this))->newObject(); QDeclarativeItem *itemObj = qobject_cast<QDeclarativeItem*>(item.toQObject()); if (!itemObj && !item.isNull()) { - qWarning().nospace() << "mapToItem() given argument " << item.toString() << " which is neither null nor an Item"; + qmlInfo(this) << "mapToItem() given argument \"" << item.toString() << "\" which is neither null nor an Item"; return 0; } @@ -2275,6 +2272,23 @@ QScriptValue QDeclarativeItem::mapToItem(const QScriptValue &item, qreal x, qrea return sv; } +/*! + \qmlmethod Item::forceFocus() + + Force the focus on the item. + This method sets the focus on the item and makes sure that all the focus scopes higher in the object hierarchy are given focus. +*/ +void QDeclarativeItem::forceFocus() +{ + setFocus(true); + QGraphicsItem *parent = parentItem(); + while (parent) { + if (parent->flags() & QGraphicsItem::ItemIsFocusScope) + parent->setFocus(Qt::OtherFocusReason); + parent = parent->parentItem(); + } +} + void QDeclarativeItemPrivate::focusChanged(bool flag) { Q_Q(QDeclarativeItem); @@ -2656,11 +2670,23 @@ void QDeclarativeItem::setTransformOrigin(TransformOrigin origin) Q_D(QDeclarativeItem); if (origin != d->origin) { d->origin = origin; - QGraphicsItem::setTransformOriginPoint(d->computeTransformOrigin()); + if (d->transformData) + QGraphicsItem::setTransformOriginPoint(d->computeTransformOrigin()); + else + d->transformOriginDirty = true; emit transformOriginChanged(d->origin); } } +void QDeclarativeItemPrivate::transformChanged() +{ + Q_Q(QDeclarativeItem); + if (transformOriginDirty) { + q->QGraphicsItem::setTransformOriginPoint(computeTransformOrigin()); + transformOriginDirty = false; + } +} + /*! \property QDeclarativeItem::smooth \brief whether the item is smoothly transformed. diff --git a/src/declarative/graphicsitems/qdeclarativeitem.h b/src/declarative/graphicsitems/qdeclarativeitem.h index 51889f6..da5a36e 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.h +++ b/src/declarative/graphicsitems/qdeclarativeitem.h @@ -157,6 +157,7 @@ public: Q_INVOKABLE QScriptValue mapFromItem(const QScriptValue &item, qreal x, qreal y) const; Q_INVOKABLE QScriptValue mapToItem(const QScriptValue &item, qreal x, qreal y) const; + Q_INVOKABLE void forceFocus(); QDeclarativeAnchorLine left() const; QDeclarativeAnchorLine right() const; diff --git a/src/declarative/graphicsitems/qdeclarativeitem_p.h b/src/declarative/graphicsitems/qdeclarativeitem_p.h index cf138c3..3f5bf1a 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem_p.h +++ b/src/declarative/graphicsitems/qdeclarativeitem_p.h @@ -116,7 +116,7 @@ public: _stateGroup(0), origin(QDeclarativeItem::Center), widthValid(false), heightValid(false), _componentComplete(true), _keepMouse(false), - smooth(false), keyHandler(0), + smooth(false), transformOriginDirty(true), keyHandler(0), mWidth(0), mHeight(0), implicitWidth(0), implicitHeight(0) { QGraphicsItemPrivate::acceptedMouseButtons = 0; @@ -233,6 +233,7 @@ public: bool _componentComplete:1; bool _keepMouse:1; bool smooth:1; + bool transformOriginDirty : 1; QDeclarativeItemKeyFilter *keyHandler; @@ -269,6 +270,9 @@ public: } } + // Reimplemented from QGraphicsItemPrivate + virtual void transformChanged(); + virtual void focusChanged(bool); static int consistentTime; diff --git a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp index 2d01eef..2945b6c 100644 --- a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp @@ -46,7 +46,6 @@ #include <QtGui/qgraphicseffect.h> #include "private/qdeclarativeevents_p_p.h" -#include "private/qdeclarativeeffects_p.h" #include "private/qdeclarativescalegrid_p_p.h" #include "private/qdeclarativeanimatedimage_p.h" #include "private/qdeclarativeborderimage_p.h" @@ -82,56 +81,59 @@ void QDeclarativeItemModule::defineModule() { -#ifndef QT_NO_MOVIE - qmlRegisterType<QDeclarativeAnimatedImage>("Qt",4,6,"AnimatedImage"); +#ifdef QT_NO_MOVIE + qmlRegisterTypeNotAvailable("Qt",4,7,"AnimatedImage", + qApp->translate("QDeclarativeAnimatedImage","Qt was built without support for QMovie")); +#else + qmlRegisterType<QDeclarativeAnimatedImage>("Qt",4,7,"AnimatedImage"); #endif - qmlRegisterType<QDeclarativeBorderImage>("Qt",4,6,"BorderImage"); - qmlRegisterType<QDeclarativeColumn>("Qt",4,6,"Column"); - qmlRegisterType<QDeclarativeDrag>("Qt",4,6,"Drag"); - qmlRegisterType<QDeclarativeFlickable>("Qt",4,6,"Flickable"); - qmlRegisterType<QDeclarativeFlipable>("Qt",4,6,"Flipable"); - qmlRegisterType<QDeclarativeFlow>("Qt",4,6,"Flow"); - qmlRegisterType<QDeclarativeFocusPanel>("Qt",4,6,"FocusPanel"); - qmlRegisterType<QDeclarativeFocusScope>("Qt",4,6,"FocusScope"); - qmlRegisterType<QDeclarativeGradient>("Qt",4,6,"Gradient"); - qmlRegisterType<QDeclarativeGradientStop>("Qt",4,6,"GradientStop"); - qmlRegisterType<QDeclarativeGrid>("Qt",4,6,"Grid"); - qmlRegisterType<QDeclarativeGridView>("Qt",4,6,"GridView"); - qmlRegisterType<QDeclarativeImage>("Qt",4,6,"Image"); - qmlRegisterType<QDeclarativeItem>("Qt",4,6,"Item"); - qmlRegisterType<QDeclarativeLayoutItem>("Qt",4,6,"LayoutItem"); - qmlRegisterType<QDeclarativeListView>("Qt",4,6,"ListView"); - qmlRegisterType<QDeclarativeLoader>("Qt",4,6,"Loader"); - qmlRegisterType<QDeclarativeMouseArea>("Qt",4,6,"MouseArea"); - qmlRegisterType<QDeclarativePath>("Qt",4,6,"Path"); - qmlRegisterType<QDeclarativePathAttribute>("Qt",4,6,"PathAttribute"); - qmlRegisterType<QDeclarativePathCubic>("Qt",4,6,"PathCubic"); - qmlRegisterType<QDeclarativePathLine>("Qt",4,6,"PathLine"); - qmlRegisterType<QDeclarativePathPercent>("Qt",4,6,"PathPercent"); - qmlRegisterType<QDeclarativePathQuad>("Qt",4,6,"PathQuad"); - qmlRegisterType<QDeclarativePathView>("Qt",4,6,"PathView"); - qmlRegisterType<QIntValidator>("Qt",4,6,"IntValidator"); + qmlRegisterType<QDeclarativeBorderImage>("Qt",4,7,"BorderImage"); + qmlRegisterType<QDeclarativeColumn>("Qt",4,7,"Column"); + qmlRegisterType<QDeclarativeDrag>("Qt",4,7,"Drag"); + qmlRegisterType<QDeclarativeFlickable>("Qt",4,7,"Flickable"); + qmlRegisterType<QDeclarativeFlipable>("Qt",4,7,"Flipable"); + qmlRegisterType<QDeclarativeFlow>("Qt",4,7,"Flow"); + qmlRegisterType<QDeclarativeFocusPanel>("Qt",4,7,"FocusPanel"); + qmlRegisterType<QDeclarativeFocusScope>("Qt",4,7,"FocusScope"); + qmlRegisterType<QDeclarativeGradient>("Qt",4,7,"Gradient"); + qmlRegisterType<QDeclarativeGradientStop>("Qt",4,7,"GradientStop"); + qmlRegisterType<QDeclarativeGrid>("Qt",4,7,"Grid"); + qmlRegisterType<QDeclarativeGridView>("Qt",4,7,"GridView"); + qmlRegisterType<QDeclarativeImage>("Qt",4,7,"Image"); + qmlRegisterType<QDeclarativeItem>("Qt",4,7,"Item"); + qmlRegisterType<QDeclarativeLayoutItem>("Qt",4,7,"LayoutItem"); + qmlRegisterType<QDeclarativeListView>("Qt",4,7,"ListView"); + qmlRegisterType<QDeclarativeLoader>("Qt",4,7,"Loader"); + qmlRegisterType<QDeclarativeMouseArea>("Qt",4,7,"MouseArea"); + qmlRegisterType<QDeclarativePath>("Qt",4,7,"Path"); + qmlRegisterType<QDeclarativePathAttribute>("Qt",4,7,"PathAttribute"); + qmlRegisterType<QDeclarativePathCubic>("Qt",4,7,"PathCubic"); + qmlRegisterType<QDeclarativePathLine>("Qt",4,7,"PathLine"); + qmlRegisterType<QDeclarativePathPercent>("Qt",4,7,"PathPercent"); + qmlRegisterType<QDeclarativePathQuad>("Qt",4,7,"PathQuad"); + qmlRegisterType<QDeclarativePathView>("Qt",4,7,"PathView"); + qmlRegisterType<QIntValidator>("Qt",4,7,"IntValidator"); qmlRegisterType<QDoubleValidator>("Qt",4,7,"DoubleValidator"); qmlRegisterType<QRegExpValidator>("Qt",4,7,"RegExpValidator"); - qmlRegisterType<QDeclarativeRectangle>("Qt",4,6,"Rectangle"); - qmlRegisterType<QDeclarativeRepeater>("Qt",4,6,"Repeater"); - qmlRegisterType<QGraphicsRotation>("Qt",4,6,"Rotation"); - qmlRegisterType<QDeclarativeRow>("Qt",4,6,"Row"); - qmlRegisterType<QDeclarativeTranslate>("Qt",4,6,"Translate"); - qmlRegisterType<QGraphicsScale>("Qt",4,6,"Scale"); - qmlRegisterType<QDeclarativeText>("Qt",4,6,"Text"); - qmlRegisterType<QDeclarativeTextEdit>("Qt",4,6,"TextEdit"); - qmlRegisterType<QDeclarativeTextInput>("Qt",4,6,"TextInput"); - qmlRegisterType<QDeclarativeViewSection>("Qt",4,6,"ViewSection"); - qmlRegisterType<QDeclarativeVisualDataModel>("Qt",4,6,"VisualDataModel"); - qmlRegisterType<QDeclarativeVisualItemModel>("Qt",4,6,"VisualItemModel"); + qmlRegisterType<QDeclarativeRectangle>("Qt",4,7,"Rectangle"); + qmlRegisterType<QDeclarativeRepeater>("Qt",4,7,"Repeater"); + qmlRegisterType<QGraphicsRotation>("Qt",4,7,"Rotation"); + qmlRegisterType<QDeclarativeRow>("Qt",4,7,"Row"); + qmlRegisterType<QDeclarativeTranslate>("Qt",4,7,"Translate"); + qmlRegisterType<QGraphicsScale>("Qt",4,7,"Scale"); + qmlRegisterType<QDeclarativeText>("Qt",4,7,"Text"); + qmlRegisterType<QDeclarativeTextEdit>("Qt",4,7,"TextEdit"); + qmlRegisterType<QDeclarativeTextInput>("Qt",4,7,"TextInput"); + qmlRegisterType<QDeclarativeViewSection>("Qt",4,7,"ViewSection"); + qmlRegisterType<QDeclarativeVisualDataModel>("Qt",4,7,"VisualDataModel"); + qmlRegisterType<QDeclarativeVisualItemModel>("Qt",4,7,"VisualItemModel"); qmlRegisterType<QDeclarativeAnchors>(); qmlRegisterType<QDeclarativeKeyEvent>(); qmlRegisterType<QDeclarativeMouseEvent>(); qmlRegisterType<QGraphicsObject>(); - qmlRegisterType<QGraphicsWidget>("Qt",4,6,"QGraphicsWidget"); - qmlRegisterExtendedType<QGraphicsWidget,QDeclarativeGraphicsWidget>("Qt",4,6,"QGraphicsWidget"); + qmlRegisterType<QGraphicsWidget>("Qt",4,7,"QGraphicsWidget"); + qmlRegisterExtendedType<QGraphicsWidget,QDeclarativeGraphicsWidget>("Qt",4,7,"QGraphicsWidget"); qmlRegisterType<QGraphicsTransform>(); qmlRegisterType<QDeclarativePathElement>(); qmlRegisterType<QDeclarativeCurve>(); @@ -141,17 +143,8 @@ void QDeclarativeItemModule::defineModule() qmlRegisterType<QAction>(); qmlRegisterType<QDeclarativePen>(); qmlRegisterType<QDeclarativeFlickableVisibleArea>(); -#ifndef QT_NO_GRAPHICSEFFECT qmlRegisterType<QGraphicsEffect>(); - qmlRegisterType<QGraphicsBlurEffect>("Qt",4,6,"Blur"); - qmlRegisterType<QGraphicsColorizeEffect>("Qt",4,6,"Colorize"); - qmlRegisterType<QGraphicsDropShadowEffect>("Qt",4,6,"DropShadow"); - qmlRegisterType<QGraphicsOpacityEffect>("Qt",4,6,"Opacity"); -#endif -#ifdef QT_WEBKIT_LIB - qmlRegisterType<QDeclarativeWebSettings>(); -#endif - qmlRegisterUncreatableType<QDeclarativeKeyNavigationAttached>("Qt",4,6,"KeyNavigation"); - qmlRegisterUncreatableType<QDeclarativeKeysAttached>("Qt",4,6,"Keys"); + qmlRegisterUncreatableType<QDeclarativeKeyNavigationAttached>("Qt",4,7,"KeyNavigation",QDeclarativeKeyNavigationAttached::tr("KeyNavigation is only available via attached properties")); + qmlRegisterUncreatableType<QDeclarativeKeysAttached>("Qt",4,7,"Keys",QDeclarativeKeysAttached::tr("Keys is only available via attached properties")); } diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 307c0a7..60e8f6c 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -50,6 +50,7 @@ #include <qdeclarativeguard_p.h> #include <qlistmodelinterface_p.h> +#include <qmath.h> #include <QKeyEvent> QT_BEGIN_NAMESPACE @@ -270,6 +271,28 @@ public: return 0; } + qreal endPositionAt(int modelIndex) const { + if (FxListItem *item = visibleItem(modelIndex)) + return item->endPosition(); + if (!visibleItems.isEmpty()) { + if (modelIndex < visibleIndex) { + int count = visibleIndex - modelIndex; + return (*visibleItems.constBegin())->position() - (count - 1) * (averageSize + spacing) - spacing - 1; + } else { + int idx = visibleItems.count() - 1; + while (idx >= 0 && visibleItems.at(idx)->index == -1) + --idx; + if (idx < 0) + idx = visibleIndex; + else + idx = visibleItems.at(idx)->index; + int count = modelIndex - idx - 1; + return (*(--visibleItems.constEnd()))->endPosition() + count * (averageSize + spacing); + } + } + return 0; + } + QString sectionAt(int modelIndex) { if (FxListItem *item = visibleItem(modelIndex)) return item->attached->section(); @@ -395,13 +418,16 @@ public: } void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) { + Q_Q(QDeclarativeListView); QDeclarativeFlickablePrivate::itemGeometryChanged(item, newGeometry, oldGeometry); - if (item != viewport) { + if (item != viewport && (!highlight || item != highlight->item)) { if ((orient == QDeclarativeListView::Vertical && newGeometry.height() != oldGeometry.height()) || (orient == QDeclarativeListView::Horizontal && newGeometry.width() != oldGeometry.width())) { scheduleLayout(); } } + if (trackedItem && trackedItem->item == item) + q->trackedPositionChanged(); } // for debugging only @@ -566,13 +592,8 @@ void QDeclarativeListViewPrivate::releaseItem(FxListItem *item) Q_Q(QDeclarativeListView); if (!item || !model) return; - if (trackedItem == item) { - const char *notifier1 = orient == QDeclarativeListView::Vertical ? SIGNAL(yChanged()) : SIGNAL(xChanged()); - const char *notifier2 = orient == QDeclarativeListView::Vertical ? SIGNAL(heightChanged()) : SIGNAL(widthChanged()); - QObject::disconnect(trackedItem->item, notifier1, q, SLOT(trackedPositionChanged())); - QObject::disconnect(trackedItem->item, notifier2, q, SLOT(trackedPositionChanged())); + if (trackedItem == item) trackedItem = 0; - } QDeclarativeItemPrivate *itemPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(item->item)); itemPrivate->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry); if (model->release(item->item) == 0) { @@ -769,21 +790,7 @@ void QDeclarativeListViewPrivate::updateTrackedItem() FxListItem *item = currentItem; if (highlight) item = highlight; - - const char *notifier1 = orient == QDeclarativeListView::Vertical ? SIGNAL(yChanged()) : SIGNAL(xChanged()); - const char *notifier2 = orient == QDeclarativeListView::Vertical ? SIGNAL(heightChanged()) : SIGNAL(widthChanged()); - - if (trackedItem && item != trackedItem) { - QObject::disconnect(trackedItem->item, notifier1, q, SLOT(trackedPositionChanged())); - QObject::disconnect(trackedItem->item, notifier2, q, SLOT(trackedPositionChanged())); - trackedItem = 0; - } - - if (!trackedItem && item) { - trackedItem = item; - QObject::connect(trackedItem->item, notifier1, q, SLOT(trackedPositionChanged())); - QObject::connect(trackedItem->item, notifier2, q, SLOT(trackedPositionChanged())); - } + trackedItem = item; if (trackedItem) q->trackedPositionChanged(); } @@ -832,6 +839,8 @@ void QDeclarativeListViewPrivate::createHighlight() highlight->item->setWidth(currentItem->item->width()); } } + QDeclarativeItemPrivate *itemPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(item)); + itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry); const QLatin1String posProp(orient == QDeclarativeListView::Vertical ? "y" : "x"); highlightPosAnimator = new QSmoothedAnimation(q); highlightPosAnimator->target = QDeclarativeProperty(highlight->item, posProp); @@ -1101,23 +1110,27 @@ void QDeclarativeListViewPrivate::fixup(AxisData &data, qreal minExtent, qreal m || (orient == QDeclarativeListView::Vertical && &data == &hData)) return; - if ((&data == &vData && !q->yflick()) - || (&data == &hData && !q->xflick()) - || data.move.timeLine()) - return; - int oldDuration = fixupDuration; fixupDuration = moveReason == Mouse ? fixupDuration : 0; if (haveHighlightRange && highlightRange == QDeclarativeListView::StrictlyEnforceRange) { - if (currentItem && currentItem->position() - position() != highlightRangeStart) { - qreal pos = currentItem->position() - highlightRangeStart; + if (currentItem) { + updateHighlight(); + qreal pos = currentItem->position(); + qreal viewPos = position(); + if (viewPos < pos + currentItem->size() - highlightRangeEnd) + viewPos = pos + currentItem->size() - highlightRangeEnd; + if (viewPos > pos - highlightRangeStart) + viewPos = pos - highlightRangeStart; + timeline.reset(data.move); - if (fixupDuration) { - timeline.move(data.move, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2); - } else { - data.move.setValue(-pos); - q->viewportMoved(); + if (viewPos != position()) { + if (fixupDuration) { + timeline.move(data.move, -viewPos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2); + } else { + data.move.setValue(-viewPos); + q->viewportMoved(); + } } vTime = timeline.time(); } @@ -1177,6 +1190,7 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m if (snapMode == QDeclarativeListView::NoSnap && highlightRange != QDeclarativeListView::StrictlyEnforceRange) data.flickTarget = maxExtent; } + bool overShoot = boundsBehavior == QDeclarativeFlickable::DragAndOvershootBounds; if (maxDistance > 0 || overShoot) { // These modes require the list to stop exactly on an item boundary. // The initial flick will estimate the boundary to stop on. @@ -1211,7 +1225,15 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m data.flickTarget -= overshootDist; } } - dist = -data.flickTarget + data.move.value(); + qreal adjDist = -data.flickTarget + data.move.value(); + if (qAbs(adjDist) > qAbs(dist)) { + // Prevent painfully slow flicking - adjust velocity to suit flickDeceleration + v2 = accel * 2.0f * qAbs(dist); + v = qSqrt(v2); + if (dist > 0) + v = -v; + } + dist = adjDist; accel = v2 / (2.0f * qAbs(dist)); } else if (overShoot) { data.flickTarget = data.move.value() - dist; @@ -1286,7 +1308,7 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m In this case ListModel is a handy way for us to test our UI. In practice the model would be implemented in C++, or perhaps via a SQL data source. - Note that views do not enable \e clip automatically. If the view + \bold Note that views do not enable \e clip automatically. If the view is not clipped by another item or the screen, it will be necessary to set \e {clip: true} in order to have the out of view items clipped nicely. @@ -2062,12 +2084,12 @@ void QDeclarativeListView::viewportMoved() if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange && d->highlight) { // reposition highlight qreal pos = d->highlight->position(); - qreal viewPos = qRound(d->position()); - if (pos > viewPos + d->highlightRangeEnd - 1 - d->highlight->size()) - pos = viewPos + d->highlightRangeEnd - 1 - d->highlight->size(); + qreal viewPos = d->position(); + if (pos > viewPos + d->highlightRangeEnd - d->highlight->size()) + pos = viewPos + d->highlightRangeEnd - d->highlight->size(); if (pos < viewPos + d->highlightRangeStart) pos = viewPos + d->highlightRangeStart; - d->highlight->setPosition(pos); + d->highlight->setPosition(qRound(pos)); // update current index int idx = d->snapIndex(); @@ -2124,8 +2146,10 @@ qreal QDeclarativeListView::minYExtent() const d->minExtent = -d->startPosition(); if (d->header && d->visibleItems.count()) d->minExtent += d->header->size(); - if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) + if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) { d->minExtent += d->highlightRangeStart; + d->minExtent = qMax(d->minExtent, -(d->endPositionAt(0) - d->highlightRangeEnd + 1)); + } d->minExtentDirty = false; } @@ -2139,10 +2163,12 @@ qreal QDeclarativeListView::maxYExtent() const return height(); if (d->maxExtentDirty) { if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) { - d->maxExtent = -(d->endPosition() - d->highlightRangeEnd); - d->maxExtent = qMax(d->maxExtent, -(d->positionAt(d->model->count()-1) - d->highlightRangeStart)); - } else + d->maxExtent = -(d->positionAt(d->model->count()-1) - d->highlightRangeStart); + if (d->highlightRangeEnd != d->highlightRangeStart) + d->maxExtent = qMin(d->maxExtent, -(d->endPosition() - d->highlightRangeEnd + 1)); + } else { d->maxExtent = -(d->endPosition() - height() + 1); + } if (d->footer) d->maxExtent -= d->footer->size(); qreal minY = minYExtent(); @@ -2162,8 +2188,10 @@ qreal QDeclarativeListView::minXExtent() const d->minExtent = -d->startPosition(); if (d->header) d->minExtent += d->header->size(); - if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) + if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) { d->minExtent += d->highlightRangeStart; + d->minExtent = qMax(d->minExtent, -(d->endPositionAt(0) - d->highlightRangeEnd + 1)); + } d->minExtentDirty = false; } @@ -2177,10 +2205,12 @@ qreal QDeclarativeListView::maxXExtent() const return width(); if (d->maxExtentDirty) { if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) { - d->maxExtent = -(d->endPosition() - d->highlightRangeEnd); - d->maxExtent = qMax(d->maxExtent, -(d->positionAt(d->model->count()-1) - d->highlightRangeStart)); - } else + d->maxExtent = -(d->positionAt(d->model->count()-1) - d->highlightRangeStart); + if (d->highlightRangeEnd != d->highlightRangeStart) + d->maxExtent = qMin(d->maxExtent, -(d->endPosition() - d->highlightRangeEnd + 1)); + } else { d->maxExtent = -(d->endPosition() - width() + 1); + } if (d->footer) d->maxExtent -= d->footer->size(); qreal minX = minXExtent(); @@ -2389,7 +2419,7 @@ void QDeclarativeListView::trackedPositionChanged() if (!d->trackedItem || !d->currentItem) return; if (!isFlicking() && !d->moving && d->moveReason == QDeclarativeListViewPrivate::SetIndex) { - const qreal trackedPos = d->trackedItem->position(); + const qreal trackedPos = qCeil(d->trackedItem->position()); const qreal viewPos = d->position(); if (d->haveHighlightRange) { if (d->highlightRange == StrictlyEnforceRange) { @@ -2823,6 +2853,8 @@ void QDeclarativeListView::animStopped() { Q_D(QDeclarativeListView); d->bufferMode = QDeclarativeListViewPrivate::NoBuffer; + if (d->haveHighlightRange && d->highlightRange == QDeclarativeListView::StrictlyEnforceRange) + d->updateHighlight(); } QDeclarativeListViewAttached *QDeclarativeListView::qmlAttachedProperties(QObject *obj) diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp index 409c228..bdd2c87 100644 --- a/src/declarative/graphicsitems/qdeclarativeloader.cpp +++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp @@ -132,12 +132,15 @@ void QDeclarativeLoaderPrivate::initResize() \endcode If the Loader source is changed, any previous items instantiated - will be destroyed. Setting \c source to an empty string + will be destroyed. Setting \c source to an empty string, or setting + sourceComponent to \e undefined will destroy the currently instantiated items, freeing resources and leaving the Loader empty. For example: \code pageLoader.source = "" + or + pageLoader.sourceComponent = undefined \endcode unloads "Page1.qml" and frees resources consumed by it. @@ -271,13 +274,18 @@ void QDeclarativeLoader::setSourceComponent(QDeclarativeComponent *comp) } } +void QDeclarativeLoader::resetSourceComponent() +{ + setSourceComponent(0); +} + void QDeclarativeLoaderPrivate::_q_sourceLoaded() { Q_Q(QDeclarativeLoader); if (component) { if (!component->errors().isEmpty()) { - qWarning() << component->errors(); + QDeclarativeEnginePrivate::warning(qmlEngine(q), component->errors()); emit q->sourceChanged(); emit q->statusChanged(); emit q->progressChanged(); @@ -312,7 +320,7 @@ void QDeclarativeLoaderPrivate::_q_sourceLoaded() } } else { if (!component->errors().isEmpty()) - qWarning() << component->errors(); + QDeclarativeEnginePrivate::warning(qmlEngine(q), component->errors()); delete obj; delete ctxt; source = QUrl(); @@ -325,7 +333,7 @@ void QDeclarativeLoaderPrivate::_q_sourceLoaded() } /*! - \qmlproperty enum Loader::status + \qmlproperty enumeration Loader::status This property holds the status of QML loading. It can be one of: \list @@ -383,7 +391,7 @@ qreal QDeclarativeLoader::progress() const } /*! - \qmlproperty enum Loader::resizeMode + \qmlproperty enumeration Loader::resizeMode This property determines how the Loader or item are resized: \list diff --git a/src/declarative/graphicsitems/qdeclarativeloader_p.h b/src/declarative/graphicsitems/qdeclarativeloader_p.h index 65538a8..e9fd8e9 100644 --- a/src/declarative/graphicsitems/qdeclarativeloader_p.h +++ b/src/declarative/graphicsitems/qdeclarativeloader_p.h @@ -58,7 +58,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeLoader : public QDeclarativeItem Q_ENUMS(ResizeMode) Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) - Q_PROPERTY(QDeclarativeComponent *sourceComponent READ sourceComponent WRITE setSourceComponent NOTIFY sourceChanged) + Q_PROPERTY(QDeclarativeComponent *sourceComponent READ sourceComponent WRITE setSourceComponent RESET resetSourceComponent NOTIFY sourceChanged) Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode NOTIFY resizeModeChanged) Q_PROPERTY(QGraphicsObject *item READ item NOTIFY itemChanged) Q_PROPERTY(Status status READ status NOTIFY statusChanged) @@ -73,6 +73,7 @@ public: QDeclarativeComponent *sourceComponent() const; void setSourceComponent(QDeclarativeComponent *); + void resetSourceComponent(); enum Status { Null, Ready, Loading, Error }; Status status() const; diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp index a6cc75e..126d041 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp +++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp @@ -50,7 +50,8 @@ QT_BEGIN_NAMESPACE static const int PressAndHoldDelay = 800; QDeclarativeDrag::QDeclarativeDrag(QObject *parent) -: QObject(parent), _target(0), _axis(XandYAxis), _xmin(0), _xmax(0), _ymin(0), _ymax(0) +: QObject(parent), _target(0), _axis(XandYAxis), _xmin(0), _xmax(0), _ymin(0), _ymax(0), +_active(false) { } @@ -144,6 +145,19 @@ void QDeclarativeDrag::setYmax(qreal m) emit maximumYChanged(); } +bool QDeclarativeDrag::active() const +{ + return _active; +} + +void QDeclarativeDrag::setActive(bool drag) +{ + if (_active == drag) + return; + _active = drag; + emit activeChanged(); +} + QDeclarativeMouseAreaPrivate::~QDeclarativeMouseAreaPrivate() { delete drag; @@ -389,7 +403,8 @@ void QDeclarativeMouseArea::mousePressEvent(QGraphicsSceneMouseEvent *event) d->dragX = drag()->axis() & QDeclarativeDrag::XAxis; d->dragY = drag()->axis() & QDeclarativeDrag::YAxis; } - d->dragged = false; + if (d->drag) + d->drag->setActive(false); setHovered(true); d->startScene = event->scenePos(); // we should only start timer if pressAndHold is connected to. @@ -438,7 +453,7 @@ void QDeclarativeMouseArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event) qreal dx = qAbs(curLocalPos.x() - startLocalPos.x()); qreal dy = qAbs(curLocalPos.y() - startLocalPos.y()); if ((d->dragX && !(dx < dragThreshold)) || (d->dragY && !(dy < dragThreshold))) - d->dragged = true; + d->drag->setActive(true); if (!keepMouseGrab()) { if ((!d->dragY && dy < dragThreshold && d->dragX && dx > dragThreshold) || (!d->dragX && dx < dragThreshold && d->dragY && dy > dragThreshold) @@ -447,7 +462,7 @@ void QDeclarativeMouseArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event) } } - if (d->dragX && d->dragged) { + if (d->dragX && d->drag->active()) { qreal x = (curLocalPos.x() - startLocalPos.x()) + d->startX; if (x < drag()->xmin()) x = drag()->xmin(); @@ -455,7 +470,7 @@ void QDeclarativeMouseArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event) x = drag()->xmax(); drag()->target()->setX(x); } - if (d->dragY && d->dragged) { + if (d->dragY && d->drag->active()) { qreal y = (curLocalPos.y() - startLocalPos.y()) + d->startY; if (y < drag()->ymin()) y = drag()->ymin(); @@ -466,6 +481,9 @@ void QDeclarativeMouseArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event) d->moved = true; } QDeclarativeMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress); + emit mousePositionChanged(&me); + me.setX(d->lastPos.x()); + me.setY(d->lastPos.y()); emit positionChanged(&me); } @@ -478,6 +496,8 @@ void QDeclarativeMouseArea::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) } else { d->saveEvent(event); setPressed(false); + if (d->drag) + d->drag->setActive(false); // If we don't accept hover, we need to reset containsMouse. if (!acceptHoverEvents()) setHovered(false); @@ -518,6 +538,9 @@ void QDeclarativeMouseArea::hoverMoveEvent(QGraphicsSceneHoverEvent *event) } else { d->lastPos = event->pos(); QDeclarativeMouseEvent me(d->lastPos.x(), d->lastPos.y(), Qt::NoButton, d->lastButtons, d->lastModifiers, false, d->longPress); + emit mousePositionChanged(&me); + me.setX(d->lastPos.x()); + me.setY(d->lastPos.y()); emit positionChanged(&me); } } @@ -541,8 +564,10 @@ bool QDeclarativeMouseArea::sceneEvent(QEvent *event) // state d->pressed = false; setKeepMouseGrab(false); + QDeclarativeMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, false); + emit released(&me); emit pressedChanged(); - //emit hoveredChanged(); + setHovered(false); } } return rv; @@ -553,7 +578,8 @@ void QDeclarativeMouseArea::timerEvent(QTimerEvent *event) Q_D(QDeclarativeMouseArea); if (event->timerId() == d->pressAndHoldTimer.timerId()) { d->pressAndHoldTimer.stop(); - if (d->pressed && d->dragged == false && d->hovered == true) { + bool dragged = d->drag && d->drag->active(); + if (d->pressed && dragged == false && d->hovered == true) { d->longPress = true; QDeclarativeMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress); emit pressAndHold(&me); @@ -561,6 +587,18 @@ void QDeclarativeMouseArea::timerEvent(QTimerEvent *event) } } +void QDeclarativeMouseArea::geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry) +{ + Q_D(QDeclarativeMouseArea); + QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); + + if (d->lastScenePos.isNull) + d->lastScenePos = mapToScene(d->lastPos); + else if (newGeometry.x() != oldGeometry.x() || newGeometry.y() != oldGeometry.y()) + d->lastPos = mapFromScene(d->lastScenePos); +} + /*! \qmlproperty bool MouseArea::hoverEnabled This property holds whether hover events are handled. @@ -641,16 +679,21 @@ void QDeclarativeMouseArea::setAcceptedButtons(Qt::MouseButtons buttons) bool QDeclarativeMouseArea::setPressed(bool p) { Q_D(QDeclarativeMouseArea); - bool isclick = d->pressed == true && p == false && d->dragged == false && d->hovered == true; + bool dragged = d->drag && d->drag->active(); + bool isclick = d->pressed == true && p == false && dragged == false && d->hovered == true; if (d->pressed != p) { d->pressed = p; QDeclarativeMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, isclick, d->longPress); if (d->pressed) { emit pressed(&me); - emit positionChanged(&me); + me.setX(d->lastPos.x()); + me.setY(d->lastPos.y()); + emit mousePositionChanged(&me); } else { emit released(&me); + me.setX(d->lastPos.x()); + me.setY(d->lastPos.y()); if (isclick && !d->longPress) emit clicked(&me); } @@ -671,6 +714,7 @@ QDeclarativeDrag *QDeclarativeMouseArea::drag() /*! \qmlproperty Item MouseArea::drag.target + \qmlproperty bool MouseArea::drag.active \qmlproperty Axis MouseArea::drag.axis \qmlproperty real MouseArea::drag.minimumX \qmlproperty real MouseArea::drag.maximumX @@ -681,6 +725,7 @@ QDeclarativeDrag *QDeclarativeMouseArea::drag() \list \i \c target specifies the item to drag. + \i \c active specifies if the target item is being currently dragged. \i \c axis specifies whether dragging can be done horizontally (XAxis), vertically (YAxis), or both (XandYAxis) \i the minimum and maximum properties limit how far the target can be dragged along the corresponding axes. \endlist diff --git a/src/declarative/graphicsitems/qdeclarativemousearea_p.h b/src/declarative/graphicsitems/qdeclarativemousearea_p.h index 58faac1..4f7df62 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea_p.h +++ b/src/declarative/graphicsitems/qdeclarativemousearea_p.h @@ -61,6 +61,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeDrag : public QObject Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax NOTIFY maximumXChanged) Q_PROPERTY(qreal minimumY READ ymin WRITE setYmin NOTIFY minimumYChanged) Q_PROPERTY(qreal maximumY READ ymax WRITE setYmax NOTIFY maximumYChanged) + Q_PROPERTY(bool active READ active NOTIFY activeChanged) //### consider drag and drop public: @@ -84,6 +85,9 @@ public: qreal ymax() const; void setYmax(qreal); + bool active() const; + void setActive(bool); + Q_SIGNALS: void targetChanged(); void axisChanged(); @@ -91,6 +95,7 @@ Q_SIGNALS: void maximumXChanged(); void minimumYChanged(); void maximumYChanged(); + void activeChanged(); private: QGraphicsObject *_target; @@ -99,6 +104,7 @@ private: qreal _xmax; qreal _ymin; qreal _ymax; + bool _active; Q_DISABLE_COPY(QDeclarativeDrag) }; @@ -108,8 +114,8 @@ class Q_DECLARATIVE_EXPORT QDeclarativeMouseArea : public QDeclarativeItem { Q_OBJECT - Q_PROPERTY(qreal mouseX READ mouseX NOTIFY positionChanged) - Q_PROPERTY(qreal mouseY READ mouseY NOTIFY positionChanged) + Q_PROPERTY(qreal mouseX READ mouseX NOTIFY mousePositionChanged) + Q_PROPERTY(qreal mouseY READ mouseY NOTIFY mousePositionChanged) Q_PROPERTY(bool containsMouse READ hovered NOTIFY hoveredChanged) Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged) Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) @@ -144,6 +150,7 @@ Q_SIGNALS: void enabledChanged(); void acceptedButtonsChanged(); void positionChanged(QDeclarativeMouseEvent *mouse); + void mousePositionChanged(QDeclarativeMouseEvent *mouse); void pressed(QDeclarativeMouseEvent *mouse); void pressAndHold(QDeclarativeMouseEvent *mouse); @@ -167,6 +174,9 @@ protected: bool sceneEvent(QEvent *); void timerEvent(QTimerEvent *event); + virtual void geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry); + private: void handlePress(); void handleRelease(); diff --git a/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h b/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h index 9068c7c..4e909ff 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h @@ -67,7 +67,8 @@ class QDeclarativeMouseAreaPrivate : public QDeclarativeItemPrivate public: QDeclarativeMouseAreaPrivate() - : absorb(true), hovered(false), pressed(false), longPress(false), drag(0) + : absorb(true), hovered(false), pressed(false), longPress(false), + moved(false), drag(0) { } @@ -81,6 +82,7 @@ public: void saveEvent(QGraphicsSceneMouseEvent *event) { lastPos = event->pos(); + lastScenePos = event->scenePos(); lastButton = event->button(); lastButtons = event->buttons(); lastModifiers = event->modifiers(); @@ -99,12 +101,12 @@ public: bool moved : 1; bool dragX : 1; bool dragY : 1; - bool dragged : 1; QDeclarativeDrag *drag; QPointF startScene; qreal startX; qreal startY; QPointF lastPos; + QDeclarativeNullableValue<QPointF> lastScenePos; Qt::MouseButton lastButton; Qt::MouseButtons lastButtons; Qt::KeyboardModifiers lastModifiers; diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp index 4aaa28d..d0a3cd1 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview.cpp +++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp @@ -314,7 +314,7 @@ void QDeclarativePathViewPrivate::regenerate() \image pathview.gif - Note that views do not enable \e clip automatically. If the view + \bold Note that views do not enable \e clip automatically. If the view is not clipped by another item or the screen, it will be necessary to set \e {clip: true} in order to have the out of view items clipped nicely. diff --git a/src/declarative/graphicsitems/qdeclarativepositioners_p.h b/src/declarative/graphicsitems/qdeclarativepositioners_p.h index 24b65fa..b5fc979 100644 --- a/src/declarative/graphicsitems/qdeclarativepositioners_p.h +++ b/src/declarative/graphicsitems/qdeclarativepositioners_p.h @@ -136,7 +136,7 @@ private: class Q_DECLARATIVE_EXPORT QDeclarativeGrid : public QDeclarativeBasePositioner { Q_OBJECT - Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowChanged) + Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowsChanged) Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged) Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged) diff --git a/src/declarative/graphicsitems/qdeclarativerectangle.cpp b/src/declarative/graphicsitems/qdeclarativerectangle.cpp index 54c8ab2..0328f91 100644 --- a/src/declarative/graphicsitems/qdeclarativerectangle.cpp +++ b/src/declarative/graphicsitems/qdeclarativerectangle.cpp @@ -172,6 +172,8 @@ void QDeclarativeGradient::doUpdate() \image declarative-rect.png */ +int QDeclarativeRectanglePrivate::doUpdateSlotIdx = -1; + /*! \internal \class QDeclarativeRectangle @@ -252,11 +254,16 @@ void QDeclarativeRectangle::setGradient(QDeclarativeGradient *gradient) Q_D(QDeclarativeRectangle); if (d->gradient == gradient) return; + static int updatedSignalIdx = -1; + if (updatedSignalIdx < 0) + updatedSignalIdx = QDeclarativeGradient::staticMetaObject.indexOfSignal("updated()"); + if (d->doUpdateSlotIdx < 0) + d->doUpdateSlotIdx = QDeclarativeRectangle::staticMetaObject.indexOfSlot("doUpdate()"); if (d->gradient) - disconnect(d->gradient, SIGNAL(updated()), this, SLOT(doUpdate())); + QMetaObject::disconnect(d->gradient, updatedSignalIdx, this, d->doUpdateSlotIdx); d->gradient = gradient; if (d->gradient) - connect(d->gradient, SIGNAL(updated()), this, SLOT(doUpdate())); + QMetaObject::connect(d->gradient, updatedSignalIdx, this, d->doUpdateSlotIdx); update(); } diff --git a/src/declarative/graphicsitems/qdeclarativerectangle_p_p.h b/src/declarative/graphicsitems/qdeclarativerectangle_p_p.h index 84418bc..001b018 100644 --- a/src/declarative/graphicsitems/qdeclarativerectangle_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativerectangle_p_p.h @@ -81,12 +81,18 @@ public: qreal radius; qreal paintmargin; QPixmap rectImage; + static int doUpdateSlotIdx; QDeclarativePen *getPen() { if (!pen) { Q_Q(QDeclarativeRectangle); pen = new QDeclarativePen; - QObject::connect(pen, SIGNAL(penChanged()), q, SLOT(doUpdate())); + static int penChangedSignalIdx = -1; + if (penChangedSignalIdx < 0) + penChangedSignalIdx = QDeclarativePen::staticMetaObject.indexOfSignal("penChanged()"); + if (doUpdateSlotIdx < 0) + doUpdateSlotIdx = QDeclarativeRectangle::staticMetaObject.indexOfSlot("doUpdate()"); + QMetaObject::connect(pen, penChangedSignalIdx, q, doUpdateSlotIdx); } return pen; } diff --git a/src/declarative/graphicsitems/qdeclarativescalegrid.cpp b/src/declarative/graphicsitems/qdeclarativescalegrid.cpp index e68f645..fe89190 100644 --- a/src/declarative/graphicsitems/qdeclarativescalegrid.cpp +++ b/src/declarative/graphicsitems/qdeclarativescalegrid.cpp @@ -175,7 +175,7 @@ QDeclarativeBorderImage::TileMode QDeclarativeGridScaledImage::stringToRule(cons if (s == QLatin1String("Round")) return QDeclarativeBorderImage::Round; - qWarning() << "Unknown tile rule specified. Using Stretch"; + qWarning("QDeclarativeGridScaledImage: Invalid tile rule specified. Using Stretch."); return QDeclarativeBorderImage::Stretch; } diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index a95c930..0b59503 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -525,18 +525,6 @@ void QDeclarativeText::setWrapMode(WrapMode mode) emit wrapModeChanged(); } -bool QDeclarativeText::wrap() const -{ - Q_D(const QDeclarativeText); - return d->wrapMode != NoWrap; -} - -void QDeclarativeText::setWrap(bool w) -{ - qmlInfo(this) << "\"wrap\" property is deprecated and will soon be removed. Use wrapMode"; - setWrapMode(w ? WordWrap : NoWrap); -} - /*! \qmlproperty enumeration Text::textFormat diff --git a/src/declarative/graphicsitems/qdeclarativetext_p.h b/src/declarative/graphicsitems/qdeclarativetext_p.h index 4fd5e3a..00ce126 100644 --- a/src/declarative/graphicsitems/qdeclarativetext_p.h +++ b/src/declarative/graphicsitems/qdeclarativetext_p.h @@ -69,7 +69,6 @@ class Q_DECLARATIVE_EXPORT QDeclarativeText : public QDeclarativeItem Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign NOTIFY horizontalAlignmentChanged) Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged) Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged) - Q_PROPERTY(bool wrap READ wrap WRITE setWrap NOTIFY wrapModeChanged) Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged) Q_PROPERTY(TextElideMode elide READ elideMode WRITE setElideMode NOTIFY elideModeChanged) //### elideMode? @@ -123,8 +122,6 @@ public: VAlignment vAlign() const; void setVAlign(VAlignment align); - bool wrap() const; - void setWrap(bool w); WrapMode wrapMode() const; void setWrapMode(WrapMode w); diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index 1fec484..25eaef6 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -495,19 +495,6 @@ void QDeclarativeTextEdit::setWrapMode(WrapMode mode) emit wrapModeChanged(); } -bool QDeclarativeTextEdit::wrap() const -{ - Q_D(const QDeclarativeTextEdit); - return d->wrapMode != QDeclarativeTextEdit::NoWrap; -} - -void QDeclarativeTextEdit::setWrap(bool w) -{ - - qmlInfo(this) << "\"wrap\" property is deprecated and will soon be removed. Use wrapMode"; - setWrapMode(w ? WordWrap : NoWrap); -} - /*! \qmlproperty bool TextEdit::cursorVisible If true the text edit shows a cursor. @@ -614,7 +601,7 @@ void QDeclarativeTextEdit::loadCursorDelegate() d->cursor->setHeight(QFontMetrics(d->font).height()); moveCursorDelegate(); }else{ - qWarning() << QLatin1String("Error loading cursor delegate for TextEdit:") + objectName(); + qmlInfo(this) << "Error loading cursor delegate."; } } @@ -1076,8 +1063,6 @@ void QDeclarativeTextEditPrivate::updateSelection() q->selectionEndChanged(); startChange = (lastSelectionStart != control->textCursor().selectionStart()); endChange = (lastSelectionEnd != control->textCursor().selectionEnd()); - if(startChange || endChange) - qWarning() << "QDeclarativeTextEditPrivate::updateSelection() has failed you."; } void QDeclarativeTextEdit::updateSelectionMarkers() diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p.h index 605b620..474de09 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextedit_p.h @@ -73,7 +73,6 @@ class Q_DECLARATIVE_EXPORT QDeclarativeTextEdit : public QDeclarativePaintedItem Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign NOTIFY horizontalAlignmentChanged) Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged) - Q_PROPERTY(bool wrap READ wrap WRITE setWrap NOTIFY wrapChanged) //### deprecated Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged) Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged) Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged) @@ -139,8 +138,6 @@ public: VAlignment vAlign() const; void setVAlign(VAlignment align); - bool wrap() const; - void setWrap(bool w); WrapMode wrapMode() const; void setWrapMode(WrapMode w); diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index e00d333..2161e23 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -779,9 +779,8 @@ void QDeclarativeTextInputPrivate::startCreatingCursor() }else if(cursorComponent->isLoading()){ q->connect(cursorComponent, SIGNAL(statusChanged(int)), q, SLOT(createCursor())); - }else{//isError - qmlInfo(q) << QDeclarativeTextInput::tr("Could not load cursor delegate"); - qWarning() << cursorComponent->errors(); + }else {//isError + qmlInfo(q, cursorComponent->errors()) << QDeclarativeTextInput::tr("Could not load cursor delegate"); } } @@ -789,8 +788,7 @@ void QDeclarativeTextInput::createCursor() { Q_D(QDeclarativeTextInput); if(d->cursorComponent->isError()){ - qmlInfo(this) << tr("Could not load cursor delegate"); - qWarning() << d->cursorComponent->errors(); + qmlInfo(this, d->cursorComponent->errors()) << tr("Could not load cursor delegate"); return; } @@ -801,8 +799,7 @@ void QDeclarativeTextInput::createCursor() delete d->cursorItem; d->cursorItem = qobject_cast<QDeclarativeItem*>(d->cursorComponent->create()); if(!d->cursorItem){ - qmlInfo(this) << tr("Could not instantiate cursor delegate"); - //The failed instantiation should print its own error messages + qmlInfo(this, d->cursorComponent->errors()) << tr("Could not instantiate cursor delegate"); return; } diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index 751284d..e2d8bc7 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -198,7 +198,7 @@ QVariant QDeclarativeVisualItemModel::evaluate(int index, const QString &express QDeclarativeContext *ctxt = new QDeclarativeContext(ccontext); ctxt->setContextObject(d->children.at(index)); QDeclarativeExpression e(ctxt, expression, objectContext); - QVariant value = e.value(); + QVariant value = e.evaluate(); delete ctxt; return value; } @@ -262,6 +262,7 @@ public: } if (m_roles.count() == 1) m_roleNames.insert("modelData", m_roles.at(0)); + m_roleNames.insert("hasModelChildren", 0); } else if (m_listAccessor) { m_roleNames.insert("modelData", 0); if (m_listAccessor->type() == QDeclarativeListAccessor::Instance) { @@ -473,11 +474,16 @@ QVariant QDeclarativeVisualDataModelDataMetaObject::initialValue(int propId) } } else if (model->m_abstractItemModel) { model->ensureRoles(); - QHash<QByteArray,int>::const_iterator it = model->m_roleNames.find(propName); - if (it != model->m_roleNames.end()) { - roleToProp.insert(*it, propId); + if (propName == "hasModelChildren") { QModelIndex index = model->m_abstractItemModel->index(data->m_index, 0, model->m_root); - return model->m_abstractItemModel->data(index, *it); + return model->m_abstractItemModel->hasChildren(index); + } else { + QHash<QByteArray,int>::const_iterator it = model->m_roleNames.find(propName); + if (it != model->m_roleNames.end()) { + roleToProp.insert(*it, propId); + QModelIndex index = model->m_abstractItemModel->index(data->m_index, 0, model->m_root); + return model->m_abstractItemModel->data(index, *it); + } } } Q_ASSERT(!"Can never be reached"); @@ -784,34 +790,13 @@ void QDeclarativeVisualDataModel::setDelegate(QDeclarativeComponent *delegate) \qmlproperty QModelIndex VisualDataModel::rootIndex QAbstractItemModel provides a heirachical tree of data, whereas - QML only operates on list data. rootIndex allows the children of + QML only operates on list data. \c rootIndex allows the children of any node in a QAbstractItemModel to be provided by this model. This property only affects models of type QAbstractItemModel. \code // main.cpp - Q_DECLARE_METATYPE(QModelIndex) - - class MyModel : public QDirModel - { - Q_OBJECT - public: - MyModel(QDeclarativeContext *ctxt) : QDirModel(), context(ctxt) { - QHash<int,QByteArray> roles = roleNames(); - roles.insert(FilePathRole, "path"); - setRoleNames(roles); - context->setContextProperty("myModel", this); - context->setContextProperty("myRoot", QVariant::fromValue(index(0,0,QModelIndex()))); - } - - Q_INVOKABLE void setRoot(const QString &path) { - QModelIndex root = index(path); - context->setContextProperty("myRoot", QVariant::fromValue(root)); - } - - QDeclarativeContext *context; - }; int main(int argc, char ** argv) { @@ -819,7 +804,8 @@ void QDeclarativeVisualDataModel::setDelegate(QDeclarativeComponent *delegate) QDeclarativeView view; - MyModel model(view.rootContext()); + QDirModel model; + view.rootContext()->setContextProperty("myModel", &model); view.setSource(QUrl("qrc:view.qml")); view.show(); @@ -835,18 +821,18 @@ void QDeclarativeVisualDataModel::setDelegate(QDeclarativeComponent *delegate) import Qt 4.7 ListView { + id: view width: 200 height: 200 model: VisualDataModel { model: myModel - rootIndex: myRoot delegate: Component { Rectangle { - height: 25; width: 100 - Text { text: path } + height: 25; width: 200 + Text { text: filePath } MouseArea { anchors.fill: parent; - onClicked: myModel.setRoot(path) + onClicked: if (hasModelChildren) view.model.rootIndex = view.model.modelIndex(index) } } } @@ -854,19 +840,21 @@ void QDeclarativeVisualDataModel::setDelegate(QDeclarativeComponent *delegate) } \endcode + \sa modelIndex(), parentModelIndex() */ -QModelIndex QDeclarativeVisualDataModel::rootIndex() const +QVariant QDeclarativeVisualDataModel::rootIndex() const { Q_D(const QDeclarativeVisualDataModel); - return d->m_root; + return QVariant::fromValue(d->m_root); } -void QDeclarativeVisualDataModel::setRootIndex(const QModelIndex &root) +void QDeclarativeVisualDataModel::setRootIndex(const QVariant &root) { Q_D(QDeclarativeVisualDataModel); - if (d->m_root != root) { + QModelIndex modelIndex = qvariant_cast<QModelIndex>(root); + if (d->m_root != modelIndex) { int oldCount = d->modelCount(); - d->m_root = root; + d->m_root = modelIndex; int newCount = d->modelCount(); if (d->m_delegate && oldCount) emit itemsRemoved(0, oldCount); @@ -878,6 +866,47 @@ void QDeclarativeVisualDataModel::setRootIndex(const QModelIndex &root) } } + +/*! + \qmlmethod QModelIndex VisualDataModel::modelIndex(int index) + + QAbstractItemModel provides a heirachical tree of data, whereas + QML only operates on list data. This function assists in using + tree models in QML. + + Returns a QModelIndex for the specified index. + This value can be assigned to rootIndex. + + \sa rootIndex +*/ +QVariant QDeclarativeVisualDataModel::modelIndex(int idx) const +{ + Q_D(const QDeclarativeVisualDataModel); + if (d->m_abstractItemModel) + return QVariant::fromValue(d->m_abstractItemModel->index(idx, 0, d->m_root)); + return QVariant::fromValue(QModelIndex()); +} + +/*! + \qmlmethod QModelIndex VisualDataModel::parentModelIndex() + + QAbstractItemModel provides a heirachical tree of data, whereas + QML only operates on list data. This function assists in using + tree models in QML. + + Returns a QModelIndex for the parent of the current rootIndex. + This value can be assigned to rootIndex. + + \sa rootIndex +*/ +QVariant QDeclarativeVisualDataModel::parentModelIndex() const +{ + Q_D(const QDeclarativeVisualDataModel); + if (d->m_abstractItemModel) + return QVariant::fromValue(d->m_abstractItemModel->parent(d->m_root)); + return QVariant::fromValue(QModelIndex()); +} + QString QDeclarativeVisualDataModel::part() const { Q_D(const QDeclarativeVisualDataModel); @@ -1011,7 +1040,7 @@ QDeclarativeItem *QDeclarativeVisualDataModel::item(int index, const QByteArray } else { delete data; delete ctxt; - qWarning() << d->m_delegate->errors(); + qmlInfo(this, d->m_delegate->errors()) << "Error creating delgate"; } } QDeclarativeItem *item = qobject_cast<QDeclarativeItem *>(nobj); @@ -1109,7 +1138,7 @@ QVariant QDeclarativeVisualDataModel::evaluate(int index, const QString &express QDeclarativeItem *item = qobject_cast<QDeclarativeItem *>(nobj); if (item) { QDeclarativeExpression e(qmlContext(item), expression, objectContext); - value = e.value(); + value = e.evaluate(); } } else { QDeclarativeContext *ccontext = d->m_context; @@ -1118,7 +1147,7 @@ QVariant QDeclarativeVisualDataModel::evaluate(int index, const QString &express QDeclarativeVisualDataModelData *data = new QDeclarativeVisualDataModelData(index, this); ctxt->setContextObject(data); QDeclarativeExpression e(ctxt, expression, objectContext); - value = e.value(); + value = e.evaluate(); delete data; delete ctxt; } diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h b/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h index d34bcaf..0a9173f 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h @@ -150,7 +150,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeVisualDataModel : public QDeclarativeVisu Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate) Q_PROPERTY(QString part READ part WRITE setPart) Q_PROPERTY(QObject *parts READ parts CONSTANT) - Q_PROPERTY(QModelIndex rootIndex READ rootIndex WRITE setRootIndex NOTIFY rootIndexChanged) + Q_PROPERTY(QVariant rootIndex READ rootIndex WRITE setRootIndex NOTIFY rootIndexChanged) Q_CLASSINFO("DefaultProperty", "delegate") public: QDeclarativeVisualDataModel(); @@ -163,8 +163,11 @@ public: QDeclarativeComponent *delegate() const; void setDelegate(QDeclarativeComponent *); - QModelIndex rootIndex() const; - void setRootIndex(const QModelIndex &root); + QVariant rootIndex() const; + void setRootIndex(const QVariant &root); + + Q_INVOKABLE QVariant modelIndex(int idx) const; + Q_INVOKABLE QVariant parentModelIndex() const; QString part() const; void setPart(const QString &); |