diff --git a/src/Editor/QmlResources/KSCropToolBar.qml b/src/Editor/QmlResources/KSCropToolBar.qml new file mode 100644 index 0000000..85d15ca --- /dev/null +++ b/src/Editor/QmlResources/KSCropToolBar.qml @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2015 Boudhayan Gupta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +import QtQuick 2.4 +import QtQuick.Layouts 1.1 +import QtQuick.Controls 1.3 +import QtQuick.Controls.Styles 1.3 +import QtQuick.Dialogs 1.2 + +ToolBar { + id: cropToolbar; + + width: toolBarLayout.width + 10; + height: toolBarLayout.height + 10; + opacity: 0.95; + + style: ToolBarStyle { + padding { left: 5; right: 5; top: 5; bottom: 5 } + background: Rectangle { color: "darkgrey"; } + } + + RowLayout { + id: toolBarLayout; + Label { text: i18n("Crop Tool"); font.bold: true; } + Rectangle { width: 24; height: 1; opacity: 0; } + + Label { text: i18n("Radius: "); } + SpinBox { + id: radiusInput; + maximumValue: 1024; + + onValueChanged: { radiusChanged(value); } + } + } +} diff --git a/src/Editor/QmlResources/KSDrawRectangleToolBar.qml b/src/Editor/QmlResources/KSDrawRectangleToolBar.qml index e7a472d..ac84948 100644 --- a/src/Editor/QmlResources/KSDrawRectangleToolBar.qml +++ b/src/Editor/QmlResources/KSDrawRectangleToolBar.qml @@ -1,166 +1,149 @@ /* * Copyright (C) 2015 Boudhayan Gupta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ import QtQuick 2.4 import QtQuick.Layouts 1.1 import QtQuick.Controls 1.3 import QtQuick.Controls.Styles 1.3 import QtQuick.Dialogs 1.2 ToolBar { id: drawRectangleToolbar; signal fillColorChanged(color newColor); signal borderColorChanged(color newColor); signal borderWidthChanged(int newWidth); signal radiusChanged(int newRadius); signal rectOpacityChanged(real newOpacity); width: toolBarLayout.width + 10; height: toolBarLayout.height + 10; opacity: 0.95; style: ToolBarStyle { padding { left: 5; right: 5; top: 5; bottom: 5 } - background: Rectangle { color: "lightgrey"; } + background: Rectangle { color: "darkgrey"; } } RowLayout { id: toolBarLayout; - Label { text: i18n("Rectangle Tool"); font.bold: true; - MouseArea { - anchors.fill: parent; - cursorShape: Qt.OpenHandCursor; - - drag { - target: drawRectangleToolbar; - axis: Drag.XAndYAxis; - minimumX: 0; - maximumX: drawRectangleToolbar.parent.width - drawRectangleToolbar.width; - minimumY: 0; - maximumY: drawRectangleToolbar.parent.height - drawRectangleToolbar.height; - } - - onPressed: { cursorShape = Qt.ClosedHandCursor; } - onReleased: { cursorShape = Qt.OpenHandCursor; } - } - } + Label { text: i18n("Rectangle Tool"); font.bold: true; } Rectangle { width: 24; height: 1; opacity: 0; } Label { text: i18n("Fill Color: "); } Rectangle { id: fillColor; color: "black"; border { color: "black"; width: 1; } height: opacityInput.height; width: opacityInput.height; onColorChanged: { fillColorChanged(color); } MouseArea { anchors.fill: parent; onClicked: { fillColorDialog.open(); } } } Label { text: i18n("Border Color: "); } Rectangle { id: borderColor; color: "black"; border { color: "black"; width: 1; } height: opacityInput.height; width: opacityInput.height; onColorChanged: { borderColorChanged(color); } MouseArea { anchors.fill: parent; onClicked: { borderColorDialog.open(); } } } Rectangle { width: 16; height: 1; opacity: 0; } Label { text: i18n("Border Width: "); } SpinBox { id: borderWidthInput; maximumValue: 1024; onValueChanged: { borderWidthChanged(value); } } Label { text: i18n("Opacity: "); } SpinBox { id: opacityInput; decimals: 2; stepSize: 0.1; minimumValue: 0.0; maximumValue: 1.0; value: 1.0; onValueChanged: { rectOpacityChanged(value); } } Label { text: i18n("Radius: "); } SpinBox { id: radiusInput; maximumValue: 1024; onValueChanged: { radiusChanged(value); } } } ColorDialog { id: fillColorDialog; title: i18n("Please choose a fill color"); showAlphaChannel: true; onAccepted: { fillColor.color = color; } } ColorDialog { id: borderColorDialog; title: i18n("Please choose a border color"); showAlphaChannel: true; onAccepted: { borderColor.color = color; } } } diff --git a/src/Editor/QmlResources/KSEditActionsToolBar.qml b/src/Editor/QmlResources/KSEditActionsToolBar.qml index c281c11..f3e6679 100644 --- a/src/Editor/QmlResources/KSEditActionsToolBar.qml +++ b/src/Editor/QmlResources/KSEditActionsToolBar.qml @@ -1,64 +1,64 @@ /* * Copyright (C) 2015 Boudhayan Gupta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ import QtQuick 2.4 import QtQuick.Layouts 1.1 import QtQuick.Controls 1.3 import QtQuick.Controls.Styles 1.3 ToolBar { id: editActionsToolbar; signal done(); signal cancel(); signal toolSelected(string toolName); width: toolBarLayout.width + 10; - opacity: 0.9; + opacity: 0.95; style: ToolBarStyle { padding { left: 5; right: 5; top: 5; bottom: 5 } - background: Rectangle { color: "lightgrey"; } + background: Rectangle { color: "darkgrey"; } } ExclusiveGroup { id: editToolGroup Action { id: cropTool; text: i18n("Crop"); iconName: "transform-crop"; checkable: true; checked: true; } Action { id: rectangleTool; text: i18n("Draw Rectangle"); iconName: "draw-rectangle"; checkable: true; } Action { id: lineTool; text: i18n("Draw Line"); iconName: "draw-line"; checkable: true; } Action { id: brushTool; text: i18n("Draw Freehand"); iconName: "draw-freehand"; checkable: true } Action { id: textTool; text: i18n("Write Text"); iconName: "draw-text"; checkable: true; } } ColumnLayout { id: toolBarLayout; ToolButton { id: cropButton; action: cropTool; onClicked: toolSelected("crop"); } ToolButton { id: rectangleButton; action: rectangleTool; onClicked: toolSelected("rectangle"); } ToolButton { id: lineButton; action: lineTool; onClicked: toolSelected("line"); } ToolButton { id: brushButton; action: brushTool; onClicked: toolSelected("brush"); } ToolButton { id: textButton; action: textTool; onClicked: toolSelected("text"); } Rectangle { width: cropButton.width; height: 1; color: "darkgrey"; } ToolButton { text: i18n("Done"); tooltip: i18n("Done"); iconName: "dialog-ok"; onClicked: done(); } ToolButton { text: i18n("Cancel"); tooltip: i18n("Cancel"); iconName: "dialog-cancel"; onClicked: cancel(); } } } diff --git a/src/Editor/QmlResources/KSRectangleTool.qml b/src/Editor/QmlResources/KSRectangleTool.qml index 4ee7ed9..14be979 100644 --- a/src/Editor/QmlResources/KSRectangleTool.qml +++ b/src/Editor/QmlResources/KSRectangleTool.qml @@ -1,89 +1,90 @@ /* * Copyright (C) 2015 Boudhayan Gupta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ import QtQuick 2.4 import "qml:///KSDrawRectangleToolBar.qml" MouseArea { id: selectArea anchors.fill: parent cursorShape: Qt.CrossCursor property var parentItem: null; + property var toolbarAnchor: null; property var highlightItem: null; property int initialX: 0 property int initialY: 0 property int rectRadius: 0; property int rectBorderWidth: 0; property real rectOpacity: 1.0; property color rectFillColor: "black"; property color rectBorderColor: "black"; onPressed: { initialX = mouse.x; initialY = mouse.y; highlightItem = highlightRectangle.createObject(parentItem, { "x" : mouse.x, "y" : mouse.y, "color" : rectFillColor, "radius" : rectRadius, "opacity" : rectOpacity, "border.width" : rectBorderWidth, "border.color" : rectBorderColor }); } onPositionChanged: { if (mouse.x < initialX) { highlightItem.x = mouse.x; highlightItem.width = (initialX - mouse.x); } else { highlightItem.width = (Math.abs (mouse.x - highlightItem.x)); } if (mouse.y < initialY) { highlightItem.y = mouse.y; highlightItem.height = (initialY - mouse.y); } else { highlightItem.height = (Math.abs (mouse.y - highlightItem.y)); } } onReleased: { highlightItem = null; } KSDrawRectangleToolBar { - x: 20; - y: 20; + y: toolbarAnchor.y; + x: toolbarAnchor.x + toolbarAnchor.width; onRectOpacityChanged: { selectArea.rectOpacity = newOpacity; } onFillColorChanged: { selectArea.rectFillColor = newColor; } onBorderColorChanged: { selectArea.rectBorderColor = newColor; } onRadiusChanged: { selectArea.rectRadius = newRadius; } onBorderWidthChanged: { selectArea.rectBorderWidth = newWidth; } } Component { id: highlightRectangle Rectangle {} } } diff --git a/src/Editor/QmlResources/QmlResources.qrc b/src/Editor/QmlResources/QmlResources.qrc index 28f1d08..ad0816d 100644 --- a/src/Editor/QmlResources/QmlResources.qrc +++ b/src/Editor/QmlResources/QmlResources.qrc @@ -1,9 +1,10 @@ HighlightRectangle.qml RegionGrabber.qml KSEditActionsToolBar.qml KSDrawRectangleToolBar.qml KSRectangleTool.qml + KSCropToolBar.qml diff --git a/src/Editor/QmlResources/RegionGrabber.qml b/src/Editor/QmlResources/RegionGrabber.qml index 1b1534d..5ba79c1 100644 --- a/src/Editor/QmlResources/RegionGrabber.qml +++ b/src/Editor/QmlResources/RegionGrabber.qml @@ -1,88 +1,101 @@ /* * Copyright (C) 2015 Boudhayan Gupta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ import QtQuick 2.4 import KSComponents 2.0 Image { id: rootItem; signal editCanceled; signal editAccepted(int x, int y, int width, int height); property var toolOptionsToolbar: null; property var currentGraphicElement: null; function prepareEditAccepted() { if (workArea.tool !== null) { workArea.tool.visible = false; workArea.tool.destroy(); } editActionsToolbar.visible = false; cropArea.noPaint = true; editAccepted(cropArea.cropX, cropArea.cropY, cropArea.cropWidth, cropArea.cropHeight); } focus: true; Keys.onEscapePressed: editCanceled(); + Keys.onReturnPressed: prepareEditAccepted(); source: "image://screenshot/image"; KSCropArea { id: cropArea; anchors.fill: parent; Item { id: workArea; anchors.fill: parent; z: -1; property var tool: null; } } + Component { id: rectangleTool; KSRectangleTool {} } + Component { id: cropToolbar; KSCropToolBar{} } + Item { id: toolBarArea; anchors.fill: parent; - } - - Component { id: rectangleTool; KSRectangleTool {} } - - KSEditActionsToolBar { - id: editActionsToolbar; - anchors.bottom: parent.bottom; - anchors.right: parent.right; - anchors.margins: 10; + KSEditActionsToolBar { + id: editActionsToolbar; - onDone: prepareEditAccepted(); - onCancel: editCanceled(); - - onToolSelected: { - if (workArea.tool !== null) { - workArea.tool.destroy(); + anchors { + top: parent.top; + left: parent.left; + margins: 10; } - if (toolName == "rectangle") { - workArea.tool = rectangleTool.createObject(toolBarArea, {"parentItem" : workArea}); + onDone: prepareEditAccepted(); + onCancel: editCanceled(); + + onToolSelected: { + if (workArea.tool !== null) { + workArea.tool.destroy(); + } + + if (toolName == "crop") { + workArea.tool = cropToolbar.createObject(toolBarArea, { + "y" : editActionsToolbar.y, + "x" : editActionsToolbar.x + editActionsToolbar.width, + }); + + } else if (toolName == "rectangle") { + workArea.tool = rectangleTool.createObject(toolBarArea, { + "parentItem" : workArea, + "toolbarAnchor" : editActionsToolbar + }); + } } } - } + } }