author | hash <hash> | 2002-08-27 01:47:36 (UTC) |
---|---|---|
committer | hash <hash> | 2002-08-27 01:47:36 (UTC) |
commit | 6aa0fb1ced890c21cd1ad4a3bab17b843c40164b (patch) (unidiff) | |
tree | fafb48427af1b54fc55cc4a064cfc0f6eb95e454 /inputmethods | |
parent | f7d9d8697c2971b7f512ade7625dfff30d0043d0 (diff) | |
download | opie-6aa0fb1ced890c21cd1ad4a3bab17b843c40164b.zip opie-6aa0fb1ced890c21cd1ad4a3bab17b843c40164b.tar.gz opie-6aa0fb1ced890c21cd1ad4a3bab17b843c40164b.tar.bz2 |
now shows whatever you wrote in the keymap 'title' var as the listItem
-rw-r--r-- | inputmethods/multikey/configdlg.cpp | 56 | ||||
-rw-r--r-- | inputmethods/multikey/keyboard.cpp | 3 |
2 files changed, 46 insertions, 13 deletions
diff --git a/inputmethods/multikey/configdlg.cpp b/inputmethods/multikey/configdlg.cpp index 10bc611..c5ebe3c 100644 --- a/inputmethods/multikey/configdlg.cpp +++ b/inputmethods/multikey/configdlg.cpp | |||
@@ -1,367 +1,401 @@ | |||
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 | * add meta key support for german, etc |
6 | * | 6 | * |
7 | * | 7 | * |
8 | * | 8 | * |
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <iostream.h> | ||
12 | |||
13 | #include <qpe/qpeapplication.h> | 11 | #include <qpe/qpeapplication.h> |
14 | #include <qpe/config.h> | 12 | #include <qpe/config.h> |
15 | 13 | ||
16 | #include <qwidget.h> | 14 | #include <qwidget.h> |
17 | #include <qdialog.h> | 15 | #include <qdialog.h> |
18 | #include <qtabwidget.h> | 16 | #include <qtabwidget.h> |
19 | #include <qvbox.h> | 17 | #include <qvbox.h> |
20 | #include <qgrid.h> | 18 | #include <qgrid.h> |
21 | #include <qgroupbox.h> | 19 | #include <qgroupbox.h> |
22 | #include <qlabel.h> | 20 | #include <qlabel.h> |
23 | #include <qcheckbox.h> | 21 | #include <qcheckbox.h> |
24 | #include <qsizepolicy.h> | 22 | #include <qsizepolicy.h> |
25 | #include <qpushbutton.h> | 23 | #include <qpushbutton.h> |
26 | #include <qlistbox.h> | 24 | #include <qlistbox.h> |
27 | #include <qstringlist.h> | 25 | #include <qstringlist.h> |
28 | #include <opie/ofiledialog.h> | 26 | #include <opie/ofiledialog.h> |
29 | #include <opie/colordialog.h> | 27 | #include <opie/colordialog.h> |
30 | #include <qdir.h> | 28 | #include <qdir.h> |
31 | #include <qfileinfo.h> | 29 | #include <qfileinfo.h> |
32 | #include "configdlg.h" | 30 | #include "configdlg.h" |
33 | #include "keyboard.h" | 31 | #include "keyboard.h" |
34 | 32 | ||
35 | // ConfigDlg::ConfigDlg() {{{1 | 33 | // ConfigDlg::ConfigDlg() {{{1 |
36 | ConfigDlg::ConfigDlg () : QTabWidget () | 34 | ConfigDlg::ConfigDlg () : QTabWidget () |
37 | { | 35 | { |
38 | setCaption( tr("Multikey Configuration") ); | 36 | setCaption( tr("Multikey Configuration") ); |
39 | Config config ("multikey"); | 37 | Config config ("multikey"); |
40 | config.setGroup("keymaps"); | 38 | config.setGroup("keymaps"); |
41 | QString current_map = config.readEntry("current", 0); | 39 | QString current_map = config.readEntry("current", 0); |
42 | 40 | ||
43 | /* | 41 | /* |
44 | * 'general config' tab | 42 | * 'general config' tab |
45 | */ | 43 | */ |
46 | 44 | ||
47 | QVBox *gen_box = new QVBox (this); | 45 | QVBox *gen_box = new QVBox (this); |
48 | gen_box->setMargin(3); | 46 | gen_box->setMargin(3); |
49 | addTab(gen_box, tr("General Settings")); | 47 | addTab(gen_box, tr("General Settings")); |
50 | 48 | ||
51 | QGroupBox *map_group = new QGroupBox (2, Qt::Vertical, tr("Keymap File"), gen_box); | 49 | QGroupBox *map_group = new QGroupBox (2, Qt::Vertical, tr("Keymap File"), gen_box); |
52 | 50 | ||
53 | keymaps = new QListBox (map_group); | 51 | keymaps = new QListBox (map_group); |
54 | keymaps->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); | 52 | keymaps->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); |
55 | 53 | ||
56 | QString cur(tr("Current Language")); | 54 | QString cur(tr("Current Language")); |
57 | keymaps->insertItem(cur); | 55 | keymaps->insertItem(cur); |
58 | keymaps->setSelected(0, true); | 56 | keymaps->setSelected(0, true); |
59 | 57 | ||
60 | QDir map_dir(QPEApplication::qpeDir() + "/share/multikey", "*.keymap"); | 58 | QDir map_dir(QPEApplication::qpeDir() + "/share/multikey", "*.keymap"); |
61 | default_maps = map_dir.entryList(); // so i can access it in other places | 59 | default_maps = map_dir.entryList(); // so i can access it in other places |
62 | 60 | ||
63 | for (uint i = 0; i <map_dir.count(); i++) { | 61 | for (uint i = 0; i < map_dir.count(); i++) { |
62 | |||
63 | QFile map (map_dir.absPath() + "/" + map_dir[i]); | ||
64 | if (map.open(IO_ReadOnly)) { | ||
65 | |||
66 | QString line; bool found = 0; | ||
67 | |||
68 | map.readLine(line, 1024); | ||
69 | while (!map.atEnd()) { | ||
64 | 70 | ||
65 | keymaps->insertItem(map_dir.absPath() + "/" + map_dir[i]); | 71 | if (line.find(QRegExp("^title\\s*=\\s*")) != -1) { |
72 | |||
73 | keymaps->insertItem(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace()); | ||
74 | found = 1; | ||
75 | break; | ||
76 | } | ||
77 | map.readLine(line, 1024); | ||
78 | } | ||
79 | if (!found) keymaps->insertItem(map_dir.absPath() + "/" + map_dir[i]); | ||
80 | |||
81 | map.close(); | ||
82 | } | ||
66 | if (map_dir.absPath() + "/" + map_dir[i] == current_map) { | 83 | if (map_dir.absPath() + "/" + map_dir[i] == current_map) { |
67 | 84 | ||
68 | keymaps->setSelected(i + 1, true); | 85 | keymaps->setSelected(i + 1, true); |
69 | } | 86 | } |
70 | 87 | ||
71 | } | 88 | } |
72 | 89 | ||
73 | custom_maps = config.readListEntry("maps", QChar('|')); | 90 | custom_maps = config.readListEntry("maps", QChar('|')); |
74 | 91 | ||
75 | for (uint i = 0; i < custom_maps.count(); i++) { | 92 | for (uint i = 0; i < custom_maps.count(); i++) { |
76 | 93 | ||
77 | if (map_dir.exists(QFileInfo(custom_maps[i]).fileName(), false) | 94 | if (map_dir.exists(QFileInfo(custom_maps[i]).fileName(), false) |
78 | || !QFile::exists(custom_maps[i])) { | 95 | || !QFile::exists(custom_maps[i])) { |
79 | 96 | ||
80 | custom_maps.remove(custom_maps.at(i)); | 97 | custom_maps.remove(custom_maps.at(i)); |
81 | 98 | ||
82 | // remove it from the list too | 99 | // remove it from the list too |
83 | config.writeEntry("maps", custom_maps.join("|")); | 100 | config.writeEntry("maps", custom_maps.join("|")); |
84 | 101 | ||
85 | 102 | ||
86 | } else { | 103 | } else { |
87 | 104 | ||
88 | keymaps->insertItem(custom_maps[i]); | 105 | QFile map (custom_maps[i]); |
106 | if (map.open(IO_ReadOnly)) { | ||
107 | |||
108 | QString line; bool found = 0; | ||
109 | |||
110 | map.readLine(line, 1024); | ||
111 | while (!map.atEnd()) { | ||
112 | |||
113 | if (line.find(QRegExp("^title\\s*=\\s*")) != -1) { | ||
114 | |||
115 | keymaps->insertItem(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace()); | ||
116 | found = 1; | ||
117 | break; | ||
118 | } | ||
119 | map.readLine(line, 1024); | ||
120 | } | ||
121 | if (!found) keymaps->insertItem(custom_maps[i]); | ||
122 | |||
123 | map.close(); | ||
124 | } | ||
89 | if (custom_maps[i] == current_map) { | 125 | if (custom_maps[i] == current_map) { |
90 | 126 | ||
91 | keymaps->setSelected(map_dir.count() + i + 1, true); | 127 | keymaps->setSelected(map_dir.count() + i + 1, true); |
92 | } | 128 | } |
93 | } | 129 | } |
94 | } | 130 | } |
95 | 131 | ||
96 | // have to "+1" because the "current language" listItem... remember? | 132 | // have to "+1" because the "current language" listItem... remember? |
97 | 133 | ||
98 | connect(keymaps, SIGNAL(highlighted(int)), SLOT(setMap(int))); | 134 | connect(keymaps, SIGNAL(highlighted(int)), SLOT(setMap(int))); |
99 | 135 | ||
100 | 136 | ||
101 | QGrid *add_remove_grid = new QGrid(2, map_group); | 137 | QGrid *add_remove_grid = new QGrid(2, map_group); |
102 | add_remove_grid->setMargin(3); | 138 | add_remove_grid->setMargin(3); |
103 | add_remove_grid->setSpacing(3); | 139 | add_remove_grid->setSpacing(3); |
104 | 140 | ||
105 | add_button = new QPushButton(tr("Add"), add_remove_grid); | 141 | add_button = new QPushButton(tr("Add"), add_remove_grid); |
106 | add_button->setFlat((bool)1); | 142 | add_button->setFlat((bool)1); |
107 | connect(add_button, SIGNAL(clicked()), SLOT(addMap())); | 143 | connect(add_button, SIGNAL(clicked()), SLOT(addMap())); |
108 | 144 | ||
109 | remove_button = new QPushButton(tr("Remove"), add_remove_grid); | 145 | remove_button = new QPushButton(tr("Remove"), add_remove_grid); |
110 | remove_button->setFlat((bool)1); | 146 | remove_button->setFlat((bool)1); |
111 | if ((int)map_dir.count() >= keymaps->currentItem()) | 147 | if ((int)map_dir.count() >= keymaps->currentItem()) |
112 | remove_button->setDisabled(true); | 148 | remove_button->setDisabled(true); |
113 | connect(remove_button, SIGNAL(clicked()), SLOT(removeMap())); | 149 | connect(remove_button, SIGNAL(clicked()), SLOT(removeMap())); |
114 | 150 | ||
115 | // make a box that will contain the buttons on the bottom | 151 | // make a box that will contain the buttons on the bottom |
116 | QGrid *other_grid = new QGrid(2, gen_box); | 152 | QGrid *other_grid = new QGrid(2, gen_box); |
117 | pick_button = new QCheckBox(tr("Pickboard"), other_grid); | 153 | pick_button = new QCheckBox(tr("Pickboard"), other_grid); |
118 | 154 | ||
119 | config.setGroup ("general"); | 155 | config.setGroup ("general"); |
120 | bool pick_open = config.readBoolEntry ("usePickboard", (bool)0); // default closed | 156 | bool pick_open = config.readBoolEntry ("usePickboard", (bool)0); // default closed |
121 | if (pick_open) { | 157 | if (pick_open) { |
122 | 158 | ||
123 | pick_button->setChecked(true); | 159 | pick_button->setChecked(true); |
124 | } | 160 | } |
125 | 161 | ||
126 | // by connecting it after checking it, the signal isn't emmited | 162 | // by connecting it after checking it, the signal isn't emmited |
127 | connect (pick_button, SIGNAL(clicked()), this, SLOT(pickTog())); | 163 | connect (pick_button, SIGNAL(clicked()), this, SLOT(pickTog())); |
128 | 164 | ||
129 | repeat_button = new QCheckBox(tr("Key Repeat"), other_grid); | 165 | repeat_button = new QCheckBox(tr("Key Repeat"), other_grid); |
130 | bool repeat_on = config.readBoolEntry ("useRepeat", (bool)1); | 166 | bool repeat_on = config.readBoolEntry ("useRepeat", (bool)1); |
131 | 167 | ||
132 | if (repeat_on) { | 168 | if (repeat_on) { |
133 | 169 | ||
134 | repeat_button->setChecked(true); | 170 | repeat_button->setChecked(true); |
135 | } | 171 | } |
136 | connect (repeat_button, SIGNAL(clicked()), this, SLOT(repeatTog())); | 172 | connect (repeat_button, SIGNAL(clicked()), this, SLOT(repeatTog())); |
137 | 173 | ||
138 | 174 | ||
139 | /* | 175 | /* |
140 | * 'color' tab | 176 | * 'color' tab |
141 | */ | 177 | */ |
142 | 178 | ||
143 | QGrid *color_box = new QGrid(2, this); | 179 | QGrid *color_box = new QGrid(2, this); |
144 | color_box->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); | 180 | color_box->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); |
145 | color_box->setMargin(3); | 181 | color_box->setMargin(3); |
146 | color_box->setSpacing(3); | 182 | color_box->setSpacing(3); |
147 | addTab(color_box, tr("Colors")); | 183 | addTab(color_box, tr("Colors")); |
148 | 184 | ||
149 | QLabel *label; | 185 | QLabel *label; |
150 | QStringList color; | 186 | QStringList color; |
151 | config.setGroup("colors"); | 187 | config.setGroup("colors"); |
152 | 188 | ||
153 | label = new QLabel(tr("Key Color"), color_box); | 189 | label = new QLabel(tr("Key Color"), color_box); |
154 | keycolor_button = new QPushButton(color_box); | 190 | keycolor_button = new QPushButton(color_box); |
155 | connect(keycolor_button, SIGNAL(clicked()), SLOT(keyColorClicked())); | 191 | connect(keycolor_button, SIGNAL(clicked()), SLOT(keyColorClicked())); |
156 | keycolor_button->setFlat((bool)1); | 192 | keycolor_button->setFlat((bool)1); |
157 | color = config.readListEntry("keycolor", QChar(',')); | 193 | color = config.readListEntry("keycolor", QChar(',')); |
158 | /* | 194 | /* |
159 | * hopefully not required | 195 | * hopefully not required |
160 | 196 | ||
161 | if (color.isEmpty()) { | 197 | if (color.isEmpty()) { |
162 | color = QStringList::split(",", "240,240,240"); | 198 | color = QStringList::split(",", "240,240,240"); |
163 | config.writeEntry("keycolor", color.join(",")); | 199 | config.writeEntry("keycolor", color.join(",")); |
164 | 200 | ||
165 | } | 201 | } |
166 | */ | 202 | */ |
167 | keycolor_button->setPalette(QPalette(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()))); | 203 | keycolor_button->setPalette(QPalette(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()))); |
168 | 204 | ||
169 | 205 | ||
170 | label = new QLabel(tr("Key Pressed Color"), color_box); | 206 | label = new QLabel(tr("Key Pressed Color"), color_box); |
171 | keycolor_pressed_button = new QPushButton(color_box); | 207 | keycolor_pressed_button = new QPushButton(color_box); |
172 | connect(keycolor_pressed_button, SIGNAL(clicked()), SLOT(keyColorPressedClicked())); | 208 | connect(keycolor_pressed_button, SIGNAL(clicked()), SLOT(keyColorPressedClicked())); |
173 | keycolor_pressed_button->setFlat((bool)1); | 209 | keycolor_pressed_button->setFlat((bool)1); |
174 | color = config.readListEntry("keycolor_pressed", QChar(',')); | 210 | color = config.readListEntry("keycolor_pressed", QChar(',')); |
175 | keycolor_pressed_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())))); | 211 | keycolor_pressed_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())))); |
176 | 212 | ||
177 | label = new QLabel(tr("Line Color"), color_box); | 213 | label = new QLabel(tr("Line Color"), color_box); |
178 | keycolor_lines_button = new QPushButton(color_box); | 214 | keycolor_lines_button = new QPushButton(color_box); |
179 | connect(keycolor_lines_button, SIGNAL(clicked()), SLOT(keyColorLinesClicked())); | 215 | connect(keycolor_lines_button, SIGNAL(clicked()), SLOT(keyColorLinesClicked())); |
180 | keycolor_lines_button->setFlat((bool)1); | 216 | keycolor_lines_button->setFlat((bool)1); |
181 | color = config.readListEntry("keycolor_lines", QChar(',')); | 217 | color = config.readListEntry("keycolor_lines", QChar(',')); |
182 | keycolor_lines_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())))); | 218 | keycolor_lines_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())))); |
183 | 219 | ||
184 | 220 | ||
185 | label = new QLabel(tr("Text Color"), color_box); | 221 | label = new QLabel(tr("Text Color"), color_box); |
186 | textcolor_button = new QPushButton(color_box); | 222 | textcolor_button = new QPushButton(color_box); |
187 | connect(textcolor_button, SIGNAL(clicked()), SLOT(textColorClicked())); | 223 | connect(textcolor_button, SIGNAL(clicked()), SLOT(textColorClicked())); |
188 | textcolor_button->setFlat((bool)1); | 224 | textcolor_button->setFlat((bool)1); |
189 | color = config.readListEntry("textcolor", QChar(',')); | 225 | color = config.readListEntry("textcolor", QChar(',')); |
190 | textcolor_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())))); | 226 | textcolor_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())))); |
191 | 227 | ||
192 | 228 | ||
193 | label = new QLabel("", color_box); // a spacer so the above buttons dont expand | 229 | label = new QLabel("", color_box); // a spacer so the above buttons dont expand |
194 | label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); | 230 | label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); |
195 | 231 | ||
196 | } | 232 | } |
197 | 233 | ||
198 | void ConfigDlg::pickTog() { | 234 | void ConfigDlg::pickTog() { |
199 | 235 | ||
200 | Config config ("multikey"); | 236 | Config config ("multikey"); |
201 | config.setGroup ("general"); | 237 | config.setGroup ("general"); |
202 | config.writeEntry ("usePickboard", pick_button->isChecked()); // default closed | 238 | config.writeEntry ("usePickboard", pick_button->isChecked()); // default closed |
203 | 239 | ||
204 | emit pickboardToggled(pick_button->isChecked()); | 240 | emit pickboardToggled(pick_button->isChecked()); |
205 | } | 241 | } |
206 | 242 | ||
207 | void ConfigDlg::repeatTog() { | 243 | void ConfigDlg::repeatTog() { |
208 | 244 | ||
209 | Config config ("multikey"); | 245 | Config config ("multikey"); |
210 | config.setGroup ("general"); | 246 | config.setGroup ("general"); |
211 | config.writeEntry ("useRepeat", repeat_button->isChecked()); // default closed | 247 | config.writeEntry ("useRepeat", repeat_button->isChecked()); // default closed |
212 | 248 | ||
213 | emit repeatToggled(repeat_button->isChecked()); | 249 | emit repeatToggled(repeat_button->isChecked()); |
214 | } | 250 | } |
215 | 251 | ||
216 | // ConfigDlg::setMap {{{1 | 252 | // ConfigDlg::setMap {{{1 |
217 | 253 | ||
218 | /* | 254 | /* |
219 | * the index is kinda screwy, because in the config file, index 0 is just the | 255 | * the index is kinda screwy, because in the config file, index 0 is just the |
220 | * first element in the QStringList, but here it's the "Current Language" | 256 | * first element in the QStringList, but here it's the "Current Language" |
221 | * listItem. therefor you have to minus one to the index before you access it. | 257 | * listItem. therefor you have to minus one to the index before you access it. |
222 | * | 258 | * |
223 | */ | 259 | */ |
224 | 260 | ||
225 | void ConfigDlg::setMap(int index) { | 261 | void ConfigDlg::setMap(int index) { |
226 | 262 | ||
227 | if (index == 0) { | 263 | if (index == 0) { |
228 | 264 | ||
229 | remove_button->setDisabled(true); | 265 | remove_button->setDisabled(true); |
230 | emit setMapToDefault(); | 266 | emit setMapToDefault(); |
231 | } | 267 | } |
232 | else if ((uint)index <= default_maps.count()) { | 268 | else if ((uint)index <= default_maps.count()) { |
233 | 269 | ||
234 | remove_button->setDisabled(true); | 270 | remove_button->setDisabled(true); |
235 | emit setMapToFile(keymaps->text(index)); | 271 | emit setMapToFile(QPEApplication::qpeDir() + "/share/multikey/" + default_maps[index - 1]); |
236 | 272 | ||
237 | } else { | 273 | } else { |
238 | 274 | ||
239 | remove_button->setEnabled(true); | 275 | remove_button->setEnabled(true); |
240 | emit setMapToFile(keymaps->text(index)); | 276 | emit setMapToFile(custom_maps[index - default_maps.count() - 1]); |
241 | } | 277 | } |
242 | } | 278 | } |
243 | 279 | ||
244 | // ConfigDlg::addMap() {{{1 | 280 | // ConfigDlg::addMap() {{{1 |
245 | void ConfigDlg::addMap() { | 281 | void ConfigDlg::addMap() { |
246 | 282 | ||
247 | QString map = OFileDialog::getOpenFileName(1, QDir::home().absPath()); | 283 | QString map = OFileDialog::getOpenFileName(1, QDir::home().absPath()); |
248 | 284 | ||
249 | if (map.isNull()) return; | 285 | if (map.isNull()) return; |
250 | 286 | ||
251 | Config config ("multikey"); | 287 | Config config ("multikey"); |
252 | config.setGroup("keymaps"); | 288 | config.setGroup("keymaps"); |
253 | QStringList maps = config.readListEntry("maps", QChar('|')); | 289 | QStringList maps = config.readListEntry("maps", QChar('|')); |
254 | maps.append(map); | 290 | maps.append(map); |
291 | custom_maps.append(map); | ||
255 | keymaps->insertItem(map); | 292 | keymaps->insertItem(map); |
256 | keymaps->setSelected(keymaps->count() - 1, true); | 293 | keymaps->setSelected(keymaps->count() - 1, true); |
257 | 294 | ||
258 | 295 | ||
259 | config.writeEntry("maps", maps, QChar('|')); | 296 | config.writeEntry("maps", maps, QChar('|')); |
260 | config.writeEntry("current", map); | 297 | config.writeEntry("current", map); |
261 | 298 | ||
262 | } | 299 | } |
263 | 300 | ||
264 | // ConfigDlg::removeMap() {{{1 | 301 | // ConfigDlg::removeMap() {{{1 |
265 | void ConfigDlg::removeMap() { | 302 | void ConfigDlg::removeMap() { |
266 | 303 | ||
267 | cout << "removing : " << custom_maps[keymaps->currentItem() - default_maps.count() - 1] << "\n"; | ||
268 | cout << "currentItem : " << keymaps->currentItem() << "\n"; | ||
269 | |||
270 | // move selection up one | 304 | // move selection up one |
271 | keymaps->setSelected(keymaps->currentItem() - 1, true); | 305 | keymaps->setSelected(keymaps->currentItem() - 1, true); |
272 | // delete the next selected item cus you just moved it up | 306 | // delete the next selected item cus you just moved it up |
273 | keymaps->removeItem(keymaps->currentItem() + 1); | 307 | keymaps->removeItem(keymaps->currentItem() + 1); |
274 | 308 | ||
275 | custom_maps.remove(custom_maps[keymaps->currentItem() - default_maps.count()]); | 309 | custom_maps.remove(custom_maps.at(keymaps->currentItem() - default_maps.count())); |
276 | 310 | ||
277 | // write the changes | 311 | // write the changes |
278 | Config config ("multikey"); | 312 | Config config ("multikey"); |
279 | config.setGroup("keymaps"); | 313 | config.setGroup("keymaps"); |
280 | config.writeEntry("maps", custom_maps, QChar('|')); | 314 | config.writeEntry("maps", custom_maps, QChar('|')); |
281 | } | 315 | } |
282 | 316 | ||
283 | /* ConfigDlg::slots for the color buttons {{{1 | 317 | /* ConfigDlg::slots for the color buttons {{{1 |
284 | * | 318 | * |
285 | * these four slots are almost the same, except for the names. i was thinking | 319 | * these four slots are almost the same, except for the names. i was thinking |
286 | * of making a map with pointers to the buttons and names of the configEntry | 320 | * of making a map with pointers to the buttons and names of the configEntry |
287 | * so it could be one slot, but then there would be no way of telling which | 321 | * so it could be one slot, but then there would be no way of telling which |
288 | * of the buttons was clicked if they all connect to the same slot. | 322 | * of the buttons was clicked if they all connect to the same slot. |
289 | * | 323 | * |
290 | */ | 324 | */ |
291 | 325 | ||
292 | void ConfigDlg::keyColorClicked() { | 326 | void ConfigDlg::keyColorClicked() { |
293 | 327 | ||
294 | Config config ("multikey"); | 328 | Config config ("multikey"); |
295 | config.setGroup ("colors"); | 329 | config.setGroup ("colors"); |
296 | 330 | ||
297 | QStringList color = config.readListEntry("keycolor", QChar(',')); | 331 | QStringList color = config.readListEntry("keycolor", QChar(',')); |
298 | 332 | ||
299 | QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); | 333 | QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); |
300 | 334 | ||
301 | color[0].setNum(newcolor.red()); | 335 | color[0].setNum(newcolor.red()); |
302 | color[1].setNum(newcolor.green()); | 336 | color[1].setNum(newcolor.green()); |
303 | color[2].setNum(newcolor.blue()); | 337 | color[2].setNum(newcolor.blue()); |
304 | 338 | ||
305 | config.writeEntry("keycolor", color, QChar(',')); | 339 | config.writeEntry("keycolor", color, QChar(',')); |
306 | config.write(); | 340 | config.write(); |
307 | 341 | ||
308 | keycolor_button->setPalette(QPalette(newcolor)); | 342 | keycolor_button->setPalette(QPalette(newcolor)); |
309 | emit reloadKeyboard(); | 343 | emit reloadKeyboard(); |
310 | } | 344 | } |
311 | void ConfigDlg::keyColorPressedClicked() { | 345 | void ConfigDlg::keyColorPressedClicked() { |
312 | 346 | ||
313 | Config config ("multikey"); | 347 | Config config ("multikey"); |
314 | config.setGroup ("colors"); | 348 | config.setGroup ("colors"); |
315 | 349 | ||
316 | QStringList color = config.readListEntry("keycolor_pressed", QChar(',')); | 350 | QStringList color = config.readListEntry("keycolor_pressed", QChar(',')); |
317 | 351 | ||
318 | QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); | 352 | QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); |
319 | 353 | ||
320 | color[0].setNum(newcolor.red()); | 354 | color[0].setNum(newcolor.red()); |
321 | color[1].setNum(newcolor.green()); | 355 | color[1].setNum(newcolor.green()); |
322 | color[2].setNum(newcolor.blue()); | 356 | color[2].setNum(newcolor.blue()); |
323 | 357 | ||
324 | config.writeEntry("keycolor_pressed", color, QChar(',')); | 358 | config.writeEntry("keycolor_pressed", color, QChar(',')); |
325 | config.write(); | 359 | config.write(); |
326 | 360 | ||
327 | keycolor_pressed_button->setPalette(QPalette(newcolor)); | 361 | keycolor_pressed_button->setPalette(QPalette(newcolor)); |
328 | emit reloadKeyboard(); | 362 | emit reloadKeyboard(); |
329 | } | 363 | } |
330 | void ConfigDlg::keyColorLinesClicked() { | 364 | void ConfigDlg::keyColorLinesClicked() { |
331 | 365 | ||
332 | Config config ("multikey"); | 366 | Config config ("multikey"); |
333 | config.setGroup ("colors"); | 367 | config.setGroup ("colors"); |
334 | 368 | ||
335 | QStringList color = config.readListEntry("keycolor_lines", QChar(',')); | 369 | QStringList color = config.readListEntry("keycolor_lines", QChar(',')); |
336 | 370 | ||
337 | QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); | 371 | QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); |
338 | 372 | ||
339 | color[0].setNum(newcolor.red()); | 373 | color[0].setNum(newcolor.red()); |
340 | color[1].setNum(newcolor.green()); | 374 | color[1].setNum(newcolor.green()); |
341 | color[2].setNum(newcolor.blue()); | 375 | color[2].setNum(newcolor.blue()); |
342 | 376 | ||
343 | config.writeEntry("keycolor_lines", color, QChar(',')); | 377 | config.writeEntry("keycolor_lines", color, QChar(',')); |
344 | config.write(); | 378 | config.write(); |
345 | 379 | ||
346 | keycolor_lines_button->setPalette(QPalette(newcolor)); | 380 | keycolor_lines_button->setPalette(QPalette(newcolor)); |
347 | emit reloadKeyboard(); | 381 | emit reloadKeyboard(); |
348 | } | 382 | } |
349 | void ConfigDlg::textColorClicked() { | 383 | void ConfigDlg::textColorClicked() { |
350 | 384 | ||
351 | Config config ("multikey"); | 385 | Config config ("multikey"); |
352 | config.setGroup ("colors"); | 386 | config.setGroup ("colors"); |
353 | 387 | ||
354 | QStringList color = config.readListEntry("textcolor", QChar(',')); | 388 | QStringList color = config.readListEntry("textcolor", QChar(',')); |
355 | 389 | ||
356 | QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); | 390 | QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); |
357 | 391 | ||
358 | color[0].setNum(newcolor.red()); | 392 | color[0].setNum(newcolor.red()); |
359 | color[1].setNum(newcolor.green()); | 393 | color[1].setNum(newcolor.green()); |
360 | color[2].setNum(newcolor.blue()); | 394 | color[2].setNum(newcolor.blue()); |
361 | 395 | ||
362 | config.writeEntry("textcolor", color, QChar(',')); | 396 | config.writeEntry("textcolor", color, QChar(',')); |
363 | config.write(); | 397 | config.write(); |
364 | 398 | ||
365 | textcolor_button->setPalette(QPalette(newcolor)); | 399 | textcolor_button->setPalette(QPalette(newcolor)); |
366 | emit reloadKeyboard(); | 400 | emit reloadKeyboard(); |
367 | } | 401 | } |
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp index 3f6f73b..c3ee8f3 100644 --- a/inputmethods/multikey/keyboard.cpp +++ b/inputmethods/multikey/keyboard.cpp | |||
@@ -1,293 +1,292 @@ | |||
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> | ||
38 | 37 | ||
39 | #include <sys/utsname.h> | 38 | #include <sys/utsname.h> |
40 | 39 | ||
41 | 40 | ||
42 | /* Keyboard::Keyboard {{{1 */ | 41 | /* Keyboard::Keyboard {{{1 */ |
43 | Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : | 42 | Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : |
44 | QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), alt(0), meta(0), | 43 | QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), alt(0), meta(0), |
45 | useLargeKeys(TRUE), usePicks(0), useRepeat(0), pressedKeyRow(-1), pressedKeyCol(-1), | 44 | useLargeKeys(TRUE), usePicks(0), useRepeat(0), pressedKeyRow(-1), pressedKeyCol(-1), |
46 | unicode(-1), qkeycode(0), modifiers(0), schar(0), mchar(0), echar(0), | 45 | unicode(-1), qkeycode(0), modifiers(0), schar(0), mchar(0), echar(0), |
47 | configdlg(0) | 46 | configdlg(0) |
48 | 47 | ||
49 | { | 48 | { |
50 | 49 | ||
51 | // get the default font | 50 | // get the default font |
52 | Config *config = new Config( "qpe" ); | 51 | Config *config = new Config( "qpe" ); |
53 | config->setGroup( "Appearance" ); | 52 | config->setGroup( "Appearance" ); |
54 | QString familyStr = config->readEntry( "FontFamily", "fixed" ); | 53 | QString familyStr = config->readEntry( "FontFamily", "fixed" ); |
55 | delete config; | 54 | delete config; |
56 | 55 | ||
57 | config = new Config("multikey"); | 56 | config = new Config("multikey"); |
58 | config->setGroup ("general"); | 57 | config->setGroup ("general"); |
59 | usePicks = config->readBoolEntry ("usePickboard", "0"); // default closed | 58 | usePicks = config->readBoolEntry ("usePickboard", "0"); // default closed |
60 | useRepeat = config->readBoolEntry ("useRepeat", "1"); | 59 | useRepeat = config->readBoolEntry ("useRepeat", "1"); |
61 | delete config; | 60 | delete config; |
62 | 61 | ||
63 | 62 | ||
64 | setFont( QFont( familyStr, 10 ) ); | 63 | setFont( QFont( familyStr, 10 ) ); |
65 | 64 | ||
66 | picks = new KeyboardPicks( this ); | 65 | picks = new KeyboardPicks( this ); |
67 | picks->setFont( QFont( familyStr, 10 ) ); | 66 | picks->setFont( QFont( familyStr, 10 ) ); |
68 | picks->initialise(); | 67 | picks->initialise(); |
69 | if (usePicks) { | 68 | if (usePicks) { |
70 | 69 | ||
71 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), | 70 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), |
72 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); | 71 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); |
73 | 72 | ||
74 | } else picks->hide(); | 73 | } else picks->hide(); |
75 | 74 | ||
76 | loadKeyboardColors(); | 75 | loadKeyboardColors(); |
77 | 76 | ||
78 | keys = new Keys(); | 77 | keys = new Keys(); |
79 | 78 | ||
80 | repeatTimer = new QTimer( this ); | 79 | repeatTimer = new QTimer( this ); |
81 | connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); | 80 | connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); |
82 | 81 | ||
83 | } | 82 | } |
84 | 83 | ||
85 | Keyboard::~Keyboard() { | 84 | Keyboard::~Keyboard() { |
86 | 85 | ||
87 | if ( configdlg ) { | 86 | if ( configdlg ) { |
88 | delete (ConfigDlg *) configdlg; | 87 | delete (ConfigDlg *) configdlg; |
89 | configdlg = 0; | 88 | configdlg = 0; |
90 | } | 89 | } |
91 | 90 | ||
92 | } | 91 | } |
93 | 92 | ||
94 | /* Keyboard::resizeEvent {{{1 */ | 93 | /* Keyboard::resizeEvent {{{1 */ |
95 | void Keyboard::resizeEvent(QResizeEvent*) | 94 | void Keyboard::resizeEvent(QResizeEvent*) |
96 | { | 95 | { |
97 | int ph = picks->sizeHint().height(); | 96 | int ph = picks->sizeHint().height(); |
98 | picks->setGeometry( 0, 0, width(), ph ); | 97 | picks->setGeometry( 0, 0, width(), ph ); |
99 | keyHeight = (height()-(usePicks ? ph : 0))/5; | 98 | keyHeight = (height()-(usePicks ? ph : 0))/5; |
100 | 99 | ||
101 | int nk; // number of keys? | 100 | int nk; // number of keys? |
102 | if ( useLargeKeys ) { | 101 | if ( useLargeKeys ) { |
103 | nk = 15; | 102 | nk = 15; |
104 | } else { | 103 | } else { |
105 | nk = 19; | 104 | nk = 19; |
106 | } | 105 | } |
107 | defaultKeyWidth = (width()/nk)/2; | 106 | defaultKeyWidth = (width()/nk)/2; |
108 | xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces? | 107 | xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces? |
109 | 108 | ||
110 | } | 109 | } |
111 | 110 | ||
112 | /* KeyboardPicks::initialize {{{1 */ | 111 | /* KeyboardPicks::initialize {{{1 */ |
113 | void KeyboardPicks::initialise() | 112 | void KeyboardPicks::initialise() |
114 | { | 113 | { |
115 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); | 114 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); |
116 | mode = 0; | 115 | mode = 0; |
117 | dc = new KeyboardConfig(this); | 116 | dc = new KeyboardConfig(this); |
118 | configs.append(dc); | 117 | configs.append(dc); |
119 | } | 118 | } |
120 | 119 | ||
121 | /* KeyboardPicks::sizeHint {{{1 */ | 120 | /* KeyboardPicks::sizeHint {{{1 */ |
122 | QSize KeyboardPicks::sizeHint() const | 121 | QSize KeyboardPicks::sizeHint() const |
123 | { | 122 | { |
124 | return QSize(240,fontMetrics().lineSpacing()); | 123 | return QSize(240,fontMetrics().lineSpacing()); |
125 | } | 124 | } |
126 | 125 | ||
127 | 126 | ||
128 | /* KeyboardConfig::generateText {{{1 */ | 127 | /* KeyboardConfig::generateText {{{1 */ |
129 | void KeyboardConfig::generateText(const QString &s) | 128 | void KeyboardConfig::generateText(const QString &s) |
130 | { | 129 | { |
131 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 130 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
132 | for (int i=0; i<(int)backspaces; i++) { | 131 | for (int i=0; i<(int)backspaces; i++) { |
133 | parent->emitKey( 0, Qt::Key_Backspace, 0, true, false ); | 132 | parent->emitKey( 0, Qt::Key_Backspace, 0, true, false ); |
134 | parent->emitKey( 0, Qt::Key_Backspace, 0, false, false ); | 133 | parent->emitKey( 0, Qt::Key_Backspace, 0, false, false ); |
135 | } | 134 | } |
136 | for (int i=0; i<(int)s.length(); i++) { | 135 | for (int i=0; i<(int)s.length(); i++) { |
137 | parent->emitKey( s[i].unicode(), 0, 0, true, false ); | 136 | parent->emitKey( s[i].unicode(), 0, 0, true, false ); |
138 | parent->emitKey( s[i].unicode(), 0, 0, false, false ); | 137 | parent->emitKey( s[i].unicode(), 0, 0, false, false ); |
139 | } | 138 | } |
140 | parent->emitKey( 0, Qt::Key_Space, 0, true, false ); | 139 | parent->emitKey( 0, Qt::Key_Space, 0, true, false ); |
141 | parent->emitKey( 0, Qt::Key_Space, 0, false, false ); | 140 | parent->emitKey( 0, Qt::Key_Space, 0, false, false ); |
142 | backspaces = 0; | 141 | backspaces = 0; |
143 | #endif | 142 | #endif |
144 | } | 143 | } |
145 | 144 | ||
146 | 145 | ||
147 | 146 | ||
148 | 147 | ||
149 | /* Keyboard::paintEvent {{{1 */ | 148 | /* Keyboard::paintEvent {{{1 */ |
150 | void Keyboard::paintEvent(QPaintEvent* e) | 149 | void Keyboard::paintEvent(QPaintEvent* e) |
151 | { | 150 | { |
152 | QPainter painter(this); | 151 | QPainter painter(this); |
153 | painter.setClipRect(e->rect()); | 152 | painter.setClipRect(e->rect()); |
154 | drawKeyboard( painter ); | 153 | drawKeyboard( painter ); |
155 | picks->dc->draw( &painter ); | 154 | picks->dc->draw( &painter ); |
156 | } | 155 | } |
157 | 156 | ||
158 | 157 | ||
159 | /* Keyboard::drawKeyboard {{{1 */ | 158 | /* Keyboard::drawKeyboard {{{1 */ |
160 | 159 | ||
161 | void Keyboard::drawKeyboard(QPainter &p, int row, int col) | 160 | void Keyboard::drawKeyboard(QPainter &p, int row, int col) |
162 | { | 161 | { |
163 | 162 | ||
164 | 163 | ||
165 | if (row != -1 && col != -1) { //just redraw one key | 164 | if (row != -1 && col != -1) { //just redraw one key |
166 | 165 | ||
167 | int x = 0; | 166 | int x = 0; |
168 | for (int i = 0; i < col; i++) { | 167 | for (int i = 0; i < col; i++) { |
169 | 168 | ||
170 | x += keys->width(row, i) * defaultKeyWidth; | 169 | x += keys->width(row, i) * defaultKeyWidth; |
171 | } | 170 | } |
172 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); | 171 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); |
173 | 172 | ||
174 | int keyWidth = keys->width(row, col); | 173 | int keyWidth = keys->width(row, col); |
175 | 174 | ||
176 | p.fillRect(x + 1, y + 1, | 175 | p.fillRect(x + 1, y + 1, |
177 | keyWidth * defaultKeyWidth - 1, keyHeight - 1, | 176 | keyWidth * defaultKeyWidth - 1, keyHeight - 1, |
178 | pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor); | 177 | pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor); |
179 | 178 | ||
180 | QImage *pix = keys->pix(row,col); | 179 | QImage *pix = keys->pix(row,col); |
181 | 180 | ||
182 | ushort c = keys->uni(row, col); | 181 | ushort c = keys->uni(row, col); |
183 | 182 | ||
184 | p.setPen(textcolor); | 183 | p.setPen(textcolor); |
185 | if (!pix) { | 184 | if (!pix) { |
186 | if (shift || lock) | 185 | if (shift || lock) |
187 | c = keys->shift(c); | 186 | c = keys->shift(c); |
188 | if (meta) { | 187 | if (meta) { |
189 | 188 | ||
190 | c = keys->meta(c); | 189 | c = keys->meta(c); |
191 | } | 190 | } |
192 | p.drawText(x, y, | 191 | p.drawText(x, y, |
193 | defaultKeyWidth * keyWidth + 3, keyHeight, | 192 | defaultKeyWidth * keyWidth + 3, keyHeight, |
194 | AlignCenter, (QChar)c); | 193 | AlignCenter, (QChar)c); |
195 | } | 194 | } |
196 | else | 195 | else |
197 | // center the image in the middle of the key | 196 | // center the image in the middle of the key |
198 | p.drawImage( x + (defaultKeyWidth * keyWidth - pix->width())/2, | 197 | p.drawImage( x + (defaultKeyWidth * keyWidth - pix->width())/2, |
199 | y + (keyHeight - pix->height())/2 + 1, | 198 | y + (keyHeight - pix->height())/2 + 1, |
200 | *pix ); | 199 | *pix ); |
201 | 200 | ||
202 | // this fixes the problem that the very right end of the board's vertical line | 201 | // this fixes the problem that the very right end of the board's vertical line |
203 | // gets painted over, because it's one pixel shorter than all other keys | 202 | // gets painted over, because it's one pixel shorter than all other keys |
204 | p.setPen(keycolor_lines); | 203 | p.setPen(keycolor_lines); |
205 | p.drawLine(width() - 1, 0, width() - 1, height()); | 204 | p.drawLine(width() - 1, 0, width() - 1, height()); |
206 | 205 | ||
207 | } else { | 206 | } else { |
208 | 207 | ||
209 | 208 | ||
210 | p.fillRect(0, 0, width(), height(), keycolor); | 209 | p.fillRect(0, 0, width(), height(), keycolor); |
211 | 210 | ||
212 | for (row = 1; row <= 5; row++) { | 211 | for (row = 1; row <= 5; row++) { |
213 | 212 | ||
214 | int x = 0; | 213 | int x = 0; |
215 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); | 214 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); |
216 | 215 | ||
217 | p.setPen(keycolor_lines); | 216 | p.setPen(keycolor_lines); |
218 | p.drawLine(x, y, x + width(), y); | 217 | p.drawLine(x, y, x + width(), y); |
219 | 218 | ||
220 | for (int col = 0; col < keys->numKeys(row); col++) { | 219 | for (int col = 0; col < keys->numKeys(row); col++) { |
221 | 220 | ||
222 | QImage *pix = keys->pix(row, col); | 221 | QImage *pix = keys->pix(row, col); |
223 | int keyWidth = keys->width(row, col); | 222 | int keyWidth = keys->width(row, col); |
224 | 223 | ||
225 | 224 | ||
226 | int keyWidthPix = defaultKeyWidth * keyWidth; | 225 | int keyWidthPix = defaultKeyWidth * keyWidth; |
227 | 226 | ||
228 | if (keys->pressed(row, col)) | 227 | if (keys->pressed(row, col)) |
229 | p.fillRect(x+1, y+1, keyWidthPix - 1, | 228 | p.fillRect(x+1, y+1, keyWidthPix - 1, |
230 | keyHeight - 1, keycolor_pressed); | 229 | keyHeight - 1, keycolor_pressed); |
231 | 230 | ||
232 | ushort c = keys->uni(row, col); | 231 | ushort c = keys->uni(row, col); |
233 | 232 | ||
234 | p.setPen(textcolor); | 233 | p.setPen(textcolor); |
235 | if (!pix) { | 234 | if (!pix) { |
236 | if ((shift || lock) && keys->shift(c)) | 235 | if ((shift || lock) && keys->shift(c)) |
237 | c = keys->shift(c); | 236 | c = keys->shift(c); |
238 | else if (meta && keys->meta(c)) | 237 | else if (meta && keys->meta(c)) |
239 | c = keys->meta(c); | 238 | c = keys->meta(c); |
240 | 239 | ||
241 | p.drawText(x, y, | 240 | p.drawText(x, y, |
242 | keyWidthPix + 3, keyHeight, | 241 | keyWidthPix + 3, keyHeight, |
243 | AlignCenter, (QChar)c); | 242 | AlignCenter, (QChar)c); |
244 | } | 243 | } |
245 | else { | 244 | else { |
246 | // center the image in the middle of the key | 245 | // center the image in the middle of the key |
247 | pix->setColor(1, textcolor.rgb()); | 246 | pix->setColor(1, textcolor.rgb()); |
248 | p.drawImage( x + (keyWidthPix - pix->width())/2, | 247 | p.drawImage( x + (keyWidthPix - pix->width())/2, |
249 | y + (keyHeight - pix->height())/2 + 1, | 248 | y + (keyHeight - pix->height())/2 + 1, |
250 | QImage(*pix) ); | 249 | QImage(*pix) ); |
251 | } | 250 | } |
252 | 251 | ||
253 | p.setPen(keycolor_lines); | 252 | p.setPen(keycolor_lines); |
254 | p.drawLine(x, y, x, y + keyHeight); | 253 | p.drawLine(x, y, x, y + keyHeight); |
255 | 254 | ||
256 | x += keyWidthPix; | 255 | x += keyWidthPix; |
257 | } | 256 | } |
258 | 257 | ||
259 | 258 | ||
260 | } | 259 | } |
261 | p.setPen(keycolor_lines); | 260 | p.setPen(keycolor_lines); |
262 | p.drawLine(0, height() - 1, width(), height() - 1); | 261 | p.drawLine(0, height() - 1, width(), height() - 1); |
263 | p.drawLine(width() - 1, 0, width() - 1, height()); | 262 | p.drawLine(width() - 1, 0, width() - 1, height()); |
264 | } | 263 | } |
265 | 264 | ||
266 | } | 265 | } |
267 | 266 | ||
268 | 267 | ||
269 | /* Keyboard::mousePressEvent {{{1 */ | 268 | /* Keyboard::mousePressEvent {{{1 */ |
270 | void Keyboard::mousePressEvent(QMouseEvent *e) | 269 | void Keyboard::mousePressEvent(QMouseEvent *e) |
271 | { | 270 | { |
272 | int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1; | 271 | int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1; |
273 | if (row > 5) row = 5; | 272 | if (row > 5) row = 5; |
274 | 273 | ||
275 | // figure out the column | 274 | // figure out the column |
276 | int col = 0; | 275 | int col = 0; |
277 | for (int w = 0; e->x() >= w; col++) | 276 | for (int w = 0; e->x() >= w; col++) |
278 | if (col < keys->numKeys(row)) // it segfaults if it trys to read past numKeys | 277 | if (col < keys->numKeys(row)) // it segfaults if it trys to read past numKeys |
279 | w += keys->width(row,col) * defaultKeyWidth; | 278 | w += keys->width(row,col) * defaultKeyWidth; |
280 | else break; | 279 | else break; |
281 | 280 | ||
282 | if (col <= 0) return; | 281 | if (col <= 0) return; |
283 | 282 | ||
284 | col --; // rewind one... | 283 | col --; // rewind one... |
285 | 284 | ||
286 | qkeycode = keys->qcode(row, col); | 285 | qkeycode = keys->qcode(row, col); |
287 | unicode = keys->uni(row, col); | 286 | unicode = keys->uni(row, col); |
288 | 287 | ||
289 | // might need to repaint if two or more of the same keys. | 288 | // might need to repaint if two or more of the same keys. |
290 | // should be faster if just paint one key even though multiple keys exist. | 289 | // should be faster if just paint one key even though multiple keys exist. |
291 | bool need_repaint = FALSE; | 290 | bool need_repaint = FALSE; |
292 | 291 | ||
293 | if (unicode == 0) { // either Qt char, or nothing | 292 | if (unicode == 0) { // either Qt char, or nothing |
@@ -349,513 +348,513 @@ void Keyboard::mousePressEvent(QMouseEvent *e) | |||
349 | need_repaint = TRUE; | 348 | need_repaint = TRUE; |
350 | 349 | ||
351 | if (shift) { | 350 | if (shift) { |
352 | *shift = 0; | 351 | *shift = 0; |
353 | shift = 0; | 352 | shift = 0; |
354 | } | 353 | } |
355 | else { | 354 | else { |
356 | shift = keys->pressedPtr(row, col); | 355 | shift = keys->pressedPtr(row, col); |
357 | *shift = 1; | 356 | *shift = 1; |
358 | if (lock) { | 357 | if (lock) { |
359 | *lock = 0; | 358 | *lock = 0; |
360 | lock = 0; | 359 | lock = 0; |
361 | } | 360 | } |
362 | } | 361 | } |
363 | if (meta) { | 362 | if (meta) { |
364 | 363 | ||
365 | *meta = 0; | 364 | *meta = 0; |
366 | meta = 0; | 365 | meta = 0; |
367 | } | 366 | } |
368 | 367 | ||
369 | } else if (qkeycode == Qt::Key_CapsLock) { | 368 | } else if (qkeycode == Qt::Key_CapsLock) { |
370 | need_repaint = TRUE; | 369 | need_repaint = TRUE; |
371 | 370 | ||
372 | if (lock) { | 371 | if (lock) { |
373 | *lock = 0; | 372 | *lock = 0; |
374 | lock = 0; | 373 | lock = 0; |
375 | } | 374 | } |
376 | else { | 375 | else { |
377 | lock = keys->pressedPtr(row, col);; | 376 | lock = keys->pressedPtr(row, col);; |
378 | *lock = 1; | 377 | *lock = 1; |
379 | if (shift) { | 378 | if (shift) { |
380 | *shift = 0; | 379 | *shift = 0; |
381 | shift = 0; | 380 | shift = 0; |
382 | } | 381 | } |
383 | } | 382 | } |
384 | if (meta) { | 383 | if (meta) { |
385 | 384 | ||
386 | *meta = 0; | 385 | *meta = 0; |
387 | meta = 0; | 386 | meta = 0; |
388 | } | 387 | } |
389 | 388 | ||
390 | } else if (qkeycode == Qt::Key_Meta) { | 389 | } else if (qkeycode == Qt::Key_Meta) { |
391 | need_repaint = TRUE; | 390 | need_repaint = TRUE; |
392 | 391 | ||
393 | if (meta) { | 392 | if (meta) { |
394 | *meta = 0; | 393 | *meta = 0; |
395 | meta = 0; | 394 | meta = 0; |
396 | 395 | ||
397 | } else { | 396 | } else { |
398 | 397 | ||
399 | meta = keys->pressedPtr(row, col); | 398 | meta = keys->pressedPtr(row, col); |
400 | need_repaint = TRUE; | 399 | need_repaint = TRUE; |
401 | *meta = !keys->pressed(row, col); | 400 | *meta = !keys->pressed(row, col); |
402 | } | 401 | } |
403 | 402 | ||
404 | if (shift) { | 403 | if (shift) { |
405 | 404 | ||
406 | *shift = 0; | 405 | *shift = 0; |
407 | shift = 0; | 406 | shift = 0; |
408 | 407 | ||
409 | } | 408 | } |
410 | if (lock) { | 409 | if (lock) { |
411 | 410 | ||
412 | *lock = 0; | 411 | *lock = 0; |
413 | lock = 0; | 412 | lock = 0; |
414 | 413 | ||
415 | } | 414 | } |
416 | 415 | ||
417 | // dont need to emit this key... acts same as alt | 416 | // dont need to emit this key... acts same as alt |
418 | qkeycode = 0; | 417 | qkeycode = 0; |
419 | } | 418 | } |
420 | 419 | ||
421 | } | 420 | } |
422 | else { // normal char | 421 | else { // normal char |
423 | if ((shift || lock) && keys->shift(unicode)) { | 422 | if ((shift || lock) && keys->shift(unicode)) { |
424 | unicode = keys->shift(unicode); | 423 | unicode = keys->shift(unicode); |
425 | } | 424 | } |
426 | if (meta && keys->meta(unicode)) { | 425 | if (meta && keys->meta(unicode)) { |
427 | unicode = keys->meta(unicode); | 426 | unicode = keys->meta(unicode); |
428 | } | 427 | } |
429 | } | 428 | } |
430 | 429 | ||
431 | // korean parsing | 430 | // korean parsing |
432 | if (keys->lang == "ko") { | 431 | if (keys->lang == "ko") { |
433 | 432 | ||
434 | unicode = parseKoreanInput(unicode); | 433 | unicode = parseKoreanInput(unicode); |
435 | } | 434 | } |
436 | 435 | ||
437 | modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0); | 436 | modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0); |
438 | 437 | ||
439 | if ('A' <= unicode && unicode <= 'z' && modifiers) { | 438 | if ('A' <= unicode && unicode <= 'z' && modifiers) { |
440 | 439 | ||
441 | qkeycode = QChar(unicode).upper(); | 440 | qkeycode = QChar(unicode).upper(); |
442 | unicode = qkeycode - '@'; | 441 | unicode = qkeycode - '@'; |
443 | } | 442 | } |
444 | 443 | ||
445 | QWSServer::sendKeyEvent(unicode, qkeycode, modifiers, true, false); | 444 | QWSServer::sendKeyEvent(unicode, qkeycode, modifiers, true, false); |
446 | 445 | ||
447 | // pickboard stuff | 446 | // pickboard stuff |
448 | if (usePicks) { | 447 | if (usePicks) { |
449 | 448 | ||
450 | KeyboardConfig *dc = picks->dc; | 449 | KeyboardConfig *dc = picks->dc; |
451 | 450 | ||
452 | if (dc) { | 451 | if (dc) { |
453 | if (qkeycode == Qt::Key_Backspace) { | 452 | if (qkeycode == Qt::Key_Backspace) { |
454 | dc->input.remove(dc->input.last()); // remove last input | 453 | dc->input.remove(dc->input.last()); // remove last input |
455 | dc->decBackspaces(); | 454 | dc->decBackspaces(); |
456 | } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) { | 455 | } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) { |
457 | dc->input.clear(); | 456 | dc->input.clear(); |
458 | dc->resetBackspaces(); | 457 | dc->resetBackspaces(); |
459 | } else { | 458 | } else { |
460 | dc->add(QString(QChar(unicode))); | 459 | dc->add(QString(QChar(unicode))); |
461 | dc->incBackspaces(); | 460 | dc->incBackspaces(); |
462 | } | 461 | } |
463 | } | 462 | } |
464 | picks->repaint(); | 463 | picks->repaint(); |
465 | } | 464 | } |
466 | 465 | ||
467 | 466 | ||
468 | // painting | 467 | // painting |
469 | pressed = TRUE; | 468 | pressed = TRUE; |
470 | 469 | ||
471 | pressedKeyRow = row; | 470 | pressedKeyRow = row; |
472 | pressedKeyCol = col; | 471 | pressedKeyCol = col; |
473 | 472 | ||
474 | if (need_repaint) repaint(FALSE); | 473 | if (need_repaint) repaint(FALSE); |
475 | else { // just paint the one key pressed | 474 | else { // just paint the one key pressed |
476 | 475 | ||
477 | 476 | ||
478 | 477 | ||
479 | QPainter p(this); | 478 | QPainter p(this); |
480 | drawKeyboard(p, row, col); | 479 | drawKeyboard(p, row, col); |
481 | 480 | ||
482 | } | 481 | } |
483 | 482 | ||
484 | if (useRepeat) repeatTimer->start( 800 ); | 483 | if (useRepeat) repeatTimer->start( 800 ); |
485 | //pressTid = startTimer(80); | 484 | //pressTid = startTimer(80); |
486 | 485 | ||
487 | } | 486 | } |
488 | 487 | ||
489 | 488 | ||
490 | /* Keyboard::mouseReleaseEvent {{{1 */ | 489 | /* Keyboard::mouseReleaseEvent {{{1 */ |
491 | void Keyboard::mouseReleaseEvent(QMouseEvent*) | 490 | void Keyboard::mouseReleaseEvent(QMouseEvent*) |
492 | { | 491 | { |
493 | pressed = FALSE; | 492 | pressed = FALSE; |
494 | //if ( pressTid == 0 ) | 493 | //if ( pressTid == 0 ) |
495 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 494 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
496 | if ( unicode != -1 ) { | 495 | if ( unicode != -1 ) { |
497 | emit key( unicode, qkeycode, modifiers, false, false ); | 496 | emit key( unicode, qkeycode, modifiers, false, false ); |
498 | repeatTimer->stop(); | 497 | repeatTimer->stop(); |
499 | } | 498 | } |
500 | #endif | 499 | #endif |
501 | if (shift && unicode != 0) { | 500 | if (shift && unicode != 0) { |
502 | 501 | ||
503 | 502 | ||
504 | *shift = 0; // unpress shift key | 503 | *shift = 0; // unpress shift key |
505 | shift = 0; // reset the shift pointer | 504 | shift = 0; // reset the shift pointer |
506 | repaint(FALSE); | 505 | repaint(FALSE); |
507 | 506 | ||
508 | } else if (meta && unicode != 0) { | 507 | } else if (meta && unicode != 0) { |
509 | 508 | ||
510 | *meta = 0; | 509 | *meta = 0; |
511 | meta = 0; | 510 | meta = 0; |
512 | repaint(FALSE); | 511 | repaint(FALSE); |
513 | } | 512 | } |
514 | else | 513 | else |
515 | 514 | ||
516 | clearHighlight(); | 515 | clearHighlight(); |
517 | } | 516 | } |
518 | 517 | ||
519 | /* Keyboard::timerEvent {{{1 */ | 518 | /* Keyboard::timerEvent {{{1 */ |
520 | 519 | ||
521 | /* dont know what this does, but i think it is here so that if your screen | 520 | /* dont know what this does, but i think it is here so that if your screen |
522 | * sticks (like on an ipaq) then it will stop repeating if you click another | 521 | * sticks (like on an ipaq) then it will stop repeating if you click another |
523 | * key... but who knows what anything does in this thing anyway? | 522 | * key... but who knows what anything does in this thing anyway? |
524 | 523 | ||
525 | void Keyboard::timerEvent(QTimerEvent* e) | 524 | void Keyboard::timerEvent(QTimerEvent* e) |
526 | { | 525 | { |
527 | if ( e->timerId() == pressTid ) { | 526 | if ( e->timerId() == pressTid ) { |
528 | killTimer(pressTid); | 527 | killTimer(pressTid); |
529 | pressTid = 0; | 528 | pressTid = 0; |
530 | if ( !pressed ) | 529 | if ( !pressed ) |
531 | cout << "calling clearHighlight from timerEvent\n"; | 530 | cout << "calling clearHighlight from timerEvent\n"; |
532 | //clearHighlight(); | 531 | //clearHighlight(); |
533 | } | 532 | } |
534 | } | 533 | } |
535 | */ | 534 | */ |
536 | 535 | ||
537 | void Keyboard::repeat() | 536 | void Keyboard::repeat() |
538 | { | 537 | { |
539 | 538 | ||
540 | repeatTimer->start( 200 ); | 539 | repeatTimer->start( 200 ); |
541 | emit key( unicode, qkeycode, modifiers, true, true ); | 540 | emit key( unicode, qkeycode, modifiers, true, true ); |
542 | } | 541 | } |
543 | 542 | ||
544 | void Keyboard::clearHighlight() | 543 | void Keyboard::clearHighlight() |
545 | { | 544 | { |
546 | if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) { | 545 | if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) { |
547 | int tmpRow = pressedKeyRow; | 546 | int tmpRow = pressedKeyRow; |
548 | int tmpCol = pressedKeyCol; | 547 | int tmpCol = pressedKeyCol; |
549 | 548 | ||
550 | pressedKeyRow = -1; | 549 | pressedKeyRow = -1; |
551 | pressedKeyCol = -1; | 550 | pressedKeyCol = -1; |
552 | 551 | ||
553 | QPainter p(this); | 552 | QPainter p(this); |
554 | drawKeyboard(p, tmpRow, tmpCol); | 553 | drawKeyboard(p, tmpRow, tmpCol); |
555 | } | 554 | } |
556 | } | 555 | } |
557 | 556 | ||
558 | 557 | ||
559 | /* Keyboard::sizeHint {{{1 */ | 558 | /* Keyboard::sizeHint {{{1 */ |
560 | QSize Keyboard::sizeHint() const | 559 | QSize Keyboard::sizeHint() const |
561 | { | 560 | { |
562 | QFontMetrics fm=fontMetrics(); | 561 | QFontMetrics fm=fontMetrics(); |
563 | int keyHeight = fm.lineSpacing() + 2; | 562 | int keyHeight = fm.lineSpacing() + 2; |
564 | 563 | ||
565 | return QSize( 240, keyHeight * 5 + (usePicks ? picks->sizeHint().height() : 0) + 1); | 564 | return QSize( 240, keyHeight * 5 + (usePicks ? picks->sizeHint().height() : 0) + 1); |
566 | } | 565 | } |
567 | 566 | ||
568 | 567 | ||
569 | void Keyboard::resetState() | 568 | void Keyboard::resetState() |
570 | { | 569 | { |
571 | schar = mchar = echar = 0; | 570 | schar = mchar = echar = 0; |
572 | picks->resetState(); | 571 | picks->resetState(); |
573 | } | 572 | } |
574 | 573 | ||
575 | /* Keyboard::togglePickboard {{{1 */ | 574 | /* Keyboard::togglePickboard {{{1 */ |
576 | void Keyboard::togglePickboard(bool on_off) | 575 | void Keyboard::togglePickboard(bool on_off) |
577 | { | 576 | { |
578 | usePicks = on_off; | 577 | usePicks = on_off; |
579 | if (usePicks) { | 578 | if (usePicks) { |
580 | picks->show(); | 579 | picks->show(); |
581 | //move(x(), y() - picks->height()); // not required anymore because QCopChannel::send | 580 | //move(x(), y() - picks->height()); // not required anymore because QCopChannel::send |
582 | //adjustSize(); | 581 | //adjustSize(); |
583 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), | 582 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), |
584 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); | 583 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); |
585 | } else { | 584 | } else { |
586 | 585 | ||
587 | picks->hide(); | 586 | picks->hide(); |
588 | picks->resetState(); | 587 | picks->resetState(); |
589 | //move(x(), y() + picks->height()); | 588 | //move(x(), y() + picks->height()); |
590 | //adjustSize(); | 589 | //adjustSize(); |
591 | QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), | 590 | QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), |
592 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); | 591 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); |
593 | 592 | ||
594 | } | 593 | } |
595 | /* | 594 | /* |
596 | * this closes && opens the input method | 595 | * this closes && opens the input method |
597 | */ | 596 | */ |
598 | QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); | 597 | QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); |
599 | QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); | 598 | QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); |
600 | } | 599 | } |
601 | 600 | ||
602 | void Keyboard::toggleRepeat(bool on) { | 601 | void Keyboard::toggleRepeat(bool on) { |
603 | 602 | ||
604 | useRepeat = on; | 603 | useRepeat = on; |
605 | cout << "setting useRepeat to: " << useRepeat << "\n"; | 604 | //cout << "setting useRepeat to: " << useRepeat << "\n"; |
606 | } | 605 | } |
607 | 606 | ||
608 | /* Keyboard::setMapTo ... {{{1 */ | 607 | /* Keyboard::setMapTo ... {{{1 */ |
609 | void Keyboard::setMapToDefault() { | 608 | void Keyboard::setMapToDefault() { |
610 | 609 | ||
611 | 610 | ||
612 | /* load current locale language map */ | 611 | /* load current locale language map */ |
613 | Config *config = new Config("locale"); | 612 | Config *config = new Config("locale"); |
614 | config->setGroup( "Language" ); | 613 | config->setGroup( "Language" ); |
615 | QString l = config->readEntry( "Language" , "en" ); | 614 | QString l = config->readEntry( "Language" , "en" ); |
616 | delete config; | 615 | delete config; |
617 | 616 | ||
618 | QString key_map = QPEApplication::qpeDir() + "/share/multikey/" | 617 | QString key_map = QPEApplication::qpeDir() + "/share/multikey/" |
619 | + l + ".keymap"; | 618 | + l + ".keymap"; |
620 | 619 | ||
621 | /* save change to multikey config file */ | 620 | /* save change to multikey config file */ |
622 | config = new Config("multikey"); | 621 | config = new Config("multikey"); |
623 | config->setGroup ("keymaps"); | 622 | config->setGroup ("keymaps"); |
624 | config->writeEntry ("current", key_map); // default closed | 623 | config->writeEntry ("current", key_map); // default closed |
625 | delete config; | 624 | delete config; |
626 | 625 | ||
627 | delete keys; | 626 | delete keys; |
628 | keys = new Keys(key_map); | 627 | keys = new Keys(key_map); |
629 | 628 | ||
630 | // have to repaint the keyboard | 629 | // have to repaint the keyboard |
631 | repaint(FALSE); | 630 | repaint(FALSE); |
632 | } | 631 | } |
633 | 632 | ||
634 | void Keyboard::setMapToFile(QString map) { | 633 | void Keyboard::setMapToFile(QString map) { |
635 | 634 | ||
636 | /* save change to multikey config file */ | 635 | /* save change to multikey config file */ |
637 | Config *config = new Config("multikey"); | 636 | Config *config = new Config("multikey"); |
638 | config->setGroup ("keymaps"); | 637 | config->setGroup ("keymaps"); |
639 | config->writeEntry ("current", map); // default closed | 638 | config->writeEntry ("current", map); // default closed |
640 | 639 | ||
641 | delete config; | 640 | delete config; |
642 | 641 | ||
643 | delete keys; | 642 | delete keys; |
644 | if (QFile(map).exists()) | 643 | if (QFile(map).exists()) |
645 | keys = new Keys(map); | 644 | keys = new Keys(map); |
646 | else | 645 | else |
647 | keys = new Keys(); | 646 | keys = new Keys(); |
648 | 647 | ||
649 | repaint(FALSE); | 648 | repaint(FALSE); |
650 | 649 | ||
651 | } | 650 | } |
652 | 651 | ||
653 | /* Keybaord::reloadKeyboard {{{1 */ | 652 | /* Keybaord::reloadKeyboard {{{1 */ |
654 | void Keyboard::reloadKeyboard() { | 653 | void Keyboard::reloadKeyboard() { |
655 | 654 | ||
656 | // reload colors and redraw | 655 | // reload colors and redraw |
657 | loadKeyboardColors(); | 656 | loadKeyboardColors(); |
658 | repaint(); | 657 | repaint(); |
659 | 658 | ||
660 | } | 659 | } |
661 | 660 | ||
662 | void Keyboard::loadKeyboardColors() { | 661 | void Keyboard::loadKeyboardColors() { |
663 | 662 | ||
664 | Config config ("multikey"); | 663 | Config config ("multikey"); |
665 | config.setGroup("colors"); | 664 | config.setGroup("colors"); |
666 | 665 | ||
667 | QStringList color; | 666 | QStringList color; |
668 | color = config.readListEntry("keycolor", QChar(',')); | 667 | color = config.readListEntry("keycolor", QChar(',')); |
669 | if (color.isEmpty()) { | 668 | if (color.isEmpty()) { |
670 | color = QStringList::split(",", "240,240,240"); | 669 | color = QStringList::split(",", "240,240,240"); |
671 | config.writeEntry("keycolor", color.join(",")); | 670 | config.writeEntry("keycolor", color.join(",")); |
672 | 671 | ||
673 | } | 672 | } |
674 | keycolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); | 673 | keycolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); |
675 | 674 | ||
676 | color = config.readListEntry("keycolor_pressed", QChar(',')); | 675 | color = config.readListEntry("keycolor_pressed", QChar(',')); |
677 | if (color.isEmpty()) { | 676 | if (color.isEmpty()) { |
678 | color = QStringList::split(",", "171,183,198"); | 677 | color = QStringList::split(",", "171,183,198"); |
679 | config.writeEntry("keycolor_pressed", color.join(",")); | 678 | config.writeEntry("keycolor_pressed", color.join(",")); |
680 | 679 | ||
681 | } | 680 | } |
682 | keycolor_pressed = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); | 681 | keycolor_pressed = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); |
683 | 682 | ||
684 | color = config.readListEntry("keycolor_lines", QChar(',')); | 683 | color = config.readListEntry("keycolor_lines", QChar(',')); |
685 | if (color.isEmpty()) { | 684 | if (color.isEmpty()) { |
686 | color = QStringList::split(",", "138,148,160"); | 685 | color = QStringList::split(",", "138,148,160"); |
687 | config.writeEntry("keycolor_lines", color.join(",")); | 686 | config.writeEntry("keycolor_lines", color.join(",")); |
688 | 687 | ||
689 | } | 688 | } |
690 | keycolor_lines = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); | 689 | keycolor_lines = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); |
691 | 690 | ||
692 | color = config.readListEntry("textcolor", QChar(',')); | 691 | color = config.readListEntry("textcolor", QChar(',')); |
693 | if (color.isEmpty()) { | 692 | if (color.isEmpty()) { |
694 | color = QStringList::split(",", "43,54,68"); | 693 | color = QStringList::split(",", "43,54,68"); |
695 | config.writeEntry("textcolor", color.join(",")); | 694 | config.writeEntry("textcolor", color.join(",")); |
696 | 695 | ||
697 | } | 696 | } |
698 | textcolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); | 697 | textcolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); |
699 | 698 | ||
700 | } | 699 | } |
701 | 700 | ||
702 | /* korean input functions {{{1 | 701 | /* korean input functions {{{1 |
703 | * | 702 | * |
704 | * TODO | 703 | * TODO |
705 | * one major problem with this implementation is that you can't move the | 704 | * one major problem with this implementation is that you can't move the |
706 | * cursor after inputing korean chars, otherwise it will eat up and replace | 705 | * cursor after inputing korean chars, otherwise it will eat up and replace |
707 | * the char before the cursor you move to. fix that | 706 | * the char before the cursor you move to. fix that |
708 | * | 707 | * |
709 | * make backspace delete one single char, not the whole thing if still | 708 | * make backspace delete one single char, not the whole thing if still |
710 | * editing. | 709 | * editing. |
711 | * | 710 | * |
712 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | 711 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
713 | * | 712 | * |
714 | * how korean input works | 713 | * how korean input works |
715 | * | 714 | * |
716 | * all following chars means unicode char value and are in hex | 715 | * all following chars means unicode char value and are in hex |
717 | * | 716 | * |
718 | * ÃÊÀ½ = schar (start char) | 717 | * ÃÊÀ½ = schar (start char) |
719 | * ÁßÀ½ = mchar (middle char) | 718 | * ÁßÀ½ = mchar (middle char) |
720 | * ³¡À½ = echar (end char) | 719 | * ³¡À½ = echar (end char) |
721 | * | 720 | * |
722 | * there are 19 schars. unicode position is at 1100 - 1112 | 721 | * there are 19 schars. unicode position is at 1100 - 1112 |
723 | * there are 21 mchars. unicode position is at 1161 - 1175 | 722 | * there are 21 mchars. unicode position is at 1161 - 1175 |
724 | * there are 27 echars. unicode position is at 11a8 - 11c2 | 723 | * there are 27 echars. unicode position is at 11a8 - 11c2 |
725 | * | 724 | * |
726 | * the map with everything combined is at ac00 - d7a3 | 725 | * the map with everything combined is at ac00 - d7a3 |
727 | * | 726 | * |
728 | */ | 727 | */ |
729 | 728 | ||
730 | ushort Keyboard::parseKoreanInput (ushort c) { | 729 | ushort Keyboard::parseKoreanInput (ushort c) { |
731 | 730 | ||
732 | if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c)) | 731 | if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c)) |
733 | || | 732 | || |
734 | (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode | 733 | (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode |
735 | && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) { | 734 | && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) { |
736 | 735 | ||
737 | schar = 0, mchar = 0, echar = 0; | 736 | schar = 0, mchar = 0, echar = 0; |
738 | return c; | 737 | return c; |
739 | } | 738 | } |
740 | 739 | ||
741 | if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input | 740 | if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input |
742 | 741 | ||
743 | if (schar == 0 || (schar != 0 && mchar == 0)) { | 742 | if (schar == 0 || (schar != 0 && mchar == 0)) { |
744 | schar = c; mchar = 0; echar = 0; | 743 | schar = c; mchar = 0; echar = 0; |
745 | return c; | 744 | return c; |
746 | } | 745 | } |
747 | else if (mchar != 0) { | 746 | else if (mchar != 0) { |
748 | 747 | ||
749 | if (echar == 0) { | 748 | if (echar == 0) { |
750 | 749 | ||
751 | if (!(echar = constoe(c))) { | 750 | if (!(echar = constoe(c))) { |
752 | 751 | ||
753 | schar = c; mchar = 0; echar = 0; | 752 | schar = c; mchar = 0; echar = 0; |
754 | return c; | 753 | return c; |
755 | } | 754 | } |
756 | 755 | ||
757 | } | 756 | } |
758 | else { // must figure out what the echar is | 757 | else { // must figure out what the echar is |
759 | 758 | ||
760 | if (echar == 0x11a8) { // ¤¡ | 759 | if (echar == 0x11a8) { // ¤¡ |
761 | 760 | ||
762 | if (c == 0x1100) echar = 0x11a9; // ¤¡ + ¤¡ | 761 | if (c == 0x1100) echar = 0x11a9; // ¤¡ + ¤¡ |
763 | else if (c == 0x1109) echar = 0x11aa; // ¤¡ + ¤µ | 762 | else if (c == 0x1109) echar = 0x11aa; // ¤¡ + ¤µ |
764 | else { | 763 | else { |
765 | schar = c; mchar = 0; echar = 0; | 764 | schar = c; mchar = 0; echar = 0; |
766 | return c; | 765 | return c; |
767 | } | 766 | } |
768 | 767 | ||
769 | } else if (echar == 0x11ab) { // ¤¤ | 768 | } else if (echar == 0x11ab) { // ¤¤ |
770 | 769 | ||
771 | if (c == 0x110c) echar = 0x11ac; // ¤¤ + ¤¸ | 770 | if (c == 0x110c) echar = 0x11ac; // ¤¤ + ¤¸ |
772 | else if (c == 0x1112) echar = 0x11ad; // ¤¤ + ¤¾ | 771 | else if (c == 0x1112) echar = 0x11ad; // ¤¤ + ¤¾ |
773 | else { | 772 | else { |
774 | schar = c; mchar = 0; echar = 0; | 773 | schar = c; mchar = 0; echar = 0; |
775 | return c; | 774 | return c; |
776 | } | 775 | } |
777 | 776 | ||
778 | } else if (echar == 0x11af) { // ¤© | 777 | } else if (echar == 0x11af) { // ¤© |
779 | 778 | ||
780 | if (c == 0x1100) echar = 0x11b0; // ¤© + ¤¡ | 779 | if (c == 0x1100) echar = 0x11b0; // ¤© + ¤¡ |
781 | else if (c == 0x1106) echar = 0x11b1; // ¤© + ¤± | 780 | else if (c == 0x1106) echar = 0x11b1; // ¤© + ¤± |
782 | else if (c == 0x1107) echar = 0x11b2; // ¤© + ¤² | 781 | else if (c == 0x1107) echar = 0x11b2; // ¤© + ¤² |
783 | else if (c == 0x1109) echar = 0x11b3; // ¤© + ¤µ | 782 | else if (c == 0x1109) echar = 0x11b3; // ¤© + ¤µ |
784 | else if (c == 0x1110) echar = 0x11b4; // ¤© + ¤¼ | 783 | else if (c == 0x1110) echar = 0x11b4; // ¤© + ¤¼ |
785 | else if (c == 0x1111) echar = 0x11b5; // ¤© + ¤½ | 784 | else if (c == 0x1111) echar = 0x11b5; // ¤© + ¤½ |
786 | else if (c == 0x1112) echar = 0x11b6; // ¤© + ¤¾ | 785 | else if (c == 0x1112) echar = 0x11b6; // ¤© + ¤¾ |
787 | else { | 786 | else { |
788 | schar = c; mchar = 0; echar = 0; | 787 | schar = c; mchar = 0; echar = 0; |
789 | return c; | 788 | return c; |
790 | } | 789 | } |
791 | 790 | ||
792 | } else if (echar == 0x11b8) { // ¤² | 791 | } else if (echar == 0x11b8) { // ¤² |
793 | 792 | ||
794 | if (c == 0x1109) echar = 0x11b9; // ¤² + ¤µ | 793 | if (c == 0x1109) echar = 0x11b9; // ¤² + ¤µ |
795 | else { | 794 | else { |
796 | schar = c; mchar = 0; echar = 0; | 795 | schar = c; mchar = 0; echar = 0; |
797 | return c; | 796 | return c; |
798 | } | 797 | } |
799 | 798 | ||
800 | } else if (echar == 0x11ba) { // ¤µ | 799 | } else if (echar == 0x11ba) { // ¤µ |
801 | 800 | ||
802 | if (c == 0x1109) echar = 0x11bb; // ¤µ + ¤µ | 801 | if (c == 0x1109) echar = 0x11bb; // ¤µ + ¤µ |
803 | else { | 802 | else { |
804 | schar = c; mchar = 0; echar = 0; | 803 | schar = c; mchar = 0; echar = 0; |
805 | return c; | 804 | return c; |
806 | } | 805 | } |
807 | 806 | ||
808 | } else { // if any other char, cannot combine chars | 807 | } else { // if any other char, cannot combine chars |
809 | 808 | ||
810 | schar = c; mchar = 0; echar = 0; | 809 | schar = c; mchar = 0; echar = 0; |
811 | return c; | 810 | return c; |
812 | } | 811 | } |
813 | 812 | ||
814 | unicode = echar; | 813 | unicode = echar; |
815 | } | 814 | } |
816 | } | 815 | } |
817 | 816 | ||
818 | } | 817 | } |
819 | else if (0x1161 <= c && c <= 0x1175) { // mchar was input | 818 | else if (0x1161 <= c && c <= 0x1175) { // mchar was input |
820 | 819 | ||
821 | if (schar != 0 && mchar == 0) { mchar = c; } | 820 | if (schar != 0 && mchar == 0) { mchar = c; } |
822 | 821 | ||
823 | else if (schar != 0 && mchar != 0 && echar == 0) { | 822 | else if (schar != 0 && mchar != 0 && echar == 0) { |
824 | 823 | ||
825 | switch (mchar) { | 824 | switch (mchar) { |
826 | case 0x1169: | 825 | case 0x1169: |
827 | if (c == 0x1161) mchar = 0x116a; | 826 | if (c == 0x1161) mchar = 0x116a; |
828 | else if (c == 0x1162) mchar = 0x116b; | 827 | else if (c == 0x1162) mchar = 0x116b; |
829 | else if (c == 0x1175) mchar = 0x116c; | 828 | else if (c == 0x1175) mchar = 0x116c; |
830 | else { | 829 | else { |
831 | schar = 0; mchar = 0; echar = 0; | 830 | schar = 0; mchar = 0; echar = 0; |
832 | return c; | 831 | return c; |
833 | } | 832 | } |
834 | break; | 833 | break; |
835 | case 0x116e: | 834 | case 0x116e: |
836 | if (c == 0x1165) mchar = 0x116f; | 835 | if (c == 0x1165) mchar = 0x116f; |
837 | else if (c == 0x1166) mchar = 0x1170; | 836 | else if (c == 0x1166) mchar = 0x1170; |
838 | else if (c == 0x1175) mchar = 0x1171; | 837 | else if (c == 0x1175) mchar = 0x1171; |
839 | else { | 838 | else { |
840 | schar = 0; mchar = 0; echar = 0; | 839 | schar = 0; mchar = 0; echar = 0; |
841 | return c; | 840 | return c; |
842 | } | 841 | } |
843 | break; | 842 | break; |
844 | case 0x1173: | 843 | case 0x1173: |
845 | if (c == 0x1175) mchar = 0x1174; | 844 | if (c == 0x1175) mchar = 0x1174; |
846 | else { | 845 | else { |
847 | schar = 0; mchar = 0; echar = 0; | 846 | schar = 0; mchar = 0; echar = 0; |
848 | return c; | 847 | return c; |
849 | } | 848 | } |
850 | break; | 849 | break; |
851 | default: | 850 | default: |
852 | schar = 0; mchar = 0; echar = 0; | 851 | schar = 0; mchar = 0; echar = 0; |
853 | return c; | 852 | return c; |
854 | } | 853 | } |
855 | } | 854 | } |
856 | else if (schar != 0 && mchar != 0 && echar != 0) { | 855 | else if (schar != 0 && mchar != 0 && echar != 0) { |
857 | 856 | ||
858 | emit key( 8, Qt::Key_Backspace, 0, true, false ); | 857 | emit key( 8, Qt::Key_Backspace, 0, true, false ); |
859 | 858 | ||
860 | ushort prev = 0; | 859 | ushort prev = 0; |
861 | switch (echar) { | 860 | switch (echar) { |