Warning, /office/klevernotes/src/contents/ui/dialogs/colorDialog/HSPicker.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-License-Identifier: GPL-2.0-or-later 0002 // SPDX-FileCopyrightText: 2023 Louis Schul <schul9louis@gmail.com> 0003 0004 import QtQuick 2.11 0005 0006 Item { 0007 id: root 0008 0009 property real h 0010 property real s 0011 property int cursorRadius: 10 0012 0013 Rectangle { 0014 // This way the middle of the cursor can trully be in a corner 0015 x : cursorRadius 0016 y : cursorRadius + parent.height - 2 * cursorRadius 0017 width: parent.height - 2 * cursorRadius 0018 height: parent.width - 2 * cursorRadius 0019 rotation: -90 0020 transformOrigin: Item.TopLeft 0021 gradient: Gradient { 0022 GradientStop { position: 0.0; color: "#FF0000" } 0023 GradientStop { position: 0.16; color: "#FFFF00" } 0024 GradientStop { position: 0.33; color: "#00FF00" } 0025 GradientStop { position: 0.5; color: "#00FFFF" } 0026 GradientStop { position: 0.76; color: "#0000FF" } 0027 GradientStop { position: 0.85; color: "#FF00FF" } 0028 GradientStop { position: 1.0; color: "#FF0000" } 0029 } 0030 } 0031 0032 Rectangle { 0033 id: bouderies 0034 0035 x: cursorRadius 0036 y: cursorRadius 0037 width: parent.width - 2 * cursorRadius 0038 height: parent.height - 2 * cursorRadius 0039 0040 gradient: Gradient { 0041 GradientStop { position: 1.0; color: "#FFFFFFFF" } 0042 GradientStop { position: 0.0; color: "#00000000" } 0043 } 0044 } 0045 0046 Rectangle { 0047 id: pickerCursor 0048 0049 x: root.h * bouderies.width 0050 y: (root.s * bouderies.height * -1) + bouderies.height 0051 width: cursorRadius*2 0052 height: cursorRadius*2 0053 0054 color: "transparent" 0055 visible: !mouseArea.containsPress 0056 0057 Rectangle { 0058 id: north 0059 0060 x: cursorRadius - 1 0061 width: 2 0062 height: cursorRadius 0063 anchors.top: parent.top 0064 0065 color: "black" 0066 } 0067 0068 Rectangle { 0069 id: east 0070 0071 y: cursorRadius - 1 0072 width: cursorRadius 0073 height: 2 0074 anchors.right: parent.right 0075 0076 color: "black" 0077 } 0078 0079 Rectangle { 0080 id: south 0081 0082 x: cursorRadius - 1 0083 width: 2 0084 height: cursorRadius 0085 anchors.bottom: parent.bottom 0086 0087 color: "black" 0088 } 0089 0090 Rectangle { 0091 id: west 0092 0093 y: cursorRadius - 1 0094 width: cursorRadius 0095 height: 2 0096 anchors.left: parent.left 0097 0098 color: "black" 0099 } 0100 0101 } 0102 0103 MouseArea { 0104 id: mouseArea 0105 0106 anchors.fill: bouderies 0107 0108 cursorShape: (containsPress) ? Qt.CrossCursor : Qt.ArrowCursor 0109 0110 onPressed: function (mouse) { 0111 handleMouse(mouse) 0112 } 0113 onPositionChanged: function (mouse) { 0114 handleMouse(mouse) 0115 } 0116 0117 function handleMouse(mouse) { 0118 if (mouse.buttons & Qt.LeftButton) { 0119 const currentX = Math.max(0, Math.min(bouderies.width, mouse.x)); 0120 const currentY = Math.max(0, Math.min(bouderies.height, mouse.y)); 0121 0122 root.h = (currentX/bouderies.width) 0123 root.s = ((bouderies.height-currentY)/bouderies.height) 0124 } 0125 } 0126 } 0127 }