summaryrefslogtreecommitdiffstats
path: root/src/declarative/graphicsitems
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/graphicsitems')
-rw-r--r--src/declarative/graphicsitems/graphicsitems.pri2
-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/qdeclarativegraphicsobjectcontainer.cpp269
-rw-r--r--src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer_p.h89
-rw-r--r--src/declarative/graphicsitems/qdeclarativegridview.cpp72
-rw-r--r--src/declarative/graphicsitems/qdeclarativegridview_p.h5
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimagebase_p.h2
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp9
-rw-r--r--src/declarative/graphicsitems/qdeclarativelistview.cpp87
-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.cpp29
-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/qdeclarativerepeater.cpp19
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext.cpp74
-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.cpp56
-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.cpp101
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput_p.h8
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput_p_p.h11
-rw-r--r--src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp6
29 files changed, 463 insertions, 498 deletions
diff --git a/src/declarative/graphicsitems/graphicsitems.pri b/src/declarative/graphicsitems/graphicsitems.pri
index af76a67..eab41e3 100644
--- a/src/declarative/graphicsitems/graphicsitems.pri
+++ b/src/declarative/graphicsitems/graphicsitems.pri
@@ -48,7 +48,6 @@ 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
@@ -82,5 +81,4 @@ SOURCES += \
$$PWD/qdeclarativetextedit.cpp \
$$PWD/qdeclarativevisualitemmodel.cpp \
$$PWD/qdeclarativelistview.cpp \
- $$PWD/qdeclarativegraphicsobjectcontainer.cpp \
$$PWD/qdeclarativelayoutitem.cpp
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/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/qdeclarativegraphicsobjectcontainer_p.h b/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer_p.h
deleted file mode 100644
index 20c5bcf..0000000
--- a/src/declarative/graphicsitems/qdeclarativegraphicsobjectcontainer_p.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtDeclarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QDECLARATIVEGRAPHICSOBJECTCONTAINER_H
-#define QDECLARATIVEGRAPHICSOBJECTCONTAINER_H
-
-#include "qdeclarativeitem.h"
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-class QGraphicsObject;
-class QDeclarativeGraphicsObjectContainerPrivate;
-
-class Q_DECLARATIVE_EXPORT QDeclarativeGraphicsObjectContainer : public QDeclarativeItem
-{
- Q_OBJECT
-
- Q_CLASSINFO("DefaultProperty", "graphicsObject")
- Q_PROPERTY(QGraphicsObject *graphicsObject READ graphicsObject WRITE setGraphicsObject)
- Q_PROPERTY(bool synchronizedResizing READ synchronizedResizing WRITE setSynchronizedResizing)
-
-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)
-};
-
-QT_END_NAMESPACE
-
-QML_DECLARE_TYPE(QDeclarativeGraphicsObjectContainer)
-
-QT_END_HEADER
-
-#endif // QDECLARATIVEGRAPHICSOBJECTCONTAINER_H
diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp
index 8247f17..9be025a 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();
@@ -662,10 +671,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;
@@ -1197,6 +1206,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 +1821,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 +1901,7 @@ void QDeclarativeGridView::itemsInserted(int modelIndex, int count)
} else if (d->currentIndex < 0) {
d->updateCurrent(0);
}
+ d->itemCount += count;
emit countChanged();
return;
}
@@ -1889,6 +1932,7 @@ void QDeclarativeGridView::itemsInserted(int modelIndex, int count)
emit currentIndexChanged();
}
d->scheduleLayout();
+ d->itemCount += count;
emit countChanged();
return;
}
@@ -1976,6 +2020,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 +2029,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 +2078,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 +2094,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 +2166,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/qdeclarativeitemsmodule.cpp b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp
index 7989a27..8e5b863 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"
@@ -96,13 +95,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");
@@ -116,10 +112,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");
@@ -151,4 +145,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..b4506ef 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;
@@ -828,10 +838,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;
@@ -1860,13 +1872,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 +1905,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 +1939,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 +2366,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 +2455,7 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count)
} else if (d->currentIndex < 0) {
d->updateCurrent(0);
}
+ d->itemCount += count;
emit countChanged();
return;
}
@@ -2432,6 +2487,7 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count)
emit currentIndexChanged();
}
d->scheduleLayout();
+ d->itemCount += count;
emit countChanged();
return;
}
@@ -2524,6 +2580,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 +2591,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 +2644,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 +2661,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..5fcac49 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.
@@ -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/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..69e3543 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.
@@ -319,37 +320,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 +398,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,7 +456,7 @@ 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.
@@ -471,7 +490,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 +557,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 +639,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 +653,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..25d7e2a 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>
@@ -170,12 +171,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 +361,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);
}
/*!
@@ -1020,11 +1042,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..1b8b84b 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
@@ -429,6 +429,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 +472,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
@@ -645,6 +668,8 @@ void QDeclarativeTextInputPrivate::focusChanged(bool hasFocus)
Q_Q(QDeclarativeTextInput);
focused = hasFocus;
q->setCursorVisible(hasFocus);
+ if (!hasFocus)
+ control->deselect();
QDeclarativeItemPrivate::focusChanged(hasFocus);
}
@@ -679,7 +704,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 +737,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 +767,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();
}
@@ -892,10 +954,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..9a3fa75 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextinput_p.h
@@ -86,6 +86,7 @@ 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(bool autoScroll READ autoScroll WRITE setAutoScroll NOTIFY autoScrollChanged)
public:
QDeclarativeTextInput(QDeclarativeItem* parent=0);
@@ -163,6 +164,9 @@ public:
bool focusOnPress() const;
void setFocusOnPress(bool);
+ bool autoScroll() const;
+ void setAutoScroll(bool);
+
bool hasAcceptableInput() const;
void drawContents(QPainter *p,const QRect &r);
@@ -189,12 +193,14 @@ Q_SIGNALS:
void inputMaskChanged(const QString &inputMask);
void echoModeChanged(EchoMode echoMode);
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 +226,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..15348ed 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
@@ -1152,6 +1152,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 +1181,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();