Warning, /libraries/kquickimageeditor/src/controls/qt5/SelectionHandle.qml is written in an unsupported language. File is not indexed.

0001 /* SPDX-FileCopyrightText: 2021 Noah Davis <noahadvs@gmail.com>
0002  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0003  */
0004 
0005 import QtQuick 2.15
0006 import QtGraphicalEffects 1.15
0007 import org.kde.kirigami 2.15 as Kirigami
0008 
0009 MouseArea {
0010     id: root
0011     enum Position {
0012         TopLeft,    Top,    TopRight,
0013         Left,               Right,
0014         BottomLeft, Bottom, BottomRight,
0015         NPositions
0016     }
0017     required property Item target
0018     property int position: SelectionHandle.TopLeft
0019 
0020     readonly property bool leftSide: position === SelectionHandle.TopLeft
0021         || position === SelectionHandle.Left
0022         || position === SelectionHandle.BottomLeft
0023     readonly property bool rightSide: position === SelectionHandle.TopRight
0024         || position === SelectionHandle.Right
0025         || position === SelectionHandle.BottomRight
0026     readonly property bool topSide: position === SelectionHandle.TopLeft
0027         || position === SelectionHandle.Top
0028         || position === SelectionHandle.TopRight
0029     readonly property bool bottomSide: position === SelectionHandle.BottomLeft
0030         || position === SelectionHandle.Bottom
0031         || position === SelectionHandle.BottomRight
0032     readonly property bool horizontalOnly: position === SelectionHandle.Left || position === SelectionHandle.Right
0033     readonly property bool verticalOnly: position === SelectionHandle.Top || position === SelectionHandle.Bottom
0034     // Like forward slash
0035     readonly property bool forwardDiagonal: position === SelectionHandle.TopRight || position === SelectionHandle.BottomLeft
0036     // Like backward slash
0037     readonly property bool backwardDiagonal: position === SelectionHandle.TopLeft || position === SelectionHandle.BottomRight
0038 
0039     property bool lockX: false
0040     property bool lockY: false
0041 
0042     LayoutMirroring.enabled: false
0043     LayoutMirroring.childrenInherit: true
0044     anchors.horizontalCenter: if (!pressed && !lockX) {
0045         if (leftSide) {
0046             target.left
0047         } else if (verticalOnly) {
0048             target.horizontalCenter
0049         } else {
0050             target.right
0051         }
0052     }
0053     anchors.verticalCenter: if (!pressed && !lockY) {
0054         if (topSide) {
0055             target.top
0056         } else if (horizontalOnly) {
0057             target.verticalCenter
0058         } else {
0059             target.bottom
0060         }
0061     }
0062     implicitWidth: graphics.implicitWidth + Kirigami.Units.largeSpacing * 2
0063     implicitHeight: graphics.implicitHeight + Kirigami.Units.largeSpacing * 2
0064     width: verticalOnly ? target.width - implicitWidth : implicitWidth
0065     height: horizontalOnly ? target.height - implicitHeight : implicitHeight
0066     cursorShape: if (horizontalOnly) {
0067         Qt.SizeHorCursor
0068     } else if (verticalOnly) {
0069         Qt.SizeVerCursor
0070     } else if (forwardDiagonal) {
0071         // actually oriented like forward slash
0072         Qt.SizeBDiagCursor
0073     } else {
0074         // actually oriented like backward slash
0075         Qt.SizeFDiagCursor
0076     }
0077     drag {
0078         axis: if (horizontalOnly) {
0079             Drag.XAxis
0080         } else if (verticalOnly) {
0081             Drag.YAxis
0082         } else {
0083             Drag.XAndYAxis
0084         }
0085         target: pressed ? root : null
0086         minimumX: -width / 2
0087         maximumX: parent.width - width / 2
0088         minimumY: -height / 2
0089         maximumY: parent.height - height / 2
0090         threshold: 0
0091     }
0092     Rectangle {
0093         id: graphics
0094         visible: false
0095         implicitWidth: Kirigami.Units.gridUnit + Kirigami.Units.gridUnit % 2
0096         implicitHeight: Kirigami.Units.gridUnit + Kirigami.Units.gridUnit % 2
0097         anchors.centerIn: parent
0098         color: Kirigami.Theme.highlightColor
0099         radius: height / 2
0100     }
0101     // Has to be the same size as source
0102     Item {
0103         id: maskSource
0104         visible: false
0105         anchors.fill: graphics
0106         Rectangle {
0107             x: root.leftSide ? parent.width - width : 0
0108             y: root.topSide ? parent.height - height : 0
0109             width: root.forwardDiagonal || root.backwardDiagonal || root.horizontalOnly ? parent.width / 2 : parent.width
0110             height: root.forwardDiagonal || root.backwardDiagonal || root.verticalOnly ? parent.height / 2 : parent.height
0111         }
0112     }
0113     OpacityMask {
0114         anchors.fill: graphics
0115         cached: true
0116         invert: true
0117         source: graphics
0118         maskSource: maskSource
0119     }
0120 }