diff --git a/source/qml/lib/Outline.qml b/source/qml/lib/Outline.qml index 4fc8eee..4d4b860 100644 --- a/source/qml/lib/Outline.qml +++ b/source/qml/lib/Outline.qml @@ -1,120 +1,119 @@ /* * Copyright 2018 Fabian Riethmayer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, 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 Library General Public License for more details * * You should have received a copy of the GNU Library 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.7 import QtQuick.Controls 2.2 import org.kde.kirigami 2.4 as Kirigami import "tools.js" as T // Draw a frame around an element Item { anchors.fill: parent; property string color: "rgba(236, 161, 169, 0.6)" property bool label: true property bool aspectratio: false property Item item property Item root : container.parent z: 10 id: container Rectangle { id: prot color: "#cc93cee9" width: childrenRect.width + 10 height: childrenRect.height + 10 visible: false z: 2 Label { x: Kirigami.Units.smallSpacing y: Kirigami.Units.smallSpacing id: dim color: "#000" font.pointSize: 8 lineHeight: 8 height: 8 - renderType: Text.QtRendering } } Canvas { anchors.fill: parent; id: canvas onPaint: { // get scale because annotation should not be scaled var scale = T.getScale(container.parent) var ctx = getContext("2d"); ctx.strokeStyle = container.color; ctx.lineWidth = 4 / scale ctx.beginPath(); // Draw an rectangle around the element var offset = ctx.lineWidth / 2; var cItem = item.mapToItem(container.root, 0, 0); ctx.moveTo(cItem.x + offset, cItem.y + offset); ctx.lineTo(cItem.x + offset, cItem.y + item.height - offset); ctx.lineTo(cItem.x + item.width - offset, cItem.y + item.height - offset); ctx.lineTo(cItem.x + item.width - offset, cItem.y + offset); ctx.lineTo(cItem.x + offset, cItem.y + offset); if (container.aspectratio) { // Write proportions of an object instead of dimensions / px ctx.moveTo(cItem.x + offset, cItem.y + offset); ctx.lineTo(cItem.x + item.width - offset, cItem.y + item.height - offset); ctx.moveTo(cItem.x + item.width - offset, cItem.y + offset); ctx.lineTo(cItem.x + offset, cItem.y + item.height - offset); var aspect = Math.round(item.width / item.height * 100) / 100 // Well known aspect ratios switch (aspect) { case 1: aspect = "1 x 1" break; case 1.33: aspect = "4 x 3" break; case 1.5: aspect = "3 x 2" break; case 1.78: aspect = "16 x 9" break; } dim.text = aspect prot.visible = true; - prot.x = cItem.x + item.width / 2 - prot.width / 2 - prot.y = cItem.y + item.height / 2 - prot.height / 2 + prot.x = Math.round(cItem.x + item.width / 2 - prot.width / 2) + prot.y = Math.round(cItem.y + item.height / 2 - prot.height / 2) } else { // Write dimensions / px if (container.label) { dim.text = Math.round(item.width * 100) / 100 + " x " + Math.round(item.height * 100) / 100; prot.visible = true; - prot.x = cItem.x + item.width / 2 - prot.width / 2 - prot.y = cItem.y + item.height / 2 - prot.height / 2 + prot.x = Math.round(cItem.x + item.width / 2 - prot.width / 2) + prot.y = Math.round(cItem.y + item.height / 2 - prot.height / 2) } } ctx.stroke(); } } } diff --git a/source/qml/lib/Padding.qml b/source/qml/lib/Padding.qml index fdfb40c..50ab5d3 100644 --- a/source/qml/lib/Padding.qml +++ b/source/qml/lib/Padding.qml @@ -1,152 +1,148 @@ /* * Copyright 2018 Fabian Riethmayer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, 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 Library General Public License for more details * * You should have received a copy of the GNU Library 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.2 import QtQuick.Controls 2.2 import org.kde.kirigami 2.4 as Kirigami // Show the padding of an element Item { anchors.fill: parent; property string color: "rgba(147,206,233, 0.8)" property bool label: false property Item item property Item root : container.parent property var padding: [] z: 10 id: container Text { id: top color: "#da4453" font.pointSize: 8 lineHeight: 8 height: 8 z: 2 - renderType: Text.QtRendering } Text { id: right color: "#da4453" font.pointSize: 8 lineHeight: 8 height: 8 z: 2 - renderType: Text.QtRendering } Text { id: bottom color: "#da4453" font.pointSize: 8 lineHeight: 8 height: 8 z: 2 - renderType: Text.QtRendering } Text { id: left color: "#da4453" font.pointSize: 8 lineHeight: 8 height: 8 z: 2 - renderType: Text.QtRendering } Canvas { anchors.fill: parent; id: canvas onPaint: { // Determen padding var padding; if (typeof container.padding === "number") { padding = { "top": container.padding, "right": container.padding, "bottom": container.padding, "left": container.padding } } - else if (typeof container.padding === "Array" && container.padding.length == 4) { + else if (Array.isArray(container.padding) && container.padding.length == 4) { padding = { "top": container.padding[0], "right": container.padding[1], "bottom": container.padding[2], "left": container.padding[3] } } else { padding = { "top": item.topPadding, "right": item.rightPadding, "bottom": item.bottomPadding, "left": item.leftPadding } } // setup drawing context var offset; var cItem = item.mapToItem(container.root, 0, 0); var ctx = getContext("2d"); ctx.strokeStyle = container.color; ctx.beginPath(); // Draw top ctx.lineWidth = padding.top; offset = ctx.lineWidth / 2; ctx.moveTo(cItem.x + offset, cItem.y + offset); ctx.lineTo(cItem.x + item.width - offset, cItem.y + offset); // Draw right ctx.lineWidth = padding.right; offset = ctx.lineWidth / 2; ctx.lineTo(cItem.x + item.width - offset, cItem.y + item.height - offset); // Draw bottom ctx.lineWidth = padding.bottom; offset = ctx.lineWidth / 2; ctx.lineTo(cItem.x + offset, cItem.y + item.height - offset); // Draw left ctx.lineWidth = padding.bottom; offset = ctx.lineWidth / 2; ctx.lineTo(cItem.x + offset, cItem.y + offset); ctx.stroke(); // Write labels top.text = padding.top; top.x = cItem.x + item.width / 2; - top.y = cItem.y - 4; + top.y = cItem.y - 4 - padding.top / 2; right.text = padding.right; - right.x = cItem.x + item.width - right.width; + right.x = cItem.x + item.width - right.width + padding.right / 2; right.y = cItem.y + item.height / 2 - right.height; bottom.text = padding.bottom; bottom.x = cItem.x + item.width / 2; - bottom.y = cItem.y + item.height - bottom.height - 4; + bottom.y = cItem.y + item.height - bottom.height - 4 + padding.bottom / 2; left.text = padding.left; - left.x = cItem.x; + left.x = cItem.x - padding.left / 2; left.y = cItem.x + item.height / 2 - left.height; } } } diff --git a/source/qml/lib/Raster.qml b/source/qml/lib/Raster.qml index 5bc079e..7b3ee8d 100644 --- a/source/qml/lib/Raster.qml +++ b/source/qml/lib/Raster.qml @@ -1,134 +1,133 @@ /* * Copyright 2018 Fabian Riethmayer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, 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 Library General Public License for more details * * You should have received a copy of the GNU Library 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.7 import QtQuick.Controls 2.2 import org.kde.kirigami 2.4 as Kirigami // Drawing a semi transparent raster and a legend Item { anchors.fill: parent; property int base: Kirigami.Units.gridUnit property string color: "rgba(200, 200, 200, 0.7)" property string label: "Units.gridUnit / 18px" property bool touch: false; // Indicate touch support property bool mobile: false; // Indicate mobile/small display support property bool mouse: false; // Indicate mouse support property bool desktop: false; // Indicate large display support // Painting the grid on a canvas Canvas { anchors.fill: parent; id: canvas onPaint: { var ctx = getContext("2d"); ctx.strokeStyle = color; ctx.beginPath(); // Horizontal grid lines var i = 0; while (i < canvas.height / base) { ctx.moveTo(0, i * base); ctx.lineTo(canvas.width, i * base); i++; } // Vertical grid lines i = 0; while (i < canvas.width / base) { ctx.moveTo(i * base, 0); ctx.lineTo(i * base, canvas.height); i++; } ctx.stroke(); // draw scale on the bottom right // |---| if (label != "") { ctx.strokeStyle = "#da4453"; ctx.beginPath(); var left = canvas.width - 2 * base - canvas.width % base; var top; if (canvas.height % base > 2 * Kirigami.Units.smallSpacing) { top = canvas.height - canvas.height % base; } else { top = canvas.height - base - canvas.height % base; } ctx.moveTo(left, top - Kirigami.Units.smallSpacing); ctx.lineTo(left, top + Kirigami.Units.smallSpacing); ctx.moveTo(left, top); ctx.lineTo(left + base, top); ctx.moveTo(left + base, top - Kirigami.Units.smallSpacing); ctx.lineTo(left + base, top + Kirigami.Units.smallSpacing); ctx.stroke(); } } } Label { id: lbl text: label anchors.bottom: parent.bottom anchors.right: parent.right anchors.bottomMargin: canvas.height % base > 2 * Kirigami.Units.smallSpacing ? canvas.height % base + Kirigami.Units.smallSpacing : base + canvas.height % base + Kirigami.Units.smallSpacing anchors.rightMargin: base color: "#da4453" font.pixelSize: 10 - renderType: Text.QtRendering } Row { anchors.bottom: lbl.top anchors.right: lbl.right anchors.margins: Kirigami.Units.smallSpacing spacing: Kirigami.Units.smallSpacing Image { visible: mouse height: Kirigami.Units.iconSizes.medium; width: Kirigami.Units.iconSizes.medium; source: "../../img/edit-select.svg" //smooth: true } Image { visible: touch height: Kirigami.Units.iconSizes.medium; width: Kirigami.Units.iconSizes.medium; source: "../../img/transform-browse.svg" //smooth: true } Image { visible: desktop height: Kirigami.Units.iconSizes.medium; width: Kirigami.Units.iconSizes.medium; source: "../../img/video-display.svg" //smooth: true } Image { visible: mobile height: Kirigami.Units.iconSizes.medium; width: Kirigami.Units.iconSizes.medium; source: "../../img/smartphone.svg" //smooth: true } } }