KQuickImageEditor

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

KDE's Doxygen guidelines are available online.