MauiKit Image Tools

SelectionHandle.qml
1/* SPDX-FileCopyrightText: 2021 Noah Davis <noahadvs@gmail.com>
2 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
3 */
4
5import QtQuick
6import QtQuick.Effects
7
8import org.mauikit.controls as Maui
9
10MouseArea {
11 id: root
12 enum Position {
13 TopLeft, Top, TopRight,
14 Left, Right,
15 BottomLeft, Bottom, BottomRight,
16 NPositions
17 }
18 required property Item target
19 property int position: SelectionHandle.TopLeft
20
21 readonly property bool leftSide: position === SelectionHandle.TopLeft
22 || position === SelectionHandle.Left
23 || position === SelectionHandle.BottomLeft
24 readonly property bool rightSide: position === SelectionHandle.TopRight
25 || position === SelectionHandle.Right
26 || position === SelectionHandle.BottomRight
27 readonly property bool topSide: position === SelectionHandle.TopLeft
28 || position === SelectionHandle.Top
29 || position === SelectionHandle.TopRight
30 readonly property bool bottomSide: position === SelectionHandle.BottomLeft
31 || position === SelectionHandle.Bottom
32 || position === SelectionHandle.BottomRight
33 readonly property bool horizontalOnly: position === SelectionHandle.Left || position === SelectionHandle.Right
34 readonly property bool verticalOnly: position === SelectionHandle.Top || position === SelectionHandle.Bottom
35 // Like forward slash
36 readonly property bool forwardDiagonal: position === SelectionHandle.TopRight || position === SelectionHandle.BottomLeft
37 // Like backward slash
38 readonly property bool backwardDiagonal: position === SelectionHandle.TopLeft || position === SelectionHandle.BottomRight
39
40 property bool lockX: false
41 property bool lockY: false
42
43 LayoutMirroring.enabled: false
44 LayoutMirroring.childrenInherit: true
45 anchors.horizontalCenter: if (!pressed && !lockX) {
46 if (leftSide) {
47 target.left
48 } else if (verticalOnly) {
49 target.horizontalCenter
50 } else {
51 target.right
52 }
53 }
54 anchors.verticalCenter: if (!pressed && !lockY) {
55 if (topSide) {
56 target.top
57 } else if (horizontalOnly) {
58 target.verticalCenter
59 } else {
60 target.bottom
61 }
62 }
63 implicitWidth: graphics.implicitWidth + Maui.Style.space.large* 2
64 implicitHeight: graphics.implicitHeight + Maui.Style.space.large* 2
65 width: verticalOnly ? target.width - implicitWidth : implicitWidth
66 height: horizontalOnly ? target.height - implicitHeight : implicitHeight
67 cursorShape: if (horizontalOnly) {
68 Qt.SizeHorCursor
69 } else if (verticalOnly) {
70 Qt.SizeVerCursor
71 } else if (forwardDiagonal) {
72 // actually oriented like forward slash
73 Qt.SizeBDiagCursor
74 } else {
75 // actually oriented like backward slash
76 Qt.SizeFDiagCursor
77 }
78 drag {
79 axis: if (horizontalOnly) {
80 Drag.XAxis
81 } else if (verticalOnly) {
82 Drag.YAxis
83 } else {
84 Drag.XAndYAxis
85 }
86 target: pressed ? root : null
87 minimumX: -width / 2
88 maximumX: parent.width - width / 2
89 minimumY: -height / 2
90 maximumY: parent.height - height / 2
91 threshold: 0
92 }
93 Rectangle {
94 id: graphics
95 visible: false
96 implicitWidth: Maui.Style.units.gridUnit + Maui.Style.units.gridUnit % 2
97 implicitHeight: Maui.Style.units.gridUnit + Maui.Style.units.gridUnit % 2
98 anchors.centerIn: parent
99 color: Maui.Theme.highlightColor
100 radius: height / 2
101 }
102 // Has to be the same size as source
103 Item {
104 id: maskSource
105 visible: false
106 anchors.fill: graphics
107 Rectangle {
108 x: root.leftSide ? parent.width - width : 0
109 y: root.topSide ? parent.height - height : 0
110 width: root.forwardDiagonal || root.backwardDiagonal || root.horizontalOnly ? parent.width / 2 : parent.width
111 height: root.forwardDiagonal || root.backwardDiagonal || root.verticalOnly ? parent.height / 2 : parent.height
112 }
113 }
114 MultiEffect {
115 anchors.fill: graphics
116 maskInverted: true
117 source: graphics
118 maskEnabled: true
119 maskSource: ShaderEffectSource {
120 sourceItem: maskSource
121 }
122 }
123}
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Apr 25 2025 11:51:53 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.