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