add proper fileDialog

This makes it so the editor page can change the image you are using.
This commit is contained in:
Chris Cochrun 2023-03-12 06:32:25 -05:00
parent 58a85bcc01
commit a543d8b9bc

View file

@ -56,42 +56,42 @@ Item {
text: "Select Image" text: "Select Image"
icon.name: "fileopen" icon.name: "fileopen"
hoverEnabled: true hoverEnabled: true
onClicked: backgroundType.open() onClicked: fileDialog.open()
} }
Controls.Popup { /* Controls.Popup { */
id: backgroundType /* id: backgroundType */
x: backgroundButton.x /* x: backgroundButton.x */
y: backgroundButton.y + backgroundButton.height + 20 /* y: backgroundButton.y + backgroundButton.height + 20 */
modal: true /* modal: true */
focus: true /* focus: true */
dim: false /* dim: false */
background: Rectangle { /* background: Rectangle { */
Kirigami.Theme.colorSet: Kirigami.Theme.Tooltip /* Kirigami.Theme.colorSet: Kirigami.Theme.Tooltip */
color: Kirigami.Theme.backgroundColor /* color: Kirigami.Theme.backgroundColor */
radius: 10 /* radius: 10 */
border.color: Kirigami.Theme.activeBackgroundColor /* border.color: Kirigami.Theme.activeBackgroundColor */
border.width: 2 /* border.width: 2 */
} /* } */
closePolicy: Controls.Popup.CloseOnEscape | Controls.Popup.CloseOnPressOutsideParent /* closePolicy: Controls.Popup.CloseOnEscape | Controls.Popup.CloseOnPressOutsideParent */
ColumnLayout { /* ColumnLayout { */
anchors.fill: parent /* anchors.fill: parent */
Controls.ToolButton { /* Controls.ToolButton { */
Layout.fillHeight: true /* Layout.fillHeight: true */
Layout.fillWidth: true /* Layout.fillWidth: true */
text: "Image" /* text: "Image" */
icon.name: "emblem-images-symbolic" /* icon.name: "emblem-images-symbolic" */
onClicked: imageFileDialog.open() & backgroundType.close() /* onClicked: imageFileDialog.open() & backgroundType.close() */
} /* } */
Controls.ToolButton { /* Controls.ToolButton { */
Layout.fillWidth: true /* Layout.fillWidth: true */
Layout.fillHeight: true /* Layout.fillHeight: true */
text: "Image" /* text: "Image" */
icon.name: "folder-pictures-symbolic" /* icon.name: "folder-pictures-symbolic" */
onClicked: imageFileDialog.open() & backgroundType.close() /* onClicked: imageFileDialog.open() & backgroundType.close() */
} /* } */
} /* } */
} /* } */
} }
} }
@ -134,7 +134,21 @@ Item {
cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.IBeamCursor cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.IBeamCursor
} }
} }
}
}
FileDialog {
id: fileDialog
title: "Please choose a background"
folder: shortcuts.home
selectMultiple: false
nameFilters: ["Image files (*.jpg *.jpeg *.png *.JPG *.JPEG *.PNG *.webp *.gif)"]
onAccepted: {
updateImage(fileDialog.fileUrls[0]);
console.log("image background = " + fileDialog.fileUrls[0]);
}
onRejected: {
console.log("Canceled")
} }
} }
@ -146,8 +160,8 @@ Item {
function updateTitle(text) { function updateTitle(text) {
changeTitle(text, false); changeTitle(text, false);
imagesqlmodel.updateTitle(image.id, text); imageProxyModel.imageModel.updateTitle(root.image.id, text);
showPassiveNotification(image.title); showPassiveNotification(root.image.title);
} }
function changeTitle(text, updateBox) { function changeTitle(text, updateBox) {
@ -155,4 +169,10 @@ Item {
imageTitleField.text = text; imageTitleField.text = text;
image.title = text; image.title = text;
} }
function updateImage(image) {
imageProxyModel.imageModel.updateFilePath(root.image.id, image);
root.image.filePath = image;
console.log(image);
}
} }