[network/neochat] src: General improvements to image attachment editing

Joshua Goins <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit aa8caa4a3814364e16d9f82faacab75e784932dc by Joshua Goins.
Committed on 23/07/2026 at 22:25.
Pushed by redstrate into branch 'master'.

General improvements to image attachment editing

While this feature works, it clearly hasn't gotten a lot of love as of
late. The dialog has a bit of an odd layout, the Crop feature is broken
and it doesn't have a proper window title on desktop.

M  +39   -52   src/chatbar/ImageEditorPage.qml
M  +2    -2    src/messagecontent/ImageComponent.qml

https://invent.kde.org/network/neochat/-/commit/aa8caa4a3814364e16d9f82faacab75e784932dc

diff --git a/src/chatbar/ImageEditorPage.qml b/src/chatbar/ImageEditorPage.qml
index 37bb5454c..1c4e2efe9 100644
--- a/src/chatbar/ImageEditorPage.qml
+++ b/src/chatbar/ImageEditorPage.qml
@@ -4,6 +4,7 @@
 import QtQuick
 import QtQuick.Controls as QQC2
 import QtCore as Core
+import QtQuick.Layouts
 
 import org.kde.kirigami as Kirigami
 import org.kde.kquickimageeditor as KQuickImageEditor
@@ -16,7 +17,9 @@ Kirigami.Page {
 
     signal newPathChanged(string newPath)
 
-    title: i18n("Edit")
+    title: i18nc("@window:title", "Edit Image")
+    globalToolBarStyle: Kirigami.ApplicationHeaderStyle.None
+
     leftPadding: 0
     rightPadding: 0
     topPadding: 0
@@ -29,30 +32,41 @@ Kirigami.Page {
         imageDoc.crop(selectionTool.selectionX / ratioX, selectionTool.selectionY / ratioY, selectionTool.selectionWidth / ratioX, selectionTool.selectionHeight / ratioY);
     }
 
-    actions: [
-        Kirigami.Action {
-            id: undoAction
-            text: i18nc("@action:button Undo modification", "Undo")
-            icon.name: "edit-undo"
-            onTriggered: imageDoc.undo()
-            visible: imageDoc.edited
-        },
-        Kirigami.Action {
-            id: okAction
-            text: i18nc("@action:button Accept image modification", "Accept")
-            icon.name: "dialog-ok"
-            onTriggered: {
-                let newPath = Core.StandardPaths.writableLocation(Core.StandardPaths.CacheLocation) + "/" + (new Date()).getTime() + "." + root.imagePath.split('.').pop();
-                if (imageDoc.saveAs(newPath)) {
-                    root.newPathChanged(newPath);
-                } else {
-                    msg.type = Kirigami.MessageType.Error;
-                    msg.text = i18n("Unable to save file. Check if you have the correct permission to edit the cache directory.");
-                    msg.visible = true;
+    footer: QQC2.ToolBar {
+        QQC2.DialogButtonBox {
+            anchors.fill: parent
+
+            QQC2.Button {
+                id: saveButton
+
+                text: i18nc("@action:button Accept image modification", "Save")
+                icon.name: "document-save"
+
+                QQC2.DialogButtonBox.buttonRole: QQC2.DialogButtonBox.ApplyRole
+
+                onClicked: {
+                    let newPath = Core.StandardPaths.writableLocation(Core.StandardPaths.CacheLocation) + "/" + (new Date()).getTime() + "." + root.imagePath.split('.').pop();
+                    if (imageDoc.saveAs(newPath)) {
+                        root.newPathChanged(newPath);
+                    } else {
+                        // TODO: is this a thing that will ever actually happen?
+                        console.warn("Unable to save file. Check if you have the correct permission to edit the cache directory.");
+                    }
                 }
             }
+            QQC2.Button {
+                id: undoButton
+
+                text: i18nc("@action:button Undo modification", "Undo")
+                icon.name: "edit-undo"
+                enabled: imageDoc.edited
+
+                QQC2.DialogButtonBox.buttonRole: QQC2.DialogButtonBox.ResetRole
+
+                onClicked: imageDoc.undo()
+            }
         }
-    ]
+    }
 
     KQuickImageEditor.ImageItem {
         id: editImage
@@ -64,17 +78,12 @@ Kirigami.Page {
 
         Shortcut {
             sequence: StandardKey.Undo
-            onActivated: undoAction.trigger()
+            onActivated: undoButton.click()
         }
 
         Shortcut {
             sequences: [StandardKey.Save, "Enter"]
-            onActivated: saveAction.trigger()
-        }
-
-        Shortcut {
-            sequence: StandardKey.SaveAs
-            onActivated: saveAsAction.trigger()
+            onActivated: saveButton.trigger()
         }
 
         KQuickImageEditor.ImageDocument {
@@ -104,6 +113,7 @@ Kirigami.Page {
                 }
             }
         }
+
         onImageChanged: {
             selectionTool.selectionX = 0;
             selectionTool.selectionY = 0;
@@ -117,21 +127,6 @@ Kirigami.Page {
             id: actionToolBar
             display: QQC2.Button.TextBesideIcon
             actions: [
-                Kirigami.Action {
-                    icon.name: root.resizing ? "dialog-cancel" : "transform-crop"
-                    text: root.resizing ? i18n("Cancel") : i18nc("@action:button Crop an image", "Crop")
-                    onTriggered: {
-                        resizeRectangle.width = editImage.paintedWidth;
-                        resizeRectangle.height = editImage.paintedHeight;
-                        resizeRectangle.x = editImage.horizontalPadding;
-                        resizeRectangle.y = editImage.verticalPadding;
-                        resizeRectangle.insideX = 100;
-                        resizeRectangle.insideY = 100;
-                        resizeRectangle.insideWidth = 100;
-                        resizeRectangle.insideHeight = 100;
-                        root.resizing = !root.resizing;
-                    }
-                },
                 Kirigami.Action {
                     icon.name: "dialog-ok"
                     visible: root.resizing
@@ -165,12 +160,4 @@ Kirigami.Page {
             ]
         }
     }
-
-    footer: Kirigami.InlineMessage {
-        id: msg
-        type: Kirigami.MessageType.Error
-        showCloseButton: true
-        visible: false
-        position: Kirigami.InlineMessage.Position.Header
-    }
 }
diff --git a/src/messagecontent/ImageComponent.qml b/src/messagecontent/ImageComponent.qml
index f1232dcfd..23d223b75 100644
--- a/src/messagecontent/ImageComponent.qml
+++ b/src/messagecontent/ImageComponent.qml
@@ -87,7 +87,7 @@ Item {
                 id: editImageButton
                 visible: root.editable
                 icon.name: "document-edit"
-                text: i18nc("@action:button", "Edit")
+                text: i18nc("@action:button", "Edit Image")
                 display: QQC2.AbstractButton.IconOnly
 
                 Component {
@@ -98,7 +98,7 @@ Item {
                 }
 
                 onClicked: {
-                    let imageEditor = (Kirigami.PageStack.pageStack as Kirigami.PageRow).pushDialogLayer(imageEditorPage);
+                    let imageEditor = (Kirigami.PageStack.pageStack as Kirigami.PageRow).pushDialogLayer(imageEditorPage, {}, { title: i18nc("@window:title", "Edit Image")});
                     imageEditor.newPathChanged.connect(function (newPath) {
                         imageEditor.closeDialog();
                         Message.contentModel?.addAttachment(newPath);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.