diff --git a/src/controls/FileDialog.qml b/src/controls/FileDialog.qml index b9531d6..86eb379 100644 --- a/src/controls/FileDialog.qml +++ b/src/controls/FileDialog.qml @@ -1,280 +1,280 @@ /* * Copyright 2018 Camilo Higuita * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program 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 General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.9 import QtQuick.Controls 2.2 import org.kde.kirigami 2.7 as Kirigami import org.kde.mauikit 1.0 as Maui import QtQuick.Layouts 1.3 Maui.Dialog { id: control maxHeight: Kirigami.Settings.isMobile ? parent.height * 0.95 : Maui.Style.unit * 500 maxWidth: Maui.Style.unit * 700 page.padding: 0 property alias currentPath : browser.currentPath property alias browser : browser property string suggestedFileName : "" property alias settings : browser.settings property bool searchBar : false readonly property var modes : ({OPEN: 0, SAVE: 1}) property int mode : modes.OPEN property var callback : ({}) property alias textField: _textField property alias singleSelection : browser.singleSelection rejectButton.visible: false acceptButton.text: control.mode === modes.SAVE ? qsTr("Save") : qsTr("Open") footBar.leftSretch: false footBar.middleContent: Maui.TextField { id: _textField visible: control.mode === modes.SAVE Layout.fillWidth: true placeholderText: qsTr("File name") text: suggestedFileName } onAccepted: { console.log("CURRENT PATHb", browser.currentPath+"/"+textField.text) if(control.mode === modes.SAVE && Maui.FM.fileExists(browser.currentPath+"/"+textField.text)) { _confirmationDialog.open() }else { done() } } Maui.Dialog { id: _confirmationDialog acceptButton.text: qsTr("Accept") rejectButton.text: qsTr("Cancel") title: qsTr(textField.text+" already exists!") message: qsTr("If you are sure you want to replace the existing file click on Accept, otherwise click on cancel and change the name of the file to something different...") onAccepted: control.done() onRejected: close() } Maui.Page { id: page anchors.fill: parent leftPadding: 0 rightPadding: leftPadding topPadding: leftPadding bottomPadding: leftPadding headBar.implicitHeight: Maui.Style.toolBarHeight + Maui.Style.space.medium Component { id: _pathBarComponent Maui.PathBar { anchors.fill: parent onPathChanged: browser.openFolder(path) url: browser.currentPath onHomeClicked: browser.openFolder(Maui.FM.homePath()) onPlaceClicked: browser.openFolder(path) } } Component { id: _searchFieldComponent Maui.TextField { anchors.fill: parent placeholderText: qsTr("Search for files... ") onAccepted: browser.openFolder("search://"+text) // onCleared: browser.goBack() onGoBackTriggered: { searchBar = false clear() // browser.goBack() } background: Rectangle { border.color: Qt.tint(Kirigami.Theme.textColor, Qt.rgba(Kirigami.Theme.backgroundColor.r, Kirigami.Theme.backgroundColor.g, Kirigami.Theme.backgroundColor.b, 0.7)) radius: Maui.Style.radiusV color: Kirigami.Theme.backgroundColor } } } headBar.leftContent: ToolButton { icon.name: "application-menu" checked: pageRow.currentIndex === 0 onClicked: pageRow.currentIndex = !pageRow.currentIndex } headBar.middleContent: Item { id: _pathBarLoader Layout.fillWidth: true Layout.margins: Maui.Style.space.medium height: Maui.Style.iconSizes.big Loader { anchors.fill: parent sourceComponent: searchBar ? _searchFieldComponent : _pathBarComponent } } headBar.rightContent: ToolButton { id: searchButton icon.name: "edit-find" onClicked: searchBar = !searchBar checked: searchBar } Kirigami.PageRow { id: pageRow anchors.fill: parent clip: true separatorVisible: wideMode initialPage: [sidebar, browser] defaultColumnWidth: Kirigami.Units.gridUnit * (Kirigami.Settings.isMobile? 15 : 8) Maui.PlacesListBrowser { id: sidebar onPlaceClicked: { pageRow.currentIndex = 1 browser.openFolder(path) } list.groups: control.mode === modes.OPEN ? [ Maui.FMList.PLACES_PATH, Maui.FMList.CLOUD_PATH, Maui.FMList.REMOTE_PATH, Maui.FMList.DRIVES_PATH, Maui.FMList.TAGS_PATH] : [Maui.FMList.PLACES_PATH, Maui.FMList.REMOTE_PATH, Maui.FMList.CLOUD_PATH, Maui.FMList.DRIVES_PATH] } Maui.FileBrowser { id: browser previewer.parent: ApplicationWindow.overlay selectionMode: control.mode === modes.OPEN onNewBookmark: { for(var index in paths) sidebar.list.addPlace(paths[index]) } onItemClicked: { switch(control.mode) { case modes.OPEN : { openItem(index) break } case modes.SAVE: { if(Maui.FM.isDir(currentFMList.get(index).path)) openItem(index) else textField.text = currentFMList.get(index).label break } } } onCurrentPathChanged: { sidebar.currentIndex = -1 for(var i = 0; i < sidebar.count; i++) if(String(browser.currentPath) === sidebar.list.get(i).path) { sidebar.currentIndex = i return; } } } } } function show(cb) { if(cb) callback = cb browser.openFolder(browser.currentPath) open() } function closeIt() { - browser.clear() + browser.clearSelection() close() } function done() { var paths = browser.selectionBar && browser.selectionBar.visible ? browser.selectionBar.selectedPaths : browser.currentPath if(control.mode === modes.SAVE) { if (typeof paths == 'string') { paths = paths + "/" + textField.text }else { for(var i in paths) paths[i] = paths[i] + "/" + textField.text } } if(callback) callback(paths) control.closeIt() } } diff --git a/src/controls/ListItemTemplate.qml b/src/controls/ListItemTemplate.qml index 54fe83d..5b4c3aa 100644 --- a/src/controls/ListItemTemplate.qml +++ b/src/controls/ListItemTemplate.qml @@ -1,214 +1,216 @@ /* * Copyright 2018 Camilo Higuita * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program 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 General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.9 import QtQuick.Layouts 1.3 import QtQuick.Controls 2.3 import QtGraphicalEffects 1.0 import org.kde.kirigami 2.7 as Kirigami import org.kde.mauikit 1.0 as Maui Item { id: control property alias label1 : _label1 property alias label2 : _label2 property alias label3 : _label3 property alias label4 : _label4 property alias iconItem : _iconLoader.item property alias iconVisible : _iconContainer.visible property int iconSizeHint : Maui.Style.iconSizes.big property string imageSource property string iconSource property bool isCurrentItem: false Component { id: _imgComponent Item { anchors.fill: parent Image { id: img anchors.centerIn: parent source: control.imageSource height: Math.min(parent.height, control.iconSizeHint) width: height sourceSize.width: width sourceSize.height: height horizontalAlignment: Qt.AlignHCenter verticalAlignment: Qt.AlignVCenter fillMode: Image.PreserveAspectCrop cache: false asynchronous: true smooth: !Kirigami.Settings.isMobile layer.enabled: true layer.effect: OpacityMask { maskSource: Item { width: img.width height: img.height Rectangle { anchors.centerIn: parent width: img.width height: img.height radius: Maui.Style.radiusV } } } } Loader { anchors.centerIn: parent sourceComponent: img.status === Image.Ready ? undefined : _iconComponent } } } Component { id: _iconComponent Kirigami.Icon { source: control.iconSource anchors.centerIn: parent fallback: "qrc:/assets/application-x-zerosize.svg" height: Math.min(parent.height, control.iconSizeHint) width: height } } RowLayout { id: _layout anchors.fill: parent spacing: Maui.Style.space.small Item { id: _iconContainer visible: (control.width > Kirigami.Units.gridUnit * 15) Layout.preferredWidth: Math.max(control.height, control.iconSizeHint) Layout.fillHeight: true Loader { id: _iconLoader height: control.iconSizeHint width: control.iconSizeHint anchors.centerIn: parent sourceComponent: _iconContainer.visible ? (control.imageSource ? _imgComponent : (control.iconSource ? _iconComponent : null) ): null } } ColumnLayout { Layout.fillHeight: visible Layout.fillWidth: visible Layout.margins: Maui.Style.space.small Layout.leftMargin: _iconLoader.visible ? 0 : Maui.Style.space.small + spacing: 0 Label { id: _label1 visible: text.length Layout.fillWidth: visible Layout.fillHeight: visible verticalAlignment: _label2.visible ? Qt.AlignBottom : Qt.AlignVCenter elide: Text.ElideMiddle wrapMode: Text.NoWrap color: control.Kirigami.Theme.textColor font.weight: Font.Normal font.pointSize: Maui.Style.fontSizes.default } Label { id: _label2 visible: text.length Layout.fillWidth: visible Layout.fillHeight: visible font.weight: Font.Normal font.pointSize: Maui.Style.fontSizes.medium wrapMode: Text.NoWrap verticalAlignment: _label1.visible ? Qt.AlignTop : Qt.AlignVCenter elide: Text.ElideRight color: control.Kirigami.Theme.textColor opacity: control.isCurrentItem || hovered ? 0.8 : 0.6 } } ColumnLayout { visible: control.width > Kirigami.Units.gridUnit * 15 Layout.fillHeight: visible Layout.fillWidth: visible Layout.margins: Maui.Style.space.small + spacing: 0 Label { id: _label3 visible: text.length > 0 Layout.fillHeight: visible Layout.fillWidth: visible Layout.alignment: Qt.AlignRight horizontalAlignment: Qt.AlignRight font.pointSize: Maui.Style.fontSizes.small font.weight: Font.Light wrapMode: Text.WrapAnywhere elide: Text.ElideMiddle color: control.Kirigami.Theme.textColor opacity: control.isCurrentItem || hovered ? 0.8 : 0.6 } Label { id: _label4 visible: text.length > 0 Layout.fillHeight: visible Layout.fillWidth: visible Layout.alignment: Qt.AlignRight horizontalAlignment: Qt.AlignRight font.pointSize: Maui.Style.fontSizes.small font.weight: Font.Light wrapMode: Text.WrapAnywhere elide: Text.ElideMiddle color: control.Kirigami.Theme.textColor opacity: control.isCurrentItem || hovered ? 0.8 : 0.6 } } } }