diff --git a/src/Editor/QmlResources/HighlightRectangle.qml b/src/Editor/QmlResources/HighlightRectangle.qml index a8d7cfa..fefd128 100644 --- a/src/Editor/QmlResources/HighlightRectangle.qml +++ b/src/Editor/QmlResources/HighlightRectangle.qml @@ -1,348 +1,348 @@ /* - * Copyright (C) 2015 Boudhayan Gupta + * 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.Controls 1.3 Item { id: selectionContainer; signal selectionCancelled; signal selectionConfirmed(int x, int y, int width, int height); // resize helper functions property int initialTop; property int initialLeft; property int initialWidth; property int initialHeight; function saveInitials() { selectionContainer.initialHeight = selectionContainer.height; selectionContainer.initialWidth = selectionContainer.width; selectionContainer.initialTop = selectionContainer.y; selectionContainer.initialLeft = selectionContainer.x; } function resizeFromTop(curMouseY, oldMouseY) { var newY = selectionContainer.y + (curMouseY - oldMouseY); var newHeight = selectionContainer.initialHeight - (newY - selectionContainer.initialTop); if ((newY >= 0) && (newHeight > 0)) { selectionContainer.y = newY; selectionContainer.height = newHeight; } } function resizeFromLeft(curMouseX, oldMouseX) { var newX = selectionContainer.x + (curMouseX - oldMouseX); var newWidth = selectionContainer.initialWidth - (newX - selectionContainer.initialLeft); if ((newX >= 0) && (newWidth > 0)) { selectionContainer.x = newX; selectionContainer.width = newWidth; } } function resizeFromBottom(curMouseY, oldMouseY) { var newHeight = selectionContainer.height + (curMouseY - oldMouseY); if (newHeight > 0) { selectionContainer.height = newHeight; } } function resizeFromRight(curMouseX, oldMouseX) { var newWidth = selectionContainer.width + (curMouseX - oldMouseX); if (newWidth > 0) { selectionContainer.width = newWidth; } } // the selection rectangle and its mouse area Rectangle { id: selectionRectangle; property int sizeGripBorderWidth: 8; color: Qt.rgba(1, 0.9, 0, 0.5); border.color: Qt.rgba(1, 0.9, 0, 0.7); border.width: 3; anchors.centerIn: parent; anchors.fill: parent; } MouseArea { id: moveArea anchors.centerIn: parent; height: parent.height - (2 * selectionRectangle.sizeGripBorderWidth); width: parent.width - (2 * selectionRectangle.sizeGripBorderWidth); cursorShape: Qt.OpenHandCursor drag.target: parent drag.axis: Drag.XAndYAxis drag.minimumX: 0 drag.minimumY: 0 drag.maximumX: parent.parent.width - parent.width drag.maximumY: parent.parent.height - parent.height onPressed: { cursorShape = Qt.ClosedHandCursor; } onReleased: { cursorShape = Qt.OpenHandCursor; } } // resize grips MouseArea { id: sizeGripTopMouseArea; cursorShape: Qt.SizeVerCursor; anchors.top: parent.top; anchors.horizontalCenter: parent.horizontalCenter; height: selectionRectangle.sizeGripBorderWidth; width: parent.width - (2 * selectionRectangle.sizeGripBorderWidth); property int oldMouseY; onPressed: { oldMouseY = mouseY; saveInitials(); } onPositionChanged: { resizeFromTop(mouseY, oldMouseY); } } MouseArea { id: sizeGripLeftMouseArea; cursorShape: Qt.SizeHorCursor; anchors.left: parent.left; anchors.verticalCenter: parent.verticalCenter; height: parent.height - (2 * selectionRectangle.sizeGripBorderWidth); width: selectionRectangle.sizeGripBorderWidth; property int oldMouseX; onPressed: { oldMouseX = mouseX; saveInitials(); } onPositionChanged: { resizeFromLeft(mouseX, oldMouseX); } } MouseArea { id: sizeGripRightMouseArea; cursorShape: Qt.SizeHorCursor; anchors.right: parent.right; anchors.verticalCenter: parent.verticalCenter; height: parent.height - (2 * selectionRectangle.sizeGripBorderWidth); width: selectionRectangle.sizeGripBorderWidth; property int oldMouseX; onPressed: { oldMouseX = mouseX; } onPositionChanged: { resizeFromRight(mouseX, oldMouseX); } } MouseArea { id: sizeGripBottomMouseArea; cursorShape: Qt.SizeVerCursor; anchors.bottom: parent.bottom; anchors.horizontalCenter: parent.horizontalCenter; height: selectionRectangle.sizeGripBorderWidth; width: parent.width - (2 * selectionRectangle.sizeGripBorderWidth); property int oldMouseY; onPressed: { oldMouseY = mouseY; } onPositionChanged: { resizeFromBottom(mouseY, oldMouseY); } } Rectangle { height: 20; width: 20; color: "transparent"; anchors.horizontalCenter: parent.left; anchors.verticalCenter: parent.top; MouseArea { id: sizeGripTopLeftMouseArea anchors.fill: parent; cursorShape: Qt.SizeFDiagCursor; property int oldMouseX; property int oldMouseY; onPressed: { oldMouseX = mouseX; oldMouseY = mouseY; saveInitials(); } onPositionChanged: { resizeFromLeft(mouseX, oldMouseX); resizeFromTop(mouseY, oldMouseY); } } } Rectangle { height: 20; width: 20; color: "transparent"; anchors.horizontalCenter: parent.right; anchors.verticalCenter: parent.top; MouseArea { id: sizeGripTopRightMouseArea anchors.fill: parent; cursorShape: Qt.SizeBDiagCursor; property int oldMouseX; property int oldMouseY; onPressed: { oldMouseX = mouseX; oldMouseY = mouseY; saveInitials(); } onPositionChanged: { resizeFromRight(mouseX, oldMouseX); resizeFromTop(mouseY, oldMouseY); } } } Rectangle { height: 20; width: 20; color: "transparent"; anchors.horizontalCenter: parent.left; anchors.verticalCenter: parent.bottom; MouseArea { id: sizeGripBottomLeftMouseArea anchors.fill: parent; cursorShape: Qt.SizeBDiagCursor; property int oldMouseX; property int oldMouseY; onPressed: { oldMouseX = mouseX; oldMouseY = mouseY; saveInitials(); } onPositionChanged: { resizeFromLeft(mouseX, oldMouseX); resizeFromBottom(mouseY, oldMouseY); } } } Rectangle { height: 20; width: 20; color: "transparent"; anchors.horizontalCenter: parent.right; anchors.verticalCenter: parent.bottom; MouseArea { id: sizeGripBottomRightMouseArea anchors.fill: parent; cursorShape: Qt.SizeFDiagCursor; property int oldMouseX; property int oldMouseY; onPressed: { oldMouseX = mouseX; oldMouseY = mouseY; } onPositionChanged: { resizeFromRight(mouseX, oldMouseX); resizeFromBottom(mouseY, oldMouseY); } } } // the buttons inside the rectangle Row { id: buttonStore; anchors.centerIn: selectionRectangle; opacity: 0.9; Button { action: exitAction; } Button { action: doneAction; } } Action { id: exitAction; text: i18n("Cancel"); iconName: "dialog-close"; enabled: true; onTriggered: selectionCancelled(); } Action { id: doneAction; text: i18n("Confirm"); iconName: "dialog-ok"; enabled: true; onTriggered: selectionConfirmed(selectionContainer.x, selectionContainer.y, selectionContainer.width, selectionContainer.height); } } diff --git a/src/Editor/QmlResources/KSDrawRectangleToolBar.qml b/src/Editor/QmlResources/KSDrawRectangleToolBar.qml index 4f28311..e7a472d 100644 --- a/src/Editor/QmlResources/KSDrawRectangleToolBar.qml +++ b/src/Editor/QmlResources/KSDrawRectangleToolBar.qml @@ -1,147 +1,166 @@ +/* + * 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"; } } 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; } } } 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 8e42754..c281c11 100644 --- a/src/Editor/QmlResources/KSEditActionsToolBar.qml +++ b/src/Editor/QmlResources/KSEditActionsToolBar.qml @@ -1,45 +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; style: ToolBarStyle { padding { left: 5; right: 5; top: 5; bottom: 5 } background: Rectangle { color: "lightgrey"; } } 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 68b8436..4ee7ed9 100644 --- a/src/Editor/QmlResources/KSRectangleTool.qml +++ b/src/Editor/QmlResources/KSRectangleTool.qml @@ -1,70 +1,89 @@ +/* + * 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 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; 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/RegionGrabber.qml b/src/Editor/QmlResources/RegionGrabber.qml index 878c563..1b1534d 100644 --- a/src/Editor/QmlResources/RegionGrabber.qml +++ b/src/Editor/QmlResources/RegionGrabber.qml @@ -1,88 +1,88 @@ /* - * Copyright (C) 2015 Boudhayan Gupta + * 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(); source: "image://screenshot/image"; KSCropArea { id: cropArea; anchors.fill: parent; Item { id: workArea; anchors.fill: parent; z: -1; property var tool: null; } } Item { id: toolBarArea; anchors.fill: parent; } Component { id: rectangleTool; KSRectangleTool {} } KSEditActionsToolBar { id: editActionsToolbar; anchors.bottom: parent.bottom; anchors.right: parent.right; anchors.margins: 10; onDone: prepareEditAccepted(); onCancel: editCanceled(); onToolSelected: { if (workArea.tool !== null) { workArea.tool.destroy(); } if (toolName == "rectangle") { workArea.tool = rectangleTool.createObject(toolBarArea, {"parentItem" : workArea}); } } } }