Warning, /plasma/plasma-desktop/desktoppackage/contents/configuration/panelconfiguration/Ruler.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.0
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.FrameSvgItem {
0020     id: root
0021 
0022     anchors.fill: parent
0023 
0024     //Those properties get updated by PanelConfiguration.qml whenever a value in the panel changes
0025     property alias offset: offsetHandle.value
0026     property alias minimumLength: rightMinimumLengthHandle.value
0027     property alias maximumLength: rightMaximumLengthHandle.value
0028     property bool isHorizontal: root.prefix[0] === 'north' || root.prefix[0] === 'south'
0029 
0030     property string maximumText: (dialogRoot.vertical ? i18nd("plasma_shell_org.kde.plasma.desktop", "Drag to change maximum height.") : i18nd("plasma_shell_org.kde.plasma.desktop", "Drag to change maximum width.")) + "\n" + i18nd("plasma_shell_org.kde.plasma.desktop", "Double click to reset.")
0031     property string minimumText: (dialogRoot.vertical ? i18nd("plasma_shell_org.kde.plasma.desktop", "Drag to change minimum height.") : i18nd("plasma_shell_org.kde.plasma.desktop", "Drag to change minimum width.")) + "\n" + i18nd("plasma_shell_org.kde.plasma.desktop", "Double click to reset.")
0032 
0033     imagePath: "widgets/containment-controls"
0034     implicitWidth: Math.max(offsetHandle.width, rightMinimumLengthHandle.width + rightMaximumLengthHandle.width)
0035     implicitHeight: Math.max(offsetHandle.height, rightMinimumLengthHandle.height + rightMaximumLengthHandle.height)
0036 
0037     onMinimumLengthChanged: rightMinimumLengthHandle.value = leftMinimumLengthHandle.value = minimumLength
0038     onMaximumLengthChanged: rightMaximumLengthHandle.value = leftMaximumLengthHandle.value = maximumLength
0039 
0040     /* As offset and length have a different meaning in all alignments, the panel shifts on alignment change.
0041      * This could result in wrong panel positions (e.g. panel shifted over monitor border).
0042      * The fancy version would be a recalculation of all values, so that the panel stays at it's current position,
0043      * but this would be error prone and complicated. As the panel alignment is rarely changed, it's not worth it.
0044      * The more easy approach is just setting the panel offset to zero. This makes sure the panel has a valid position and size.
0045      */
0046     Connections {
0047         target: panel
0048         function onAlignmentChanged() {
0049             offset = 0
0050         }
0051     }
0052 
0053     Component.onCompleted: {
0054         offsetHandle.value = panel.offset
0055         rightMinimumLengthHandle.value = panel.minimumLength
0056         rightMaximumLengthHandle.value = panel.maximumLength
0057         leftMinimumLengthHandle.value = panel.minimumLength
0058         leftMaximumLengthHandle.value = panel.maximumLength
0059     }
0060 
0061     KSvg.SvgItem {
0062         id: centerMark
0063         imagePath: "widgets/containment-controls"
0064         elementId: dialogRoot.vertical ? "vertical-centerindicator" : "horizontal-centerindicator"
0065         visible: panel.alignment === Qt.AlignCenter
0066         width: dialogRoot.vertical ? parent.width : naturalSize.width
0067         height: dialogRoot.vertical ? naturalSize.height : parent.height
0068         anchors.centerIn: parent
0069     }
0070 
0071     SliderHandle {
0072         id: offsetHandle
0073         anchors {
0074             right: !root.isHorizontal ? root.right : undefined
0075             bottom: root.isHorizontal ? root.bottom : undefined
0076         }
0077         graphicElementName: "offsetslider"
0078         description: i18nd("plasma_shell_org.kde.plasma.desktop", "Drag to change position on this screen edge.\nDouble click to reset.")
0079         offset: panel.alignment === Qt.AlignCenter ? 0 : (dialogRoot.vertical ? panel.height : panel.width) / 2
0080         property int position: (dialogRoot.vertical) ? y + height / 2 : x + width / 2
0081         onPositionChanged: {
0082             if (!offsetHandle.hasEverBeenMoved) return;
0083             let panelLength = dialogRoot.vertical ? panel.height : panel.width
0084             let rootLength = dialogRoot.vertical ? root.height : root.width
0085             // Snap at the center
0086             if (Math.abs(position - rootLength / 2) < 5) {
0087                 if (panel.alignment !== Qt.AlignCenter) {
0088                     panel.alignment = Qt.AlignCenter
0089                     // Coordinate change: since we switch from measuring the min/max
0090                     // length from the side of the panel to the center of the panel,
0091                     // we need to double the distance between the min/max indicators
0092                     // and the panel side.
0093                     panel.minimumLength += panel.minimumLength - panelLength
0094                     panel.maximumLength += panel.maximumLength - panelLength
0095                 }
0096                 panel.offset = 0
0097             } else if (position > rootLength / 2) {
0098                 if (panel.alignment === Qt.AlignCenter) {
0099                     // This is the opposite of the previous comment, as we are
0100                     // cutting in half the distance between the min/max indicators
0101                     // and the side of the panel.
0102                     panel.minimumLength -= (panel.minimumLength - panelLength) / 2
0103                     panel.maximumLength -= (panel.maximumLength - panelLength) / 2
0104                 }
0105                 panel.alignment = Qt.AlignRight
0106                 panel.offset = Math.round(rootLength - position - offset)
0107             } else if (position <= rootLength / 2) {
0108                 if (panel.alignment === Qt.AlignCenter) {
0109                     panel.minimumLength -= (panel.minimumLength - panelLength) / 2
0110                     panel.maximumLength -= (panel.maximumLength - panelLength) / 2
0111                 }
0112                 panel.alignment = Qt.AlignLeft
0113                 panel.offset = Math.round(position - offset)
0114             }
0115         }
0116         /* The maximum/minimumPosition values are needed to prevent the user from moving a panel with
0117          * center alignment to the left and then drag the position handle to the left.
0118          * This would make the panel to go off the monitor:
0119          * |<-        V        ->                         |
0120          * |  ->      |      <-                           |
0121          *            ^move this slider to the left
0122          */
0123         minimumPosition: {
0124             var size = dialogRoot.vertical ? height : width
0125             switch(panel.alignment){
0126             case Qt.AlignLeft:
0127                 return -size / 2 + offset
0128             case Qt.AlignRight:
0129                 return leftMaximumLengthHandle.value - size / 2 - offset
0130             default:
0131                 return panel.maximumLength / 2 - size / 2
0132             }
0133         }
0134         //Needed for the same reason as above
0135         maximumPosition: {
0136             var size = dialogRoot.vertical ? height : width
0137             var rootSize = dialogRoot.vertical ? root.height : root.width
0138             switch(panel.alignment){
0139             case Qt.AlignLeft:
0140                 return rootSize - rightMaximumLengthHandle.value - size / 2 + offset
0141             case Qt.AlignRight:
0142                 return rootSize - size / 2 - offset
0143             default:
0144                 return rootSize - panel.maximumLength / 2 - size / 2
0145             }
0146         }
0147         function defaultPosition(): int /*override*/ {
0148             return 0;
0149         }
0150     }
0151 
0152     /* The maximumPosition value for the right handles and the minimumPosition value for the left handles are
0153      * needed to prevent the user from moving a panel with center alignment to the left (right) and then pull one of the
0154      * right (left) sliders to the right (left).
0155      * Because the left and right sliders are coupled, this would make the left (right) sliders to go off the monitor.
0156      *
0157      * |<-        V        ->                         |
0158      * |   ->     |     <-                            |
0159      *                      ^move this slider to the right
0160      *
0161      * The other max/min Position values just set a minimum panel size
0162      */
0163 
0164     SliderHandle {
0165         id: rightMinimumLengthHandle
0166         anchors {
0167             left: !root.isHorizontal ? root.left : undefined
0168             top: root.isHorizontal ? root.top : undefined
0169         }
0170         description: root.minimumText
0171         alignment: panel.alignment | Qt.AlignLeft
0172         visible: panel.alignment !== Qt.AlignRight
0173         offset: panel.offset
0174         graphicElementName: "minslider"
0175         onValueChanged: panel.minimumLength = value
0176         minimumPosition: offsetHandle.position + Kirigami.Units.gridUnit * 3
0177         maximumPosition: {
0178             var rootSize = dialogRoot.vertical ? root.height : root.width
0179             var size = dialogRoot.vertical ? height : width
0180             panel.alignment === Qt.AlignCenter ? Math.min(rootSize - size/2, rootSize + offset * 2 - size/2) : rootSize - size/2
0181         }
0182     }
0183 
0184     SliderHandle {
0185         id: rightMaximumLengthHandle
0186         anchors {
0187             right: !root.isHorizontal ? root.right : undefined
0188             bottom: root.isHorizontal ? root.bottom : undefined
0189         }
0190         description: root.maximumText
0191         alignment: panel.alignment | Qt.AlignLeft
0192         visible: panel.alignment !== Qt.AlignRight
0193         offset: panel.offset
0194         graphicElementName: "maxslider"
0195         onValueChanged: panel.maximumLength = value
0196         minimumPosition: offsetHandle.position + Kirigami.Units.gridUnit * 3
0197         maximumPosition: {
0198             var rootSize = dialogRoot.vertical ? root.height : root.width
0199             var size = dialogRoot.vertical ? height : width
0200             panel.alignment === Qt.AlignCenter ? Math.min(rootSize - size/2, rootSize + offset * 2 - size/2) : rootSize - size/2
0201         }
0202     }
0203 
0204     SliderHandle {
0205         id: leftMinimumLengthHandle
0206         anchors {
0207             left: !root.isHorizontal ? root.left : undefined
0208             top: root.isHorizontal ? root.top : undefined
0209         }
0210         description: root.minimumText
0211         alignment: panel.alignment | Qt.AlignRight
0212         visible: panel.alignment !== Qt.AlignLeft
0213         offset: panel.offset
0214         graphicElementName: "maxslider"
0215         onValueChanged: panel.minimumLength = value
0216         maximumPosition: offsetHandle.position - Kirigami.Units.gridUnit * 3
0217         minimumPosition: {
0218             var size = dialogRoot.vertical ? height : width
0219             panel.alignment === Qt.AlignCenter ? Math.max(-size/2, offset*2 - size/2) : -size/2
0220         }
0221     }
0222 
0223     SliderHandle {
0224         id: leftMaximumLengthHandle
0225         anchors {
0226             right: !root.isHorizontal ? root.right : undefined
0227             bottom: root.isHorizontal ? root.bottom : undefined
0228         }
0229         description: root.maximumText
0230         alignment: panel.alignment | Qt.AlignRight
0231         visible: panel.alignment !== Qt.AlignLeft
0232         offset: panel.offset
0233         graphicElementName: "minslider"
0234         onValueChanged: panel.maximumLength = value
0235         maximumPosition: offsetHandle.position - Kirigami.Units.gridUnit * 3
0236         minimumPosition: {
0237             var size = dialogRoot.vertical ? height : width
0238             panel.alignment === Qt.AlignCenter ? Math.max(-size/2, offset*2 - size/2) : -size/2
0239         }
0240     }
0241 }