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