Warning, /graphics/spectacle/src/Gui/Annotations/ResizeHandles.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * SPDX-FileCopyrightText: 2022 Marco Martin <mart@kde.org>
0003 *
0004 * SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006
0007 import QtQuick
0008 import org.kde.kirigami as Kirigami
0009 import org.kde.spectacle.private
0010 import ".."
0011
0012 AnimatedLoader {
0013 id: root
0014 required property AnnotationViewport viewport
0015 readonly property AnnotationDocument document: viewport.document
0016 readonly property bool shouldShow: enabled
0017 && document.tool.type === AnnotationTool.SelectTool
0018 && document.selectedItem.hasSelection
0019 && (document.selectedItem.options & AnnotationTool.TextOption) === 0
0020 property bool dragging: false
0021
0022 state: shouldShow ? "active" : "inactive"
0023
0024 sourceComponent: Item {
0025 id: resizeHandles
0026 readonly property bool dragging: tlHandle.active || tHandle.active || trHandle.active
0027 || lHandle.active || rHandle.active
0028 || blHandle.active || bHandle.active || brHandle.active
0029
0030 LayoutMirroring.enabled: false
0031 LayoutMirroring.childrenInherit: true
0032
0033 focus: true
0034
0035 Binding {
0036 target: root
0037 property: "dragging"
0038 value: resizeHandles.dragging
0039 when: root.shouldShow
0040 restoreMode: Binding.RestoreNone
0041 }
0042
0043 // These have to be set here to avoid having a (0,0,0,0) rect.
0044 Binding {
0045 target: root
0046 property: "x"
0047 value: root.document.selectedItem.mousePath.boundingRect.x
0048 when: root.shouldShow
0049 restoreMode: Binding.RestoreNone
0050 }
0051 Binding {
0052 target: root
0053 property: "y"
0054 value: root.document.selectedItem.mousePath.boundingRect.y
0055 when: root.shouldShow
0056 restoreMode: Binding.RestoreNone
0057 }
0058 Binding {
0059 target: root
0060 property: "width"
0061 value: root.document.selectedItem.mousePath.boundingRect.width
0062 when: root.shouldShow
0063 restoreMode: Binding.RestoreNone
0064 }
0065 Binding {
0066 target: root
0067 property: "height"
0068 value: root.document.selectedItem.mousePath.boundingRect.height
0069 when: root.shouldShow
0070 restoreMode: Binding.RestoreNone
0071 }
0072
0073 SelectionBackground {
0074 id: outline
0075 svgPath: root.document.selectedItem.mousePath.svgPath
0076 zoom: root.viewport.effectiveZoom
0077 pathScale: Qt.size((root.width + effectiveStrokeWidth) / root.width,
0078 (root.height + effectiveStrokeWidth) / root.height)
0079 x: -startX - boundingRect.x
0080 y: -startY - boundingRect.y
0081 width: boundingRect.width
0082 height: boundingRect.height
0083 containsMode: SelectionBackground.FillContains
0084 HoverHandler {
0085 cursorShape: Qt.SizeAllCursor
0086 }
0087 }
0088
0089 component ResizeHandle: Handle {
0090 id: handle
0091 property int edges
0092 readonly property alias active: dragHandler.active
0093
0094 implicitWidth: Kirigami.Units.gridUnit + Kirigami.Units.gridUnit % 2
0095 implicitHeight: Kirigami.Units.gridUnit + Kirigami.Units.gridUnit % 2
0096 visible: root.document.selectedItem.hasSelection
0097 && (root.document.selectedItem.options & AnnotationTool.NumberOption) === 0
0098 enabled: visible
0099
0100 HoverHandler {
0101 margin: dragHandler.margin
0102 cursorShape: {
0103 if (enabled) {
0104 if (handle.edges === (Qt.LeftEdge | Qt.TopEdge)
0105 || handle.edges === (Qt.RightEdge | Qt.BottomEdge)) {
0106 return Qt.SizeFDiagCursor;
0107 } else if (handle.edges === Qt.LeftEdge
0108 || handle.edges === Qt.RightEdge) {
0109 return Qt.SizeHorCursor;
0110 } else if (handle.edges === (Qt.LeftEdge | Qt.BottomEdge)
0111 || handle.edges === (Qt.RightEdge | Qt.TopEdge)) {
0112 return Qt.SizeBDiagCursor;
0113 } else if (handle.edges === Qt.TopEdge
0114 || handle.edges === Qt.BottomEdge) {
0115 return Qt.SizeVerCursor;
0116 }
0117 } else {
0118 return undefined
0119 }
0120 }
0121 }
0122 DragHandler {
0123 id: dragHandler
0124 margin: Math.min(root.width, root.height) < 12 ? 0 : 4
0125 target: null
0126 dragThreshold: 0
0127 onActiveTranslationChanged: if (active) {
0128 let dx = activeTranslation.x / viewport.effectiveZoom
0129 let dy = activeTranslation.y / viewport.effectiveZoom
0130 root.document.selectedItem.transform(dx, dy, edges)
0131 }
0132 onActiveChanged: if (!active) {
0133 root.document.selectedItem.commitChanges()
0134 }
0135 }
0136 }
0137 ResizeHandle {
0138 id: tlHandle
0139 anchors {
0140 horizontalCenter: parent.left
0141 verticalCenter: parent.top
0142 }
0143 startAngle: 90
0144 sweepAngle: 270
0145 edges: Qt.TopEdge | Qt.LeftEdge
0146 }
0147 ResizeHandle {
0148 id: lHandle
0149 anchors {
0150 horizontalCenter: parent.left
0151 verticalCenter: parent.verticalCenter
0152 }
0153 startAngle: 90
0154 sweepAngle: 180
0155 edges: Qt.LeftEdge
0156 }
0157 ResizeHandle {
0158 id: blHandle
0159 anchors {
0160 horizontalCenter: parent.left
0161 verticalCenter: parent.bottom
0162 }
0163 startAngle: 0
0164 sweepAngle: 270
0165 edges: Qt.BottomEdge | Qt.LeftEdge
0166 }
0167 ResizeHandle {
0168 id: tHandle
0169 anchors {
0170 horizontalCenter: parent.horizontalCenter
0171 verticalCenter: parent.top
0172 }
0173 startAngle: 180
0174 sweepAngle: 180
0175 edges: Qt.TopEdge
0176 }
0177 ResizeHandle {
0178 id: bHandle
0179 anchors {
0180 horizontalCenter: parent.horizontalCenter
0181 verticalCenter: parent.bottom
0182 }
0183 startAngle: 0
0184 sweepAngle: 180
0185 edges: Qt.BottomEdge
0186 }
0187 ResizeHandle {
0188 id: trHandle
0189 anchors {
0190 horizontalCenter: parent.right
0191 verticalCenter: parent.top
0192 }
0193 startAngle: 180
0194 sweepAngle: 270
0195 edges: Qt.TopEdge | Qt.RightEdge
0196 }
0197 ResizeHandle {
0198 id: rHandle
0199 anchors {
0200 horizontalCenter: parent.right
0201 verticalCenter: parent.verticalCenter
0202 }
0203 startAngle: 270
0204 sweepAngle: 180
0205 edges: Qt.RightEdge
0206 }
0207 ResizeHandle {
0208 id: brHandle
0209 anchors {
0210 horizontalCenter: parent.right
0211 verticalCenter: parent.bottom
0212 }
0213 startAngle: 270
0214 sweepAngle: 270
0215 edges: Qt.BottomEdge | Qt.RightEdge
0216 }
0217 Component.onCompleted: forceActiveFocus()
0218 }
0219 }
0220
0221