1 /*
2 SPDX-FileCopyrightText: 2020 Weng Xuetian <wengxt@gmail.com>
3
4 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
5 */
6 #include "kimpanel.h"
7
Kimpanel(QObject * parent)8 Kimpanel::Kimpanel(QObject *parent)
9 : QObject(parent)
10 , m_panelAgent(new PanelAgent(this))
11 {
12 connect(m_panelAgent, &PanelAgent::updateAux, this, &Kimpanel::updateAux);
13 connect(m_panelAgent, &PanelAgent::updatePreeditText, this, &Kimpanel::updatePreeditText);
14 connect(m_panelAgent, &PanelAgent::updatePreeditCaret, this, &Kimpanel::updatePreeditCaret);
15 connect(m_panelAgent, &PanelAgent::updateLookupTable, this, &Kimpanel::updateLookupTable);
16 connect(m_panelAgent, &PanelAgent::updateSpotLocation, this, &Kimpanel::updateSpotLocation);
17 connect(m_panelAgent, &PanelAgent::updateSpotRect, this, &Kimpanel::updateSpotRect);
18 connect(m_panelAgent, &PanelAgent::showAux, this, &Kimpanel::showAux);
19 connect(m_panelAgent, &PanelAgent::showPreedit, this, &Kimpanel::showPreedit);
20 connect(m_panelAgent, &PanelAgent::showLookupTable, this, &Kimpanel::showLookupTable);
21 connect(m_panelAgent, &PanelAgent::updateLookupTableCursor, this, &Kimpanel::updateLookupTableCursor);
22 connect(m_panelAgent, &PanelAgent::updateLookupTableFull, this, &Kimpanel::updateLookupTableFull);
23
24 connect(m_panelAgent, &PanelAgent::updateProperty, this, &Kimpanel::updateProperty);
25 connect(m_panelAgent, &PanelAgent::registerProperties, this, &Kimpanel::registerProperties);
26 connect(m_panelAgent, &PanelAgent::execMenu, this, &Kimpanel::execMenu);
27 connect(m_panelAgent, &PanelAgent::execDialog, this, &Kimpanel::execDialog);
28 }
29
updateAux(const QString & text,const QList<TextAttribute> & attrList)30 void Kimpanel::updateAux(const QString &text, const QList<TextAttribute> &attrList)
31 {
32 Q_UNUSED(attrList);
33 if (m_auxText != text) {
34 m_auxText = text;
35 Q_EMIT auxTextChanged();
36 }
37 }
38
updatePreeditText(const QString & text,const QList<TextAttribute> & attrList)39 void Kimpanel::updatePreeditText(const QString &text, const QList<TextAttribute> &attrList)
40 {
41 Q_UNUSED(attrList);
42 if (m_preeditText != text) {
43 m_preeditText = text;
44 Q_EMIT preeditTextChanged();
45 }
46 }
47
updatePreeditCaret(int pos)48 void Kimpanel::updatePreeditCaret(int pos)
49 {
50 if (m_caretPos != pos) {
51 m_caretPos = pos;
52 Q_EMIT preeditTextChanged();
53 }
54 }
55
updateLookupTable(const KimpanelLookupTable & lookupTable)56 void Kimpanel::updateLookupTable(const KimpanelLookupTable &lookupTable)
57 {
58 m_labels.clear();
59 m_texts.clear();
60 Q_FOREACH (const KimpanelLookupTable::Entry &entry, lookupTable.entries) {
61 m_labels << entry.label;
62 m_texts << entry.text;
63 }
64 m_hasPrev = lookupTable.has_prev;
65 m_hasNext = lookupTable.has_next;
66 Q_EMIT lookupTableChanged();
67 }
68
updateSpotLocation(int x,int y)69 void Kimpanel::updateSpotLocation(int x, int y)
70 {
71 updateSpotRect(x, y, 0, 0);
72 }
73
updateSpotRect(int x,int y,int w,int h)74 void Kimpanel::updateSpotRect(int x, int y, int w, int h)
75 {
76 m_spotRect = QRect(x, y, w, h);
77 Q_EMIT spotRectChanged();
78 }
79
showAux(bool visible)80 void Kimpanel::showAux(bool visible)
81 {
82 if (m_auxVisible != visible) {
83 m_auxVisible = visible;
84 Q_EMIT auxTextChanged();
85 }
86 }
87
showPreedit(bool visible)88 void Kimpanel::showPreedit(bool visible)
89 {
90 if (m_preeditVisible != visible) {
91 m_preeditVisible = visible;
92 Q_EMIT preeditTextChanged();
93 }
94 }
95
showLookupTable(bool visible)96 void Kimpanel::showLookupTable(bool visible)
97 {
98 if (m_lookupTableVisible != visible) {
99 m_lookupTableVisible = visible;
100 Q_EMIT lookupTableChanged();
101 }
102 }
103
updateLookupTableCursor(int cursor)104 void Kimpanel::updateLookupTableCursor(int cursor)
105 {
106 if (m_lookupTableCursor != cursor) {
107 m_lookupTableCursor = cursor;
108 Q_EMIT lookupTableChanged();
109 }
110 }
111
updateLookupTableFull(const KimpanelLookupTable & lookupTable,int cursor,int layout)112 void Kimpanel::updateLookupTableFull(const KimpanelLookupTable &lookupTable, int cursor, int layout)
113 {
114 m_labels.clear();
115 m_texts.clear();
116 Q_FOREACH (const KimpanelLookupTable::Entry &entry, lookupTable.entries) {
117 m_labels << entry.label;
118 m_texts << entry.text;
119 }
120 m_hasPrev = lookupTable.has_prev;
121 m_hasNext = lookupTable.has_next;
122 m_lookupTableCursor = cursor;
123 m_lookupTableLayout = layout;
124 Q_EMIT lookupTableChanged();
125 }
126
updateProperty(const KimpanelProperty & property)127 void Kimpanel::updateProperty(const KimpanelProperty &property)
128 {
129 for (auto &prop : m_props) {
130 if (prop.toMap()[QStringLiteral("key")] == property.key) {
131 prop = property.toMap();
132 Q_EMIT propertiesChanged();
133 break;
134 }
135 }
136 }
137
registerProperties(const QList<KimpanelProperty> & props)138 void Kimpanel::registerProperties(const QList<KimpanelProperty> &props)
139 {
140 m_props.clear();
141 for (const auto &prop : props) {
142 m_props << prop.toMap();
143 }
144 Q_EMIT propertiesChanged();
145 }
146
execMenu(const QList<KimpanelProperty> & props)147 void Kimpanel::execMenu(const QList<KimpanelProperty> &props)
148 {
149 QVariantList menuProps;
150 for (const auto &prop : props) {
151 menuProps << prop.toMap();
152 }
153 Q_EMIT menuTriggered(menuProps);
154 }
155
execDialog(const KimpanelProperty & prop)156 void Kimpanel::execDialog(const KimpanelProperty &prop)
157 {
158 Q_UNUSED(prop)
159 }
160
configure()161 void Kimpanel::configure()
162 {
163 m_panelAgent->configure();
164 }
165
exit()166 void Kimpanel::exit()
167 {
168 m_panelAgent->exit();
169 }
170
lookupTablePageDown()171 void Kimpanel::lookupTablePageDown()
172 {
173 m_panelAgent->lookupTablePageDown();
174 }
175
lookupTablePageUp()176 void Kimpanel::lookupTablePageUp()
177 {
178 m_panelAgent->lookupTablePageUp();
179 }
180
movePreeditCaret(int position)181 void Kimpanel::movePreeditCaret(int position)
182 {
183 m_panelAgent->movePreeditCaret(position);
184 }
185
reloadConfig()186 void Kimpanel::reloadConfig()
187 {
188 m_panelAgent->reloadConfig();
189 }
190
selectCandidate(int candidate)191 void Kimpanel::selectCandidate(int candidate)
192 {
193 m_panelAgent->selectCandidate(candidate);
194 }
195
triggerProperty(const QString & key)196 void Kimpanel::triggerProperty(const QString &key)
197 {
198 m_panelAgent->triggerProperty(key);
199 }
200