diff --git a/qmlUiKirigami/AlbumDelegate.qml b/qmlUiKirigami/AlbumDelegate.qml --- a/qmlUiKirigami/AlbumDelegate.qml +++ b/qmlUiKirigami/AlbumDelegate.qml @@ -100,7 +100,8 @@ break; } case Koko.Types.Image: { - imageSelected(model.index) + console.log( "albumdelegate " + model.sourceIndex) + imageSelected(model.sourceIndex) break; } default: { diff --git a/qmlUiKirigami/AlbumView.qml b/qmlUiKirigami/AlbumView.qml --- a/qmlUiKirigami/AlbumView.qml +++ b/qmlUiKirigami/AlbumView.qml @@ -99,7 +99,7 @@ onCollectionSelected: pageStack.push( Qt.resolvedUrl("AlbumView.qml"), { "model": selectedModel, "title": i18n(cover)}) onFolderSelected: pageStack.push( Qt.resolvedUrl("AlbumView.qml"), { "model": selectedModel, "title": i18n(cover)}) onImageSelected: { - currentImage.model = model + currentImage.model = model.sourceModel currentImage.index = currentIndex imageViewer.state = "open"; } diff --git a/qmlUiKirigami/ImageViewer.qml b/qmlUiKirigami/ImageViewer.qml --- a/qmlUiKirigami/ImageViewer.qml +++ b/qmlUiKirigami/ImageViewer.qml @@ -25,12 +25,13 @@ import QtQuick.Layouts 1.3 import QtQuick.Controls 2.0 as Controls import org.kde.kirigami 2.0 as Kirigami +import org.kde.koko 0.1 as Koko Kirigami.Page { id: root - property alias model: listView.model - property alias currentIndex: listView.currentIndex + property alias model: imagesListModel.sourceModel + property int indexValue property int imageWidth property int imageHeight @@ -114,6 +115,18 @@ orientation: Qt.Horizontal snapMode: ListView.SnapOneItem onMovementEnded: currentImage.index = indexAt(contentX+1, 1); + + model: Koko.SortModel { + id: imagesListModel + filterRole: Koko.Roles.MimeTypeRole + filterRegExp: /image\// + } + currentIndex: model.proxyIndex( indexValue) + + onCurrentIndexChanged: { + currentImage.index = model.sourceIndex + listView.positionViewAtIndex(currentIndex, ListView.Beginning) + } delegate: Flickable { id: flick @@ -261,10 +274,6 @@ } } - onCurrentIndexChanged: { - currentImage.index = currentIndex - listView.positionViewAtIndex(currentIndex, ListView.Beginning) - } //FIXME: placeholder, will have to use the state machine Controls.Button { text: i18n("Back") diff --git a/qmlUiKirigami/main.qml b/qmlUiKirigami/main.qml --- a/qmlUiKirigami/main.qml +++ b/qmlUiKirigami/main.qml @@ -29,6 +29,9 @@ id: root header: Kirigami.ApplicationHeader {} + /* + * currentImage now stores the information related to the source model + */ QtObject { id: currentImage property int index @@ -101,6 +104,10 @@ Koko.SortModel{ id: imageFolderModel sourceModel: Koko.ImageFolderModel {} + /* + * filterRole is an Item property exposed by the QSortFilterProxyModel + */ + filterRole: Koko.Roles.MimeTypeRole } Koko.SortModel { @@ -168,7 +175,7 @@ parent: root.overlay.parent width: overlay.width height: overlay.height - currentIndex: currentImage.index + indexValue: currentImage.index model: currentImage.model imageWidth: root.width imageHeight: root.height diff --git a/src/qmlplugins.cpp b/src/qmlplugins.cpp --- a/src/qmlplugins.cpp +++ b/src/qmlplugins.cpp @@ -30,6 +30,7 @@ #include "fileinfo.h" #include "imagelistmodel.h" #include "types.h" +#include "roles.h" #include @@ -49,4 +50,5 @@ qmlRegisterType (uri, 0, 1, "FileInfo"); qmlRegisterType (uri, 0, 1, "ImageListModel"); qmlRegisterUncreatableType(uri, 0, 1, "Types", "Cannot instantiate the Types class"); + qmlRegisterUncreatableType(uri, 0, 1, "Roles", "Cannot instantiate the Roles class"); } diff --git a/src/roles.h b/src/roles.h --- a/src/roles.h +++ b/src/roles.h @@ -24,6 +24,7 @@ class Roles : public QObject { Q_OBJECT + Q_ENUMS(RoleNames) public: Roles(QObject* parent); ~Roles(); diff --git a/src/sortmodel.h b/src/sortmodel.h --- a/src/sortmodel.h +++ b/src/sortmodel.h @@ -56,6 +56,7 @@ Q_INVOKABLE void clearSelections(); Q_INVOKABLE void selectAll(); Q_INVOKABLE void deleteSelection(); + Q_INVOKABLE int proxyIndex(const int &indexValue); protected Q_SLOTS: void setContainImages(bool); diff --git a/src/sortmodel.cpp b/src/sortmodel.cpp --- a/src/sortmodel.cpp +++ b/src/sortmodel.cpp @@ -144,7 +144,7 @@ } case Roles::SourceIndex: { - return mapToSource(index); + return mapToSource(index).row(); } } @@ -239,6 +239,11 @@ trashJob->exec(); } +int SortModel::proxyIndex(const int& indexValue) +{ + return mapFromSource( index( indexValue, 0, QModelIndex())).row(); +} + void SortModel::delayedPreview() { QHash::const_iterator i = m_filesToPreview.constBegin();