/*SPDX-FileCopyrightText: 2020 Andrey Butirsky <butirsky@gmail.com>SPDX-License-Identifier: GPL-2.0-or-later*/pragma ComponentBehavior: Boundimport QtQuickimport org.kde.plasma.plasmoidimport org.kde.plasma.core as PlasmaCoreimport org.kde.plasma.components as PlasmaComponents3import org.kde.plasma.workspace.componentsimport org.kde.plasma.private.kcm_keyboard as KCMKeyboardimport org.kde.kirigami as KirigamiPlasmoidItem {id: rootsignal layoutSelected(int layoutIndex)preferredRepresentation: fullRepresentationtoolTipMainText: Plasmoid.titletoolTipSubText: "" // proper subtext is set by fullRepresentationreadonly property bool inEmbeddedContainment: Plasmoid.containment.containmentType === PlasmaCore.Containment.CustomEmbeddedfullRepresentation: KeyboardLayoutSwitcher {id: switcherhoverEnabled: truePlasmoid.status: hasMultipleKeyboardLayouts ? PlasmaCore.Types.ActiveStatus : root.inEmbeddedContainment ? PlasmaCore.Types.HiddenStatus : PlasmaCore.Types.PassiveStatusBinding {root.toolTipSubText: switcher.layoutNames.longName}PlasmaCore.ToolTipArea {anchors.fill: parentmainText: root.toolTipMainTextsubText: root.toolTipSubText}Instantiator {id: actionsInstantiatormodel: switcher.keyboardLayout.layoutsListdelegate: PlasmaCore.Action {required property string longNamerequired property string shortNamerequired property int indextext: longNameicon.icon: KCMKeyboard.Flags.getIcon(shortName)onTriggered: {root.layoutSelected(index);}}onObjectAdded: (index, object) => {Plasmoid.contextualActions.push(object)}onObjectRemoved: (index, object) => {Plasmoid.contextualActions.splice(Plasmoid.contextualActions.indexOf(object), 1)}}Connections {target: rootfunction onLayoutSelected(layoutIndex) {switcher.keyboardLayout.layout = layoutIndex;}}Connections {target: Plasmoidfunction onActivated() {switcher.keyboardLayout.switchToNextLayout()}}Kirigami.Icon {id: flaganchors.fill: parentvisible: valid && (Plasmoid.configuration.displayStyle === 1 || Plasmoid.configuration.displayStyle === 2)active: switcher.containsMousesource: KCMKeyboard.Flags.getIcon(switcher.layoutNames.shortName)BadgeOverlay {anchors.bottom: parent.bottomanchors.right: parent.right// The parent component has it set really tight to save space;// we need to undo that here for legibilityhorizontalPadding: Kirigami.Units.smallSpacingvisible: !countryCode.visible && Plasmoid.configuration.displayStyle === 2text: countryCode.texticon: flag}}PlasmaComponents3.Label {id: countryCodeanchors.centerIn: parentwidth: Math.min(switcher.width, switcher.height)height: widthvisible: Plasmoid.configuration.displayStyle === 0 || !flag.validfont.pointSize: height || Kirigami.Theme.defaultFont.pointSizefontSizeMode: Text.FithorizontalAlignment: Text.AlignHCenterverticalAlignment: Text.AlignVCentertext: switcher.layoutNames.displayName || switcher.layoutNames.shortNametextFormat: Text.PlainText}}function actionTriggered(actionName) {const layoutIndex = parseInt(actionName);if (!isNaN(layoutIndex)) {layoutSelected(layoutIndex);}}}