mirror of
https://github.com/vinceliuice/MacSequoia-kde.git
synced 2024-11-22 13:50:13 +00:00
62 lines
1.8 KiB
QML
62 lines
1.8 KiB
QML
|
/*
|
||
|
SPDX-FileCopyrightText: 2016 David Edmundson <davidedmundson@kde.org>
|
||
|
SPDX-FileCopyrightText: 2022 Aleix Pol Gonzalez <aleixpol@kde.org>
|
||
|
|
||
|
SPDX-License-Identifier: LGPL-2.0-or-later
|
||
|
*/
|
||
|
|
||
|
import QtQuick 2.15
|
||
|
|
||
|
import org.kde.plasma.components 3.0 as PlasmaComponents
|
||
|
import org.kde.kirigami 2.20 as Kirigami
|
||
|
|
||
|
PlasmaComponents.ToolButton {
|
||
|
id: root
|
||
|
|
||
|
property int currentIndex: keyboard.currentLayout
|
||
|
onCurrentIndexChanged: keyboard.currentLayout = currentIndex
|
||
|
|
||
|
text: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Keyboard Layout: %1", keyboard.layouts[currentIndex].longName)
|
||
|
visible: keyboard.layouts.length > 1
|
||
|
|
||
|
checkable: true
|
||
|
checked: menu.opened
|
||
|
onToggled: {
|
||
|
if (checked) {
|
||
|
menu.popup(root, 0, 0)
|
||
|
} else {
|
||
|
menu.dismiss()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
signal keyboardLayoutChanged()
|
||
|
|
||
|
PlasmaComponents.Menu {
|
||
|
id: menu
|
||
|
Kirigami.Theme.colorSet: Kirigami.Theme.Window
|
||
|
Kirigami.Theme.inherit: false
|
||
|
|
||
|
onAboutToShow: {
|
||
|
if (instantiator.model === null) {
|
||
|
let layouts = keyboard.layouts;
|
||
|
layouts.sort((a, b) => a.longName.localeCompare(b.longName));
|
||
|
instantiator.model = layouts;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Instantiator {
|
||
|
id: instantiator
|
||
|
model: null
|
||
|
onObjectAdded: (index, object) => menu.insertItem(index, object)
|
||
|
onObjectRemoved: (index, object) => menu.removeItem(object)
|
||
|
delegate: PlasmaComponents.MenuItem {
|
||
|
text: modelData.longName
|
||
|
onTriggered: {
|
||
|
keyboard.currentLayout = keyboard.layouts.indexOf(modelData)
|
||
|
root.keyboardLayoutChanged()
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|