Skip to content

Commit

Permalink
FEXQonfig: Add Qt 6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
neobrain committed Aug 21, 2024
1 parent d585063 commit ed0c045
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 27 deletions.
7 changes: 5 additions & 2 deletions Source/Tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ if (NOT MINGW_BUILD)
if (BUILD_FEXCONFIG)
add_subdirectory(FEXConfig/)

find_package(Qt5 COMPONENTS Qml Quick Widgets)
if (Qt5_FOUND)
find_package(Qt6 COMPONENTS Qml Quick Widgets)
if (NOT Qt6_FOUND)
find_package(Qt5 COMPONENTS Qml Quick Widgets)
endif()
if (Qt6_FOUND OR Qt5_FOUND)
add_subdirectory(FEXQonfig/)
endif()
endif()
Expand Down
10 changes: 8 additions & 2 deletions Source/Tools/FEXQonfig/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
set(CMAKE_AUTOMOC ON)
qt_add_resources(QT_RESOURCES qml.qrc)

add_executable(FEXQonfig)
target_sources(FEXQonfig PRIVATE Main.cpp ConfigModel.h ${QT_RESOURCES})
target_include_directories(FEXQonfig PRIVATE ${CMAKE_SOURCE_DIR}/Source/)
target_link_libraries(FEXQonfig PRIVATE Common)
target_link_libraries(FEXQonfig PRIVATE Qt5::Qml Qt5::Quick Qt5::Widgets)
if (Qt6_FOUND)
qt_add_resources(QT_RESOURCES qml6.qrc)
target_link_libraries(FEXQonfig PRIVATE Qt6::Qml Qt6::Quick Qt6::Widgets)
else()
qt_add_resources(QT_RESOURCES qml5.qrc)
target_link_libraries(FEXQonfig PRIVATE Qt5::Qml Qt5::Quick Qt5::Widgets)
endif()
target_sources(FEXQonfig PRIVATE ${QT_RESOURCES})

if (CMAKE_BUILD_TYPE MATCHES "RELEASE")
target_link_options(FEXQonfig
Expand Down
41 changes: 23 additions & 18 deletions Source/Tools/FEXQonfig/main.qml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Dialogs 1.3
import QtQuick.Layouts 1.15

import FEX.ConfigModel 1.0
import FEX.EnvVarModel 1.0
import FEX.RootFSModel 1.0

// Qt 6 changed the API of the Dialogs module slightly.
// The differences are abstracted away in this import:
import "qrc:/dialogs"

ApplicationWindow {
id: root

Expand Down Expand Up @@ -43,33 +46,35 @@ ApplicationWindow {
id: openFileDialog
title: qsTr("Open FEX configuration")
nameFilters: [ "Config files(*.json)", "All files(*)" ]
// TODO: Set default folder to ~/.fex-emu?
folder: "file:///home/tony/.fex-emu/"

onAccepted: {
root.selectedConfigFile(fileUrl)
configFilename = fileUrl
root.selectedConfigFile(selectedFile)
configFilename = selectedFile
}
}

MessageDialog {
id: confirmCloseDialog
title: qsTr("Save changes")
text: configFilename.toString() === "" ? qsTr("Save changes before quitting?") : qsTr("Save changes to %1 before quitting?").arg(urlToLocalFile(configFilename))
standardButtons: StandardButton.Save | StandardButton.Discard | StandardButton.Cancel

onAccepted: {
save(configFilename)
root.close()
}

onDiscard: {
closeConfirmed = true
root.close()
enabledButtons: buttonSave | buttonDiscard | buttonCancel

onButtonClicked: (button) => {
switch (button) {
case buttonSave:
save(configFilename)
root.close()
break

case buttonDiscard:
closeConfirmed = true
root.close()
break
}
}
}

onClosing: {
onClosing: (close) => {
if (configDirty) {
close.accepted = closeConfirmed
onTriggered: confirmCloseDialog.open()
Expand Down Expand Up @@ -200,13 +205,13 @@ ApplicationWindow {
component ConfigTextFieldForPath: RowLayout {
property string text
property string config
property bool isFolder: false
property bool isFolder: false // TODO: Implement

FileDialog {
id: fileSelectorDialog
onAccepted: {
configDirty = true
ConfigModel.setString(config, urlToLocalFile(fileUrl))
ConfigModel.setString(config, urlToLocalFile(selectedFile))
}
}

Expand Down
5 changes: 0 additions & 5 deletions Source/Tools/FEXQonfig/qml.qrc

This file was deleted.

9 changes: 9 additions & 0 deletions Source/Tools/FEXQonfig/qml5.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
</qresource>
<qresource prefix="/dialogs">
<file alias="FileDialog.qml">qt5/FileDialog.qml</file>
<file alias="MessageDialog.qml">qt5/MessageDialog.qml</file>
</qresource>
</RCC>
9 changes: 9 additions & 0 deletions Source/Tools/FEXQonfig/qml6.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
</qresource>
<qresource prefix="/dialogs">
<file alias="FileDialog.qml">qt6/FileDialog.qml</file>
<file alias="MessageDialog.qml">qt6/MessageDialog.qml</file>
</qresource>
</RCC>
7 changes: 7 additions & 0 deletions Source/Tools/FEXQonfig/qt5/FileDialog.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import QtQuick.Dialogs 1.3 as FromQt

FromQt.FileDialog {
property url selectedFile

onAccepted: selectedFile = fileUrl
}
17 changes: 17 additions & 0 deletions Source/Tools/FEXQonfig/qt5/MessageDialog.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import QtQuick.Dialogs 1.3 as FromQt

FromQt.MessageDialog {
readonly property int buttonSave: FromQt.Dialog.Save
readonly property int buttonDiscard: FromQt.Dialog.Discard
readonly property int buttonCancel: FromQt.Dialog.Cancel

property var enabledButtons

standardButtons: enabledButtons

signal buttonClicked(button: int)

onAccepted: buttonClicked(buttonSave)
onDiscard: buttonClicked(buttonDiscard)
onRejected: buttonClicked(buttonCancel)
}
3 changes: 3 additions & 0 deletions Source/Tools/FEXQonfig/qt6/FileDialog.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import QtQuick.Dialogs as FromQt

FromQt.FileDialog {}
10 changes: 10 additions & 0 deletions Source/Tools/FEXQonfig/qt6/MessageDialog.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import QtQuick.Dialogs as FromQt

FromQt.MessageDialog {
readonly property int buttonSave: MessageDialog.Save
readonly property int buttonDiscard: MessageDialog.Discard
readonly property int buttonCancel: MessageDialog.Cancel

property var enabledButtons
buttons: enabledButtons
}

0 comments on commit ed0c045

Please sign in to comment.