summaryrefslogtreecommitdiffstats
path: root/src/declarative/graphicsitems
diff options
context:
space:
mode:
authorAlexis Menard <alexis.menard@nokia.com>2010-04-14 05:48:40 (GMT)
committerAlexis Menard <alexis.menard@nokia.com>2010-04-14 05:48:40 (GMT)
commit2333ad8b4b93337c2515bc673b100c47b45e516b (patch)
treea338e4682dc857658824e7f07efe9ca57e4b9d0e /src/declarative/graphicsitems
parentc6483baf226e9e698983aa596761825ad4a8a698 (diff)
parent37581fa549c5cbe56afc68c71fa97d8f933512c0 (diff)
downloadQt-2333ad8b4b93337c2515bc673b100c47b45e516b.zip
Qt-2333ad8b4b93337c2515bc673b100c47b45e516b.tar.gz
Qt-2333ad8b4b93337c2515bc673b100c47b45e516b.tar.bz2
Merge branch '4.7' into reviews/2361
Conflicts: src/declarative/graphicsitems/qdeclarativeitem.h
Diffstat (limited to 'src/declarative/graphicsitems')
-rw-r--r--src/declarative/graphicsitems/graphicsitems.pri8
-rw-r--r--src/declarative/graphicsitems/qdeclarativeanchors.cpp144
-rw-r--r--src/declarative/graphicsitems/qdeclarativeanchors_p.h19
-rw-r--r--src/declarative/graphicsitems/qdeclarativeanchors_p_p.h21
-rw-r--r--src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp2
-rw-r--r--src/declarative/graphicsitems/qdeclarativeanimatedimage_p.h5
-rw-r--r--src/declarative/graphicsitems/qdeclarativeevents.cpp11
-rw-r--r--src/declarative/graphicsitems/qdeclarativeflickable.cpp4
-rw-r--r--src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer.cpp269
-rw-r--r--src/declarative/graphicsitems/qdeclarativegraphicswidget.cpp144
-rw-r--r--src/declarative/graphicsitems/qdeclarativegraphicswidget_p.h (renamed from src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer_p.h)59
-rw-r--r--src/declarative/graphicsitems/qdeclarativegridview.cpp82
-rw-r--r--src/declarative/graphicsitems/qdeclarativegridview_p.h5
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimagebase_p.h2
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.cpp2
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.h5
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem_p.h3
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp13
-rw-r--r--src/declarative/graphicsitems/qdeclarativelistview.cpp97
-rw-r--r--src/declarative/graphicsitems/qdeclarativelistview_p.h10
-rw-r--r--src/declarative/graphicsitems/qdeclarativeloader.cpp6
-rw-r--r--src/declarative/graphicsitems/qdeclarativemousearea.cpp20
-rw-r--r--src/declarative/graphicsitems/qdeclarativemousearea_p.h3
-rw-r--r--src/declarative/graphicsitems/qdeclarativepathview.cpp35
-rw-r--r--src/declarative/graphicsitems/qdeclarativepathview_p.h5
-rw-r--r--src/declarative/graphicsitems/qdeclarativepathview_p_p.h4
-rw-r--r--src/declarative/graphicsitems/qdeclarativepositioners.cpp9
-rw-r--r--src/declarative/graphicsitems/qdeclarativerectangle.cpp1
-rw-r--r--src/declarative/graphicsitems/qdeclarativerepeater.cpp19
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext.cpp206
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext_p.h15
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext_p_p.h6
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextedit.cpp161
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextedit_p.h14
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextedit_p_p.h21
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput.cpp288
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput_p.h23
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput_p_p.h11
-rw-r--r--src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp21
39 files changed, 1217 insertions, 556 deletions
diff --git a/src/declarative/graphicsitems/graphicsitems.pri b/src/declarative/graphicsitems/graphicsitems.pri
index af76a67..ad7ccb5 100644
--- a/src/declarative/graphicsitems/graphicsitems.pri
+++ b/src/declarative/graphicsitems/graphicsitems.pri
@@ -48,10 +48,10 @@ HEADERS += \
$$PWD/qdeclarativetext_p_p.h \
$$PWD/qdeclarativevisualitemmodel_p.h \
$$PWD/qdeclarativelistview_p.h \
- $$PWD/qdeclarativegraphicsobjectcontainer_p.h \
$$PWD/qdeclarativelayoutitem_p.h \
$$PWD/qdeclarativeitemchangelistener_p.h \
- $$PWD/qdeclarativeeffects.cpp
+ $$PWD/qdeclarativeeffects.cpp \
+ $$PWD/qdeclarativegraphicswidget_p.h
SOURCES += \
$$PWD/qdeclarativeitemsmodule.cpp \
@@ -82,5 +82,5 @@ SOURCES += \
$$PWD/qdeclarativetextedit.cpp \
$$PWD/qdeclarativevisualitemmodel.cpp \
$$PWD/qdeclarativelistview.cpp \
- $$PWD/qdeclarativegraphicsobjectcontainer.cpp \
- $$PWD/qdeclarativelayoutitem.cpp
+ $$PWD/qdeclarativelayoutitem.cpp \
+ $$PWD/qdeclarativegraphicswidget.cpp
diff --git a/src/declarative/graphicsitems/qdeclarativeanchors.cpp b/src/declarative/graphicsitems/qdeclarativeanchors.cpp
index 7a7e5be..96d0867 100644
--- a/src/declarative/graphicsitems/qdeclarativeanchors.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeanchors.cpp
@@ -55,30 +55,32 @@ QT_BEGIN_NAMESPACE
//### const item?
//local position
-static qreal position(QDeclarativeItem *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
+static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
{
qreal ret = 0.0;
+ QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(item);
switch(anchorLine) {
case QDeclarativeAnchorLine::Left:
ret = item->x();
break;
case QDeclarativeAnchorLine::Right:
- ret = item->x() + item->width();
+ ret = item->x() + d->width();
break;
case QDeclarativeAnchorLine::Top:
ret = item->y();
break;
case QDeclarativeAnchorLine::Bottom:
- ret = item->y() + item->height();
+ ret = item->y() + d->height();
break;
case QDeclarativeAnchorLine::HCenter:
- ret = item->x() + item->width()/2;
+ ret = item->x() + d->width()/2;
break;
case QDeclarativeAnchorLine::VCenter:
- ret = item->y() + item->height()/2;
+ ret = item->y() + d->height()/2;
break;
case QDeclarativeAnchorLine::Baseline:
- ret = item->y() + item->baselineOffset();
+ if (d->isDeclarativeItem)
+ ret = item->y() + static_cast<QDeclarativeItem*>(item)->baselineOffset();
break;
default:
break;
@@ -88,30 +90,32 @@ static qreal position(QDeclarativeItem *item, QDeclarativeAnchorLine::AnchorLine
}
//position when origin is 0,0
-static qreal adjustedPosition(QDeclarativeItem *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
+static qreal adjustedPosition(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
{
int ret = 0;
+ QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(item);
switch(anchorLine) {
case QDeclarativeAnchorLine::Left:
ret = 0;
break;
case QDeclarativeAnchorLine::Right:
- ret = item->width();
+ ret = d->width();
break;
case QDeclarativeAnchorLine::Top:
ret = 0;
break;
case QDeclarativeAnchorLine::Bottom:
- ret = item->height();
+ ret = d->height();
break;
case QDeclarativeAnchorLine::HCenter:
- ret = item->width()/2;
+ ret = d->width()/2;
break;
case QDeclarativeAnchorLine::VCenter:
- ret = item->height()/2;
+ ret = d->height()/2;
break;
case QDeclarativeAnchorLine::Baseline:
- ret = item->baselineOffset();
+ if (d->isDeclarativeItem)
+ ret = static_cast<QDeclarativeItem*>(item)->baselineOffset();
break;
default:
break;
@@ -136,7 +140,7 @@ QDeclarativeAnchors::QDeclarativeAnchors(QObject *parent)
qFatal("QDeclarativeAnchors::QDeclarativeAnchors(QObject*) called");
}
-QDeclarativeAnchors::QDeclarativeAnchors(QDeclarativeItem *item, QObject *parent)
+QDeclarativeAnchors::QDeclarativeAnchors(QGraphicsObject *item, QObject *parent)
: QObject(*new QDeclarativeAnchorsPrivate(item), parent)
{
}
@@ -168,7 +172,8 @@ void QDeclarativeAnchorsPrivate::fillChanged()
} else if (fill->parentItem() == item->parentItem()) { //siblings
setItemPos(QPointF(fill->x()+leftMargin, fill->y()+topMargin));
}
- setItemSize(QSizeF(fill->width()-leftMargin-rightMargin, fill->height()-topMargin-bottomMargin));
+ QGraphicsItemPrivate *fillPrivate = QGraphicsItemPrivate::get(fill);
+ setItemSize(QSizeF(fillPrivate->width()-leftMargin-rightMargin, fillPrivate->height()-topMargin-bottomMargin));
--updatingFill;
} else {
@@ -185,16 +190,17 @@ void QDeclarativeAnchorsPrivate::centerInChanged()
if (updatingCenterIn < 2) {
++updatingCenterIn;
-
+ QGraphicsItemPrivate *itemPrivate = QGraphicsItemPrivate::get(item);
if (centerIn == item->parentItem()) {
- QPointF p((item->parentItem()->width() - item->width()) / 2. + hCenterOffset,
- (item->parentItem()->height() - item->height()) / 2. + vCenterOffset);
+ QGraphicsItemPrivate *parentPrivate = QGraphicsItemPrivate::get(item->parentItem());
+ QPointF p((parentPrivate->width() - itemPrivate->width()) / 2. + hCenterOffset,
+ (parentPrivate->height() - itemPrivate->height()) / 2. + vCenterOffset);
setItemPos(p);
} else if (centerIn->parentItem() == item->parentItem()) {
-
- QPointF p(centerIn->x() + (centerIn->width() - item->width()) / 2. + hCenterOffset,
- centerIn->y() + (centerIn->height() - item->height()) / 2. + vCenterOffset);
+ QGraphicsItemPrivate *centerPrivate = QGraphicsItemPrivate::get(centerIn);
+ QPointF p(centerIn->x() + (centerPrivate->width() - itemPrivate->width()) / 2. + hCenterOffset,
+ centerIn->y() + (centerPrivate->height() - itemPrivate->height()) / 2. + vCenterOffset);
setItemPos(p);
}
@@ -205,7 +211,7 @@ void QDeclarativeAnchorsPrivate::centerInChanged()
}
}
-void QDeclarativeAnchorsPrivate::clearItem(QDeclarativeItem *item)
+void QDeclarativeAnchorsPrivate::clearItem(QGraphicsObject *item)
{
if (!item)
return;
@@ -243,22 +249,38 @@ void QDeclarativeAnchorsPrivate::clearItem(QDeclarativeItem *item)
}
}
-void QDeclarativeAnchorsPrivate::addDepend(QDeclarativeItem *item)
+void QDeclarativeAnchorsPrivate::addDepend(QGraphicsObject *item)
{
if (!item)
return;
- QDeclarativeItemPrivate *p =
- static_cast<QDeclarativeItemPrivate *>(QGraphicsItemPrivate::get(item));
- p->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry);
+ QGraphicsItemPrivate * itemPrivate = QGraphicsItemPrivate::get(item);
+ if (itemPrivate->isDeclarativeItem) {
+ QDeclarativeItemPrivate *p =
+ static_cast<QDeclarativeItemPrivate *>(QGraphicsItemPrivate::get(item));
+ p->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry);
+ } else if(itemPrivate->isWidget) {
+ Q_Q(QDeclarativeAnchors);
+ QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item);
+ QObject::connect(widget, SIGNAL(destroyed(QObject *)), q, SLOT(_q_widgetDestroyed(QObject *)));
+ QObject::connect(widget, SIGNAL(geometryChanged()), q, SLOT(_q_widgetGeometryChanged()));
+ }
}
-void QDeclarativeAnchorsPrivate::remDepend(QDeclarativeItem *item)
+void QDeclarativeAnchorsPrivate::remDepend(QGraphicsObject *item)
{
if (!item)
return;
- QDeclarativeItemPrivate *p =
- static_cast<QDeclarativeItemPrivate *>(QGraphicsItemPrivate::get(item));
- p->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry);
+ QGraphicsItemPrivate * itemPrivate = QGraphicsItemPrivate::get(item);
+ if (itemPrivate->isDeclarativeItem) {
+ QDeclarativeItemPrivate *p =
+ static_cast<QDeclarativeItemPrivate *>(itemPrivate);
+ p->removeItemChangeListener(this, QDeclarativeItemPrivate::Geometry);
+ } else if(itemPrivate->isWidget) {
+ Q_Q(QDeclarativeAnchors);
+ QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item);
+ QObject::disconnect(widget, SIGNAL(destroyed(QObject *)), q, SLOT(_q_widgetDestroyed(QObject *)));
+ QObject::disconnect(widget, SIGNAL(geometryChanged()), q, SLOT(_q_widgetGeometryChanged()));
+ }
}
bool QDeclarativeAnchorsPrivate::isItemComplete() const
@@ -281,14 +303,14 @@ void QDeclarativeAnchors::componentComplete()
void QDeclarativeAnchorsPrivate::setItemHeight(qreal v)
{
updatingMe = true;
- item->setHeight(v);
+ QGraphicsItemPrivate::get(item)->setHeight(v);
updatingMe = false;
}
void QDeclarativeAnchorsPrivate::setItemWidth(qreal v)
{
updatingMe = true;
- item->setWidth(v);
+ QGraphicsItemPrivate::get(item)->setWidth(v);
updatingMe = false;
}
@@ -316,7 +338,10 @@ void QDeclarativeAnchorsPrivate::setItemPos(const QPointF &v)
void QDeclarativeAnchorsPrivate::setItemSize(const QSizeF &v)
{
updatingMe = true;
- item->setSize(v);
+ if(QGraphicsItemPrivate::get(item)->isWidget)
+ static_cast<QGraphicsWidget *>(item)->resize(v);
+ else if (QGraphicsItemPrivate::get(item)->isDeclarativeItem)
+ static_cast<QDeclarativeItem *>(item)->setSize(v);
updatingMe = false;
}
@@ -341,24 +366,36 @@ void QDeclarativeAnchorsPrivate::updateOnComplete()
updateVerticalAnchors();
}
-void QDeclarativeAnchorsPrivate::itemGeometryChanged(QDeclarativeItem *, const QRectF &newG, const QRectF &oldG)
+void QDeclarativeAnchorsPrivate::_q_widgetDestroyed(QObject *obj)
+{
+ clearItem(qobject_cast<QGraphicsObject*>(obj));
+}
+
+void QDeclarativeAnchorsPrivate::_q_widgetGeometryChanged()
{
fillChanged();
centerInChanged();
+ updateHorizontalAnchors();
+ updateVerticalAnchors();
+}
+void QDeclarativeAnchorsPrivate::itemGeometryChanged(QDeclarativeItem *, const QRectF &newG, const QRectF &oldG)
+{
+ fillChanged();
+ centerInChanged();
if (newG.x() != oldG.x() || newG.width() != oldG.width())
updateHorizontalAnchors();
if (newG.y() != oldG.y() || newG.height() != oldG.height())
updateVerticalAnchors();
}
-QDeclarativeItem *QDeclarativeAnchors::fill() const
+QGraphicsObject *QDeclarativeAnchors::fill() const
{
Q_D(const QDeclarativeAnchors);
return d->fill;
}
-void QDeclarativeAnchors::setFill(QDeclarativeItem *f)
+void QDeclarativeAnchors::setFill(QGraphicsObject *f)
{
Q_D(QDeclarativeAnchors);
if (d->fill == f)
@@ -386,13 +423,13 @@ void QDeclarativeAnchors::resetFill()
setFill(0);
}
-QDeclarativeItem *QDeclarativeAnchors::centerIn() const
+QGraphicsObject *QDeclarativeAnchors::centerIn() const
{
Q_D(const QDeclarativeAnchors);
return d->centerIn;
}
-void QDeclarativeAnchors::setCenterIn(QDeclarativeItem* c)
+void QDeclarativeAnchors::setCenterIn(QGraphicsObject* c)
{
Q_D(QDeclarativeAnchors);
if (d->centerIn == c)
@@ -439,10 +476,10 @@ bool QDeclarativeAnchorsPrivate::calcStretch(const QDeclarativeAnchorLine &edge1
- ((int)position(edge1.item, edge1.anchorLine) + offset1);
} else if (edge2IsParent && edge1IsSibling) {
stretch = ((int)position(edge2.item, edge2.anchorLine) + offset2)
- - ((int)position(item->parentItem(), line)
+ - ((int)position(item->parentObject(), line)
+ (int)position(edge1.item, edge1.anchorLine) + offset1);
} else if (edge2IsSibling && edge1IsParent) {
- stretch = ((int)position(item->parentItem(), line) + (int)position(edge2.item, edge2.anchorLine) + offset2)
+ stretch = ((int)position(item->parentObject(), line) + (int)position(edge2.item, edge2.anchorLine) + offset2)
- ((int)position(edge1.item, edge1.anchorLine) + offset1);
} else
invalid = true;
@@ -457,6 +494,7 @@ void QDeclarativeAnchorsPrivate::updateVerticalAnchors()
if (updatingVerticalAnchor < 2) {
++updatingVerticalAnchor;
+ QGraphicsItemPrivate *itemPrivate = QGraphicsItemPrivate::get(item);
if (usedAnchors & QDeclarativeAnchors::HasTopAnchor) {
//Handle stretching
bool invalid = true;
@@ -488,9 +526,9 @@ void QDeclarativeAnchorsPrivate::updateVerticalAnchors()
//Handle bottom
if (bottom.item == item->parentItem()) {
- setItemY(adjustedPosition(bottom.item, bottom.anchorLine) - item->height() - bottomMargin);
+ setItemY(adjustedPosition(bottom.item, bottom.anchorLine) - itemPrivate->height() - bottomMargin);
} else if (bottom.item->parentItem() == item->parentItem()) {
- setItemY(position(bottom.item, bottom.anchorLine) - item->height() - bottomMargin);
+ setItemY(position(bottom.item, bottom.anchorLine) - itemPrivate->height() - bottomMargin);
}
} else if (usedAnchors & QDeclarativeAnchors::HasVCenterAnchor) {
//(stetching handled above)
@@ -498,18 +536,20 @@ void QDeclarativeAnchorsPrivate::updateVerticalAnchors()
//Handle vCenter
if (vCenter.item == item->parentItem()) {
setItemY(adjustedPosition(vCenter.item, vCenter.anchorLine)
- - item->height()/2 + vCenterOffset);
+ - itemPrivate->height()/2 + vCenterOffset);
} else if (vCenter.item->parentItem() == item->parentItem()) {
- setItemY(position(vCenter.item, vCenter.anchorLine) - item->height()/2 + vCenterOffset);
+ setItemY(position(vCenter.item, vCenter.anchorLine) - itemPrivate->height()/2 + vCenterOffset);
}
} else if (usedAnchors & QDeclarativeAnchors::HasBaselineAnchor) {
//Handle baseline
if (baseline.item == item->parentItem()) {
- setItemY(adjustedPosition(baseline.item, baseline.anchorLine)
- - item->baselineOffset() + baselineOffset);
+ if (itemPrivate->isDeclarativeItem)
+ setItemY(adjustedPosition(baseline.item, baseline.anchorLine)
+ - static_cast<QDeclarativeItem *>(item)->baselineOffset() + baselineOffset);
} else if (baseline.item->parentItem() == item->parentItem()) {
- setItemY(position(baseline.item, baseline.anchorLine)
- - item->baselineOffset() + baselineOffset);
+ if (itemPrivate->isDeclarativeItem)
+ setItemY(position(baseline.item, baseline.anchorLine)
+ - static_cast<QDeclarativeItem *>(item)->baselineOffset() + baselineOffset);
}
}
--updatingVerticalAnchor;
@@ -526,7 +566,7 @@ void QDeclarativeAnchorsPrivate::updateHorizontalAnchors()
if (updatingHorizontalAnchor < 2) {
++updatingHorizontalAnchor;
-
+ QGraphicsItemPrivate *itemPrivate = QGraphicsItemPrivate::get(item);
if (usedAnchors & QDeclarativeAnchors::HasLeftAnchor) {
//Handle stretching
bool invalid = true;
@@ -558,16 +598,16 @@ void QDeclarativeAnchorsPrivate::updateHorizontalAnchors()
//Handle right
if (right.item == item->parentItem()) {
- setItemX(adjustedPosition(right.item, right.anchorLine) - item->width() - rightMargin);
+ setItemX(adjustedPosition(right.item, right.anchorLine) - itemPrivate->width() - rightMargin);
} else if (right.item->parentItem() == item->parentItem()) {
- setItemX(position(right.item, right.anchorLine) - item->width() - rightMargin);
+ setItemX(position(right.item, right.anchorLine) - itemPrivate->width() - rightMargin);
}
} else if (usedAnchors & QDeclarativeAnchors::HasHCenterAnchor) {
//Handle hCenter
if (hCenter.item == item->parentItem()) {
- setItemX(adjustedPosition(hCenter.item, hCenter.anchorLine) - item->width()/2 + hCenterOffset);
+ setItemX(adjustedPosition(hCenter.item, hCenter.anchorLine) - itemPrivate->width()/2 + hCenterOffset);
} else if (hCenter.item->parentItem() == item->parentItem()) {
- setItemX(position(hCenter.item, hCenter.anchorLine) - item->width()/2 + hCenterOffset);
+ setItemX(position(hCenter.item, hCenter.anchorLine) - itemPrivate->width()/2 + hCenterOffset);
}
}
diff --git a/src/declarative/graphicsitems/qdeclarativeanchors_p.h b/src/declarative/graphicsitems/qdeclarativeanchors_p.h
index 1961fdd..f2e57cc 100644
--- a/src/declarative/graphicsitems/qdeclarativeanchors_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeanchors_p.h
@@ -55,7 +55,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QDeclarativeAnchorsPrivate;
-struct QDeclarativeAnchorLine;
+class QDeclarativeAnchorLine;
class Q_DECLARATIVE_EXPORT QDeclarativeAnchors : public QObject
{
Q_OBJECT
@@ -75,12 +75,12 @@ class Q_DECLARATIVE_EXPORT QDeclarativeAnchors : public QObject
Q_PROPERTY(qreal bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged)
Q_PROPERTY(qreal verticalCenterOffset READ verticalCenterOffset WRITE setVerticalCenterOffset NOTIFY verticalCenterOffsetChanged())
Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged())
- Q_PROPERTY(QDeclarativeItem *fill READ fill WRITE setFill RESET resetFill NOTIFY fillChanged)
- Q_PROPERTY(QDeclarativeItem *centerIn READ centerIn WRITE setCenterIn RESET resetCenterIn NOTIFY centerInChanged)
+ Q_PROPERTY(QGraphicsObject *fill READ fill WRITE setFill RESET resetFill NOTIFY fillChanged)
+ Q_PROPERTY(QGraphicsObject *centerIn READ centerIn WRITE setCenterIn RESET resetCenterIn NOTIFY centerInChanged)
public:
QDeclarativeAnchors(QObject *parent=0);
- QDeclarativeAnchors(QDeclarativeItem *item, QObject *parent=0);
+ QDeclarativeAnchors(QGraphicsObject *item, QObject *parent=0);
virtual ~QDeclarativeAnchors();
enum UsedAnchor {
@@ -148,12 +148,12 @@ public:
qreal baselineOffset() const;
void setBaselineOffset(qreal);
- QDeclarativeItem *fill() const;
- void setFill(QDeclarativeItem *);
+ QGraphicsObject *fill() const;
+ void setFill(QGraphicsObject *);
void resetFill();
- QDeclarativeItem *centerIn() const;
- void setCenterIn(QDeclarativeItem *);
+ QGraphicsObject *centerIn() const;
+ void setCenterIn(QGraphicsObject *);
void resetCenterIn();
UsedAnchors usedAnchors() const;
@@ -182,8 +182,11 @@ Q_SIGNALS:
private:
friend class QDeclarativeItem;
+ friend class QDeclarativeGraphicsWidget;
Q_DISABLE_COPY(QDeclarativeAnchors)
Q_DECLARE_PRIVATE(QDeclarativeAnchors)
+ 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)
diff --git a/src/declarative/graphicsitems/qdeclarativeanchors_p_p.h b/src/declarative/graphicsitems/qdeclarativeanchors_p_p.h
index ba6359a..f8489aa 100644
--- a/src/declarative/graphicsitems/qdeclarativeanchors_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeanchors_p_p.h
@@ -59,8 +59,9 @@
QT_BEGIN_NAMESPACE
-struct QDeclarativeAnchorLine
+class QDeclarativeAnchorLine
{
+public:
QDeclarativeAnchorLine() : item(0), anchorLine(Invalid) {}
enum AnchorLine {
@@ -76,7 +77,7 @@ struct QDeclarativeAnchorLine
Vertical_Mask = Top | Bottom | VCenter | Baseline
};
- QDeclarativeItem *item;
+ QGraphicsObject *item;
AnchorLine anchorLine;
};
@@ -89,7 +90,7 @@ class QDeclarativeAnchorsPrivate : public QObjectPrivate, public QDeclarativeIte
{
Q_DECLARE_PUBLIC(QDeclarativeAnchors)
public:
- QDeclarativeAnchorsPrivate(QDeclarativeItem *i)
+ QDeclarativeAnchorsPrivate(QGraphicsObject *i)
: componentComplete(true), updatingMe(false), updatingHorizontalAnchor(0),
updatingVerticalAnchor(0), updatingFill(0), updatingCenterIn(0), item(i), usedAnchors(0), fill(0),
centerIn(0), leftMargin(0), rightMargin(0), topMargin(0), bottomMargin(0),
@@ -97,10 +98,10 @@ public:
{
}
- void clearItem(QDeclarativeItem *);
+ void clearItem(QGraphicsObject *);
- void addDepend(QDeclarativeItem *);
- void remDepend(QDeclarativeItem *);
+ void addDepend(QGraphicsObject *);
+ void remDepend(QGraphicsObject *);
bool isItemComplete() const;
bool componentComplete:1;
@@ -122,6 +123,8 @@ public:
// QDeclarativeItemGeometryListener interface
void itemGeometryChanged(QDeclarativeItem *, const QRectF &, const QRectF &);
+ void _q_widgetDestroyed(QObject *);
+ void _q_widgetGeometryChanged();
QDeclarativeAnchorsPrivate *anchorPrivate() { return this; }
bool checkHValid() const;
@@ -135,11 +138,11 @@ public:
void fillChanged();
void centerInChanged();
- QDeclarativeItem *item;
+ QGraphicsObject *item;
QDeclarativeAnchors::UsedAnchors usedAnchors;
- QDeclarativeItem *fill;
- QDeclarativeItem *centerIn;
+ QGraphicsObject *fill;
+ QGraphicsObject *centerIn;
QDeclarativeAnchorLine left;
QDeclarativeAnchorLine right;
diff --git a/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp b/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp
index f14f773..cc062f0 100644
--- a/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp
@@ -312,7 +312,7 @@ void QDeclarativeAnimatedImage::playingStatusChanged()
void QDeclarativeAnimatedImage::componentComplete()
{
Q_D(QDeclarativeAnimatedImage);
- QDeclarativeImage::componentComplete();
+ QDeclarativeItem::componentComplete(); // NOT QDeclarativeImage
if (!d->reply) {
setCurrentFrame(d->preset_currentframe);
d->preset_currentframe = 0;
diff --git a/src/declarative/graphicsitems/qdeclarativeanimatedimage_p.h b/src/declarative/graphicsitems/qdeclarativeanimatedimage_p.h
index 6ab66b3..9d8087c 100644
--- a/src/declarative/graphicsitems/qdeclarativeanimatedimage_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeanimatedimage_p.h
@@ -61,6 +61,10 @@ class Q_DECLARATIVE_EXPORT QDeclarativeAnimatedImage : public QDeclarativeImage
Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged)
Q_PROPERTY(int currentFrame READ currentFrame WRITE setCurrentFrame NOTIFY frameChanged)
Q_PROPERTY(int frameCount READ frameCount)
+
+ // read-only for AnimatedImage
+ Q_PROPERTY(QSize sourceSize READ sourceSize NOTIFY sourceSizeChanged)
+
public:
QDeclarativeAnimatedImage(QDeclarativeItem *parent=0);
~QDeclarativeAnimatedImage();
@@ -83,6 +87,7 @@ Q_SIGNALS:
void playingChanged();
void pausedChanged();
void frameChanged();
+ void sourceSizeChanged();
private Q_SLOTS:
void movieUpdate();
diff --git a/src/declarative/graphicsitems/qdeclarativeevents.cpp b/src/declarative/graphicsitems/qdeclarativeevents.cpp
index 6118ea8..a181071 100644
--- a/src/declarative/graphicsitems/qdeclarativeevents.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeevents.cpp
@@ -133,6 +133,17 @@ Item {
These properties hold the position of the mouse event.
*/
+
+/*!
+ \qmlproperty bool MouseEvent::accepted
+
+ Setting \a accepted to true prevents the mouse event from being
+ propagated to items below this item.
+
+ Generally, if the item acts on the mouse event then it should be accepted
+ so that items lower in the stacking order do not also respond to the same event.
+*/
+
/*!
\qmlproperty enum MouseEvent::button
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
index fc7a87b..951b171 100644
--- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
@@ -816,6 +816,8 @@ void QDeclarativeFlickable::wheelEvent(QGraphicsSceneWheelEvent *event)
d->vData.velocity = qMin(event->delta() - d->vData.smoothVelocity.value(), qreal(-250.0));
d->flicked = false;
d->flickY(d->vData.velocity);
+ if (d->flicked)
+ movementStarting();
event->accept();
} else if (xflick()) {
if (event->delta() > 0)
@@ -824,6 +826,8 @@ void QDeclarativeFlickable::wheelEvent(QGraphicsSceneWheelEvent *event)
d->hData.velocity = qMin(event->delta() - d->hData.smoothVelocity.value(), qreal(-250.0));
d->flicked = false;
d->flickX(d->hData.velocity);
+ if (d->flicked)
+ movementStarting();
event->accept();
} else {
QDeclarativeItem::wheelEvent(event);
diff --git a/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer.cpp b/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer.cpp
deleted file mode 100644
index c846431..0000000
--- a/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer.cpp
+++ /dev/null
@@ -1,269 +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 "private/qdeclarativegraphicsobjectcontainer_p.h"
-
-#include "private/qdeclarativeitem_p.h"
-
-#include <QGraphicsObject>
-#include <QGraphicsWidget>
-#include <QGraphicsSceneResizeEvent>
-
-QT_BEGIN_NAMESPACE
-
-class QDeclarativeGraphicsObjectContainerPrivate : public QDeclarativeItemPrivate
-{
- Q_DECLARE_PUBLIC(QDeclarativeGraphicsObjectContainer)
-
-public:
- QDeclarativeGraphicsObjectContainerPrivate() : QDeclarativeItemPrivate(), graphicsObject(0), syncedResize(false)
- { }
-
- void _q_updateSize();
-
- void setFiltering(bool on)
- {
- Q_Q(QDeclarativeGraphicsObjectContainer);
- if (graphicsObject && graphicsObject->isWidget()) {
- if (!on) {
- graphicsObject->removeEventFilter(q);
- QObject::disconnect(q, SIGNAL(widthChanged()), q, SLOT(_q_updateSize()));
- QObject::disconnect(q, SIGNAL(heightChanged()), q, SLOT(_q_updateSize()));
- } else {
- graphicsObject->installEventFilter(q);
- QObject::connect(q, SIGNAL(widthChanged()), q, SLOT(_q_updateSize()));
- QObject::connect(q, SIGNAL(heightChanged()), q, SLOT(_q_updateSize()));
- }
- }
- }
-
-
- QGraphicsObject *graphicsObject;
- bool syncedResize;
-};
-
-
-/*!
- \qmlclass GraphicsObjectContainer QDeclarativeGraphicsObjectContainer
- \since 4.7
- \brief The GraphicsObjectContainer element allows you to add QGraphicsObjects into Fluid UI elements.
-
- While any QObject based class can be exposed to QML, QDeclarativeItem
- provides a lot of important functionality, including anchors and proper
- management of child items. GraphicsObjectContainer helps provide these
- functions to other QGraphicsObjects, so that they can be used unaltered in
- a QML scene. QGraphicsObjects, which are not QDeclarativeItems, and which are
- placed in a QML scene outside of a GraphicsObjectContainer, will not appear
- on screen at all.
-
- A GraphicsObjectContainer can have one element inside it, and it must be a
- QGraphicsObject or subclass which has been exposed to the QML engine.
- The graphics object inside the GraphicsObjectContainer can then be used
- like any other item in QML with the exception of not being reparentable
- and not having the standard properties of QML items (such as anchors).
-
- As the contained object is positioned relative to the container, anchors
- affecting the container item will affect the onscreen position of the
- contained item. If synchronizedResizing is set to true, then anchors
- affecting the container item's size will also affect the contained item's
- size.
-
- Example:
- \code
- import Qt 4.6
- import MyApp 2.1 as Widgets
- Rectangle{
- id: rect
- property alias widgetPropertyThree: widget.myThirdProperty;
- GraphicsObjectContainer{
- synchronizedResizing: true
- anchors.margins: 10
- anchors.fill: parent
- Widgets.MyWidget{
- myProperty: "A Value"
- myOtherProperty: rect.color
- }
- }
- }
- \endcode
-*/
-
-/*!
- \internal
- \class QDeclarativeGraphicsObjectContainer
- \brief The QDeclarativeGraphicsObjectContainer class allows you to add QGraphicsObjects into Fluid UI applications.
-*/
-
-QDeclarativeGraphicsObjectContainer::QDeclarativeGraphicsObjectContainer(QDeclarativeItem *parent)
-: QDeclarativeItem(*new QDeclarativeGraphicsObjectContainerPrivate, parent)
-{
-}
-
-QDeclarativeGraphicsObjectContainer::~QDeclarativeGraphicsObjectContainer()
-{
-}
-
-QGraphicsObject *QDeclarativeGraphicsObjectContainer::graphicsObject() const
-{
- Q_D(const QDeclarativeGraphicsObjectContainer);
- return d->graphicsObject;
-}
-
-/*!
- \qmlproperty QGraphicsObject GraphicsObjectContainer::graphicsObject
- The QGraphicsObject associated with this element.
-*/
-void QDeclarativeGraphicsObjectContainer::setGraphicsObject(QGraphicsObject *object)
-{
- Q_D(QDeclarativeGraphicsObjectContainer);
- if (object == d->graphicsObject)
- return;
-
- //### remove previously set item?
-
- d->setFiltering(false);
-
- d->graphicsObject = object;
-
- if (d->graphicsObject) {
- d->graphicsObject->setParentItem(this);
-
- if (d->syncedResize && d->graphicsObject->isWidget()) {
- QGraphicsWidget *gw = static_cast<QGraphicsWidget*>(d->graphicsObject);
- QSizeF gwSize = gw->size(); //### should we use sizeHint?
- QSizeF newSize = gwSize;
- if (heightValid())
- newSize.setHeight(height());
- if (widthValid())
- newSize.setWidth(width());
- if (gwSize != newSize)
- gw->resize(newSize);
-
- gwSize = gw->size();
- setImplicitWidth(gwSize.width());
- setImplicitHeight(gwSize.height());
-
- d->setFiltering(true);
- }
- }
-}
-
-QVariant QDeclarativeGraphicsObjectContainer::itemChange(GraphicsItemChange change, const QVariant &value)
-{
- Q_D(QDeclarativeGraphicsObjectContainer);
- if (change == ItemSceneHasChanged) {
- QGraphicsObject *o = d->graphicsObject;
- d->graphicsObject = 0;
- setGraphicsObject(o);
- }
- return QDeclarativeItem::itemChange(change, value);
-}
-
-bool QDeclarativeGraphicsObjectContainer::eventFilter(QObject *watched, QEvent *e)
-{
- Q_D(QDeclarativeGraphicsObjectContainer);
- if (watched == d->graphicsObject && e->type() == QEvent::GraphicsSceneResize) {
- if (d->graphicsObject && d->graphicsObject->isWidget() && d->syncedResize) {
- QSizeF newSize = static_cast<QGraphicsWidget*>(d->graphicsObject)->size();
- setImplicitWidth(newSize.width());
- setImplicitHeight(newSize.height());
- }
- }
- return QDeclarativeItem::eventFilter(watched, e);
-}
-
-/*!
- \qmlproperty bool GraphicsObjectContainer::synchronizedResizing
-
- This property determines whether or not the container and graphics object will synchronize their
- sizes.
-
- \note This property only applies when wrapping a QGraphicsWidget.
-
- If synchronizedResizing is enabled, the container and widget will
- synchronize their sizes as follows.
- \list
- \o If a size has been set on the container, the widget will be resized to the container.
- Any changes in the container's size will be reflected in the widget.
-
- \o \e Otherwise, the container will initially be sized to the preferred size of the widget.
- Any changes to the container's size will be reflected in the widget, and any changes to the
- widget's size will be reflected in the container.
- \endlist
-*/
-bool QDeclarativeGraphicsObjectContainer::synchronizedResizing() const
-{
- Q_D(const QDeclarativeGraphicsObjectContainer);
- return d->syncedResize;
-}
-
-void QDeclarativeGraphicsObjectContainer::setSynchronizedResizing(bool on)
-{
- Q_D(QDeclarativeGraphicsObjectContainer);
- if (on == d->syncedResize)
- return;
-
- d->syncedResize = on;
- d->setFiltering(on);
-}
-
-void QDeclarativeGraphicsObjectContainerPrivate::_q_updateSize()
-{
- if (!graphicsObject || !graphicsObject->isWidget() || !syncedResize)
- return;
-
- QGraphicsWidget *gw = static_cast<QGraphicsWidget*>(graphicsObject);
- const QSizeF newSize(width(), height());
- gw->resize(newSize);
-
- //### will respecting the widgets min/max ever get us in trouble? (all other items always
- // size to exactly what you tell them)
- /*QSizeF constrainedSize = newSize.expandedTo(gw->minimumSize()).boundedTo(gw->maximumSize());
- gw->resize(constrainedSize);
- if (constrainedSize != newSize) {
- setImplicitWidth(constrainedSize.width());
- setImplicitHeight(constrainedSize.height());
- }*/
-}
-
-#include <moc_qdeclarativegraphicsobjectcontainer_p.cpp>
-
-QT_END_NAMESPACE
diff --git a/src/declarative/graphicsitems/qdeclarativegraphicswidget.cpp b/src/declarative/graphicsitems/qdeclarativegraphicswidget.cpp
new file mode 100644
index 0000000..ee45406
--- /dev/null
+++ b/src/declarative/graphicsitems/qdeclarativegraphicswidget.cpp
@@ -0,0 +1,144 @@
+/****************************************************************************
+**
+** 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 "qdeclarativegraphicswidget_p.h"
+#include "private/qdeclarativeanchors_p.h"
+#include "private/qdeclarativeitem_p.h"
+#include "private/qdeclarativeanchors_p_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QDeclarativeGraphicsWidgetPrivate : public QObjectPrivate {
+ Q_DECLARE_PUBLIC(QDeclarativeGraphicsWidget)
+public :
+ QDeclarativeGraphicsWidgetPrivate() :
+ _anchors(0), _anchorLines(0)
+ {}
+ QDeclarativeItemPrivate::AnchorLines *anchorLines() const;
+ QDeclarativeAnchors *_anchors;
+ mutable QDeclarativeItemPrivate::AnchorLines *_anchorLines;
+};
+
+QDeclarativeGraphicsWidget::QDeclarativeGraphicsWidget(QObject *parent) :
+ QObject(*new QDeclarativeGraphicsWidgetPrivate, parent)
+{
+}
+QDeclarativeGraphicsWidget::~QDeclarativeGraphicsWidget()
+{
+ Q_D(QDeclarativeGraphicsWidget);
+ delete d->_anchorLines; d->_anchorLines = 0;
+ delete d->_anchors; d->_anchors = 0;
+}
+
+/*! \internal */
+QDeclarativeAnchors *QDeclarativeGraphicsWidget::anchors()
+{
+ Q_D(QDeclarativeGraphicsWidget);
+ if (!d->_anchors)
+ d->_anchors = new QDeclarativeAnchors(static_cast<QGraphicsObject *>(parent()));
+ return d->_anchors;
+}
+
+QDeclarativeItemPrivate::AnchorLines *QDeclarativeGraphicsWidgetPrivate::anchorLines() const
+{
+ Q_Q(const QDeclarativeGraphicsWidget);
+ if (!_anchorLines)
+ _anchorLines = new QDeclarativeItemPrivate::AnchorLines(static_cast<QGraphicsObject *>(q->parent()));
+ return _anchorLines;
+}
+
+/*!
+ \internal
+*/
+QDeclarativeAnchorLine QDeclarativeGraphicsWidget::left() const
+{
+ Q_D(const QDeclarativeGraphicsWidget);
+ return d->anchorLines()->left;
+}
+
+/*!
+ \internal
+*/
+QDeclarativeAnchorLine QDeclarativeGraphicsWidget::right() const
+{
+ Q_D(const QDeclarativeGraphicsWidget);
+ return d->anchorLines()->right;
+}
+
+/*!
+ \internal
+*/
+QDeclarativeAnchorLine QDeclarativeGraphicsWidget::horizontalCenter() const
+{
+ Q_D(const QDeclarativeGraphicsWidget);
+ return d->anchorLines()->hCenter;
+}
+
+/*!
+ \internal
+*/
+QDeclarativeAnchorLine QDeclarativeGraphicsWidget::top() const
+{
+ Q_D(const QDeclarativeGraphicsWidget);
+ return d->anchorLines()->top;
+}
+
+/*!
+ \internal
+*/
+QDeclarativeAnchorLine QDeclarativeGraphicsWidget::bottom() const
+{
+ Q_D(const QDeclarativeGraphicsWidget);
+ return d->anchorLines()->bottom;
+}
+
+/*!
+ \internal
+*/
+QDeclarativeAnchorLine QDeclarativeGraphicsWidget::verticalCenter() const
+{
+ Q_D(const QDeclarativeGraphicsWidget);
+ return d->anchorLines()->vCenter;
+}
+
+QT_END_NAMESPACE
+
+#include <moc_qdeclarativegraphicswidget_p.cpp>
diff --git a/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer_p.h b/src/declarative/graphicsitems/qdeclarativegraphicswidget_p.h
index 20c5bcf..987303e 100644
--- a/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer_p.h
+++ b/src/declarative/graphicsitems/qdeclarativegraphicswidget_p.h
@@ -39,10 +39,11 @@
**
****************************************************************************/
-#ifndef QDECLARATIVEGRAPHICSOBJECTCONTAINER_H
-#define QDECLARATIVEGRAPHICSOBJECTCONTAINER_H
+#ifndef QDECLARATIVEGRAPHICSWIDGET_P_H
+#define QDECLARATIVEGRAPHICSWIDGET_P_H
-#include "qdeclarativeitem.h"
+#include <QObject>
+#include <QtDeclarative/qdeclarativecomponent.h>
QT_BEGIN_HEADER
@@ -50,40 +51,40 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
+class QDeclarativeAnchorLine;
+class QDeclarativeAnchors;
class QGraphicsObject;
-class QDeclarativeGraphicsObjectContainerPrivate;
+class QDeclarativeGraphicsWidgetPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeGraphicsObjectContainer : public QDeclarativeItem
+// ### TODO can the extension object be the anchor directly? We save one allocation -> awesome.
+class QDeclarativeGraphicsWidget : public QObject
{
Q_OBJECT
-
- Q_CLASSINFO("DefaultProperty", "graphicsObject")
- Q_PROPERTY(QGraphicsObject *graphicsObject READ graphicsObject WRITE setGraphicsObject)
- Q_PROPERTY(bool synchronizedResizing READ synchronizedResizing WRITE setSynchronizedResizing)
-
+ Q_PROPERTY(QDeclarativeAnchors * anchors READ anchors DESIGNABLE false CONSTANT FINAL)
+ Q_PROPERTY(QDeclarativeAnchorLine left READ left CONSTANT FINAL)
+ Q_PROPERTY(QDeclarativeAnchorLine right READ right CONSTANT FINAL)
+ Q_PROPERTY(QDeclarativeAnchorLine horizontalCenter READ horizontalCenter CONSTANT FINAL)
+ Q_PROPERTY(QDeclarativeAnchorLine top READ top CONSTANT FINAL)
+ Q_PROPERTY(QDeclarativeAnchorLine bottom READ bottom CONSTANT FINAL)
+ Q_PROPERTY(QDeclarativeAnchorLine verticalCenter READ verticalCenter CONSTANT FINAL)
+ // ### TODO : QGraphicsWidget don't have a baseline concept yet.
+ //Q_PROPERTY(QDeclarativeAnchorLine baseline READ baseline CONSTANT FINAL)
public:
- QDeclarativeGraphicsObjectContainer(QDeclarativeItem *parent = 0);
- ~QDeclarativeGraphicsObjectContainer();
-
- QGraphicsObject *graphicsObject() const;
- void setGraphicsObject(QGraphicsObject *);
-
- bool synchronizedResizing() const;
- void setSynchronizedResizing(bool on);
-
-protected:
- QVariant itemChange(GraphicsItemChange change, const QVariant &value);
- bool eventFilter(QObject *watched, QEvent *e);
-
-private:
- Q_PRIVATE_SLOT(d_func(), void _q_updateSize())
- Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeGraphicsObjectContainer)
+ QDeclarativeGraphicsWidget(QObject *parent = 0);
+ ~QDeclarativeGraphicsWidget();
+ QDeclarativeAnchors *anchors();
+ QDeclarativeAnchorLine left() const;
+ QDeclarativeAnchorLine right() const;
+ QDeclarativeAnchorLine horizontalCenter() const;
+ QDeclarativeAnchorLine top() const;
+ QDeclarativeAnchorLine bottom() const;
+ QDeclarativeAnchorLine verticalCenter() const;
+ Q_DISABLE_COPY(QDeclarativeGraphicsWidget)
+ Q_DECLARE_PRIVATE(QDeclarativeGraphicsWidget)
};
QT_END_NAMESPACE
-QML_DECLARE_TYPE(QDeclarativeGraphicsObjectContainer)
-
QT_END_HEADER
-#endif // QDECLARATIVEGRAPHICSOBJECTCONTAINER_H
+#endif // QDECLARATIVEGRAPHICSWIDGET_P_H
diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp
index 8247f17..562ba2a 100644
--- a/src/declarative/graphicsitems/qdeclarativegridview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp
@@ -102,10 +102,11 @@ public:
QDeclarativeGridViewPrivate()
: currentItem(0), flow(QDeclarativeGridView::LeftToRight)
, visibleIndex(0) , currentIndex(-1)
- , cellWidth(100), cellHeight(100), columns(1), requestedIndex(-1)
+ , cellWidth(100), cellHeight(100), columns(1), requestedIndex(-1), itemCount(0)
, highlightRangeStart(0), highlightRangeEnd(0), highlightRange(QDeclarativeGridView::NoHighlightRange)
, highlightComponent(0), highlight(0), trackedItem(0)
, moveReason(Other), buffer(0), highlightXAnimator(0), highlightYAnimator(0)
+ , highlightMoveDuration(150)
, bufferMode(NoBuffer), snapMode(QDeclarativeGridView::NoSnap)
, ownModel(false), wrap(false), autoHighlight(true)
, fixCurrentVisibility(false), lazyRelease(false), layoutScheduled(false)
@@ -315,6 +316,7 @@ public:
int cellHeight;
int columns;
int requestedIndex;
+ int itemCount;
qreal highlightRangeStart;
qreal highlightRangeEnd;
QDeclarativeGridView::HighlightRangeMode highlightRange;
@@ -326,6 +328,7 @@ public:
int buffer;
QSmoothedAnimation *highlightXAnimator;
QSmoothedAnimation *highlightYAnimator;
+ int highlightMoveDuration;
enum BufferMode { NoBuffer = 0x00, BufferBefore = 0x01, BufferAfter = 0x02 };
BufferMode bufferMode;
QDeclarativeGridView::SnapMode snapMode;
@@ -358,6 +361,7 @@ void QDeclarativeGridViewPrivate::clear()
currentItem = 0;
createHighlight();
trackedItem = 0;
+ itemCount = 0;
}
FxGridItem *QDeclarativeGridViewPrivate::createItem(int modelIndex)
@@ -403,6 +407,7 @@ void QDeclarativeGridViewPrivate::refill(qreal from, qreal to, bool doBuffer)
if (!isValid() || !q->isComponentComplete())
return;
+ itemCount = model->count();
qreal bufferFrom = from - buffer;
qreal bufferTo = to + buffer;
qreal fillFrom = from;
@@ -546,6 +551,10 @@ void QDeclarativeGridViewPrivate::layout()
{
Q_Q(QDeclarativeGridView);
layoutScheduled = false;
+ if (!isValid()) {
+ clear();
+ return;
+ }
if (visibleItems.count()) {
qreal rowPos = visibleItems.first()->rowPos();
qreal colPos = visibleItems.first()->colPos();
@@ -604,8 +613,6 @@ void QDeclarativeGridViewPrivate::updateTrackedItem()
if (highlight)
item = highlight;
- FxGridItem *oldTracked = trackedItem;
-
if (trackedItem && item != trackedItem) {
QObject::disconnect(trackedItem->item, SIGNAL(yChanged()), q, SLOT(trackedPositionChanged()));
QObject::disconnect(trackedItem->item, SIGNAL(xChanged()), q, SLOT(trackedPositionChanged()));
@@ -617,7 +624,7 @@ void QDeclarativeGridViewPrivate::updateTrackedItem()
QObject::connect(trackedItem->item, SIGNAL(yChanged()), q, SLOT(trackedPositionChanged()));
QObject::connect(trackedItem->item, SIGNAL(xChanged()), q, SLOT(trackedPositionChanged()));
}
- if (trackedItem && trackedItem != oldTracked)
+ if (trackedItem)
q->trackedPositionChanged();
}
@@ -662,10 +669,10 @@ void QDeclarativeGridViewPrivate::createHighlight()
highlight = new FxGridItem(item, q);
highlightXAnimator = new QSmoothedAnimation(q);
highlightXAnimator->target = QDeclarativeProperty(highlight->item, QLatin1String("x"));
- highlightXAnimator->userDuration = 150;
+ highlightXAnimator->userDuration = highlightMoveDuration;
highlightYAnimator = new QSmoothedAnimation(q);
highlightYAnimator->target = QDeclarativeProperty(highlight->item, QLatin1String("y"));
- highlightYAnimator->userDuration = 150;
+ highlightYAnimator->userDuration = highlightMoveDuration;
highlightXAnimator->restart();
highlightYAnimator->restart();
changed = true;
@@ -929,10 +936,10 @@ QDeclarativeGridView::~QDeclarativeGridView()
id: myDelegate
Item {
id: wrapper
- SequentialAnimation on GridView.onRemove {
- PropertyAction { target: wrapper.GridView; property: "delayRemove"; value: true }
+ GridView.onRemove: SequentialAnimation {
+ PropertyAction { target: wrapper; property: "GridView.delayRemove"; value: true }
NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing.type: "InOutQuad" }
- PropertyAction { target: wrapper.GridView; property: "delayRemove"; value: false }
+ PropertyAction { target: wrapper; property: "GridView.delayRemove"; value: false }
}
}
}
@@ -1197,6 +1204,37 @@ void QDeclarativeGridView::setHighlightFollowsCurrentItem(bool autoHighlight)
}
/*!
+ \qmlproperty int GridView::highlightMoveDuration
+ This property holds the move animation duration of the highlight delegate.
+
+ highlightFollowsCurrentItem must be true for this property
+ to have effect.
+
+ The default value for the duration is 150ms.
+
+ \sa highlightFollowsCurrentItem
+*/
+int QDeclarativeGridView::highlightMoveDuration() const
+{
+ Q_D(const QDeclarativeGridView);
+ return d->highlightMoveDuration;
+}
+
+void QDeclarativeGridView::setHighlightMoveDuration(int duration)
+{
+ Q_D(QDeclarativeGridView);
+ if (d->highlightMoveDuration != duration) {
+ d->highlightMoveDuration = duration;
+ if (d->highlightYAnimator) {
+ d->highlightXAnimator->userDuration = d->highlightMoveDuration;
+ d->highlightYAnimator->userDuration = d->highlightMoveDuration;
+ }
+ emit highlightMoveDurationChanged();
+ }
+}
+
+
+/*!
\qmlproperty real GridView::preferredHighlightBegin
\qmlproperty real GridView::preferredHighlightEnd
\qmlproperty enumeration GridView::highlightRangeMode
@@ -1781,12 +1819,14 @@ void QDeclarativeGridView::componentComplete()
Q_D(QDeclarativeGridView);
QDeclarativeFlickable::componentComplete();
d->updateGrid();
- refill();
- if (d->currentIndex < 0)
- d->updateCurrent(0);
- else
- d->updateCurrent(d->currentIndex);
- d->fixupPosition();
+ if (d->isValid()) {
+ refill();
+ if (d->currentIndex < 0)
+ d->updateCurrent(0);
+ else
+ d->updateCurrent(d->currentIndex);
+ d->fixupPosition();
+ }
}
void QDeclarativeGridView::trackedPositionChanged()
@@ -1859,6 +1899,7 @@ void QDeclarativeGridView::itemsInserted(int modelIndex, int count)
} else if (d->currentIndex < 0) {
d->updateCurrent(0);
}
+ d->itemCount += count;
emit countChanged();
return;
}
@@ -1889,6 +1930,7 @@ void QDeclarativeGridView::itemsInserted(int modelIndex, int count)
emit currentIndexChanged();
}
d->scheduleLayout();
+ d->itemCount += count;
emit countChanged();
return;
}
@@ -1976,6 +2018,7 @@ void QDeclarativeGridView::itemsInserted(int modelIndex, int count)
for (int j = 0; j < added.count(); ++j)
added.at(j)->attached->emitAdd();
+ d->itemCount += count;
emit countChanged();
}
@@ -1984,6 +2027,8 @@ void QDeclarativeGridView::itemsRemoved(int modelIndex, int count)
Q_D(QDeclarativeGridView);
if (!isComponentComplete())
return;
+
+ d->itemCount -= count;
bool currentRemoved = d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count;
bool removedVisible = false;
@@ -2031,7 +2076,8 @@ void QDeclarativeGridView::itemsRemoved(int modelIndex, int count)
d->releaseItem(d->currentItem);
d->currentItem = 0;
d->currentIndex = -1;
- d->updateCurrent(qMin(modelIndex, d->model->count()-1));
+ if (d->itemCount)
+ d->updateCurrent(qMin(modelIndex, d->itemCount-1));
}
// update visibleIndex
@@ -2046,7 +2092,7 @@ void QDeclarativeGridView::itemsRemoved(int modelIndex, int count)
if (removedVisible && d->visibleItems.isEmpty()) {
d->timeline.clear();
d->setPosition(0);
- if (d->model->count() == 0)
+ if (d->itemCount == 0)
update();
}
@@ -2118,6 +2164,8 @@ void QDeclarativeGridView::itemsMoved(int from, int to, int count)
if (!movedItem)
movedItem = d->createItem(item->index);
it = d->visibleItems.insert(it, movedItem);
+ if (it == d->visibleItems.begin() && firstItem)
+ movedItem->setPosition(firstItem->colPos(), firstItem->rowPos());
++it;
--remaining;
} else {
diff --git a/src/declarative/graphicsitems/qdeclarativegridview_p.h b/src/declarative/graphicsitems/qdeclarativegridview_p.h
index f73f632..5baa1dd 100644
--- a/src/declarative/graphicsitems/qdeclarativegridview_p.h
+++ b/src/declarative/graphicsitems/qdeclarativegridview_p.h
@@ -66,6 +66,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeGridView : public QDeclarativeFlickable
Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged)
Q_PROPERTY(QDeclarativeItem *highlightItem READ highlightItem NOTIFY highlightItemChanged)
Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem)
+ Q_PROPERTY(int highlightMoveDuration READ highlightMoveDuration WRITE setHighlightMoveDuration NOTIFY highlightMoveDurationChanged)
Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged)
Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged)
@@ -106,6 +107,9 @@ public:
bool highlightFollowsCurrentItem() const;
void setHighlightFollowsCurrentItem(bool);
+ int highlightMoveDuration() const;
+ void setHighlightMoveDuration(int);
+
enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange };
HighlightRangeMode highlightRangeMode() const;
void setHighlightRangeMode(HighlightRangeMode mode);
@@ -161,6 +165,7 @@ Q_SIGNALS:
void preferredHighlightBeginChanged();
void preferredHighlightEndChanged();
void highlightRangeModeChanged();
+ void highlightMoveDurationChanged();
void modelChanged();
void delegateChanged();
void flowChanged();
diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase_p.h b/src/declarative/graphicsitems/qdeclarativeimagebase_p.h
index 6c84456..49b1c58 100644
--- a/src/declarative/graphicsitems/qdeclarativeimagebase_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeimagebase_p.h
@@ -73,7 +73,7 @@ public:
bool asynchronous() const;
void setAsynchronous(bool);
- void setSourceSize(const QSize&);
+ virtual void setSourceSize(const QSize&);
QSize sourceSize() const;
Q_SIGNALS:
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp
index 55a81f4..86dbaf0 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp
@@ -2507,7 +2507,7 @@ QDeclarativeStateGroup *QDeclarativeItemPrivate::states()
return _stateGroup;
}
-QDeclarativeItemPrivate::AnchorLines::AnchorLines(QDeclarativeItem *q)
+QDeclarativeItemPrivate::AnchorLines::AnchorLines(QGraphicsObject *q)
{
left.item = q;
left.anchorLine = QDeclarativeAnchorLine::Left;
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.h b/src/declarative/graphicsitems/qdeclarativeitem.h
index 0e03e6d..51889f6 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.h
+++ b/src/declarative/graphicsitems/qdeclarativeitem.h
@@ -59,7 +59,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QDeclarativeState;
-struct QDeclarativeAnchorLine;
+class QDeclarativeAnchorLine;
class QDeclarativeTransition;
class QDeclarativeKeyEvent;
class QDeclarativeAnchors;
@@ -91,9 +91,6 @@ class Q_DECLARATIVE_EXPORT QDeclarativeItem : public QGraphicsObject, public QDe
Q_PROPERTY(QDeclarativeListProperty<QGraphicsTransform> transform READ transform DESIGNABLE false FINAL)
Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin NOTIFY transformOriginChanged)
Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged)
-#ifndef QT_NO_GRAPHICSEFFECT
- Q_PROPERTY(QGraphicsEffect *effect READ graphicsEffect WRITE setGraphicsEffect)
-#endif
Q_ENUMS(TransformOrigin)
Q_CLASSINFO("DefaultProperty", "data")
diff --git a/src/declarative/graphicsitems/qdeclarativeitem_p.h b/src/declarative/graphicsitems/qdeclarativeitem_p.h
index 2607137..cf138c3 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeitem_p.h
@@ -120,6 +120,7 @@ public:
mWidth(0), mHeight(0), implicitWidth(0), implicitHeight(0)
{
QGraphicsItemPrivate::acceptedMouseButtons = 0;
+ isDeclarativeItem = 1;
QGraphicsItemPrivate::flags = QGraphicsItem::GraphicsItemFlags(
QGraphicsItem::ItemHasNoContents
| QGraphicsItem::ItemIsFocusable
@@ -183,7 +184,7 @@ public:
QDeclarativeNullableValue<qreal> _baselineOffset;
struct AnchorLines {
- AnchorLines(QDeclarativeItem *);
+ AnchorLines(QGraphicsObject *);
QDeclarativeAnchorLine left;
QDeclarativeAnchorLine right;
QDeclarativeAnchorLine hCenter;
diff --git a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp
index ab57860..731b1aa 100644
--- a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp
@@ -57,7 +57,6 @@
#include "private/qdeclarativeflipable_p.h"
#include "private/qdeclarativefocuspanel_p.h"
#include "private/qdeclarativefocusscope_p.h"
-#include "private/qdeclarativegraphicsobjectcontainer_p.h"
#include "private/qdeclarativegridview_p.h"
#include "private/qdeclarativeimage_p.h"
#include "private/qdeclarativeitem_p.h"
@@ -74,6 +73,7 @@
#include "private/qdeclarativetextedit_p.h"
#include "private/qdeclarativetextinput_p.h"
#include "private/qdeclarativevisualitemmodel_p.h"
+#include "private/qdeclarativegraphicswidget_p.h"
#ifdef QT_WEBKIT_LIB
#include "private/qdeclarativewebview_p.h"
#include "private/qdeclarativewebview_p_p.h"
@@ -93,13 +93,10 @@ void QDeclarativeItemModule::defineModule()
qmlRegisterType<QDeclarativeFocusScope>("Qt",4,6,"FocusScope");
qmlRegisterType<QDeclarativeGradient>("Qt",4,6,"Gradient");
qmlRegisterType<QDeclarativeGradientStop>("Qt",4,6,"GradientStop");
- qmlRegisterType<QDeclarativeGraphicsObjectContainer>("Qt",4,6,"GraphicsObjectContainer");
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<QDeclarativeKeyNavigationAttached>("Qt",4,6,"KeyNavigation");
- qmlRegisterType<QDeclarativeKeysAttached>("Qt",4,6,"Keys");
qmlRegisterType<QDeclarativeLayoutItem>("Qt",4,6,"LayoutItem");
qmlRegisterType<QDeclarativeListView>("Qt",4,6,"ListView");
qmlRegisterType<QDeclarativeLoader>("Qt",4,6,"Loader");
@@ -112,10 +109,8 @@ void QDeclarativeItemModule::defineModule()
qmlRegisterType<QDeclarativePathQuad>("Qt",4,6,"PathQuad");
qmlRegisterType<QDeclarativePathView>("Qt",4,6,"PathView");
qmlRegisterType<QIntValidator>("Qt",4,6,"IntValidator");
-#if (QT_VERSION >= QT_VERSION_CHECK(4,7,0))
qmlRegisterType<QDoubleValidator>("Qt",4,7,"DoubleValidator");
qmlRegisterType<QRegExpValidator>("Qt",4,7,"RegExpValidator");
-#endif
qmlRegisterType<QDeclarativeRectangle>("Qt",4,6,"Rectangle");
qmlRegisterType<QDeclarativeRepeater>("Qt",4,6,"Repeater");
qmlRegisterType<QGraphicsRotation>("Qt",4,6,"Rotation");
@@ -133,7 +128,8 @@ void QDeclarativeItemModule::defineModule()
qmlRegisterType<QDeclarativeKeyEvent>();
qmlRegisterType<QDeclarativeMouseEvent>();
qmlRegisterType<QGraphicsObject>();
- qmlRegisterType<QGraphicsWidget>();
+ qmlRegisterType<QGraphicsWidget>("Qt",4,6,"QGraphicsWidget");
+ qmlRegisterExtendedType<QGraphicsWidget,QDeclarativeGraphicsWidget>("Qt",4,6,"QGraphicsWidget");
qmlRegisterType<QGraphicsTransform>();
qmlRegisterType<QDeclarativePathElement>();
qmlRegisterType<QDeclarativeCurve>();
@@ -153,4 +149,7 @@ void QDeclarativeItemModule::defineModule()
#ifdef QT_WEBKIT_LIB
qmlRegisterType<QDeclarativeWebSettings>();
#endif
+
+ qmlRegisterUncreatableType<QDeclarativeKeyNavigationAttached>("Qt",4,6,"KeyNavigation");
+ qmlRegisterUncreatableType<QDeclarativeKeysAttached>("Qt",4,6,"Keys");
}
diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp
index e85d60f..cf7b96f 100644
--- a/src/declarative/graphicsitems/qdeclarativelistview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp
@@ -152,11 +152,12 @@ public:
: currentItem(0), orient(QDeclarativeListView::Vertical)
, visiblePos(0), visibleIndex(0)
, averageSize(100.0), currentIndex(-1), requestedIndex(-1)
- , highlightRangeStart(0), highlightRangeEnd(0)
+ , itemCount(0), highlightRangeStart(0), highlightRangeEnd(0)
, highlightComponent(0), highlight(0), trackedItem(0)
, moveReason(Other), buffer(0), highlightPosAnimator(0), highlightSizeAnimator(0)
, sectionCriteria(0), spacing(0.0)
- , highlightMoveSpeed(400), highlightResizeSpeed(400), highlightRange(QDeclarativeListView::NoHighlightRange)
+ , highlightMoveSpeed(400), highlightMoveDuration(-1)
+ , highlightResizeSpeed(400), highlightResizeDuration(-1), highlightRange(QDeclarativeListView::NoHighlightRange)
, snapMode(QDeclarativeListView::NoSnap), overshootDist(0.0)
, footerComponent(0), footer(0), headerComponent(0), header(0)
, bufferMode(NoBuffer)
@@ -447,6 +448,7 @@ public:
qreal averageSize;
int currentIndex;
int requestedIndex;
+ int itemCount;
qreal highlightRangeStart;
qreal highlightRangeEnd;
QDeclarativeComponent *highlightComponent;
@@ -463,7 +465,9 @@ public:
QDeclarativeItem *sectionCache[sectionCacheSize];
qreal spacing;
qreal highlightMoveSpeed;
+ int highlightMoveDuration;
qreal highlightResizeSpeed;
+ int highlightResizeDuration;
QDeclarativeListView::HighlightRangeMode highlightRange;
QDeclarativeListView::SnapMode snapMode;
qreal overshootDist;
@@ -501,6 +505,7 @@ void QDeclarativeListViewPrivate::init()
void QDeclarativeListViewPrivate::clear()
{
+ timeline.clear();
for (int i = 0; i < visibleItems.count(); ++i)
releaseItem(visibleItems.at(i));
visibleItems.clear();
@@ -516,6 +521,8 @@ void QDeclarativeListViewPrivate::clear()
trackedItem = 0;
minExtentDirty = true;
maxExtentDirty = true;
+ setPosition(0);
+ itemCount = 0;
}
FxListItem *QDeclarativeListViewPrivate::createItem(int modelIndex)
@@ -594,6 +601,7 @@ void QDeclarativeListViewPrivate::refill(qreal from, qreal to, bool doBuffer)
Q_Q(QDeclarativeListView);
if (!isValid() || !q->isComponentComplete())
return;
+ itemCount = model->count();
qreal bufferFrom = from - buffer;
qreal bufferTo = to + buffer;
qreal fillFrom = from;
@@ -698,6 +706,10 @@ void QDeclarativeListViewPrivate::layout()
{
Q_Q(QDeclarativeListView);
layoutScheduled = false;
+ if (!isValid()) {
+ clear();
+ return;
+ }
updateSections();
if (!visibleItems.isEmpty()) {
int oldEnd = visibleItems.last()->endPosition();
@@ -711,8 +723,6 @@ void QDeclarativeListViewPrivate::layout()
if (currentItem && currentIndex > lastVisibleIndex())
currentItem->setPosition(currentItem->position() + (visibleItems.last()->endPosition() - oldEnd));
}
- if (!isValid())
- return;
q->refill();
minExtentDirty = true;
maxExtentDirty = true;
@@ -760,8 +770,6 @@ void QDeclarativeListViewPrivate::updateTrackedItem()
if (highlight)
item = highlight;
- FxListItem *oldTracked = trackedItem;
-
const char *notifier1 = orient == QDeclarativeListView::Vertical ? SIGNAL(yChanged()) : SIGNAL(xChanged());
const char *notifier2 = orient == QDeclarativeListView::Vertical ? SIGNAL(heightChanged()) : SIGNAL(widthChanged());
@@ -776,7 +784,7 @@ void QDeclarativeListViewPrivate::updateTrackedItem()
QObject::connect(trackedItem->item, notifier1, q, SLOT(trackedPositionChanged()));
QObject::connect(trackedItem->item, notifier2, q, SLOT(trackedPositionChanged()));
}
- if (trackedItem && trackedItem != oldTracked)
+ if (trackedItem)
q->trackedPositionChanged();
}
@@ -828,10 +836,12 @@ void QDeclarativeListViewPrivate::createHighlight()
highlightPosAnimator = new QSmoothedAnimation(q);
highlightPosAnimator->target = QDeclarativeProperty(highlight->item, posProp);
highlightPosAnimator->velocity = highlightMoveSpeed;
+ highlightPosAnimator->userDuration = highlightMoveDuration;
highlightPosAnimator->restart();
const QLatin1String sizeProp(orient == QDeclarativeListView::Vertical ? "height" : "width");
highlightSizeAnimator = new QSmoothedAnimation(q);
highlightSizeAnimator->velocity = highlightResizeSpeed;
+ highlightSizeAnimator->userDuration = highlightResizeDuration;
highlightSizeAnimator->target = QDeclarativeProperty(highlight->item, sizeProp);
highlightSizeAnimator->restart();
changed = true;
@@ -1352,10 +1362,10 @@ QDeclarativeListView::~QDeclarativeListView()
id: myDelegate
Item {
id: wrapper
- SequentialAnimation on ListView.onRemove {
- PropertyAction { target: wrapper.ListView; property: "delayRemove"; value: true }
+ ListView.onRemove: SequentialAnimation {
+ PropertyAction { target: wrapper; property: "ListView.delayRemove"; value: true }
NumberAnimation { target: wrapper; property: "scale"; to: 0; duration: 250; easing.type: "InOutQuad" }
- PropertyAction { target: wrapper.ListView; property: "delayRemove"; value: false }
+ PropertyAction { target: wrapper; property: "ListView.delayRemove"; value: false }
}
}
}
@@ -1860,13 +1870,19 @@ QString QDeclarativeListView::currentSection() const
/*!
\qmlproperty real ListView::highlightMoveSpeed
+ \qmlproperty int ListView::highlightMoveDuration
\qmlproperty real ListView::highlightResizeSpeed
+ \qmlproperty int ListView::highlightResizeDuration
These properties hold the move and resize animation speed of the highlight delegate.
highlightFollowsCurrentItem must be true for these properties
to have effect.
- The default value for these properties is 400 pixels/second.
+ The default value for the speed properties is 400 pixels/second.
+ The default value for the duration properties is -1, i.e. the
+ highlight will take as much time as necessary to move at the set speed.
+
+ These properties have the same characteristics as a SmoothedAnimation.
\sa highlightFollowsCurrentItem
*/
@@ -1887,6 +1903,23 @@ void QDeclarativeListView::setHighlightMoveSpeed(qreal speed)
}
}
+int QDeclarativeListView::highlightMoveDuration() const
+{
+ Q_D(const QDeclarativeListView);
+ return d->highlightMoveDuration;
+}
+
+void QDeclarativeListView::setHighlightMoveDuration(int duration)
+{
+ Q_D(QDeclarativeListView);\
+ if (d->highlightMoveDuration != duration) {
+ d->highlightMoveDuration = duration;
+ if (d->highlightPosAnimator)
+ d->highlightPosAnimator->userDuration = d->highlightMoveDuration;
+ emit highlightMoveDurationChanged();
+ }
+}
+
qreal QDeclarativeListView::highlightResizeSpeed() const
{
Q_D(const QDeclarativeListView);\
@@ -1904,6 +1937,23 @@ void QDeclarativeListView::setHighlightResizeSpeed(qreal speed)
}
}
+int QDeclarativeListView::highlightResizeDuration() const
+{
+ Q_D(const QDeclarativeListView);
+ return d->highlightResizeDuration;
+}
+
+void QDeclarativeListView::setHighlightResizeDuration(int duration)
+{
+ Q_D(QDeclarativeListView);\
+ if (d->highlightResizeDuration != duration) {
+ d->highlightResizeDuration = duration;
+ if (d->highlightSizeAnimator)
+ d->highlightSizeAnimator->userDuration = d->highlightResizeDuration;
+ emit highlightResizeDurationChanged();
+ }
+}
+
/*!
\qmlproperty enumeration ListView::snapMode
@@ -2314,13 +2364,15 @@ void QDeclarativeListView::componentComplete()
{
Q_D(QDeclarativeListView);
QDeclarativeFlickable::componentComplete();
- refill();
- d->moveReason = QDeclarativeListViewPrivate::SetIndex;
- if (d->currentIndex < 0)
- d->updateCurrent(0);
- else
- d->updateCurrent(d->currentIndex);
- d->fixupPosition();
+ if (d->isValid()) {
+ refill();
+ d->moveReason = QDeclarativeListViewPrivate::SetIndex;
+ if (d->currentIndex < 0)
+ d->updateCurrent(0);
+ else
+ d->updateCurrent(d->currentIndex);
+ d->fixupPosition();
+ }
}
void QDeclarativeListView::refill()
@@ -2401,6 +2453,7 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count)
} else if (d->currentIndex < 0) {
d->updateCurrent(0);
}
+ d->itemCount += count;
emit countChanged();
return;
}
@@ -2432,6 +2485,7 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count)
emit currentIndexChanged();
}
d->scheduleLayout();
+ d->itemCount += count;
emit countChanged();
return;
}
@@ -2524,6 +2578,7 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count)
for (int j = 0; j < added.count(); ++j)
added.at(j)->attached->emitAdd();
+ d->itemCount += count;
emit countChanged();
}
@@ -2534,6 +2589,7 @@ void QDeclarativeListView::itemsRemoved(int modelIndex, int count)
return;
d->moveReason = QDeclarativeListViewPrivate::Other;
d->updateUnrequestedIndexes();
+ d->itemCount -= count;
FxListItem *firstVisible = d->firstVisibleItem();
int preRemovedSize = 0;
@@ -2586,7 +2642,8 @@ void QDeclarativeListView::itemsRemoved(int modelIndex, int count)
d->releaseItem(d->currentItem);
d->currentItem = 0;
d->currentIndex = -1;
- d->updateCurrent(qMin(modelIndex, d->model->count()-1));
+ if (d->itemCount)
+ d->updateCurrent(qMin(modelIndex, d->itemCount-1));
}
// update visibleIndex
@@ -2602,7 +2659,7 @@ void QDeclarativeListView::itemsRemoved(int modelIndex, int count)
d->visiblePos = d->header ? d->header->size() : 0;
d->timeline.clear();
d->setPosition(0);
- if (d->model->count() == 0)
+ if (d->itemCount == 0)
update();
}
diff --git a/src/declarative/graphicsitems/qdeclarativelistview_p.h b/src/declarative/graphicsitems/qdeclarativelistview_p.h
index 5810979..9c0b7dd 100644
--- a/src/declarative/graphicsitems/qdeclarativelistview_p.h
+++ b/src/declarative/graphicsitems/qdeclarativelistview_p.h
@@ -101,7 +101,9 @@ class Q_DECLARATIVE_EXPORT QDeclarativeListView : public QDeclarativeFlickable
Q_PROPERTY(QDeclarativeItem *highlightItem READ highlightItem NOTIFY highlightItemChanged)
Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem NOTIFY highlightFollowsCurrentItemChanged)
Q_PROPERTY(qreal highlightMoveSpeed READ highlightMoveSpeed WRITE setHighlightMoveSpeed NOTIFY highlightMoveSpeedChanged)
+ Q_PROPERTY(int highlightMoveDuration READ highlightMoveDuration WRITE setHighlightMoveDuration NOTIFY highlightMoveDurationChanged)
Q_PROPERTY(qreal highlightResizeSpeed READ highlightResizeSpeed WRITE setHighlightResizeSpeed NOTIFY highlightResizeSpeedChanged)
+ Q_PROPERTY(int highlightResizeDuration READ highlightResizeDuration WRITE setHighlightResizeDuration NOTIFY highlightResizeDurationChanged)
Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged)
Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged)
@@ -176,9 +178,15 @@ public:
qreal highlightMoveSpeed() const;
void setHighlightMoveSpeed(qreal);
+ int highlightMoveDuration() const;
+ void setHighlightMoveDuration(int);
+
qreal highlightResizeSpeed() const;
void setHighlightResizeSpeed(qreal);
+ int highlightResizeDuration() const;
+ void setHighlightResizeDuration(int);
+
enum SnapMode { NoSnap, SnapToItem, SnapOneItem };
SnapMode snapMode() const;
void setSnapMode(SnapMode mode);
@@ -208,7 +216,9 @@ Q_SIGNALS:
void currentIndexChanged();
void currentSectionChanged();
void highlightMoveSpeedChanged();
+ void highlightMoveDurationChanged();
void highlightResizeSpeedChanged();
+ void highlightResizeDurationChanged();
void highlightChanged();
void highlightItemChanged();
void modelChanged();
diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp
index 2aab36f..409c228 100644
--- a/src/declarative/graphicsitems/qdeclarativeloader.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp
@@ -276,9 +276,6 @@ void QDeclarativeLoaderPrivate::_q_sourceLoaded()
Q_Q(QDeclarativeLoader);
if (component) {
- QDeclarativeContext *ctxt = new QDeclarativeContext(qmlContext(q));
- ctxt->setContextObject(q);
-
if (!component->errors().isEmpty()) {
qWarning() << component->errors();
emit q->sourceChanged();
@@ -287,6 +284,9 @@ void QDeclarativeLoaderPrivate::_q_sourceLoaded()
return;
}
+ QDeclarativeContext *ctxt = new QDeclarativeContext(qmlContext(q));
+ ctxt->setContextObject(q);
+
QDeclarativeComponent *c = component;
QObject *obj = component->create(ctxt);
if (component != c) {
diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp
index 816aa78..a6cc75e 100644
--- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp
+++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp
@@ -71,6 +71,14 @@ void QDeclarativeDrag::setTarget(QGraphicsObject *t)
emit targetChanged();
}
+void QDeclarativeDrag::resetTarget()
+{
+ if (!_target)
+ return;
+ _target = 0;
+ emit targetChanged();
+}
+
QDeclarativeDrag::Axis QDeclarativeDrag::axis() const
{
return _axis;
@@ -412,8 +420,8 @@ void QDeclarativeMouseArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
if (d->drag && d->drag->target()) {
if (!d->moved) {
- if (d->dragX) d->startX = drag()->target()->x();
- if (d->dragY) d->startY = drag()->target()->y();
+ d->startX = drag()->target()->x();
+ d->startY = drag()->target()->y();
}
QPointF startLocalPos;
@@ -439,7 +447,7 @@ void QDeclarativeMouseArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
}
}
- if (d->dragX) {
+ if (d->dragX && d->dragged) {
qreal x = (curLocalPos.x() - startLocalPos.x()) + d->startX;
if (x < drag()->xmin())
x = drag()->xmin();
@@ -447,7 +455,7 @@ void QDeclarativeMouseArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
x = drag()->xmax();
drag()->target()->setX(x);
}
- if (d->dragY) {
+ if (d->dragY && d->dragged) {
qreal y = (curLocalPos.y() - startLocalPos.y()) + d->startY;
if (y < drag()->ymin())
y = drag()->ymin();
@@ -455,8 +463,8 @@ void QDeclarativeMouseArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
y = drag()->ymax();
drag()->target()->setY(y);
}
+ d->moved = true;
}
- d->moved = true;
QDeclarativeMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress);
emit positionChanged(&me);
}
@@ -643,7 +651,7 @@ bool QDeclarativeMouseArea::setPressed(bool p)
emit positionChanged(&me);
} else {
emit released(&me);
- if (isclick)
+ if (isclick && !d->longPress)
emit clicked(&me);
}
diff --git a/src/declarative/graphicsitems/qdeclarativemousearea_p.h b/src/declarative/graphicsitems/qdeclarativemousearea_p.h
index db49b57..58faac1 100644
--- a/src/declarative/graphicsitems/qdeclarativemousearea_p.h
+++ b/src/declarative/graphicsitems/qdeclarativemousearea_p.h
@@ -55,7 +55,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeDrag : public QObject
Q_OBJECT
Q_ENUMS(Axis)
- Q_PROPERTY(QGraphicsObject *target READ target WRITE setTarget NOTIFY targetChanged)
+ Q_PROPERTY(QGraphicsObject *target READ target WRITE setTarget NOTIFY targetChanged RESET resetTarget)
Q_PROPERTY(Axis axis READ axis WRITE setAxis NOTIFY axisChanged)
Q_PROPERTY(qreal minimumX READ xmin WRITE setXmin NOTIFY minimumXChanged)
Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax NOTIFY maximumXChanged)
@@ -69,6 +69,7 @@ public:
QGraphicsObject *target() const;
void setTarget(QGraphicsObject *);
+ void resetTarget();
enum Axis { XAxis=0x01, YAxis=0x02, XandYAxis=0x03 };
Axis axis() const;
diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp
index 813b525..4aaa28d 100644
--- a/src/declarative/graphicsitems/qdeclarativepathview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp
@@ -221,7 +221,7 @@ void QDeclarativePathViewPrivate::updateHighlight()
tl.reset(moveHighlight);
moveHighlight.setValue(highlightPosition);
- const int duration = 300;
+ const int duration = highlightMoveDuration;
if (target - highlightPosition > model->count()/2) {
highlightUp = false;
@@ -691,6 +691,31 @@ void QDeclarativePathView::setHighlightRangeMode(HighlightRangeMode mode)
emit highlightRangeModeChanged();
}
+
+/*!
+ \qmlproperty int PathView::highlightMoveDuration
+ This property holds the move animation duration of the highlight delegate.
+
+ If the highlightRangeMode is StrictlyEnforceRange then this property
+ determines the speed that the items move along the path.
+
+ The default value for the duration is 300ms.
+*/
+int QDeclarativePathView::highlightMoveDuration() const
+{
+ Q_D(const QDeclarativePathView);
+ return d->highlightMoveDuration;
+}
+
+void QDeclarativePathView::setHighlightMoveDuration(int duration)
+{
+ Q_D(QDeclarativePathView);
+ if (d->highlightMoveDuration == duration)
+ return;
+ d->highlightMoveDuration = duration;
+ emit highlightMoveDurationChanged();
+}
+
/*!
\qmlproperty real PathView::dragMargin
This property holds the maximum distance from the path that initiate mouse dragging.
@@ -1077,7 +1102,6 @@ void QDeclarativePathView::refill()
// qDebug() << "append" << idx;
QDeclarativeItem *item = d->getItem(idx);
item->setZValue(idx+1);
- d->model->completeItem();
if (d->currentIndex == idx) {
item->setFocus(true);
if (QDeclarativePathViewAttached *att = d->attached(item))
@@ -1090,6 +1114,7 @@ void QDeclarativePathView::refill()
d->firstIndex = idx;
d->items.append(item);
d->updateItem(item, pos);
+ d->model->completeItem();
++idx;
if (idx >= d->model->count())
idx = 0;
@@ -1104,7 +1129,6 @@ void QDeclarativePathView::refill()
// qDebug() << "prepend" << idx;
QDeclarativeItem *item = d->getItem(idx);
item->setZValue(idx+1);
- d->model->completeItem();
if (d->currentIndex == idx) {
item->setFocus(true);
if (QDeclarativePathViewAttached *att = d->attached(item))
@@ -1115,6 +1139,7 @@ void QDeclarativePathView::refill()
}
d->items.prepend(item);
d->updateItem(item, pos);
+ d->model->completeItem();
d->firstIndex = idx;
idx = d->firstIndex - 1;
if (idx < 0)
@@ -1130,7 +1155,7 @@ void QDeclarativePathView::refill()
d->updateItem(d->highlightItem, d->highlightRangeStart);
if (QDeclarativePathViewAttached *att = d->attached(d->highlightItem))
att->setOnPath(true);
- } else if (d->moveReason != QDeclarativePathViewPrivate::SetIndex) {
+ } else if (d->highlightItem && d->moveReason != QDeclarativePathViewPrivate::SetIndex) {
d->updateItem(d->highlightItem, d->currentItemOffset);
if (QDeclarativePathViewAttached *att = d->attached(d->highlightItem))
att->setOnPath(currentVisible);
@@ -1316,7 +1341,7 @@ void QDeclarativePathViewPrivate::snapToCurrent()
tl.reset(moveOffset);
moveOffset.setValue(offset);
- const int duration = 300;
+ const int duration = highlightMoveDuration;
if (targetOffset - offset > model->count()/2) {
qreal distance = model->count() - targetOffset + offset;
diff --git a/src/declarative/graphicsitems/qdeclarativepathview_p.h b/src/declarative/graphicsitems/qdeclarativepathview_p.h
index 69770cd..7240578 100644
--- a/src/declarative/graphicsitems/qdeclarativepathview_p.h
+++ b/src/declarative/graphicsitems/qdeclarativepathview_p.h
@@ -68,6 +68,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativePathView : public QDeclarativeItem
Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged)
Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged)
Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode NOTIFY highlightRangeModeChanged)
+ Q_PROPERTY(int highlightMoveDuration READ highlightMoveDuration WRITE setHighlightMoveDuration NOTIFY highlightMoveDurationChanged)
Q_PROPERTY(qreal dragMargin READ dragMargin WRITE setDragMargin NOTIFY dragMarginChanged)
Q_PROPERTY(qreal flickDeceleration READ flickDeceleration WRITE setFlickDeceleration NOTIFY flickDecelerationChanged)
@@ -109,6 +110,9 @@ public:
qreal preferredHighlightEnd() const;
void setPreferredHighlightEnd(qreal);
+ int highlightMoveDuration() const;
+ void setHighlightMoveDuration(int);
+
qreal dragMargin() const;
void setDragMargin(qreal margin);
@@ -145,6 +149,7 @@ Q_SIGNALS:
void interactiveChanged();
void highlightChanged();
void highlightItemChanged();
+ void highlightMoveDurationChanged();
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
diff --git a/src/declarative/graphicsitems/qdeclarativepathview_p_p.h b/src/declarative/graphicsitems/qdeclarativepathview_p_p.h
index 11712fd..303486f 100644
--- a/src/declarative/graphicsitems/qdeclarativepathview_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativepathview_p_p.h
@@ -85,7 +85,7 @@ public:
, highlightPosition(0)
, highlightRangeStart(0), highlightRangeEnd(0)
, highlightRangeMode(QDeclarativePathView::StrictlyEnforceRange)
- , highlightMoveSpeed(1.0)
+ , highlightMoveDuration(300)
{
}
@@ -160,7 +160,7 @@ public:
qreal highlightRangeStart;
qreal highlightRangeEnd;
QDeclarativePathView::HighlightRangeMode highlightRangeMode;
- qreal highlightMoveSpeed;
+ int highlightMoveDuration;
};
QT_END_NAMESPACE
diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp
index d33a8be..f436471 100644
--- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp
@@ -700,14 +700,15 @@ void QDeclarativeGrid::setRows(const int rows)
void QDeclarativeGrid::doPositioning(QSizeF *contentSize)
{
- int c=_columns,r=_rows;//Actual number of rows/columns
+ int c = _columns;
+ int r = _rows;
int numVisible = positionedItems.count();
- if (_columns==-1 && _rows==-1){
+ if (_columns <= 0 && _rows <= 0){
c = 4;
r = (numVisible+3)/4;
- }else if (_rows==-1){
+ } else if (_rows <= 0){
r = (numVisible+(_columns-1))/_columns;
- }else if (_columns==-1){
+ } else if (_columns <= 0){
c = (numVisible+(_rows-1))/_rows;
}
diff --git a/src/declarative/graphicsitems/qdeclarativerectangle.cpp b/src/declarative/graphicsitems/qdeclarativerectangle.cpp
index 3f7548f..54c8ab2 100644
--- a/src/declarative/graphicsitems/qdeclarativerectangle.cpp
+++ b/src/declarative/graphicsitems/qdeclarativerectangle.cpp
@@ -464,6 +464,7 @@ void QDeclarativeRectangle::drawRect(QPainter &p)
filtering at the beginning of the animation and reenable it at the conclusion.
\image rect-smooth.png
+ On this image, smooth is turned off on the top half and on on the bottom half.
*/
QRectF QDeclarativeRectangle::boundingRect() const
diff --git a/src/declarative/graphicsitems/qdeclarativerepeater.cpp b/src/declarative/graphicsitems/qdeclarativerepeater.cpp
index e836788..95f6276 100644
--- a/src/declarative/graphicsitems/qdeclarativerepeater.cpp
+++ b/src/declarative/graphicsitems/qdeclarativerepeater.cpp
@@ -62,10 +62,10 @@ QDeclarativeRepeaterPrivate::~QDeclarativeRepeaterPrivate()
/*!
\qmlclass Repeater QDeclarativeRepeater
- \since 4.7
+ \since 4.7
\inherits Item
- \brief The Repeater item allows you to repeat a component based on a model.
+ \brief The Repeater item allows you to repeat an Item-based component using a model.
The Repeater item is used when you want to create a large number of
similar items. For each entry in the model, an item is instantiated
@@ -102,15 +102,24 @@ QDeclarativeRepeaterPrivate::~QDeclarativeRepeaterPrivate()
The repeater instance continues to own all items it instantiates, even
if they are otherwise manipulated. It is illegal to manually remove an item
created by the Repeater.
+
+ \note Repeater is Item-based, and cannot be used to repeat non-Item-derived objects.
+ For example, it cannot be used to repeat QtObjects.
+ \badcode
+ Item {
+ //XXX illegal. Can't repeat QtObject as it doesn't derive from Item.
+ Repeater {
+ model: 10
+ QtObject {}
+ }
+ }
+ \endcode
*/
/*!
\internal
\class QDeclarativeRepeater
\qmlclass Repeater
-
- XXX Repeater is very conservative in how it instatiates/deletes items. Also
- new model entries will not be created and old ones will not be removed.
*/
/*!
diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp
index a4f3068..b65212b 100644
--- a/src/declarative/graphicsitems/qdeclarativetext.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetext.cpp
@@ -42,6 +42,7 @@
#include "private/qdeclarativetext_p.h"
#include "private/qdeclarativetext_p_p.h"
#include <qdeclarativestyledtext_p.h>
+#include <qdeclarativeinfo.h>
#include <QTextLayout>
#include <QTextLine>
@@ -70,7 +71,7 @@ QT_BEGIN_NAMESPACE
\image declarative-text.png
If height and width are not explicitly set, Text will attempt to determine how
- much room is needed and set it accordingly. Unless \c wrap is set, it will always
+ much room is needed and set it accordingly. Unless \c wrapMode is set, it will always
prefer width to height (all text will be placed on a single line).
The \c elide property can alternatively be used to fit a single line of
@@ -98,7 +99,7 @@ QT_BEGIN_NAMESPACE
\image text.png
If height and width are not explicitly set, Text will attempt to determine how
- much room is needed and set it accordingly. Unless \c wrap is set, it will always
+ much room is needed and set it accordingly. Unless \c wrapMode is set, it will always
prefer width to height (all text will be placed on a single line).
The \c elide property can alternatively be used to fit a line of plain text to a set width.
@@ -121,14 +122,116 @@ QDeclarativeTextPrivate::~QDeclarativeTextPrivate()
/*!
\qmlproperty string Text::font.family
+
+ Sets the family name of the font.
+
+ The family name is case insensitive and may optionally include a foundry name, e.g. "Helvetica [Cronyx]".
+ If the family is available from more than one foundry and the foundry isn't specified, an arbitrary foundry is chosen.
+ If the family isn't available a family will be set using the font matching algorithm.
+*/
+
+/*!
\qmlproperty bool Text::font.bold
+
+ Sets the font's weight to bold.
+*/
+
+/*!
+ \qmlproperty enumeration Text::font.weight
+
+ Sets the font's weight.
+
+ The weight can be one of:
+ \list
+ \o Light
+ \o Normal - the default
+ \o DemiBold
+ \o Bold
+ \o Black
+ \endlist
+
+ \qml
+ Text { text: "Hello"; font.weight: Font.DemiBold }
+ \endqml
+*/
+
+/*!
\qmlproperty bool Text::font.italic
+
+ Sets the style of the text to italic.
+*/
+
+/*!
\qmlproperty bool Text::font.underline
+
+ Set the style of the text to underline.
+*/
+
+/*!
+ \qmlproperty bool Text::font.outline
+
+ Set the style of the text to outline.
+*/
+
+/*!
+ \qmlproperty bool Text::font.strikeout
+
+ Set the style of the text to strikeout.
+*/
+
+/*!
\qmlproperty real Text::font.pointSize
+
+ Sets the font size in points. The point size must be greater than zero.
+*/
+
+/*!
\qmlproperty int Text::font.pixelSize
- Set the Text's font attributes.
+ Sets the font size in pixels.
+
+ Using this function makes the font device dependent.
+ Use \c pointSize to set the size of the font in a device independent manner.
+*/
+
+/*!
+ \qmlproperty real Text::font.letterSpacing
+
+ Sets the letter spacing for the font.
+
+ Letter spacing changes the default spacing between individual letters in the font.
+ A value of 100 will keep the spacing unchanged; a value of 200 will enlarge the spacing after a character by
+ the width of the character itself.
+*/
+
+/*!
+ \qmlproperty real Text::font.wordSpacing
+
+ Sets the word spacing for the font.
+
+ Word spacing changes the default spacing between individual words.
+ A positive value increases the word spacing by a corresponding amount of pixels,
+ while a negative value decreases the inter-word spacing accordingly.
+*/
+
+/*!
+ \qmlproperty enumeration Text::font.capitalization
+
+ Sets the capitalization for the text.
+
+ \list
+ \o MixedCase - This is the normal text rendering option where no capitalization change is applied.
+ \o AllUppercase - This alters the text to be rendered in all uppercase type.
+ \o AllLowercase - This alters the text to be rendered in all lowercase type.
+ \o SmallCaps - This alters the text to be rendered in small-caps type.
+ \o Capitalize - This alters the text to be rendered with the first character of each word as an uppercase character.
+ \endlist
+
+ \qml
+ Text { text: "Hello"; font.capitalization: Font.AllLowercase }
+ \endqml
*/
+
QFont QDeclarativeText::font() const
{
Q_D(const QDeclarativeText);
@@ -172,7 +275,7 @@ void QDeclarativeText::setText(const QString &n)
/*!
\qmlproperty string Text::text
- The text to display. Text supports both plain and rich text strings.
+ The text to display. Text supports both plain and rich text strings.
The item will try to automatically determine whether the text should
be treated as rich text. This determination is made using Qt::mightBeRichText().
@@ -219,14 +322,20 @@ QColor QDeclarativeText::color() const
Set an additional text style.
- Supported text styles are \c Normal, \c Outline, \c Raised and \c Sunken.
+ Supported text styles are:
+ \list
+ \o Normal - the default
+ \o Outline
+ \o Raised
+ \o Sunken
+ \endlist
\qml
Row {
Text { font.pointSize: 24; text: "Normal" }
- Text { font.pointSize: 24; text: "Raised"; style: Text.Raised; styleColor: "#AAAAAA" }
- Text { font.pointSize: 24; text: "Outline"; style: Text.Outline; styleColor: "red" }
- Text { font.pointSize: 24; text: "Sunken"; style: Text.Sunken; styleColor: "#AAAAAA" }
+ Text { font.pointSize: 24; text: "Raised"; style: Text.Raised; styleColor: "#AAAAAA" }
+ Text { font.pointSize: 24; text: "Outline";style: Text.Outline; styleColor: "red" }
+ Text { font.pointSize: 24; text: "Sunken"; style: Text.Sunken; styleColor: "#AAAAAA" }
}
\endqml
@@ -268,6 +377,10 @@ void QDeclarativeText::setStyleColor(const QColor &color)
\c styleColor is used as the outline color for outlined text, and as the
shadow color for raised or sunken text. If no style has been set, it is not
used at all.
+
+ \qml
+ Text { font.pointSize: 18; text: "hello"; style: Text.Raised; styleColor: "gray" }
+ \endqml
*/
QColor QDeclarativeText::styleColor() const
{
@@ -319,37 +432,55 @@ void QDeclarativeText::setVAlign(VAlignment align)
}
/*!
- \qmlproperty bool Text::wrap
+ \qmlproperty enumeration Text::wrapMode
Set this property to wrap the text to the Text item's width. The text will only
- wrap if an explicit width has been set.
+ wrap if an explicit width has been set. wrapMode can be one of:
- Wrapping is done on word boundaries (i.e. it is a "word-wrap"). If the text cannot be
+ \list
+ \o NoWrap - no wrapping will be performed.
+ \o WordWrap - wrapping is done on word boundaries. If the text cannot be
word-wrapped to the specified width it will be partially drawn outside of the item's bounds.
If this is undesirable then enable clipping on the item (Item::clip).
+ \o WrapAnywhere - Text can be wrapped at any point on a line, even if it occurs in the middle of a word.
+ \o WrapAtWordBoundaryOrAnywhere - If possible, wrapping occurs at a word boundary; otherwise it
+ will occur at the appropriate point on the line, even in the middle of a word.
+ \endlist
- Wrapping is off by default.
+ The default is NoWrap.
*/
-//### Future may provide choice of wrap modes, such as QTextOption::WrapAtWordBoundaryOrAnywhere
-bool QDeclarativeText::wrap() const
+QDeclarativeText::WrapMode QDeclarativeText::wrapMode() const
{
Q_D(const QDeclarativeText);
- return d->wrap;
+ return d->wrapMode;
}
-void QDeclarativeText::setWrap(bool w)
+void QDeclarativeText::setWrapMode(WrapMode mode)
{
Q_D(QDeclarativeText);
- if (w == d->wrap)
+ if (mode == d->wrapMode)
return;
- d->wrap = w;
+ d->wrapMode = mode;
d->updateLayout();
d->markImgDirty();
- emit wrapChanged(d->wrap);
+ 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
@@ -379,18 +510,18 @@ void QDeclarativeText::setWrap(bool w)
\o
\qml
Column {
- TextEdit {
+ Text {
font.pointSize: 24
text: "<b>Hello</b> <i>World!</i>"
}
- TextEdit {
+ Text {
font.pointSize: 24
- textFormat: "RichText"
+ textFormat: Text.RichText
text: "<b>Hello</b> <i>World!</i>"
}
- TextEdit {
+ Text {
font.pointSize: 24
- textFormat: "PlainText"
+ textFormat: Text.PlainText
text: "<b>Hello</b> <i>World!</i>"
}
}
@@ -437,9 +568,15 @@ void QDeclarativeText::setTextFormat(TextFormat format)
Set this property to elide parts of the text fit to the Text item's width.
The text will only elide if an explicit width has been set.
- This property cannot be used with wrap enabled or with rich text.
+ This property cannot be used with wrapping enabled or with rich text.
- Eliding can be \c ElideNone (the default), \c ElideLeft, \c ElideMiddle, or \c ElideRight.
+ Eliding can be:
+ \list
+ \o ElideNone - the default
+ \o ElideLeft
+ \o ElideMiddle
+ \o ElideRight
+ \endlist
If the text is a multi-length string, and the mode is not \c ElideNone,
the first string that fits will be used, otherwise the last will be elided.
@@ -471,7 +608,7 @@ void QDeclarativeText::geometryChanged(const QRectF &newGeometry,
{
Q_D(QDeclarativeText);
if (newGeometry.width() != oldGeometry.width()) {
- if (d->wrap || d->elideMode != QDeclarativeText::ElideNone) {
+ if (d->wrapMode != QDeclarativeText::NoWrap || d->elideMode != QDeclarativeText::ElideNone) {
//re-elide if needed
if (d->singleline && d->elideMode != QDeclarativeText::ElideNone &&
isComponentComplete() && widthValid()) {
@@ -538,12 +675,9 @@ void QDeclarativeTextPrivate::updateSize()
singleline = false; // richtext can't elide or be optimized for single-line case
doc->setDefaultFont(font);
QTextOption option((Qt::Alignment)int(hAlign | vAlign));
- if (wrap)
- option.setWrapMode(QTextOption::WordWrap);
- else
- option.setWrapMode(QTextOption::NoWrap);
+ option.setWrapMode(QTextOption::WrapMode(wrapMode));
doc->setDefaultTextOption(option);
- if (wrap && !q->heightValid() && q->widthValid())
+ if (wrapMode != QDeclarativeText::NoWrap && !q->heightValid() && q->widthValid())
doc->setTextWidth(q->width());
else
doc->setTextWidth(doc->idealWidth()); // ### Text does not align if width is not set (QTextDoc bug)
@@ -623,9 +757,13 @@ QSize QDeclarativeTextPrivate::setupTextLayout(QTextLayout *layout)
qreal lineWidth = 0;
//set manual width
- if ((wrap || elideMode != QDeclarativeText::ElideNone) && q->widthValid())
+ if ((wrapMode != QDeclarativeText::NoWrap || elideMode != QDeclarativeText::ElideNone) && q->widthValid())
lineWidth = q->width();
+ QTextOption textOption = layout->textOption();
+ textOption.setWrapMode(QTextOption::WrapMode(wrapMode));
+ layout->setTextOption(textOption);
+
layout->beginLayout();
while (1) {
@@ -633,7 +771,7 @@ QSize QDeclarativeTextPrivate::setupTextLayout(QTextLayout *layout)
if (!line.isValid())
break;
- if ((wrap || elideMode != QDeclarativeText::ElideNone) && q->widthValid())
+ if ((wrapMode != QDeclarativeText::NoWrap || elideMode != QDeclarativeText::ElideNone) && q->widthValid())
line.setLineWidth(lineWidth);
}
layout->endLayout();
diff --git a/src/declarative/graphicsitems/qdeclarativetext_p.h b/src/declarative/graphicsitems/qdeclarativetext_p.h
index cbea8f3..871c833 100644
--- a/src/declarative/graphicsitems/qdeclarativetext_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetext_p.h
@@ -42,6 +42,7 @@
#ifndef QDECLARATIVETEXT_H
#define QDECLARATIVETEXT_H
+#include <QtGui/qtextoption.h>
#include "qdeclarativeitem.h"
QT_BEGIN_HEADER
@@ -58,6 +59,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeText : public QDeclarativeItem
Q_ENUMS(TextStyle)
Q_ENUMS(TextFormat)
Q_ENUMS(TextElideMode)
+ Q_ENUMS(WrapMode)
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
@@ -66,7 +68,8 @@ class Q_DECLARATIVE_EXPORT QDeclarativeText : public QDeclarativeItem
Q_PROPERTY(QColor styleColor READ styleColor WRITE setStyleColor NOTIFY styleColorChanged)
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) //### there are several wrap modes in Qt
+ 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?
@@ -93,6 +96,12 @@ public:
ElideMiddle = Qt::ElideMiddle,
ElideNone = Qt::ElideNone };
+ enum WrapMode { NoWrap = QTextOption::NoWrap,
+ WordWrap = QTextOption::WordWrap,
+ WrapAnywhere = QTextOption::WrapAnywhere,
+ WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere
+ };
+
QString text() const;
void setText(const QString &);
@@ -116,6 +125,8 @@ public:
bool wrap() const;
void setWrap(bool w);
+ WrapMode wrapMode() const;
+ void setWrapMode(WrapMode w);
TextFormat textFormat() const;
void setTextFormat(TextFormat format);
@@ -136,7 +147,7 @@ Q_SIGNALS:
void styleColorChanged(const QColor &color);
void horizontalAlignmentChanged(HAlignment alignment);
void verticalAlignmentChanged(VAlignment alignment);
- void wrapChanged(bool wrap);
+ void wrapModeChanged();
void textFormatChanged(TextFormat textFormat);
void elideModeChanged(TextElideMode mode);
diff --git a/src/declarative/graphicsitems/qdeclarativetext_p_p.h b/src/declarative/graphicsitems/qdeclarativetext_p_p.h
index 85a65ce..cc5a9f2 100644
--- a/src/declarative/graphicsitems/qdeclarativetext_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetext_p_p.h
@@ -72,8 +72,8 @@ public:
QDeclarativeTextPrivate()
: color((QRgb)0), style(QDeclarativeText::Normal),
hAlign(QDeclarativeText::AlignLeft), vAlign(QDeclarativeText::AlignTop), elideMode(QDeclarativeText::ElideNone),
- imgDirty(true), dirty(true), wrap(false), richText(false), singleline(false), cache(true), doc(0),
- format(QDeclarativeText::AutoText)
+ imgDirty(true), dirty(true), richText(false), singleline(false), cache(true), doc(0),
+ format(QDeclarativeText::AutoText), wrapMode(QDeclarativeText::NoWrap)
{
#if defined(QML_NO_TEXT_CACHE)
cache = false;
@@ -115,7 +115,6 @@ public:
QDeclarativeText::TextElideMode elideMode;
bool imgDirty:1;
bool dirty:1;
- bool wrap:1;
bool richText:1;
bool singleline:1;
bool cache:1;
@@ -123,6 +122,7 @@ public:
QTextLayout layout;
QSize cachedLayoutSize;
QDeclarativeText::TextFormat format;
+ QDeclarativeText::WrapMode wrapMode;
};
QT_END_NAMESPACE
diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp
index 7374bc8..1fec484 100644
--- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp
@@ -44,6 +44,7 @@
#include "private/qdeclarativeevents_p_p.h"
#include <private/qdeclarativeglobal_p.h>
+#include <qdeclarativeinfo.h>
#include <QTextLayout>
#include <QTextLine>
@@ -117,13 +118,114 @@ QString QDeclarativeTextEdit::text() const
/*!
\qmlproperty string TextEdit::font.family
+
+ Sets the family name of the font.
+
+ The family name is case insensitive and may optionally include a foundry name, e.g. "Helvetica [Cronyx]".
+ If the family is available from more than one foundry and the foundry isn't specified, an arbitrary foundry is chosen.
+ If the family isn't available a family will be set using the font matching algorithm.
+*/
+
+/*!
\qmlproperty bool TextEdit::font.bold
+
+ Sets the font's weight to bold.
+*/
+
+/*!
+ \qmlproperty enumeration TextEdit::font.weight
+
+ Sets the font's weight.
+
+ The weight can be one of:
+ \list
+ \o Light
+ \o Normal - the default
+ \o DemiBold
+ \o Bold
+ \o Black
+ \endlist
+
+ \qml
+ TextEdit { text: "Hello"; font.weight: Font.DemiBold }
+ \endqml
+*/
+
+/*!
\qmlproperty bool TextEdit::font.italic
+
+ Sets the style of the text to italic.
+*/
+
+/*!
\qmlproperty bool TextEdit::font.underline
+
+ Set the style of the text to underline.
+*/
+
+/*!
+ \qmlproperty bool TextEdit::font.outline
+
+ Set the style of the text to outline.
+*/
+
+/*!
+ \qmlproperty bool TextEdit::font.strikeout
+
+ Set the style of the text to strikeout.
+*/
+
+/*!
\qmlproperty real TextEdit::font.pointSize
+
+ Sets the font size in points. The point size must be greater than zero.
+*/
+
+/*!
\qmlproperty int TextEdit::font.pixelSize
- Set the TextEdit's font attributes.
+ Sets the font size in pixels.
+
+ Using this function makes the font device dependent.
+ Use \c pointSize to set the size of the font in a device independent manner.
+*/
+
+/*!
+ \qmlproperty real TextEdit::font.letterSpacing
+
+ Sets the letter spacing for the font.
+
+ Letter spacing changes the default spacing between individual letters in the font.
+ A value of 100 will keep the spacing unchanged; a value of 200 will enlarge the spacing after a character by
+ the width of the character itself.
+*/
+
+/*!
+ \qmlproperty real TextEdit::font.wordSpacing
+
+ Sets the word spacing for the font.
+
+ Word spacing changes the default spacing between individual words.
+ A positive value increases the word spacing by a corresponding amount of pixels,
+ while a negative value decreases the inter-word spacing accordingly.
+*/
+
+/*!
+ \qmlproperty enumeration TextEdit::font.capitalization
+
+ Sets the capitalization for the text.
+
+ \list
+ \o MixedCase - This is the normal text rendering option where no capitalization change is applied.
+ \o AllUppercase - This alters the text to be rendered in all uppercase type.
+ \o AllLowercase - This alters the text to be rendered in all lowercase type.
+ \o SmallCaps - This alters the text to be rendered in small-caps type.
+ \o Capitalize - This alters the text to be rendered with the first character of each word as an uppercase character.
+ \endlist
+
+ \qml
+ TextEdit { text: "Hello"; font.capitalization: Font.AllLowercase }
+ \endqml
*/
/*!
@@ -170,12 +272,12 @@ Column {
}
TextEdit {
font.pointSize: 24
- textFormat: "RichText"
+ textFormat: TextEdit.RichText
text: "<b>Hello</b> <i>World!</i>"
}
TextEdit {
font.pointSize: 24
- textFormat: "PlainText"
+ textFormat: TextEdit.PlainText
text: "<b>Hello</b> <i>World!</i>"
}
}
@@ -360,29 +462,50 @@ void QDeclarativeTextEdit::setVAlign(QDeclarativeTextEdit::VAlignment alignment)
emit verticalAlignmentChanged(d->vAlign);
}
-bool QDeclarativeTextEdit::wrap() const
-{
- Q_D(const QDeclarativeTextEdit);
- return d->wrap;
-}
-
/*!
- \qmlproperty bool TextEdit::wrap
+ \qmlproperty enumeration TextEdit::wrapMode
Set this property to wrap the text to the TextEdit item's width.
The text will only wrap if an explicit width has been set.
- Wrapping is done on word boundaries (i.e. it is a "word-wrap"). Wrapping is off by default.
+ \list
+ \o NoWrap - no wrapping will be performed.
+ \o WordWrap - wrapping is done on word boundaries.
+ \o WrapAnywhere - Text can be wrapped at any point on a line, even if it occurs in the middle of a word.
+ \o WrapAtWordBoundaryOrAnywhere - If possible, wrapping occurs at a word boundary; otherwise it
+ will occur at the appropriate point on the line, even in the middle of a word.
+ \endlist
+
+ The default is NoWrap.
*/
-void QDeclarativeTextEdit::setWrap(bool w)
+QDeclarativeTextEdit::WrapMode QDeclarativeTextEdit::wrapMode() const
+{
+ Q_D(const QDeclarativeTextEdit);
+ return d->wrapMode;
+}
+
+void QDeclarativeTextEdit::setWrapMode(WrapMode mode)
{
Q_D(QDeclarativeTextEdit);
- if (w == d->wrap)
+ if (mode == d->wrapMode)
return;
- d->wrap = w;
+ d->wrapMode = mode;
d->updateDefaultTextOption();
updateSize();
- emit wrapChanged(d->wrap);
+ 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);
}
/*!
@@ -666,7 +789,7 @@ void QDeclarativeTextEdit::componentComplete()
*/
void QDeclarativeTextEdit::setReadOnly(bool r)
{
- Q_D(QDeclarativeTextEdit);
+ Q_D(QDeclarativeTextEdit);
if (r == isReadOnly())
return;
@@ -1020,11 +1143,7 @@ void QDeclarativeTextEditPrivate::updateDefaultTextOption()
opt.setAlignment((Qt::Alignment)(int)(hAlign | vAlign));
QTextOption::WrapMode oldWrapMode = opt.wrapMode();
-
- if (wrap)
- opt.setWrapMode(QTextOption::WordWrap);
- else
- opt.setWrapMode(QTextOption::NoWrap);
+ opt.setWrapMode(QTextOption::WrapMode(wrapMode));
if (oldWrapMode == opt.wrapMode() && oldAlignment == opt.alignment())
return;
diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p.h
index 0e91e73..605b620 100644
--- a/src/declarative/graphicsitems/qdeclarativetextedit_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextedit_p.h
@@ -64,6 +64,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeTextEdit : public QDeclarativePaintedItem
Q_ENUMS(VAlignment)
Q_ENUMS(HAlignment)
Q_ENUMS(TextFormat)
+ Q_ENUMS(WrapMode)
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
@@ -72,7 +73,8 @@ 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) //### other wrap modes
+ 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)
Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged)
@@ -107,6 +109,12 @@ public:
AutoText = Qt::AutoText
};
+ enum WrapMode { NoWrap = QTextOption::NoWrap,
+ WordWrap = QTextOption::WordWrap,
+ WrapAnywhere = QTextOption::WrapAnywhere,
+ WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere
+ };
+
QString text() const;
void setText(const QString &);
@@ -133,6 +141,8 @@ public:
bool wrap() const;
void setWrap(bool w);
+ WrapMode wrapMode() const;
+ void setWrapMode(WrapMode w);
bool isCursorVisible() const;
void setCursorVisible(bool on);
@@ -185,7 +195,7 @@ Q_SIGNALS:
void fontChanged(const QFont &font);
void horizontalAlignmentChanged(HAlignment alignment);
void verticalAlignmentChanged(VAlignment alignment);
- void wrapChanged(bool isWrapped);
+ void wrapModeChanged();
void textFormatChanged(TextFormat textFormat);
void readOnlyChanged(bool isReadOnly);
void cursorVisibleChanged(bool isCursorVisible);
diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h
index 310db48..8d4b611 100644
--- a/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h
@@ -68,10 +68,11 @@ class QDeclarativeTextEditPrivate : public QDeclarativePaintedItemPrivate
public:
QDeclarativeTextEditPrivate()
- : color("black"), imgDirty(true), hAlign(QDeclarativeTextEdit::AlignLeft), vAlign(QDeclarativeTextEdit::AlignTop),
- dirty(false), wrap(false), richText(false), cursorVisible(false), focusOnPress(true),
+ : color("black"), hAlign(QDeclarativeTextEdit::AlignLeft), vAlign(QDeclarativeTextEdit::AlignTop),
+ imgDirty(true), dirty(false), richText(false), cursorVisible(false), focusOnPress(true),
persistentSelection(true), textMargin(0.0), lastSelectionStart(0), lastSelectionEnd(0),
- cursorComponent(0), cursor(0), format(QDeclarativeTextEdit::AutoText), document(0)
+ cursorComponent(0), cursor(0), format(QDeclarativeTextEdit::AutoText), document(0),
+ wrapMode(QDeclarativeTextEdit::NoWrap)
{
}
@@ -89,17 +90,16 @@ public:
QColor selectedTextColor;
QString style;
QColor styleColor;
- bool imgDirty;
QPixmap imgCache;
QPixmap imgStyleCache;
QDeclarativeTextEdit::HAlignment hAlign;
QDeclarativeTextEdit::VAlignment vAlign;
- bool dirty;
- bool wrap;
- bool richText;
- bool cursorVisible;
- bool focusOnPress;
- bool persistentSelection;
+ bool imgDirty : 1;
+ bool dirty : 1;
+ bool richText : 1;
+ bool cursorVisible : 1;
+ bool focusOnPress : 1;
+ bool persistentSelection : 1;
qreal textMargin;
int lastSelectionStart;
int lastSelectionEnd;
@@ -108,6 +108,7 @@ public:
QDeclarativeTextEdit::TextFormat format;
QTextDocument *document;
QTextControl *control;
+ QDeclarativeTextEdit::WrapMode wrapMode;
};
QT_END_NAMESPACE
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
index 29e43f9..89ec834 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
@@ -97,14 +97,116 @@ void QDeclarativeTextInput::setText(const QString &s)
/*!
\qmlproperty string TextInput::font.family
+
+ Sets the family name of the font.
+
+ The family name is case insensitive and may optionally include a foundry name, e.g. "Helvetica [Cronyx]".
+ If the family is available from more than one foundry and the foundry isn't specified, an arbitrary foundry is chosen.
+ If the family isn't available a family will be set using the font matching algorithm.
+*/
+
+/*!
\qmlproperty bool TextInput::font.bold
+
+ Sets the font's weight to bold.
+*/
+
+/*!
+ \qmlproperty enumeration TextInput::font.weight
+
+ Sets the font's weight.
+
+ The weight can be one of:
+ \list
+ \o Light
+ \o Normal - the default
+ \o DemiBold
+ \o Bold
+ \o Black
+ \endlist
+
+ \qml
+ TextInput { text: "Hello"; font.weight: Font.DemiBold }
+ \endqml
+*/
+
+/*!
\qmlproperty bool TextInput::font.italic
+
+ Sets the style of the text to italic.
+*/
+
+/*!
\qmlproperty bool TextInput::font.underline
+
+ Set the style of the text to underline.
+*/
+
+/*!
+ \qmlproperty bool TextInput::font.outline
+
+ Set the style of the text to outline.
+*/
+
+/*!
+ \qmlproperty bool TextInput::font.strikeout
+
+ Set the style of the text to strikeout.
+*/
+
+/*!
\qmlproperty real TextInput::font.pointSize
+
+ Sets the font size in points. The point size must be greater than zero.
+*/
+
+/*!
\qmlproperty int TextInput::font.pixelSize
- Set the TextInput's font attributes.
+ Sets the font size in pixels.
+
+ Using this function makes the font device dependent.
+ Use \c pointSize to set the size of the font in a device independent manner.
*/
+
+/*!
+ \qmlproperty real TextInput::font.letterSpacing
+
+ Sets the letter spacing for the font.
+
+ Letter spacing changes the default spacing between individual letters in the font.
+ A value of 100 will keep the spacing unchanged; a value of 200 will enlarge the spacing after a character by
+ the width of the character itself.
+*/
+
+/*!
+ \qmlproperty real TextInput::font.wordSpacing
+
+ Sets the word spacing for the font.
+
+ Word spacing changes the default spacing between individual words.
+ A positive value increases the word spacing by a corresponding amount of pixels,
+ while a negative value decreases the inter-word spacing accordingly.
+*/
+
+/*!
+ \qmlproperty enumeration TextInput::font.capitalization
+
+ Sets the capitalization for the text.
+
+ \list
+ \o MixedCase - This is the normal text rendering option where no capitalization change is applied.
+ \o AllUppercase - This alters the text to be rendered in all uppercase type.
+ \o AllLowercase - This alters the text to be rendered in all lowercase type.
+ \o SmallCaps - This alters the text to be rendered in small-caps type.
+ \o Capitalize - This alters the text to be rendered with the first character of each word as an uppercase character.
+ \endlist
+
+ \qml
+ TextInput { text: "Hello"; font.capitalization: Font.AllLowercase }
+ \endqml
+*/
+
QFont QDeclarativeTextInput::font() const
{
Q_D(const QDeclarativeTextInput);
@@ -429,6 +531,29 @@ void QDeclarativeTextInput::setFocusOnPress(bool b)
}
/*!
+ \qmlproperty bool TextInput::autoScroll
+
+ Whether the TextInput should scroll when the text is longer than the width. By default this is
+ set to true.
+*/
+bool QDeclarativeTextInput::autoScroll() const
+{
+ Q_D(const QDeclarativeTextInput);
+ return d->autoScroll;
+}
+
+void QDeclarativeTextInput::setAutoScroll(bool b)
+{
+ Q_D(QDeclarativeTextInput);
+ if (d->autoScroll == b)
+ return;
+
+ d->autoScroll = b;
+
+ emit autoScrollChanged(d->autoScroll);
+}
+
+/*!
\qmlproperty Validator TextInput::validator
Allows you to set a validator on the TextInput. When a validator is set
@@ -449,7 +574,7 @@ void QDeclarativeTextInput::setFocusOnPress(bool b)
input of integers between 11 and 31 into the text input:
\code
- import Qt 4.6
+ import Qt 4.7
TextInput{
validator: IntValidator{bottom: 11; top: 31;}
focus: true
@@ -634,7 +759,18 @@ void QDeclarativeTextInput::moveCursor()
d->cursorItem->setX(d->control->cursorToX() - d->hscroll);
}
-int QDeclarativeTextInput::xToPos(int x)
+/*
+ \qmlmethod int xToPosition(int x)
+
+ This function returns the character position at
+ x pixels from the left of the textInput. Position 0 is before the
+ first character, position 1 is after the first character but before the second,
+ and so on until position text.length, which is after all characters.
+
+ This means that for all x values before the first character this function returns 0,
+ and for all x values after the last character this function returns text.length.
+*/
+int QDeclarativeTextInput::xToPosition(int x)
{
Q_D(const QDeclarativeTextInput);
return d->control->xToPos(x - d->hscroll);
@@ -645,6 +781,10 @@ void QDeclarativeTextInputPrivate::focusChanged(bool hasFocus)
Q_Q(QDeclarativeTextInput);
focused = hasFocus;
q->setCursorVisible(hasFocus);
+ if(q->echoMode() == QDeclarativeTextInput::PasswordEchoOnEdit && !hasFocus)
+ control->updatePasswordEchoEditing(false);//QLineControl sets it on key events, but doesn't deal with focus events
+ if (!hasFocus)
+ control->deselect();
QDeclarativeItemPrivate::focusChanged(hasFocus);
}
@@ -679,7 +819,15 @@ void QDeclarativeTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event)
}
setFocus(true);
}
- d->control->processEvent(event);
+ bool mark = event->modifiers() & Qt::ShiftModifier;
+ int cursor = d->xToPos(event->pos().x());
+ d->control->moveCursor(cursor, mark);
+}
+
+void QDeclarativeTextInput::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
+{
+ Q_D(QDeclarativeTextInput);
+ d->control->moveCursor(d->xToPos(event->pos().x()), true);
}
/*!
@@ -704,6 +852,7 @@ bool QDeclarativeTextInput::event(QEvent* ev)
case QEvent::KeyPress:
case QEvent::KeyRelease://###Should the control be doing anything with release?
case QEvent::GraphicsSceneMousePress:
+ case QEvent::GraphicsSceneMouseMove:
case QEvent::GraphicsSceneMouseRelease:
break;
default:
@@ -733,28 +882,56 @@ void QDeclarativeTextInput::drawContents(QPainter *p, const QRect &r)
int flags = QLineControl::DrawText;
if(!isReadOnly() && d->cursorVisible && !d->cursorItem)
flags |= QLineControl::DrawCursor;
- if (d->control->hasSelectedText()){
+ if (d->control->hasSelectedText())
flags |= QLineControl::DrawSelections;
- }
-
QPoint offset = QPoint(0,0);
- if(d->hAlign != AlignLeft){
- QFontMetrics fm = QFontMetrics(d->font);
- //###Is this using bearing appropriately?
- int minLB = qMax(0, -fm.minLeftBearing());
- int minRB = qMax(0, -fm.minRightBearing());
- int widthUsed = qRound(d->control->naturalTextWidth()) + 1 + minRB;
- int hOffset = 0;
+ QFontMetrics fm = QFontMetrics(d->font);
+ int cix = qRound(d->control->cursorToX());
+ QRect br(boundingRect().toRect());
+ //###Is this using bearing appropriately?
+ int minLB = qMax(0, -fm.minLeftBearing());
+ int minRB = qMax(0, -fm.minRightBearing());
+ int widthUsed = qRound(d->control->naturalTextWidth()) + 1 + minRB;
+ if (d->autoScroll) {
+ if ((minLB + widthUsed) <= br.width()) {
+ // text fits in br; use hscroll for alignment
+ switch (d->hAlign & ~(Qt::AlignAbsolute|Qt::AlignVertical_Mask)) {
+ case Qt::AlignRight:
+ d->hscroll = widthUsed - br.width() + 1;
+ break;
+ case Qt::AlignHCenter:
+ d->hscroll = (widthUsed - br.width()) / 2;
+ break;
+ default:
+ // Left
+ d->hscroll = 0;
+ break;
+ }
+ d->hscroll -= minLB;
+ } else if (cix - d->hscroll >= br.width()) {
+ // text doesn't fit, cursor is to the right of br (scroll right)
+ d->hscroll = cix - br.width() + 1;
+ } else if (cix - d->hscroll < 0 && d->hscroll < widthUsed) {
+ // text doesn't fit, cursor is to the left of br (scroll left)
+ d->hscroll = cix;
+ } else if (widthUsed - d->hscroll < br.width()) {
+ // text doesn't fit, text document is to the left of br; align
+ // right
+ d->hscroll = widthUsed - br.width() + 1;
+ }
+ // the y offset is there to keep the baseline constant in case we have script changes in the text.
+ offset = br.topLeft() - QPoint(d->hscroll, d->control->ascent() - fm.ascent());
+ } else {
if(d->hAlign == AlignRight){
- hOffset = width() - widthUsed;
+ d->hscroll = width() - widthUsed;
}else if(d->hAlign == AlignHCenter){
- hOffset = (width() - widthUsed) / 2;
+ d->hscroll = (width() - widthUsed) / 2;
}
- hOffset -= minLB;
- offset = QPoint(hOffset, 0);
+ d->hscroll -= minLB;
+ offset = QPoint(d->hscroll, 0);
}
- QRect clipRect = r;
- d->control->draw(p, offset, clipRect, flags);
+
+ d->control->draw(p, offset, r, flags);
p->restore();
}
@@ -809,6 +986,72 @@ void QDeclarativeTextInput::selectAll()
filtering at the beginning of the animation and reenable it at the conclusion.
*/
+/*
+ \qmlproperty string TextInput::passwordCharacter
+
+ This is the character displayed when echoMode is set to Password or
+ PasswordEchoOnEdit. By default it is an asterisk.
+
+ Attempting to set this to more than one character will set it to
+ the first character in the string. Attempting to set this to less
+ than one character will fail.
+*/
+QString QDeclarativeTextInput::passwordCharacter() const
+{
+ Q_D(const QDeclarativeTextInput);
+ return QString(d->control->passwordCharacter());
+}
+
+void QDeclarativeTextInput::setPasswordCharacter(const QString &str)
+{
+ Q_D(QDeclarativeTextInput);
+ if(str.length() < 1)
+ return;
+ emit passwordCharacterChanged();
+ d->control->setPasswordCharacter(str.constData()[0]);
+}
+
+/*
+ \qmlproperty string TextInput::displayText
+
+ This is the actual text displayed in the TextInput. When
+ echoMode is set to TextInput::Normal this will be exactly
+ the same as the TextInput::text property. When echoMode
+ is set to something else, this property will contain the text
+ the user sees, while the text property will contain the
+ entered text.
+*/
+QString QDeclarativeTextInput::displayText() const
+{
+ Q_D(const QDeclarativeTextInput);
+ return d->control->displayText();
+}
+
+/*
+ \qmlmethod void moveCursorSelection(int pos)
+
+ This method allows you to move the cursor while modifying the selection accordingly.
+ To simply move the cursor, set the cursorPosition property.
+
+ When this method is called it additionally sets either the
+ selectionStart or the selectionEnd (whichever was at the previous cursor position)
+ to the specified position. This allows you to easily extend and contract the selected
+ text range.
+
+ Example: The sequence of calls
+ cursorPosition = 5
+ moveCursorSelection(9)
+ moveCursorSelection(7)
+ would move the cursor to position 5, extend the selection end from 5 to 9
+ and then retract the selection end from 9 to 7, leaving the text from position 5 to 7
+ selected (the 6th and 7th characters).
+*/
+void QDeclarativeTextInput::moveCursorSelection(int pos)
+{
+ Q_D(QDeclarativeTextInput);
+ d->control->moveCursor(pos, true);
+}
+
void QDeclarativeTextInputPrivate::init()
{
Q_Q(QDeclarativeTextInput);
@@ -824,6 +1067,8 @@ void QDeclarativeTextInputPrivate::init()
q->connect(control, SIGNAL(selectionChanged()),
q, SLOT(selectionChanged()));
q->connect(control, SIGNAL(textChanged(const QString &)),
+ q, SIGNAL(displayTextChanged(const QString &)));
+ q->connect(control, SIGNAL(textChanged(const QString &)),
q, SLOT(q_textChanged()));
q->connect(control, SIGNAL(accepted()),
q, SIGNAL(accepted()));
@@ -892,10 +1137,11 @@ void QDeclarativeTextInput::q_textChanged()
void QDeclarativeTextInput::updateRect(const QRect &r)
{
+ Q_D(QDeclarativeTextInput);
if(r == QRect())
clearCache();
else
- dirtyCache(r);
+ dirtyCache(QRect(r.x() - d->hscroll, r.y(), r.width(), r.height()));
update();
}
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p.h
index 64aff7d..c0c1e50 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextinput_p.h
@@ -86,6 +86,9 @@ class Q_DECLARATIVE_EXPORT QDeclarativeTextInput : public QDeclarativePaintedIte
Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged)
Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode NOTIFY echoModeChanged)
Q_PROPERTY(bool focusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY focusOnPressChanged)
+ Q_PROPERTY(QString passwordCharacter READ passwordCharacter WRITE setPasswordCharacter NOTIFY passwordCharacterChanged)
+ Q_PROPERTY(QString displayText READ displayText NOTIFY displayTextChanged)
+ Q_PROPERTY(bool autoScroll READ autoScroll WRITE setAutoScroll NOTIFY autoScrollChanged)
public:
QDeclarativeTextInput(QDeclarativeItem* parent=0);
@@ -104,9 +107,9 @@ public:
AlignHCenter = Qt::AlignHCenter
};
- //### Should we have this function, x based properties,
- //### or copy TextEdit with x instead of QTextCursor?
- Q_INVOKABLE int xToPos(int x);
+ //Auxilliary functions needed to control the TextInput from QML
+ Q_INVOKABLE int xToPosition(int x);
+ Q_INVOKABLE void moveCursorSelection(int pos);
QString text() const;
void setText(const QString &);
@@ -157,12 +160,20 @@ public:
EchoMode echoMode() const;
void setEchoMode(EchoMode echo);
+ QString passwordCharacter() const;
+ void setPasswordCharacter(const QString &str);
+
+ QString displayText() const;
+
QDeclarativeComponent* cursorDelegate() const;
void setCursorDelegate(QDeclarativeComponent*);
bool focusOnPress() const;
void setFocusOnPress(bool);
+ bool autoScroll() const;
+ void setAutoScroll(bool);
+
bool hasAcceptableInput() const;
void drawContents(QPainter *p,const QRect &r);
@@ -188,13 +199,17 @@ Q_SIGNALS:
void validatorChanged();
void inputMaskChanged(const QString &inputMask);
void echoModeChanged(EchoMode echoMode);
+ void passwordCharacterChanged();
+ void displayTextChanged(const QString &text);
void focusOnPressChanged(bool focusOnPress);
+ void autoScrollChanged(bool autoScroll);
protected:
virtual void geometryChanged(const QRectF &newGeometry,
const QRectF &oldGeometry);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
+ void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void keyPressEvent(QKeyEvent* ev);
bool event(QEvent *e);
@@ -220,10 +235,8 @@ QT_END_NAMESPACE
QML_DECLARE_TYPE(QDeclarativeTextInput)
QML_DECLARE_TYPE(QValidator)
QML_DECLARE_TYPE(QIntValidator)
-#if (QT_VERSION >= QT_VERSION_CHECK(4,7,0))
QML_DECLARE_TYPE(QDoubleValidator)
QML_DECLARE_TYPE(QRegExpValidator)
-#endif
QT_END_HEADER
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
index 9e44b15..26cf78c 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
@@ -72,7 +72,7 @@ public:
color((QRgb)0), style(QDeclarativeText::Normal),
styleColor((QRgb)0), hAlign(QDeclarativeTextInput::AlignLeft),
hscroll(0), oldScroll(0), focused(false), focusOnPress(true),
- cursorVisible(false)
+ cursorVisible(false), autoScroll(true)
{
}
@@ -81,6 +81,14 @@ public:
delete control;
}
+ int xToPos(int x, QTextLine::CursorPosition betweenOrOn = QTextLine::CursorBetweenCharacters) const
+ {
+ Q_Q(const QDeclarativeTextInput);
+ QRect cr = q->boundingRect().toRect();
+ x-= cr.x() - hscroll;
+ return control->xToPos(x, betweenOrOn);
+ }
+
void init();
void startCreatingCursor();
void focusChanged(bool hasFocus);
@@ -107,6 +115,7 @@ public:
bool focused;
bool focusOnPress;
bool cursorVisible;
+ bool autoScroll;
};
QT_END_NAMESPACE
diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
index 2938f51..dc325ce 100644
--- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
+++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
@@ -830,7 +830,7 @@ void QDeclarativeVisualDataModel::setDelegate(QDeclarativeComponent *delegate)
\code
// view.qml
- import Qt 4.6
+ import Qt 4.7
ListView {
width: 200
@@ -1127,20 +1127,21 @@ void QDeclarativeVisualDataModel::_q_itemsChanged(int index, int count,
const QList<int> &roles)
{
Q_D(QDeclarativeVisualDataModel);
- // XXX - highly inefficient
- for (int ii = index; ii < index + count; ++ii) {
-
- if (QObject *item = d->m_cache.item(ii)) {
- QDeclarativeVisualDataModelData *data = d->data(item);
+ for (QHash<int,QDeclarativeVisualDataModelPrivate::ObjectRef>::ConstIterator iter = d->m_cache.begin();
+ iter != d->m_cache.end(); ++iter) {
+ const int idx = iter.key();
+ if (idx >= index && idx < index+count) {
+ QDeclarativeVisualDataModelPrivate::ObjectRef objRef = *iter;
+ QDeclarativeVisualDataModelData *data = d->data(objRef.obj);
for (int roleIdx = 0; roleIdx < roles.count(); ++roleIdx) {
int role = roles.at(roleIdx);
int propId = data->propForRole(role);
if (propId != -1) {
if (d->m_listModelInterface) {
- data->setValue(propId, d->m_listModelInterface->data(ii, QList<int>() << role).value(role));
+ data->setValue(propId, d->m_listModelInterface->data(idx, QList<int>() << role).value(role));
} else if (d->m_abstractItemModel) {
- QModelIndex index = d->m_abstractItemModel->index(ii, 0, d->m_root);
+ QModelIndex index = d->m_abstractItemModel->index(idx, 0, d->m_root);
data->setValue(propId, d->m_abstractItemModel->data(index, role));
}
}
@@ -1152,6 +1153,8 @@ void QDeclarativeVisualDataModel::_q_itemsChanged(int index, int count,
void QDeclarativeVisualDataModel::_q_itemsInserted(int index, int count)
{
Q_D(QDeclarativeVisualDataModel);
+ if (!count)
+ return;
// XXX - highly inefficient
QHash<int,QDeclarativeVisualDataModelPrivate::ObjectRef> items;
for (QHash<int,QDeclarativeVisualDataModelPrivate::ObjectRef>::Iterator iter = d->m_cache.begin();
@@ -1179,6 +1182,8 @@ void QDeclarativeVisualDataModel::_q_itemsInserted(int index, int count)
void QDeclarativeVisualDataModel::_q_itemsRemoved(int index, int count)
{
Q_D(QDeclarativeVisualDataModel);
+ if (!count)
+ return;
// XXX - highly inefficient
QHash<int, QDeclarativeVisualDataModelPrivate::ObjectRef> items;
for (QHash<int, QDeclarativeVisualDataModelPrivate::ObjectRef>::Iterator iter = d->m_cache.begin();