Skip to content

Commit cc9f081

Browse files
committed
Use icon buttons for file selection and creation
Those are smaller and thus fit better on screen size constrained mobile platforms and work fine on desktop as well. Also allows to create snapshot files that way. TODO: - Document and test createDialogLoader logic - Rename saveDialogSupported to saveDialogCanOverwrite?
1 parent a1b13c4 commit cc9f081

File tree

7 files changed

+75
-30
lines changed

7 files changed

+75
-30
lines changed

qml/ConfigPageKits.qml

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -79,32 +79,23 @@ ColumnLayout {
7979
elide: Text.ElideMiddle
8080
}
8181

82-
ColumnLayout {
82+
FileSelect {
83+
id: flashEdit
8384
Layout.fillWidth: true
84-
85-
FileSelect {
86-
id: flashEdit
87-
Layout.fillWidth: true
88-
filePath: kitList.currentItem.myData.flash
89-
onFilePathChanged: {
90-
if(filePath !== kitList.currentItem.myData.flash)
91-
kitModel.setDataRow(kitList.currentIndex, filePath, KitModel.FlashRole);
92-
filePath = Qt.binding(function() { return kitList.currentItem.myData.flash; });
93-
}
94-
}
95-
96-
FlashDialog {
97-
id: flashDialog
98-
onFlashCreated: {
85+
filePath: kitList.currentItem.myData.flash
86+
onFilePathChanged: {
87+
if(filePath !== kitList.currentItem.myData.flash)
9988
kitModel.setDataRow(kitList.currentIndex, filePath, KitModel.FlashRole);
100-
}
89+
filePath = Qt.binding(function() { return kitList.currentItem.myData.flash; });
10190
}
91+
showCreateButton: true
92+
onCreate: flashDialog.visible = true
93+
}
10294

103-
Button {
104-
id: createButton
105-
Layout.alignment: Qt.AlignRight
106-
text: qsTr("New")
107-
onClicked: flashDialog.visible = true
95+
FlashDialog {
96+
id: flashDialog
97+
onFlashCreated: {
98+
kitModel.setDataRow(kitList.currentIndex, filePath, KitModel.FlashRole);
10899
}
109100
}
110101

qml/Firebird/UIComponents/FileSelect.qml

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@ import QtQuick.Layouts 1.0
55
import Firebird.Emu 1.0
66

77
RowLayout {
8-
id: root
98
property string filePath: ""
109
property bool selectExisting: true
10+
property bool showCreateButton: false
11+
signal create()
1112

1213
Loader {
1314
id: dialogLoader
1415
active: false
1516
sourceComponent: FileDialog {
1617
folder: filePath ? Emu.dir(filePath) : Global.lastFileDialogDir
1718
// If save dialogs are not supported, force an open dialog
18-
selectExisting: root.selectExisting || !Emu.saveDialogSupported()
19+
selectExisting: parent.selectExisting || !Emu.saveDialogSupported()
1920
onAccepted: {
2021
filePath = Emu.toLocalFile(fileUrl);
2122
Global.lastFileDialogDir = Emu.dir(filePath);
@@ -38,13 +39,40 @@ RowLayout {
3839
color: (!selectExisting || filePath === "" || Emu.fileExists(filePath)) ? paletteActive.text : "red"
3940
}
4041

41-
Button {
42-
id: selectButton
43-
text: qsTr("Select")
42+
// Button for either custom creation functionality (onCreate) or
43+
// if the open file dialog doesn't allow creation, to open a file creation dialog.
44+
IconButton {
45+
visible: showCreateButton || (!selectExisting && !Emu.saveDialogSupported())
46+
icon: "qrc:/icons/resources/icons/document-new.png"
4447

48+
Loader {
49+
id: createDialogLoader
50+
active: false
51+
sourceComponent: FileDialog {
52+
folder: filePath ? Emu.dir(filePath) : Global.lastFileDialogDir
53+
selectExisting: false
54+
onAccepted: {
55+
filePath = Emu.toLocalFile(fileUrl);
56+
Global.lastFileDialogDir = Emu.dir(filePath);
57+
}
58+
}
59+
}
60+
61+
onClicked: {
62+
if(showCreateButton)
63+
parent.create()
64+
else {
65+
createDialogLoader.active = true;
66+
createDialogLoader.item.visible = true;
67+
}
68+
}
69+
}
70+
71+
IconButton {
72+
icon: "qrc:/icons/resources/icons/document-edit.png"
4573
onClicked: {
46-
dialogLoader.active = true
47-
dialogLoader.item.visible = true
74+
dialogLoader.active = true;
75+
dialogLoader.item.visible = true;
4876
}
4977
}
5078
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import QtQuick 2.0
2+
import QtQuick.Controls 1.0
3+
4+
/* A push button with a symbol instead of text.
5+
* ToolButton and <img/> in Label don't size correctly,
6+
* so do it manually.
7+
* With QQC2, button icons have a better default size
8+
* and it can also be specified explicitly. */
9+
10+
Button {
11+
property alias icon: image.source
12+
13+
implicitHeight: TextMetrics.normalSize * 2.5
14+
implicitWidth: implicitHeight
15+
16+
Image {
17+
id: image
18+
height: parent.height * 0.6
19+
anchors.centerIn: parent
20+
21+
fillMode: Image.PreserveAspectFit
22+
}
23+
}

qml/FlashDialog.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Dialog {
2323
GridLayout {
2424
id: layout
2525
width: parent.width
26-
columns: width > modelCombo.implicitWidth * 2 ? 2 : 1
26+
columns: 2
2727

2828
FBLabel {
2929
Layout.minimumHeight: implicitHeight

resources.qrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
<file>resources/icons/drive-removable-media-usb.png</file>
2323
<file>resources/icons/smartphone.png</file>
2424
<file>resources/icons/video-display.png</file>
25+
<file>resources/icons/document-edit.png</file>
26+
<file>resources/icons/document-new.png</file>
2527
</qresource>
2628
<qresource prefix="/qml">
2729
<file>qml/Keypad.qml</file>
@@ -58,6 +60,7 @@
5860
<file>qml/Firebird/UIComponents/VerticalSwipeBar.qml</file>
5961
<file>qml/Firebird/UIComponents/Global.qml</file>
6062
<file>qml/FlashDialog.qml</file>
63+
<file>qml/Firebird/UIComponents/IconButton.qml</file>
6164
</qresource>
6265
<qresource prefix="/i18n">
6366
<file>i18n/de_DE.qm</file>

resources/icons/document-edit.png

2.89 KB
Loading

resources/icons/document-new.png

2.4 KB
Loading

0 commit comments

Comments
 (0)