Warning, /plasma/plasma-desktop/desktoppackage/contents/configuration/panelconfiguration/SliderHandle.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 import QtQuick 2.15 0008 import QtQuick.Layouts 1.0 0009 import QtQuick.Controls 2.4 as QQC2 0010 import org.kde.plasma.plasmoid 2.0 0011 import org.kde.plasma.core as PlasmaCore 0012 import org.kde.plasma.extras 2.0 as PlasmaExtras 0013 import org.kde.kirigami 2.20 as Kirigami 0014 import org.kde.ksvg 1.0 as KSvg 0015 import org.kde.plasma.components 3.0 as PC3 0016 import org.kde.plasma.shell.panel 0.1 as Panel 0017 import org.kde.kquickcontrols 2.0 0018 0019 KSvg.SvgItem { 0020 id: root 0021 0022 //Those properties get updated by PanelConfiguration.qml whenever a value changes 0023 imagePath: "widgets/containment-controls" 0024 elementId: parent.prefix + '-' + graphicElementName 0025 width: naturalSize.width 0026 height: naturalSize.height 0027 0028 //value expressed by this slider, this is the distance to offset 0029 property int value 0030 0031 //name of the graphics to load 0032 property string graphicElementName 0033 0034 //where the point "0" is 0035 property int offset: 0 0036 0037 /*handle type: behave in different ways based on the alignment: 0038 * alignment === Qt.AlignRight: Panel aligned to right and handle value relative to the right 0039 * alignment === Qt.AlignLeft: Panel aligned to left and handle relative to the left 0040 * (alignment !== Qt.AlignRight) && (alignment & Qt.AlignRight): Panel aligned to the center and handle right of offset and value doubled 0041 * (alignment !== Qt.AlignLeft) && (alignment & Qt.AlignLeft): Panel aligned to the center and handle left of offset and value doubled 0042 * else: Panel aligned to center and handle relative to the center 0043 * Note that right/left and top/bottom are interchangeable 0044 */ 0045 property int alignment: panel.alignment 0046 0047 //The maximum/minimum Position (X/Y) the silder can be moved to 0048 property int minimumPosition 0049 property int maximumPosition 0050 //Provide default position for "reset" action. 0051 function defaultPosition(): int { 0052 var dialogSize, panelSize; 0053 if (dialogRoot.vertical) { 0054 dialogSize = dialogRoot.height; 0055 panelSize = panel.height; 0056 } else { 0057 dialogSize = dialogRoot.width; 0058 panelSize = panel.width; 0059 } 0060 return (value === panelSize) ? dialogSize : panelSize; 0061 } 0062 0063 // Handle name displayed as a tooltip. 0064 property string description 0065 0066 property bool hasEverBeenMoved: false 0067 0068 function syncPos() { 0069 if (dialogRoot.vertical) { 0070 if (alignment === Qt.AlignRight) { 0071 y = root.parent.height - (value + offset + root.height/2) 0072 } else if (alignment === Qt.AlignLeft) { 0073 y = value + offset - root.height/2 0074 } else { 0075 if (root.alignment & Qt.AlignRight) { 0076 y = root.parent.height/2 - value/2 + offset - root.height/2 0077 } else if (root.alignment & Qt.AlignLeft) { 0078 y = root.parent.height/2 + value/2 + offset - root.height/2 0079 } else { 0080 y = root.parent.height/2 + value + offset -root.height/2 0081 } 0082 } 0083 } else { 0084 if (alignment === Qt.AlignRight) { 0085 x = root.parent.width - (value + offset + root.width/2) 0086 } else if (alignment === Qt.AlignLeft) { 0087 x = value + offset - root.width/2 0088 } else { 0089 if (root.alignment & Qt.AlignRight) { 0090 x = root.parent.width/2 - value/2 + offset - root.width/2 0091 } else if (root.alignment & Qt.AlignLeft) { 0092 x = root.parent.width/2 + value/2 + offset -root.width/2 0093 } else { 0094 x = root.parent.width/2 + value + offset -root.width/2 0095 } 0096 } 0097 } 0098 } 0099 onValueChanged: syncPos() 0100 onOffsetChanged: syncPos() 0101 onAlignmentChanged: syncPos() 0102 Connections { 0103 target: root.parent 0104 function onWidthChanged() { 0105 syncPos() 0106 } 0107 function onHeightChanged() { 0108 syncPos() 0109 } 0110 } 0111 0112 PC3.ToolTip { 0113 text: root.description 0114 visible: root.description !== "" && ((area.containsMouse && !area.containsPress) || area.activeFocus) 0115 } 0116 0117 MouseArea { 0118 id: area 0119 drag { 0120 target: parent 0121 axis: (dialogRoot.vertical) ? Drag.YAxis : Drag.XAxis 0122 minimumX: root.minimumPosition 0123 minimumY: root.minimumPosition 0124 maximumX: root.maximumPosition 0125 maximumY: root.maximumPosition 0126 } 0127 anchors { 0128 fill: parent 0129 leftMargin: (dialogRoot.vertical) ? 0 : -Kirigami.Units.gridUnit 0130 rightMargin: (dialogRoot.vertical) ? 0 : -Kirigami.Units.gridUnit 0131 topMargin: (dialogRoot.vertical) ? -Kirigami.Units.gridUnit : 0 0132 bottomMargin: (dialogRoot.vertical) ? -Kirigami.Units.gridUnit : 0 0133 } 0134 0135 readonly property int keyboardMoveStepSize: Math.ceil((root.maximumPosition - root.minimumPosition) / 20) 0136 0137 activeFocusOnTab: true 0138 hoverEnabled: true 0139 cursorShape: dialogRoot.vertical ? Qt.SizeVerCursor : Qt.SizeHorCursor 0140 0141 Accessible.description: root.description 0142 0143 Keys.onEnterPressed: doubleClicked(null); 0144 Keys.onReturnPressed: doubleClicked(null); 0145 Keys.onSpacePressed: doubleClicked(null); 0146 0147 // BEGIN Arrow keys 0148 Keys.onUpPressed: if (dialogRoot.vertical) { 0149 root.y = Math.max(root.minimumPosition, root.y - ((event.modifiers & Qt.ShiftModifier) ? 1 : keyboardMoveStepSize)); 0150 changePosition(); 0151 } else { 0152 event.accepted = false; 0153 } 0154 Keys.onDownPressed: if (dialogRoot.vertical) { 0155 root.y = Math.min(root.maximumPosition, root.y + ((event.modifiers & Qt.ShiftModifier) ? 1 : keyboardMoveStepSize)); 0156 changePosition(); 0157 } else { 0158 event.accepted = false; 0159 } 0160 Keys.onLeftPressed: if (!dialogRoot.vertical) { 0161 root.x = Math.max(root.minimumPosition, root.x - ((event.modifiers & Qt.ShiftModifier) ? 1 : keyboardMoveStepSize)); 0162 changePosition(); 0163 } else { 0164 event.accepted = false; 0165 } 0166 Keys.onRightPressed: if (!dialogRoot.vertical) { 0167 root.x = Math.min(root.maximumPosition, root.x + ((event.modifiers & Qt.ShiftModifier) ? 1 : keyboardMoveStepSize)); 0168 changePosition(); 0169 } else { 0170 event.accepted = false; 0171 } 0172 // END Arrow keys 0173 0174 onPositionChanged: { 0175 if (!drag.active) { 0176 return; 0177 } 0178 changePosition(); 0179 } 0180 onDoubleClicked: { 0181 root.value = root.defaultPosition(); 0182 } 0183 0184 function changePosition() { 0185 root.hasEverBeenMoved = true 0186 if (dialogRoot.vertical) { 0187 if (root.alignment === Qt.AlignRight) { 0188 root.value = root.parent.height - (root.y + offset + root.height/2) 0189 } else if (alignment === Qt.AlignLeft) { 0190 root.value = root.y - offset + root.height/2 0191 //Center 0192 } else { 0193 if (root.alignment & Qt.AlignRight) { 0194 root.value = (root.parent.height/2 - root.y + offset)*2 - root.height 0195 } else if (root.alignment & Qt.AlignLeft) { 0196 root.value = (root.y - offset - root.parent.height/2)*2 + root.height 0197 } else { 0198 var value = root.y - root.parent.height/2 - offset + root.height/2 0199 //Snap 0200 if (Math.abs(value) < 5) { 0201 root.value = 0 0202 } else { 0203 root.value = value 0204 } 0205 } 0206 } 0207 } else { 0208 if (root.alignment === Qt.AlignRight) { 0209 root.value = root.parent.width - (root.x + offset + root.width/2) 0210 } else if (alignment === Qt.AlignLeft) { 0211 root.value = root.x - offset + root.width/2 0212 //Center 0213 } else { 0214 if (root.alignment & Qt.AlignRight) { 0215 root.value = (root.parent.width/2 - root.x + offset)*2 - root.width 0216 } else if (root.alignment & Qt.AlignLeft) { 0217 root.value = (root.x - offset - root.parent.width/2)*2 + root.width 0218 } else { 0219 var value = root.x - root.parent.width/2 - offset + root.width/2 0220 //Snap 0221 if (Math.abs(value) < 5) { 0222 root.value = 0 0223 } else { 0224 root.value = value 0225 } 0226 } 0227 } 0228 } 0229 } 0230 0231 PlasmaExtras.Highlight { 0232 anchors.fill: parent 0233 visible: parent.activeFocus 0234 hovered: true 0235 } 0236 } 0237 }