diff --git a/qmlUiKirigami/AlbumDelegate.qml b/qmlUiKirigami/AlbumDelegate.qml index 5ddc055..046b5d6 100644 --- a/qmlUiKirigami/AlbumDelegate.qml +++ b/qmlUiKirigami/AlbumDelegate.qml @@ -1,125 +1,128 @@ /* * Copyright (C) 2017 Atul Sharma * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . * */ import QtQuick 2.7 import QtQuick.Controls 2.1 as Controls import org.kde.kquickcontrolsaddons 2.0 as KQA import org.kde.kirigami 2.1 as Kirigami import org.kde.koko 0.1 as Koko Item { id: albumDelegate width: gridView.cellWidth height: gridView.cellHeight KQA.QImageItem { id: image anchors.centerIn: parent width: gridView.cellWidth - (Kirigami.Units.smallSpacing * 2 ) height: width smooth: true image: model.thumbnail fillMode: KQA.QImageItem.PreserveAspectCrop } Rectangle { visible: model.itemType == Koko.Types.Folder || model.itemType == Koko.Types.Album width: image.width height: textLabel.contentHeight + (Kirigami.Units.smallSpacing * 2) color: Kirigami.Theme.viewBackgroundColor anchors.top: image.top anchors.left: image.left opacity: 0.8 Controls.Label { id: textLabel anchors.fill: parent padding: Kirigami.Units.smallSpacing wrapMode: Text.WordWrap color: Kirigami.Theme.textColor text: model.fileCount ? i18np("%2 \n 1 Image", "%2 \n %1 Images", model.fileCount, model.display) : model.display } } SelectionButton { id: selectionButton - visible: ( albumThumbnailMouseArea.containsMouse || iconMouseArea.containsMouse ) && !(model.itemType == Koko.Types.Folder || model.itemType == Koko.Types.Album) + visible: ( albumThumbnailMouseArea.containsMouse || iconMouseArea.containsMouse || page.state == "selecting") && !(model.itemType == Koko.Types.Folder || model.itemType == Koko.Types.Album) } SelectionDelegateHighlight { id: selectionHighlight visible: model.selected } - + MouseArea { id: albumThumbnailMouseArea anchors.fill: parent hoverEnabled: true + onPressAndHold: { + gridView.model.toggleSelected(model.index) + } onClicked: { - if ((mouse.modifiers & Qt.ControlModifier ) && (model.itemType == Koko.Types.Image)) { + if (page.state == "selecting" || (mouse.modifiers & Qt.ControlModifier ) && (model.itemType == Koko.Types.Image)) { gridView.model.toggleSelected(model.index) } else { activate(); } } } Keys.onPressed: { switch (event.key) { case Qt.Key_Enter: case Qt.Key_Return: case Qt.Key_Space: activate(); break; default: break; } } function activate( ) { gridView.model.clearSelections() gridView.currentIndex = model.index; switch( model.itemType) { case Koko.Types.Album: { imageListModel.query = imageListModel.queryForIndex( model.sourceIndex) sortedListModel.sourceModel = imageListModel collectionSelected( sortedListModel, model.display) break; } case Koko.Types.Folder: { imageFolderModel.url = model.imageurl sortedListModel.sourceModel = imageFolderModel folderSelected( sortedListModel, model.display) break; } case Koko.Types.Image: { imageSelected( model.sourceIndex) break; } default: { console.log("Unknown") break; } } } } diff --git a/qmlUiKirigami/AlbumView.qml b/qmlUiKirigami/AlbumView.qml index f325937..51bf89c 100644 --- a/qmlUiKirigami/AlbumView.qml +++ b/qmlUiKirigami/AlbumView.qml @@ -1,108 +1,129 @@ /* * Copyright (C) 2017 Atul Sharma * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . * */ import QtQuick 2.7 import QtQuick.Controls 2.1 as Controls import org.kde.kirigami 2.1 as Kirigami import org.kde.koko 0.1 as Koko Kirigami.ScrollablePage { id: page property alias model: gridView.model signal collectionSelected(QtObject selectedModel, string cover) signal imageSelected(int currentIndex) signal folderSelected(QtObject selectedModel, string cover) keyboardNavigationEnabled: true focus: true - - contextualActions: [ - Kirigami.Action { - iconName: "edit-select-all" - text: i18n("Select All") - tooltip: i18n("Selects all the images in the current view") - enabled: model.containImages - onTriggered: model.selectAll() - }, - Kirigami.Action { - iconName: "edit-select-none" - text: i18n("Deselect All") - tooltip: i18n("De-selects all the selected images") - enabled: model.hasSelectedImages - onTriggered: model.clearSelections() + + states: [ + State { + name: "browsing" + when: !model.hasSelectedImages }, - Kirigami.Action { - iconName: "group-delete" - text: i18n("Delete Selection") - tooltip: i18n("Move selected items to trash") - enabled: model.hasSelectedImages - onTriggered: model.deleteSelection() + State { + name: "selecting" + when: model.hasSelectedImages && Kirigami.Settings.isMobile } - ] + actions { + main: Kirigami.Action { + iconName: "edit-select-none" + text: i18n("Deselect All") + tooltip: i18n("De-selects all the selected images") + enabled: model.hasSelectedImages + visible: model.hasSelectedImages && Kirigami.Settings.isMobile + onTriggered: model.clearSelections() + } + contextualActions: [ + Kirigami.Action { + iconName: "edit-select-all" + text: i18n("Select All") + tooltip: i18n("Selects all the images in the current view") + enabled: model.containImages + onTriggered: model.selectAll() + }, + Kirigami.Action { + iconName: "edit-select-none" + text: i18n("Deselect All") + tooltip: i18n("De-selects all the selected images") + enabled: model.hasSelectedImages + onTriggered: model.clearSelections() + }, + Kirigami.Action { + iconName: "group-delete" + text: i18n("Delete Selection") + tooltip: i18n("Move selected items to trash") + enabled: model.hasSelectedImages + onTriggered: model.deleteSelection() + } + + ] + } + background: Rectangle { color: Kirigami.Theme.viewBackgroundColor } Keys.onPressed: { switch (event.key) { case Qt.Key_Escape: gridView.model.clearSelections() break; default: break; } } leftPadding: (page.width - Math.floor(page.width / gridView.cellWidth) * gridView.cellWidth)/2 rightPadding: leftPadding GridView { id: gridView //FIXME: right now if those two objects are out of this, the whole page breaks Koko.SortModel { id: sortedListModel } Koko.ImageFolderModel { id: imageFolderModel } keyNavigationEnabled: true cellWidth: Kirigami.Units.iconSizes.enormous + Kirigami.Units.smallSpacing * 2 cellHeight: cellWidth highlight: Rectangle { color: Kirigami.Theme.highlightColor} delegate: AlbumDelegate {} } 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.sourceModel currentImage.index = currentIndex imageViewer.state = "open"; } }