MauiKit Image Tools

ImageEditor.qml
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4
5import org.mauikit.controls 1.2 as Maui
6
7import org.kde.kquickimageeditor 1.0 as KQuickImageEditor
8import Qt5Compat.GraphicalEffects
9
10import "private" as Private
11
13/**
14 * @inherit org::mauikit::controls::Page
15 * @brief A control with different tools for editingan image
16 *
17 */
18Maui.Page
19{
20 id: control
22 property url url
23
24 readonly property bool ready : String(control.url).length
25
26 readonly property alias editor : imageDoc
27
28 headBar.visible: control.ready
29
30 headBar.leftContent: ToolButton
31 {
32 icon.name: "edit-undo"
33 enabled: imageDoc.edited
34 onClicked: imageDoc.undo()
35 }
36
37 headBar.middleContent: Maui.ToolActions
38 {
39 id: _editTools
40 Layout.alignment: Qt.AlignHCenter
41 autoExclusive: true
42 property int currentIndex : 1
43 expanded: control.width > Maui.Style.units.gridUnit * 30
44 display: ToolButton.TextBesideIcon
45
46 Action
47 {
48 text: i18nd("mauikitimagetools","Color")
49 checked: _editTools.currentIndex === 0
50 onTriggered: _editTools.currentIndex = 0
51 }
52
53 Action
54 {
55 text: i18nd("mauikitimagetools","Transform")
56 checked: _editTools.currentIndex === 1
57 onTriggered: _editTools.currentIndex = 1
58 }
59
60 Action
61 {
62 text: i18nd("mauikitimagetools","Layer")
63 checked: _editTools.currentIndex === 2
64 onTriggered: _editTools.currentIndex = 2
65 }
66 }
67
68 KQuickImageEditor.ImageItem
69 {
70 id: editImage
71 readonly property real ratioX: editImage.paintedWidth / editImage.nativeWidth;
72 readonly property real ratioY: editImage.paintedHeight / editImage.nativeHeight;
73
74 fillMode: KQuickImageEditor.ImageItem.PreserveAspectFit
75 image: imageDoc.image
76 anchors.fill: parent
77 anchors.margins: Maui.Style.space.medium
78
79 rotation: _transBar.rotationSlider.value
80
81 KQuickImageEditor.ImageDocument
82 {
83 id: imageDoc
84 path: control.url
85 }
86
87 KQuickImageEditor.SelectionTool
88 {
89 id: selectionTool
90 visible: _transBar.cropButton.checked
91 width: editImage.paintedWidth
92 height: editImage.paintedHeight
93 x: editImage.horizontalPadding
94 y: editImage.verticalPadding
95
96 KQuickImageEditor.CropBackground
97 {
98 anchors.fill: parent
99 z: -1
100 insideX: selectionTool.selectionX
101 insideY: selectionTool.selectionY
102 insideWidth: selectionTool.selectionWidth
103 insideHeight: selectionTool.selectionHeight
104 }
105 Connections {
106 target: selectionTool.selectionArea
107 function onDoubleClicked() {
108 control.crop()
109 }
110 }
111 }
112
113 onImageChanged:
114 {
115 selectionTool.selectionX = 0
116 selectionTool.selectionY = 0
117 selectionTool.selectionWidth = Qt.binding(() => selectionTool.width)
118 selectionTool.selectionHeight = Qt.binding(() => selectionTool.height)
119 }
120
121
122 Canvas
123 {
124 visible: _transBar.rotationButton.checked
125 opacity: 0.15
126 anchors.fill : parent
127 property int wgrid: control.width / 20
128 onPaint: {
129 var ctx = getContext("2d")
130 ctx.lineWidth = 0.5
131 ctx.strokeStyle = Maui.Theme.textColor
132 ctx.beginPath()
133 var nrows = height/wgrid;
134 for(var i=0; i < nrows+1; i++){
135 ctx.moveTo(0, wgrid*i);
136 ctx.lineTo(width, wgrid*i);
137 }
138
139 var ncols = width/wgrid
140 for(var j=0; j < ncols+1; j++){
141 ctx.moveTo(wgrid*j, 0);
142 ctx.lineTo(wgrid*j, height);
143 }
144 ctx.closePath()
145 ctx.stroke()
146 }
147 }
148 }
149
150 footBar.visible: false
151 footerColumn: [
152
153 Private.TransformationBar
154 {
155 id: _transBar
156 visible: _editTools.currentIndex === 1 && control.ready
157 width: parent.width
158 },
159
160 Private.ColourBar
161 {
162 id: _colourBar
163 visible: _editTools.currentIndex === 0 && control.ready
164 width: parent.width
165 }
166 ]
167
168
169 function crop() {
170 console.log("CROP")
171 imageDoc.crop(selectionTool.selectionX / editImage.ratioX,
172 selectionTool.selectionY / editImage.ratioY,
173 selectionTool.selectionWidth / editImage.ratioX,
174 selectionTool.selectionHeight / editImage.ratioY);
175 }
176}
QString i18nd(const char *domain, const char *text, const TYPE &arg...)
QString & fill(QChar ch, qsizetype size)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:53:05 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.