summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/src/declarative/declarativeui.qdoc1
-rw-r--r--doc/src/declarative/qmldebugging.qdoc16
-rw-r--r--examples/declarative/layouts/positioners.qml62
-rw-r--r--src/declarative/graphicsitems/qmlgraphicslistview.cpp80
-rw-r--r--src/declarative/graphicsitems/qmlgraphicspositioners.cpp173
-rw-r--r--src/declarative/graphicsitems/qmlgraphicspositioners_p.h30
-rw-r--r--src/declarative/util/qnumberformat.cpp4
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp1
8 files changed, 310 insertions, 57 deletions
diff --git a/doc/src/declarative/declarativeui.qdoc b/doc/src/declarative/declarativeui.qdoc
index 8516c98..4d2b09c 100644
--- a/doc/src/declarative/declarativeui.qdoc
+++ b/doc/src/declarative/declarativeui.qdoc
@@ -102,5 +102,6 @@ completely new applications. QML is fully \l {Extending QML}{extensible from C+
\o \l {Extending QML}
\o \l {QML Internationalization}
\o \l {QtDeclarative Module}
+\o \l {Debugging QML}
\endlist
*/
diff --git a/doc/src/declarative/qmldebugging.qdoc b/doc/src/declarative/qmldebugging.qdoc
index 13ad5f7..a6def19 100644
--- a/doc/src/declarative/qmldebugging.qdoc
+++ b/doc/src/declarative/qmldebugging.qdoc
@@ -45,7 +45,7 @@
\section1 Logging
-console.log can be used to print debugging information to the console. For example:
+\c console.log can be used to print debugging information to the console. For example:
\qml
Rectangle {
@@ -57,6 +57,13 @@ Rectangle {
}
\endqml
+\section1 Debugging Transitions
+
+When a transition doesn't look quite right, it can be helpful to view it in slow
+motion to see what is happening more clearly. \l {qmlviewer} provides a
+"Slow Down Animations" menu option to facilitate this.
+
+
\section1 The QML Inspector
The \c qmldebugger tool provides an experimental inspector to aid with debugging.
@@ -110,11 +117,4 @@ to an available port number and run the \c qmlviewer. For example:
Then in another process, start the \c qmldebugger tool, enter the port number into the corresponding spinbox
in the top right hand corner, and press the "Connect" button.
-
-\section1 Debugging Transitions
-
-When a transition doesn't look quite right, it can be helpful to view it in slow
-motion to see more clearly what is happening. \l {qmlviewer} provides a menu option
-"Slow Down Animations" to facilitate this.
-
*/
diff --git a/examples/declarative/layouts/positioners.qml b/examples/declarative/layouts/positioners.qml
index e912632..4c26bea 100644
--- a/examples/declarative/layouts/positioners.qml
+++ b/examples/declarative/layouts/positioners.qml
@@ -78,6 +78,9 @@ Rectangle {
blueG1.opacity = 0
blueG2.opacity = 0
blueG3.opacity = 0
+ blueF1.opacity = 0
+ blueF2.opacity = 0
+ blueF3.opacity = 0
}
}
@@ -95,6 +98,9 @@ Rectangle {
blueG1.opacity = 1
blueG2.opacity = 1
blueG3.opacity = 1
+ blueF1.opacity = 1
+ blueF2.opacity = 1
+ blueF3.opacity = 1
}
}
@@ -121,20 +127,58 @@ Rectangle {
}
}
- Rectangle { color: "red"; width: 50; height: 100; border.color: "black"; radius: 15 }
- Rectangle { id: blueG1; color: "lightsteelblue"; width: 50; height: 100; border.color: "black"; radius: 15
+ Rectangle { color: "red"; width: 50; height: 50; border.color: "black"; radius: 15 }
+ Rectangle { id: blueG1; color: "lightsteelblue"; width: 50; height: 50; border.color: "black"; radius: 15
opacity: Behavior{NumberAnimation{}}
}
- Rectangle { color: "green"; width: 50; height: 100; border.color: "black"; radius: 15 }
- Rectangle { id: blueG2; color: "lightsteelblue"; width: 50; height: 100; border.color: "black"; radius: 15
+ Rectangle { color: "green"; width: 50; height: 50; border.color: "black"; radius: 15 }
+ Rectangle { id: blueG2; color: "lightsteelblue"; width: 50; height: 50; border.color: "black"; radius: 15
opacity: Behavior{NumberAnimation{}}
}
- Rectangle { color: "orange"; width: 50; height: 100; border.color: "black"; radius: 15 }
- Rectangle { id: blueG3; color: "lightsteelblue"; width: 50; height: 100; border.color: "black"; radius: 15
+ Rectangle { color: "orange"; width: 50; height: 50; border.color: "black"; radius: 15 }
+ Rectangle { id: blueG3; color: "lightsteelblue"; width: 50; height: 50; border.color: "black"; radius: 15
opacity: Behavior{NumberAnimation{}}
}
- Rectangle { color: "red"; width: 50; height: 100; border.color: "black"; radius: 15 }
- Rectangle { color: "green"; width: 50; height: 100; border.color: "black"; radius: 15 }
- Rectangle { color: "orange"; width: 50; height: 100; border.color: "black"; radius: 15 }
+ Rectangle { color: "red"; width: 50; height: 50; border.color: "black"; radius: 15 }
+ Rectangle { color: "green"; width: 50; height: 50; border.color: "black"; radius: 15 }
+ Rectangle { color: "orange"; width: 50; height: 50; border.color: "black"; radius: 15 }
}
+
+ Flow {
+ id: layout4
+ x: 260
+ y: 250
+ width: 150
+ remove: Transition {
+ NumberAnimation {
+ matchProperties: "x,y"; easing: "easeOutBounce"
+ }
+ }
+
+ move: Transition {
+ NumberAnimation {
+ matchProperties: "x,y"; easing: "easeOutBounce"
+ }
+ }
+
+ add: Transition {
+ NumberAnimation {
+ matchProperties: "x,y"; easing: "easeOutBounce"
+ }
+ }
+ Rectangle { color: "red"; width: 50; height: 50; border.color: "black"; radius: 15 }
+ Rectangle { id: blueF1; color: "lightsteelblue"; width: 60; height: 50; border.color: "black"; radius: 15
+ opacity: Behavior{NumberAnimation{}}
+ }
+ Rectangle { color: "green"; width: 30; height: 50; border.color: "black"; radius: 15 }
+ Rectangle { id: blueF2; color: "lightsteelblue"; width: 60; height: 50; border.color: "black"; radius: 15
+ opacity: Behavior{NumberAnimation{}}
+ }
+ Rectangle { color: "orange"; width: 50; height: 50; border.color: "black"; radius: 15 }
+ Rectangle { id: blueF3; color: "lightsteelblue"; width: 40; height: 50; border.color: "black"; radius: 15
+ opacity: Behavior{NumberAnimation{}}
+ }
+ Rectangle { color: "red"; width: 80; height: 50; border.color: "black"; radius: 15 }
+ }
+
}
diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp
index 135262c..2084d94 100644
--- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp
@@ -1076,14 +1076,11 @@ void QmlGraphicsListViewPrivate::flickX(qreal velocity)
accel = v2 / (2.0f * qAbs(dist));
overshootDist = 0.0;
} else {
- if (velocity > 0)
- flickTargetX = minX;
- else
- flickTargetX = maxX;
+ flickTargetX = velocity > 0 ? minX : maxX;
overshootDist = overShoot ? 30 : 0;
}
timeline.reset(_moveX);
- timeline.accel(_moveX, v, accel, maxDistance);
+ timeline.accel(_moveX, v, accel, maxDistance + overshootDist);
timeline.execute(fixupXEvent);
flicked = true;
emit q->flickingChanged();
@@ -1091,14 +1088,15 @@ void QmlGraphicsListViewPrivate::flickX(qreal velocity)
correctFlick = true;
} else {
// reevaluate the target boundary.
- qreal newtarget = -snapPosAt(-(flickTargetX - highlightRangeStart)) + highlightRangeStart;
- if (newtarget < maxX) {
+ qreal newtarget = flickTargetX;
+ if (snapMode != QmlGraphicsListView::NoSnap || highlightRange == QmlGraphicsListView::StrictlyEnforceRange)
+ newtarget = -snapPosAt(-(flickTargetX - highlightRangeStart)) + highlightRangeStart;
+ if (velocity < 0 && newtarget < maxX)
newtarget = maxX;
- }
- if (newtarget == flickTargetX) {
- // boundary unchanged - nothing to do
+ else if (velocity > 0 && newtarget > minX)
+ newtarget = minX;
+ if (newtarget == flickTargetX) // boundary unchanged - nothing to do
return;
- }
flickTargetX = newtarget;
qreal dist = -newtarget + _moveX.value();
if ((v < 0 && dist < 0) || (v > 0 && dist > 0)) {
@@ -1175,14 +1173,11 @@ void QmlGraphicsListViewPrivate::flickY(qreal velocity)
accel = v2 / (2.0f * qAbs(dist));
overshootDist = 0.0;
} else {
- if (velocity > 0)
- flickTargetY = minY;
- else
- flickTargetY = maxY;
+ flickTargetY = velocity > 0 ? minY : maxY;
overshootDist = overShoot ? 30 : 0;
}
timeline.reset(_moveY);
- timeline.accel(_moveY, v, accel, maxDistance);
+ timeline.accel(_moveY, v, accel, maxDistance + overshootDist);
timeline.execute(fixupYEvent);
flicked = true;
emit q->flickingChanged();
@@ -1190,14 +1185,15 @@ void QmlGraphicsListViewPrivate::flickY(qreal velocity)
correctFlick = true;
} else {
// reevaluate the target boundary.
- qreal newtarget = -snapPosAt(-(flickTargetY - highlightRangeStart)) + highlightRangeStart;
- if (newtarget < maxY) {
+ qreal newtarget = flickTargetY;
+ if (snapMode != QmlGraphicsListView::NoSnap || highlightRange == QmlGraphicsListView::StrictlyEnforceRange)
+ newtarget = -snapPosAt(-(flickTargetY - highlightRangeStart)) + highlightRangeStart;
+ if (velocity < 0 && newtarget < maxY)
newtarget = maxY;
- }
- if (newtarget == flickTargetY) {
- // boundary unchanged - nothing to do
+ else if (velocity > 0 && newtarget > minY)
+ newtarget = minY;
+ if (newtarget == flickTargetY) // boundary unchanged - nothing to do
return;
- }
flickTargetY = newtarget;
qreal dist = -newtarget + _moveY.value();
if ((v < 0 && dist < 0) || (v > 0 && dist > 0)) {
@@ -1922,20 +1918,32 @@ void QmlGraphicsListView::viewportMoved()
if (d->flicked && d->correctFlick) {
// Near an end and it seems that the extent has changed?
// Recalculate the flick so that we don't end up in an odd position.
- if (d->velocityY > 0) {
- if (d->flickTargetY - d->_moveY.value() < height()/2 && minYExtent() != d->flickTargetY)
- d->flickY(-d->verticalVelocity.value());
- } else if (d->velocityY < 0) {
- if (d->_moveY.value() - d->flickTargetY < height()/2 && maxYExtent() != d->flickTargetY)
- d->flickY(-d->verticalVelocity.value());
- }
-
- if (d->velocityX > 0) {
- if (d->flickTargetX - d->_moveX.value() < height()/2 && minXExtent() != d->flickTargetX)
- d->flickX(-d->verticalVelocity.value());
- } else if (d->velocityX < 0) {
- if (d->_moveX.value() - d->flickTargetX < height()/2 && maxXExtent() != d->flickTargetX)
- d->flickX(-d->verticalVelocity.value());
+ if (yflick()) {
+ if (d->velocityY > 0) {
+ const qreal minY = minYExtent();
+ if ((minY - d->_moveY.value() < height()/2 || d->flickTargetY - d->_moveY.value() < height()/2)
+ && minY != d->flickTargetY)
+ d->flickY(-d->verticalVelocity.value());
+ } else if (d->velocityY < 0) {
+ const qreal maxY = maxYExtent();
+ if ((d->_moveY.value() - maxY < height()/2 || d->_moveY.value() - d->flickTargetY < height()/2)
+ && maxY != d->flickTargetY)
+ d->flickY(-d->verticalVelocity.value());
+ }
+ }
+
+ if (xflick()) {
+ if (d->velocityX > 0) {
+ const qreal minX = minXExtent();
+ if ((minX - d->_moveX.value() < height()/2 || d->flickTargetX - d->_moveX.value() < height()/2)
+ && minX != d->flickTargetX)
+ d->flickX(-d->verticalVelocity.value());
+ } else if (d->velocityX < 0) {
+ const qreal maxX = maxXExtent();
+ if ((d->_moveX.value() - maxX < height()/2 || d->_moveX.value() - d->flickTargetX < height()/2)
+ && maxX != d->flickTargetX)
+ d->flickX(-d->verticalVelocity.value());
+ }
}
}
}
diff --git a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp
index db0cc7c..b1ec5a7 100644
--- a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp
@@ -47,6 +47,7 @@
#include <qmlstategroup_p.h>
#include <qmlstateoperations_p.h>
#include <qfxperf_p_p.h>
+#include <QtCore/qmath.h>
#include <QDebug>
#include <QCoreApplication>
@@ -889,4 +890,176 @@ void QmlGraphicsGrid::doPositioning()
}
}
+
+QML_DEFINE_TYPE(Qt,4,6,Flow,QmlGraphicsFlow)
+/*!
+ \qmlclass Flow QmlGraphicsFlow
+ \brief The Flow item lines up its children side by side, wrapping as necessary.
+ \inherits Item
+
+
+*/
+/*!
+ \qmlproperty Transition Flow::remove
+ This property holds the transition to apply when removing an item from the positioner.
+ The transition will only be applied to the removed item(s).
+ Positioner transitions will only affect the position (x,y) of items.
+
+ Removed can mean that either the object has been deleted or reparented, and thus is now longer a child of the positioner, or that the object has had its opacity set to zero, and thus is no longer visible.
+
+ Note that if the item counts as removed because its opacity is zero it will not be visible during the transition unless you set the opacity in the transition, like in the below example.
+
+
+*/
+/*!
+ \qmlproperty Transition Flow::add
+ This property holds the transition to apply when adding an item to the positioner.
+ The transition will only be applied to the added item(s).
+ Positioner transitions will only affect the position (x,y) of items.
+
+ Added can mean that either the object has been created or reparented, and thus is now a child or the positioner, or that the object has had its opacity increased from zero, and thus is now visible.
+
+
+*/
+/*!
+ \qmlproperty Transition Flow::move
+ This property holds the transition to apply when moving an item within the positioner.
+ Positioner transitions will only affect the position (x,y) of items.
+
+ This can happen when other items are added or removed from the positioner, or when items resize themselves.
+
+ \qml
+Flow {
+ id: positioner
+ move: Transition {
+ NumberAnimation {
+ matchProperties: "x,y"
+ ease: "easeOutBounce"
+ }
+ }
+}
+ \endqml
+
+*/
+/*!
+ \qmlproperty int Flow::spacing
+
+ spacing is the amount in pixels left empty between each adjacent
+ item, and defaults to 0.
+
+*/
+
+class QmlGraphicsFlowPrivate : public QmlGraphicsBasePositionerPrivate
+{
+ Q_DECLARE_PUBLIC(QmlGraphicsFlow)
+
+public:
+ QmlGraphicsFlowPrivate()
+ : QmlGraphicsBasePositionerPrivate(), flow(QmlGraphicsFlow::LeftToRight)
+ {}
+
+ QmlGraphicsFlow::Flow flow;
+};
+
+QmlGraphicsFlow::QmlGraphicsFlow(QmlGraphicsItem *parent)
+: QmlGraphicsBasePositioner(*(new QmlGraphicsFlowPrivate), Both, parent)
+{
+}
+
+/*!
+ \qmlproperty enumeration Flow::flow
+ This property holds the flow of the layout.
+
+ Possible values are \c LeftToRight (default) and \c TopToBottom.
+
+ If \a flow is \c LeftToRight, the items are positioned next to
+ to each other from left to right until the width of the Flow
+ is exceeded, then wrapped to the next line.
+ If \a flow is \c TopToBottom, the items are positioned next to each
+ other from top to bottom until the height of the Flow is exceeded,
+ then wrapped to the next column.
+*/
+QmlGraphicsFlow::Flow QmlGraphicsFlow::flow() const
+{
+ Q_D(const QmlGraphicsFlow);
+ return d->flow;
+}
+
+void QmlGraphicsFlow::setFlow(Flow flow)
+{
+ Q_D(QmlGraphicsFlow);
+ if (d->flow != flow) {
+ d->flow = flow;
+ prePositioning();
+ emit flowChanged();
+ }
+}
+
+void QmlGraphicsFlow::doPositioning()
+{
+ Q_D(QmlGraphicsFlow);
+ foreach(QmlGraphicsItem* item, *leavingItems()){
+ if (remove()){
+ QList<QPair<QString,QVariant> > changes;
+ applyRemove(changes, item);
+ }
+ }
+
+ int hoffset = 0;
+ int voffset = 0;
+ int linemax = 0;
+
+ QList<QmlGraphicsItem *> children = positionedItems;
+ for (int ii = 0; ii < children.count(); ++ii) {
+ QmlGraphicsItem *child = children.at(ii);
+ if (!child || isInvisible(child))
+ continue;
+
+ if (d->flow == LeftToRight) {
+ if (hoffset && hoffset + child->width() > width()) {
+ hoffset = 0;
+ voffset += linemax + spacing();
+ linemax = 0;
+ }
+ } else {
+ if (voffset && voffset + child->height() > height()) {
+ voffset = 0;
+ hoffset += linemax + spacing();
+ linemax = 0;
+ }
+ }
+
+ bool needMove = (child->x() != hoffset || child->y() != voffset);
+
+ if (newItems()->contains(child) && add()) {
+ QList<QPair<QString, QVariant> > changes;
+ changes << qMakePair(QString(QLatin1String("x")),QVariant(hoffset));
+ changes << qMakePair(QString(QLatin1String("y")),QVariant(voffset));
+ applyAdd(changes,child);
+ } else if (needMove) {
+ if (move()){
+ QList<QPair<QString, QVariant> > changes;
+ changes << qMakePair(QString(QLatin1String("x")),QVariant(hoffset));
+ changes << qMakePair(QString(QLatin1String("y")),QVariant(voffset));
+ applyMove(changes,child);
+ } else {
+ setMovingItem(child);
+ child->setPos(QPointF(hoffset, voffset));
+ setMovingItem(0);
+ }
+ }
+
+ if (d->flow == LeftToRight) {
+ hoffset += child->width();
+ hoffset += spacing();
+ linemax = qMax(linemax, qCeil(child->height()));
+ } else {
+ voffset += child->height();
+ voffset += spacing();
+ linemax = qMax(linemax, qCeil(child->width()));
+ }
+ }
+}
+
+
QT_END_NAMESPACE
diff --git a/src/declarative/graphicsitems/qmlgraphicspositioners_p.h b/src/declarative/graphicsitems/qmlgraphicspositioners_p.h
index 03e0f41..a4ef32d 100644
--- a/src/declarative/graphicsitems/qmlgraphicspositioners_p.h
+++ b/src/declarative/graphicsitems/qmlgraphicspositioners_p.h
@@ -98,8 +98,6 @@ Q_SIGNALS:
protected Q_SLOTS:
virtual void doPositioning()=0;
-
-private Q_SLOTS:
void prePositioning();
protected:
@@ -158,11 +156,39 @@ private:
Q_DISABLE_COPY(QmlGraphicsGrid)
};
+class QmlGraphicsFlowPrivate;
+class Q_DECLARATIVE_EXPORT QmlGraphicsFlow: public QmlGraphicsBasePositioner
+{
+ Q_OBJECT
+ Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged)
+public:
+ QmlGraphicsFlow(QmlGraphicsItem *parent=0);
+
+ Q_ENUMS(Flow)
+ enum Flow { LeftToRight, TopToBottom };
+ Flow flow() const;
+ void setFlow(Flow);
+
+Q_SIGNALS:
+ void flowChanged();
+
+protected Q_SLOTS:
+ virtual void doPositioning();
+
+protected:
+ QmlGraphicsFlow(QmlGraphicsFlowPrivate &dd, QmlGraphicsItem *parent);
+private:
+ Q_DISABLE_COPY(QmlGraphicsFlow)
+ Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QmlGraphicsFlow)
+};
+
+
QT_END_NAMESPACE
QML_DECLARE_TYPE(QmlGraphicsColumn)
QML_DECLARE_TYPE(QmlGraphicsRow)
QML_DECLARE_TYPE(QmlGraphicsGrid)
+QML_DECLARE_TYPE(QmlGraphicsFlow)
QT_END_HEADER
diff --git a/src/declarative/util/qnumberformat.cpp b/src/declarative/util/qnumberformat.cpp
index c6a03e9..fd44db1 100644
--- a/src/declarative/util/qnumberformat.cpp
+++ b/src/declarative/util/qnumberformat.cpp
@@ -75,7 +75,7 @@ void QNumberFormat::handleFormat()
{
// ### is extremely messy
if (_format.isEmpty()) {
- _text = QString(QLatin1String("%1")).arg(_number, -1, 'f', -1);
+ _text = QString::number(_number, 'f', -1);
return;
}
@@ -115,7 +115,7 @@ void QNumberFormat::handleFormat()
}
// round given the decimal length/precision
- inputString = QString(QLatin1String("%1")).arg(_number, -1, 'f', decimalLength);
+ inputString = QString::number(_number, 'f', decimalLength);
QStringList parts = inputString.split(QLatin1Char('.'));
QStringList formatParts = _format.split(QLatin1Char('.'));
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index dd76f1c..9e6fcc0 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -1328,6 +1328,7 @@ QGraphicsItem::~QGraphicsItem()
d_ptr->removeExtraItemCache();
clearFocus();
+ d_ptr->subFocusItem = 0;
// Update focus scope item ptr.
QGraphicsItem *p = d_ptr->parent;