diff --git a/qmlUiKirigami/AlbumDelegate.qml b/qmlUiKirigami/AlbumDelegate.qml --- a/qmlUiKirigami/AlbumDelegate.qml +++ b/qmlUiKirigami/AlbumDelegate.qml @@ -100,7 +100,7 @@ break; } case Koko.Types.Image: { - imageSelected(model.index) + imageSelected( model.sourceIndex) break; } default: { diff --git a/qmlUiKirigami/AlbumView.qml b/qmlUiKirigami/AlbumView.qml --- a/qmlUiKirigami/AlbumView.qml +++ b/qmlUiKirigami/AlbumView.qml @@ -97,7 +97,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 sourceModel: imagesListModel.sourceModel + property int indexValue property int imageWidth property int imageHeight @@ -113,7 +114,19 @@ anchors.fill: parent orientation: Qt.Horizontal snapMode: ListView.SnapOneItem - onMovementEnded: currentImage.index = indexAt(contentX+1, 1); + onMovementEnded: currentImage.index = model.sourceIndex(indexAt(contentX+1, 1)) + + model: Koko.SortModel { + id: imagesListModel + filterRole: Koko.Roles.MimeTypeRole + filterRegExp: /image\// + } + currentIndex: model.proxyIndex( indexValue) + + onCurrentIndexChanged: { + currentImage.index = model.sourceIndex( currentIndex) + listView.positionViewAtIndex(currentIndex, ListView.Beginning) + } delegate: Flickable { id: flick @@ -260,11 +273,7 @@ } } } - - 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,13 +29,16 @@ id: root header: Kirigami.ApplicationHeader {} + /* + * currentImage now stores the information related to the source model + */ QtObject { id: currentImage property int index property var model property GridView view : pageStack.currentItem.flickable onIndexChanged: { - view.currentIndex = currentImage.index + view.currentIndex = view.model.proxyIndex(currentImage.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,8 +175,8 @@ parent: root.overlay.parent width: overlay.width height: overlay.height - currentIndex: currentImage.index - model: currentImage.model + indexValue: currentImage.index + sourceModel: currentImage.model imageWidth: root.width imageHeight: root.height } diff --git a/src/imagelistmodel.h b/src/imagelistmodel.h --- a/src/imagelistmodel.h +++ b/src/imagelistmodel.h @@ -53,7 +53,7 @@ QByteArray query() const; void setQuery(const QByteArray &statement); - Q_INVOKABLE QByteArray queryForIndex(const QModelIndex &index); + Q_INVOKABLE QByteArray queryForIndex(const int &index); void slotLocationGroupChanged(); void slotTimeGroupChanged(); diff --git a/src/imagelistmodel.cpp b/src/imagelistmodel.cpp --- a/src/imagelistmodel.cpp +++ b/src/imagelistmodel.cpp @@ -47,6 +47,7 @@ QHash hash = QAbstractListModel::roleNames(); hash.insert( Roles::ImageUrlRole, "imageurl"); hash.insert( Roles::ItemTypeRole, "itemType"); + hash.insert( Roles::MimeTypeRole, "mimeType"); return hash; } @@ -70,6 +71,11 @@ case Roles::ItemTypeRole: return Types::Image; + case Roles::MimeTypeRole: { + QMimeDatabase db; + QMimeType type = db.mimeTypeForFile( m_images.at(indexValue)); + return type.name(); + } } return QVariant(); @@ -150,12 +156,12 @@ emit queryChanged(); } -QByteArray ImageListModel::queryForIndex(const QModelIndex &index) +QByteArray ImageListModel::queryForIndex(const int& index) { if(m_queryType == Types::LocationQuery) { - return m_locations.at( index.row()).first; + return m_locations.at( index).first; } else if( m_queryType == Types::TimeQuery) { - return m_times.at( index.row()).first; + return m_times.at( index).first; } return QByteArray(); } 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,8 @@ Q_INVOKABLE void clearSelections(); Q_INVOKABLE void selectAll(); Q_INVOKABLE void deleteSelection(); + Q_INVOKABLE int proxyIndex(const int &indexValue); + Q_INVOKABLE int sourceIndex(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(); } } @@ -166,7 +166,6 @@ return m_containImages; } - bool SortModel::hasSelectedImages() { return m_selectionModel->hasSelection(); @@ -239,6 +238,19 @@ trashJob->exec(); } +int SortModel::proxyIndex(const int& indexValue) +{ + if( sourceModel() ) { + return mapFromSource( sourceModel()->index( indexValue, 0, QModelIndex())).row(); + } + return -1; +} + +int SortModel::sourceIndex(const int& indexValue) +{ + return mapToSource( index(indexValue, 0, QModelIndex())).row(); +} + void SortModel::delayedPreview() { QHash::const_iterator i = m_filesToPreview.constBegin();