Warning, /graphics/koko/src/qml/OverviewControl.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 QtQml 2.15 0007 import org.kde.kirigami 2.15 as Kirigami 0008 0009 Rectangle { 0010 id: root 0011 property Item target: null 0012 property alias pressed: mouseArea.pressed 0013 property real contentAspectRatio: target ? target.contentAspectRatio : 1 0014 property real widthRatio: target ? target.width / target.contentWidth : 1 0015 property real heightRatio: target ? target.height / target.contentHeight : 1 0016 // Don't use Flickable::visibleArea.xPosition or Flickable::visibleArea.yPosition. They won't give the correct values. 0017 property real normalizedX: target && (target.contentWidth - target.width) !== 0 ? 0018 -target.contentX / (target.contentWidth - target.width) : 0 0019 property real normalizedY: target && (target.contentHeight - target.height) !== 0 ? 0020 -target.contentY / (target.contentHeight - target.height) : 0 0021 readonly property real preferredWidth: contentAspectRatio >= 1 || contentAspectRatio <= 0 ? 0022 implicitWidth : implicitHeight * contentAspectRatio 0023 readonly property real preferredHeight: contentAspectRatio <= 1 ? 0024 implicitHeight : implicitWidth / contentAspectRatio 0025 implicitWidth: 100 0026 implicitHeight: 100 0027 width: preferredWidth 0028 height: preferredHeight 0029 color: Qt.rgba(0,0,0,0.5) 0030 border.color: Qt.rgba(1,1,1,1) 0031 border.width: 1 0032 antialiasing: false // no need for rounding now 0033 Rectangle { 0034 id: handleRect 0035 property bool mouseInside: mouseArea.mouseX >= handleRect.x 0036 && mouseArea.mouseX <= handleRect.x + handleRect.width 0037 && mouseArea.mouseY >= handleRect.y 0038 && mouseArea.mouseY <= handleRect.y + handleRect.height 0039 visible: Math.max(width, height) > dot.implicitHeight 0040 antialiasing: false 0041 width: Math.min(root.width * root.widthRatio, root.width) 0042 height: Math.min(root.height * root.heightRatio, root.height) 0043 color: Qt.rgba(1,1,1,0.25) 0044 border.color: Qt.rgba(1,1,1,0.5) 0045 border.width: 1 0046 Binding { 0047 target: handleRect; property: "x" 0048 value: root.normalizedX * (root.width - handleRect.width) 0049 when: !mouseArea.pressed 0050 restoreMode: Binding.RestoreBinding 0051 } 0052 Binding { 0053 target: handleRect; property: "y" 0054 value: root.normalizedY * (root.height - handleRect.height) 0055 when: !mouseArea.pressed 0056 restoreMode: Binding.RestoreBinding 0057 } 0058 } 0059 Rectangle { 0060 id: dot // For improved visibility 0061 radius: height / 2 0062 anchors.centerIn: handleRect 0063 implicitWidth: 6 0064 implicitHeight: 6 0065 color: "white" 0066 // shadow outline for slightly better contrast. 0067 // Even more contrast when handle is too small. 0068 border.color: Qt.rgba(0, 0, 0, 0069 handleRect.width - 2 <= dot.implicitWidth 0070 || handleRect.height - 2 <= dot.implicitHeight ? 0.4 : 0.2) 0071 border.width: 1 0072 Behavior on border.color { 0073 ColorAnimation { 0074 duration: Kirigami.Units.shortDuration 0075 // No easing curve looks better since the motion between larger 0076 // and smaller handle sizes tends to look fairly linear. 0077 } 0078 } 0079 } 0080 MouseArea { 0081 id: mouseArea 0082 anchors.fill: parent 0083 hoverEnabled: true 0084 cursorShape: if (pressed) { 0085 return Qt.ClosedHandCursor 0086 } else if (handleRect.mouseInside) { 0087 return Qt.OpenHandCursor 0088 } else { 0089 return Qt.ArrowCursor 0090 } 0091 preventStealing: true 0092 drag { 0093 axis: Drag.XAndYAxis 0094 target: handleRect 0095 minimumX: 0 0096 maximumX: root.width - handleRect.width 0097 minimumY: 0 0098 maximumY: root.height - handleRect.height 0099 threshold: 0 0100 } 0101 onPressed: if (!handleRect.mouseInside && !mouseArea.drag.active) { 0102 handleRect.x = Math.max(drag.minimumX, // min 0103 Math.min(mouseArea.mouseX - handleRect.width / 2, 0104 drag.maximumX)) // max 0105 handleRect.y = Math.max(drag.minimumY, // min 0106 Math.min(mouseArea.mouseY - handleRect.height / 2, 0107 drag.maximumY)) // max 0108 } 0109 } 0110 Binding { 0111 target: root; property: "normalizedX" 0112 value: handleRect.x / (root.width - handleRect.width) 0113 when: mouseArea.pressed 0114 restoreMode: Binding.RestoreBinding 0115 } 0116 Binding { 0117 target: root; property: "normalizedY" 0118 value: handleRect.y / (root.height - handleRect.height) 0119 when: mouseArea.pressed 0120 restoreMode: Binding.RestoreBinding 0121 } 0122 }