Warning, /plasma/plasma-desktop/containments/desktop/package/contents/ui/RenameEditor.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2014-2015 Eike Hein <hein@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 import QtQuick 2.15 0008 import QtQuick.Layouts 1.15 0009 import QtQml 2.15 0010 0011 import org.kde.plasma.plasmoid 2.0 0012 import org.kde.plasma.components 3.0 as PlasmaComponents 0013 import org.kde.kquickcontrolsaddons 2.0 0014 import org.kde.kirigami 2.20 as Kirigami 0015 0016 0017 PlasmaComponents.ScrollView { 0018 id: root 0019 0020 property alias text: editor.text 0021 property alias targetItem: editor.targetItem 0022 signal commit 0023 0024 onFocusChanged: { 0025 if (focus) { 0026 editor.forceActiveFocus(); 0027 } 0028 } 0029 0030 PlasmaComponents.TextArea { 0031 id: editor 0032 0033 wrapMode: root.useListViewMode ? TextEdit.NoWrap : TextEdit.Wrap 0034 0035 textMargin: 0 0036 0037 horizontalAlignment: root.useListViewMode ? TextEdit.AlignLeft : TextEdit.AlignHCenter 0038 0039 rightPadding: root.PlasmaComponents.ScrollBar.vertical.visible ? root.PlasmaComponents.ScrollBar.vertical.width : 0 0040 0041 property Item targetItem: null 0042 0043 Binding { 0044 target: editor.background 0045 property: "width" 0046 value: root.width 0047 } 0048 Binding { 0049 target: editor.background 0050 property: "height" 0051 value: root.height 0052 } 0053 Component.onCompleted: root.contentItem.clip = false 0054 0055 onTargetItemChanged: { 0056 if (targetItem !== null) { 0057 var xy = getXY(); 0058 root.x = xy[0]; 0059 root.y = xy[1]; 0060 root.width = getWidth(); 0061 root.height = getInitHeight(); 0062 text = targetItem.name; 0063 adjustSize(); 0064 editor.select(0, dir.fileExtensionBoundary(positioner.map(targetItem.index))); 0065 if (isPopup) { 0066 root.contentItem.contentX = Math.max(root.contentItem.contentWidth - contentItem.width, 0); 0067 } else { 0068 root.contentItem.contentY = Math.max(root.contentItem.contentHeight - contentItem.height, 0); 0069 } 0070 root.visible = true; 0071 } else { 0072 root.x = 0; 0073 root.y = 0; 0074 root.visible = false; 0075 } 0076 } 0077 0078 Keys.onPressed: event => { 0079 switch(event.key) { 0080 case Qt.Key_Return: 0081 case Qt.Key_Enter: 0082 root.commit(); 0083 break; 0084 case Qt.Key_Escape: 0085 if (targetItem) { 0086 targetItem = null; 0087 event.accepted = true; 0088 } 0089 break; 0090 case Qt.Key_Home: 0091 if (event.modifiers & Qt.ShiftModifier) { 0092 editor.select(0, cursorPosition); 0093 } else { 0094 editor.select(0, 0); 0095 } 0096 event.accepted = true; 0097 break; 0098 case Qt.Key_End: 0099 if (event.modifiers & Qt.ShiftModifier) { 0100 editor.select(cursorPosition, text.length); 0101 } else { 0102 editor.select(text.length, text.length); 0103 } 0104 event.accepted = true; 0105 break; 0106 default: 0107 adjustSize(); 0108 break; 0109 } 0110 } 0111 0112 Keys.onReleased: event => { 0113 adjustSize(); 0114 } 0115 0116 function getXY() { 0117 if (!targetItem) { 0118 return [0,0]; 0119 } 0120 var pos = main.mapFromItem(targetItem, targetItem.labelArea.x, targetItem.labelArea.y); 0121 var _x, _y; 0122 if (root.useListViewMode) { 0123 _x = targetItem.labelArea.x - editor.leftPadding; 0124 _y = pos.y - editor.topPadding; 0125 } else { 0126 _x = targetItem.x + Math.abs(Math.min(gridView.contentX, gridView.originX)); 0127 _x += editor.leftPadding; 0128 _x += scrollArea.viewport.x; 0129 if (root.PlasmaComponents.ScrollBar.vertical.policy === Qt.ScrollBarAlwaysOn 0130 && gridView.effectiveLayoutDirection === Qt.RightToLeft) { 0131 _x -= root.PlasmaComponents.ScrollBar.vertical.width; 0132 } 0133 _y = pos.y + Kirigami.Units.smallSpacing - editor.topPadding; 0134 } 0135 return [ _x, _y ]; 0136 } 0137 0138 function getWidth(addWidthVerticalScroller) { 0139 if (!targetItem) { 0140 return 0; 0141 } 0142 return(targetItem.label.parent.width - Kirigami.Units.smallSpacing + 0143 (root.useListViewMode ? -(editor.leftPadding + editor.rightPadding + Kirigami.Units.smallSpacing) : 0) + 0144 (addWidthVerticalScroller ? root.PlasmaComponents.ScrollBar.vertical.width : 0)); 0145 } 0146 0147 function getHeight(addWidthHoriozontalScroller, init) { 0148 if (!targetItem) { 0149 return 0; 0150 } 0151 var _height; 0152 if (isPopup || init) { 0153 _height = targetItem.labelArea.height + editor.topPadding + editor.bottomPadding; 0154 } else { 0155 var realHeight = contentHeight + editor.topPadding + editor.bottomPadding; 0156 var maxHeight = Kirigami.Units.iconSizes.sizeForLabels * (Plasmoid.configuration.textLines + 1) + editor.topPadding + editor.bottomPadding; 0157 _height = Math.min(realHeight, maxHeight); 0158 } 0159 return _height + (addWidthHoriozontalScroller ? root.PlasmaComponents.ScrollBar.horizontal.height : 0); 0160 } 0161 0162 function getInitHeight() { 0163 return getHeight(false, true); 0164 } 0165 0166 function adjustSize() { 0167 if (isPopup) { 0168 if(contentWidth + editor.leftPadding + editor.rightPadding > root.width) { 0169 root.visible = targetItem !== null; 0170 root.PlasmaComponents.ScrollBar.horizontal.policy = Qt.ScrollBarAlwaysOn; 0171 root.height = getHeight(true); 0172 } else { 0173 root.PlasmaComponents.ScrollBar.horizontal.policy = Qt.ScrollBarAlwaysOff; 0174 root.height = getHeight(); 0175 } 0176 } else { 0177 root.height = getHeight(); 0178 if(contentHeight + editor.topPadding + editor.bottomPadding > root.height) { 0179 root.visible = targetItem !== null; 0180 root.PlasmaComponents.ScrollBar.vertical.policy = Qt.ScrollBarAlwaysOn; 0181 root.width = getWidth(true); 0182 } else { 0183 root.PlasmaComponents.ScrollBar.vertical.policy = Qt.ScrollBarAlwaysOff; 0184 root.width = getWidth(); 0185 } 0186 } 0187 0188 var xy = getXY(); 0189 root.x = xy[0]; 0190 root.y = xy[1]; 0191 } 0192 } 0193 } 0194