File indexing completed on 2024-04-28 16:52:19

0001 /*
0002     SPDX-FileCopyrightText: 2020 Carson Black <uhhadd@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #ifndef PLASMAIMCONTEXT_H
0008 #define PLASMAIMCONTEXT_H
0009 
0010 #include <QPointer>
0011 #include <QWidget>
0012 
0013 #include <KConfigGroup>
0014 #include <KConfigWatcher>
0015 #include <KSharedConfig>
0016 
0017 #include <qpa/qplatforminputcontext.h>
0018 
0019 QT_BEGIN_NAMESPACE
0020 
0021 struct TooltipData {
0022     QString character;
0023     QString number;
0024     int idx;
0025 };
0026 
0027 class PlasmaIMContext : public QPlatformInputContext
0028 {
0029     Q_OBJECT
0030 
0031 public:
0032     PlasmaIMContext();
0033     ~PlasmaIMContext();
0034 
0035     bool isValid() const override;
0036     void setFocusObject(QObject *object) override;
0037     bool filterEvent(const QEvent *event) override;
0038 
0039 private:
0040     void cleanUpState();
0041     void applyReplacement(const QString &data);
0042     void showPopup(const QList<TooltipData> &text);
0043     void configChangedHandler(const KConfigGroup &grp, const QByteArrayList &names);
0044 
0045     QPointer<QWidget> popup;
0046     QPointer<QObject> m_focusObject = nullptr;
0047 
0048     bool isPreHold = false;
0049     QString preHoldText = QString();
0050     KSharedConfig::Ptr config = KSharedConfig::openConfig(QStringLiteral("kcminputrc"));
0051     KConfigGroup keyboard = KConfigGroup(config, "Keyboard");
0052     KConfigWatcher::Ptr watcher = KConfigWatcher::create(config);
0053 };
0054 
0055 QT_END_NAMESPACE
0056 
0057 #endif