Port Qt Quick GUI to Qt 6 and KF6

This commit is contained in:
Martchus 2023-01-31 17:04:18 +01:00
parent e1f753cd89
commit 05e0ad5696
6 changed files with 102 additions and 36 deletions

View File

@ -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)

39
qml/FileDialog5.qml Normal file
View File

@ -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()
}
}

40
qml/FileDialog6.qml Normal file
View File

@ -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()
}
}

View File

@ -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 {

5
resources/qml5.qrc Normal file
View File

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/qml">
<file alias="FileDialog.qml">../qml/FileDialog5.qml</file>
</qresource>
</RCC>

5
resources/qml6.qrc Normal file
View File

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/qml">
<file alias="FileDialog.qml">../qml/FileDialog6.qml</file>
</qresource>
</RCC>