File indexing completed on 2024-11-17 05:01:08

0001 /*
0002     SPDX-FileCopyrightText: 2020 Weng Xuetian <wengxt@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #pragma once
0008 
0009 #include "kimpanelagent.h"
0010 #include <QList>
0011 #include <QObject>
0012 #include <QRect>
0013 #include <QVariantList>
0014 
0015 class Kimpanel : public QObject
0016 {
0017     Q_OBJECT
0018     Q_PROPERTY(QString auxText MEMBER m_auxText NOTIFY auxTextChanged)
0019     Q_PROPERTY(bool auxVisible MEMBER m_auxVisible NOTIFY auxTextChanged)
0020 
0021     Q_PROPERTY(QString preeditText MEMBER m_preeditText NOTIFY preeditTextChanged)
0022     Q_PROPERTY(int caretPos MEMBER m_caretPos NOTIFY preeditTextChanged)
0023     Q_PROPERTY(bool preeditVisible MEMBER m_preeditVisible NOTIFY preeditTextChanged)
0024 
0025     Q_PROPERTY(QRect spotRect MEMBER m_spotRect NOTIFY spotRectChanged)
0026 
0027     Q_PROPERTY(bool lookupTableVisible MEMBER m_lookupTableVisible NOTIFY lookupTableChanged)
0028     Q_PROPERTY(int lookupTableCursor MEMBER m_lookupTableCursor NOTIFY lookupTableChanged)
0029     Q_PROPERTY(int lookupTableLayout MEMBER m_lookupTableLayout NOTIFY lookupTableChanged)
0030     Q_PROPERTY(bool hasPrev MEMBER m_hasPrev NOTIFY lookupTableChanged)
0031     Q_PROPERTY(bool hasNext MEMBER m_hasNext NOTIFY lookupTableChanged)
0032     Q_PROPERTY(QStringList labels MEMBER m_labels NOTIFY lookupTableChanged)
0033     Q_PROPERTY(QStringList texts MEMBER m_texts NOTIFY lookupTableChanged)
0034 
0035     Q_PROPERTY(QVariantList properties MEMBER m_props NOTIFY propertiesChanged)
0036 public:
0037     Kimpanel(QObject *parent = nullptr);
0038 
0039     Q_INVOKABLE void lookupTablePageUp();
0040     Q_INVOKABLE void lookupTablePageDown();
0041     Q_INVOKABLE void movePreeditCaret(int position);
0042     Q_INVOKABLE void selectCandidate(int candidate);
0043     Q_INVOKABLE void triggerProperty(const QString &key);
0044     Q_INVOKABLE void reloadConfig();
0045     Q_INVOKABLE void configure();
0046     Q_INVOKABLE void exit();
0047 
0048 Q_SIGNALS:
0049     void auxTextChanged();
0050     void preeditTextChanged();
0051     void lookupTableChanged();
0052     void spotRectChanged();
0053     void propertiesChanged();
0054     void menuTriggered(const QVariantList &props);
0055 
0056 private Q_SLOTS:
0057     void updatePreeditText(const QString &text, const QList<TextAttribute> &attrList);
0058     void updateAux(const QString &text, const QList<TextAttribute> &attrList);
0059     void updatePreeditCaret(int pos);
0060     void updateLookupTable(const KimpanelLookupTable &lookupTable);
0061     void updateLookupTableFull(const KimpanelLookupTable &lookupTable, int cursor, int layout);
0062     void updateSpotLocation(int x, int y);
0063     void updateSpotRect(int x, int y, int w, int h);
0064     void showAux(bool visible);
0065     void showPreedit(bool visible);
0066     void showLookupTable(bool visible);
0067     void updateLookupTableCursor(int cursor);
0068 
0069     void updateProperty(const KimpanelProperty &property);
0070     void registerProperties(const QList<KimpanelProperty> &props);
0071     void execDialog(const KimpanelProperty &prop);
0072     void execMenu(const QList<KimpanelProperty> &prop_list);
0073 
0074 private:
0075     PanelAgent *m_panelAgent;
0076     QString m_auxText;
0077     QString m_preeditText;
0078     int m_caretPos = 0;
0079     QRect m_spotRect;
0080     bool m_auxVisible = false;
0081     bool m_preeditVisible = false;
0082     bool m_lookupTableVisible = false;
0083     int m_lookupTableCursor = -1;
0084     int m_lookupTableLayout = 0;
0085     bool m_hasPrev = false;
0086     bool m_hasNext = false;
0087     QStringList m_labels;
0088     QStringList m_texts;
0089 
0090     QVariantList m_props;
0091 };