summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2009-09-11 06:07:27 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2009-09-11 06:07:27 (GMT)
commit1646d52f35d96f9cc4f874b76861b046343d2534 (patch)
tree64b741e8282d83bb9ed553771d19f709c73bff84 /src/declarative
parentbc7e8e12e96ff523278032d7c32c9bd504456de3 (diff)
parentf7982be51ec5872dba11d87ea653b791251a0215 (diff)
downloadQt-1646d52f35d96f9cc4f874b76861b046343d2534.zip
Qt-1646d52f35d96f9cc4f874b76861b046343d2534.tar.gz
Qt-1646d52f35d96f9cc4f874b76861b046343d2534.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/QmlChanges.txt2
-rw-r--r--src/declarative/fx/qfxflickable.cpp30
-rw-r--r--src/declarative/fx/qfxgridview.cpp4
-rw-r--r--src/declarative/fx/qfxgridview.h2
-rw-r--r--src/declarative/fx/qfximage.cpp5
-rw-r--r--src/declarative/fx/qfxlistview.cpp36
-rw-r--r--src/declarative/fx/qfxlistview.h8
7 files changed, 47 insertions, 40 deletions
diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt
index eace089..fe923a7 100644
--- a/src/declarative/QmlChanges.txt
+++ b/src/declarative/QmlChanges.txt
@@ -64,6 +64,8 @@ WebView: mouseY -> clickY (parameter to onDoubleClick)
WebView: cacheSize -> pixelCacheSize
Repeater: component -> delegate
Repeater: dataSource -> model
+ListView: current -> currentItem
+GridView: current -> currentItem
Additions:
MouseRegion: add "acceptedButtons" property
diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp
index c227899..1e6ad5a 100644
--- a/src/declarative/fx/qfxflickable.cpp
+++ b/src/declarative/fx/qfxflickable.cpp
@@ -48,6 +48,16 @@
QT_BEGIN_NAMESPACE
+
+// These are highly device dependant.
+// DragThreshold determines how far the "mouse" must move before
+// we begin a drag.
+// FlickThreshold determines how far the "mouse" must have moved
+// before we perform a flick.
+static const int DragThreshold = 8;
+static const int FlickThreshold = 20;
+
+
class QFxFlickableVisibleArea : public QObject
{
Q_OBJECT
@@ -147,7 +157,7 @@ QFxFlickablePrivate::QFxFlickablePrivate()
: viewport(new QFxItem), _moveX(viewport, &QFxItem::setX), _moveY(viewport, &QFxItem::setY)
, vWidth(-1), vHeight(-1), overShoot(true), flicked(false), moving(false), stealMouse(false)
, pressed(false), atXEnd(false), atXBeginning(true), atYEnd(false), atYBeginning(true)
- , interactive(true), maxVelocity(-1), reportedVelocitySmoothing(100)
+ , interactive(true), maxVelocity(5000), reportedVelocitySmoothing(100)
, delayedPressEvent(0), delayedPressTarget(0), pressDelay(0)
, horizontalVelocity(this), verticalVelocity(this), vTime(0), visibleArea(0)
{
@@ -327,8 +337,6 @@ void QFxFlickablePrivate::updateBeginningEnd()
visibleArea->updateVisible();
}
-static const int FlickThreshold = 5;
-
QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Flickable,QFxFlickable)
/*!
@@ -602,7 +610,7 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event)
if (q->yflick()) {
int dy = int(event->pos().y() - pressPos.y());
- if (qAbs(dy) > FlickThreshold || pressTime.elapsed() > 200) {
+ if (qAbs(dy) > DragThreshold || pressTime.elapsed() > 200) {
qreal newY = dy + pressY;
const qreal minY = q->minYExtent();
const qreal maxY = q->maxYExtent();
@@ -615,14 +623,14 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event)
moved = true;
} else if (!q->overShoot())
rejectY = true;
- if (qAbs(dy) > FlickThreshold)
+ if (qAbs(dy) > DragThreshold)
stealMouse = true;
}
}
if (q->xflick()) {
int dx = int(event->pos().x() - pressPos.x());
- if (qAbs(dx) > FlickThreshold || pressTime.elapsed() > 200) {
+ if (qAbs(dx) > DragThreshold || pressTime.elapsed() > 200) {
qreal newX = dx + pressX;
const qreal minX = q->minXExtent();
const qreal maxX = q->maxXExtent();
@@ -635,7 +643,7 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event)
moved = true;
} else if (!q->overShoot())
rejectX = true;
- if (qAbs(dx) > FlickThreshold)
+ if (qAbs(dx) > DragThreshold)
stealMouse = true;
}
}
@@ -666,7 +674,7 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event)
lastPos = event->pos();
}
-void QFxFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *)
+void QFxFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
Q_Q(QFxFlickable);
pressed = false;
@@ -674,12 +682,12 @@ void QFxFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *)
return;
vTime = timeline.time();
- if (qAbs(velocityY) > 10)
+ if (qAbs(velocityY) > 10 && qAbs(event->pos().y() - pressPos.y()) > FlickThreshold)
flickY(velocityY);
else
fixupY();
- if (qAbs(velocityX) > 10)
+ if (qAbs(velocityX) > 10 && qAbs(event->pos().x() - pressPos.x()) > FlickThreshold)
flickX(velocityX);
else
fixupX();
@@ -1093,6 +1101,8 @@ bool QFxFlickable::sceneEventFilter(QGraphicsItem *i, QEvent *e)
/*!
\qmlproperty int Flickable::maximumFlickVelocity
This property holds the maximum velocity that the user can flick the view in pixels/second.
+
+ The default is 5000 pixels/s
*/
qreal QFxFlickable::maximumFlickVelocity() const
{
diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp
index f49375a..d4cf691 100644
--- a/src/declarative/fx/qfxgridview.cpp
+++ b/src/declarative/fx/qfxgridview.cpp
@@ -795,10 +795,10 @@ void QFxGridView::setDelegate(QmlComponent *delegate)
/*!
\qmlproperty int GridView::currentIndex
- \qmlproperty Item GridView::current
+ \qmlproperty Item GridView::currentItem
\c currentIndex holds the index of the current item.
- \c current is the current item. Note that the position of the current item
+ \c currentItem is the current item. Note that the position of the current item
may only be approximate until it becomes visible in the view.
*/
int QFxGridView::currentIndex() const
diff --git a/src/declarative/fx/qfxgridview.h b/src/declarative/fx/qfxgridview.h
index 734039c..e08ba9e 100644
--- a/src/declarative/fx/qfxgridview.h
+++ b/src/declarative/fx/qfxgridview.h
@@ -60,7 +60,7 @@ class Q_DECLARATIVE_EXPORT QFxGridView : public QFxFlickable
Q_PROPERTY(QVariant model READ model WRITE setModel)
Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate)
Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
- Q_PROPERTY(QFxItem *current READ currentItem NOTIFY currentIndexChanged) //### currentItem
+ Q_PROPERTY(QFxItem *currentItem READ currentItem NOTIFY currentIndexChanged)
Q_PROPERTY(int count READ count NOTIFY countChanged)
Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight)
Q_PROPERTY(bool autoHighlight READ autoHighlight WRITE setAutoHighlight)
diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp
index 79b3ae1..3ac3f3c 100644
--- a/src/declarative/fx/qfximage.cpp
+++ b/src/declarative/fx/qfximage.cpp
@@ -252,17 +252,12 @@ void QFxImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
if (width() != d->pix.width() || height() != d->pix.height()) {
if (d->fillMode >= Tile) {
- p->save();
- p->setClipRect(0, 0, width(), height(), Qt::IntersectClip);
-
if (d->fillMode == Tile)
p->drawTiledPixmap(QRectF(0,0,width(),height()), d->pix);
else if (d->fillMode == TileVertically)
p->drawTiledPixmap(QRectF(0,0,d->pix.width(),height()), d->pix);
else
p->drawTiledPixmap(QRectF(0,0,width(),d->pix.height()), d->pix);
-
- p->restore();
} else {
qreal widthScale = width() / qreal(d->pix.width());
qreal heightScale = height() / qreal(d->pix.height());
diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp
index a07b3c0..ac9b6ca 100644
--- a/src/declarative/fx/qfxlistview.cpp
+++ b/src/declarative/fx/qfxlistview.cpp
@@ -172,11 +172,11 @@ public:
QFxListViewPrivate()
: model(0), currentItem(0), tmpCurrent(0), orient(Qt::Vertical)
, visiblePos(0), visibleIndex(0)
- , averageSize(100), currentIndex(-1), requestedIndex(-1)
+ , averageSize(100.0), currentIndex(-1), requestedIndex(-1)
, currItemMode(QFxListView::Free), snapPos(0), highlightComponent(0), highlight(0), trackedItem(0)
- , moveReason(Other), buffer(0), highlightPosAnimator(0), highlightSizeAnimator(0), spacing(0)
+ , moveReason(Other), buffer(0), highlightPosAnimator(0), highlightSizeAnimator(0), spacing(0.0)
, ownModel(false), wrap(false), autoHighlight(true)
- , fixCurrentVisibility(false) {}
+ {}
void init();
void clear();
@@ -205,7 +205,7 @@ public:
else
q->setViewportX(pos);
}
- int size() const {
+ qreal size() const {
Q_Q(const QFxListView);
return orient == Qt::Vertical ? q->height() : q->width();
}
@@ -384,12 +384,11 @@ public:
QmlEaseFollow *highlightSizeAnimator;
QString sectionExpression;
QString currentSection;
- int spacing;
+ qreal spacing;
- int ownModel : 1;
- int wrap : 1;
- int autoHighlight : 1;
- int fixCurrentVisibility : 1;
+ bool ownModel : 1;
+ bool wrap : 1;
+ bool autoHighlight : 1;
};
void QFxListViewPrivate::init()
@@ -755,7 +754,6 @@ void QFxListViewPrivate::updateCurrent(int modelIndex)
FxListItem *oldCurrentItem = currentItem;
currentIndex = modelIndex;
currentItem = createItem(modelIndex);
- fixCurrentVisibility = true;
if (oldCurrentItem && (!currentItem || oldCurrentItem->item != currentItem->item))
oldCurrentItem->attached->setIsCurrentItem(false);
if (currentItem) {
@@ -983,10 +981,10 @@ void QFxListView::setDelegate(QmlComponent *delegate)
/*!
\qmlproperty int ListView::currentIndex
- \qmlproperty Item ListView::current
+ \qmlproperty Item ListView::currentItem
\c currentIndex holds the index of the current item.
- \c current is the current item. Note that the position of the current item
+ \c currentItem is the current item. Note that the position of the current item
may only be approximate until it becomes visible in the view.
*/
int QFxListView::currentIndex() const
@@ -1149,13 +1147,13 @@ void QFxListView::setSnapPosition(int pos)
This property holds the spacing to leave between items.
*/
-int QFxListView::spacing() const
+qreal QFxListView::spacing() const
{
Q_D(const QFxListView);
return d->spacing;
}
-void QFxListView::setSpacing(int spacing)
+void QFxListView::setSpacing(qreal spacing)
{
Q_D(QFxListView);
if (spacing != d->spacing) {
@@ -1640,6 +1638,7 @@ void QFxListView::destroyRemoved()
void QFxListView::itemsMoved(int from, int to, int count)
{
Q_D(QFxListView);
+ qreal firstItemPos = d->visibleItems.first()->position();
QHash<int,FxListItem*> moved;
int moveBy = 0;
@@ -1653,11 +1652,9 @@ void QFxListView::itemsMoved(int from, int to, int count)
moveBy += item->size();
it = d->visibleItems.erase(it);
} else {
- if (item->index > from && item->index != -1) {
- // move everything after the moved items.
+ // move everything after the moved items.
+ if (item->index > from && item->index != -1)
item->index -= count;
- item->setPosition(item->position()-moveBy);
- }
++it;
}
}
@@ -1698,6 +1695,9 @@ void QFxListView::itemsMoved(int from, int to, int count)
while (moved.count())
d->releaseItem(moved.take(moved.begin().key()));
+ // Ensure we don't cause an ugly list scroll.
+ d->visibleItems.first()->setPosition(firstItemPos);
+
d->layout();
}
diff --git a/src/declarative/fx/qfxlistview.h b/src/declarative/fx/qfxlistview.h
index 829e202..095c27b 100644
--- a/src/declarative/fx/qfxlistview.h
+++ b/src/declarative/fx/qfxlistview.h
@@ -67,13 +67,13 @@ class Q_DECLARATIVE_EXPORT QFxListView : public QFxFlickable
Q_PROPERTY(QVariant model READ model WRITE setModel)
Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) //### what happens if delegate is not a QFxItem?
Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
- Q_PROPERTY(QFxItem *current READ currentItem NOTIFY currentIndexChanged) //### currentItem
+ Q_PROPERTY(QFxItem *currentItem READ currentItem NOTIFY currentIndexChanged)
Q_PROPERTY(int count READ count NOTIFY countChanged)
Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight)
Q_PROPERTY(bool autoHighlight READ autoHighlight WRITE setAutoHighlight) //### highlightFollowsCurrentItem
Q_PROPERTY(CurrentItemPositioning currentItemPositioning READ currentItemPositioning WRITE setCurrentItemPositioning) //### mode
Q_PROPERTY(int snapPosition READ snapPosition WRITE setSnapPosition)
- Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) //### qreal
+ Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged)
Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
Q_PROPERTY(bool wrap READ isWrapEnabled WRITE setWrapEnabled) //### keyNavigationWraps, stops at end when held
Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer)
@@ -115,8 +115,8 @@ public:
int snapPosition() const;
void setSnapPosition(int pos);
- int spacing() const;
- void setSpacing(int spacing);
+ qreal spacing() const;
+ void setSpacing(qreal spacing);
Qt::Orientation orientation() const;
void setOrientation(Qt::Orientation);