Warning, /plasma/kscreen/osd/qml/OsdSelector.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2017 Daniel Vrátil <dvratil@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 import QtQuick 2.15
0008 import QtQuick.Controls 2.15
0009 import QtQuick.Layouts 1.10
0010 
0011 import org.kde.plasma.core 2.0 as PlasmaCore
0012 import org.kde.plasma.extras 2.0 as PlasmaExtras
0013 import org.kde.plasma.components 3.0 as PlasmaComponents
0014 
0015 import org.kde.KScreen 1.0
0016 
0017 
0018 Control {
0019     id: root
0020     property string infoText
0021     property var actions
0022     signal clicked(int actionId)
0023 
0024     leftPadding: shadow.margins.left + background.margins.left
0025     rightPadding: shadow.margins.right + background.margins.right
0026     topPadding: shadow.margins.top + background.margins.top
0027     bottomPadding: shadow.margins.bottom + background.margins.bottom
0028 
0029     contentItem : ColumnLayout {
0030         RowLayout {
0031             Repeater {
0032                 id: actionRepeater
0033                 property int currentIndex: 0
0034                 model: root.actions
0035                 delegate: PlasmaComponents.Button {
0036                     property int actionId: modelData.action
0037 
0038                     Accessible.name: modelData.label
0039 
0040                     icon.name: modelData.iconName
0041                     icon.height: PlasmaCore.Units.gridUnit * 8
0042                     icon.width: PlasmaCore.Units.gridUnit * 8
0043 
0044                     onClicked: root.clicked(actionId)
0045                     onHoveredChanged: {
0046                         actionRepeater.currentIndex = index
0047                     }
0048 
0049                     activeFocusOnTab: true
0050 
0051                     // use checked only indirectly, since its binding will break
0052                     property bool current: index == actionRepeater.currentIndex
0053                     onCurrentChanged: {
0054                         if (current) {
0055                             checked = true
0056                             root.infoText = modelData.label
0057                             forceActiveFocus()
0058                         } else {
0059                             checked = false
0060                         }
0061                     }
0062                     onActiveFocusChanged: {
0063                         if (activeFocus) {
0064                             actionRepeater.currentIndex = index
0065                         }
0066                     }
0067                 }
0068             }
0069         }
0070 
0071         PlasmaExtras.Heading {
0072             text: root.infoText
0073             horizontalAlignment: Text.AlignHCenter
0074             maximumLineCount: 2
0075             wrapMode: Text.WordWrap
0076 
0077             Layout.fillWidth: true
0078             Layout.margins: Math.floor(PlasmaCore.Units.smallSpacing / 2)
0079         }
0080 
0081         // Shift current by delta, but do not wrap around when repeat is true.
0082         function wrappingAdd(count: int, current: int, delta: int, repeat: bool): int {
0083             const next = current + delta;
0084             // Rule out invalid states.
0085             if (count === 0 || current < 0 || current >= count) {
0086                 return current;
0087             }
0088             // Don't wrap on autorepeat.
0089             if (repeat && (next < 0 || next >= count)) {
0090                 return current;
0091             }
0092             // Add an extra `count`, so that wrapping % works predictably with positive values only.
0093             // This assumes that delta is not smaller than `-count` (usually just -1, 0 or +1).
0094             return (next + count) % count;
0095         }
0096 
0097         function move(event) {
0098             actionRepeater.currentIndex = wrappingAdd(actionRepeater.count, actionRepeater.currentIndex,
0099                 (event.key === Qt.Key_Left) ? -1 : 1, event.isAutoRepeat);
0100         }
0101 
0102         Keys.onPressed: {
0103             switch (event.key) {
0104                 case Qt.Key_Return:
0105                 case Qt.Key_Enter:
0106                     clicked(actionRepeater.itemAt(actionRepeater.currentIndex).actionId)
0107                     break
0108                 case Qt.Key_Right:
0109                 case Qt.Key_Left:
0110                     move(event)
0111                     break
0112                 case Qt.Key_Escape:
0113                     clicked(OsdAction.NoAction)
0114                     break
0115             }
0116         }
0117     }
0118 
0119       background: PlasmaCore.FrameSvgItem {
0120         id: shadow
0121         imagePath: "dialogs/background"
0122         prefix: "shadow"
0123 
0124         PlasmaCore.FrameSvgItem {
0125             id: background
0126             anchors.leftMargin: shadow.margins.left
0127             anchors.rightMargin: shadow.margins.right
0128             anchors.topMargin: shadow.margins.top
0129             anchors.bottomMargin: shadow.margins.bottom
0130             anchors.fill: parent
0131             imagePath: "solid/dialogs/background"
0132         }
0133     }
0134 }