author | alwin <alwin> | 2005-02-28 09:40:30 (UTC) |
---|---|---|
committer | alwin <alwin> | 2005-02-28 09:40:30 (UTC) |
commit | 2b64a84d39eeed5681d0ee5068c7d11a01527750 (patch) (unidiff) | |
tree | c8693340dbc5ef5e2f9afa90b690829ddff2c4bd /noncore/applets/keyhelper/keyhelperconf/KHCWidget.cpp | |
parent | 61fa699140c5efbb6ba0bf2a62f7e8fbf62976be (diff) | |
download | opie-2b64a84d39eeed5681d0ee5068c7d11a01527750.zip opie-2b64a84d39eeed5681d0ee5068c7d11a01527750.tar.gz opie-2b64a84d39eeed5681d0ee5068c7d11a01527750.tar.bz2 |
other keymapping tool - not working this moment, I have to check it out
- the reason is that the config file is somewhat easier to understand than
from zkbapplet and has a nice config tool.
Please don't put it into any repositories this moment.
Diffstat (limited to 'noncore/applets/keyhelper/keyhelperconf/KHCWidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/applets/keyhelper/keyhelperconf/KHCWidget.cpp | 307 |
1 files changed, 307 insertions, 0 deletions
diff --git a/noncore/applets/keyhelper/keyhelperconf/KHCWidget.cpp b/noncore/applets/keyhelper/keyhelperconf/KHCWidget.cpp new file mode 100644 index 0000000..b0767cf --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperconf/KHCWidget.cpp | |||
@@ -0,0 +1,307 @@ | |||
1 | #include "KHCWidget.h" | ||
2 | |||
3 | KHCWidget::KHCWidget(QWidget* parent, const char* name, WFlags fl) | ||
4 | : KHCWidgetBase(parent, name, fl) | ||
5 | { | ||
6 | m_isEnable = true; | ||
7 | setLayout(); | ||
8 | setHandler(); | ||
9 | |||
10 | txtOrgKey->installEventFilter(this); | ||
11 | txtMapKey->installEventFilter(this); | ||
12 | } | ||
13 | |||
14 | KHCWidget::~KHCWidget() | ||
15 | { | ||
16 | } | ||
17 | |||
18 | void KHCWidget::setLayout() | ||
19 | { | ||
20 | QBoxLayout* topLayout = new QVBoxLayout(this, 5); | ||
21 | |||
22 | QBoxLayout* orgLayout1 = new QHBoxLayout(topLayout); | ||
23 | orgLayout1->addWidget(lblOriginal); | ||
24 | orgLayout1->addWidget(txtOrgKey); | ||
25 | |||
26 | QBoxLayout* orgLayout2 = new QHBoxLayout(topLayout); | ||
27 | orgLayout2->addWidget(lblOrgK); | ||
28 | orgLayout2->addWidget(lblOrgKeycode); | ||
29 | #if 0 | ||
30 | orgLayout2->addWidget(lblOrgM); | ||
31 | orgLayout2->addWidget(lblOrgModifiers); | ||
32 | #endif | ||
33 | orgLayout2->addWidget(lblOrgU); | ||
34 | orgLayout2->addWidget(lblOrgUnicode); | ||
35 | orgLayout2->addWidget(chkOrgShift); | ||
36 | orgLayout2->addWidget(chkOrgCtrl); | ||
37 | orgLayout2->addWidget(chkOrgAlt); | ||
38 | |||
39 | QBoxLayout* mapLayout1 = new QHBoxLayout(topLayout); | ||
40 | mapLayout1->addWidget(lblMapping); | ||
41 | mapLayout1->addWidget(txtMapKey); | ||
42 | |||
43 | QBoxLayout* mapLayout2 = new QHBoxLayout(topLayout); | ||
44 | mapLayout2->addWidget(lblMapK); | ||
45 | mapLayout2->addWidget(lblMapKeycode); | ||
46 | #if 0 | ||
47 | mapLayout2->addWidget(lblMapM); | ||
48 | mapLayout2->addWidget(lblMapModifiers); | ||
49 | #endif | ||
50 | mapLayout2->addWidget(lblMapU); | ||
51 | mapLayout2->addWidget(lblMapUnicode); | ||
52 | mapLayout2->addWidget(chkMapShift); | ||
53 | mapLayout2->addWidget(chkMapCtrl); | ||
54 | mapLayout2->addWidget(chkMapAlt); | ||
55 | |||
56 | QBoxLayout* btnLayout = new QHBoxLayout(topLayout); | ||
57 | btnLayout->addWidget(btnGen); | ||
58 | btnLayout->addWidget(btnCopy); | ||
59 | btnLayout->addWidget(btnCtrl); | ||
60 | |||
61 | topLayout->addWidget(mleDefine); | ||
62 | } | ||
63 | |||
64 | void KHCWidget::setHandler() | ||
65 | { | ||
66 | connect(btnGen, SIGNAL(clicked()), this, SLOT(onClick_Gen())); | ||
67 | connect(btnCopy, SIGNAL(clicked()), this, SLOT(onClick_Copy())); | ||
68 | connect(btnCtrl, SIGNAL(clicked()), this, SLOT(onClick_Ctrl())); | ||
69 | } | ||
70 | |||
71 | bool KHCWidget::eventFilter(QObject* o, QEvent* e) | ||
72 | { | ||
73 | if(::strcmp(o->name(), "txtOrgKey") == 0){ | ||
74 | if(e->type() == QEvent::KeyPress){ | ||
75 | QKeyEvent* ke = (QKeyEvent*)e; | ||
76 | if(ke->isAutoRepeat() == false){ | ||
77 | onPress_Org(ke); | ||
78 | } | ||
79 | return(true); | ||
80 | } | ||
81 | } else if(::strcmp(o->name(), "txtMapKey") == 0){ | ||
82 | if(e->type() == QEvent::KeyPress){ | ||
83 | QKeyEvent* ke = (QKeyEvent*)e; | ||
84 | if(ke->isAutoRepeat() == false){ | ||
85 | onPress_Map(ke); | ||
86 | } | ||
87 | return(true); | ||
88 | } | ||
89 | } | ||
90 | |||
91 | return QWidget::eventFilter(o, e); | ||
92 | } | ||
93 | |||
94 | void KHCWidget::onPress_Org(QKeyEvent* ke) | ||
95 | { | ||
96 | /* keycode */ | ||
97 | const QString& name = KeyNames::getName(ke->key()); | ||
98 | if(name == QString::null){ | ||
99 | lblOrgKeycode->setText(QString::number(ke->key(), 16)); | ||
100 | } else { | ||
101 | lblOrgKeycode->setText(name); | ||
102 | } | ||
103 | /* modifiers */ | ||
104 | chkOrgShift->setChecked(ke->state() & Qt::ShiftButton); | ||
105 | chkOrgCtrl->setChecked(ke->state() & Qt::ControlButton); | ||
106 | chkOrgAlt->setChecked(ke->state() & Qt::AltButton); | ||
107 | |||
108 | /* unicode */ | ||
109 | if(ke->text()[0].isPrint()){ | ||
110 | lblOrgUnicode->setText(ke->text()); | ||
111 | } else { | ||
112 | lblOrgUnicode->setText(QString::number(ke->ascii(), 16)); | ||
113 | } | ||
114 | m_OrgkeyData.setData(ke); | ||
115 | } | ||
116 | |||
117 | void KHCWidget::onPress_Map(QKeyEvent* ke) | ||
118 | { | ||
119 | /* keycode */ | ||
120 | const QString& name = KeyNames::getName(ke->key()); | ||
121 | if(name == QString::null){ | ||
122 | lblMapKeycode->setText(QString::number(ke->key(), 16)); | ||
123 | } else { | ||
124 | lblMapKeycode->setText(name); | ||
125 | } | ||
126 | /* modifiers */ | ||
127 | chkMapShift->setChecked(ke->state() & Qt::ShiftButton); | ||
128 | chkMapCtrl->setChecked(ke->state() & Qt::ControlButton); | ||
129 | chkMapAlt->setChecked(ke->state() & Qt::AltButton); | ||
130 | |||
131 | /* unicode */ | ||
132 | if(ke->text()[0].isPrint()){ | ||
133 | lblMapUnicode->setText(ke->text()); | ||
134 | } else { | ||
135 | lblMapUnicode->setText(QString::number(ke->ascii(), 16)); | ||
136 | } | ||
137 | m_MapkeyData.setData(ke); | ||
138 | } | ||
139 | |||
140 | void KHCWidget::onClick_Gen() | ||
141 | { | ||
142 | mleDefine->clear(); | ||
143 | if(m_OrgkeyData.key == 0 | ||
144 | || m_MapkeyData.key == 0){ | ||
145 | return; | ||
146 | } | ||
147 | /* original key */ | ||
148 | QString line; | ||
149 | const QString& name = KeyNames::getName(m_OrgkeyData.key); | ||
150 | line = "<define "; | ||
151 | if(name == QString::null){ | ||
152 | line.append("code=\""); | ||
153 | line.append(QString::number(m_OrgkeyData.key, 16)); | ||
154 | } else { | ||
155 | line.append("key=\""); | ||
156 | line.append(name); | ||
157 | } | ||
158 | line.append("\">"); | ||
159 | mleDefine->append(line); | ||
160 | |||
161 | /* original modifiers */ | ||
162 | bool need = false; | ||
163 | line = "<modifier"; | ||
164 | if(chkOrgShift->isChecked()){ | ||
165 | line.append(" Shift=\"On\""); | ||
166 | need = true; | ||
167 | } | ||
168 | if(chkOrgCtrl->isChecked()){ | ||
169 | line.append(" Control=\"On\""); | ||
170 | need = true; | ||
171 | } | ||
172 | if(chkOrgAlt->isChecked()){ | ||
173 | line.append(" Alt=\"On\""); | ||
174 | need = true; | ||
175 | } | ||
176 | line.append("/>"); | ||
177 | if(need){ | ||
178 | mleDefine->append(line); | ||
179 | } | ||
180 | |||
181 | /* mapping key */ | ||
182 | const QString& mapname = KeyNames::getName(m_MapkeyData.key); | ||
183 | line = "<map"; | ||
184 | if(mapname == QString::null){ | ||
185 | line.append(" code=\""); | ||
186 | line.append(QString::number(m_MapkeyData.key, 16)); | ||
187 | } else { | ||
188 | line.append(" key=\""); | ||
189 | line.append(mapname); | ||
190 | } | ||
191 | line.append("\"/>"); | ||
192 | mleDefine->append(line); | ||
193 | |||
194 | /* mapping modifiers */ | ||
195 | need = false; | ||
196 | line = "<map_modifier"; | ||
197 | bool on = chkMapShift->isChecked(); | ||
198 | if(chkOrgShift->isChecked() != on){ | ||
199 | line.append(" Shift=\""); | ||
200 | if(on){ | ||
201 | line.append("On\""); | ||
202 | } else { | ||
203 | line.append("Off\""); | ||
204 | } | ||
205 | need = true; | ||
206 | } | ||
207 | on = chkMapCtrl->isChecked(); | ||
208 | if(chkOrgCtrl->isChecked() != on){ | ||
209 | line.append(" Control=\""); | ||
210 | if(on){ | ||
211 | line.append("On\""); | ||
212 | } else { | ||
213 | line.append("Off\""); | ||
214 | } | ||
215 | need = true; | ||
216 | } | ||
217 | on = chkMapAlt->isChecked(); | ||
218 | if(chkOrgAlt->isChecked() != on){ | ||
219 | line.append(" Alt=\""); | ||
220 | if(on){ | ||
221 | line.append("On\""); | ||
222 | } else { | ||
223 | line.append("Off\""); | ||
224 | } | ||
225 | need = true; | ||
226 | } | ||
227 | line.append("/>"); | ||
228 | if(need){ | ||
229 | mleDefine->append(line); | ||
230 | } | ||
231 | |||
232 | /* mapping unicode */ | ||
233 | bool found = false; | ||
234 | for(const QWSServer::KeyMap* m = QWSServer::keyMap(); | ||
235 | m->key_code != 0; m++){ | ||
236 | if(m->key_code == m_MapkeyData.key){ | ||
237 | if(m_MapkeyData.state & Qt::ControlButton){ | ||
238 | if(m->ctrl_unicode == m_MapkeyData.ascii){ | ||
239 | found = true; | ||
240 | break; | ||
241 | } | ||
242 | } else if(m_MapkeyData.state & Qt::ShiftButton){ | ||
243 | if(m->shift_unicode == m_MapkeyData.ascii){ | ||
244 | found = true; | ||
245 | break; | ||
246 | } | ||
247 | } else { | ||
248 | if(m->unicode == m_MapkeyData.ascii){ | ||
249 | found = true; | ||
250 | break; | ||
251 | } | ||
252 | } | ||
253 | } | ||
254 | } | ||
255 | if(found == false){ | ||
256 | if(m_MapkeyData.text[0].isPrint()){ | ||
257 | line = "<map_unicode"; | ||
258 | if(m_MapkeyData.state & Qt::ControlButton){ | ||
259 | line.append(" ctrl_unicode=\""); | ||
260 | } else if(m_MapkeyData.state & Qt::ShiftButton){ | ||
261 | line.append(" shift_unicode=\""); | ||
262 | } else { | ||
263 | line.append(" unicode=\""); | ||
264 | } | ||
265 | line.append(m_MapkeyData.text); | ||
266 | line.append("\"/>"); | ||
267 | mleDefine->append(line); | ||
268 | } else { | ||
269 | mleDefine->clear(); | ||
270 | mleDefine->append("Not Support"); | ||
271 | return; | ||
272 | } | ||
273 | } | ||
274 | |||
275 | /* close tag */ | ||
276 | line = "</define>"; | ||
277 | mleDefine->append(line); | ||
278 | } | ||
279 | |||
280 | void KHCWidget::onClick_Copy() | ||
281 | { | ||
282 | mleDefine->selectAll(); | ||
283 | mleDefine->copy(); | ||
284 | mleDefine->deselect(); | ||
285 | } | ||
286 | |||
287 | void KHCWidget::onClick_Ctrl() | ||
288 | { | ||
289 | if(m_isEnable){ | ||
290 | QCopEnvelope e("QPE/KeyHelper", "disable()"); | ||
291 | btnCtrl->setText(tr("Enable")); | ||
292 | //btnCtrl->update(); | ||
293 | } else { | ||
294 | QCopEnvelope e("QPE/KeyHelper", "enable()"); | ||
295 | btnCtrl->setText(tr("Disable")); | ||
296 | //btnCtrl->update(); | ||
297 | } | ||
298 | m_isEnable = !m_isEnable; | ||
299 | } | ||
300 | |||
301 | void KHCWidget::closeEvent(QCloseEvent* ce) | ||
302 | { | ||
303 | qDebug("closeEvent()"); | ||
304 | QCopEnvelope e("QPE/KeyHelper", "enable()"); | ||
305 | ce->accept(); | ||
306 | } | ||
307 | |||