diff --git a/CMakeLists.txt b/CMakeLists.txt index 5960960..4b2bd88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -155,6 +155,19 @@ if (QUICK_GUI) list(APPEND ADDITIONAL_KF_MODULES Kirigami2) endif () +# add Qt-version-specific QML files +unset(QML_FILE) +if (NOT QT_PACKAGE_PREFIX) + set(QML_FILE "resources/qml5.qrc") +elseif (QT_PACKAGE_PREFIX MATCHES ".*Qt([0-9]+).*") + set(QML_FILE "resources/qml${CMAKE_MATCH_1}.qrc") +endif () +if (NOT QML_FILE) + message(FATAL_ERROR "Unable to add Qt-version-specific resource file for QT_PACKAGE_PREFIX \"${QT_PACKAGE_PREFIX}\".") +endif () +message(STATUS "Adding Qt-version-specific resource file \"${QML_FILE}\" to build") +list(APPEND QML_SRC_FILES "${QML_FILE}") + # apply further configuration if (WIDGETS_GUI OR QUICK_GUI) include(QtGuiConfig) diff --git a/qml/FileDialog5.qml b/qml/FileDialog5.qml new file mode 100644 index 0000000..6ac6a8c --- /dev/null +++ b/qml/FileDialog5.qml @@ -0,0 +1,39 @@ +import QtQuick.Dialogs 1.3 + +FileDialog { + id: fileDialog + property bool createNewFile: false + title: selectExisting ? qsTr("Select an existing file") : (saveAs ? qsTr("Select path to save file") : qsTr("Select path for new file")) + onAccepted: { + if (fileUrls.length < 1) { + return + } + nativeInterface.handleFileSelectionAccepted(fileUrls[0], "", + this.selectExisting, + this.createNewFile) + } + onRejected: nativeInterface.handleFileSelectionCanceled() + + function show() { + if (nativeInterface.showNativeFileDialog(this.selectExisting, this.createNewFile)) { + return + } + // fallback to the Qt Quick file dialog if a native implementation is not available + this.open() + } + function openExisting() { + this.selectExisting = true + this.createNewFile = false + this.show() + } + function createNew() { + this.selectExisting = false + this.createNewFile = true + this.show() + } + function saveAs() { + this.selectExisting = false + this.createNewFile = false + this.show() + } +} diff --git a/qml/FileDialog6.qml b/qml/FileDialog6.qml new file mode 100644 index 0000000..03804c7 --- /dev/null +++ b/qml/FileDialog6.qml @@ -0,0 +1,40 @@ +import QtQuick.Dialogs as Dialogs + +Dialogs.FileDialog { + id: fileDialog + property bool createNewFile: false + property bool selectExisting: fileMode !== Dialogs.FileDialog.SaveFile + title: selectExisting ? qsTr("Select an existing file") : (!createNewFile ? qsTr("Select path to save file") : qsTr("Select path for new file")) + onAccepted: { + if (selectedFiles.length < 1) { + return + } + nativeInterface.handleFileSelectionAccepted(selectedFiles[0], "", + this.selectExisting, + this.createNewFile) + } + onRejected: nativeInterface.handleFileSelectionCanceled() + + function show() { + if (nativeInterface.showNativeFileDialog(this.selectExisting, this.createNewFile)) { + return + } + // fallback to the Qt Quick file dialog if a native implementation is not available + this.open() + } + function openExisting() { + this.fileMode = Dialogs.FileDialog.OpenFile + this.createNewFile = false + this.show() + } + function createNew() { + this.fileMode = Dialogs.FileDialog.SaveFile + this.createNewFile = true + this.show() + } + function saveAs() { + this.fileMode = Dialogs.FileDialog.SaveFile + this.createNewFile = false + this.show() + } +} diff --git a/qml/main.qml b/qml/main.qml index 665aae4..d4d9481 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -2,7 +2,6 @@ import QtQuick 2.7 import QtQuick.Templates 2.0 as T2 import QtQuick.Controls 2.1 as Controls import QtQuick.Layouts 1.2 -import QtQuick.Dialogs 1.3 import org.kde.kirigami 2.4 as Kirigami Kirigami.ApplicationWindow { @@ -257,41 +256,6 @@ Kirigami.ApplicationWindow { FileDialog { id: fileDialog - property bool createNewFile: false - title: selectExisting ? qsTr("Select an existing file") : (saveAs ? qsTr("Select path to save file") : qsTr("Select path for new file")) - onAccepted: { - if (fileUrls.length < 1) { - return - } - nativeInterface.handleFileSelectionAccepted(fileUrls[0], "", - this.selectExisting, - this.createNewFile) - } - onRejected: nativeInterface.handleFileSelectionCanceled() - - function show() { - if (nativeInterface.showNativeFileDialog(this.selectExisting, - this.createNewFile)) { - return - } - // fallback to the Qt Quick file dialog if a native implementation is not available - this.open() - } - function openExisting() { - this.selectExisting = true - this.createNewFile = false - this.show() - } - function createNew() { - this.selectExisting = false - this.createNewFile = true - this.show() - } - function saveAs() { - this.selectExisting = false - this.createNewFile = false - this.show() - } } BasicDialog { diff --git a/resources/qml5.qrc b/resources/qml5.qrc new file mode 100644 index 0000000..ee19d9f --- /dev/null +++ b/resources/qml5.qrc @@ -0,0 +1,5 @@ + + + ../qml/FileDialog5.qml + + diff --git a/resources/qml6.qrc b/resources/qml6.qrc new file mode 100644 index 0000000..58bf379 --- /dev/null +++ b/resources/qml6.qrc @@ -0,0 +1,5 @@ + + + ../qml/FileDialog6.qml + +