mirror of
https://github.com/RustyRaptor/plasma-keyboard.git
synced 2026-12-03 15:55:19 -07:00
Add emoji layout
This commit is contained in:
1 parent
ad5a4db0e4
commit
49e9e72a92
23 files changed
+1004
-28
No files matched your search
@@ -167,6 +167,22 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "kemoji",
|
||||
"buildsystem": "cmake-ninja",
|
||||
"config-opts": [
|
||||
"-DCMAKE_BUILD_TYPE=Release",
|
||||
"-DBUILD_TESTING=OFF",
|
||||
"-DKEMOJI_BUILD_EMOJIER=OFF"
|
||||
],
|
||||
"sources": [
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://invent.kde.org/libraries/kemoji.git",
|
||||
"branch": "master"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "libplasma",
|
||||
"buildsystem": "cmake-ninja",
|
||||
|
||||
@@ -10,6 +10,7 @@ Dependencies:
|
||||
"frameworks/kcmutils": "@latest-kf6"
|
||||
"frameworks/kconfig": "@latest-kf6"
|
||||
"frameworks/kcrash": "@latest-kf6"
|
||||
"libraries/kemoji": "@latest"
|
||||
"plasma/libplasma": "@same"
|
||||
|
||||
Options:
|
||||
|
||||
@@ -23,6 +23,7 @@ include(KDEInstallDirs) # Should be included first so its variables are availabl
|
||||
include(ECMDeprecationSettings)
|
||||
include(ECMInstallIcons)
|
||||
include(ECMQmlModule)
|
||||
include(ECMFindQmlModule)
|
||||
include(ECMQtDeclareLoggingCategory)
|
||||
include(ECMSetupVersion)
|
||||
|
||||
@@ -66,6 +67,8 @@ find_package(KF6 ${KF6_MIN_VERSION} REQUIRED COMPONENTS
|
||||
)
|
||||
|
||||
find_package(PlasmaQuick ${PROJECT_DEP_VERSION} REQUIRED)
|
||||
find_package(KEmoji 0.1 REQUIRED)
|
||||
ecm_find_qmlmodule(org.kde.kemoji REQUIRED)
|
||||
|
||||
ecm_set_disabled_deprecation_versions(QT 6.11.0
|
||||
KF 6.29.0
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "inputengine.h"
|
||||
#include "basictextcomposer.h"
|
||||
#include "directtextcomposer.h"
|
||||
#include "emojicontroller.h"
|
||||
#include "inputbackend.h"
|
||||
|
||||
#include <QLoggingCategory>
|
||||
@@ -208,6 +209,73 @@ private Q_SLOTS:
|
||||
QCOMPARE(engine.pressedKeys(), QList<int>{Qt::Key_Control});
|
||||
}
|
||||
|
||||
// Emoji search
|
||||
|
||||
void emojiSearchCapturesQueryWithActiveComposer()
|
||||
{
|
||||
auto *backend = new TestInputBackend;
|
||||
backend->setInputMethodHintsState(Qt::ImhNone);
|
||||
InputEngine engine(backend);
|
||||
auto *originalComposer = new DirectTextComposer;
|
||||
engine.setTextComposer(originalComposer);
|
||||
EmojiController controller(&engine);
|
||||
|
||||
controller.open();
|
||||
controller.startSearch();
|
||||
QVERIFY(controller.active());
|
||||
QVERIFY(controller.searchActive());
|
||||
QVERIFY(engine.textCaptureActive());
|
||||
QCOMPARE(engine.textComposer(), originalComposer);
|
||||
|
||||
QVERIFY(engine.sendTextComposerKey(Qt::Key_S, QStringLiteral("s")));
|
||||
QVERIFY(engine.sendTextComposerKey(Qt::Key_M, QStringLiteral("m")));
|
||||
QVERIFY(engine.sendTextComposerKey(Qt::Key_I, QStringLiteral("i")));
|
||||
QVERIFY(engine.sendTextComposerKey(Qt::Key_L, QStringLiteral("l")));
|
||||
QVERIFY(engine.sendTextComposerKey(Qt::Key_E, QStringLiteral("e")));
|
||||
QCOMPARE(controller.query(), QStringLiteral("smile"));
|
||||
QVERIFY(backend->commitRequests.isEmpty());
|
||||
|
||||
QVERIFY(engine.sendTextComposerKey(Qt::Key_Backspace, QString()));
|
||||
QCOMPARE(controller.query(), QStringLiteral("smil"));
|
||||
|
||||
controller.commitEmoji(QStringLiteral("😀"));
|
||||
QCOMPARE(backend->commitRequests, QStringList{QStringLiteral("😀")});
|
||||
QCOMPARE(controller.query(), QStringLiteral("smil"));
|
||||
|
||||
controller.stopSearch();
|
||||
QVERIFY(!controller.searchActive());
|
||||
QVERIFY(!engine.textCaptureActive());
|
||||
QVERIFY(controller.query().isEmpty());
|
||||
QCOMPARE(engine.textComposer(), originalComposer);
|
||||
|
||||
QVERIFY(engine.sendTextComposerKey(Qt::Key_A, QStringLiteral("a")));
|
||||
QCOMPARE(backend->commitRequests, QStringList({QStringLiteral("😀"), QStringLiteral("a")}));
|
||||
}
|
||||
|
||||
void emojiModeClosesForSensitiveAndExclusiveInput()
|
||||
{
|
||||
auto *backend = new TestInputBackend;
|
||||
backend->setInputMethodHintsState(Qt::ImhNone);
|
||||
InputEngine engine(backend);
|
||||
auto *originalComposer = new DirectTextComposer;
|
||||
engine.setTextComposer(originalComposer);
|
||||
EmojiController controller(&engine);
|
||||
|
||||
QVERIFY(controller.available());
|
||||
controller.open();
|
||||
controller.startSearch();
|
||||
|
||||
backend->setInputMethodHintsState(Qt::ImhSensitiveData);
|
||||
QVERIFY(!controller.available());
|
||||
QVERIFY(!controller.active());
|
||||
QCOMPARE(engine.textComposer(), originalComposer);
|
||||
|
||||
backend->setInputMethodHintsState(Qt::ImhEmailCharactersOnly);
|
||||
QVERIFY(!controller.available());
|
||||
controller.open();
|
||||
QVERIFY(!controller.active());
|
||||
}
|
||||
|
||||
// Surrounding text
|
||||
|
||||
void convertsUtf8PositionsAndSelections()
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "pinyintextcomposer.h"
|
||||
#include "emojicontroller.h"
|
||||
#include "textcomposertestutils.h"
|
||||
|
||||
#include <QStandardPaths>
|
||||
@@ -73,6 +74,37 @@ private Q_SLOTS:
|
||||
QVERIFY(engine.preeditText().isEmpty());
|
||||
QVERIFY(engine.candidates().isEmpty());
|
||||
}
|
||||
|
||||
void emojiSearchUsesPinyinCandidates()
|
||||
{
|
||||
auto *backend = new TextComposerTestBackend;
|
||||
InputEngine engine(backend);
|
||||
auto *composer = new PinyinTextComposer;
|
||||
engine.setTextComposer(composer);
|
||||
EmojiController controller(&engine);
|
||||
|
||||
controller.open();
|
||||
controller.startSearch();
|
||||
QCOMPARE(engine.textComposer(), composer);
|
||||
|
||||
QVERIFY(sendText(engine, u"nihao"));
|
||||
QCOMPARE(controller.query(), QStringLiteral("nihao"));
|
||||
QVERIFY(backend->preeditRequests.isEmpty());
|
||||
int candidateIndex = engine.candidates().indexOf(QStringLiteral("你好"));
|
||||
QVERIFY(candidateIndex >= 0);
|
||||
|
||||
QVERIFY(engine.selectCandidate(candidateIndex));
|
||||
QCOMPARE(controller.query(), QStringLiteral("你好"));
|
||||
QVERIFY(engine.preeditText().isEmpty());
|
||||
QVERIFY(engine.candidates().isEmpty());
|
||||
QVERIFY(backend->commitRequests.isEmpty());
|
||||
|
||||
controller.commitEmoji(QStringLiteral("😀"));
|
||||
QCOMPARE(backend->commitRequests, QStringList{QStringLiteral("😀")});
|
||||
|
||||
controller.stopSearch();
|
||||
QCOMPARE(engine.textComposer(), composer);
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_GUILESS_MAIN(PinyinTextComposerTest)
|
||||
|
||||
@@ -22,6 +22,7 @@ Kirigami.ShadowedRectangle {
|
||||
property alias characterPopup: characterPopup
|
||||
property alias flickPreviewPopup: flickPreviewPopup
|
||||
readonly property var keyboardController: virtualKeyboardContext ? virtualKeyboardContext.keyboardController : null
|
||||
readonly property var emojiController: virtualKeyboardContext ? virtualKeyboardContext.emojiController : null
|
||||
|
||||
readonly property bool isFloating: false
|
||||
readonly property bool isFullScreenWidth: !isFloating && PlasmaKeyboardSettings.panelFillScreenWidth
|
||||
@@ -51,6 +52,7 @@ Kirigami.ShadowedRectangle {
|
||||
id: languagePopup
|
||||
keyboardPanel: inputPanel
|
||||
keyboardController: root.keyboardController
|
||||
emojiController: root.emojiController
|
||||
onShowSettings: root.showSettingsRequested()
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,9 @@ InputPanelWindow {
|
||||
|
||||
onVisibleChanged: {
|
||||
keyboardPanel.inputPanel.resetNavigation();
|
||||
if (keyboardPanel.emojiController) {
|
||||
keyboardPanel.emojiController.close();
|
||||
}
|
||||
if (visible) {
|
||||
keyboardPanel.keyboardController.symbolMode = false;
|
||||
} else {
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
add_library(plasma-keyboard-virtualkeyboard STATIC
|
||||
emojicontroller.cpp
|
||||
emojicontroller.h
|
||||
inputbackend.cpp
|
||||
inputbackend.h
|
||||
inputengine.cpp
|
||||
@@ -91,6 +93,7 @@ ecm_add_qml_module(keyboardvirtualkeyboardcomponents
|
||||
QtQuick
|
||||
QtQuick.Controls
|
||||
org.kde.kirigami
|
||||
org.kde.kemoji
|
||||
org.kde.plasma.keyboard.virtualkeyboard
|
||||
)
|
||||
|
||||
@@ -107,6 +110,8 @@ ecm_target_qml_sources(keyboardvirtualkeyboardcomponents SOURCES
|
||||
components/AlternativeKeysPopup.qml
|
||||
components/CharacterPopup.qml
|
||||
components/FlickPreviewPopup.qml
|
||||
components/EmojiPicker.qml
|
||||
components/EmojiSearchStrip.qml
|
||||
components/Keyboard.qml
|
||||
components/KeyboardNavigation.qml
|
||||
components/KeyboardStrip.qml
|
||||
|
||||
@@ -0,0 +1,244 @@
|
||||
/*
|
||||
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
|
||||
import org.kde.kemoji as KEmoji
|
||||
import org.kde.plasma.keyboard
|
||||
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
required property var emojiController
|
||||
required property var inputEngine
|
||||
|
||||
readonly property font emojiFont: Qt.font({
|
||||
family: "emoji",
|
||||
pixelSize: Math.max(1, Math.round(58 * BreezeConstants.scaleHint))
|
||||
})
|
||||
readonly property real toolbarHeight: Math.max(Math.round(88 * BreezeConstants.scaleHint), searchButton.implicitHeight, abcButton.implicitHeight, backspaceButton.implicitHeight)
|
||||
readonly property real categoryBarHeight: Math.max(Math.round(80 * BreezeConstants.scaleHint), Kirigami.Units.gridUnit * 2)
|
||||
readonly property real emojiCellSize: emojiMetrics.height + Kirigami.Units.mediumSpacing * 2
|
||||
|
||||
FontMetrics {
|
||||
id: emojiMetrics
|
||||
font: root.emojiFont
|
||||
}
|
||||
|
||||
function commitEmoji(emoji) {
|
||||
if (emoji.unicode.length === 0) {
|
||||
return;
|
||||
}
|
||||
Feedback.play(Feedback.SelectionCommit);
|
||||
emojiController.commitEmoji(emoji.unicode);
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
emojiGrid.model.currentCategory = KEmoji.Categories.Recent;
|
||||
if (emojiGrid.model.rowCount() === 0) {
|
||||
emojiGrid.model.currentCategory = KEmoji.Categories.All;
|
||||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
id: pickerLayout
|
||||
|
||||
anchors.fill: parent
|
||||
spacing: 0
|
||||
|
||||
RowLayout {
|
||||
id: pickerToolbar
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.minimumHeight: root.toolbarHeight
|
||||
Layout.preferredHeight: root.toolbarHeight
|
||||
Layout.maximumHeight: root.toolbarHeight
|
||||
spacing: Math.round(8 * BreezeConstants.scaleHint)
|
||||
|
||||
QQC2.ToolButton {
|
||||
id: abcButton
|
||||
|
||||
Layout.fillHeight: true
|
||||
text: i18nc("@action:button", "Back")
|
||||
icon.name: root.LayoutMirroring.enabled ? "go-next-symbolic" : "go-previous-symbolic"
|
||||
display: QQC2.AbstractButton.IconOnly
|
||||
onClicked: root.emojiController.close()
|
||||
}
|
||||
|
||||
QQC2.ToolButton {
|
||||
id: searchButton
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
text: i18nc("@action:button", "Search emoji")
|
||||
icon.name: "search"
|
||||
onClicked: root.emojiController.startSearch()
|
||||
|
||||
contentItem: RowLayout {
|
||||
spacing: Kirigami.Units.smallSpacing
|
||||
|
||||
Kirigami.Icon {
|
||||
source: "search"
|
||||
implicitWidth: Math.round(40 * BreezeConstants.scaleHint)
|
||||
implicitHeight: implicitWidth
|
||||
}
|
||||
QQC2.Label {
|
||||
Layout.fillWidth: true
|
||||
text: i18nc("@action:button", "Search emoji")
|
||||
color: BreezeConstants.keyTextColor
|
||||
elide: Text.ElideRight
|
||||
font.family: BreezeConstants.fontFamily
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QQC2.ToolButton {
|
||||
id: backspaceButton
|
||||
|
||||
Layout.fillHeight: true
|
||||
icon.name: "edit-clear-symbolic"
|
||||
text: i18nc("@action:button", "Backspace")
|
||||
display: QQC2.AbstractButton.IconOnly
|
||||
onClicked: root.inputEngine.sendTextComposerKey(Qt.Key_Backspace, "")
|
||||
|
||||
QQC2.ToolTip.visible: hovered
|
||||
QQC2.ToolTip.text: text
|
||||
}
|
||||
}
|
||||
|
||||
KEmoji.EmojiGrid {
|
||||
id: emojiGrid
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
Layout.minimumHeight: 0
|
||||
clip: true
|
||||
font: root.emojiFont
|
||||
showUnsupportedEmojis: false
|
||||
|
||||
delegate: KEmoji.EmojiDelegate {
|
||||
id: emojiDelegate
|
||||
|
||||
font: root.emojiFont
|
||||
highlighted: GridView.isCurrentItem || variantPopup.owner === emojiDelegate
|
||||
onClicked: root.commitEmoji(emojiDelegate.emoji)
|
||||
onPressAndHold: {
|
||||
if (emojiDelegate.variantEmojis.size > 0) {
|
||||
variantPopup.openFor(emojiDelegate, emojiDelegate.variantEmojis)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: categoryView
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.minimumHeight: root.categoryBarHeight
|
||||
Layout.preferredHeight: root.categoryBarHeight
|
||||
Layout.maximumHeight: root.categoryBarHeight
|
||||
orientation: ListView.Horizontal
|
||||
boundsBehavior: Flickable.StopAtBounds
|
||||
clip: true
|
||||
spacing: Kirigami.Units.smallSpacing
|
||||
model: [
|
||||
KEmoji.Categories.Recent,
|
||||
KEmoji.Categories.Smileys,
|
||||
KEmoji.Categories.People,
|
||||
KEmoji.Categories.Animals,
|
||||
KEmoji.Categories.Food,
|
||||
KEmoji.Categories.Travel,
|
||||
KEmoji.Categories.Activities,
|
||||
KEmoji.Categories.Objects,
|
||||
KEmoji.Categories.Symbols,
|
||||
KEmoji.Categories.Flags
|
||||
]
|
||||
|
||||
delegate: QQC2.ToolButton {
|
||||
id: categoryButton
|
||||
|
||||
required property int modelData
|
||||
|
||||
KEmoji.Category.category: modelData
|
||||
|
||||
width: Math.max(categoryView.height, implicitWidth)
|
||||
height: categoryView.height
|
||||
icon.name: KEmoji.Category.iconName
|
||||
text: KEmoji.Category.name
|
||||
display: QQC2.AbstractButton.IconOnly
|
||||
checked: emojiGrid.model.currentCategory === modelData
|
||||
onClicked: emojiGrid.model.currentCategory = modelData
|
||||
|
||||
Accessible.name: text
|
||||
QQC2.ToolTip.visible: hovered
|
||||
QQC2.ToolTip.text: text
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QQC2.Popup {
|
||||
id: variantPopup
|
||||
|
||||
property Item owner: null
|
||||
property KEmoji.group emojis
|
||||
readonly property int columnCount: Math.min(emojis.size, 5)
|
||||
readonly property int rowCount: Math.ceil(emojis.size / 5)
|
||||
|
||||
parent: root
|
||||
padding: Kirigami.Units.smallSpacing
|
||||
modal: true
|
||||
dim: false
|
||||
focus: false
|
||||
popupType: QQC2.Popup.Item
|
||||
closePolicy: QQC2.Popup.CloseOnEscape | QQC2.Popup.CloseOnPressOutside
|
||||
width: root.emojiCellSize * columnCount + leftPadding + rightPadding
|
||||
height: root.emojiCellSize * rowCount + topPadding + bottomPadding
|
||||
|
||||
background: PopupBackground {
|
||||
theme: BreezeConstants
|
||||
}
|
||||
|
||||
function openFor(delegate, variantEmojis) {
|
||||
owner = delegate
|
||||
emojis = variantEmojis
|
||||
|
||||
const point = delegate.mapToItem(root, 0, 0)
|
||||
x = Math.max(0, Math.min(root.width - width, point.x + (delegate.width - width) / 2))
|
||||
const aboveY = point.y - height
|
||||
y = aboveY >= 0 ? aboveY : Math.min(root.height - height, point.y + delegate.height)
|
||||
open()
|
||||
}
|
||||
|
||||
onClosed: owner = null
|
||||
|
||||
contentItem: GridView {
|
||||
id: variantView
|
||||
|
||||
cellWidth: root.emojiCellSize
|
||||
cellHeight: root.emojiCellSize
|
||||
interactive: false
|
||||
model: KEmoji.Model {
|
||||
emojis: variantPopup.emojis
|
||||
}
|
||||
|
||||
delegate: KEmoji.EmojiDelegate {
|
||||
id: variantDelegate
|
||||
|
||||
font: root.emojiFont
|
||||
showVariantEmojis: false
|
||||
onClicked: {
|
||||
variantPopup.close()
|
||||
root.commitEmoji(variantDelegate.emoji)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
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
|
||||
import org.kde.kemoji as KEmoji
|
||||
import org.kde.plasma.keyboard
|
||||
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
Rectangle {
|
||||
id: root
|
||||
|
||||
required property var emojiController
|
||||
readonly property string query: emojiController ? emojiController.query : ""
|
||||
readonly property font emojiFont: Qt.font({
|
||||
family: "emoji",
|
||||
pixelSize: Math.max(1, Math.round(48 * BreezeConstants.scaleHint))
|
||||
})
|
||||
readonly property real searchFieldHeight: Math.max(Math.round(76 * BreezeConstants.scaleHint), backButton.implicitHeight)
|
||||
readonly property real resultRowHeight: Math.max(Math.round(100 * BreezeConstants.scaleHint), emojiMetrics.height + Kirigami.Units.mediumSpacing * 2)
|
||||
|
||||
implicitHeight: searchFieldHeight + resultRowHeight
|
||||
color: BreezeConstants.selectionListBackgroundColor
|
||||
|
||||
FontMetrics {
|
||||
id: emojiMetrics
|
||||
font: root.emojiFont
|
||||
}
|
||||
|
||||
function commitEmoji(emoji) {
|
||||
if (emoji.unicode.length === 0) {
|
||||
return;
|
||||
}
|
||||
Feedback.play(Feedback.SelectionCommit);
|
||||
emojiController.commitEmoji(emoji.unicode);
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
anchors.fill: parent
|
||||
spacing: 0
|
||||
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
Layout.minimumHeight: root.searchFieldHeight
|
||||
Layout.preferredHeight: root.searchFieldHeight
|
||||
Layout.maximumHeight: root.searchFieldHeight
|
||||
spacing: Math.round(8 * BreezeConstants.scaleHint)
|
||||
|
||||
QQC2.ToolButton {
|
||||
id: backButton
|
||||
|
||||
Layout.fillHeight: true
|
||||
icon.name: root.LayoutMirroring.enabled ? "go-next-symbolic" : "go-previous-symbolic"
|
||||
text: i18nc("@action:button", "Back to emoji picker")
|
||||
display: QQC2.AbstractButton.IconOnly
|
||||
onClicked: root.emojiController.stopSearch()
|
||||
|
||||
QQC2.ToolTip.visible: hovered
|
||||
QQC2.ToolTip.text: text
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
radius: BreezeConstants.buttonRadius
|
||||
color: BreezeConstants.normalKeyBackgroundColor
|
||||
|
||||
Kirigami.Icon {
|
||||
id: searchIcon
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: Kirigami.Units.smallSpacing
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: Math.round(36 * BreezeConstants.scaleHint)
|
||||
height: width
|
||||
source: "search"
|
||||
}
|
||||
|
||||
QQC2.Label {
|
||||
anchors.left: searchIcon.right
|
||||
anchors.right: parent.right
|
||||
anchors.leftMargin: Kirigami.Units.smallSpacing
|
||||
anchors.rightMargin: Kirigami.Units.smallSpacing
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: root.query.length > 0 ? root.query : i18nc("@info:placeholder", "Search emoji")
|
||||
color: BreezeConstants.keyTextColor
|
||||
opacity: root.query.length > 0 ? 1 : 0.65
|
||||
elide: Text.ElideLeft
|
||||
}
|
||||
}
|
||||
|
||||
QQC2.ToolButton {
|
||||
Layout.fillHeight: true
|
||||
visible: root.query.length > 0
|
||||
icon.name: "edit-clear-symbolic"
|
||||
text: i18nc("@action:button", "Clear emoji search")
|
||||
display: QQC2.AbstractButton.IconOnly
|
||||
onClicked: root.emojiController.clearQuery()
|
||||
|
||||
QQC2.ToolTip.visible: hovered
|
||||
QQC2.ToolTip.text: text
|
||||
}
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: resultView
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.minimumHeight: root.resultRowHeight
|
||||
Layout.preferredHeight: root.resultRowHeight
|
||||
Layout.maximumHeight: root.resultRowHeight
|
||||
orientation: ListView.Horizontal
|
||||
boundsBehavior: Flickable.StopAtBounds
|
||||
clip: true
|
||||
spacing: 0
|
||||
model: KEmoji.SortFilterModel {
|
||||
searchText: root.query
|
||||
currentCategory: root.query.length > 0 ? KEmoji.Categories.All : KEmoji.Categories.Recent
|
||||
currentFont: root.emojiFont
|
||||
showUnsupportedEmojis: false
|
||||
sourceModel: KEmoji.Model {
|
||||
emojis: KEmoji.Dict.emojis
|
||||
}
|
||||
}
|
||||
|
||||
delegate: KEmoji.EmojiDelegate {
|
||||
id: resultDelegate
|
||||
|
||||
height: resultView.height
|
||||
font: root.emojiFont
|
||||
showVariantEmojis: false
|
||||
onClicked: root.commitEmoji(resultDelegate.emoji)
|
||||
}
|
||||
|
||||
QQC2.Label {
|
||||
anchors.centerIn: parent
|
||||
visible: resultView.count === 0
|
||||
text: root.query.length > 0 ? i18nc("@info", "No emoji found") : i18nc("@info", "Type to search for emoji")
|
||||
color: BreezeConstants.selectionListTextColor
|
||||
opacity: 0.7
|
||||
font.family: BreezeConstants.fontFamily
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,9 +23,10 @@ Item {
|
||||
property real bottomPadding: padding
|
||||
|
||||
readonly property var inputEngine: virtualKeyboardContext ? virtualKeyboardContext.inputEngine : VirtualKeyboard.inputEngine
|
||||
readonly property var emojiController: virtualKeyboardContext ? virtualKeyboardContext.emojiController : VirtualKeyboard.emojiController
|
||||
readonly property var keyboardController: virtualKeyboardContext ? virtualKeyboardContext.keyboardController : VirtualKeyboard.keyboardController
|
||||
readonly property var keyboardPackageResolver: virtualKeyboardContext ? virtualKeyboardContext.keyboardPackageResolver : VirtualKeyboard.keyboardPackageResolver
|
||||
readonly property bool navigationAvailable: keyboardNavigation.navigationAvailable
|
||||
readonly property bool navigationAvailable: (!emojiController || !emojiController.active || emojiController.searchActive) && keyboardNavigation.navigationAvailable
|
||||
property alias navigationModeActive: keyboardNavigation.navigationModeActive
|
||||
|
||||
readonly property string layoutId: keyboardController ? keyboardController.layoutId : ""
|
||||
@@ -38,7 +39,9 @@ Item {
|
||||
// Always have the keyboard panel be 30% of the screen height, or 150px, whichever is larger
|
||||
readonly property real __baseKeyboardInputAreaHeight: Math.max(Screen.height * 0.3, 150)
|
||||
readonly property real __keyboardInputAreaHeight: __baseKeyboardInputAreaHeight * ((layoutLoader.item && layoutLoader.item.panelHeightFactor !== undefined) ? layoutLoader.item.panelHeightFactor : 1)
|
||||
readonly property real __contentHeight: __keyboardInputAreaHeight + (candidateStrip.visible ? candidateStrip.implicitHeight : 0)
|
||||
readonly property real __contentHeight: __keyboardInputAreaHeight
|
||||
+ (candidateStrip.visible ? candidateStrip.implicitHeight : 0)
|
||||
+ (emojiSearchStrip.visible ? emojiSearchStrip.implicitHeight : 0)
|
||||
readonly property real __horizontalPadding: leftPadding + rightPadding
|
||||
readonly property real __verticalPadding: topPadding + bottomPadding
|
||||
readonly property real __keyboardHeight: __contentHeight + __verticalPadding
|
||||
@@ -115,35 +118,58 @@ Item {
|
||||
id: candidateStrip
|
||||
Layout.fillWidth: true
|
||||
inputEngine: root.inputEngine
|
||||
suppressed: root.emojiController && root.emojiController.active && !root.emojiController.searchActive
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: layoutLoader
|
||||
EmojiSearchStrip {
|
||||
id: emojiSearchStrip
|
||||
Layout.fillWidth: true
|
||||
visible: root.emojiController && root.emojiController.active && root.emojiController.searchActive
|
||||
emojiController: root.emojiController
|
||||
}
|
||||
|
||||
Item {
|
||||
id: keyboardArea
|
||||
Layout.preferredWidth: parent.width
|
||||
Layout.maximumWidth: (item && item.maxWidthToHeightRatio !== -1) ? (item.maxWidthToHeightRatio * height) : parent.width
|
||||
Layout.maximumWidth: (layoutLoader.item && layoutLoader.item.maxWidthToHeightRatio !== -1) ? (layoutLoader.item.maxWidthToHeightRatio * height) : parent.width
|
||||
Layout.minimumHeight: root.__keyboardInputAreaHeight
|
||||
Layout.preferredHeight: root.__keyboardInputAreaHeight
|
||||
Layout.maximumHeight: root.__keyboardInputAreaHeight
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
|
||||
source: root.keyboardPackageResolver ? root.keyboardPackageResolver.layoutUrl(root.layoutId, root.layoutType) : ""
|
||||
Loader {
|
||||
id: layoutLoader
|
||||
|
||||
onLoaded: {
|
||||
resetNavigation();
|
||||
if (item && item.virtualKeyboardContext !== undefined) {
|
||||
item.virtualKeyboardContext = root.virtualKeyboardContext;
|
||||
anchors.fill: parent
|
||||
enabled: !root.emojiController || !root.emojiController.active || root.emojiController.searchActive
|
||||
opacity: enabled ? 1 : 0
|
||||
source: root.keyboardPackageResolver ? root.keyboardPackageResolver.layoutUrl(root.layoutId, root.layoutType) : ""
|
||||
|
||||
onLoaded: {
|
||||
resetNavigation();
|
||||
if (item && item.virtualKeyboardContext !== undefined) {
|
||||
item.virtualKeyboardContext = root.virtualKeyboardContext;
|
||||
}
|
||||
if (item && item.keyboardLayoutId !== undefined) {
|
||||
item.keyboardLayoutId = root.layoutId;
|
||||
}
|
||||
if (item && item.packageId !== undefined) {
|
||||
item.packageId = root.packageId;
|
||||
}
|
||||
}
|
||||
if (item && item.layoutId !== undefined) {
|
||||
item.layoutId = root.layoutId;
|
||||
}
|
||||
if (item && item.packageId !== undefined) {
|
||||
item.packageId = root.packageId;
|
||||
|
||||
onStatusChanged: {
|
||||
if (status === Loader.Error) {
|
||||
console.warn("Failed to load keyboard layout", root.layoutId, root.layoutType, source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onStatusChanged: {
|
||||
if (status === Loader.Error) {
|
||||
console.warn("Failed to load keyboard layout", root.layoutId, root.layoutType, source);
|
||||
}
|
||||
EmojiPicker {
|
||||
anchors.fill: parent
|
||||
visible: root.emojiController && root.emojiController.active && !root.emojiController.searchActive
|
||||
emojiController: root.emojiController
|
||||
inputEngine: root.inputEngine
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,13 +16,14 @@ Rectangle {
|
||||
id: root
|
||||
|
||||
property var inputEngine: VirtualKeyboard.inputEngine
|
||||
property bool suppressed: false
|
||||
property bool navigationModeActive: false
|
||||
readonly property real candidateHorizontalPadding: Math.round(28 * BreezeConstants.scaleHint)
|
||||
readonly property int candidateCount: candidateView.count
|
||||
readonly property bool hasNavigationSelection: candidateView.currentIndex >= 0
|
||||
readonly property bool hasCandidates: inputEngine && inputEngine.wordCandidateListVisibleHint
|
||||
|
||||
visible: hasCandidates
|
||||
visible: hasCandidates && !suppressed
|
||||
implicitHeight: Math.round(100 * BreezeConstants.scaleHint)
|
||||
color: BreezeConstants.selectionListBackgroundColor
|
||||
|
||||
|
||||
@@ -12,11 +12,14 @@ import QtQuick.Templates as T
|
||||
import org.kde.kirigami as Kirigami
|
||||
import org.kde.plasma.keyboard.virtualkeyboard
|
||||
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
QQC2.Popup {
|
||||
id: root
|
||||
|
||||
property Item keyboardPanel
|
||||
property var keyboardController: VirtualKeyboard.keyboardController
|
||||
property var emojiController: VirtualKeyboard.emojiController
|
||||
readonly property bool popupVisible: visible
|
||||
readonly property int itemCount: languageListView.count
|
||||
property int currentIndex: languageListView.currentIndex
|
||||
@@ -79,6 +82,9 @@ QQC2.Popup {
|
||||
}
|
||||
|
||||
keyboardController.setCurrentLayout(keyboardController.activeLayoutIds[currentIndex]);
|
||||
if (emojiController) {
|
||||
emojiController.close();
|
||||
}
|
||||
close();
|
||||
return true;
|
||||
}
|
||||
@@ -160,6 +166,9 @@ QQC2.Popup {
|
||||
|
||||
root.currentIndex = root.keyboardController.activeLayoutIds.indexOf(modelData);
|
||||
root.keyboardController.setCurrentLayout(modelData);
|
||||
if (root.emojiController) {
|
||||
root.emojiController.close();
|
||||
}
|
||||
root.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,12 @@ Item {
|
||||
*/
|
||||
property string smallText: ""
|
||||
|
||||
/**
|
||||
* Small icon shown in the corner of the key.
|
||||
* If empty, no small corner icon is shown.
|
||||
*/
|
||||
property string smallIconName: ""
|
||||
|
||||
/**
|
||||
* Alternate characters offered from the long-press popup.
|
||||
* Layouts can provide this either as a string or as an explicit list.
|
||||
@@ -233,6 +239,16 @@ Item {
|
||||
|
||||
visible: text.length > 0
|
||||
}
|
||||
|
||||
Kirigami.Icon {
|
||||
source: root.smallIconName
|
||||
anchors.top: parent.top
|
||||
anchors.right: parent.right
|
||||
anchors.margins: BreezeConstants.keyContentMargin / 3
|
||||
implicitWidth: Math.round(32 * root.scaleHint)
|
||||
implicitHeight: implicitWidth
|
||||
visible: root.smallIconName.length > 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,19 +6,48 @@ import QtQuick
|
||||
import org.kde.plasma.keyboard
|
||||
import org.kde.plasma.keyboard.virtualkeyboard
|
||||
|
||||
// Action key that opens the keyboard layout/language selector.
|
||||
// Emoji key that opens the keyboard layout/language selector when held.
|
||||
|
||||
ActionKey {
|
||||
AbstractKey {
|
||||
id: root
|
||||
|
||||
iconName: "globe-symbolic"
|
||||
property bool __held: false
|
||||
|
||||
iconName: "smiley"
|
||||
smallIconName: "translate"
|
||||
displayText: ""
|
||||
functionKey: true
|
||||
secondaryStyle: true
|
||||
|
||||
onClicked: {
|
||||
if (VirtualKeyboard.languagePopup) {
|
||||
VirtualKeyboard.languagePopup.showForItem(root)
|
||||
if (VirtualKeyboard.keyboardController) {
|
||||
VirtualKeyboard.keyboardController.symbolMode = false
|
||||
}
|
||||
if (VirtualKeyboard.emojiController) {
|
||||
VirtualKeyboard.emojiController.open()
|
||||
}
|
||||
}
|
||||
|
||||
KeyMouseArea {
|
||||
keyItem: root
|
||||
pressAndHoldInterval: 500
|
||||
|
||||
onPressStarted: root.__held = false
|
||||
|
||||
onPressAndHold: {
|
||||
if (VirtualKeyboard.languagePopup) {
|
||||
root.__held = true
|
||||
VirtualKeyboard.languagePopup.showForItem(root)
|
||||
}
|
||||
}
|
||||
|
||||
onReleaseFinished: {
|
||||
if (!root.__held) {
|
||||
root.trigger()
|
||||
}
|
||||
root.__held = false
|
||||
}
|
||||
|
||||
onCancelFinished: root.__held = false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
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 "emojicontroller.h"
|
||||
|
||||
#include "inputengine.h"
|
||||
|
||||
#include <QTextBoundaryFinder>
|
||||
|
||||
EmojiController::EmojiController(InputEngine *inputEngine, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_inputEngine(inputEngine)
|
||||
{
|
||||
Q_ASSERT(m_inputEngine);
|
||||
|
||||
connect(m_inputEngine, &InputEngine::inputMethodHintsChanged, this, [this] {
|
||||
Q_EMIT availableChanged();
|
||||
if (!available()) {
|
||||
close();
|
||||
}
|
||||
});
|
||||
connect(m_inputEngine, &InputEngine::preeditTextChanged, this, [this] {
|
||||
if (m_searchActive) {
|
||||
Q_EMIT queryChanged();
|
||||
}
|
||||
});
|
||||
connect(m_inputEngine, &InputEngine::textCaptured, this, [this](const QString &text, int replaceFrom, int replaceLength) {
|
||||
if (m_searchActive) {
|
||||
replaceQueryText(text, replaceFrom, replaceLength);
|
||||
}
|
||||
});
|
||||
connect(m_inputEngine, &InputEngine::capturedBackspaceRequested, this, [this] {
|
||||
if (m_searchActive) {
|
||||
removeLastQueryCharacter();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
EmojiController::~EmojiController()
|
||||
{
|
||||
stopSearch();
|
||||
}
|
||||
|
||||
bool EmojiController::active() const
|
||||
{
|
||||
return m_active;
|
||||
}
|
||||
|
||||
bool EmojiController::searchActive() const
|
||||
{
|
||||
return m_searchActive;
|
||||
}
|
||||
|
||||
QString EmojiController::query() const
|
||||
{
|
||||
return m_query + (m_searchActive ? m_inputEngine->preeditText() : QString());
|
||||
}
|
||||
|
||||
bool EmojiController::available() const
|
||||
{
|
||||
const auto unavailableHints = Qt::ImhHiddenText | Qt::ImhSensitiveData | Qt::ImhDate | Qt::ImhTime | Qt::ImhDigitsOnly | Qt::ImhFormattedNumbersOnly
|
||||
| Qt::ImhUppercaseOnly | Qt::ImhLowercaseOnly | Qt::ImhDialableCharactersOnly | Qt::ImhEmailCharactersOnly | Qt::ImhUrlCharactersOnly
|
||||
| Qt::ImhLatinOnly;
|
||||
return !m_inputEngine->inputMethodHints().testAnyFlags(unavailableHints);
|
||||
}
|
||||
|
||||
void EmojiController::open()
|
||||
{
|
||||
if (m_active || !available()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_inputEngine->commit();
|
||||
if (auto *composer = m_inputEngine->textComposer()) {
|
||||
composer->reset();
|
||||
}
|
||||
m_active = true;
|
||||
Q_EMIT activeChanged();
|
||||
}
|
||||
|
||||
void EmojiController::close()
|
||||
{
|
||||
if (!m_active) {
|
||||
return;
|
||||
}
|
||||
|
||||
stopSearch();
|
||||
m_active = false;
|
||||
Q_EMIT activeChanged();
|
||||
}
|
||||
|
||||
void EmojiController::startSearch()
|
||||
{
|
||||
if (!m_active || m_searchActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_inputEngine->beginTextCapture();
|
||||
m_searchActive = true;
|
||||
Q_EMIT searchActiveChanged();
|
||||
}
|
||||
|
||||
void EmojiController::stopSearch()
|
||||
{
|
||||
if (!m_searchActive) {
|
||||
clearQuery();
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto *composer = m_inputEngine->textComposer()) {
|
||||
composer->reset();
|
||||
}
|
||||
m_inputEngine->endTextCapture();
|
||||
m_searchActive = false;
|
||||
Q_EMIT searchActiveChanged();
|
||||
clearQuery();
|
||||
}
|
||||
|
||||
void EmojiController::clearQuery()
|
||||
{
|
||||
if (m_searchActive) {
|
||||
if (auto *composer = m_inputEngine->textComposer()) {
|
||||
composer->reset();
|
||||
}
|
||||
}
|
||||
setQuery(QString());
|
||||
}
|
||||
|
||||
void EmojiController::commitEmoji(const QString &emoji)
|
||||
{
|
||||
if (!m_active || emoji.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto *composer = m_inputEngine->textComposer()) {
|
||||
composer->reset();
|
||||
}
|
||||
m_inputEngine->commitDirect(emoji);
|
||||
}
|
||||
|
||||
void EmojiController::appendQueryText(const QString &text)
|
||||
{
|
||||
if (!m_searchActive || text.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setQuery(m_query + text);
|
||||
}
|
||||
|
||||
void EmojiController::removeLastQueryCharacter()
|
||||
{
|
||||
if (!m_searchActive || m_query.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QTextBoundaryFinder finder(QTextBoundaryFinder::Grapheme, m_query);
|
||||
finder.toEnd();
|
||||
const qsizetype previousBoundary = finder.toPreviousBoundary();
|
||||
setQuery(previousBoundary < 0 ? QString() : m_query.first(previousBoundary));
|
||||
}
|
||||
|
||||
void EmojiController::setQuery(const QString &query)
|
||||
{
|
||||
if (m_query == query) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_query = query;
|
||||
Q_EMIT queryChanged();
|
||||
}
|
||||
|
||||
void EmojiController::replaceQueryText(const QString &text, int replaceFrom, int replaceLength)
|
||||
{
|
||||
if (!m_searchActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString query = m_query;
|
||||
if (replaceLength > 0) {
|
||||
int start = replaceFrom < 0 ? query.size() + replaceFrom : replaceFrom;
|
||||
start = qBound(0, start, query.size());
|
||||
query.remove(start, qMin(replaceLength, query.size() - start));
|
||||
}
|
||||
query.append(text);
|
||||
setQuery(query);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
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 <QObject>
|
||||
#include <QString>
|
||||
#include <qqmlintegration.h>
|
||||
|
||||
class InputEngine;
|
||||
|
||||
class EmojiController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
QML_ANONYMOUS
|
||||
Q_PROPERTY(bool active READ active NOTIFY activeChanged)
|
||||
Q_PROPERTY(bool searchActive READ searchActive NOTIFY searchActiveChanged)
|
||||
Q_PROPERTY(QString query READ query NOTIFY queryChanged)
|
||||
Q_PROPERTY(bool available READ available NOTIFY availableChanged)
|
||||
|
||||
public:
|
||||
explicit EmojiController(InputEngine *inputEngine, QObject *parent = nullptr);
|
||||
~EmojiController() override;
|
||||
|
||||
bool active() const;
|
||||
bool searchActive() const;
|
||||
QString query() const;
|
||||
bool available() const;
|
||||
|
||||
Q_INVOKABLE void open();
|
||||
Q_INVOKABLE void close();
|
||||
Q_INVOKABLE void startSearch();
|
||||
Q_INVOKABLE void stopSearch();
|
||||
Q_INVOKABLE void clearQuery();
|
||||
Q_INVOKABLE void commitEmoji(const QString &emoji);
|
||||
|
||||
void appendQueryText(const QString &text);
|
||||
void removeLastQueryCharacter();
|
||||
|
||||
Q_SIGNALS:
|
||||
void activeChanged();
|
||||
void searchActiveChanged();
|
||||
void queryChanged();
|
||||
void availableChanged();
|
||||
|
||||
private:
|
||||
void setQuery(const QString &query);
|
||||
void replaceQueryText(const QString &text, int replaceFrom, int replaceLength);
|
||||
|
||||
InputEngine *m_inputEngine = nullptr;
|
||||
QString m_query;
|
||||
bool m_active = false;
|
||||
bool m_searchActive = false;
|
||||
};
|
||||
@@ -149,7 +149,9 @@ void InputEngine::setPreeditText(const QString &text)
|
||||
}
|
||||
|
||||
m_preeditText = text;
|
||||
m_backend->setPreeditText(text);
|
||||
if (!m_textCaptureActive) {
|
||||
m_backend->setPreeditText(text);
|
||||
}
|
||||
Q_EMIT preeditTextChanged();
|
||||
}
|
||||
|
||||
@@ -250,6 +252,32 @@ bool InputEngine::wordCandidateListVisibleHint() const
|
||||
return !m_candidates.isEmpty();
|
||||
}
|
||||
|
||||
bool InputEngine::textCaptureActive() const
|
||||
{
|
||||
return m_textCaptureActive;
|
||||
}
|
||||
|
||||
void InputEngine::beginTextCapture()
|
||||
{
|
||||
if (m_textCaptureActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_textCaptureActive = true;
|
||||
setCapsLockActive(false);
|
||||
setShiftActive(false);
|
||||
}
|
||||
|
||||
void InputEngine::endTextCapture()
|
||||
{
|
||||
if (!m_textCaptureActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_textCaptureActive = false;
|
||||
updateAutomaticShift();
|
||||
}
|
||||
|
||||
bool InputEngine::sendTextComposerKey(int key, const QString &text)
|
||||
{
|
||||
if (!m_textComposer) {
|
||||
@@ -285,12 +313,29 @@ bool InputEngine::selectCandidate(int index)
|
||||
void InputEngine::commit()
|
||||
{
|
||||
if (!m_preeditText.isEmpty()) {
|
||||
m_backend->commitText(m_preeditText);
|
||||
if (m_textCaptureActive) {
|
||||
Q_EMIT textCaptured(m_preeditText, 0, 0);
|
||||
} else {
|
||||
m_backend->commitText(m_preeditText);
|
||||
}
|
||||
clearCompositionState(true);
|
||||
}
|
||||
}
|
||||
|
||||
void InputEngine::commit(const QString &text, int replaceFrom, int replaceLength)
|
||||
{
|
||||
if (m_textCaptureActive) {
|
||||
if (!text.isEmpty() || replaceLength != 0) {
|
||||
Q_EMIT textCaptured(text, replaceFrom, replaceLength);
|
||||
}
|
||||
clearCompositionState(true);
|
||||
return;
|
||||
}
|
||||
|
||||
commitDirect(text, replaceFrom, replaceLength);
|
||||
}
|
||||
|
||||
void InputEngine::commitDirect(const QString &text, int replaceFrom, int replaceLength)
|
||||
{
|
||||
if (replaceLength != 0) {
|
||||
m_backend->deleteSurroundingText(replaceFrom, replaceLength);
|
||||
@@ -310,6 +355,40 @@ void InputEngine::clear()
|
||||
|
||||
bool InputEngine::handleKeyCommit(int key, const QString &text)
|
||||
{
|
||||
if (m_textCaptureActive) {
|
||||
switch (key) {
|
||||
case Qt::Key_Backspace:
|
||||
case Qt::Key_Delete:
|
||||
Q_EMIT capturedBackspaceRequested();
|
||||
return true;
|
||||
case Qt::Key_Return:
|
||||
case Qt::Key_Enter:
|
||||
case Qt::Key_Tab:
|
||||
case Qt::Key_Left:
|
||||
case Qt::Key_Right:
|
||||
case Qt::Key_Up:
|
||||
case Qt::Key_Down:
|
||||
case Qt::Key_Home:
|
||||
case Qt::Key_End:
|
||||
return true;
|
||||
case Qt::Key_Space:
|
||||
Q_EMIT textCaptured(QStringLiteral(" "), 0, 0);
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (text.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Q_EMIT textCaptured(text, 0, 0);
|
||||
if (m_shiftActive && !m_capsLockActive) {
|
||||
setShiftActive(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (key) {
|
||||
case Qt::Key_Backspace:
|
||||
case Qt::Key_Delete:
|
||||
@@ -381,6 +460,12 @@ void InputEngine::connectBackend()
|
||||
|
||||
void InputEngine::resetShiftState()
|
||||
{
|
||||
if (m_textCaptureActive) {
|
||||
setCapsLockActive(false);
|
||||
setShiftActive(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_backend->isActive()) {
|
||||
setCapsLockActive(false);
|
||||
setShiftActive(false);
|
||||
@@ -400,6 +485,11 @@ void InputEngine::resetShiftState()
|
||||
|
||||
void InputEngine::updateAutomaticShift()
|
||||
{
|
||||
if (m_textCaptureActive) {
|
||||
setShiftActive(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_capsLockActive) {
|
||||
return;
|
||||
}
|
||||
@@ -426,7 +516,7 @@ void InputEngine::clearCompositionState(bool updateBackend)
|
||||
const bool hadPreedit = !m_preeditText.isEmpty();
|
||||
const bool hadCandidates = !m_candidates.isEmpty();
|
||||
|
||||
if (updateBackend && hadPreedit) {
|
||||
if (updateBackend && hadPreedit && !m_textCaptureActive) {
|
||||
m_backend->setPreeditText(QString());
|
||||
}
|
||||
|
||||
|
||||
@@ -78,6 +78,11 @@ public:
|
||||
WordCandidateListModel *wordCandidateListModel() const;
|
||||
bool wordCandidateListVisibleHint() const;
|
||||
|
||||
// Capture input through a proxy - used for emoji search
|
||||
bool textCaptureActive() const;
|
||||
void beginTextCapture();
|
||||
void endTextCapture();
|
||||
|
||||
/** Sends a text key through the active text composer. */
|
||||
Q_INVOKABLE bool sendTextComposerKey(int key, const QString &text);
|
||||
|
||||
@@ -89,6 +94,9 @@ public:
|
||||
Q_INVOKABLE void commit(const QString &text, int replaceFrom = 0, int replaceLength = 0);
|
||||
Q_INVOKABLE void clear();
|
||||
|
||||
// Commit to the client even while text capture is active - for proxies (i.e. emojis)
|
||||
void commitDirect(const QString &text, int replaceFrom = 0, int replaceLength = 0);
|
||||
|
||||
bool handleKeyCommit(int key, const QString &text);
|
||||
|
||||
Q_SIGNALS:
|
||||
@@ -108,6 +116,10 @@ Q_SIGNALS:
|
||||
void pressedKeysChanged();
|
||||
void wordCandidateListVisibleHintChanged();
|
||||
|
||||
// Capture input through a proxy - used for emoji search
|
||||
void textCaptured(const QString &text, int replaceFrom, int replaceLength);
|
||||
void capturedBackspaceRequested();
|
||||
|
||||
private:
|
||||
void connectBackend();
|
||||
void clearCompositionState(bool updateBackend);
|
||||
@@ -125,4 +137,5 @@ private:
|
||||
QString m_preeditText;
|
||||
QString m_preeditPrefix;
|
||||
QStringList m_candidates;
|
||||
bool m_textCaptureActive = false;
|
||||
};
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "virtualkeyboardattached.h"
|
||||
|
||||
#include "emojicontroller.h"
|
||||
#include "inputengine.h"
|
||||
#include "keyboardcontroller.h"
|
||||
#include "keyboardpackageresolver.h"
|
||||
@@ -60,6 +61,12 @@ InputEngine *VirtualKeyboardAttached::inputEngine() const
|
||||
return keyboardContext ? keyboardContext->inputEngine() : nullptr;
|
||||
}
|
||||
|
||||
EmojiController *VirtualKeyboardAttached::emojiController() const
|
||||
{
|
||||
auto *keyboardContext = context();
|
||||
return keyboardContext ? keyboardContext->emojiController() : nullptr;
|
||||
}
|
||||
|
||||
KeyboardController *VirtualKeyboardAttached::keyboardController() const
|
||||
{
|
||||
auto *keyboardContext = context();
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <qqmlintegration.h>
|
||||
|
||||
class InputEngine;
|
||||
class EmojiController;
|
||||
class KeyboardController;
|
||||
class KeyboardPackageResolver;
|
||||
class VirtualKeyboardContext;
|
||||
@@ -23,6 +24,7 @@ class VirtualKeyboardAttached : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(InputEngine *inputEngine READ inputEngine NOTIFY contextChanged)
|
||||
Q_PROPERTY(EmojiController *emojiController READ emojiController NOTIFY contextChanged)
|
||||
Q_PROPERTY(KeyboardController *keyboardController READ keyboardController NOTIFY contextChanged)
|
||||
Q_PROPERTY(KeyboardPackageResolver *keyboardPackageResolver READ keyboardPackageResolver NOTIFY contextChanged)
|
||||
Q_PROPERTY(QObject *alternativeKeysPopup READ alternativeKeysPopup NOTIFY contextChanged)
|
||||
@@ -35,6 +37,7 @@ public:
|
||||
explicit VirtualKeyboardAttached(QObject *attachedObject);
|
||||
|
||||
InputEngine *inputEngine() const;
|
||||
EmojiController *emojiController() const;
|
||||
KeyboardController *keyboardController() const;
|
||||
KeyboardPackageResolver *keyboardPackageResolver() const;
|
||||
QObject *alternativeKeysPopup() const;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "virtualkeyboardcontext.h"
|
||||
|
||||
#include "emojicontroller.h"
|
||||
#include "inputbackend.h"
|
||||
#include "inputengine.h"
|
||||
#include "keyboardcontroller.h"
|
||||
@@ -14,6 +15,7 @@
|
||||
VirtualKeyboardContext::VirtualKeyboardContext(InputBackend *inputBackend, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_inputEngine(new InputEngine(inputBackend, this))
|
||||
, m_emojiController(new EmojiController(m_inputEngine, this))
|
||||
, m_keyboardPackageResolver(new KeyboardPackageResolver(this))
|
||||
, m_keyboardController(new KeyboardController(m_inputEngine, m_keyboardPackageResolver, this))
|
||||
{
|
||||
@@ -24,6 +26,11 @@ InputEngine *VirtualKeyboardContext::inputEngine() const
|
||||
return m_inputEngine;
|
||||
}
|
||||
|
||||
EmojiController *VirtualKeyboardContext::emojiController() const
|
||||
{
|
||||
return m_emojiController;
|
||||
}
|
||||
|
||||
KeyboardController *VirtualKeyboardContext::keyboardController() const
|
||||
{
|
||||
return m_keyboardController;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
class InputBackend;
|
||||
class InputEngine;
|
||||
class EmojiController;
|
||||
class KeyboardController;
|
||||
class KeyboardPackageResolver;
|
||||
|
||||
@@ -22,6 +23,7 @@ class VirtualKeyboardContext : public QObject
|
||||
Q_OBJECT
|
||||
QML_ANONYMOUS
|
||||
Q_PROPERTY(InputEngine *inputEngine READ inputEngine CONSTANT)
|
||||
Q_PROPERTY(EmojiController *emojiController READ emojiController CONSTANT)
|
||||
Q_PROPERTY(KeyboardController *keyboardController READ keyboardController CONSTANT)
|
||||
Q_PROPERTY(KeyboardPackageResolver *keyboardPackageResolver READ keyboardPackageResolver CONSTANT)
|
||||
|
||||
@@ -29,11 +31,13 @@ public:
|
||||
explicit VirtualKeyboardContext(InputBackend *inputBackend, QObject *parent = nullptr);
|
||||
|
||||
InputEngine *inputEngine() const;
|
||||
EmojiController *emojiController() const;
|
||||
KeyboardController *keyboardController() const;
|
||||
KeyboardPackageResolver *keyboardPackageResolver() const;
|
||||
|
||||
private:
|
||||
InputEngine *m_inputEngine = nullptr;
|
||||
EmojiController *m_emojiController = nullptr;
|
||||
KeyboardPackageResolver *m_keyboardPackageResolver = nullptr;
|
||||
KeyboardController *m_keyboardController = nullptr;
|
||||
};
|
||||
Reference in new issue
Block a user