kcm: Introduce "enabled layouts" page with option to sort

Currently the layout selection only allows for toggling on and off
keyboard layouts.

This MR moves this page into being an "add keyboard layout page", and
introduces a new page that is just the list of enabled keyboard layouts,
with buttons to sort and delete.
This commit is contained in:
Devin Lin committed 2026-10-28 17:21:46 -04:00
1 parent db28aa2ab1
commit 22a7261147
13 files changed
+283 -26

No files matched your search

+2
View File
@@ -10,6 +10,8 @@ kconfig_add_kcfg_files(kcm_plasmakeyboard GENERATE_MOC plasmakeyboardsettings.kc
target_sources(kcm_plasmakeyboard PRIVATE
../virtualkeyboard/keyboardlayoutmetadata.cpp
../virtualkeyboard/keyboardlayoutmetadata.h
enabledkeyboardlayoutmodel.cpp
enabledkeyboardlayoutmodel.h
keyboardlayoutgroupmodel.cpp
keyboardlayoutgroupmodel.h
keyboardlayoutmodel.cpp
+89
View File
@@ -0,0 +1,89 @@
/*
SPDX-FileCopyrightText: 2026 Devin Lin <devin@kde.org>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include "enabledkeyboardlayoutmodel.h"
#include "keyboardlayoutmetadata.h"
EnabledKeyboardLayoutModel::EnabledKeyboardLayoutModel(QObject *parent)
: QAbstractListModel(parent)
{
for (const auto &entry : KeyboardLayoutMetadata::keyboardLayouts()) {
m_installedLayouts.insert(entry.layoutId,
{
.layoutId = entry.layoutId,
.name = KeyboardLayoutModel::displayName(entry),
.description = KeyboardLayoutModel::descriptionForLocales(entry.locales),
.locales = entry.locales,
});
}
}
int EnabledKeyboardLayoutModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid()) {
return 0;
}
return m_layoutIds.size();
}
QVariant EnabledKeyboardLayoutModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() < 0 || index.row() >= m_layoutIds.size()) {
return {};
}
QString layoutId = m_layoutIds.at(index.row());
const auto it = m_installedLayouts.constFind(layoutId);
const bool installed = it != m_installedLayouts.constEnd();
switch (role) {
case LayoutIdRole:
return layoutId;
case NameRole:
return installed ? it->name : layoutId;
default:
return {};
}
}
QHash<int, QByteArray> EnabledKeyboardLayoutModel::roleNames() const
{
return {
{LayoutIdRole, "layoutId"},
{NameRole, "name"},
};
}
QStringList EnabledKeyboardLayoutModel::layoutIds() const
{
return m_layoutIds;
}
void EnabledKeyboardLayoutModel::setLayoutIds(const QStringList &layoutIds)
{
if (m_layoutIds == layoutIds) {
return;
}
beginResetModel();
m_layoutIds = layoutIds;
endResetModel();
}
bool EnabledKeyboardLayoutModel::move(int fromRow, int destRow)
{
if (fromRow == destRow || fromRow < 0 || destRow < 0 || fromRow >= m_layoutIds.size() || destRow >= m_layoutIds.size()) {
return false;
}
if (!beginMoveRows({}, fromRow, fromRow, {}, destRow > fromRow ? destRow + 1 : destRow)) {
return false;
}
m_layoutIds.move(fromRow, destRow);
endMoveRows();
return true;
}
+42
View File
@@ -0,0 +1,42 @@
/*
SPDX-FileCopyrightText: 2026 Devin Lin <devin@kde.org>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#pragma once
#include "keyboardlayoutmodel.h"
#include <QAbstractListModel>
#include <QHash>
#include <QStringList>
/**
* Model to list the enabled keyboard layouts that are shown to the user.
*/
class EnabledKeyboardLayoutModel : public QAbstractListModel
{
Q_OBJECT
public:
enum Role {
LayoutIdRole = Qt::UserRole + 1,
NameRole,
};
Q_ENUM(Role)
explicit EnabledKeyboardLayoutModel(QObject *parent = nullptr);
int rowCount(const QModelIndex &parent = {}) const override;
QVariant data(const QModelIndex &index, int role) const override;
QHash<int, QByteArray> roleNames() const override;
QStringList layoutIds() const;
void setLayoutIds(const QStringList &layoutIds);
bool move(int fromRow, int destRow);
private:
QHash<QString, KeyboardLayoutModel::Layout> m_installedLayouts;
QStringList m_layoutIds;
};
+1 -2
View File
@@ -143,8 +143,7 @@ void KeyboardLayoutGroupModel::loadInstalledGroups()
}
const QString layoutName = KeyboardLayoutMetadata::keyboardLayoutName(entry.layoutDefinition);
const QString keyboardName = KeyboardLayoutMetadata::keyboardDisplayName(entry);
const QString displayName = layoutName.isEmpty() ? keyboardName : keyboardName + QStringLiteral(" - ") + layoutName;
const QString displayName = KeyboardLayoutModel::displayName(entry);
flatLayouts.append({
.layoutId = entry.layoutId,
+7
View File
@@ -140,6 +140,13 @@ bool KeyboardLayoutModel::matchesFilter(const Layout &layout, const QString &fil
return filterText.isEmpty() || layout.name.toLower().contains(filterText) || layout.description.toLower().contains(filterText);
}
QString KeyboardLayoutModel::displayName(const KeyboardLayoutMetadata::Layout &entry)
{
const QString layoutName = KeyboardLayoutMetadata::keyboardLayoutName(entry.layoutDefinition);
const QString keyboardName = KeyboardLayoutMetadata::keyboardDisplayName(entry);
return layoutName.isEmpty() ? keyboardName : keyboardName + QStringLiteral(" - ") + layoutName;
}
QString KeyboardLayoutModel::descriptionForLocales(const QStringList &locales)
{
QStringList names;
+3
View File
@@ -6,6 +6,8 @@
#pragma once
#include "keyboardlayoutmetadata.h"
#include <QAbstractListModel>
#include <QStringList>
@@ -45,6 +47,7 @@ public:
int enabledVisibleLayoutCount() const;
QString layoutForLocale(const QString &locale) const;
void setLayouts(QList<Layout> layouts);
static QString displayName(const KeyboardLayoutMetadata::Layout &entry);
static QString descriptionForLocales(const QStringList &locales);
static bool matchesFilter(const Layout &layout, const QString &filterText);
+17
View File
@@ -18,6 +18,7 @@ K_PLUGIN_CLASS_WITH_JSON(PlasmaKeyboardKcm, "kcm_plasmakeyboard.json")
PlasmaKeyboardKcm::PlasmaKeyboardKcm(QObject *parent, const KPluginMetaData &metaData)
: KQuickManagedConfigModule(parent, metaData)
, m_settings(new PlasmaKeyboardSettings(this))
, m_enabledKeyboardLayouts(new EnabledKeyboardLayoutModel(this))
, m_availableKeyboardLayoutGroups(new KeyboardLayoutGroupModel(this))
{
qmlRegisterAnonymousType<PlasmaKeyboardSettings>("org.kde.plasma.keyboard.settings", 0);
@@ -45,9 +46,11 @@ PlasmaKeyboardKcm::PlasmaKeyboardKcm(QObject *parent, const KPluginMetaData &met
m_settings->setEnabledLocales({});
}
}
m_enabledKeyboardLayouts->setLayoutIds(enabledKeyboardLayoutIds);
m_availableKeyboardLayoutGroups->setEnabledLayoutIds(enabledKeyboardLayoutIds);
connect(m_settings, &PlasmaKeyboardSettings::enabledKeyboardLayoutIdsChanged, this, [this]() {
m_enabledKeyboardLayouts->setLayoutIds(m_settings->enabledKeyboardLayoutIds());
m_availableKeyboardLayoutGroups->setEnabledLayoutIds(m_settings->enabledKeyboardLayoutIds());
});
}
@@ -57,6 +60,11 @@ PlasmaKeyboardSettings *PlasmaKeyboardKcm::plasmaKeyboardSettings() const
return m_settings;
}
QAbstractItemModel *PlasmaKeyboardKcm::enabledKeyboardLayouts() const
{
return m_enabledKeyboardLayouts;
}
QAbstractItemModel *PlasmaKeyboardKcm::availableKeyboardLayouts() const
{
return m_availableKeyboardLayoutGroups->layouts();
@@ -109,6 +117,15 @@ void PlasmaKeyboardKcm::disableKeyboardLayout(const QString &layoutId)
m_settings->setEnabledKeyboardLayoutIds(enabledKeyboardLayoutIds);
}
void PlasmaKeyboardKcm::moveKeyboardLayout(int from, int to)
{
if (!m_enabledKeyboardLayouts->move(from, to)) {
return;
}
m_settings->setEnabledKeyboardLayoutIds(m_enabledKeyboardLayouts->layoutIds());
}
void PlasmaKeyboardKcm::refreshAvailableKeyboardLayoutFilter()
{
m_availableKeyboardLayoutGroups->setFormFactorFilter(keyboardLayoutFormFactorFilterEnabled() ? m_keyboardLayoutFormFactorFilter : QStringList{});
+5
View File
@@ -9,6 +9,7 @@
#include <KQuickManagedConfigModule>
#include "enabledkeyboardlayoutmodel.h"
#include "keyboardlayoutgroupmodel.h"
#include "plasmakeyboardsettings.h"
@@ -18,6 +19,7 @@ class PlasmaKeyboardKcm : public KQuickManagedConfigModule
{
Q_OBJECT
Q_PROPERTY(PlasmaKeyboardSettings *plasmaKeyboardSettings READ plasmaKeyboardSettings CONSTANT)
Q_PROPERTY(QAbstractItemModel *enabledKeyboardLayouts READ enabledKeyboardLayouts CONSTANT)
Q_PROPERTY(QAbstractItemModel *availableKeyboardLayouts READ availableKeyboardLayouts CONSTANT)
Q_PROPERTY(QAbstractItemModel *availableKeyboardLayoutGroups READ availableKeyboardLayoutGroups CONSTANT)
Q_PROPERTY(bool hasHiddenKeyboardLayouts READ hasHiddenKeyboardLayouts CONSTANT)
@@ -28,6 +30,7 @@ public:
PlasmaKeyboardKcm(QObject *parent, const KPluginMetaData &metaData);
PlasmaKeyboardSettings *plasmaKeyboardSettings() const;
QAbstractItemModel *enabledKeyboardLayouts() const;
QAbstractItemModel *availableKeyboardLayouts() const;
QAbstractItemModel *availableKeyboardLayoutGroups() const;
bool hasHiddenKeyboardLayouts() const;
@@ -37,6 +40,7 @@ public:
Q_INVOKABLE void enableKeyboardLayout(const QString &layoutId);
Q_INVOKABLE void disableKeyboardLayout(const QString &layoutId);
Q_INVOKABLE void moveKeyboardLayout(int from, int to);
Q_SIGNALS:
void keyboardLayoutFormFactorFilterEnabledChanged();
@@ -45,6 +49,7 @@ private:
void refreshAvailableKeyboardLayoutFilter();
PlasmaKeyboardSettings *m_settings = nullptr;
EnabledKeyboardLayoutModel *m_enabledKeyboardLayouts = nullptr;
KeyboardLayoutGroupModel *m_availableKeyboardLayoutGroups = nullptr;
QStringList m_keyboardLayoutFormFactorFilter;
bool m_hasHiddenKeyboardLayouts = false;
+13
View File
@@ -0,0 +1,13 @@
/*
SPDX-FileCopyrightText: 2026 Devin Lin <devin@kde.org>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
import org.kde.kirigami as Kirigami
Kirigami.ScrollablePage {
title: i18n("Add Layout")
KeyboardLayoutSelectorListView {}
}
@@ -59,14 +59,6 @@ ListView {
checked = Qt.binding(() => !kcm.keyboardLayoutFormFactorFilterEnabled);
}
}
Kirigami.InlineMessage {
Layout.topMargin: Kirigami.Units.smallSpacing
Layout.fillWidth: true
text: i18n("No keyboard layouts selected. The default keyboard layout for the system will be used.")
type: Kirigami.MessageType.Information
visible: kcm.plasmaKeyboardSettings.enabledKeyboardLayoutIds.length === 0
}
}
}
+102
View File
@@ -0,0 +1,102 @@
/*
SPDX-FileCopyrightText: 2026 Devin Lin <devin@kde.org>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
Kirigami.ScrollablePage {
id: root
title: i18n("On-Screen Keyboard Layouts")
actions: [
Kirigami.Action {
id: addLayoutAction
text: i18n("Add Layout…")
icon.name: "list-add-symbolic"
onTriggered: kcm.push("AddKeyboardLayoutPage.qml")
}
]
ListView {
id: layoutList
model: kcm.enabledKeyboardLayouts
Kirigami.PlaceholderMessage {
anchors.centerIn: parent
width: parent.width - Kirigami.Units.gridUnit * 4
visible: layoutList.count === 0
icon.name: "input-keyboard-virtual"
text: i18n("No keyboard layouts selected")
explanation: i18n("The default keyboard layout for the system will be used.")
helpfulAction: addLayoutAction
}
delegate: QQC2.ItemDelegate {
id: layoutDelegate
required property int index
required property string layoutId
required property string name
width: layoutList.width
down: false
highlighted: false
hoverEnabled: false
contentItem: RowLayout {
spacing: Kirigami.Units.smallSpacing
Kirigami.TitleSubtitle {
Layout.fillWidth: true
title: layoutDelegate.name
}
QQC2.ToolButton {
icon.name: "arrow-up-symbolic"
text: i18nc("Move the layout up a row", "Move Up")
display: QQC2.AbstractButton.IconOnly
visible: layoutList.count > 1
enabled: layoutDelegate.index > 0
onClicked: kcm.moveKeyboardLayout(layoutDelegate.index, layoutDelegate.index - 1)
QQC2.ToolTip.text: text
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
QQC2.ToolButton {
icon.name: "arrow-down-symbolic"
text: i18nc("Move the layout down a row", "Move Down")
display: QQC2.AbstractButton.IconOnly
visible: layoutList.count > 1
enabled: layoutDelegate.index < layoutList.count - 1
onClicked: kcm.moveKeyboardLayout(layoutDelegate.index, layoutDelegate.index + 1)
QQC2.ToolTip.text: text
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
QQC2.ToolButton {
icon.name: "list-remove-symbolic"
text: i18nc("Remove the layout", "Remove")
display: QQC2.AbstractButton.IconOnly
onClicked: kcm.disableKeyboardLayout(layoutDelegate.layoutId)
QQC2.ToolTip.text: text
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
}
}
}
}
+1 -8
View File
@@ -24,14 +24,7 @@ KCM.SimpleKCM {
Kirigami.FormData.label: i18n("Keyboard layouts:")
text: i18n("Configure…")
icon.name: "languages"
onClicked: kcm.push(layoutPage);
Kirigami.ScrollablePage {
id: layoutPage
title: i18n("Keyboard Layouts")
KeyboardLayoutSelectorListView {}
}
onClicked: kcm.push("KeyboardLayoutsPage.qml")
}
QQC2.CheckBox {
+1 -8
View File
@@ -74,14 +74,7 @@ KCM.SimpleKCM {
id: layoutList
text: i18n("Keyboard Layouts")
icon.name: 'languages'
onClicked: kcm.push(layoutPage)
Kirigami.ScrollablePage {
id: layoutPage
title: i18n("Keyboard Layouts")
KeyboardLayoutSelectorListView {}
}
onClicked: kcm.push("KeyboardLayoutsPage.qml")
}
}