summaryrefslogtreecommitdiffstats
path: root/src/declarative/graphicsitems
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/graphicsitems')
-rw-r--r--src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp22
-rw-r--r--src/declarative/graphicsitems/qdeclarativeanimatedimage_p.h1
-rw-r--r--src/declarative/graphicsitems/qdeclarativeflickable.cpp55
-rw-r--r--src/declarative/graphicsitems/qdeclarativeflickable_p.h1
-rw-r--r--src/declarative/graphicsitems/qdeclarativeflickable_p_p.h1
-rw-r--r--src/declarative/graphicsitems/qdeclarativegridview.cpp62
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp1
-rw-r--r--src/declarative/graphicsitems/qdeclarativelistview.cpp38
-rw-r--r--src/declarative/graphicsitems/qdeclarativemousearea.cpp40
-rw-r--r--src/declarative/graphicsitems/qdeclarativemousearea_p.h5
-rw-r--r--src/declarative/graphicsitems/qdeclarativemousearea_p_p.h3
-rw-r--r--src/declarative/graphicsitems/qdeclarativepathview.cpp46
-rw-r--r--src/declarative/graphicsitems/qdeclarativerepeater.cpp2
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext.cpp12
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext_p.h2
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextedit.cpp39
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput.cpp89
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput_p.h1
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput_p_p.h2
19 files changed, 310 insertions, 112 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp b/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp
index 27bb6a2..016b87d 100644
--- a/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp
@@ -221,13 +221,22 @@ void QDeclarativeAnimatedImage::setSource(const QUrl &url)
}
d->url = url;
+ emit sourceChanged(d->url);
- if (url.isEmpty()) {
+ if (isComponentComplete())
+ load();
+}
+
+void QDeclarativeAnimatedImage::load()
+{
+ Q_D(QDeclarativeAnimatedImage);
+
+ if (d->url.isEmpty()) {
delete d->_movie;
d->status = Null;
} else {
#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML
- QString lf = QDeclarativeEnginePrivate::urlToLocalFileOrQrc(url);
+ QString lf = QDeclarativeEnginePrivate::urlToLocalFileOrQrc(d->url);
if (!lf.isEmpty()) {
//### should be unified with movieRequestFinished
d->_movie = new QMovie(lf);
@@ -235,6 +244,8 @@ void QDeclarativeAnimatedImage::setSource(const QUrl &url)
qmlInfo(this) << "Error Reading Animated Image File " << d->url.toString();
delete d->_movie;
d->_movie = 0;
+ d->status = Error;
+ emit statusChanged(d->status);
return;
}
connect(d->_movie, SIGNAL(stateChanged(QMovie::MovieState)),
@@ -264,7 +275,6 @@ void QDeclarativeAnimatedImage::setSource(const QUrl &url)
QObject::connect(d->reply, SIGNAL(finished()),
this, SLOT(movieRequestFinished()));
}
-
emit statusChanged(d->status);
}
@@ -294,6 +304,8 @@ void QDeclarativeAnimatedImage::movieRequestFinished()
#endif
delete d->_movie;
d->_movie = 0;
+ d->status = Error;
+ emit statusChanged(d->status);
return;
}
connect(d->_movie, SIGNAL(stateChanged(QMovie::MovieState)),
@@ -310,6 +322,8 @@ void QDeclarativeAnimatedImage::movieRequestFinished()
if(d->paused)
d->_movie->setPaused(true);
d->setPixmap(d->_movie->currentPixmap());
+ d->status = Ready;
+ emit statusChanged(d->status);
}
void QDeclarativeAnimatedImage::movieUpdate()
@@ -336,6 +350,8 @@ void QDeclarativeAnimatedImage::componentComplete()
{
Q_D(QDeclarativeAnimatedImage);
QDeclarativeItem::componentComplete(); // NOT QDeclarativeImage
+ if (d->url.isValid())
+ load();
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 e5025bf..e2ed70b 100644
--- a/src/declarative/graphicsitems/qdeclarativeanimatedimage_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeanimatedimage_p.h
@@ -97,6 +97,7 @@ private Q_SLOTS:
void playingStatusChanged();
protected:
+ virtual void load();
void componentComplete();
private:
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
index 11a0477..55b05b9 100644
--- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
@@ -53,6 +53,10 @@ QT_BEGIN_NAMESPACE
// before we perform a flick.
static const int FlickThreshold = 20;
+// RetainGrabVelocity is the maxmimum instantaneous velocity that
+// will ensure the Flickable retains the grab on consecutive flicks.
+static const int RetainGrabVelocity = 15;
+
QDeclarativeFlickableVisibleArea::QDeclarativeFlickableVisibleArea(QDeclarativeFlickable *parent)
: QObject(parent), flickable(parent), m_xPosition(0.), m_widthRatio(0.)
, m_yPosition(0.), m_heightRatio(0.)
@@ -672,7 +676,8 @@ void QDeclarativeFlickable::setFlickableDirection(FlickableDirection direction)
void QDeclarativeFlickablePrivate::handleMousePressEvent(QGraphicsSceneMouseEvent *event)
{
Q_Q(QDeclarativeFlickable);
- if (interactive && timeline.isActive() && (qAbs(hData.velocity) > 10 || qAbs(vData.velocity) > 10))
+ if (interactive && timeline.isActive()
+ && (qAbs(hData.smoothVelocity.value()) > RetainGrabVelocity || qAbs(vData.smoothVelocity.value()) > RetainGrabVelocity))
stealMouse = true; // If we've been flicked then steal the click.
else
stealMouse = false;
@@ -840,7 +845,8 @@ void QDeclarativeFlickable::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QDeclarativeFlickable);
if (d->interactive) {
- d->handleMousePressEvent(event);
+ if (!d->pressed)
+ d->handleMousePressEvent(event);
event->accept();
} else {
QDeclarativeItem::mousePressEvent(event);
@@ -905,11 +911,27 @@ void QDeclarativeFlickable::wheelEvent(QGraphicsSceneWheelEvent *event)
}
}
+bool QDeclarativeFlickablePrivate::isOutermostPressDelay() const
+{
+ Q_Q(const QDeclarativeFlickable);
+ QDeclarativeItem *item = q->parentItem();
+ while (item) {
+ QDeclarativeFlickable *flick = qobject_cast<QDeclarativeFlickable*>(item);
+ if (flick && flick->pressDelay() > 0 && flick->isInteractive())
+ return false;
+ item = item->parentItem();
+ }
+
+ return true;
+}
+
void QDeclarativeFlickablePrivate::captureDelayedPress(QGraphicsSceneMouseEvent *event)
{
Q_Q(QDeclarativeFlickable);
if (!q->scene() || pressDelay <= 0)
return;
+ if (!isOutermostPressDelay())
+ return;
delayedPressTarget = q->scene()->mouseGrabberItem();
delayedPressEvent = new QGraphicsSceneMouseEvent(event->type());
delayedPressEvent->setAccepted(false);
@@ -965,9 +987,10 @@ void QDeclarativeFlickable::timerEvent(QTimerEvent *event)
if (scene()->mouseGrabberItem() == d->delayedPressTarget)
d->delayedPressTarget->ungrabMouse();
//Use the event handler that will take care of finding the proper item to propagate the event
- QApplication::sendEvent(scene(), d->delayedPressEvent);
+ QApplication::postEvent(scene(), d->delayedPressEvent);
+ } else {
+ delete d->delayedPressEvent;
}
- delete d->delayedPressEvent;
d->delayedPressEvent = 0;
}
}
@@ -1359,6 +1382,22 @@ bool QDeclarativeFlickable::yflick() const
return d->flickableDirection & QDeclarativeFlickable::VerticalFlick;
}
+bool QDeclarativeFlickable::sceneEvent(QEvent *event)
+{
+ bool rv = QDeclarativeItem::sceneEvent(event);
+ if (event->type() == QEvent::UngrabMouse) {
+ Q_D(QDeclarativeFlickable);
+ if (d->pressed) {
+ // if our mouse grab has been removed (probably by another Flickable),
+ // fix our state
+ d->pressed = false;
+ d->stealMouse = false;
+ setKeepMouseGrab(false);
+ }
+ }
+ return rv;
+}
+
bool QDeclarativeFlickable::sendMouseEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QDeclarativeFlickable);
@@ -1386,7 +1425,7 @@ bool QDeclarativeFlickable::sendMouseEvent(QGraphicsSceneMouseEvent *event)
d->handleMouseMoveEvent(&mouseEvent);
break;
case QEvent::GraphicsSceneMousePress:
- if (d->delayedPressEvent)
+ if (d->pressed) // we are already pressed - this is a delayed replay
return false;
d->handleMousePressEvent(&mouseEvent);
@@ -1405,6 +1444,8 @@ bool QDeclarativeFlickable::sendMouseEvent(QGraphicsSceneMouseEvent *event)
// We send the release
scene()->sendEvent(s->mouseGrabberItem(), event);
// And the event has been consumed
+ d->stealMouse = false;
+ d->pressed = false;
return true;
}
d->handleMouseReleaseEvent(&mouseEvent);
@@ -1427,6 +1468,7 @@ bool QDeclarativeFlickable::sendMouseEvent(QGraphicsSceneMouseEvent *event)
d->stealMouse = false;
d->pressed = false;
}
+
return false;
}
@@ -1525,6 +1567,9 @@ bool QDeclarativeFlickable::isFlickingVertically() const
If the flickable is dragged/flicked before the delay times out
the press event will not be delivered. If the button is released
within the timeout, both the press and release will be delivered.
+
+ Note that for nested Flickables with pressDelay set, the pressDelay of
+ inner Flickables is overridden by the outermost Flickable.
*/
int QDeclarativeFlickable::pressDelay() const
{
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p.h
index 4fde1d5..a14cc1c 100644
--- a/src/declarative/graphicsitems/qdeclarativeflickable_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeflickable_p.h
@@ -204,6 +204,7 @@ protected:
virtual void viewportMoved();
virtual void geometryChanged(const QRectF &newGeometry,
const QRectF &oldGeometry);
+ bool sceneEvent(QEvent *event);
bool sendMouseEvent(QGraphicsSceneMouseEvent *event);
bool xflick() const;
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h
index 5ad6ff6..1b6081c 100644
--- a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h
@@ -118,6 +118,7 @@ public:
void updateBeginningEnd();
+ bool isOutermostPressDelay() const;
void captureDelayedPress(QGraphicsSceneMouseEvent *event);
void clearDelayedPress();
diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp
index 0601b6f..80e853d 100644
--- a/src/declarative/graphicsitems/qdeclarativegridview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp
@@ -331,8 +331,10 @@ public:
}
}
} else if ((header && header->item == item) || (footer && footer->item == item)) {
- updateHeader();
- updateFooter();
+ if (header)
+ updateHeader();
+ if (footer)
+ updateFooter();
}
}
@@ -2388,24 +2390,9 @@ void QDeclarativeGridView::itemsInserted(int modelIndex, int count)
Q_D(QDeclarativeGridView);
if (!isComponentComplete())
return;
- if (!d->visibleItems.count() || d->model->count() <= 1) {
- d->scheduleLayout();
- if (d->itemCount && d->currentIndex >= modelIndex) {
- // adjust current item index
- d->currentIndex += count;
- if (d->currentItem)
- d->currentItem->index = d->currentIndex;
- emit currentIndexChanged();
- } else if (!d->currentIndex || (d->currentIndex < 0 && !d->currentIndexCleared)) {
- d->updateCurrent(0);
- }
- d->itemCount += count;
- emit countChanged();
- return;
- }
- int index = d->mapFromModel(modelIndex);
- if (index == -1) {
+ int index = d->visibleItems.count() ? d->mapFromModel(modelIndex) : 0;
+ if (index < 0) {
int i = d->visibleItems.count() - 1;
while (i > 0 && d->visibleItems.at(i)->index == -1)
--i;
@@ -2436,28 +2423,35 @@ void QDeclarativeGridView::itemsInserted(int modelIndex, int count)
}
}
- // At least some of the added items will be visible
int insertCount = count;
- if (index < d->visibleIndex) {
+ if (index < d->visibleIndex && d->visibleItems.count()) {
insertCount -= d->visibleIndex - index;
index = d->visibleIndex;
modelIndex = d->visibleIndex;
}
- index -= d->visibleIndex;
int to = d->buffer+d->position()+d->size()-1;
- int colPos, rowPos;
- if (index < d->visibleItems.count()) {
- colPos = d->visibleItems.at(index)->colPos();
- rowPos = d->visibleItems.at(index)->rowPos();
- } else {
- // appending items to visible list
- colPos = d->visibleItems.at(index-1)->colPos() + d->colSize();
- rowPos = d->visibleItems.at(index-1)->rowPos();
- if (colPos > d->colSize() * (d->columns-1)) {
- colPos = 0;
- rowPos += d->rowSize();
+ int colPos = 0;
+ int rowPos = 0;
+ if (d->visibleItems.count()) {
+ index -= d->visibleIndex;
+ if (index < d->visibleItems.count()) {
+ colPos = d->visibleItems.at(index)->colPos();
+ rowPos = d->visibleItems.at(index)->rowPos();
+ } else {
+ // appending items to visible list
+ colPos = d->visibleItems.at(index-1)->colPos() + d->colSize();
+ rowPos = d->visibleItems.at(index-1)->rowPos();
+ if (colPos > d->colSize() * (d->columns-1)) {
+ colPos = 0;
+ rowPos += d->rowSize();
+ }
}
+ } else if (d->itemCount == 0 && d->header) {
+ if (d->flow == QDeclarativeGridView::LeftToRight)
+ rowPos = d->headerSize();
+ else
+ colPos = d->headerSize();
}
// Update the indexes of the following visible items.
@@ -2510,6 +2504,8 @@ void QDeclarativeGridView::itemsInserted(int modelIndex, int count)
if (d->currentItem) {
d->currentItem->index = d->currentIndex;
d->currentItem->setPosition(d->colPosAt(d->currentIndex), d->rowPosAt(d->currentIndex));
+ } else if (!d->currentIndex || (d->currentIndex < 0 && !d->currentIndexCleared)) {
+ d->updateCurrent(0);
}
emit currentIndexChanged();
}
diff --git a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp
index bc4a2d0..3c8f64e 100644
--- a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp
@@ -180,6 +180,7 @@ void QDeclarativeItemModule::defineModule()
qmlRegisterType<QDeclarativePinch>("QtQuick",1,1,"Pinch");
qmlRegisterType<QDeclarativePinchEvent>();
qmlRegisterType<QDeclarativeItem,1>("QtQuick",1,1,"Item");
+ qmlRegisterType<QDeclarativeMouseArea,1>("QtQuick",1,1,"MouseArea");
qmlRegisterType<QDeclarativeFlickable,1>("QtQuick",1,1,"Flickable");
qmlRegisterType<QDeclarativeListView,1>("QtQuick",1,1,"ListView");
qmlRegisterType<QDeclarativeGridView,1>("QtQuick",1,1,"GridView");
diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp
index 075c3af..a60a4aa 100644
--- a/src/declarative/graphicsitems/qdeclarativelistview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp
@@ -413,8 +413,10 @@ public:
}
}
if ((header && header->item == item) || (footer && footer->item == item)) {
- updateHeader();
- updateFooter();
+ if (header)
+ updateHeader();
+ if (footer)
+ updateFooter();
}
if (currentItem && currentItem->item == item)
updateHighlight();
@@ -936,6 +938,9 @@ void QDeclarativeListViewPrivate::createSection(FxListItem *listItem)
}
}
listItem->setPosition(pos);
+ } else {
+ QDeclarativeContext *context = QDeclarativeEngine::contextForObject(listItem->section)->parentContext();
+ context->setContextProperty(QLatin1String("section"), listItem->attached->m_section);
}
} else if (listItem->section) {
qreal pos = listItem->position();
@@ -2848,23 +2853,8 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count)
return;
d->updateUnrequestedIndexes();
d->moveReason = QDeclarativeListViewPrivate::Other;
- if (!d->visibleItems.count() || d->model->count() <= 1) {
- d->scheduleLayout();
- if (d->itemCount && d->currentIndex >= modelIndex) {
- // adjust current item index
- d->currentIndex += count;
- if (d->currentItem)
- d->currentItem->index = d->currentIndex;
- emit currentIndexChanged();
- } else if (!d->currentIndex || (d->currentIndex < 0 && !d->currentIndexCleared)) {
- d->updateCurrent(0);
- }
- d->itemCount += count;
- emit countChanged();
- return;
- }
- int index = d->mapFromModel(modelIndex);
+ int index = d->visibleItems.count() ? d->mapFromModel(modelIndex) : 0;
if (index < 0) {
int i = d->visibleItems.count() - 1;
while (i > 0 && d->visibleItems.at(i)->index == -1)
@@ -2900,11 +2890,15 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count)
}
}
- // At least some of the added items will be visible
-
// index can be the next item past the end of the visible items list (i.e. appended)
- int pos = index < d->visibleItems.count() ? d->visibleItems.at(index)->position()
+ int pos = 0;
+ if (d->visibleItems.count()) {
+ pos = index < d->visibleItems.count() ? d->visibleItems.at(index)->position()
: d->visibleItems.last()->endPosition()+d->spacing+1;
+ } else if (d->itemCount == 0 && d->header) {
+ pos = d->header->size();
+ }
+
int initialPos = pos;
int diff = 0;
QList<FxListItem*> added;
@@ -2971,6 +2965,8 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count)
if (d->currentItem) {
d->currentItem->index = d->currentIndex;
d->currentItem->setPosition(d->currentItem->position() + diff);
+ } else if (!d->currentIndex || (d->currentIndex < 0 && !d->currentIndexCleared)) {
+ d->updateCurrent(0);
}
emit currentIndexChanged();
}
diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp
index 59c1f15..bf6bfd6 100644
--- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp
+++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp
@@ -314,6 +314,8 @@ QDeclarativeMouseAreaPrivate::~QDeclarativeMouseAreaPrivate()
position of the release of the click, and whether the click was held.
The \e accepted property of the MouseEvent parameter is ignored in this handler.
+
+ \sa onCanceled()
*/
/*!
@@ -414,6 +416,40 @@ void QDeclarativeMouseArea::setEnabled(bool a)
emit enabledChanged();
}
}
+
+/*!
+ \qmlproperty bool MouseArea::preventStealing
+ \since Quick 1.1
+ This property holds whether the mouse events may be stolen from this
+ MouseArea.
+
+ If a MouseArea is placed within an item that filters child mouse
+ events, such as Flickable, the mouse
+ events may be stolen from the MouseArea if a gesture is recognized
+ by the parent element, e.g. a flick gesture. If preventStealing is
+ set to true, no element will steal the mouse events.
+
+ Note that setting preventStealing to true once an element has started
+ stealing events will have no effect until the next press event.
+
+ By default this property is false.
+*/
+bool QDeclarativeMouseArea::preventStealing() const
+{
+ Q_D(const QDeclarativeMouseArea);
+ return d->preventStealing;
+}
+
+void QDeclarativeMouseArea::setPreventStealing(bool prevent)
+{
+ Q_D(QDeclarativeMouseArea);
+ if (prevent != d->preventStealing) {
+ d->preventStealing = prevent;
+ setKeepMouseGrab(d->preventStealing && d->absorb);
+ emit preventStealingChanged();
+ }
+}
+
/*!
\qmlproperty MouseButtons MouseArea::pressedButtons
This property holds the mouse buttons currently pressed.
@@ -441,7 +477,7 @@ void QDeclarativeMouseArea::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QDeclarativeMouseArea);
d->moved = false;
- d->stealMouse = false;
+ d->stealMouse = d->preventStealing;
if (!d->absorb)
QDeclarativeItem::mousePressEvent(event);
else {
@@ -458,7 +494,7 @@ void QDeclarativeMouseArea::mousePressEvent(QGraphicsSceneMouseEvent *event)
// we should only start timer if pressAndHold is connected to.
if (d->isPressAndHoldConnected())
d->pressAndHoldTimer.start(PressAndHoldDelay, this);
- setKeepMouseGrab(false);
+ setKeepMouseGrab(d->stealMouse);
event->setAccepted(setPressed(true));
}
}
diff --git a/src/declarative/graphicsitems/qdeclarativemousearea_p.h b/src/declarative/graphicsitems/qdeclarativemousearea_p.h
index 937ac78..985f27e 100644
--- a/src/declarative/graphicsitems/qdeclarativemousearea_p.h
+++ b/src/declarative/graphicsitems/qdeclarativemousearea_p.h
@@ -129,6 +129,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeMouseArea : public QDeclarativeItem
Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged)
Q_PROPERTY(bool hoverEnabled READ hoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged)
Q_PROPERTY(QDeclarativeDrag *drag READ drag CONSTANT) //### add flicking to QDeclarativeDrag or add a QDeclarativeFlick ???
+ Q_PROPERTY(bool preventStealing READ preventStealing WRITE setPreventStealing NOTIFY preventStealingChanged REVISION 1)
public:
QDeclarativeMouseArea(QDeclarativeItem *parent=0);
@@ -153,6 +154,9 @@ public:
QDeclarativeDrag *drag();
+ bool preventStealing() const;
+ void setPreventStealing(bool prevent);
+
Q_SIGNALS:
void hoveredChanged();
void pressedChanged();
@@ -161,6 +165,7 @@ Q_SIGNALS:
void hoverEnabledChanged();
void positionChanged(QDeclarativeMouseEvent *mouse);
void mousePositionChanged(QDeclarativeMouseEvent *mouse);
+ Q_REVISION(1) void preventStealingChanged();
void pressed(QDeclarativeMouseEvent *mouse);
void pressAndHold(QDeclarativeMouseEvent *mouse);
diff --git a/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h b/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h
index 2a327af..67694fb 100644
--- a/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h
@@ -68,7 +68,7 @@ class QDeclarativeMouseAreaPrivate : public QDeclarativeItemPrivate
public:
QDeclarativeMouseAreaPrivate()
: absorb(true), hovered(false), pressed(false), longPress(false),
- moved(false), stealMouse(false), doubleClick(false), drag(0)
+ moved(false), stealMouse(false), doubleClick(false), preventStealing(false), drag(0)
{
}
@@ -110,6 +110,7 @@ public:
bool dragY : 1;
bool stealMouse : 1;
bool doubleClick : 1;
+ bool preventStealing : 1;
QDeclarativeDrag *drag;
QPointF startScene;
qreal startX;
diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp
index 306575e..4e401e9 100644
--- a/src/declarative/graphicsitems/qdeclarativepathview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp
@@ -1152,7 +1152,7 @@ void QDeclarativePathViewPrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent
moveReason = QDeclarativePathViewPrivate::Mouse;
qreal diff = (newPc - startPc)*modelCount*mappedRange;
if (diff) {
- setOffset(offset + diff);
+ q->setOffset(offset + diff);
if (diff > modelCount/2)
diff -= modelCount;
@@ -1455,17 +1455,18 @@ void QDeclarativePathView::itemsInserted(int modelIndex, int count)
if (!d->isValid() || !isComponentComplete())
return;
- d->itemCache += d->items;
- d->items.clear();
- if (modelIndex <= d->currentIndex) {
- d->currentIndex += count;
- emit currentIndexChanged();
- } else if (d->offset != 0) {
- d->offset += count;
- d->offsetAdj += count;
+ if (d->modelCount) {
+ d->itemCache += d->items;
+ d->items.clear();
+ if (modelIndex <= d->currentIndex) {
+ d->currentIndex += count;
+ emit currentIndexChanged();
+ } else if (d->offset != 0) {
+ d->offset += count;
+ d->offsetAdj += count;
+ }
}
-
- d->modelCount = d->model->count();
+ d->modelCount += count;
if (d->flicking || d->moving) {
d->regenerate();
d->updateCurrent();
@@ -1502,18 +1503,29 @@ void QDeclarativePathView::itemsRemoved(int modelIndex, int count)
d->itemCache += d->items;
d->items.clear();
+ bool changedOffset = false;
if (modelIndex > d->currentIndex) {
if (d->offset >= count) {
+ changedOffset = true;
d->offset -= count;
d->offsetAdj -= count;
}
}
- d->modelCount = d->model->count();
- d->regenerate();
- d->updateCurrent();
- if (!d->modelCount)
+ d->modelCount -= count;
+ if (!d->modelCount) {
+ while (d->itemCache.count())
+ d->releaseItem(d->itemCache.takeLast());
+ d->offset = 0;
+ changedOffset = true;
+ d->tl.reset(d->moveOffset);
update();
+ } else {
+ d->regenerate();
+ d->updateCurrent();
+ }
+ if (changedOffset)
+ emit offsetChanged();
if (currentChanged)
emit currentIndexChanged();
emit countChanged();
@@ -1601,7 +1613,7 @@ void QDeclarativePathView::movementEnding()
int QDeclarativePathViewPrivate::calcCurrentIndex()
{
int current = -1;
- if (model && items.count()) {
+ if (modelCount && model && items.count()) {
offset = qmlMod(offset, modelCount);
if (offset < 0)
offset += modelCount;
@@ -1617,7 +1629,7 @@ void QDeclarativePathViewPrivate::updateCurrent()
Q_Q(QDeclarativePathView);
if (moveReason != Mouse)
return;
- if (!haveHighlightRange || highlightRangeMode != QDeclarativePathView::StrictlyEnforceRange)
+ if (!modelCount || !haveHighlightRange || highlightRangeMode != QDeclarativePathView::StrictlyEnforceRange)
return;
int idx = calcCurrentIndex();
diff --git a/src/declarative/graphicsitems/qdeclarativerepeater.cpp b/src/declarative/graphicsitems/qdeclarativerepeater.cpp
index 8455513..4d0f34c 100644
--- a/src/declarative/graphicsitems/qdeclarativerepeater.cpp
+++ b/src/declarative/graphicsitems/qdeclarativerepeater.cpp
@@ -198,7 +198,6 @@ void QDeclarativeRepeater::setModel(const QVariant &model)
*/
}
d->dataSource = model;
- emit modelChanged();
QObject *object = qvariant_cast<QObject*>(model);
QDeclarativeVisualModel *vim = 0;
if (object && (vim = qobject_cast<QDeclarativeVisualModel *>(object))) {
@@ -226,6 +225,7 @@ void QDeclarativeRepeater::setModel(const QVariant &model)
*/
regenerate();
}
+ emit modelChanged();
emit countChanged();
}
diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp
index 8f1d531..049169e 100644
--- a/src/declarative/graphicsitems/qdeclarativetext.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetext.cpp
@@ -99,7 +99,8 @@ QString QDeclarativeTextPrivate::elideChar = QString(0x2026);
QDeclarativeTextPrivate::QDeclarativeTextPrivate()
: color((QRgb)0), style(QDeclarativeText::Normal), hAlign(QDeclarativeText::AlignLeft),
vAlign(QDeclarativeText::AlignTop), elideMode(QDeclarativeText::ElideNone),
- format(QDeclarativeText::AutoText), wrapMode(QDeclarativeText::NoWrap), lineHeight(1), lineHeightMode(QDeclarativeText::MultiplyHeight),
+ format(QDeclarativeText::AutoText), wrapMode(QDeclarativeText::NoWrap), lineHeight(1),
+ lineHeightMode(QDeclarativeText::ProportionalHeight),
lineCount(1), truncated(false), maximumLineCount(INT_MAX),
maximumLineCountValid(false), imageCacheDirty(true), updateOnComponentComplete(true), richText(false), singleline(false),
cacheAllTextAsImage(true), internalWidthUpdate(false), requireImplicitWidth(false), naturalWidth(0), doc(0)
@@ -189,7 +190,7 @@ QDeclarativeTextDocumentLayout::QDeclarativeTextDocumentLayout(QTextDocument *do
: QTextDocumentLayout(doc) {
}
-void QDeclarativeTextDocumentLayout::setLineHeight(qreal lineHeight, QDeclarativeText::LineHeightMode mode = QDeclarativeText::MultiplyHeight)
+void QDeclarativeTextDocumentLayout::setLineHeight(qreal lineHeight, QDeclarativeText::LineHeightMode mode = QDeclarativeText::ProportionalHeight)
{
QTextDocumentLayout::setLineHeight(lineHeight, QTextDocumentLayout::LineHeightMode(mode));
}
@@ -468,7 +469,7 @@ QSize QDeclarativeTextPrivate::setupTextLayout()
for (int i = 0; i < layout.lineCount(); ++i) {
QTextLine line = layout.lineAt(i);
line.setPosition(QPointF(0, height));
- height += (lineHeightMode == QDeclarativeText::PixelHeight) ? lineHeight : line.height() * lineHeight;
+ height += (lineHeightMode == QDeclarativeText::FixedHeight) ? lineHeight : line.height() * lineHeight;
if (!cacheAllTextAsImage) {
if ((hAlignment == QDeclarativeText::AlignLeft) || (hAlignment == QDeclarativeText::AlignJustify)) {
@@ -1482,8 +1483,9 @@ void QDeclarativeText::setLineHeight(qreal lineHeight)
The possible values are:
\list
- \o Text.MultiplyHeight (default) - specifies a line height multiplier,
- \o Text.PixelHeight - specifies the line height in pixels.
+ \o Text.ProportionalHeight (default) - this sets the spacing proportional to the
+ line (as a multiplier). For example, set to 2 for double spacing.
+ \o Text.FixedHeight - this sets the line height to a fixed line height (in pixels).
\endlist
*/
QDeclarativeText::LineHeightMode QDeclarativeText::lineHeightMode() const
diff --git a/src/declarative/graphicsitems/qdeclarativetext_p.h b/src/declarative/graphicsitems/qdeclarativetext_p.h
index f3697d5..b8835d1 100644
--- a/src/declarative/graphicsitems/qdeclarativetext_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetext_p.h
@@ -114,7 +114,7 @@ public:
Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
};
- enum LineHeightMode { MultiplyHeight, PixelHeight };
+ enum LineHeightMode { ProportionalHeight, FixedHeight };
QString text() const;
void setText(const QString &);
diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp
index 39f1465..7f383a6 100644
--- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp
@@ -976,6 +976,11 @@ void QDeclarativeTextEdit::setSelectByMouse(bool on)
Q_D(QDeclarativeTextEdit);
if (d->selectByMouse != on) {
d->selectByMouse = on;
+ setKeepMouseGrab(on);
+ if (on)
+ setTextInteractionFlags(d->control->textInteractionFlags() | Qt::TextSelectableByMouse);
+ else
+ setTextInteractionFlags(d->control->textInteractionFlags() & ~Qt::TextSelectableByMouse);
emit selectByMouseChanged(on);
}
}
@@ -1028,11 +1033,10 @@ void QDeclarativeTextEdit::setReadOnly(bool r)
setFlag(QGraphicsItem::ItemAcceptsInputMethod, !r);
Qt::TextInteractionFlags flags = Qt::LinksAccessibleByMouse;
- if (r) {
+ if (d->selectByMouse)
flags = flags | Qt::TextSelectableByMouse;
- } else {
- flags = flags | Qt::TextEditorInteraction;
- }
+ if (!r)
+ flags = flags | Qt::TextSelectableByKeyboard | Qt::TextEditable;
d->control->setTextInteractionFlags(flags);
if (!r)
d->control->moveCursor(QTextCursor::End);
@@ -1124,7 +1128,7 @@ void QDeclarativeTextEdit::keyReleaseEvent(QKeyEvent *event)
void QDeclarativeTextEditPrivate::focusChanged(bool hasFocus)
{
Q_Q(QDeclarativeTextEdit);
- q->setCursorVisible(hasFocus);
+ q->setCursorVisible(hasFocus && scene && scene->hasFocus());
QDeclarativeItemPrivate::focusChanged(hasFocus);
}
@@ -1250,8 +1254,8 @@ void QDeclarativeTextEdit::mousePressEvent(QGraphicsSceneMouseEvent *event)
}
}
}
- if (event->type() != QEvent::GraphicsSceneMouseDoubleClick || d->selectByMouse)
- d->control->processEvent(event, QPointF(0, -d->yoff));
+
+ d->control->processEvent(event, QPointF(0, -d->yoff));
if (!event->isAccepted())
QDeclarativePaintedItem::mousePressEvent(event);
}
@@ -1286,13 +1290,11 @@ Handles the given mouse \a event.
void QDeclarativeTextEdit::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QDeclarativeTextEdit);
- if (d->selectByMouse) {
- d->control->processEvent(event, QPointF(0, -d->yoff));
- if (!event->isAccepted())
- QDeclarativePaintedItem::mouseDoubleClickEvent(event);
- } else {
+
+ d->control->processEvent(event, QPointF(0, -d->yoff));
+ if (!event->isAccepted())
QDeclarativePaintedItem::mouseDoubleClickEvent(event);
- }
+
}
/*!
@@ -1302,14 +1304,9 @@ Handles the given mouse \a event.
void QDeclarativeTextEdit::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QDeclarativeTextEdit);
- if (d->selectByMouse) {
- d->control->processEvent(event, QPointF(0, -d->yoff));
- if (!event->isAccepted())
- QDeclarativePaintedItem::mouseMoveEvent(event);
- event->setAccepted(true);
- } else {
+ d->control->processEvent(event, QPointF(0, -d->yoff));
+ if (!event->isAccepted())
QDeclarativePaintedItem::mouseMoveEvent(event);
- }
}
/*!
@@ -1408,7 +1405,7 @@ void QDeclarativeTextEditPrivate::init()
control = new QTextControl(q);
control->setIgnoreUnusedNavigationEvents(true);
- control->setTextInteractionFlags(control->textInteractionFlags() | Qt::LinksAccessibleByMouse);
+ control->setTextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::TextSelectableByKeyboard | Qt::TextEditable);
control->setDragEnabled(false);
// QTextControl follows the default text color
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
index 6f7d3ff..78f34db 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
@@ -51,6 +51,7 @@
#include <QFontMetrics>
#include <QPainter>
#include <QTextBoundaryFinder>
+#include <QInputContext>
#include <qstyle.h>
#ifndef QT_NO_LINEEDIT
@@ -776,6 +777,15 @@ bool QDeclarativeTextInput::hasAcceptableInput() const
}
/*!
+ \qmlsignal TextInput::onAccepted()
+
+ This handler is called when the Return or Enter key is pressed.
+ Note that if there is a \l validator or \l inputMask set on the text
+ input, the handler will only be emitted if the input is in an acceptable
+ state.
+*/
+
+/*!
\qmlproperty enumeration TextInput::echoMode
Specifies how the text should be displayed in the TextInput.
@@ -938,7 +948,7 @@ void QDeclarativeTextInputPrivate::focusChanged(bool hasFocus)
{
Q_Q(QDeclarativeTextInput);
focused = hasFocus;
- q->setCursorVisible(hasFocus);
+ q->setCursorVisible(hasFocus && scene && scene->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)
@@ -980,6 +990,7 @@ void QDeclarativeTextInput::inputMethodEvent(QInputMethodEvent *ev)
} else {
d->control->processInputMethodEvent(ev);
updateSize();
+ d->updateHorizontalScroll();
}
if (!ev->isAccepted())
QDeclarativePaintedItem::inputMethodEvent(ev);
@@ -992,6 +1003,8 @@ Handles the given mouse \a event.
void QDeclarativeTextInput::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QDeclarativeTextInput);
+ if (d->sendMouseEventToInputContext(event, QEvent::MouseButtonDblClick))
+ return;
if (d->selectByMouse) {
int cursor = d->xToPos(event->pos().x());
d->control->selectWordAtPos(cursor);
@@ -1004,6 +1017,8 @@ void QDeclarativeTextInput::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *even
void QDeclarativeTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QDeclarativeTextInput);
+ if (d->sendMouseEventToInputContext(event, QEvent::MouseButtonPress))
+ return;
if(d->focusOnPress){
bool hadActiveFocus = hasActiveFocus();
forceActiveFocus();
@@ -1018,6 +1033,10 @@ void QDeclarativeTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event)
}
}
}
+ if (d->selectByMouse) {
+ setKeepMouseGrab(false);
+ d->pressPos = event->pos();
+ }
bool mark = event->modifiers() & Qt::ShiftModifier;
int cursor = d->xToPos(event->pos().x());
d->control->moveCursor(cursor, mark);
@@ -1027,7 +1046,11 @@ void QDeclarativeTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event)
void QDeclarativeTextInput::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QDeclarativeTextInput);
+ if (d->sendMouseEventToInputContext(event, QEvent::MouseMove))
+ event->setAccepted(true);
if (d->selectByMouse) {
+ if (qAbs(int(event->pos().x() - d->pressPos.x())) > QApplication::startDragDistance())
+ setKeepMouseGrab(true);
moveCursorSelection(d->xToPos(event->pos().x()), d->mouseSelectionMode);
event->setAccepted(true);
} else {
@@ -1042,6 +1065,10 @@ Handles the given mouse \a event.
void QDeclarativeTextInput::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QDeclarativeTextInput);
+ if (d->sendMouseEventToInputContext(event, QEvent::MouseButtonRelease))
+ return;
+ if (d->selectByMouse)
+ setKeepMouseGrab(false);
if (!d->showInputPanelOnFocus) { // input panel on click
if (d->focusOnPress && !isReadOnly() && boundingRect().contains(event->pos())) {
if (QGraphicsView * view = qobject_cast<QGraphicsView*>(qApp->focusWidget())) {
@@ -1057,6 +1084,53 @@ void QDeclarativeTextInput::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
QDeclarativePaintedItem::mouseReleaseEvent(event);
}
+bool QDeclarativeTextInputPrivate::sendMouseEventToInputContext(
+ QGraphicsSceneMouseEvent *event, QEvent::Type eventType)
+{
+#if !defined QT_NO_IM
+ if (event->widget() && control->composeMode()) {
+ int tmp_cursor = xToPos(event->pos().x());
+ int mousePos = tmp_cursor - control->cursor();
+ if (mousePos < 0 || mousePos > control->preeditAreaText().length()) {
+ mousePos = -1;
+ // don't send move events outside the preedit area
+ if (eventType == QEvent::MouseMove)
+ return true;
+ }
+
+ QInputContext *qic = event->widget()->inputContext();
+ if (qic) {
+ QMouseEvent mouseEvent(
+ eventType,
+ event->widget()->mapFromGlobal(event->screenPos()),
+ event->screenPos(),
+ event->button(),
+ event->buttons(),
+ event->modifiers());
+ // may be causing reset() in some input methods
+ qic->mouseHandler(mousePos, &mouseEvent);
+ event->setAccepted(mouseEvent.isAccepted());
+ }
+ if (!control->preeditAreaText().isEmpty())
+ return true;
+ }
+#else
+ Q_UNUSED(event);
+ Q_UNUSED(eventType)
+#endif
+
+ return false;
+}
+
+bool QDeclarativeTextInput::sceneEvent(QEvent *event)
+{
+ bool rv = QDeclarativeItem::sceneEvent(event);
+ if (event->type() == QEvent::UngrabMouse) {
+ setKeepMouseGrab(false);
+ }
+ return rv;
+}
+
bool QDeclarativeTextInput::event(QEvent* ev)
{
Q_D(QDeclarativeTextInput);
@@ -1098,7 +1172,8 @@ int QDeclarativeTextInputPrivate::calculateTextWidth()
void QDeclarativeTextInputPrivate::updateHorizontalScroll()
{
Q_Q(QDeclarativeTextInput);
- int cix = qRound(control->cursorToX());
+ const int preeditLength = control->preeditAreaText().length();
+ int cix = qRound(control->cursorToX(control->cursor() + preeditLength));
QRect br(q->boundingRect().toRect());
int widthUsed = calculateTextWidth();
Qt::Alignment va = QStyle::visualAlignment(control->layoutDirection(), QFlag(Qt::Alignment(hAlign)));
@@ -1128,6 +1203,14 @@ void QDeclarativeTextInputPrivate::updateHorizontalScroll()
// right
hscroll = widthUsed - br.width() + 1;
}
+ if (preeditLength > 0) {
+ // check to ensure long pre-edit text doesn't push the cursor
+ // off to the left
+ cix = qRound(control->cursorToX(
+ control->cursor() + qMax(0, control->preeditCursor() - 1)));
+ if (cix < hscroll)
+ hscroll = cix;
+ }
} else {
switch (va & ~(Qt::AlignAbsolute|Qt::AlignVertical_Mask)) {
case Qt::AlignRight:
@@ -1626,6 +1709,8 @@ void QDeclarativeTextInputPrivate::init()
q->connect(QApplication::clipboard(), SIGNAL(dataChanged()),
q, SLOT(q_canPasteChanged()));
#endif // QT_NO_CLIPBOARD
+ q->connect(control, SIGNAL(updateMicroFocus()),
+ q, SLOT(updateMicroFocus()));
q->updateSize();
oldValidity = control->hasAcceptableInput();
lastSelectionStart = 0;
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p.h
index 63d0e53..e1e66a9 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextinput_p.h
@@ -240,6 +240,7 @@ protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
+ bool sceneEvent(QEvent *event);
void keyPressEvent(QKeyEvent* ev);
void inputMethodEvent(QInputMethodEvent *);
bool event(QEvent *e);
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
index 7a0086e..ab2838b 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
@@ -104,6 +104,7 @@ public:
void focusChanged(bool hasFocus);
void updateHorizontalScroll();
int calculateTextWidth();
+ bool sendMouseEventToInputContext(QGraphicsSceneMouseEvent *event, QEvent::Type eventType);
QLineControl* control;
@@ -118,6 +119,7 @@ public:
QDeclarativeTextInput::SelectionMode mouseSelectionMode;
QPointer<QDeclarativeComponent> cursorComponent;
QPointer<QDeclarativeItem> cursorItem;
+ QPointF pressPos;
int lastSelectionStart;
int lastSelectionEnd;