Warning, /plasma/plasma-workspace/applets/panelspacer/package/contents/ui/main.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2014 Marco Martin <mart@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 import QtQuick 0008 import QtQuick.Layouts 0009 import org.kde.plasma.core as PlasmaCore 0010 import org.kde.plasma.plasmoid 2.0 0011 import org.kde.kirigami 2.20 as Kirigami 0012 0013 PlasmoidItem { 0014 id: root 0015 0016 property bool horizontal: Plasmoid.formFactor !== PlasmaCore.Types.Vertical 0017 0018 Layout.fillWidth: Plasmoid.configuration.expanding 0019 Layout.fillHeight: Plasmoid.configuration.expanding 0020 0021 Layout.minimumWidth: Plasmoid.containment.corona?.editMode ? Kirigami.Units.gridUnit * 2 : 1 0022 Layout.minimumHeight: Plasmoid.containment.corona?.editMode ? Kirigami.Units.gridUnit * 2 : 1 0023 Layout.preferredWidth: horizontal 0024 ? (Plasmoid.configuration.expanding ? optimalSize : Plasmoid.configuration.length) 0025 : 0 0026 Layout.preferredHeight: horizontal 0027 ? 0 0028 : (Plasmoid.configuration.expanding ? optimalSize : Plasmoid.configuration.length) 0029 0030 preferredRepresentation: fullRepresentation 0031 0032 // Search the actual gridLayout of the panel 0033 property GridLayout panelLayout: { 0034 let candidate = root.parent; 0035 while (candidate) { 0036 if (candidate instanceof GridLayout) { 0037 return candidate; 0038 } 0039 candidate = candidate.parent; 0040 } 0041 return null; 0042 } 0043 0044 Plasmoid.contextualActions: [ 0045 PlasmaCore.Action { 0046 text: i18n("Set flexible size") 0047 checkable: true 0048 checked: Plasmoid.configuration.expanding 0049 onTriggered: checked => { 0050 Plasmoid.configuration.expanding = checked; 0051 } 0052 } 0053 ] 0054 0055 Component.onCompleted: { 0056 Plasmoid.removeInternalAction("configure"); 0057 } 0058 0059 property real optimalSize: { 0060 if (!panelLayout || !Plasmoid.configuration.expanding) return Plasmoid.configuration.length; 0061 let expandingSpacers = 0; 0062 let thisSpacerIndex = null; 0063 let sizeHints = [0]; 0064 // Children order is guaranteed to be the same as the visual order of items in the layout 0065 for (var i in panelLayout.children) { 0066 const child = panelLayout.children[i]; 0067 if (!child.visible) continue; 0068 0069 if (child.applet && child.applet.plasmoid.pluginName === 'org.kde.plasma.panelspacer' && child.applet.plasmoid.configuration.expanding) { 0070 if (child.applet.plasmoid === Plasmoid) { 0071 thisSpacerIndex = expandingSpacers 0072 } 0073 sizeHints.push(0) 0074 expandingSpacers += 1 0075 } else if (root.horizontal) { 0076 sizeHints[sizeHints.length - 1] += Math.min(child.Layout.maximumWidth, Math.max(child.Layout.minimumWidth, child.Layout.preferredWidth)) + panelLayout.rowSpacing; 0077 } else { 0078 sizeHints[sizeHints.length - 1] += Math.min(child.Layout.maximumHeight, Math.max(child.Layout.minimumHeight, child.Layout.preferredHeight)) + panelLayout.columnSpacing; 0079 } 0080 } 0081 sizeHints[0] *= 2; sizeHints[sizeHints.length - 1] *= 2 0082 let containment = Plasmoid.containmentItem 0083 let opt = (root.horizontal ? containment.width : containment.height) / expandingSpacers - sizeHints[thisSpacerIndex] / 2 - sizeHints[thisSpacerIndex + 1] / 2 0084 return Math.max(opt, 0) 0085 } 0086 0087 Rectangle { 0088 anchors.fill: parent 0089 color: Kirigami.Theme.highlightColor 0090 opacity: Plasmoid.containment.corona?.editMode ? 1 : 0.2 0091 visible: Plasmoid.containment.corona?.editMode || animator.running 0092 0093 Behavior on opacity { 0094 NumberAnimation { 0095 id: animator 0096 duration: Kirigami.Units.longDuration 0097 // easing.type is updated after animation starts 0098 easing.type: Plasmoid.containment.corona?.editMode ? Easing.InCubic : Easing.OutCubic 0099 } 0100 } 0101 } 0102 }