moment/src/qml/Base/HFileDialogOpener.qml

48 lines
1.3 KiB
QML
Raw Normal View History

2019-07-16 06:14:08 +10:00
import QtQuick 2.12
import Qt.labs.platform 1.1
Item {
2019-07-16 18:37:39 +10:00
id: opener
2019-07-16 06:14:08 +10:00
anchors.fill: parent
property alias dialog: fileDialog
2019-07-16 18:37:39 +10:00
property string selectedFile: ""
property string file: ""
2019-07-16 06:14:08 +10:00
enum FileType { All, Images }
property int fileType: HFileDialogOpener.FileType.All
2019-07-16 06:14:08 +10:00
TapHandler { onTapped: fileDialog.open() }
FileDialog {
id: fileDialog
property var filters: ({
all: qsTr("All files") + " (*)",
images: qsTr("Image files") +
" (*.jpg *.jpeg *.png *.gif *.bmp *.webp)"
})
nameFilters:
fileType == HFileDialogOpener.FileType.Images ?
[filters.images, filters.all] :
[filters.all]
folder: StandardPaths.writableLocation(
fileType == HFileDialogOpener.FileType.Images ?
StandardPaths.PicturesLocation :
StandardPaths.HomeLocation
)
title: "Select file"
modality: Qt.NonModal
2019-07-16 06:14:08 +10:00
onVisibleChanged: if (visible) {
2019-07-16 18:37:39 +10:00
opener.selectedFile = Qt.binding(() => Qt.resolvedUrl(currentFile))
opener.file = Qt.binding(() => Qt.resolvedUrl(file))
2019-07-16 06:14:08 +10:00
}
2019-07-16 18:37:39 +10:00
onAccepted: { opener.selectedFile = currentFile, opener.file = file }
onRejected: { selectedFile = ""; file = ""}
2019-07-16 06:14:08 +10:00
}
}