MauiKit Image Tools

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

KDE's Doxygen guidelines are available online.