Warning, /maui/mauikit-imagetools/src/controls.6/ImageEditor.qml is written in an unsupported language. File is not indexed.
0001 import QtQuick 0002 import QtQuick.Controls 0003 import QtQuick.Layouts 0004 0005 import org.mauikit.controls 1.2 as Maui 0006 0007 import org.kde.kquickimageeditor 1.0 as KQuickImageEditor 0008 import Qt5Compat.GraphicalEffects 0009 0010 import "private" as Private 0011 0012 0013 /** 0014 * @inherit org::mauikit::controls::Page 0015 * @brief A control with different tools for editingan image 0016 * 0017 */ 0018 Maui.Page 0019 { 0020 id: control 0021 0022 property url url 0023 0024 readonly property bool ready : String(control.url).length 0025 0026 readonly property alias editor : imageDoc 0027 0028 headBar.visible: control.ready 0029 0030 headBar.leftContent: ToolButton 0031 { 0032 icon.name: "edit-undo" 0033 enabled: imageDoc.edited 0034 onClicked: imageDoc.undo() 0035 } 0036 0037 headBar.middleContent: Maui.ToolActions 0038 { 0039 id: _editTools 0040 Layout.alignment: Qt.AlignHCenter 0041 autoExclusive: true 0042 property int currentIndex : 1 0043 expanded: control.width > Maui.Style.units.gridUnit * 30 0044 display: ToolButton.TextBesideIcon 0045 0046 Action 0047 { 0048 text: i18nd("mauikitimagetools","Color") 0049 checked: _editTools.currentIndex === 0 0050 onTriggered: _editTools.currentIndex = 0 0051 } 0052 0053 Action 0054 { 0055 text: i18nd("mauikitimagetools","Transform") 0056 checked: _editTools.currentIndex === 1 0057 onTriggered: _editTools.currentIndex = 1 0058 } 0059 0060 Action 0061 { 0062 text: i18nd("mauikitimagetools","Layer") 0063 checked: _editTools.currentIndex === 2 0064 onTriggered: _editTools.currentIndex = 2 0065 } 0066 } 0067 0068 KQuickImageEditor.ImageItem 0069 { 0070 id: editImage 0071 readonly property real ratioX: editImage.paintedWidth / editImage.nativeWidth; 0072 readonly property real ratioY: editImage.paintedHeight / editImage.nativeHeight; 0073 0074 fillMode: KQuickImageEditor.ImageItem.PreserveAspectFit 0075 image: imageDoc.image 0076 anchors.fill: parent 0077 anchors.margins: Maui.Style.space.medium 0078 0079 rotation: _transBar.rotationSlider.value 0080 0081 KQuickImageEditor.ImageDocument 0082 { 0083 id: imageDoc 0084 path: control.url 0085 } 0086 0087 KQuickImageEditor.SelectionTool 0088 { 0089 id: selectionTool 0090 visible: _transBar.cropButton.checked 0091 width: editImage.paintedWidth 0092 height: editImage.paintedHeight 0093 x: editImage.horizontalPadding 0094 y: editImage.verticalPadding 0095 0096 KQuickImageEditor.CropBackground 0097 { 0098 anchors.fill: parent 0099 z: -1 0100 insideX: selectionTool.selectionX 0101 insideY: selectionTool.selectionY 0102 insideWidth: selectionTool.selectionWidth 0103 insideHeight: selectionTool.selectionHeight 0104 } 0105 Connections { 0106 target: selectionTool.selectionArea 0107 function onDoubleClicked() { 0108 control.crop() 0109 } 0110 } 0111 } 0112 0113 onImageChanged: 0114 { 0115 selectionTool.selectionX = 0 0116 selectionTool.selectionY = 0 0117 selectionTool.selectionWidth = Qt.binding(() => selectionTool.width) 0118 selectionTool.selectionHeight = Qt.binding(() => selectionTool.height) 0119 } 0120 0121 0122 Canvas 0123 { 0124 visible: _transBar.rotationButton.checked 0125 opacity: 0.15 0126 anchors.fill : parent 0127 property int wgrid: control.width / 20 0128 onPaint: { 0129 var ctx = getContext("2d") 0130 ctx.lineWidth = 0.5 0131 ctx.strokeStyle = Maui.Theme.textColor 0132 ctx.beginPath() 0133 var nrows = height/wgrid; 0134 for(var i=0; i < nrows+1; i++){ 0135 ctx.moveTo(0, wgrid*i); 0136 ctx.lineTo(width, wgrid*i); 0137 } 0138 0139 var ncols = width/wgrid 0140 for(var j=0; j < ncols+1; j++){ 0141 ctx.moveTo(wgrid*j, 0); 0142 ctx.lineTo(wgrid*j, height); 0143 } 0144 ctx.closePath() 0145 ctx.stroke() 0146 } 0147 } 0148 } 0149 0150 footBar.visible: false 0151 footerColumn: [ 0152 0153 Private.TransformationBar 0154 { 0155 id: _transBar 0156 visible: _editTools.currentIndex === 1 && control.ready 0157 width: parent.width 0158 }, 0159 0160 Private.ColourBar 0161 { 0162 id: _colourBar 0163 visible: _editTools.currentIndex === 0 && control.ready 0164 width: parent.width 0165 } 0166 ] 0167 0168 0169 function crop() { 0170 console.log("CROP") 0171 imageDoc.crop(selectionTool.selectionX / editImage.ratioX, 0172 selectionTool.selectionY / editImage.ratioY, 0173 selectionTool.selectionWidth / editImage.ratioX, 0174 selectionTool.selectionHeight / editImage.ratioY); 0175 } 0176 }