diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-07-01 05:55:32 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-07-01 05:55:32 (GMT) |
commit | 1924f31db80328b7445ac37bc8fd8a0263cf166b (patch) | |
tree | fe201dbeaedf119e324ea76e2f530c6b3ea0ac2c /src | |
parent | f1b6711ab742c9ab56304861f2bef01a8beecebc (diff) | |
parent | 9fdcef95dfb369ef490d5be8e4621485d11cddda (diff) | |
download | Qt-1924f31db80328b7445ac37bc8fd8a0263cf166b.zip Qt-1924f31db80328b7445ac37bc8fd8a0263cf166b.tar.gz Qt-1924f31db80328b7445ac37bc8fd8a0263cf166b.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/extra/qmlfolderlistmodel.cpp | 48 | ||||
-rw-r--r-- | src/declarative/extra/qmlfolderlistmodel.h | 2 | ||||
-rw-r--r-- | src/declarative/fx/qfxflickable.cpp | 8 |
3 files changed, 45 insertions, 13 deletions
diff --git a/src/declarative/extra/qmlfolderlistmodel.cpp b/src/declarative/extra/qmlfolderlistmodel.cpp index e6f3b76..8b008a5 100644 --- a/src/declarative/extra/qmlfolderlistmodel.cpp +++ b/src/declarative/extra/qmlfolderlistmodel.cpp @@ -49,7 +49,7 @@ QT_BEGIN_NAMESPACE class QmlFolderListModelPrivate : public QObjectPrivate { public: - QmlFolderListModelPrivate() { + QmlFolderListModelPrivate() : count(0) { folder = QDir::currentPath(); nameFilters << "*"; } @@ -58,6 +58,7 @@ public: QString folder; QStringList nameFilters; QModelIndex folderIndex; + int count; }; QmlFolderListModel::QmlFolderListModel(QObject *parent) @@ -67,6 +68,11 @@ QmlFolderListModel::QmlFolderListModel(QObject *parent) d->model.setFilter(QDir::AllDirs | QDir::Files | QDir::Drives); connect(&d->model, SIGNAL(rowsInserted(const QModelIndex&,int,int)) , this, SLOT(inserted(const QModelIndex&,int,int))); + connect(&d->model, SIGNAL(rowsRemoved(const QModelIndex&,int,int)) + , this, SLOT(removed(const QModelIndex&,int,int))); + connect(&d->model, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)) + , this, SLOT(dataChanged(const QModelIndex&,const QModelIndex&))); + connect(&d->model, SIGNAL(modelReset()), this, SLOT(refresh())); } QmlFolderListModel::~QmlFolderListModel() @@ -89,9 +95,7 @@ QHash<int,QVariant> QmlFolderListModel::data(int index, const QList<int> &roles) int QmlFolderListModel::count() const { Q_D(const QmlFolderListModel); - if (!d->folderIndex.isValid()) - return 0; - return d->model.rowCount(d->folderIndex); + return d->count; } QList<int> QmlFolderListModel::roles() const @@ -162,22 +166,42 @@ bool QmlFolderListModel::isFolder(int index) const void QmlFolderListModel::refresh() { Q_D(QmlFolderListModel); - int prevCount = count(); d->folderIndex = QModelIndex(); - if (prevCount) - emit itemsRemoved(0, prevCount); + if (d->count) { + int tmpCount = d->count; + d->count = 0; + emit itemsRemoved(0, tmpCount); + } d->folderIndex = d->model.index(d->folder); - qDebug() << "count" << count(); - if (count()) - emit itemsInserted(0, count()); + d->count = d->model.rowCount(d->folderIndex); + if (d->count) { + emit itemsInserted(0, d->count); + } } void QmlFolderListModel::inserted(const QModelIndex &index, int start, int end) { Q_D(QmlFolderListModel); - qDebug() << "inserted" << start << end; - if (index == d->folderIndex) + if (index == d->folderIndex) { + d->count = d->model.rowCount(d->folderIndex); emit itemsInserted(start, end - start + 1); + } +} + +void QmlFolderListModel::removed(const QModelIndex &index, int start, int end) +{ + Q_D(QmlFolderListModel); + if (index == d->folderIndex) { + d->count = d->model.rowCount(d->folderIndex); + emit itemsRemoved(start, end - start + 1); + } +} + +void QmlFolderListModel::dataChanged(const QModelIndex &start, const QModelIndex &end) +{ + Q_D(QmlFolderListModel); + if (start.parent() == d->folderIndex) + emit itemsChanged(start.row(), end.row() - start.row() + 1, roles()); } QML_DEFINE_TYPE(QmlFolderListModel,FolderListModel) diff --git a/src/declarative/extra/qmlfolderlistmodel.h b/src/declarative/extra/qmlfolderlistmodel.h index dc520f1..8c99b22 100644 --- a/src/declarative/extra/qmlfolderlistmodel.h +++ b/src/declarative/extra/qmlfolderlistmodel.h @@ -88,6 +88,8 @@ Q_SIGNALS: private Q_SLOTS: void refresh(); void inserted(const QModelIndex &index, int start, int end); + void removed(const QModelIndex &index, int start, int end); + void dataChanged(const QModelIndex &start, const QModelIndex &end); private: Q_DECLARE_PRIVATE(QmlFolderListModel) diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp index 3580edb..a82385a 100644 --- a/src/declarative/fx/qfxflickable.cpp +++ b/src/declarative/fx/qfxflickable.cpp @@ -597,7 +597,13 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) int dx = int(event->pos().x() - pressPos.x()); if (qAbs(dx) > FlickThreshold || pressTime.elapsed() > 200) { qreal newX = dx + pressX; - if (q->overShoot() || (newX <= q->minXExtent() && newX >= q->maxXExtent())) { + const qreal minX = q->minXExtent(); + const qreal maxX = q->maxXExtent(); + if (newX > minX) + newX = minX + (newX - minX) / 2; + if (newX < maxX && maxX - minX < 0) + newX = maxX + (newX - maxX) / 2; + if (q->overShoot() || (newX <= minX && newX >= maxX)) { if (dragMode == QFxFlickable::Hard) _moveX.setValue(newX); else |