-rw-r--r-- | inputmethods/multikey/configdlg.cpp | 1 | ||||
-rw-r--r-- | inputmethods/multikey/keyboard.cpp | 8 |
2 files changed, 8 insertions, 1 deletions
diff --git a/inputmethods/multikey/configdlg.cpp b/inputmethods/multikey/configdlg.cpp index 89b713e..a9137b9 100644 --- a/inputmethods/multikey/configdlg.cpp +++ b/inputmethods/multikey/configdlg.cpp | |||
@@ -1,363 +1,364 @@ | |||
1 | /* | 1 | /* |
2 | * TODO | 2 | * TODO |
3 | * make a font selection thing (size too) | 3 | * make a font selection thing (size too) |
4 | * make a cursor thing | 4 | * make a cursor thing |
5 | * add meta key support for german, etc | ||
5 | * | 6 | * |
6 | * | 7 | * |
7 | * | 8 | * |
8 | */ | 9 | */ |
9 | 10 | ||
10 | #include <iostream.h> | 11 | #include <iostream.h> |
11 | 12 | ||
12 | #include <qpe/qpeapplication.h> | 13 | #include <qpe/qpeapplication.h> |
13 | #include <qpe/config.h> | 14 | #include <qpe/config.h> |
14 | 15 | ||
15 | #include <qwidget.h> | 16 | #include <qwidget.h> |
16 | #include <qdialog.h> | 17 | #include <qdialog.h> |
17 | #include <qtabwidget.h> | 18 | #include <qtabwidget.h> |
18 | #include <qvbox.h> | 19 | #include <qvbox.h> |
19 | #include <qgrid.h> | 20 | #include <qgrid.h> |
20 | #include <qgroupbox.h> | 21 | #include <qgroupbox.h> |
21 | #include <qlabel.h> | 22 | #include <qlabel.h> |
22 | #include <qcheckbox.h> | 23 | #include <qcheckbox.h> |
23 | #include <qsizepolicy.h> | 24 | #include <qsizepolicy.h> |
24 | #include <qpushbutton.h> | 25 | #include <qpushbutton.h> |
25 | #include <qlistbox.h> | 26 | #include <qlistbox.h> |
26 | #include <qstringlist.h> | 27 | #include <qstringlist.h> |
27 | #include <opie/ofiledialog.h> | 28 | #include <opie/ofiledialog.h> |
28 | #include <opie/colordialog.h> | 29 | #include <opie/colordialog.h> |
29 | #include <qdir.h> | 30 | #include <qdir.h> |
30 | #include <qfileinfo.h> | 31 | #include <qfileinfo.h> |
31 | #include "configdlg.h" | 32 | #include "configdlg.h" |
32 | #include "keyboard.h" | 33 | #include "keyboard.h" |
33 | 34 | ||
34 | // ConfigDlg::ConfigDlg() {{{1 | 35 | // ConfigDlg::ConfigDlg() {{{1 |
35 | ConfigDlg::ConfigDlg () : QTabWidget () | 36 | ConfigDlg::ConfigDlg () : QTabWidget () |
36 | { | 37 | { |
37 | setCaption( tr("Multikey Configuration") ); | 38 | setCaption( tr("Multikey Configuration") ); |
38 | Config config ("multikey"); | 39 | Config config ("multikey"); |
39 | config.setGroup("keymaps"); | 40 | config.setGroup("keymaps"); |
40 | QString current_map = config.readEntry("current", 0); | 41 | QString current_map = config.readEntry("current", 0); |
41 | 42 | ||
42 | /* | 43 | /* |
43 | * 'general config' tab | 44 | * 'general config' tab |
44 | */ | 45 | */ |
45 | 46 | ||
46 | QVBox *gen_box = new QVBox (this); | 47 | QVBox *gen_box = new QVBox (this); |
47 | gen_box->setMargin(3); | 48 | gen_box->setMargin(3); |
48 | addTab(gen_box, tr("General Settings")); | 49 | addTab(gen_box, tr("General Settings")); |
49 | 50 | ||
50 | QGroupBox *map_group = new QGroupBox (2, Qt::Vertical, tr("Keymap File"), gen_box); | 51 | QGroupBox *map_group = new QGroupBox (2, Qt::Vertical, tr("Keymap File"), gen_box); |
51 | 52 | ||
52 | keymaps = new QListBox (map_group); | 53 | keymaps = new QListBox (map_group); |
53 | keymaps->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); | 54 | keymaps->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); |
54 | 55 | ||
55 | QString cur(tr("Current Language")); | 56 | QString cur(tr("Current Language")); |
56 | keymaps->insertItem(cur); | 57 | keymaps->insertItem(cur); |
57 | keymaps->setSelected(0, true); | 58 | keymaps->setSelected(0, true); |
58 | 59 | ||
59 | QDir map_dir(QPEApplication::qpeDir() + "/share/multikey", "*.keymap"); | 60 | QDir map_dir(QPEApplication::qpeDir() + "/share/multikey", "*.keymap"); |
60 | default_maps = map_dir.entryList(); // so i can access it in other places | 61 | default_maps = map_dir.entryList(); // so i can access it in other places |
61 | 62 | ||
62 | for (uint i = 0; i <map_dir.count(); i++) { | 63 | for (uint i = 0; i <map_dir.count(); i++) { |
63 | 64 | ||
64 | keymaps->insertItem(map_dir.absPath() + "/" + map_dir[i]); | 65 | keymaps->insertItem(map_dir.absPath() + "/" + map_dir[i]); |
65 | if (map_dir.absPath() + "/" + map_dir[i] == current_map) { | 66 | if (map_dir.absPath() + "/" + map_dir[i] == current_map) { |
66 | 67 | ||
67 | keymaps->setSelected(i + 1, true); | 68 | keymaps->setSelected(i + 1, true); |
68 | } | 69 | } |
69 | 70 | ||
70 | } | 71 | } |
71 | 72 | ||
72 | custom_maps = config.readListEntry("maps", QChar('|')); | 73 | custom_maps = config.readListEntry("maps", QChar('|')); |
73 | 74 | ||
74 | for (uint i = 0; i < custom_maps.count(); i++) { | 75 | for (uint i = 0; i < custom_maps.count(); i++) { |
75 | 76 | ||
76 | if (map_dir.exists(QFileInfo(custom_maps[i]).fileName(), false) | 77 | if (map_dir.exists(QFileInfo(custom_maps[i]).fileName(), false) |
77 | || !QFile::exists(custom_maps[i])) { | 78 | || !QFile::exists(custom_maps[i])) { |
78 | 79 | ||
79 | custom_maps.remove(custom_maps.at(i)); | 80 | custom_maps.remove(custom_maps.at(i)); |
80 | 81 | ||
81 | // remove it from the list too | 82 | // remove it from the list too |
82 | config.writeEntry("maps", custom_maps.join("|")); | 83 | config.writeEntry("maps", custom_maps.join("|")); |
83 | 84 | ||
84 | 85 | ||
85 | } else { | 86 | } else { |
86 | 87 | ||
87 | keymaps->insertItem(custom_maps[i]); | 88 | keymaps->insertItem(custom_maps[i]); |
88 | if (custom_maps[i] == current_map) { | 89 | if (custom_maps[i] == current_map) { |
89 | 90 | ||
90 | keymaps->setSelected(map_dir.count() + i + 1, true); | 91 | keymaps->setSelected(map_dir.count() + i + 1, true); |
91 | } | 92 | } |
92 | } | 93 | } |
93 | } | 94 | } |
94 | 95 | ||
95 | // have to "+1" because the "current language" listItem... remember? | 96 | // have to "+1" because the "current language" listItem... remember? |
96 | 97 | ||
97 | connect(keymaps, SIGNAL(highlighted(int)), SLOT(setMap(int))); | 98 | connect(keymaps, SIGNAL(highlighted(int)), SLOT(setMap(int))); |
98 | 99 | ||
99 | 100 | ||
100 | QGrid *add_remove_grid = new QGrid(2, map_group); | 101 | QGrid *add_remove_grid = new QGrid(2, map_group); |
101 | add_remove_grid->setMargin(3); | 102 | add_remove_grid->setMargin(3); |
102 | add_remove_grid->setSpacing(3); | 103 | add_remove_grid->setSpacing(3); |
103 | 104 | ||
104 | add_button = new QPushButton(tr("Add"), add_remove_grid); | 105 | add_button = new QPushButton(tr("Add"), add_remove_grid); |
105 | add_button->setFlat((bool)1); | 106 | add_button->setFlat((bool)1); |
106 | connect(add_button, SIGNAL(clicked()), SLOT(addMap())); | 107 | connect(add_button, SIGNAL(clicked()), SLOT(addMap())); |
107 | 108 | ||
108 | remove_button = new QPushButton(tr("Remove"), add_remove_grid); | 109 | remove_button = new QPushButton(tr("Remove"), add_remove_grid); |
109 | remove_button->setFlat((bool)1); | 110 | remove_button->setFlat((bool)1); |
110 | if ((int)map_dir.count() >= keymaps->currentItem()) | 111 | if ((int)map_dir.count() >= keymaps->currentItem()) |
111 | remove_button->setDisabled(true); | 112 | remove_button->setDisabled(true); |
112 | connect(remove_button, SIGNAL(clicked()), SLOT(removeMap())); | 113 | connect(remove_button, SIGNAL(clicked()), SLOT(removeMap())); |
113 | 114 | ||
114 | // make a box that will contain the buttons on the bottom | 115 | // make a box that will contain the buttons on the bottom |
115 | QGrid *other_grid = new QGrid(2, gen_box); | 116 | QGrid *other_grid = new QGrid(2, gen_box); |
116 | pick_button = new QCheckBox(tr("Pickboard"), other_grid); | 117 | pick_button = new QCheckBox(tr("Pickboard"), other_grid); |
117 | 118 | ||
118 | config.setGroup ("general"); | 119 | config.setGroup ("general"); |
119 | bool pick_open = config.readBoolEntry ("usePickboard", (bool)0); // default closed | 120 | bool pick_open = config.readBoolEntry ("usePickboard", (bool)0); // default closed |
120 | if (pick_open) { | 121 | if (pick_open) { |
121 | 122 | ||
122 | pick_button->setChecked(true); | 123 | pick_button->setChecked(true); |
123 | } | 124 | } |
124 | 125 | ||
125 | // by connecting it after checking it, the signal isn't emmited | 126 | // by connecting it after checking it, the signal isn't emmited |
126 | connect (pick_button, SIGNAL(clicked()), this, SLOT(pickTog())); | 127 | connect (pick_button, SIGNAL(clicked()), this, SLOT(pickTog())); |
127 | 128 | ||
128 | repeat_button = new QCheckBox(tr("Key Repeat"), other_grid); | 129 | repeat_button = new QCheckBox(tr("Key Repeat"), other_grid); |
129 | bool repeat_on = config.readBoolEntry ("useRepeat", (bool)1); | 130 | bool repeat_on = config.readBoolEntry ("useRepeat", (bool)1); |
130 | 131 | ||
131 | if (repeat_on) { | 132 | if (repeat_on) { |
132 | 133 | ||
133 | repeat_button->setChecked(true); | 134 | repeat_button->setChecked(true); |
134 | } | 135 | } |
135 | connect (repeat_button, SIGNAL(clicked()), this, SLOT(repeatTog())); | 136 | connect (repeat_button, SIGNAL(clicked()), this, SLOT(repeatTog())); |
136 | 137 | ||
137 | 138 | ||
138 | /* | 139 | /* |
139 | * 'color' tab | 140 | * 'color' tab |
140 | */ | 141 | */ |
141 | 142 | ||
142 | QGrid *color_box = new QGrid(2, this); | 143 | QGrid *color_box = new QGrid(2, this); |
143 | color_box->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); | 144 | color_box->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); |
144 | color_box->setMargin(3); | 145 | color_box->setMargin(3); |
145 | color_box->setSpacing(3); | 146 | color_box->setSpacing(3); |
146 | addTab(color_box, tr("Colors")); | 147 | addTab(color_box, tr("Colors")); |
147 | 148 | ||
148 | QLabel *label; | 149 | QLabel *label; |
149 | QStringList color; | 150 | QStringList color; |
150 | config.setGroup("colors"); | 151 | config.setGroup("colors"); |
151 | 152 | ||
152 | label = new QLabel(tr("Key Color"), color_box); | 153 | label = new QLabel(tr("Key Color"), color_box); |
153 | keycolor_button = new QPushButton(color_box); | 154 | keycolor_button = new QPushButton(color_box); |
154 | connect(keycolor_button, SIGNAL(clicked()), SLOT(keyColorClicked())); | 155 | connect(keycolor_button, SIGNAL(clicked()), SLOT(keyColorClicked())); |
155 | keycolor_button->setFlat((bool)1); | 156 | keycolor_button->setFlat((bool)1); |
156 | color = config.readListEntry("keycolor", QChar(',')); | 157 | color = config.readListEntry("keycolor", QChar(',')); |
157 | /* | 158 | /* |
158 | * hopefully not required | 159 | * hopefully not required |
159 | 160 | ||
160 | if (color.isEmpty()) { | 161 | if (color.isEmpty()) { |
161 | color = QStringList::split(",", "240,240,240"); | 162 | color = QStringList::split(",", "240,240,240"); |
162 | config.writeEntry("keycolor", color.join(",")); | 163 | config.writeEntry("keycolor", color.join(",")); |
163 | 164 | ||
164 | } | 165 | } |
165 | */ | 166 | */ |
166 | keycolor_button->setBackgroundColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); | 167 | keycolor_button->setBackgroundColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); |
167 | 168 | ||
168 | 169 | ||
169 | label = new QLabel(tr("Key Pressed Color"), color_box); | 170 | label = new QLabel(tr("Key Pressed Color"), color_box); |
170 | keycolor_pressed_button = new QPushButton(color_box); | 171 | keycolor_pressed_button = new QPushButton(color_box); |
171 | connect(keycolor_pressed_button, SIGNAL(clicked()), SLOT(keyColorPressedClicked())); | 172 | connect(keycolor_pressed_button, SIGNAL(clicked()), SLOT(keyColorPressedClicked())); |
172 | keycolor_pressed_button->setFlat((bool)1); | 173 | keycolor_pressed_button->setFlat((bool)1); |
173 | color = config.readListEntry("keycolor_pressed", QChar(',')); | 174 | color = config.readListEntry("keycolor_pressed", QChar(',')); |
174 | keycolor_pressed_button->setBackgroundColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); | 175 | keycolor_pressed_button->setBackgroundColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); |
175 | 176 | ||
176 | label = new QLabel(tr("Line Color"), color_box); | 177 | label = new QLabel(tr("Line Color"), color_box); |
177 | keycolor_lines_button = new QPushButton(color_box); | 178 | keycolor_lines_button = new QPushButton(color_box); |
178 | connect(keycolor_lines_button, SIGNAL(clicked()), SLOT(keyColorLinesClicked())); | 179 | connect(keycolor_lines_button, SIGNAL(clicked()), SLOT(keyColorLinesClicked())); |
179 | keycolor_lines_button->setFlat((bool)1); | 180 | keycolor_lines_button->setFlat((bool)1); |
180 | color = config.readListEntry("keycolor_lines", QChar(',')); | 181 | color = config.readListEntry("keycolor_lines", QChar(',')); |
181 | keycolor_lines_button->setBackgroundColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); | 182 | keycolor_lines_button->setBackgroundColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); |
182 | 183 | ||
183 | 184 | ||
184 | label = new QLabel(tr("Text Color"), color_box); | 185 | label = new QLabel(tr("Text Color"), color_box); |
185 | textcolor_button = new QPushButton(color_box); | 186 | textcolor_button = new QPushButton(color_box); |
186 | connect(textcolor_button, SIGNAL(clicked()), SLOT(textColorClicked())); | 187 | connect(textcolor_button, SIGNAL(clicked()), SLOT(textColorClicked())); |
187 | textcolor_button->setFlat((bool)1); | 188 | textcolor_button->setFlat((bool)1); |
188 | color = config.readListEntry("textcolor", QChar(',')); | 189 | color = config.readListEntry("textcolor", QChar(',')); |
189 | textcolor_button->setBackgroundColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); | 190 | textcolor_button->setBackgroundColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); |
190 | 191 | ||
191 | 192 | ||
192 | label = new QLabel("", color_box); // a spacer so the above buttons dont expand | 193 | label = new QLabel("", color_box); // a spacer so the above buttons dont expand |
193 | label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); | 194 | label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); |
194 | 195 | ||
195 | } | 196 | } |
196 | 197 | ||
197 | void ConfigDlg::pickTog() { | 198 | void ConfigDlg::pickTog() { |
198 | 199 | ||
199 | Config config ("multikey"); | 200 | Config config ("multikey"); |
200 | config.setGroup ("general"); | 201 | config.setGroup ("general"); |
201 | config.writeEntry ("usePickboard", pick_button->isChecked()); // default closed | 202 | config.writeEntry ("usePickboard", pick_button->isChecked()); // default closed |
202 | 203 | ||
203 | emit pickboardToggled(pick_button->isChecked()); | 204 | emit pickboardToggled(pick_button->isChecked()); |
204 | } | 205 | } |
205 | 206 | ||
206 | void ConfigDlg::repeatTog() { | 207 | void ConfigDlg::repeatTog() { |
207 | 208 | ||
208 | Config config ("multikey"); | 209 | Config config ("multikey"); |
209 | config.setGroup ("general"); | 210 | config.setGroup ("general"); |
210 | config.writeEntry ("useRepeat", repeat_button->isChecked()); // default closed | 211 | config.writeEntry ("useRepeat", repeat_button->isChecked()); // default closed |
211 | 212 | ||
212 | emit repeatToggled(repeat_button->isChecked()); | 213 | emit repeatToggled(repeat_button->isChecked()); |
213 | } | 214 | } |
214 | 215 | ||
215 | // ConfigDlg::setMap {{{1 | 216 | // ConfigDlg::setMap {{{1 |
216 | 217 | ||
217 | /* | 218 | /* |
218 | * the index is kinda screwy, because in the config file, index 0 is just the | 219 | * the index is kinda screwy, because in the config file, index 0 is just the |
219 | * first element in the QStringList, but here it's the "Current Language" | 220 | * first element in the QStringList, but here it's the "Current Language" |
220 | * listItem. therefor you have to minus one to the index before you access it. | 221 | * listItem. therefor you have to minus one to the index before you access it. |
221 | * | 222 | * |
222 | */ | 223 | */ |
223 | 224 | ||
224 | void ConfigDlg::setMap(int index) { | 225 | void ConfigDlg::setMap(int index) { |
225 | 226 | ||
226 | if (index == 0) { | 227 | if (index == 0) { |
227 | 228 | ||
228 | remove_button->setDisabled(true); | 229 | remove_button->setDisabled(true); |
229 | emit setMapToDefault(); | 230 | emit setMapToDefault(); |
230 | } | 231 | } |
231 | else if ((uint)index <= default_maps.count()) { | 232 | else if ((uint)index <= default_maps.count()) { |
232 | 233 | ||
233 | remove_button->setDisabled(true); | 234 | remove_button->setDisabled(true); |
234 | emit setMapToFile(keymaps->text(index)); | 235 | emit setMapToFile(keymaps->text(index)); |
235 | 236 | ||
236 | } else { | 237 | } else { |
237 | 238 | ||
238 | remove_button->setEnabled(true); | 239 | remove_button->setEnabled(true); |
239 | emit setMapToFile(keymaps->text(index)); | 240 | emit setMapToFile(keymaps->text(index)); |
240 | } | 241 | } |
241 | } | 242 | } |
242 | 243 | ||
243 | // ConfigDlg::addMap() {{{1 | 244 | // ConfigDlg::addMap() {{{1 |
244 | void ConfigDlg::addMap() { | 245 | void ConfigDlg::addMap() { |
245 | 246 | ||
246 | QString map = OFileDialog::getOpenFileName(1, QDir::home().absPath()); | 247 | QString map = OFileDialog::getOpenFileName(1, QDir::home().absPath()); |
247 | Config config ("multikey"); | 248 | Config config ("multikey"); |
248 | config.setGroup("keymaps"); | 249 | config.setGroup("keymaps"); |
249 | QStringList maps = config.readListEntry("maps", QChar('|')); | 250 | QStringList maps = config.readListEntry("maps", QChar('|')); |
250 | maps.append(map); | 251 | maps.append(map); |
251 | keymaps->insertItem(map); | 252 | keymaps->insertItem(map); |
252 | keymaps->setSelected(keymaps->count() - 1, true); | 253 | keymaps->setSelected(keymaps->count() - 1, true); |
253 | 254 | ||
254 | 255 | ||
255 | config.writeEntry("maps", maps, QChar('|')); | 256 | config.writeEntry("maps", maps, QChar('|')); |
256 | config.writeEntry("current", map); | 257 | config.writeEntry("current", map); |
257 | 258 | ||
258 | } | 259 | } |
259 | 260 | ||
260 | // ConfigDlg::removeMap() {{{1 | 261 | // ConfigDlg::removeMap() {{{1 |
261 | void ConfigDlg::removeMap() { | 262 | void ConfigDlg::removeMap() { |
262 | 263 | ||
263 | cout << "removing : " << custom_maps[keymaps->currentItem() - default_maps.count() - 1] << "\n"; | 264 | cout << "removing : " << custom_maps[keymaps->currentItem() - default_maps.count() - 1] << "\n"; |
264 | cout << "currentItem : " << keymaps->currentItem() << "\n"; | 265 | cout << "currentItem : " << keymaps->currentItem() << "\n"; |
265 | 266 | ||
266 | // move selection up one | 267 | // move selection up one |
267 | keymaps->setSelected(keymaps->currentItem() - 1, true); | 268 | keymaps->setSelected(keymaps->currentItem() - 1, true); |
268 | // delete the next selected item cus you just moved it up | 269 | // delete the next selected item cus you just moved it up |
269 | keymaps->removeItem(keymaps->currentItem() + 1); | 270 | keymaps->removeItem(keymaps->currentItem() + 1); |
270 | 271 | ||
271 | custom_maps.remove(custom_maps[keymaps->currentItem() - default_maps.count()]); | 272 | custom_maps.remove(custom_maps[keymaps->currentItem() - default_maps.count()]); |
272 | 273 | ||
273 | // write the changes | 274 | // write the changes |
274 | Config config ("multikey"); | 275 | Config config ("multikey"); |
275 | config.setGroup("keymaps"); | 276 | config.setGroup("keymaps"); |
276 | config.writeEntry("maps", custom_maps, QChar('|')); | 277 | config.writeEntry("maps", custom_maps, QChar('|')); |
277 | } | 278 | } |
278 | 279 | ||
279 | /* ConfigDlg::slots for the color buttons {{{1 | 280 | /* ConfigDlg::slots for the color buttons {{{1 |
280 | * | 281 | * |
281 | * these four slots are almost the same, except for the names. i was thinking | 282 | * these four slots are almost the same, except for the names. i was thinking |
282 | * of making a map with pointers to the buttons and names of the configEntry | 283 | * of making a map with pointers to the buttons and names of the configEntry |
283 | * so it could be one slot, but then there would be no way of telling which | 284 | * so it could be one slot, but then there would be no way of telling which |
284 | * of the buttons was clicked if they all connect to the same slot. | 285 | * of the buttons was clicked if they all connect to the same slot. |
285 | * | 286 | * |
286 | */ | 287 | */ |
287 | 288 | ||
288 | void ConfigDlg::keyColorClicked() { | 289 | void ConfigDlg::keyColorClicked() { |
289 | 290 | ||
290 | Config config ("multikey"); | 291 | Config config ("multikey"); |
291 | config.setGroup ("colors"); | 292 | config.setGroup ("colors"); |
292 | 293 | ||
293 | QStringList color = config.readListEntry("keycolor", QChar(',')); | 294 | QStringList color = config.readListEntry("keycolor", QChar(',')); |
294 | 295 | ||
295 | QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); | 296 | QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); |
296 | 297 | ||
297 | color[0].setNum(newcolor.red()); | 298 | color[0].setNum(newcolor.red()); |
298 | color[1].setNum(newcolor.green()); | 299 | color[1].setNum(newcolor.green()); |
299 | color[2].setNum(newcolor.blue()); | 300 | color[2].setNum(newcolor.blue()); |
300 | 301 | ||
301 | config.writeEntry("keycolor", color, QChar(',')); | 302 | config.writeEntry("keycolor", color, QChar(',')); |
302 | config.write(); | 303 | config.write(); |
303 | 304 | ||
304 | keycolor_button->setBackgroundColor(newcolor); | 305 | keycolor_button->setBackgroundColor(newcolor); |
305 | emit reloadKeyboard(); | 306 | emit reloadKeyboard(); |
306 | } | 307 | } |
307 | void ConfigDlg::keyColorPressedClicked() { | 308 | void ConfigDlg::keyColorPressedClicked() { |
308 | 309 | ||
309 | Config config ("multikey"); | 310 | Config config ("multikey"); |
310 | config.setGroup ("colors"); | 311 | config.setGroup ("colors"); |
311 | 312 | ||
312 | QStringList color = config.readListEntry("keycolor_pressed", QChar(',')); | 313 | QStringList color = config.readListEntry("keycolor_pressed", QChar(',')); |
313 | 314 | ||
314 | QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); | 315 | QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); |
315 | 316 | ||
316 | color[0].setNum(newcolor.red()); | 317 | color[0].setNum(newcolor.red()); |
317 | color[1].setNum(newcolor.green()); | 318 | color[1].setNum(newcolor.green()); |
318 | color[2].setNum(newcolor.blue()); | 319 | color[2].setNum(newcolor.blue()); |
319 | 320 | ||
320 | config.writeEntry("keycolor_pressed", color, QChar(',')); | 321 | config.writeEntry("keycolor_pressed", color, QChar(',')); |
321 | config.write(); | 322 | config.write(); |
322 | 323 | ||
323 | keycolor_pressed_button->setBackgroundColor(newcolor); | 324 | keycolor_pressed_button->setBackgroundColor(newcolor); |
324 | emit reloadKeyboard(); | 325 | emit reloadKeyboard(); |
325 | } | 326 | } |
326 | void ConfigDlg::keyColorLinesClicked() { | 327 | void ConfigDlg::keyColorLinesClicked() { |
327 | 328 | ||
328 | Config config ("multikey"); | 329 | Config config ("multikey"); |
329 | config.setGroup ("colors"); | 330 | config.setGroup ("colors"); |
330 | 331 | ||
331 | QStringList color = config.readListEntry("keycolor_lines", QChar(',')); | 332 | QStringList color = config.readListEntry("keycolor_lines", QChar(',')); |
332 | 333 | ||
333 | QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); | 334 | QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); |
334 | 335 | ||
335 | color[0].setNum(newcolor.red()); | 336 | color[0].setNum(newcolor.red()); |
336 | color[1].setNum(newcolor.green()); | 337 | color[1].setNum(newcolor.green()); |
337 | color[2].setNum(newcolor.blue()); | 338 | color[2].setNum(newcolor.blue()); |
338 | 339 | ||
339 | config.writeEntry("keycolor_lines", color, QChar(',')); | 340 | config.writeEntry("keycolor_lines", color, QChar(',')); |
340 | config.write(); | 341 | config.write(); |
341 | 342 | ||
342 | keycolor_lines_button->setBackgroundColor(newcolor); | 343 | keycolor_lines_button->setBackgroundColor(newcolor); |
343 | emit reloadKeyboard(); | 344 | emit reloadKeyboard(); |
344 | } | 345 | } |
345 | void ConfigDlg::textColorClicked() { | 346 | void ConfigDlg::textColorClicked() { |
346 | 347 | ||
347 | Config config ("multikey"); | 348 | Config config ("multikey"); |
348 | config.setGroup ("colors"); | 349 | config.setGroup ("colors"); |
349 | 350 | ||
350 | QStringList color = config.readListEntry("textcolor", QChar(',')); | 351 | QStringList color = config.readListEntry("textcolor", QChar(',')); |
351 | 352 | ||
352 | QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); | 353 | QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); |
353 | 354 | ||
354 | color[0].setNum(newcolor.red()); | 355 | color[0].setNum(newcolor.red()); |
355 | color[1].setNum(newcolor.green()); | 356 | color[1].setNum(newcolor.green()); |
356 | color[2].setNum(newcolor.blue()); | 357 | color[2].setNum(newcolor.blue()); |
357 | 358 | ||
358 | config.writeEntry("textcolor", color, QChar(',')); | 359 | config.writeEntry("textcolor", color, QChar(',')); |
359 | config.write(); | 360 | config.write(); |
360 | 361 | ||
361 | textcolor_button->setBackgroundColor(newcolor); | 362 | textcolor_button->setBackgroundColor(newcolor); |
362 | emit reloadKeyboard(); | 363 | emit reloadKeyboard(); |
363 | } | 364 | } |
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp index 7334c1c..949164a 100644 --- a/inputmethods/multikey/keyboard.cpp +++ b/inputmethods/multikey/keyboard.cpp | |||
@@ -1,1149 +1,1155 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "keyboard.h" | 21 | #include "keyboard.h" |
22 | #include "configdlg.h" | 22 | #include "configdlg.h" |
23 | 23 | ||
24 | #include <qpe/global.h> | 24 | #include <qpe/global.h> |
25 | #include <qpe/qcopenvelope_qws.h> | 25 | #include <qpe/qcopenvelope_qws.h> |
26 | 26 | ||
27 | #include <qwindowsystem_qws.h> | 27 | #include <qwindowsystem_qws.h> |
28 | #include <qpainter.h> | 28 | #include <qpainter.h> |
29 | #include <qfontmetrics.h> | 29 | #include <qfontmetrics.h> |
30 | #include <qtimer.h> | 30 | #include <qtimer.h> |
31 | #include <qpe/qpeapplication.h> | 31 | #include <qpe/qpeapplication.h> |
32 | #include <qpe/config.h> | 32 | #include <qpe/config.h> |
33 | #include <ctype.h> | 33 | #include <ctype.h> |
34 | #include <qfile.h> | 34 | #include <qfile.h> |
35 | #include <qtextstream.h> | 35 | #include <qtextstream.h> |
36 | #include <qstringlist.h> | 36 | #include <qstringlist.h> |
37 | #include <iostream.h> | 37 | #include <iostream.h> |
38 | 38 | ||
39 | #include <sys/utsname.h> | 39 | #include <sys/utsname.h> |
40 | 40 | ||
41 | 41 | ||
42 | /* Keyboard::Keyboard {{{1 */ | 42 | /* Keyboard::Keyboard {{{1 */ |
43 | Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : | 43 | Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : |
44 | QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), | 44 | QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), |
45 | alt(0), useLargeKeys(TRUE), usePicks(0), useRepeat(0), pressedKeyRow(-1), pressedKeyCol(-1), | 45 | alt(0), useLargeKeys(TRUE), usePicks(0), useRepeat(0), pressedKeyRow(-1), pressedKeyCol(-1), |
46 | unicode(-1), qkeycode(0), modifiers(0), schar(0), mchar(0), echar(0), | 46 | unicode(-1), qkeycode(0), modifiers(0), schar(0), mchar(0), echar(0), |
47 | configdlg(0) | 47 | configdlg(0) |
48 | 48 | ||
49 | { | 49 | { |
50 | 50 | ||
51 | // get the default font | 51 | // get the default font |
52 | Config *config = new Config( "qpe" ); | 52 | Config *config = new Config( "qpe" ); |
53 | config->setGroup( "Appearance" ); | 53 | config->setGroup( "Appearance" ); |
54 | QString familyStr = config->readEntry( "FontFamily", "fixed" ); | 54 | QString familyStr = config->readEntry( "FontFamily", "fixed" ); |
55 | delete config; | 55 | delete config; |
56 | 56 | ||
57 | config = new Config("multikey"); | 57 | config = new Config("multikey"); |
58 | config->setGroup ("general"); | 58 | config->setGroup ("general"); |
59 | usePicks = config->readBoolEntry ("usePickboard", "0"); // default closed | 59 | usePicks = config->readBoolEntry ("usePickboard", "0"); // default closed |
60 | useRepeat = config->readBoolEntry ("useRepeat", "1"); | 60 | useRepeat = config->readBoolEntry ("useRepeat", "1"); |
61 | delete config; | 61 | delete config; |
62 | 62 | ||
63 | 63 | ||
64 | setFont( QFont( familyStr, 10 ) ); | 64 | setFont( QFont( familyStr, 10 ) ); |
65 | 65 | ||
66 | picks = new KeyboardPicks( this ); | 66 | picks = new KeyboardPicks( this ); |
67 | picks->setFont( QFont( familyStr, 10 ) ); | 67 | picks->setFont( QFont( familyStr, 10 ) ); |
68 | picks->initialise(); | 68 | picks->initialise(); |
69 | if (usePicks) { | 69 | if (usePicks) { |
70 | 70 | ||
71 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), | 71 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), |
72 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); | 72 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); |
73 | 73 | ||
74 | } else picks->hide(); | 74 | } else picks->hide(); |
75 | 75 | ||
76 | loadKeyboardColors(); | 76 | loadKeyboardColors(); |
77 | 77 | ||
78 | keys = new Keys(); | 78 | keys = new Keys(); |
79 | 79 | ||
80 | repeatTimer = new QTimer( this ); | 80 | repeatTimer = new QTimer( this ); |
81 | connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); | 81 | connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); |
82 | 82 | ||
83 | } | 83 | } |
84 | 84 | ||
85 | Keyboard::~Keyboard() { | 85 | Keyboard::~Keyboard() { |
86 | 86 | ||
87 | if ( configdlg ) { | 87 | if ( configdlg ) { |
88 | delete (ConfigDlg *) configdlg; | 88 | delete (ConfigDlg *) configdlg; |
89 | configdlg = 0; | 89 | configdlg = 0; |
90 | } | 90 | } |
91 | 91 | ||
92 | } | 92 | } |
93 | 93 | ||
94 | /* Keyboard::resizeEvent {{{1 */ | 94 | /* Keyboard::resizeEvent {{{1 */ |
95 | void Keyboard::resizeEvent(QResizeEvent*) | 95 | void Keyboard::resizeEvent(QResizeEvent*) |
96 | { | 96 | { |
97 | int ph = picks->sizeHint().height(); | 97 | int ph = picks->sizeHint().height(); |
98 | picks->setGeometry( 0, 0, width(), ph ); | 98 | picks->setGeometry( 0, 0, width(), ph ); |
99 | keyHeight = (height()-(usePicks ? ph : 0))/5; | 99 | keyHeight = (height()-(usePicks ? ph : 0))/5; |
100 | 100 | ||
101 | int nk; // number of keys? | 101 | int nk; // number of keys? |
102 | if ( useLargeKeys ) { | 102 | if ( useLargeKeys ) { |
103 | nk = 15; | 103 | nk = 15; |
104 | } else { | 104 | } else { |
105 | nk = 19; | 105 | nk = 19; |
106 | } | 106 | } |
107 | defaultKeyWidth = (width()/nk)/2; | 107 | defaultKeyWidth = (width()/nk)/2; |
108 | xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces? | 108 | xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces? |
109 | 109 | ||
110 | } | 110 | } |
111 | 111 | ||
112 | /* KeyboardPicks::initialize {{{1 */ | 112 | /* KeyboardPicks::initialize {{{1 */ |
113 | void KeyboardPicks::initialise() | 113 | void KeyboardPicks::initialise() |
114 | { | 114 | { |
115 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); | 115 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); |
116 | mode = 0; | 116 | mode = 0; |
117 | dc = new KeyboardConfig(this); | 117 | dc = new KeyboardConfig(this); |
118 | configs.append(dc); | 118 | configs.append(dc); |
119 | } | 119 | } |
120 | 120 | ||
121 | /* KeyboardPicks::sizeHint {{{1 */ | 121 | /* KeyboardPicks::sizeHint {{{1 */ |
122 | QSize KeyboardPicks::sizeHint() const | 122 | QSize KeyboardPicks::sizeHint() const |
123 | { | 123 | { |
124 | return QSize(240,fontMetrics().lineSpacing()); | 124 | return QSize(240,fontMetrics().lineSpacing()); |
125 | } | 125 | } |
126 | 126 | ||
127 | 127 | ||
128 | /* KeyboardConfig::generateText {{{1 */ | 128 | /* KeyboardConfig::generateText {{{1 */ |
129 | void KeyboardConfig::generateText(const QString &s) | 129 | void KeyboardConfig::generateText(const QString &s) |
130 | { | 130 | { |
131 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 131 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
132 | for (int i=0; i<(int)backspaces; i++) { | 132 | for (int i=0; i<(int)backspaces; i++) { |
133 | parent->emitKey( 0, Qt::Key_Backspace, 0, true, false ); | 133 | parent->emitKey( 0, Qt::Key_Backspace, 0, true, false ); |
134 | parent->emitKey( 0, Qt::Key_Backspace, 0, false, false ); | 134 | parent->emitKey( 0, Qt::Key_Backspace, 0, false, false ); |
135 | } | 135 | } |
136 | for (int i=0; i<(int)s.length(); i++) { | 136 | for (int i=0; i<(int)s.length(); i++) { |
137 | parent->emitKey( s[i].unicode(), 0, 0, true, false ); | 137 | parent->emitKey( s[i].unicode(), 0, 0, true, false ); |
138 | parent->emitKey( s[i].unicode(), 0, 0, false, false ); | 138 | parent->emitKey( s[i].unicode(), 0, 0, false, false ); |
139 | } | 139 | } |
140 | parent->emitKey( 0, Qt::Key_Space, 0, true, false ); | 140 | parent->emitKey( 0, Qt::Key_Space, 0, true, false ); |
141 | parent->emitKey( 0, Qt::Key_Space, 0, false, false ); | 141 | parent->emitKey( 0, Qt::Key_Space, 0, false, false ); |
142 | backspaces = 0; | 142 | backspaces = 0; |
143 | #endif | 143 | #endif |
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | 147 | ||
148 | 148 | ||
149 | /* Keyboard::paintEvent {{{1 */ | 149 | /* Keyboard::paintEvent {{{1 */ |
150 | void Keyboard::paintEvent(QPaintEvent* e) | 150 | void Keyboard::paintEvent(QPaintEvent* e) |
151 | { | 151 | { |
152 | QPainter painter(this); | 152 | QPainter painter(this); |
153 | painter.setClipRect(e->rect()); | 153 | painter.setClipRect(e->rect()); |
154 | drawKeyboard( painter ); | 154 | drawKeyboard( painter ); |
155 | picks->dc->draw( &painter ); | 155 | picks->dc->draw( &painter ); |
156 | } | 156 | } |
157 | 157 | ||
158 | 158 | ||
159 | /* Keyboard::drawKeyboard {{{1 */ | 159 | /* Keyboard::drawKeyboard {{{1 */ |
160 | 160 | ||
161 | void Keyboard::drawKeyboard(QPainter &p, int row, int col) | 161 | void Keyboard::drawKeyboard(QPainter &p, int row, int col) |
162 | { | 162 | { |
163 | 163 | ||
164 | 164 | ||
165 | if (row != -1 && col != -1) { //just redraw one key | 165 | if (row != -1 && col != -1) { //just redraw one key |
166 | 166 | ||
167 | int x = 0; | 167 | int x = 0; |
168 | for (int i = 0; i < col; i++) { | 168 | for (int i = 0; i < col; i++) { |
169 | 169 | ||
170 | x += keys->width(row, i) * defaultKeyWidth; | 170 | x += keys->width(row, i) * defaultKeyWidth; |
171 | } | 171 | } |
172 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); | 172 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); |
173 | 173 | ||
174 | int keyWidth = keys->width(row, col); | 174 | int keyWidth = keys->width(row, col); |
175 | 175 | ||
176 | p.fillRect(x + 1, y + 1, | 176 | p.fillRect(x + 1, y + 1, |
177 | keyWidth * defaultKeyWidth - 1, keyHeight - 1, | 177 | keyWidth * defaultKeyWidth - 1, keyHeight - 1, |
178 | pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor); | 178 | pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor); |
179 | 179 | ||
180 | QPixmap *pix = keys->pix(row,col); | 180 | QPixmap *pix = keys->pix(row,col); |
181 | 181 | ||
182 | ushort c = keys->uni(row, col); | 182 | ushort c = keys->uni(row, col); |
183 | 183 | ||
184 | p.setPen(textcolor); | 184 | p.setPen(textcolor); |
185 | if (!pix) | 185 | if (!pix) |
186 | p.drawText(x, y, | 186 | p.drawText(x, y, |
187 | defaultKeyWidth * keyWidth, keyHeight, | 187 | defaultKeyWidth * keyWidth, keyHeight, |
188 | AlignCenter, ((shift || lock) && keys->shift(c)) ? (QChar)keys->shift(c) : (QChar)c); | 188 | AlignCenter, ((shift || lock) && keys->shift(c)) ? (QChar)keys->shift(c) : (QChar)c); |
189 | else | 189 | else |
190 | // center the image in the middle of the key | 190 | // center the image in the middle of the key |
191 | p.drawPixmap( x + (defaultKeyWidth * keyWidth - pix->width())/2, | 191 | p.drawPixmap( x + (defaultKeyWidth * keyWidth - pix->width())/2, |
192 | y + (keyHeight - pix->height())/2 + 1, | 192 | y + (keyHeight - pix->height())/2 + 1, |
193 | *pix ); | 193 | *pix ); |
194 | 194 | ||
195 | // this fixes the problem that the very right end of the board's vertical line | 195 | // this fixes the problem that the very right end of the board's vertical line |
196 | // gets painted over, because it's one pixel shorter than all other keys | 196 | // gets painted over, because it's one pixel shorter than all other keys |
197 | p.setPen(keycolor_lines); | 197 | p.setPen(keycolor_lines); |
198 | p.drawLine(width() - 1, 0, width() - 1, height()); | 198 | p.drawLine(width() - 1, 0, width() - 1, height()); |
199 | 199 | ||
200 | } else { | 200 | } else { |
201 | 201 | ||
202 | 202 | ||
203 | p.fillRect(0, 0, width(), height(), keycolor); | 203 | p.fillRect(0, 0, width(), height(), keycolor); |
204 | 204 | ||
205 | for (row = 1; row <= 5; row++) { | 205 | for (row = 1; row <= 5; row++) { |
206 | 206 | ||
207 | int x = 0; | 207 | int x = 0; |
208 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); | 208 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); |
209 | 209 | ||
210 | p.setPen(keycolor_lines); | 210 | p.setPen(keycolor_lines); |
211 | p.drawLine(x, y, x + width(), y); | 211 | p.drawLine(x, y, x + width(), y); |
212 | 212 | ||
213 | for (int col = 0; col < keys->numKeys(row); col++) { | 213 | for (int col = 0; col < keys->numKeys(row); col++) { |
214 | 214 | ||
215 | QPixmap *pix = keys->pix(row, col); | 215 | QPixmap *pix = keys->pix(row, col); |
216 | int keyWidth = keys->width(row, col); | 216 | int keyWidth = keys->width(row, col); |
217 | 217 | ||
218 | 218 | ||
219 | int keyWidthPix = defaultKeyWidth * keyWidth; | 219 | int keyWidthPix = defaultKeyWidth * keyWidth; |
220 | 220 | ||
221 | if (keys->pressed(row, col)) | 221 | if (keys->pressed(row, col)) |
222 | p.fillRect(x+1, y+1, keyWidthPix - 1, | 222 | p.fillRect(x+1, y+1, keyWidthPix - 1, |
223 | keyHeight - 1, keycolor_pressed); | 223 | keyHeight - 1, keycolor_pressed); |
224 | 224 | ||
225 | ushort c = keys->uni(row, col); | 225 | ushort c = keys->uni(row, col); |
226 | 226 | ||
227 | if (!pix) { | 227 | if (!pix) { |
228 | p.setPen(textcolor); | 228 | p.setPen(textcolor); |
229 | p.drawText(x, y, | 229 | p.drawText(x, y, |
230 | keyWidthPix, keyHeight, | 230 | keyWidthPix, keyHeight, |
231 | AlignCenter, ((shift || lock) && keys->shift(c)) ? (QChar)keys->shift(c) : (QChar)c); | 231 | AlignCenter, ((shift || lock) && keys->shift(c)) ? (QChar)keys->shift(c) : (QChar)c); |
232 | } | 232 | } |
233 | else { | 233 | else { |
234 | // center the image in the middle of the key | 234 | // center the image in the middle of the key |
235 | p.drawPixmap( x + (keyWidthPix - pix->width())/2, | 235 | p.drawPixmap( x + (keyWidthPix - pix->width())/2, |
236 | y + (keyHeight - pix->height())/2 + 1, | 236 | y + (keyHeight - pix->height())/2 + 1, |
237 | QPixmap(*pix) ); | 237 | QPixmap(*pix) ); |
238 | } | 238 | } |
239 | 239 | ||
240 | p.setPen(keycolor_lines); | 240 | p.setPen(keycolor_lines); |
241 | p.drawLine(x, y, x, y + keyHeight); | 241 | p.drawLine(x, y, x, y + keyHeight); |
242 | 242 | ||
243 | x += keyWidthPix; | 243 | x += keyWidthPix; |
244 | } | 244 | } |
245 | 245 | ||
246 | 246 | ||
247 | } | 247 | } |
248 | p.drawLine(0, height() - 1, width(), height() - 1); | 248 | p.drawLine(0, height() - 1, width(), height() - 1); |
249 | p.drawLine(width() - 1, 0, width() - 1, height()); | 249 | p.drawLine(width() - 1, 0, width() - 1, height()); |
250 | } | 250 | } |
251 | 251 | ||
252 | } | 252 | } |
253 | 253 | ||
254 | 254 | ||
255 | /* Keyboard::mousePressEvent {{{1 */ | 255 | /* Keyboard::mousePressEvent {{{1 */ |
256 | void Keyboard::mousePressEvent(QMouseEvent *e) | 256 | void Keyboard::mousePressEvent(QMouseEvent *e) |
257 | { | 257 | { |
258 | int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1; | 258 | int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1; |
259 | if (row > 5) row = 5; | 259 | if (row > 5) row = 5; |
260 | 260 | ||
261 | // figure out the column | 261 | // figure out the column |
262 | int col = 0; | 262 | int col = 0; |
263 | for (int w = 0; e->x() >= w; col++) | 263 | for (int w = 0; e->x() >= w; col++) |
264 | if (col < keys->numKeys(row)) // it segfaults if it trys to read past numKeys | 264 | if (col < keys->numKeys(row)) // it segfaults if it trys to read past numKeys |
265 | w += keys->width(row,col) * defaultKeyWidth; | 265 | w += keys->width(row,col) * defaultKeyWidth; |
266 | else break; | 266 | else break; |
267 | 267 | ||
268 | col --; // rewind one... | 268 | col --; // rewind one... |
269 | 269 | ||
270 | qkeycode = keys->qcode(row, col); | 270 | qkeycode = keys->qcode(row, col); |
271 | unicode = keys->uni(row, col); | 271 | unicode = keys->uni(row, col); |
272 | 272 | ||
273 | // might need to repaint if two or more of the same keys. | 273 | // might need to repaint if two or more of the same keys. |
274 | // should be faster if just paint one key even though multiple keys exist. | 274 | // should be faster if just paint one key even though multiple keys exist. |
275 | bool need_repaint = FALSE; | 275 | bool need_repaint = FALSE; |
276 | 276 | ||
277 | if (unicode == 0) { // either Qt char, or nothing | 277 | if (unicode == 0) { // either Qt char, or nothing |
278 | 278 | ||
279 | if (qkeycode == Qt::Key_F1) { // toggle the pickboard | 279 | if (qkeycode == Qt::Key_F1) { // toggle the pickboard |
280 | 280 | ||
281 | if ( configdlg ) { | 281 | if ( configdlg ) { |
282 | delete (ConfigDlg *) configdlg; | 282 | delete (ConfigDlg *) configdlg; |
283 | configdlg = 0; | 283 | configdlg = 0; |
284 | } | 284 | } |
285 | else { | 285 | else { |
286 | configdlg = new ConfigDlg (); | 286 | configdlg = new ConfigDlg (); |
287 | connect(configdlg, SIGNAL(setMapToDefault()), | 287 | connect(configdlg, SIGNAL(setMapToDefault()), |
288 | this, SLOT(setMapToDefault())); | 288 | this, SLOT(setMapToDefault())); |
289 | connect(configdlg, SIGNAL(setMapToFile(QString)), | 289 | connect(configdlg, SIGNAL(setMapToFile(QString)), |
290 | this, SLOT(setMapToFile(QString))); | 290 | this, SLOT(setMapToFile(QString))); |
291 | connect(configdlg, SIGNAL(pickboardToggled(bool)), | 291 | connect(configdlg, SIGNAL(pickboardToggled(bool)), |
292 | this, SLOT(togglePickboard(bool))); | 292 | this, SLOT(togglePickboard(bool))); |
293 | connect(configdlg, SIGNAL(repeatToggled(bool)), | 293 | connect(configdlg, SIGNAL(repeatToggled(bool)), |
294 | this, SLOT(toggleRepeat(bool))); | 294 | this, SLOT(toggleRepeat(bool))); |
295 | connect(configdlg, SIGNAL(reloadKeyboard()), | 295 | connect(configdlg, SIGNAL(reloadKeyboard()), |
296 | this, SLOT(reloadKeyboard())); | 296 | this, SLOT(reloadKeyboard())); |
297 | configdlg->showMaximized(); | 297 | configdlg->showMaximized(); |
298 | configdlg->show(); | 298 | configdlg->show(); |
299 | configdlg->raise(); | 299 | configdlg->raise(); |
300 | } | 300 | } |
301 | 301 | ||
302 | } else if (qkeycode == Qt::Key_Control) { | 302 | } else if (qkeycode == Qt::Key_Control) { |
303 | ctrl = keys->pressedPtr(row, col); | 303 | ctrl = keys->pressedPtr(row, col); |
304 | need_repaint = TRUE; | 304 | need_repaint = TRUE; |
305 | *ctrl = !keys->pressed(row, col); | 305 | *ctrl = !keys->pressed(row, col); |
306 | 306 | ||
307 | } else if (qkeycode == Qt::Key_Alt) { | 307 | } else if (qkeycode == Qt::Key_Alt) { |
308 | alt = keys->pressedPtr(row, col); | 308 | alt = keys->pressedPtr(row, col); |
309 | need_repaint = TRUE; | 309 | need_repaint = TRUE; |
310 | *alt = !keys->pressed(row, col); | 310 | *alt = !keys->pressed(row, col); |
311 | 311 | ||
312 | } else if (qkeycode == Qt::Key_Shift) { | 312 | } else if (qkeycode == Qt::Key_Shift) { |
313 | need_repaint = TRUE; | 313 | need_repaint = TRUE; |
314 | 314 | ||
315 | if (shift) { | 315 | if (shift) { |
316 | *shift = 0; | 316 | *shift = 0; |
317 | shift = 0; | 317 | shift = 0; |
318 | } | 318 | } |
319 | else { | 319 | else { |
320 | shift = keys->pressedPtr(row, col); | 320 | shift = keys->pressedPtr(row, col); |
321 | *shift = 1; | 321 | *shift = 1; |
322 | if (lock) { | 322 | if (lock) { |
323 | *lock = 0; | 323 | *lock = 0; |
324 | lock = 0; | 324 | lock = 0; |
325 | } | 325 | } |
326 | } | 326 | } |
327 | 327 | ||
328 | } else if (qkeycode == Qt::Key_CapsLock) { | 328 | } else if (qkeycode == Qt::Key_CapsLock) { |
329 | need_repaint = TRUE; | 329 | need_repaint = TRUE; |
330 | 330 | ||
331 | if (lock) { | 331 | if (lock) { |
332 | *lock = 0; | 332 | *lock = 0; |
333 | lock = 0; | 333 | lock = 0; |
334 | } | 334 | } |
335 | else { | 335 | else { |
336 | lock = keys->pressedPtr(row, col);; | 336 | lock = keys->pressedPtr(row, col);; |
337 | *lock = 1; | 337 | *lock = 1; |
338 | if (shift) { | 338 | if (shift) { |
339 | *shift = 0; | 339 | *shift = 0; |
340 | shift = 0; | 340 | shift = 0; |
341 | } | 341 | } |
342 | } | 342 | } |
343 | 343 | ||
344 | } | 344 | } |
345 | 345 | ||
346 | } | 346 | } |
347 | else { // normal char | 347 | else { // normal char |
348 | if ((shift || lock) && keys->shift(unicode)) { | 348 | if ((shift || lock) && keys->shift(unicode)) { |
349 | unicode = keys->shift(unicode); | 349 | unicode = keys->shift(unicode); |
350 | } | 350 | } |
351 | } | 351 | } |
352 | 352 | ||
353 | // korean parsing | 353 | // korean parsing |
354 | if (keys->lang == "ko") { | 354 | if (keys->lang == "ko") { |
355 | 355 | ||
356 | unicode = parseKoreanInput(unicode); | 356 | unicode = parseKoreanInput(unicode); |
357 | } | 357 | } |
358 | 358 | ||
359 | modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0); | 359 | modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0); |
360 | 360 | ||
361 | emit key(unicode, qkeycode, modifiers, true, false); | 361 | if ('A' <= unicode && unicode <= 'z' && modifiers) { |
362 | |||
363 | qkeycode = QChar(unicode).upper(); | ||
364 | unicode = qkeycode - '@'; | ||
365 | } | ||
366 | |||
367 | QWSServer::sendKeyEvent(unicode, qkeycode, modifiers, true, false); | ||
362 | 368 | ||
363 | // pickboard stuff | 369 | // pickboard stuff |
364 | if (usePicks) { | 370 | if (usePicks) { |
365 | 371 | ||
366 | KeyboardConfig *dc = picks->dc; | 372 | KeyboardConfig *dc = picks->dc; |
367 | 373 | ||
368 | if (dc) { | 374 | if (dc) { |
369 | if (qkeycode == Qt::Key_Backspace) { | 375 | if (qkeycode == Qt::Key_Backspace) { |
370 | dc->input.remove(dc->input.last()); // remove last input | 376 | dc->input.remove(dc->input.last()); // remove last input |
371 | dc->decBackspaces(); | 377 | dc->decBackspaces(); |
372 | } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) { | 378 | } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) { |
373 | dc->input.clear(); | 379 | dc->input.clear(); |
374 | dc->resetBackspaces(); | 380 | dc->resetBackspaces(); |
375 | } else { | 381 | } else { |
376 | dc->add(QString(QChar(unicode))); | 382 | dc->add(QString(QChar(unicode))); |
377 | dc->incBackspaces(); | 383 | dc->incBackspaces(); |
378 | } | 384 | } |
379 | } | 385 | } |
380 | picks->repaint(); | 386 | picks->repaint(); |
381 | } | 387 | } |
382 | 388 | ||
383 | 389 | ||
384 | // painting | 390 | // painting |
385 | pressed = TRUE; | 391 | pressed = TRUE; |
386 | 392 | ||
387 | pressedKeyRow = row; | 393 | pressedKeyRow = row; |
388 | pressedKeyCol = col; | 394 | pressedKeyCol = col; |
389 | 395 | ||
390 | if (need_repaint) repaint(FALSE); | 396 | if (need_repaint) repaint(FALSE); |
391 | else { // just paint the one key pressed | 397 | else { // just paint the one key pressed |
392 | 398 | ||
393 | 399 | ||
394 | 400 | ||
395 | QPainter p(this); | 401 | QPainter p(this); |
396 | drawKeyboard(p, row, col); | 402 | drawKeyboard(p, row, col); |
397 | 403 | ||
398 | } | 404 | } |
399 | 405 | ||
400 | if (useRepeat) repeatTimer->start( 800 ); | 406 | if (useRepeat) repeatTimer->start( 800 ); |
401 | //pressTid = startTimer(80); | 407 | //pressTid = startTimer(80); |
402 | 408 | ||
403 | } | 409 | } |
404 | 410 | ||
405 | 411 | ||
406 | /* Keyboard::mouseReleaseEvent {{{1 */ | 412 | /* Keyboard::mouseReleaseEvent {{{1 */ |
407 | void Keyboard::mouseReleaseEvent(QMouseEvent*) | 413 | void Keyboard::mouseReleaseEvent(QMouseEvent*) |
408 | { | 414 | { |
409 | pressed = FALSE; | 415 | pressed = FALSE; |
410 | //if ( pressTid == 0 ) | 416 | //if ( pressTid == 0 ) |
411 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 417 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
412 | if ( unicode != -1 ) { | 418 | if ( unicode != -1 ) { |
413 | emit key( unicode, qkeycode, modifiers, false, false ); | 419 | emit key( unicode, qkeycode, modifiers, false, false ); |
414 | repeatTimer->stop(); | 420 | repeatTimer->stop(); |
415 | } | 421 | } |
416 | #endif | 422 | #endif |
417 | if (shift && unicode != 0) { | 423 | if (shift && unicode != 0) { |
418 | 424 | ||
419 | 425 | ||
420 | *shift = 0; // unpress shift key | 426 | *shift = 0; // unpress shift key |
421 | shift = 0; // reset the shift pointer | 427 | shift = 0; // reset the shift pointer |
422 | repaint(FALSE); | 428 | repaint(FALSE); |
423 | 429 | ||
424 | } | 430 | } |
425 | else | 431 | else |
426 | 432 | ||
427 | clearHighlight(); | 433 | clearHighlight(); |
428 | } | 434 | } |
429 | 435 | ||
430 | /* Keyboard::timerEvent {{{1 */ | 436 | /* Keyboard::timerEvent {{{1 */ |
431 | 437 | ||
432 | /* dont know what this does, but i think it is here so that if your screen | 438 | /* dont know what this does, but i think it is here so that if your screen |
433 | * sticks (like on an ipaq) then it will stop repeating if you click another | 439 | * sticks (like on an ipaq) then it will stop repeating if you click another |
434 | * key... but who knows what anything does in this thing anyway? | 440 | * key... but who knows what anything does in this thing anyway? |
435 | 441 | ||
436 | void Keyboard::timerEvent(QTimerEvent* e) | 442 | void Keyboard::timerEvent(QTimerEvent* e) |
437 | { | 443 | { |
438 | if ( e->timerId() == pressTid ) { | 444 | if ( e->timerId() == pressTid ) { |
439 | killTimer(pressTid); | 445 | killTimer(pressTid); |
440 | pressTid = 0; | 446 | pressTid = 0; |
441 | if ( !pressed ) | 447 | if ( !pressed ) |
442 | cout << "calling clearHighlight from timerEvent\n"; | 448 | cout << "calling clearHighlight from timerEvent\n"; |
443 | //clearHighlight(); | 449 | //clearHighlight(); |
444 | } | 450 | } |
445 | } | 451 | } |
446 | */ | 452 | */ |
447 | 453 | ||
448 | void Keyboard::repeat() | 454 | void Keyboard::repeat() |
449 | { | 455 | { |
450 | 456 | ||
451 | repeatTimer->start( 200 ); | 457 | repeatTimer->start( 200 ); |
452 | emit key( unicode, qkeycode, modifiers, true, true ); | 458 | emit key( unicode, qkeycode, modifiers, true, true ); |
453 | } | 459 | } |
454 | 460 | ||
455 | void Keyboard::clearHighlight() | 461 | void Keyboard::clearHighlight() |
456 | { | 462 | { |
457 | if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) { | 463 | if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) { |
458 | int tmpRow = pressedKeyRow; | 464 | int tmpRow = pressedKeyRow; |
459 | int tmpCol = pressedKeyCol; | 465 | int tmpCol = pressedKeyCol; |
460 | 466 | ||
461 | pressedKeyRow = -1; | 467 | pressedKeyRow = -1; |
462 | pressedKeyCol = -1; | 468 | pressedKeyCol = -1; |
463 | 469 | ||
464 | QPainter p(this); | 470 | QPainter p(this); |
465 | drawKeyboard(p, tmpRow, tmpCol); | 471 | drawKeyboard(p, tmpRow, tmpCol); |
466 | } | 472 | } |
467 | } | 473 | } |
468 | 474 | ||
469 | 475 | ||
470 | /* Keyboard::sizeHint {{{1 */ | 476 | /* Keyboard::sizeHint {{{1 */ |
471 | QSize Keyboard::sizeHint() const | 477 | QSize Keyboard::sizeHint() const |
472 | { | 478 | { |
473 | QFontMetrics fm=fontMetrics(); | 479 | QFontMetrics fm=fontMetrics(); |
474 | int keyHeight = fm.lineSpacing() + 2; | 480 | int keyHeight = fm.lineSpacing() + 2; |
475 | 481 | ||
476 | return QSize( 240, keyHeight * 5 + (usePicks ? picks->sizeHint().height() : 0) + 1); | 482 | return QSize( 240, keyHeight * 5 + (usePicks ? picks->sizeHint().height() : 0) + 1); |
477 | } | 483 | } |
478 | 484 | ||
479 | 485 | ||
480 | void Keyboard::resetState() | 486 | void Keyboard::resetState() |
481 | { | 487 | { |
482 | schar = mchar = echar = 0; | 488 | schar = mchar = echar = 0; |
483 | picks->resetState(); | 489 | picks->resetState(); |
484 | } | 490 | } |
485 | 491 | ||
486 | /* Keyboard::togglePickboard {{{1 */ | 492 | /* Keyboard::togglePickboard {{{1 */ |
487 | void Keyboard::togglePickboard(bool on_off) | 493 | void Keyboard::togglePickboard(bool on_off) |
488 | { | 494 | { |
489 | usePicks = on_off; | 495 | usePicks = on_off; |
490 | if (usePicks) { | 496 | if (usePicks) { |
491 | picks->show(); | 497 | picks->show(); |
492 | //move(x(), y() - picks->height()); // not required anymore because QCopChannel::send | 498 | //move(x(), y() - picks->height()); // not required anymore because QCopChannel::send |
493 | //adjustSize(); | 499 | //adjustSize(); |
494 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), | 500 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), |
495 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); | 501 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); |
496 | } else { | 502 | } else { |
497 | 503 | ||
498 | picks->hide(); | 504 | picks->hide(); |
499 | picks->resetState(); | 505 | picks->resetState(); |
500 | //move(x(), y() + picks->height()); | 506 | //move(x(), y() + picks->height()); |
501 | //adjustSize(); | 507 | //adjustSize(); |
502 | QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), | 508 | QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), |
503 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); | 509 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); |
504 | 510 | ||
505 | } | 511 | } |
506 | /* | 512 | /* |
507 | * this closes && opens the input method | 513 | * this closes && opens the input method |
508 | */ | 514 | */ |
509 | QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); | 515 | QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); |
510 | QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); | 516 | QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); |
511 | } | 517 | } |
512 | 518 | ||
513 | void Keyboard::toggleRepeat(bool on) { | 519 | void Keyboard::toggleRepeat(bool on) { |
514 | 520 | ||
515 | useRepeat = on; | 521 | useRepeat = on; |
516 | cout << "setting useRepeat to: " << useRepeat << "\n"; | 522 | cout << "setting useRepeat to: " << useRepeat << "\n"; |
517 | } | 523 | } |
518 | 524 | ||
519 | /* Keyboard::setMapTo ... {{{1 */ | 525 | /* Keyboard::setMapTo ... {{{1 */ |
520 | void Keyboard::setMapToDefault() { | 526 | void Keyboard::setMapToDefault() { |
521 | 527 | ||
522 | 528 | ||
523 | /* load current locale language map */ | 529 | /* load current locale language map */ |
524 | Config *config = new Config("locale"); | 530 | Config *config = new Config("locale"); |
525 | config->setGroup( "Language" ); | 531 | config->setGroup( "Language" ); |
526 | QString l = config->readEntry( "Language" , "en" ); | 532 | QString l = config->readEntry( "Language" , "en" ); |
527 | delete config; | 533 | delete config; |
528 | 534 | ||
529 | QString key_map = QPEApplication::qpeDir() + "/share/multikey/" | 535 | QString key_map = QPEApplication::qpeDir() + "/share/multikey/" |
530 | + l + ".keymap"; | 536 | + l + ".keymap"; |
531 | 537 | ||
532 | /* save change to multikey config file */ | 538 | /* save change to multikey config file */ |
533 | config = new Config("multikey"); | 539 | config = new Config("multikey"); |
534 | config->setGroup ("keymaps"); | 540 | config->setGroup ("keymaps"); |
535 | config->writeEntry ("current", key_map); // default closed | 541 | config->writeEntry ("current", key_map); // default closed |
536 | delete config; | 542 | delete config; |
537 | 543 | ||
538 | delete keys; | 544 | delete keys; |
539 | keys = new Keys(key_map); | 545 | keys = new Keys(key_map); |
540 | 546 | ||
541 | // have to repaint the keyboard | 547 | // have to repaint the keyboard |
542 | repaint(FALSE); | 548 | repaint(FALSE); |
543 | } | 549 | } |
544 | 550 | ||
545 | void Keyboard::setMapToFile(QString map) { | 551 | void Keyboard::setMapToFile(QString map) { |
546 | 552 | ||
547 | /* save change to multikey config file */ | 553 | /* save change to multikey config file */ |
548 | Config *config = new Config("multikey"); | 554 | Config *config = new Config("multikey"); |
549 | config->setGroup ("keymaps"); | 555 | config->setGroup ("keymaps"); |
550 | config->writeEntry ("current", map); // default closed | 556 | config->writeEntry ("current", map); // default closed |
551 | 557 | ||
552 | delete config; | 558 | delete config; |
553 | 559 | ||
554 | delete keys; | 560 | delete keys; |
555 | if (QFile(map).exists()) | 561 | if (QFile(map).exists()) |
556 | keys = new Keys(map); | 562 | keys = new Keys(map); |
557 | else | 563 | else |
558 | keys = new Keys(); | 564 | keys = new Keys(); |
559 | 565 | ||
560 | repaint(FALSE); | 566 | repaint(FALSE); |
561 | 567 | ||
562 | } | 568 | } |
563 | 569 | ||
564 | /* Keybaord::reloadKeyboard {{{1 */ | 570 | /* Keybaord::reloadKeyboard {{{1 */ |
565 | void Keyboard::reloadKeyboard() { | 571 | void Keyboard::reloadKeyboard() { |
566 | 572 | ||
567 | // reload colors and redraw | 573 | // reload colors and redraw |
568 | loadKeyboardColors(); | 574 | loadKeyboardColors(); |
569 | repaint(); | 575 | repaint(); |
570 | 576 | ||
571 | } | 577 | } |
572 | 578 | ||
573 | void Keyboard::loadKeyboardColors() { | 579 | void Keyboard::loadKeyboardColors() { |
574 | 580 | ||
575 | Config config ("multikey"); | 581 | Config config ("multikey"); |
576 | config.setGroup("colors"); | 582 | config.setGroup("colors"); |
577 | 583 | ||
578 | QStringList color; | 584 | QStringList color; |
579 | color = config.readListEntry("keycolor", QChar(',')); | 585 | color = config.readListEntry("keycolor", QChar(',')); |
580 | if (color.isEmpty()) { | 586 | if (color.isEmpty()) { |
581 | color = QStringList::split(",", "240,240,240"); | 587 | color = QStringList::split(",", "240,240,240"); |
582 | config.writeEntry("keycolor", color.join(",")); | 588 | config.writeEntry("keycolor", color.join(",")); |
583 | 589 | ||
584 | } | 590 | } |
585 | keycolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); | 591 | keycolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); |
586 | 592 | ||
587 | color = config.readListEntry("keycolor_pressed", QChar(',')); | 593 | color = config.readListEntry("keycolor_pressed", QChar(',')); |
588 | if (color.isEmpty()) { | 594 | if (color.isEmpty()) { |
589 | color = QStringList::split(",", "171,183,198"); | 595 | color = QStringList::split(",", "171,183,198"); |
590 | config.writeEntry("keycolor_pressed", color.join(",")); | 596 | config.writeEntry("keycolor_pressed", color.join(",")); |
591 | 597 | ||
592 | } | 598 | } |
593 | keycolor_pressed = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); | 599 | keycolor_pressed = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); |
594 | 600 | ||
595 | color = config.readListEntry("keycolor_lines", QChar(',')); | 601 | color = config.readListEntry("keycolor_lines", QChar(',')); |
596 | if (color.isEmpty()) { | 602 | if (color.isEmpty()) { |
597 | color = QStringList::split(",", "138,148,160"); | 603 | color = QStringList::split(",", "138,148,160"); |
598 | config.writeEntry("keycolor_lines", color.join(",")); | 604 | config.writeEntry("keycolor_lines", color.join(",")); |
599 | 605 | ||
600 | } | 606 | } |
601 | keycolor_lines = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); | 607 | keycolor_lines = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); |
602 | 608 | ||
603 | color = config.readListEntry("textcolor", QChar(',')); | 609 | color = config.readListEntry("textcolor", QChar(',')); |
604 | if (color.isEmpty()) { | 610 | if (color.isEmpty()) { |
605 | color = QStringList::split(",", "43,54,68"); | 611 | color = QStringList::split(",", "43,54,68"); |
606 | config.writeEntry("textcolor", color.join(",")); | 612 | config.writeEntry("textcolor", color.join(",")); |
607 | 613 | ||
608 | } | 614 | } |
609 | textcolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); | 615 | textcolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); |
610 | 616 | ||
611 | } | 617 | } |
612 | 618 | ||
613 | /* korean input functions {{{1 | 619 | /* korean input functions {{{1 |
614 | * | 620 | * |
615 | * TODO | 621 | * TODO |
616 | * one major problem with this implementation is that you can't move the | 622 | * one major problem with this implementation is that you can't move the |
617 | * cursor after inputing korean chars, otherwise it will eat up and replace | 623 | * cursor after inputing korean chars, otherwise it will eat up and replace |
618 | * the char before the cursor you move to. fix that | 624 | * the char before the cursor you move to. fix that |
619 | * | 625 | * |
620 | * make backspace delete one single char, not the whole thing if still | 626 | * make backspace delete one single char, not the whole thing if still |
621 | * editing. | 627 | * editing. |
622 | * | 628 | * |
623 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | 629 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
624 | * | 630 | * |
625 | * how korean input works | 631 | * how korean input works |
626 | * | 632 | * |
627 | * all following chars means unicode char value and are in hex | 633 | * all following chars means unicode char value and are in hex |
628 | * | 634 | * |
629 | * ÃÊÀ½ = schar (start char) | 635 | * ÃÊÀ½ = schar (start char) |
630 | * ÁßÀ½ = mchar (middle char) | 636 | * ÁßÀ½ = mchar (middle char) |
631 | * ³¡À½ = echar (end char) | 637 | * ³¡À½ = echar (end char) |
632 | * | 638 | * |
633 | * there are 19 schars. unicode position is at 1100 - 1112 | 639 | * there are 19 schars. unicode position is at 1100 - 1112 |
634 | * there are 21 mchars. unicode position is at 1161 - 1175 | 640 | * there are 21 mchars. unicode position is at 1161 - 1175 |
635 | * there are 27 echars. unicode position is at 11a8 - 11c2 | 641 | * there are 27 echars. unicode position is at 11a8 - 11c2 |
636 | * | 642 | * |
637 | * the map with everything combined is at ac00 - d7a3 | 643 | * the map with everything combined is at ac00 - d7a3 |
638 | * | 644 | * |
639 | */ | 645 | */ |
640 | 646 | ||
641 | ushort Keyboard::parseKoreanInput (ushort c) { | 647 | ushort Keyboard::parseKoreanInput (ushort c) { |
642 | 648 | ||
643 | if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c)) | 649 | if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c)) |
644 | || | 650 | || |
645 | (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode | 651 | (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode |
646 | && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) { | 652 | && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) { |
647 | 653 | ||
648 | schar = 0, mchar = 0, echar = 0; | 654 | schar = 0, mchar = 0, echar = 0; |
649 | return c; | 655 | return c; |
650 | } | 656 | } |
651 | 657 | ||
652 | if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input | 658 | if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input |
653 | 659 | ||
654 | if (schar == 0 || (schar != 0 && mchar == 0)) { | 660 | if (schar == 0 || (schar != 0 && mchar == 0)) { |
655 | schar = c; mchar = 0; echar = 0; | 661 | schar = c; mchar = 0; echar = 0; |
656 | return c; | 662 | return c; |
657 | } | 663 | } |
658 | else if (mchar != 0) { | 664 | else if (mchar != 0) { |
659 | 665 | ||
660 | if (echar == 0) { | 666 | if (echar == 0) { |
661 | 667 | ||
662 | if (!(echar = constoe(c))) { | 668 | if (!(echar = constoe(c))) { |
663 | 669 | ||
664 | schar = c; mchar = 0; echar = 0; | 670 | schar = c; mchar = 0; echar = 0; |
665 | return c; | 671 | return c; |
666 | } | 672 | } |
667 | 673 | ||
668 | } | 674 | } |
669 | else { // must figure out what the echar is | 675 | else { // must figure out what the echar is |
670 | 676 | ||
671 | if (echar == 0x11a8) { // ¤¡ | 677 | if (echar == 0x11a8) { // ¤¡ |
672 | 678 | ||
673 | if (c == 0x1100) echar = 0x11a9; // ¤¡ + ¤¡ | 679 | if (c == 0x1100) echar = 0x11a9; // ¤¡ + ¤¡ |
674 | else if (c == 0x1109) echar = 0x11aa; // ¤¡ + ¤µ | 680 | else if (c == 0x1109) echar = 0x11aa; // ¤¡ + ¤µ |
675 | else { | 681 | else { |
676 | schar = c; mchar = 0; echar = 0; | 682 | schar = c; mchar = 0; echar = 0; |
677 | return c; | 683 | return c; |
678 | } | 684 | } |
679 | 685 | ||
680 | } else if (echar == 0x11ab) { // ¤¤ | 686 | } else if (echar == 0x11ab) { // ¤¤ |
681 | 687 | ||
682 | if (c == 0x110c) echar = 0x11ac; // ¤¤ + ¤¸ | 688 | if (c == 0x110c) echar = 0x11ac; // ¤¤ + ¤¸ |
683 | else if (c == 0x1112) echar = 0x11ad; // ¤¤ + ¤¾ | 689 | else if (c == 0x1112) echar = 0x11ad; // ¤¤ + ¤¾ |
684 | else { | 690 | else { |
685 | schar = c; mchar = 0; echar = 0; | 691 | schar = c; mchar = 0; echar = 0; |
686 | return c; | 692 | return c; |
687 | } | 693 | } |
688 | 694 | ||
689 | } else if (echar == 0x11af) { // ¤© | 695 | } else if (echar == 0x11af) { // ¤© |
690 | 696 | ||
691 | if (c == 0x1100) echar = 0x11b0; // ¤© + ¤¡ | 697 | if (c == 0x1100) echar = 0x11b0; // ¤© + ¤¡ |
692 | else if (c == 0x1106) echar = 0x11b1; // ¤© + ¤± | 698 | else if (c == 0x1106) echar = 0x11b1; // ¤© + ¤± |
693 | else if (c == 0x1107) echar = 0x11b2; // ¤© + ¤² | 699 | else if (c == 0x1107) echar = 0x11b2; // ¤© + ¤² |
694 | else if (c == 0x1109) echar = 0x11b3; // ¤© + ¤µ | 700 | else if (c == 0x1109) echar = 0x11b3; // ¤© + ¤µ |
695 | else if (c == 0x1110) echar = 0x11b4; // ¤© + ¤¼ | 701 | else if (c == 0x1110) echar = 0x11b4; // ¤© + ¤¼ |
696 | else if (c == 0x1111) echar = 0x11b5; // ¤© + ¤½ | 702 | else if (c == 0x1111) echar = 0x11b5; // ¤© + ¤½ |
697 | else if (c == 0x1112) echar = 0x11b6; // ¤© + ¤¾ | 703 | else if (c == 0x1112) echar = 0x11b6; // ¤© + ¤¾ |
698 | else { | 704 | else { |
699 | schar = c; mchar = 0; echar = 0; | 705 | schar = c; mchar = 0; echar = 0; |
700 | return c; | 706 | return c; |
701 | } | 707 | } |
702 | 708 | ||
703 | } else if (echar == 0x11b8) { // ¤² | 709 | } else if (echar == 0x11b8) { // ¤² |
704 | 710 | ||
705 | if (c == 0x1109) echar = 0x11b9; // ¤² + ¤µ | 711 | if (c == 0x1109) echar = 0x11b9; // ¤² + ¤µ |
706 | else { | 712 | else { |
707 | schar = c; mchar = 0; echar = 0; | 713 | schar = c; mchar = 0; echar = 0; |
708 | return c; | 714 | return c; |
709 | } | 715 | } |
710 | 716 | ||
711 | } else if (echar == 0x11ba) { // ¤µ | 717 | } else if (echar == 0x11ba) { // ¤µ |
712 | 718 | ||
713 | if (c == 0x1109) echar = 0x11bb; // ¤µ + ¤µ | 719 | if (c == 0x1109) echar = 0x11bb; // ¤µ + ¤µ |
714 | else { | 720 | else { |
715 | schar = c; mchar = 0; echar = 0; | 721 | schar = c; mchar = 0; echar = 0; |
716 | return c; | 722 | return c; |
717 | } | 723 | } |
718 | 724 | ||
719 | } else { // if any other char, cannot combine chars | 725 | } else { // if any other char, cannot combine chars |
720 | 726 | ||
721 | schar = c; mchar = 0; echar = 0; | 727 | schar = c; mchar = 0; echar = 0; |
722 | return c; | 728 | return c; |
723 | } | 729 | } |
724 | 730 | ||
725 | unicode = echar; | 731 | unicode = echar; |
726 | } | 732 | } |
727 | } | 733 | } |
728 | 734 | ||
729 | } | 735 | } |
730 | else if (0x1161 <= c && c <= 0x1175) { // mchar was input | 736 | else if (0x1161 <= c && c <= 0x1175) { // mchar was input |
731 | 737 | ||
732 | if (schar != 0 && mchar == 0) { mchar = c; } | 738 | if (schar != 0 && mchar == 0) { mchar = c; } |
733 | 739 | ||
734 | else if (schar != 0 && mchar != 0 && echar == 0) { | 740 | else if (schar != 0 && mchar != 0 && echar == 0) { |
735 | 741 | ||
736 | switch (mchar) { | 742 | switch (mchar) { |
737 | case 0x1169: | 743 | case 0x1169: |
738 | if (c == 0x1161) mchar = 0x116a; | 744 | if (c == 0x1161) mchar = 0x116a; |
739 | else if (c == 0x1162) mchar = 0x116b; | 745 | else if (c == 0x1162) mchar = 0x116b; |
740 | else if (c == 0x1175) mchar = 0x116c; | 746 | else if (c == 0x1175) mchar = 0x116c; |
741 | else { | 747 | else { |
742 | schar = 0; mchar = 0; echar = 0; | 748 | schar = 0; mchar = 0; echar = 0; |
743 | return c; | 749 | return c; |
744 | } | 750 | } |
745 | break; | 751 | break; |
746 | case 0x116e: | 752 | case 0x116e: |
747 | if (c == 0x1165) mchar = 0x116f; | 753 | if (c == 0x1165) mchar = 0x116f; |
748 | else if (c == 0x1166) mchar = 0x1170; | 754 | else if (c == 0x1166) mchar = 0x1170; |
749 | else if (c == 0x1175) mchar = 0x1171; | 755 | else if (c == 0x1175) mchar = 0x1171; |
750 | else { | 756 | else { |
751 | schar = 0; mchar = 0; echar = 0; | 757 | schar = 0; mchar = 0; echar = 0; |
752 | return c; | 758 | return c; |
753 | } | 759 | } |
754 | break; | 760 | break; |
755 | case 0x1173: | 761 | case 0x1173: |
756 | if (c == 0x1175) mchar = 0x1174; | 762 | if (c == 0x1175) mchar = 0x1174; |
757 | else { | 763 | else { |
758 | schar = 0; mchar = 0; echar = 0; | 764 | schar = 0; mchar = 0; echar = 0; |
759 | return c; | 765 | return c; |
760 | } | 766 | } |
761 | break; | 767 | break; |
762 | default: | 768 | default: |
763 | schar = 0; mchar = 0; echar = 0; | 769 | schar = 0; mchar = 0; echar = 0; |
764 | return c; | 770 | return c; |
765 | } | 771 | } |
766 | } | 772 | } |
767 | else if (schar != 0 && mchar != 0 && echar != 0) { | 773 | else if (schar != 0 && mchar != 0 && echar != 0) { |
768 | 774 | ||
769 | emit key( 8, Qt::Key_Backspace, 0, true, false ); | 775 | emit key( 8, Qt::Key_Backspace, 0, true, false ); |
770 | 776 | ||
771 | ushort prev = 0; | 777 | ushort prev = 0; |
772 | switch (echar) { | 778 | switch (echar) { |
773 | /* | 779 | /* |
774 | case 0x11a9: | 780 | case 0x11a9: |
775 | prev = combineKoreanChars(schar, mchar, 0x11a8); | 781 | prev = combineKoreanChars(schar, mchar, 0x11a8); |
776 | schar = 0x1100; | 782 | schar = 0x1100; |
777 | break; | 783 | break; |
778 | */ | 784 | */ |
779 | case 0x11aa: | 785 | case 0x11aa: |
780 | prev = combineKoreanChars(schar, mchar, 0x11a8); | 786 | prev = combineKoreanChars(schar, mchar, 0x11a8); |
781 | schar = 0x1109; | 787 | schar = 0x1109; |
782 | break; | 788 | break; |
783 | case 0x11ac: | 789 | case 0x11ac: |
784 | prev = combineKoreanChars(schar, mchar, 0x11ab); | 790 | prev = combineKoreanChars(schar, mchar, 0x11ab); |
785 | schar = 0x110c; | 791 | schar = 0x110c; |
786 | break; | 792 | break; |
787 | case 0x11ad: | 793 | case 0x11ad: |
788 | prev = combineKoreanChars(schar, mchar, 0x11ab); | 794 | prev = combineKoreanChars(schar, mchar, 0x11ab); |
789 | schar = 0x1112; | 795 | schar = 0x1112; |
790 | break; | 796 | break; |
791 | case 0x11b0: | 797 | case 0x11b0: |
792 | prev = combineKoreanChars(schar, mchar, 0x11af); | 798 | prev = combineKoreanChars(schar, mchar, 0x11af); |
793 | schar = 0x1100; | 799 | schar = 0x1100; |
794 | break; | 800 | break; |
795 | case 0x11b1: | 801 | case 0x11b1: |
796 | prev = combineKoreanChars(schar, mchar, 0x11af); | 802 | prev = combineKoreanChars(schar, mchar, 0x11af); |
797 | schar = 0x1106; | 803 | schar = 0x1106; |
798 | break; | 804 | break; |
799 | case 0x11b2: | 805 | case 0x11b2: |
800 | prev = combineKoreanChars(schar, mchar, 0x11af); | 806 | prev = combineKoreanChars(schar, mchar, 0x11af); |
801 | schar = 0x1107; | 807 | schar = 0x1107; |
802 | break; | 808 | break; |
803 | case 0x11b3: | 809 | case 0x11b3: |
804 | prev = combineKoreanChars(schar, mchar, 0x11af); | 810 | prev = combineKoreanChars(schar, mchar, 0x11af); |
805 | schar = 0x1109; | 811 | schar = 0x1109; |
806 | break; | 812 | break; |
807 | case 0x11b4: | 813 | case 0x11b4: |
808 | prev = combineKoreanChars(schar, mchar, 0x11af); | 814 | prev = combineKoreanChars(schar, mchar, 0x11af); |
809 | schar = 0x1110; | 815 | schar = 0x1110; |
810 | break; | 816 | break; |
811 | case 0x11b9: | 817 | case 0x11b9: |
812 | prev = combineKoreanChars(schar, mchar, 0x11b8); | 818 | prev = combineKoreanChars(schar, mchar, 0x11b8); |
813 | schar = 0x1109; | 819 | schar = 0x1109; |
814 | break; | 820 | break; |
815 | /* | 821 | /* |
816 | case 0x11bb: | 822 | case 0x11bb: |
817 | prev = combineKoreanChars(schar, mchar, 0x11ba); | 823 | prev = combineKoreanChars(schar, mchar, 0x11ba); |
818 | schar = 0x1109; | 824 | schar = 0x1109; |
819 | break; | 825 | break; |
820 | */ | 826 | */ |
821 | default: | 827 | default: |
822 | 828 | ||
823 | if (constoe(echar)) { | 829 | if (constoe(echar)) { |
824 | 830 | ||
825 | prev = combineKoreanChars(schar, mchar, 0); | 831 | prev = combineKoreanChars(schar, mchar, 0); |
826 | schar = constoe(echar); | 832 | schar = constoe(echar); |
827 | } | 833 | } |
828 | break; | 834 | break; |
829 | } | 835 | } |
830 | 836 | ||
831 | emit key( prev, prev, 0, true, false ); | 837 | emit key( prev, prev, 0, true, false ); |
832 | 838 | ||
833 | mchar = c; echar = 0; | 839 | mchar = c; echar = 0; |
834 | 840 | ||
835 | return combineKoreanChars(schar, mchar, 0); | 841 | return combineKoreanChars(schar, mchar, 0); |
836 | 842 | ||
837 | } | 843 | } |
838 | else { | 844 | else { |
839 | schar = 0; mchar = 0; echar = 0; | 845 | schar = 0; mchar = 0; echar = 0; |
840 | return c; | 846 | return c; |
841 | } | 847 | } |
842 | 848 | ||
843 | } | 849 | } |
844 | else /*if (c == ' ')*/ return c; | 850 | else /*if (c == ' ')*/ return c; |
845 | 851 | ||
846 | 852 | ||
847 | // and now... finally delete previous char, and return new char | 853 | // and now... finally delete previous char, and return new char |
848 | emit key( 8, Qt::Key_Backspace, 0, true, false ); | 854 | emit key( 8, Qt::Key_Backspace, 0, true, false ); |
849 | 855 | ||
850 | 856 | ||
851 | return combineKoreanChars( schar, mchar, echar); | 857 | return combineKoreanChars( schar, mchar, echar); |
852 | 858 | ||
853 | } | 859 | } |
854 | 860 | ||
855 | ushort Keyboard::combineKoreanChars(const ushort s, const ushort m, const ushort e) { | 861 | ushort Keyboard::combineKoreanChars(const ushort s, const ushort m, const ushort e) { |
856 | 862 | ||
857 | return ((s - 0x1100) * 588) + ((m - 0x1161) * 28) + (e ? e - 0x11a7 : 0) + 0xac00; | 863 | return ((s - 0x1100) * 588) + ((m - 0x1161) * 28) + (e ? e - 0x11a7 : 0) + 0xac00; |
858 | 864 | ||
859 | } | 865 | } |
860 | 866 | ||
861 | ushort Keyboard::constoe(const ushort c) { | 867 | ushort Keyboard::constoe(const ushort c) { |
862 | 868 | ||
863 | // converts schars to echars if possible | 869 | // converts schars to echars if possible |
864 | 870 | ||
865 | if (0x1100 <= c && c <= 0x1112) { // schar to echar | 871 | if (0x1100 <= c && c <= 0x1112) { // schar to echar |
866 | 872 | ||
867 | switch (c) { | 873 | switch (c) { |
868 | case 0x1100: return 0x11a8; | 874 | case 0x1100: return 0x11a8; |
869 | case 0x1101: return 0x11a9; | 875 | case 0x1101: return 0x11a9; |
870 | case 0x1102: return 0x11ab; | 876 | case 0x1102: return 0x11ab; |
871 | case 0x1103: return 0x11ae; | 877 | case 0x1103: return 0x11ae; |
872 | case 0x1105: return 0x11af; | 878 | case 0x1105: return 0x11af; |
873 | case 0x1106: return 0x11b7; | 879 | case 0x1106: return 0x11b7; |
874 | case 0x1107: return 0x11b8; | 880 | case 0x1107: return 0x11b8; |
875 | case 0x1109: return 0x11ba; | 881 | case 0x1109: return 0x11ba; |
876 | case 0x110a: return 0x11bb; | 882 | case 0x110a: return 0x11bb; |
877 | case 0x110b: return 0x11bc; | 883 | case 0x110b: return 0x11bc; |
878 | case 0x110c: return 0x11bd; | 884 | case 0x110c: return 0x11bd; |
879 | case 0x110e: return 0x11be; | 885 | case 0x110e: return 0x11be; |
880 | case 0x110f: return 0x11bf; | 886 | case 0x110f: return 0x11bf; |
881 | case 0x1110: return 0x11c0; | 887 | case 0x1110: return 0x11c0; |
882 | case 0x1111: return 0x11c1; | 888 | case 0x1111: return 0x11c1; |
883 | case 0x1112: return 0x11c2; | 889 | case 0x1112: return 0x11c2; |
884 | default: return 0; | 890 | default: return 0; |
885 | 891 | ||
886 | } | 892 | } |
887 | 893 | ||
888 | } else { //echar to schar | 894 | } else { //echar to schar |
889 | 895 | ||
890 | switch (c) { | 896 | switch (c) { |
891 | case 0x11a8: return 0x1100; | 897 | case 0x11a8: return 0x1100; |
892 | case 0x11a9: return 0x1101; | 898 | case 0x11a9: return 0x1101; |
893 | case 0x11ab: return 0x1102; | 899 | case 0x11ab: return 0x1102; |
894 | case 0x11ae: return 0x1103; | 900 | case 0x11ae: return 0x1103; |
895 | case 0x11af: return 0x1105; | 901 | case 0x11af: return 0x1105; |
896 | case 0x11b7: return 0x1106; | 902 | case 0x11b7: return 0x1106; |
897 | case 0x11b8: return 0x1107; | 903 | case 0x11b8: return 0x1107; |
898 | case 0x11ba: return 0x1109; | 904 | case 0x11ba: return 0x1109; |
899 | case 0x11bb: return 0x110a; | 905 | case 0x11bb: return 0x110a; |
900 | case 0x11bc: return 0x110b; | 906 | case 0x11bc: return 0x110b; |
901 | case 0x11bd: return 0x110c; | 907 | case 0x11bd: return 0x110c; |
902 | case 0x11be: return 0x110e; | 908 | case 0x11be: return 0x110e; |
903 | case 0x11bf: return 0x110f; | 909 | case 0x11bf: return 0x110f; |
904 | case 0x11c0: return 0x1110; | 910 | case 0x11c0: return 0x1110; |
905 | case 0x11c1: return 0x1111; | 911 | case 0x11c1: return 0x1111; |
906 | case 0x11c2: return 0x1112; | 912 | case 0x11c2: return 0x1112; |
907 | default: return 0; | 913 | default: return 0; |
908 | 914 | ||
909 | } | 915 | } |
910 | 916 | ||
911 | } | 917 | } |
912 | } | 918 | } |
913 | 919 | ||
914 | 920 | ||
915 | // Keys::Keys {{{1 | 921 | // Keys::Keys {{{1 |
916 | 922 | ||
917 | Keys::Keys() { | 923 | Keys::Keys() { |
918 | 924 | ||
919 | Config *config = new Config ("multikey"); | 925 | Config *config = new Config ("multikey"); |
920 | config->setGroup( "keymaps" ); | 926 | config->setGroup( "keymaps" ); |
921 | QString map = config->readEntry( "current" ); | 927 | QString map = config->readEntry( "current" ); |
922 | delete config; | 928 | delete config; |
923 | 929 | ||
924 | if (map.isNull() || !(QFile(map).exists())) { | 930 | if (map.isNull() || !(QFile(map).exists())) { |
925 | 931 | ||
926 | Config *config = new Config("locale"); | 932 | Config *config = new Config("locale"); |
927 | config->setGroup( "Language" ); | 933 | config->setGroup( "Language" ); |
928 | QString l = config->readEntry( "Language" , "en" ); | 934 | QString l = config->readEntry( "Language" , "en" ); |
929 | delete config; | 935 | delete config; |
930 | 936 | ||
931 | map = QPEApplication::qpeDir() + "/share/multikey/" | 937 | map = QPEApplication::qpeDir() + "/share/multikey/" |
932 | + l + ".keymap"; | 938 | + l + ".keymap"; |
933 | 939 | ||
934 | } | 940 | } |
935 | 941 | ||
936 | setKeysFromFile(map); | 942 | setKeysFromFile(map); |
937 | } | 943 | } |
938 | 944 | ||
939 | Keys::Keys(const char * filename) { | 945 | Keys::Keys(const char * filename) { |
940 | 946 | ||
941 | setKeysFromFile(filename); | 947 | setKeysFromFile(filename); |
942 | } | 948 | } |
943 | 949 | ||
944 | // Keys::setKeysFromFile {{{2 | 950 | // Keys::setKeysFromFile {{{2 |
945 | void Keys::setKeysFromFile(const char * filename) { | 951 | void Keys::setKeysFromFile(const char * filename) { |
946 | 952 | ||
947 | QFile f(filename); | 953 | QFile f(filename); |
948 | 954 | ||
949 | if (f.open(IO_ReadOnly)) { | 955 | if (f.open(IO_ReadOnly)) { |
950 | 956 | ||
951 | QTextStream t(&f); | 957 | QTextStream t(&f); |
952 | int row; | 958 | int row; |
953 | int qcode; | 959 | int qcode; |
954 | ushort unicode; | 960 | ushort unicode; |
955 | int width; | 961 | int width; |
956 | QString buf; | 962 | QString buf; |
957 | QString comment; | 963 | QString comment; |
958 | char * xpm[256]; //couldnt be larger than that... could it? | 964 | char * xpm[256]; //couldnt be larger than that... could it? |
959 | QPixmap *xpm2pix = 0; | 965 | QPixmap *xpm2pix = 0; |
960 | 966 | ||
961 | buf = t.readLine(); | 967 | buf = t.readLine(); |
962 | while (buf) { | 968 | while (buf) { |
963 | 969 | ||
964 | // key definition | 970 | // key definition |
965 | if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) { | 971 | if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) { |
966 | // no $1 type referencing!!! this implementation of regexp sucks | 972 | // no $1 type referencing!!! this implementation of regexp sucks |
967 | 973 | ||
968 | // dont know of any sscanf() type funcs in Qt lib | 974 | // dont know of any sscanf() type funcs in Qt lib |
969 | QTextStream tmp (buf, IO_ReadOnly); | 975 | QTextStream tmp (buf, IO_ReadOnly); |
970 | tmp >> row >> qcode >> unicode >> width >> comment; | 976 | tmp >> row >> qcode >> unicode >> width >> comment; |
971 | 977 | ||
972 | buf = t.readLine(); | 978 | buf = t.readLine(); |
973 | int xpmLineCount = 0; | 979 | int xpmLineCount = 0; |
974 | xpm2pix = 0; | 980 | xpm2pix = 0; |
975 | 981 | ||
976 | // erase blank space | 982 | // erase blank space |
977 | while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine(); | 983 | while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine(); |
978 | 984 | ||
979 | while (buf.contains(QRegExp("^\\s*\".*\""))) { | 985 | while (buf.contains(QRegExp("^\\s*\".*\""))) { |
980 | 986 | ||
981 | QString xpmBuf = buf.stripWhiteSpace(); | 987 | QString xpmBuf = buf.stripWhiteSpace(); |
982 | 988 | ||
983 | xpm[xpmLineCount] = new char [xpmBuf.length()]; | 989 | xpm[xpmLineCount] = new char [xpmBuf.length()]; |
984 | 990 | ||
985 | int j = 0; | 991 | int j = 0; |
986 | for (ushort i = 0; i < xpmBuf.length(); i++) { | 992 | for (ushort i = 0; i < xpmBuf.length(); i++) { |
987 | if (xpmBuf[i].latin1() != '"') { | 993 | if (xpmBuf[i].latin1() != '"') { |
988 | 994 | ||
989 | ((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1(); | 995 | ((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1(); |
990 | j++; | 996 | j++; |
991 | } | 997 | } |
992 | 998 | ||
993 | } | 999 | } |
994 | // have to close that facker up | 1000 | // have to close that facker up |
995 | ((char *)xpm[xpmLineCount])[j] = '\0'; | 1001 | ((char *)xpm[xpmLineCount])[j] = '\0'; |
996 | 1002 | ||
997 | xpmLineCount++; | 1003 | xpmLineCount++; |
998 | buf = t.readLine(); | 1004 | buf = t.readLine(); |
999 | } | 1005 | } |
1000 | if (xpmLineCount) { | 1006 | if (xpmLineCount) { |
1001 | 1007 | ||
1002 | xpm2pix = new QPixmap((const char **)xpm); | 1008 | xpm2pix = new QPixmap((const char **)xpm); |
1003 | for (int i = 0; i < xpmLineCount; i++) | 1009 | for (int i = 0; i < xpmLineCount; i++) |
1004 | 1010 | ||
1005 | delete [] (xpm[i]); | 1011 | delete [] (xpm[i]); |
1006 | 1012 | ||
1007 | } | 1013 | } |
1008 | setKey(row, qcode, unicode, width, xpm2pix); | 1014 | setKey(row, qcode, unicode, width, xpm2pix); |
1009 | } | 1015 | } |
1010 | 1016 | ||
1011 | // shift map | 1017 | // shift map |
1012 | else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { | 1018 | else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { |
1013 | 1019 | ||
1014 | QTextStream tmp (buf, IO_ReadOnly); | 1020 | QTextStream tmp (buf, IO_ReadOnly); |
1015 | ushort lower, shift; | 1021 | ushort lower, shift; |
1016 | tmp >> lower >> shift; | 1022 | tmp >> lower >> shift; |
1017 | 1023 | ||
1018 | shiftMap.insert(lower, shift); | 1024 | shiftMap.insert(lower, shift); |
1019 | 1025 | ||
1020 | buf = t.readLine(); | 1026 | buf = t.readLine(); |
1021 | } | 1027 | } |
1022 | 1028 | ||
1023 | // other variables like lang & title | 1029 | // other variables like lang & title |
1024 | else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) { | 1030 | else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) { |
1025 | 1031 | ||
1026 | QTextStream tmp (buf, IO_ReadOnly); | 1032 | QTextStream tmp (buf, IO_ReadOnly); |
1027 | QString name, equals, value; | 1033 | QString name, equals, value; |
1028 | 1034 | ||
1029 | tmp >> name >> equals >> value; | 1035 | tmp >> name >> equals >> value; |
1030 | 1036 | ||
1031 | if (name == "lang") { | 1037 | if (name == "lang") { |
1032 | 1038 | ||
1033 | lang = value; | 1039 | lang = value; |
1034 | 1040 | ||
1035 | } | 1041 | } |
1036 | 1042 | ||
1037 | buf = t.readLine(); | 1043 | buf = t.readLine(); |
1038 | } | 1044 | } |
1039 | // comments | 1045 | // comments |
1040 | else if (buf.contains(QRegExp("^\\s*#"))) { | 1046 | else if (buf.contains(QRegExp("^\\s*#"))) { |
1041 | 1047 | ||
1042 | buf = t.readLine(); | 1048 | buf = t.readLine(); |
1043 | 1049 | ||
1044 | } else { // blank line, or garbage | 1050 | } else { // blank line, or garbage |
1045 | 1051 | ||
1046 | buf = t.readLine(); | 1052 | buf = t.readLine(); |
1047 | 1053 | ||
1048 | } | 1054 | } |
1049 | 1055 | ||
1050 | } | 1056 | } |
1051 | f.close(); | 1057 | f.close(); |
1052 | } | 1058 | } |
1053 | 1059 | ||
1054 | } | 1060 | } |
1055 | 1061 | ||
1056 | // Keys::setKey {{{2 | 1062 | // Keys::setKey {{{2 |
1057 | void Keys::setKey(const int row, const int qcode, const ushort unicode, | 1063 | void Keys::setKey(const int row, const int qcode, const ushort unicode, |
1058 | const int width, QPixmap *pix) { | 1064 | const int width, QPixmap *pix) { |
1059 | 1065 | ||
1060 | Key * key; | 1066 | Key * key; |
1061 | key = new Key; | 1067 | key = new Key; |
1062 | key->qcode = qcode; | 1068 | key->qcode = qcode; |
1063 | key->unicode = unicode; | 1069 | key->unicode = unicode; |
1064 | key->width = width; | 1070 | key->width = width; |
1065 | 1071 | ||
1066 | // share key->pressed between same keys | 1072 | // share key->pressed between same keys |
1067 | bool found = 0; | 1073 | bool found = 0; |
1068 | for (int i = 1; i <= 5; i++) { | 1074 | for (int i = 1; i <= 5; i++) { |
1069 | for (unsigned int j = 0; j < keys[i].count(); j++) | 1075 | for (unsigned int j = 0; j < keys[i].count(); j++) |
1070 | if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) { | 1076 | if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) { |
1071 | 1077 | ||
1072 | key->pressed = keys[i].at(j)->pressed; | 1078 | key->pressed = keys[i].at(j)->pressed; |
1073 | found = 1; | 1079 | found = 1; |
1074 | } | 1080 | } |
1075 | 1081 | ||
1076 | } | 1082 | } |
1077 | if (!found) { | 1083 | if (!found) { |
1078 | 1084 | ||
1079 | key->pressed = new bool; | 1085 | key->pressed = new bool; |
1080 | *(key->pressed) = 0; | 1086 | *(key->pressed) = 0; |
1081 | } | 1087 | } |
1082 | 1088 | ||
1083 | key->pix = pix; | 1089 | key->pix = pix; |
1084 | 1090 | ||
1085 | 1091 | ||
1086 | keys[row].append(key); | 1092 | keys[row].append(key); |
1087 | } | 1093 | } |
1088 | 1094 | ||
1089 | // Keys::~Keys {{{2 | 1095 | // Keys::~Keys {{{2 |
1090 | Keys::~Keys() { | 1096 | Keys::~Keys() { |
1091 | 1097 | ||
1092 | for (int i = 1; i <= 5; i++) | 1098 | for (int i = 1; i <= 5; i++) |
1093 | for (unsigned int j = 0; j < keys[i].count(); j++) | 1099 | for (unsigned int j = 0; j < keys[i].count(); j++) |
1094 | delete keys[i].at(j); | 1100 | delete keys[i].at(j); |
1095 | 1101 | ||
1096 | } | 1102 | } |
1097 | 1103 | ||
1098 | // Keys:: other functions {{{2 | 1104 | // Keys:: other functions {{{2 |
1099 | int Keys::width(const int row, const int col) { | 1105 | int Keys::width(const int row, const int col) { |
1100 | 1106 | ||
1101 | return keys[row].at(col)->width; | 1107 | return keys[row].at(col)->width; |
1102 | 1108 | ||
1103 | } | 1109 | } |
1104 | ushort Keys::uni(const int row, const int col) { | 1110 | ushort Keys::uni(const int row, const int col) { |
1105 | 1111 | ||
1106 | return keys[row].at(col)->unicode; | 1112 | return keys[row].at(col)->unicode; |
1107 | 1113 | ||
1108 | } | 1114 | } |
1109 | 1115 | ||
1110 | int Keys::qcode(const int row, const int col) { | 1116 | int Keys::qcode(const int row, const int col) { |
1111 | 1117 | ||
1112 | return keys[row].at(col)->qcode; | 1118 | return keys[row].at(col)->qcode; |
1113 | } | 1119 | } |
1114 | 1120 | ||
1115 | QPixmap *Keys::pix(const int row, const int col) { | 1121 | QPixmap *Keys::pix(const int row, const int col) { |
1116 | 1122 | ||
1117 | return keys[row].at(col)->pix; | 1123 | return keys[row].at(col)->pix; |
1118 | 1124 | ||
1119 | } | 1125 | } |
1120 | bool Keys::pressed(const int row, const int col) { | 1126 | bool Keys::pressed(const int row, const int col) { |
1121 | 1127 | ||
1122 | return *(keys[row].at(col)->pressed); | 1128 | return *(keys[row].at(col)->pressed); |
1123 | } | 1129 | } |
1124 | 1130 | ||
1125 | int Keys::numKeys(const int row) { | 1131 | int Keys::numKeys(const int row) { |
1126 | 1132 | ||
1127 | return keys[row].count(); | 1133 | return keys[row].count(); |
1128 | } | 1134 | } |
1129 | 1135 | ||
1130 | void Keys::setPressed(const int row, const int col, const bool pressed) { | 1136 | void Keys::setPressed(const int row, const int col, const bool pressed) { |
1131 | 1137 | ||
1132 | *(keys[row].at(col)->pressed) = pressed; | 1138 | *(keys[row].at(col)->pressed) = pressed; |
1133 | } | 1139 | } |
1134 | 1140 | ||
1135 | ushort Keys::shift(const ushort uni) { | 1141 | ushort Keys::shift(const ushort uni) { |
1136 | 1142 | ||
1137 | if (shiftMap[uni]) { | 1143 | if (shiftMap[uni]) { |
1138 | 1144 | ||
1139 | return shiftMap[uni]; | 1145 | return shiftMap[uni]; |
1140 | } | 1146 | } |
1141 | else | 1147 | else |
1142 | return 0; | 1148 | return 0; |
1143 | 1149 | ||
1144 | } | 1150 | } |
1145 | 1151 | ||
1146 | bool *Keys::pressedPtr(const int row, const int col) { | 1152 | bool *Keys::pressedPtr(const int row, const int col) { |
1147 | 1153 | ||
1148 | return keys[row].at(col)->pressed; | 1154 | return keys[row].at(col)->pressed; |
1149 | } | 1155 | } |