summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2009-09-11 05:54:49 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2009-09-11 05:54:49 (GMT)
commitf7982be51ec5872dba11d87ea653b791251a0215 (patch)
tree556dad915f8ffba2c388dba2750e48d52962f71f
parentefc7963a15c204db48cb3b6560366410b640e5c3 (diff)
parente4648700e7e3c84c61d6b012f7d480394b889c31 (diff)
downloadQt-f7982be51ec5872dba11d87ea653b791251a0215.zip
Qt-f7982be51ec5872dba11d87ea653b791251a0215.tar.gz
Qt-f7982be51ec5872dba11d87ea653b791251a0215.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
-rw-r--r--examples/declarative/listview/content/ClickAutoRepeating.qml29
-rw-r--r--examples/declarative/listview/dynamic.qml7
-rw-r--r--examples/declarative/listview/highlight.qml2
-rw-r--r--examples/declarative/loader/Browser.qml2
-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/qfxlistview.cpp36
-rw-r--r--src/declarative/fx/qfxlistview.h8
-rw-r--r--src/declarative/util/qmllistmodel.cpp5
11 files changed, 87 insertions, 40 deletions
diff --git a/examples/declarative/listview/content/ClickAutoRepeating.qml b/examples/declarative/listview/content/ClickAutoRepeating.qml
new file mode 100644
index 0000000..19dd6f6
--- /dev/null
+++ b/examples/declarative/listview/content/ClickAutoRepeating.qml
@@ -0,0 +1,29 @@
+import Qt 4.6
+
+Item {
+ id: Page
+ property int repeatdelay: 300
+ property int repeatperiod: 75
+ property bool pressed: false
+ signal pressed
+ signal released
+ signal clicked
+ pressed: SequentialAnimation {
+ id: AutoRepeat
+ PropertyAction { target: Page; property: "pressed"; value: true }
+ ScriptAction { script: Page.onPressed }
+ ScriptAction { script: Page.onClicked }
+ PauseAnimation { duration: repeatdelay }
+ SequentialAnimation {
+ repeat: true
+ ScriptAction { script: Page.onClicked }
+ PauseAnimation { duration: repeatperiod }
+ }
+ }
+ MouseRegion {
+ id: MR
+ anchors.fill: parent
+ onPressed: AutoRepeat.start()
+ onReleased: { AutoRepeat.stop(); parent.pressed = false; Page.released }
+ }
+}
diff --git a/examples/declarative/listview/dynamic.qml b/examples/declarative/listview/dynamic.qml
index f615c24..dde24f6 100644
--- a/examples/declarative/listview/dynamic.qml
+++ b/examples/declarative/listview/dynamic.qml
@@ -1,4 +1,5 @@
import Qt 4.6
+import "content"
Item {
width: 320
@@ -75,10 +76,12 @@ Item {
anchors.right: parent.right
width: childrenRect.width
Image { source: "content/pics/add.png"
- MouseRegion { anchors.fill: parent; onClicked: FruitModel.set(index,"cost",Number(cost)+0.25) }
+ ClickAutoRepeating { id: ClickUp; anchors.fill: parent; onClicked: FruitModel.set(index,"cost",Number(cost)+0.25) }
+ scale: ClickUp.pressed ? 0.9 : 1
}
Image { source: "content/pics/del.png"
- MouseRegion { anchors.fill: parent; onClicked: FruitModel.set(index,"cost",Number(cost)-0.25) }
+ ClickAutoRepeating { id: ClickDown; anchors.fill: parent; onClicked: FruitModel.set(index,"cost",Math.max(0,Number(cost)-0.25)) }
+ scale: ClickDown.pressed ? 0.9 : 1
}
Image { source: "content/pics/trash.png"
MouseRegion { anchors.fill: parent; onClicked: FruitModel.remove(index) }
diff --git a/examples/declarative/listview/highlight.qml b/examples/declarative/listview/highlight.qml
index e707ac0..cb92ad9 100644
--- a/examples/declarative/listview/highlight.qml
+++ b/examples/declarative/listview/highlight.qml
@@ -44,7 +44,7 @@ Rectangle {
id: PetHighlight
Rectangle {
width: 200; height: 50; color: "#FFFF88"
- y: SpringFollow { source: List1.current.y; spring: 3; damping: 0.1 }
+ y: SpringFollow { source: List1.currentItem.y; spring: 3; damping: 0.1 }
}
}
ListView {
diff --git a/examples/declarative/loader/Browser.qml b/examples/declarative/loader/Browser.qml
index 196cdc5..6711de4 100644
--- a/examples/declarative/loader/Browser.qml
+++ b/examples/declarative/loader/Browser.qml
@@ -82,7 +82,7 @@ Rectangle {
focus: true
Keys.onPressed: {
if (event.key == Qt.Key_Return || event.key == Qt.Key_Select) {
- View.current.launch();
+ View.currentItem.launch();
event.accepted = true;
}
}
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/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);
diff --git a/src/declarative/util/qmllistmodel.cpp b/src/declarative/util/qmllistmodel.cpp
index 345bc3b..69bed25 100644
--- a/src/declarative/util/qmllistmodel.cpp
+++ b/src/declarative/util/qmllistmodel.cpp
@@ -499,6 +499,9 @@ void QmlListModel::move(int from, int to, int n)
{
if (from+n > count() || to+n > count() || n==0 || from==to || from < 0 || to < 0)
return;
+ int origfrom=from; // preserve actual move, so any animations are correct
+ int origto=to;
+ int orign=n;
if (from > to) {
// Only move forwards - flip if backwards moving
int tfrom = from;
@@ -524,7 +527,7 @@ void QmlListModel::move(int from, int to, int n)
for (; f != replaced.end(); ++f, ++t)
*t = *f;
}
- emit itemsMoved(from,to,n);
+ emit itemsMoved(origfrom,origto,orign);
}
/*!