Skip to content

Commit

Permalink
WIP: Icon buttons for file selection and creation
Browse files Browse the repository at this point in the history
Saves (horizontal) space, important on phones.

Also allows to create snapshot files that way.

TODO:
- Document and test createDialogLoader logic
- Proper button on desktop
- Rename saveDialogSupported to saveDialogCanOverwrite?
  • Loading branch information
Vogtinator committed Mar 30, 2022
1 parent f16a39a commit cb3796b
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 29 deletions.
35 changes: 13 additions & 22 deletions qml/ConfigPageKits.qml
Original file line number Diff line number Diff line change
Expand Up @@ -78,32 +78,23 @@ ColumnLayout {
elide: Text.ElideMiddle
}

ColumnLayout {
FileSelect {
id: flashEdit
Layout.fillWidth: true

FileSelect {
id: flashEdit
Layout.fillWidth: true
filePath: kitList.currentItem.myData.flash
onFilePathChanged: {
if(filePath !== kitList.currentItem.myData.flash)
kitModel.setDataRow(kitList.currentIndex, filePath, KitModel.FlashRole);
filePath = Qt.binding(function() { return kitList.currentItem.myData.flash; });
}
}

FlashDialog {
id: flashDialog
onFlashCreated: {
filePath: kitList.currentItem.myData.flash
onFilePathChanged: {
if(filePath !== kitList.currentItem.myData.flash)
kitModel.setDataRow(kitList.currentIndex, filePath, KitModel.FlashRole);
}
filePath = Qt.binding(function() { return kitList.currentItem.myData.flash; });
}
showCreateButton: true
onCreate: flashDialog.visible = true
}

Button {
id: createButton
Layout.alignment: Qt.AlignRight
text: qsTr("New")
onClicked: flashDialog.visible = true
FlashDialog {
id: flashDialog
onFlashCreated: {
kitModel.setDataRow(kitList.currentIndex, filePath, KitModel.FlashRole);
}
}

Expand Down
41 changes: 35 additions & 6 deletions qml/Firebird/UIComponents/FileSelect.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import QtQuick.Layouts 1.0
import Firebird.Emu 1.0

RowLayout {
id: root
property string filePath: ""
property bool selectExisting: true
property bool showCreateButton: false
signal create()

Loader {
id: dialogLoader
Expand Down Expand Up @@ -38,13 +39,41 @@ RowLayout {
color: (!selectExisting || filePath === "" || Emu.fileExists(filePath)) ? paletteActive.text : "red"
}

Button {
id: selectButton
text: qsTr("Select")
// Button for either custom creation functionality (onCreate) or
// if the open file dialog doesn't allow creation, to open a file creation dialog.
ToolButton {
text: qsTr("New")
visible: showCreateButton || (!selectExisting && !Emu.saveDialogSupported())
iconSource: "qrc:/icons/resources/icons/document-new.png"
onClicked: {
if(showCreateButton)
parent.create()
else {
createDialogLoader.active = true;
createDialogLoader.item.visible = true;
}
}

Loader {
id: createDialogLoader
active: false
sourceComponent: FileDialog {
folder: filePath ? Emu.dir(filePath) : Global.lastFileDialogDir
selectExisting: false
onAccepted: {
filePath = Emu.toLocalFile(fileUrl);
Global.lastFileDialogDir = Emu.dir(filePath);
}
}
}
}

ToolButton {
text: qsTr("Select")
iconSource: "qrc:/icons/resources/icons/document-edit.png"
onClicked: {
dialogLoader.active = true
dialogLoader.item.visible = true
dialogLoader.active = true;
dialogLoader.item.visible = true;
}
}
}
2 changes: 1 addition & 1 deletion qml/FlashDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Dialog {
GridLayout {
id: layout
width: parent.width
columns: width > modelCombo.implicitWidth * 2 ? 2 : 1
columns: 2

FBLabel {
Layout.minimumHeight: implicitHeight
Expand Down
2 changes: 2 additions & 0 deletions resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<file>resources/icons/drive-removable-media-usb.png</file>
<file>resources/icons/smartphone.png</file>
<file>resources/icons/video-display.png</file>
<file>resources/icons/document-edit.png</file>
<file>resources/icons/document-new.png</file>
</qresource>
<qresource prefix="/qml">
<file>qml/Keypad.qml</file>
Expand Down
Binary file added resources/icons/document-edit.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/document-new.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cb3796b

Please sign in to comment.