Warning, /plasma/plasma-workspace/applets/lock_logout/contents/ui/main.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2011 Viranch Mehta <viranch.mehta@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 import QtQuick
0008 import QtQuick.Layouts
0009 import org.kde.plasma.plasmoid
0010 import org.kde.plasma.core as PlasmaCore
0011 import "data.js" as Data
0012 import org.kde.plasma.private.sessions
0013 import org.kde.kirigami as Kirigami
0014 
0015 PlasmoidItem {
0016     id: root
0017 
0018     readonly property int minButtonSize: Kirigami.Units.iconSizes.small
0019 
0020     preferredRepresentation: fullRepresentation
0021     fullRepresentation: Flow {
0022         id: lockout
0023 
0024         Layout.minimumWidth: {
0025             if (Plasmoid.formFactor === PlasmaCore.Types.Vertical) {
0026                 return 0
0027             } else if (Plasmoid.formFactor === PlasmaCore.Types.Horizontal) {
0028                 return height < minButtonSize * visibleButtons ? height * visibleButtons : height / visibleButtons;
0029             } else {
0030                 return width > height ? minButtonSize * visibleButtons : minButtonSize
0031             }
0032         }
0033         Layout.minimumHeight: {
0034             if (Plasmoid.formFactor === PlasmaCore.Types.Vertical) {
0035                 return width >= minButtonSize * visibleButtons ? width / visibleButtons : width * visibleButtons
0036             } else if (Plasmoid.formFactor === PlasmaCore.Types.Horizontal) {
0037                 return 0
0038             } else {
0039                 return width > height ? minButtonSize : minButtonSize * visibleButtons
0040             }
0041         }
0042 
0043         Layout.preferredWidth: Layout.minimumWidth
0044         Layout.preferredHeight: Layout.minimumHeight
0045 
0046         readonly property int visibleButtons: {
0047             var count = 0
0048             for (var i = 0, j = items.count; i < j; ++i) {
0049                 if (items.itemAt(i).visible) {
0050                     ++count
0051                 }
0052             }
0053             return count
0054         }
0055 
0056         flow: {
0057             if ((Plasmoid.formFactor === PlasmaCore.Types.Vertical && width >= minButtonSize * visibleButtons) ||
0058                 (Plasmoid.formFactor === PlasmaCore.Types.Horizontal && height < minButtonSize * visibleButtons) ||
0059                 (width > height)) {
0060                 return Flow.LeftToRight // horizontal
0061             } else {
0062                 return Flow.TopToBottom // vertical
0063             }
0064         }
0065 
0066         SessionManagement {
0067             id: session
0068         }
0069 
0070         Repeater {
0071             id: items
0072             property int itemWidth: parent.flow==Flow.LeftToRight ? Math.floor(parent.width/visibleButtons) : parent.width
0073             property int itemHeight: parent.flow==Flow.TopToBottom ? Math.floor(parent.height/visibleButtons) : parent.height
0074             property int iconSize: Math.min(itemWidth, itemHeight)
0075 
0076             model: Data.data
0077 
0078             delegate: PlasmaCore.ToolTipArea {
0079                 id: iconDelegate
0080                 visible: Plasmoid.configuration["show_" + modelData.configKey] && (!modelData.hasOwnProperty("requires") || session["can" + modelData.requires])
0081                 width: items.itemWidth
0082                 height: items.itemHeight
0083 
0084                 activeFocusOnTab: true
0085                 mainText: modelData.tooltip_mainText
0086                 subText: modelData.tooltip_subText
0087                 textFormat: Text.PlainText
0088 
0089                 Accessible.name: iconDelegate.mainText
0090                 Accessible.description: iconDelegate.subText
0091                 Accessible.role: Accessible.Button
0092                 Keys.onPressed: event => {
0093                     switch (event.key) {
0094                     case Qt.Key_Space:
0095                     case Qt.Key_Enter:
0096                     case Qt.Key_Return:
0097                     case Qt.Key_Select:
0098                         performOperation(modelData.operation)
0099                         break;
0100                     }
0101                 }
0102 
0103                 TapHandler {
0104                     id: tapHandler
0105                     onTapped: performOperation(modelData.operation)
0106                 }
0107 
0108                 Kirigami.Icon {
0109                     id: iconButton
0110                     width: items.iconSize
0111                     height: items.iconSize
0112                     anchors.centerIn: parent
0113                     source: modelData.icon
0114                     scale: tapHandler.pressed ? 0.9 : 1
0115                     active: iconDelegate.containsMouse
0116                 }
0117             }
0118         }
0119 
0120         function performOperation(operation) {
0121             session[operation]()
0122         }
0123     }
0124 }