From 1971dbdde166f6e21da6bdceac582ca7bb5c5542 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 1 Jul 2009 09:22:30 +1000 Subject: Replace browser with loaded QML. --- examples/declarative/loader/Browser.qml | 41 +++++++++++++++++++++++++++++++++ examples/declarative/loader/loader.qml | 39 ++----------------------------- examples/declarative/loader/loader.qrc | 1 + 3 files changed, 44 insertions(+), 37 deletions(-) create mode 100644 examples/declarative/loader/Browser.qml diff --git a/examples/declarative/loader/Browser.qml b/examples/declarative/loader/Browser.qml new file mode 100644 index 0000000..af5538e --- /dev/null +++ b/examples/declarative/loader/Browser.qml @@ -0,0 +1,41 @@ +Rect { + id: Root + width: parent.width + height: parent.height + FolderListModel { + id: folders + nameFilters: [ "*.qml" ] + } + + Component { + id: FolderDelegate + Text { + id: Wrapper + width: Root.width + text: fileName + font.bold: true + font.size: 14 + MouseRegion { + anchors.fill: parent + onClicked: { + if (folders.isFolder(index)) { + folders.folder = filePath; + } else { + Shell.qml = filePath; + } + } + } + } + } + + Text { id: DirText; text: folders.folder } + + ListView { + anchors.top: DirText.bottom + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: parent.bottom + model: folders + delegate: FolderDelegate + } +} diff --git a/examples/declarative/loader/loader.qml b/examples/declarative/loader/loader.qml index 4dd7a03..6e4d6ec 100644 --- a/examples/declarative/loader/loader.qml +++ b/examples/declarative/loader/loader.qml @@ -1,41 +1,6 @@ Rect { - id: Root + id: Shell width: 300 height: 400 - FolderListModel { - id: folders - nameFilters: [ "*.qml" ] - } - - Component { - id: FolderDelegate - Text { - id: Wrapper - width: Root.width - text: fileName - font.bold: true - font.size: 14 - MouseRegion { - anchors.fill: parent - onClicked: { - if (folders.isFolder(index)) { - folders.folder = filePath; - } else { - Root.qml = filePath; - } - } - } - } - } - - Text { id: DirText; text: folders.folder } - - ListView { - anchors.top: DirText.bottom - anchors.left: parent.left - anchors.right: parent.right - anchors.bottom: parent.bottom - model: folders - delegate: FolderDelegate - } + qml: "Browser.qml" } diff --git a/examples/declarative/loader/loader.qrc b/examples/declarative/loader/loader.qrc index 8c80052..1f0925f 100644 --- a/examples/declarative/loader/loader.qrc +++ b/examples/declarative/loader/loader.qrc @@ -1,5 +1,6 @@ loader.qml + Browser.qml -- cgit v0.12 From ee44073a48392972f704d36f8794171700dceba4 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 1 Jul 2009 11:57:37 +1000 Subject: FolderListModel fixes. --- src/declarative/extra/qmlfolderlistmodel.cpp | 48 +++++++++++++++++++++------- src/declarative/extra/qmlfolderlistmodel.h | 2 ++ 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/declarative/extra/qmlfolderlistmodel.cpp b/src/declarative/extra/qmlfolderlistmodel.cpp index abec01e..649169b 100644 --- a/src/declarative/extra/qmlfolderlistmodel.cpp +++ b/src/declarative/extra/qmlfolderlistmodel.cpp @@ -51,7 +51,7 @@ QT_MODULE(Declarative) class QmlFolderListModelPrivate : public QObjectPrivate { public: - QmlFolderListModelPrivate() { + QmlFolderListModelPrivate() : count(0) { folder = QDir::currentPath(); nameFilters << "*"; } @@ -60,6 +60,7 @@ public: QString folder; QStringList nameFilters; QModelIndex folderIndex; + int count; }; QmlFolderListModel::QmlFolderListModel(QObject *parent) @@ -69,6 +70,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() @@ -91,9 +97,7 @@ QHash QmlFolderListModel::data(int index, const QList &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 QmlFolderListModel::roles() const @@ -164,22 +168,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 a6e8526..d46ec79 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) -- cgit v0.12 From 9fdcef95dfb369ef490d5be8e4621485d11cddda Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 1 Jul 2009 15:47:19 +1000 Subject: Implement edge resistance for flickable dragging horizontally. --- src/declarative/fx/qfxflickable.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 -- cgit v0.12