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