Warning, /plasma/latte-dock/shell/package/contents/controls/DragCorner.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2021 Michail Vourlakos <mvourlakos@gmail.com> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 import QtQuick 2.7 0007 import org.kde.plasma.core 2.0 as PlasmaCore 0008 0009 Rectangle { 0010 id: _corner 0011 width: 22 0012 height: width 0013 anchors.horizontalCenter: parent.right 0014 anchors.verticalCenter: parent.top 0015 rotation: 45 0016 color: resizeWindowMouseArea.isActive ? theme.buttonFocusColor : theme.textColor 0017 opacity: resizeWindowMouseArea.isActive ? 1 : 0.2 0018 0019 readonly property alias isActive: resizeWindowMouseArea.isActive 0020 0021 MouseArea { 0022 id: resizeWindowMouseArea 0023 anchors.fill: parent 0024 hoverEnabled: true 0025 0026 cursorShape: plasmoid.location === PlasmaCore.Types.LeftEdge ? Qt.SizeBDiagCursor : Qt.SizeFDiagCursor 0027 0028 readonly property bool isActive: containsMouse || pressed 0029 0030 property bool initialized: false 0031 property int initGlobalX: 0 0032 property int initGlobalY: 0 0033 property int initWidth: 100 0034 property int initHeight: 100 0035 property real initScaleWidth: 1 0036 property real initScaleHeight: 1 0037 0038 property int curGlobalX: 0 0039 property int curGlobalY: 0 0040 0041 onPressed: { 0042 if (pressed) { 0043 var scenePos = mapToGlobal(mouse.x, mouse.y); 0044 0045 if (plasmoid.location !== PlasmaCore.Types.LeftEdge) { 0046 initGlobalX = viewConfig.x + mouse.x; 0047 initGlobalY = viewConfig.y + mouse.y; 0048 } else { 0049 initGlobalX = viewConfig.x + mouse.x; 0050 initGlobalY = viewConfig.y + mouse.y; 0051 } 0052 0053 initWidth = dialog.width; 0054 initHeight = dialog.height; 0055 initScaleWidth = dialog.userScaleWidth; 0056 initScaleHeight = dialog.userScaleHeight; 0057 initialized = true; 0058 } 0059 } 0060 0061 onPositionChanged: { 0062 if (pressed && initialized) { 0063 var scenePos = mapToGlobal(mouse.x, mouse.y); 0064 if (plasmoid.location !== PlasmaCore.Types.LeftEsge) { 0065 curGlobalX = viewConfig.x + mouse.x; 0066 curGlobalY = viewConfig.y + mouse.y; 0067 } else { 0068 curGlobalX = viewConfig.x + mouse.x; 0069 curGlobalY = viewConfig.y + mouse.y; 0070 } 0071 0072 var differX = 0; 0073 0074 if (plasmoid.location !== PlasmaCore.Types.LeftEdge) { 0075 differX = initGlobalX - curGlobalX; 0076 } else { 0077 differX = curGlobalX - initGlobalX; 0078 } 0079 0080 //! In normal settings mode for horizontal View when dragging the corner the length must be increased two times 0081 //! in order to be in the exact position when finished 0082 var percentXMultiplier = (!dialog.advancedLevel && plasmoid.formFactor===PlasmaCore.Types.Horizontal ? 2 : 1); 0083 0084 var percentX = percentXMultiplier * (differX / initWidth); 0085 var newScaleWidth = Math.max(0.35, initScaleWidth + (percentX*initScaleWidth)).toFixed(3); 0086 0087 var newScaleHeight = dialog.userScaleHeight; 0088 0089 if (!dialog.advancedLevel) { 0090 var differY = 0; 0091 0092 if (plasmoid.location !== PlasmaCore.Types.LeftEdge) { 0093 if (plasmoid.location === PlasmaCore.Types.TopEdge) { 0094 differY = curGlobalY - initGlobalY; 0095 } else { 0096 differY = initGlobalY - curGlobalY; 0097 } 0098 } else { 0099 differY = initGlobalY - curGlobalY; 0100 } 0101 0102 var percentYMultiplier = (!dialog.advancedLevel && plasmoid.formFactor===PlasmaCore.Types.Vertical ? 2 : 1); 0103 var percentY = percentYMultiplier * (differY / initHeight); 0104 newScaleHeight = Math.max(0.5, initScaleHeight + (percentY*initScaleHeight)).toFixed(3); 0105 } 0106 0107 universalSettings.setScreenScales(latteView.positioner.currentScreenName, newScaleWidth, newScaleHeight); 0108 dialog.userScaleWidth = newScaleWidth; 0109 dialog.userScaleHeight = newScaleHeight; 0110 viewConfig.syncGeometry(); 0111 } else if (!pressed) { 0112 initialized = false; 0113 } 0114 } 0115 0116 onReleased: { 0117 initialized = false; 0118 } 0119 0120 onDoubleClicked: { 0121 dialog.userScaleWidth = 1; 0122 dialog.userScaleHeight = 1; 0123 universalSettings.setScreenScales(latteView.positioner.currentScreenName, 1, 1); 0124 viewConfig.syncGeometry(); 0125 } 0126 } 0127 0128 states:[ 0129 State{ 0130 name: "bottom" 0131 when: plasmoid.location === PlasmaCore.Types.BottomEdge 0132 0133 AnchorChanges{ 0134 target: _corner; 0135 anchors.horizontalCenter: parent.left; anchors.verticalCenter: parent.top; 0136 } 0137 }, 0138 State{ 0139 name: "top" 0140 when: plasmoid.location === PlasmaCore.Types.TopEdge 0141 0142 AnchorChanges{ 0143 target: _corner; 0144 anchors.horizontalCenter: parent.left; anchors.verticalCenter: parent.top; 0145 } 0146 }, 0147 State{ 0148 name: "left" 0149 when: plasmoid.location === PlasmaCore.Types.LeftEdge 0150 0151 AnchorChanges{ 0152 target: _corner; 0153 anchors.horizontalCenter: parent.right; anchors.verticalCenter: parent.top; 0154 } 0155 }, 0156 State{ 0157 name: "right" 0158 when: plasmoid.location === PlasmaCore.Types.RightEdge 0159 0160 AnchorChanges{ 0161 target: _corner; 0162 anchors.horizontalCenter: parent.left; anchors.verticalCenter: parent.top; 0163 } 0164 } 0165 ] 0166 }