author | alwin <alwin> | 2004-08-01 10:33:38 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-08-01 10:33:38 (UTC) |
commit | ecd0e7c523c9f190eb2b8765ef2d629aa399d635 (patch) (unidiff) | |
tree | 1ac230cbfd75b94f7d1496dc16ccb1c9af1a81be | |
parent | 142d432ef9f8215636a81c358c828d4b6986a6ad (diff) | |
download | opie-ecd0e7c523c9f190eb2b8765ef2d629aa399d635.zip opie-ecd0e7c523c9f190eb2b8765ef2d629aa399d635.tar.gz opie-ecd0e7c523c9f190eb2b8765ef2d629aa399d635.tar.bz2 |
switched keyboard filter to the new singleton class OKeyFilter from within
opiecore2 so we can better handle it.
-rw-r--r-- | noncore/applets/zkbapplet/zkbwidget.cpp | 235 | ||||
-rw-r--r-- | noncore/applets/zkbapplet/zkbwidget.h | 32 | ||||
-rw-r--r-- | noncore/apps/keyz-cfg/zkb.cpp | 3 |
3 files changed, 140 insertions, 130 deletions
diff --git a/noncore/applets/zkbapplet/zkbwidget.cpp b/noncore/applets/zkbapplet/zkbwidget.cpp index 38bfba9..8499500 100644 --- a/noncore/applets/zkbapplet/zkbwidget.cpp +++ b/noncore/applets/zkbapplet/zkbwidget.cpp | |||
@@ -1,161 +1,168 @@ | |||
1 | #include <opie2/otaskbarapplet.h> | 1 | #include <opie2/otaskbarapplet.h> |
2 | #include <opie2/okeyfilter.h> | ||
2 | #include <qpe/qcopenvelope_qws.h> | 3 | #include <qpe/qcopenvelope_qws.h> |
3 | #include <qpe/applnk.h> | 4 | #include <qpe/applnk.h> |
4 | #include <qpe/qpeapplication.h> | 5 | #include <qpe/qpeapplication.h> |
5 | #include <qpe/resource.h> | 6 | #include <qpe/resource.h> |
6 | #include <stdio.h> | 7 | #include <stdio.h> |
7 | #include <unistd.h> | 8 | #include <unistd.h> |
8 | #include "zkbwidget.h" | 9 | #include "zkbwidget.h" |
9 | #include "zkbcfg.h" | 10 | #include "zkbcfg.h" |
10 | 11 | ||
11 | using namespace Opie::Ui; | 12 | using namespace Opie::Ui; |
12 | ZkbWidget::ZkbWidget(QWidget* parent):QLabel(parent),keymap(0), | ||
13 | disabled(Resource::loadPixmap("zkb-disabled")) { | ||
14 | 13 | ||
15 | labels = new QPopupMenu(); | 14 | ZkbWidget::ZkbWidget(QWidget* parent) |
16 | connect(labels, SIGNAL(activated(int)), this, | 15 | :QLabel(parent),keymap(0),disabled(Resource::loadPixmap("zkb-disabled")) { |
17 | SLOT(labelChanged(int))); | ||
18 | 16 | ||
19 | loadKeymap(); | 17 | labels = new QPopupMenu(); |
18 | connect(labels, SIGNAL(activated(int)), this, | ||
19 | SLOT(labelChanged(int))); | ||
20 | 20 | ||
21 | channel = new QCopChannel("QPE/zkb", this); | 21 | loadKeymap(); |
22 | connect(channel, SIGNAL(received(const QCString&,const QByteArray&)), | 22 | |
23 | this, SLOT(signalReceived(const QCString&,const QByteArray&))); | 23 | channel = new QCopChannel("QPE/zkb", this); |
24 | connect(channel, SIGNAL(received(const QCString&,const QByteArray&)), | ||
25 | this, SLOT(signalReceived(const QCString&,const QByteArray&))); | ||
24 | setFixedWidth ( AppLnk::smallIconSize() ); | 26 | setFixedWidth ( AppLnk::smallIconSize() ); |
25 | setFixedHeight ( AppLnk::smallIconSize() ); | 27 | setFixedHeight ( AppLnk::smallIconSize() ); |
26 | } | 28 | } |
27 | 29 | ||
28 | ZkbWidget::~ZkbWidget() { | 30 | ZkbWidget::~ZkbWidget() |
31 | { | ||
32 | if (keymap != 0) { | ||
33 | delete keymap; | ||
34 | keymap = 0; | ||
35 | } | ||
29 | } | 36 | } |
30 | 37 | ||
31 | int ZkbWidget::position() | 38 | int ZkbWidget::position() |
32 | { | 39 | { |
33 | return 8; | 40 | return 8; |
34 | } | 41 | } |
35 | 42 | ||
36 | bool ZkbWidget::loadKeymap() { | 43 | bool ZkbWidget::loadKeymap() { |
37 | ZkbConfig c(QPEApplication::qpeDir()+"/share/zkb"); | 44 | ZkbConfig c(QPEApplication::qpeDir()+"/share/zkb"); |
38 | QFontMetrics fm(font()); | 45 | QFontMetrics fm(font()); |
39 | 46 | ||
40 | if (keymap != 0) { | 47 | if (keymap != 0) { |
41 | delete keymap; | 48 | delete keymap; |
42 | keymap = 0; | 49 | keymap = 0; |
43 | } | 50 | } |
44 | 51 | ||
45 | Keymap* km = new Keymap(); | 52 | Keymap* km = new Keymap(); |
46 | 53 | ||
47 | if (!c.load("zkb.xml", *km, "")) { | 54 | if (!c.load("zkb.xml", *km, "")) { |
48 | delete km; | 55 | delete km; |
49 | setPixmap(disabled); | 56 | setPixmap(disabled); |
50 | return false; | 57 | return false; |
51 | } | 58 | } |
52 | 59 | ||
53 | connect(km, SIGNAL(stateChanged(const QString&)), | 60 | connect(km, SIGNAL(stateChanged(const QString&)), |
54 | this, SLOT(stateChanged(const QString&))); | 61 | this, SLOT(stateChanged(const QString&))); |
55 | 62 | ||
56 | qwsServer->setKeyboardFilter(km); | 63 | Opie::Core::OKeyFilter::inst()->addHandler(km); |
57 | 64 | ||
58 | Keymap* oldkm = keymap; | 65 | Keymap* oldkm = keymap; |
59 | keymap = km; | 66 | keymap = km; |
60 | 67 | ||
61 | if (oldkm != 0) { | 68 | if (oldkm != 0) { |
62 | delete oldkm; | 69 | delete oldkm; |
63 | } | 70 | } |
64 | 71 | ||
65 | setText(keymap->getCurrentLabel()); | 72 | QString ltext = keymap->getCurrentLabel(); |
66 | 73 | if (ltext.length()==0) ltext = "??"; | |
67 | labels->clear(); | 74 | setText(ltext); |
68 | QStringList l = keymap->listLabels(); | 75 | |
69 | labels->insertItem(disabled, 0, 0); | 76 | labels->clear(); |
70 | int n = 1; | 77 | QStringList l = keymap->listLabels(); |
71 | w = 0; | 78 | labels->insertItem(disabled, 0, 0); |
72 | for(QStringList::Iterator it = l.begin(); it != l.end(); | 79 | int n = 1; |
73 | ++it, n++) { | 80 | w = 0; |
74 | 81 | for(QStringList::Iterator it = l.begin(); it != l.end(); | |
75 | // printf("label: %s\n", (const char*) (*it).utf8()); | 82 | ++it, n++) { |
76 | 83 | ||
77 | labels->insertItem(*it, n, n); | 84 | // printf("label: %s\n", (const char*) (*it).utf8()); |
78 | int lw = fm.width(*it); | 85 | |
79 | if (lw > w) { | 86 | labels->insertItem(*it, n, n); |
80 | w = lw; | 87 | int lw = fm.width(*it); |
81 | } | 88 | if (lw > w) { |
82 | } | 89 | w = lw; |
83 | 90 | } | |
84 | if (w == 0) { | 91 | } |
85 | hide(); | 92 | |
86 | } else { | 93 | if (w == 0) { |
87 | show(); | 94 | hide(); |
88 | } | 95 | } else { |
89 | return true; | 96 | show(); |
97 | } | ||
98 | return true; | ||
90 | } | 99 | } |
91 | 100 | ||
92 | QSize ZkbWidget::sizeHint() const { | 101 | QSize ZkbWidget::sizeHint() const { |
93 | return QSize(AppLnk::smallIconSize(),AppLnk::smallIconSize()); | 102 | return QSize(AppLnk::smallIconSize(),AppLnk::smallIconSize()); |
94 | } | 103 | } |
95 | 104 | ||
96 | void ZkbWidget::stateChanged(const QString& s) { | 105 | void ZkbWidget::stateChanged(const QString& s) { |
97 | //odebug << "stateChanged: " << s.utf8() << "\n" << oendl; | 106 | // odebug << "stateChanged: " << s.utf8() << "\n" << oendl; |
98 | setText(s); | 107 | setText(s); |
99 | } | 108 | } |
100 | 109 | ||
101 | void ZkbWidget::labelChanged(int id) { | 110 | void ZkbWidget::labelChanged(int id) { |
102 | if (id == 0) { | 111 | if (id == 0) { |
103 | keymap->disable(); | 112 | keymap->disable(); |
104 | setPixmap(disabled); | 113 | setPixmap(disabled); |
105 | return; | 114 | return; |
106 | } | 115 | } |
107 | 116 | ||
108 | keymap->enable(); | 117 | keymap->enable(); |
109 | 118 | ||
110 | QStringList l = keymap->listLabels(); | 119 | QStringList l = keymap->listLabels(); |
111 | QString lbl = l[id-1]; | 120 | QString lbl = l[id-1]; |
112 | 121 | ||
113 | //printf("labelChanged: %s\n", (const char*) lbl.utf8()); | 122 | // printf("labelChanged: %s\n", (const char*) lbl.utf8()); |
114 | State* state = keymap->getStateByLabel(lbl); | 123 | State* state = keymap->getStateByLabel(lbl); |
115 | if (state != 0) { | 124 | if (state != 0) { |
116 | keymap->setCurrentState(state); | 125 | keymap->setCurrentState(state); |
117 | setText(lbl); | 126 | setText(lbl); |
118 | } | 127 | } |
119 | } | 128 | } |
120 | 129 | ||
121 | void ZkbWidget::mouseReleaseEvent(QMouseEvent*) { | 130 | void ZkbWidget::mouseReleaseEvent(QMouseEvent*) { |
122 | QSize sh = labels->sizeHint(); | 131 | QSize sh = labels->sizeHint(); |
123 | QPoint p = mapToGlobal(QPoint((width()-sh.width())/2,-sh.height())); | 132 | QPoint p = mapToGlobal(QPoint((width()-sh.width())/2,-sh.height())); |
124 | labels->exec(p); | 133 | labels->exec(p); |
125 | } | 134 | } |
126 | 135 | ||
127 | void ZkbWidget::signalReceived(const QCString& msg, const QByteArray& data) { | 136 | void ZkbWidget::signalReceived(const QCString& msg, const QByteArray& data) { |
128 | QDataStream stream(data, IO_ReadOnly); | 137 | QDataStream stream(data, IO_ReadOnly); |
129 | 138 | ||
130 | if (msg == "enable()") { | 139 | if (msg == "enable()") { |
131 | keymap->enable(); | 140 | keymap->enable(); |
132 | } else if (msg == "disable()") { | 141 | } else if (msg == "disable()") { |
133 | keymap->disable(); | 142 | keymap->disable(); |
134 | } else if (msg == "reload()") { | 143 | } else if (msg == "reload()") { |
135 | QCopEnvelope("QPE/System", "busy()"); | 144 | QCopEnvelope("QPE/System", "busy()"); |
136 | QTimer::singleShot(0, this, SLOT(reload())); | 145 | QTimer::singleShot(0, this, SLOT(reload())); |
137 | } else if (msg == "switch(QString)") { | 146 | } else if (msg == "switch(QString)") { |
138 | QString lbl; | 147 | QString lbl; |
139 | stream >> lbl; | 148 | stream >> lbl; |
140 | 149 | ||
141 | if (keymap != 0) { | 150 | if (keymap != 0) { |
142 | State* state = keymap->getStateByLabel(lbl); | 151 | State* state = keymap->getStateByLabel(lbl); |
143 | if (state != 0) { | 152 | if (state != 0) { |
144 | keymap->setCurrentState(state); | 153 | keymap->setCurrentState(state); |
145 | setText(lbl); | 154 | setText(lbl); |
146 | } | 155 | } |
147 | } | 156 | } |
148 | } else if (msg == "debug(QString)") { | 157 | } else if (msg == "debug(QString)") { |
149 | QString flag; | 158 | QString flag; |
150 | stream >> flag; | 159 | stream >> flag; |
151 | } | 160 | } |
152 | } | 161 | } |
153 | 162 | ||
154 | void ZkbWidget::reload() { | 163 | void ZkbWidget::reload() { |
155 | loadKeymap(); | 164 | loadKeymap(); |
156 | QCopEnvelope("QPE/System", "notBusy()"); | 165 | QCopEnvelope("QPE/System", "notBusy()"); |
157 | } | 166 | } |
158 | 167 | ||
159 | EXPORT_OPIE_APPLET_v1( ZkbWidget ) | 168 | EXPORT_OPIE_APPLET_v1( ZkbWidget ) |
160 | |||
161 | |||
diff --git a/noncore/applets/zkbapplet/zkbwidget.h b/noncore/applets/zkbapplet/zkbwidget.h index 7c67794..9bce85a 100644 --- a/noncore/applets/zkbapplet/zkbwidget.h +++ b/noncore/applets/zkbapplet/zkbwidget.h | |||
@@ -1,39 +1,39 @@ | |||
1 | #ifndef ZKBWIDGET_H | 1 | #ifndef ZKBWIDGET_H |
2 | #define ZKBWIDGET_H | 2 | #define ZKBWIDGET_H |
3 | 3 | ||
4 | #include <qwidget.h> | 4 | #include <qwidget.h> |
5 | #include <qlabel.h> | 5 | #include <qlabel.h> |
6 | #include <qpopupmenu.h> | 6 | #include <qpopupmenu.h> |
7 | #include <qpixmap.h> | 7 | #include <qpixmap.h> |
8 | #include <qcopchannel_qws.h> | 8 | #include <qcopchannel_qws.h> |
9 | 9 | ||
10 | #include "zkb.h" | 10 | #include "zkb.h" |
11 | 11 | ||
12 | class ZkbWidget : public QLabel { | 12 | class ZkbWidget : public QLabel { |
13 | Q_OBJECT | 13 | Q_OBJECT |
14 | 14 | ||
15 | public: | 15 | public: |
16 | ZkbWidget(QWidget* parent); | 16 | ZkbWidget(QWidget* parent); |
17 | ~ZkbWidget(); | 17 | ~ZkbWidget(); |
18 | static int position(); | 18 | static int position(); |
19 | 19 | ||
20 | QSize sizeHint() const; | 20 | QSize sizeHint() const; |
21 | 21 | ||
22 | protected: | 22 | protected: |
23 | QLabel* label; | 23 | QLabel* label; |
24 | Keymap* keymap; | 24 | Keymap* keymap; |
25 | QPopupMenu* labels; | 25 | QPopupMenu* labels; |
26 | QCopChannel* channel; | 26 | QCopChannel* channel; |
27 | int w, h; | 27 | int w, h; |
28 | QPixmap disabled; | 28 | QPixmap disabled; |
29 | 29 | ||
30 | bool loadKeymap(); | 30 | bool loadKeymap(); |
31 | void mouseReleaseEvent(QMouseEvent*); | 31 | void mouseReleaseEvent(QMouseEvent*); |
32 | 32 | ||
33 | protected slots: | 33 | protected slots: |
34 | void stateChanged(const QString&); | 34 | void stateChanged(const QString&); |
35 | void labelChanged(int id); | 35 | void labelChanged(int id); |
36 | void signalReceived(const QCString& msg, const QByteArray& data); | 36 | void signalReceived(const QCString& msg, const QByteArray& data); |
37 | void reload(); | 37 | void reload(); |
38 | }; | 38 | }; |
39 | #endif | 39 | #endif |
diff --git a/noncore/apps/keyz-cfg/zkb.cpp b/noncore/apps/keyz-cfg/zkb.cpp index c9e1dc5..a357b88 100644 --- a/noncore/apps/keyz-cfg/zkb.cpp +++ b/noncore/apps/keyz-cfg/zkb.cpp | |||
@@ -1,589 +1,592 @@ | |||
1 | #include "zkb.h" | 1 | #include "zkb.h" |
2 | 2 | ||
3 | /* OPIE */ | 3 | /* OPIE */ |
4 | #include <opie2/odebug.h> | 4 | #include <opie2/odebug.h> |
5 | #include <opie2/okeyfilter.h> | ||
5 | 6 | ||
6 | #include <stdio.h> | 7 | #include <stdio.h> |
7 | 8 | ||
8 | // Implementation of Action class | 9 | // Implementation of Action class |
9 | Action::Action():state(0), keycode(0), unicode(0), flags(0) { | 10 | Action::Action():state(0), keycode(0), unicode(0), flags(0) { |
10 | } | 11 | } |
11 | 12 | ||
12 | Action::Action(State* s, ushort kc, ushort uni, int f): | 13 | Action::Action(State* s, ushort kc, ushort uni, int f): |
13 | state(s), keycode(kc), unicode(uni), flags(f) { | 14 | state(s), keycode(kc), unicode(uni), flags(f) { |
14 | } | 15 | } |
15 | 16 | ||
16 | Action::~Action() { | 17 | Action::~Action() { |
17 | } | 18 | } |
18 | 19 | ||
19 | State* Action::getState() const { | 20 | State* Action::getState() const { |
20 | return state; | 21 | return state; |
21 | } | 22 | } |
22 | 23 | ||
23 | void Action::setState(State* s) { | 24 | void Action::setState(State* s) { |
24 | state = s; | 25 | state = s; |
25 | setDefined(true); | 26 | setDefined(true); |
26 | } | 27 | } |
27 | 28 | ||
28 | bool Action::hasEvent() const { | 29 | bool Action::hasEvent() const { |
29 | return flags & Event; | 30 | return flags & Event; |
30 | } | 31 | } |
31 | 32 | ||
32 | void Action::setEvent(bool e) { | 33 | void Action::setEvent(bool e) { |
33 | flags = (flags & ~Event) | ((e) ? Event : 0); | 34 | flags = (flags & ~Event) | ((e) ? Event : 0); |
34 | 35 | ||
35 | if (e) { | 36 | if (e) { |
36 | setDefined(true); | 37 | setDefined(true); |
37 | } else { | 38 | } else { |
38 | if (state == 0) { | 39 | if (state == 0) { |
39 | setDefined(false); | 40 | setDefined(false); |
40 | } | 41 | } |
41 | } | 42 | } |
42 | } | 43 | } |
43 | 44 | ||
44 | bool Action::isDefined() const { | 45 | bool Action::isDefined() const { |
45 | return flags & Defined; | 46 | return flags & Defined; |
46 | } | 47 | } |
47 | 48 | ||
48 | void Action::setDefined(bool d) { | 49 | void Action::setDefined(bool d) { |
49 | flags = (flags & ~Defined) | ((d) ? Defined : 0); | 50 | flags = (flags & ~Defined) | ((d) ? Defined : 0); |
50 | } | 51 | } |
51 | 52 | ||
52 | int Action::getKeycode() const { | 53 | int Action::getKeycode() const { |
53 | return keycode; | 54 | return keycode; |
54 | } | 55 | } |
55 | 56 | ||
56 | void Action::setKeycode(int c) { | 57 | void Action::setKeycode(int c) { |
57 | keycode = (ushort) c; | 58 | keycode = (ushort) c; |
58 | setEvent(true); | 59 | setEvent(true); |
59 | } | 60 | } |
60 | 61 | ||
61 | int Action::getUnicode() const { | 62 | int Action::getUnicode() const { |
62 | return unicode; | 63 | return unicode; |
63 | } | 64 | } |
64 | 65 | ||
65 | void Action::setUnicode(int u) { | 66 | void Action::setUnicode(int u) { |
66 | unicode = (ushort) u; | 67 | unicode = (ushort) u; |
67 | setEvent(true); | 68 | setEvent(true); |
68 | } | 69 | } |
69 | 70 | ||
70 | int Action::getModifiers() const { | 71 | int Action::getModifiers() const { |
71 | int ret = 0; | 72 | int ret = 0; |
72 | if (flags & Shift_Mod) { | 73 | if (flags & Shift_Mod) { |
73 | ret |= Qt::ShiftButton; | 74 | ret |= Qt::ShiftButton; |
74 | } | 75 | } |
75 | 76 | ||
76 | if (flags & Ctrl_Mod) { | 77 | if (flags & Ctrl_Mod) { |
77 | ret |= Qt::ControlButton; | 78 | ret |= Qt::ControlButton; |
78 | } | 79 | } |
79 | 80 | ||
80 | if (flags & Alt_Mod) { | 81 | if (flags & Alt_Mod) { |
81 | ret |= Qt::AltButton; | 82 | ret |= Qt::AltButton; |
82 | } | 83 | } |
83 | 84 | ||
84 | if (flags & Keypad_Mod) { | 85 | if (flags & Keypad_Mod) { |
85 | ret |= Qt::Keypad; | 86 | ret |= Qt::Keypad; |
86 | } | 87 | } |
87 | 88 | ||
88 | return ret; | 89 | return ret; |
89 | } | 90 | } |
90 | 91 | ||
91 | void Action::setModifiers(int m) { | 92 | void Action::setModifiers(int m) { |
92 | int n = 0; | 93 | int n = 0; |
93 | 94 | ||
94 | if (m & Qt::ShiftButton) { | 95 | if (m & Qt::ShiftButton) { |
95 | n |= Shift_Mod; | 96 | n |= Shift_Mod; |
96 | } | 97 | } |
97 | 98 | ||
98 | if (m & Qt::ControlButton) { | 99 | if (m & Qt::ControlButton) { |
99 | n |= Ctrl_Mod; | 100 | n |= Ctrl_Mod; |
100 | } | 101 | } |
101 | 102 | ||
102 | if (m & Qt::AltButton) { | 103 | if (m & Qt::AltButton) { |
103 | n |= Alt_Mod; | 104 | n |= Alt_Mod; |
104 | } | 105 | } |
105 | 106 | ||
106 | if (m & Qt::Keypad) { | 107 | if (m & Qt::Keypad) { |
107 | n |= Keypad_Mod; | 108 | n |= Keypad_Mod; |
108 | } | 109 | } |
109 | 110 | ||
110 | flags = flags & ~Mod_Bits | n; | 111 | flags = flags & ~Mod_Bits | n; |
111 | setEvent(true); | 112 | setEvent(true); |
112 | } | 113 | } |
113 | 114 | ||
114 | bool Action::isPressed() const { | 115 | bool Action::isPressed() const { |
115 | return (flags & Press) != 0; | 116 | return (flags & Press) != 0; |
116 | } | 117 | } |
117 | 118 | ||
118 | void Action::setPressed(bool p) { | 119 | void Action::setPressed(bool p) { |
119 | flags = (flags & ~Press) | ((p) ? Press : 0); | 120 | flags = (flags & ~Press) | ((p) ? Press : 0); |
120 | setEvent(true); | 121 | setEvent(true); |
121 | } | 122 | } |
122 | 123 | ||
123 | bool Action::isAutorepeat() const { | 124 | bool Action::isAutorepeat() const { |
124 | return (flags & Autorepeat) != 0; | 125 | return (flags & Autorepeat) != 0; |
125 | } | 126 | } |
126 | 127 | ||
127 | void Action::setAutorepeat(bool p) { | 128 | void Action::setAutorepeat(bool p) { |
128 | flags = (flags & ~Autorepeat) | ((p) ? Autorepeat : 0); | 129 | flags = (flags & ~Autorepeat) | ((p) ? Autorepeat : 0); |
129 | setEvent(true); | 130 | setEvent(true); |
130 | } | 131 | } |
131 | 132 | ||
132 | // Implementation of State class | 133 | // Implementation of State class |
133 | const short State::x1[] = { /* from 0x20 to 0x5f */ | 134 | const short State::x1[] = { /* from 0x20 to 0x5f */ |
134 | 31, 0, 28, 3, 5, 6, 9, 28, /* 0x20 - 0x27 */ | 135 | 31, 0, 28, 3, 5, 6, 9, 28, /* 0x20 - 0x27 */ |
135 | 11, 26, 10, 13, 26, 1, 29, 27, /* 0x28 - 0x2f */ | 136 | 11, 26, 10, 13, 26, 1, 29, 27, /* 0x28 - 0x2f */ |
136 | 15, 16, 22, 4, 17, 19, 24, 20, /* 0x30 - 0x37 */ | 137 | 15, 16, 22, 4, 17, 19, 24, 20, /* 0x30 - 0x37 */ |
137 | 8, 14, 29, 26, 29, 12, 32, 27, /* 0x38 - 0x3f */ | 138 | 8, 14, 29, 26, 29, 12, 32, 27, /* 0x38 - 0x3f */ |
138 | 18, 0, 1, 2, 3, 4, 5, 6, /* 0x40 - 0x47 */ | 139 | 18, 0, 1, 2, 3, 4, 5, 6, /* 0x40 - 0x47 */ |
139 | 7, 8, 9, 10, 11, 12, 13, 14, /* 0x48 - 0x4f */ | 140 | 7, 8, 9, 10, 11, 12, 13, 14, /* 0x48 - 0x4f */ |
140 | 15, 16, 17, 18, 19, 20, 21, 22, /* 0x50 - 0x57 */ | 141 | 15, 16, 17, 18, 19, 20, 21, 22, /* 0x50 - 0x57 */ |
141 | 23, 24, 25, 30, -1, 26, 28, 7, /* 0x58 - 0x5f */ | 142 | 23, 24, 25, 30, -1, 26, 28, 7, /* 0x58 - 0x5f */ |
142 | 31, -1, -1, -1, -1, -1, -1, -1, /* 0x60 - 0x67 */ | 143 | 31, -1, -1, -1, -1, -1, -1, -1, /* 0x60 - 0x67 */ |
143 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x68 - 0x6f */ | 144 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x68 - 0x6f */ |
144 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70 - 0x77 */ | 145 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70 - 0x77 */ |
145 | -1, -1, -1, 29, 31, 32, 32, 28, /* 0x78 - 0x7f */ | 146 | -1, -1, -1, 29, 31, 32, 32, 28, /* 0x78 - 0x7f */ |
146 | }; | 147 | }; |
147 | 148 | ||
148 | const short State::x2[] = { /* from 0x1000 to 0x1057*/ | 149 | const short State::x2[] = { /* from 0x1000 to 0x1057*/ |
149 | 42, 36, -1, 30, 32, -1, -1, -1, /* 0x1000 - 0x1007 */ | 150 | 42, 36, -1, 30, 32, -1, -1, -1, /* 0x1000 - 0x1007 */ |
150 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1008 - 0x100f */ | 151 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1008 - 0x100f */ |
151 | -1, -1, 44, 45, 46, 47, -1, -1, /* 0x1010 - 0x1017 */ | 152 | -1, -1, 44, 45, 46, 47, -1, -1, /* 0x1010 - 0x1017 */ |
152 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1018 - 0x101f */ | 153 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1018 - 0x101f */ |
153 | 33, 35, 34, -1, 36, 27, -1, -1, /* 0x1020 - 0x1027 */ | 154 | 33, 35, 34, -1, 36, 27, -1, -1, /* 0x1020 - 0x1027 */ |
154 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1028 - 0x102f */ | 155 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1028 - 0x102f */ |
155 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1030 - 0x1037 */ | 156 | -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1030 - 0x1037 */ |
156 | 37, 38, 40, 39, 41, -1, -1, -1, /* 0x1038 - 0x103f */ | 157 | 37, 38, 40, 39, 41, -1, -1, -1, /* 0x1038 - 0x103f */ |
157 | -1, -1, -1, -1, -1, 35, -1, -1, /* 0x1040 - 0x1047 */ | 158 | -1, -1, -1, -1, -1, 35, -1, -1, /* 0x1040 - 0x1047 */ |
158 | -1, -1, -1, -1, -1, 48, -1, -1, /* 0x1048 - 0x104f */ | 159 | -1, -1, -1, -1, -1, 48, -1, -1, /* 0x1048 - 0x104f */ |
159 | 43, 49, 50, -1, -1, -1, -1, -1, /* 0x1050 - 0x1057 */ | 160 | 43, 49, 50, -1, -1, -1, -1, -1, /* 0x1050 - 0x1057 */ |
160 | }; | 161 | }; |
161 | 162 | ||
162 | State::State(State* p):parent(p), keys(0) { | 163 | State::State(State* p):parent(p), keys(0) { |
163 | keys = new Action[Key_Max * 2 + 1]; | 164 | keys = new Action[Key_Max * 2 + 1]; |
164 | } | 165 | } |
165 | 166 | ||
166 | State::State(const State& s) { | 167 | State::State(const State& s) { |
167 | parent = s.parent; | 168 | parent = s.parent; |
168 | keys = new Action[Key_Max * 2 + 1]; | 169 | keys = new Action[Key_Max * 2 + 1]; |
169 | memcpy(keys, s.keys, sizeof(Action) * (Key_Max * 2 + 1)); | 170 | memcpy(keys, s.keys, sizeof(Action) * (Key_Max * 2 + 1)); |
170 | } | 171 | } |
171 | 172 | ||
172 | State::~State() { | 173 | State::~State() { |
173 | if (keys!=0) { | 174 | if (keys!=0) { |
174 | delete [] keys; | 175 | delete [] keys; |
175 | } | 176 | } |
176 | } | 177 | } |
177 | 178 | ||
178 | Action* State::get(int keycode, bool pressed, bool follow) const { | 179 | Action* State::get(int keycode, bool pressed, bool follow) const { |
179 | Action* ret = 0; | 180 | Action* ret = 0; |
180 | int n = translateKeycode(keycode); | 181 | int n = translateKeycode(keycode); |
181 | 182 | ||
182 | if (n != -1 && keys != 0) { | 183 | if (n != -1 && keys != 0) { |
183 | if (pressed) { | 184 | if (pressed) { |
184 | n += Key_Max; | 185 | n += Key_Max; |
185 | } | 186 | } |
186 | ret = &keys[n]; | 187 | ret = &keys[n]; |
187 | } | 188 | } |
188 | 189 | ||
189 | if (ret==0 || !ret->isDefined()) { | 190 | if (ret==0 || !ret->isDefined()) { |
190 | if (follow && parent!=0) { | 191 | if (follow && parent!=0) { |
191 | ret = parent->get(keycode, pressed, follow); | 192 | ret = parent->get(keycode, pressed, follow); |
192 | } | 193 | } |
193 | } | 194 | } |
194 | 195 | ||
195 | return ret; | 196 | return ret; |
196 | } | 197 | } |
197 | 198 | ||
198 | bool State::set(int keycode, bool pressed, Action& action) { | 199 | bool State::set(int keycode, bool pressed, Action& action) { |
199 | int n = translateKeycode(keycode); | 200 | int n = translateKeycode(keycode); |
200 | 201 | ||
201 | if (n==-1 || keys==0) { | 202 | if (n==-1 || keys==0) { |
202 | return false; | 203 | return false; |
203 | } | 204 | } |
204 | 205 | ||
205 | if (pressed) { | 206 | if (pressed) { |
206 | n += Key_Max + 1; | 207 | n += Key_Max + 1; |
207 | } | 208 | } |
208 | 209 | ||
209 | keys[n] = action; | 210 | keys[n] = action; |
210 | return true; | 211 | return true; |
211 | } | 212 | } |
212 | 213 | ||
213 | State* State::getParent() const { | 214 | State* State::getParent() const { |
214 | return parent; | 215 | return parent; |
215 | } | 216 | } |
216 | 217 | ||
217 | void State::setParent(State* s) { | 218 | void State::setParent(State* s) { |
218 | parent = s; | 219 | parent = s; |
219 | } | 220 | } |
220 | 221 | ||
221 | int State::translateKeycode(int keycode) const { | 222 | int State::translateKeycode(int keycode) const { |
222 | if (keycode < 0x20) { | 223 | if (keycode < 0x20) { |
223 | return -1; | 224 | return -1; |
224 | } | 225 | } |
225 | 226 | ||
226 | if (keycode < 0x80) { | 227 | if (keycode < 0x80) { |
227 | return x1[keycode - 0x20]; | 228 | return x1[keycode - 0x20]; |
228 | } | 229 | } |
229 | 230 | ||
230 | if (keycode < 0x1000) { | 231 | if (keycode < 0x1000) { |
231 | return -1; | 232 | return -1; |
232 | } | 233 | } |
233 | 234 | ||
234 | if (keycode < 0x1057) { | 235 | if (keycode < 0x1057) { |
235 | return x2[keycode - 0x1000]; | 236 | return x2[keycode - 0x1000]; |
236 | } | 237 | } |
237 | 238 | ||
238 | return -1; | 239 | return -1; |
239 | } | 240 | } |
240 | 241 | ||
241 | // Implementation of Keymap class | 242 | // Implementation of Keymap class |
242 | Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(this) { | 243 | Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(this) { |
243 | repeatDelay=400; | 244 | repeatDelay=400; |
244 | repeatPeriod=80; | 245 | repeatPeriod=80; |
245 | connect(&repeater, SIGNAL(timeout()), this, SLOT(autoRepeat())); | 246 | connect(&repeater, SIGNAL(timeout()), this, SLOT(autoRepeat())); |
246 | } | 247 | } |
247 | 248 | ||
248 | Keymap::~Keymap() { | 249 | Keymap::~Keymap() { |
250 | odebug << "removing keyboard filter for zkb"<<oendl; | ||
251 | Opie::Core::OKeyFilter::inst()->remHandler(this); | ||
249 | QMap<QString, State*>::Iterator it; | 252 | QMap<QString, State*>::Iterator it; |
250 | for(it = states.begin(); it != states.end(); ++it) { | 253 | for(it = states.begin(); it != states.end(); ++it) { |
251 | delete it.data(); | 254 | delete it.data(); |
252 | } | 255 | } |
253 | states.clear(); | 256 | states.clear(); |
254 | } | 257 | } |
255 | 258 | ||
256 | bool Keymap::filter(int unicode, int keycode, int modifiers, | 259 | bool Keymap::filter(int unicode, int keycode, int modifiers, |
257 | bool isPress, bool autoRepeat) { | 260 | bool isPress, bool autoRepeat) { |
258 | 261 | ||
259 | odebug << "filter: >>> unicode=" << unicode << ", keycode=" << keycode | 262 | odebug << "filter: >>> unicode=" << unicode << ", keycode=" << keycode |
260 | << ", modifiers=" << modifiers << ", ispressed=" << isPress << oendl; | 263 | << ", modifiers=" << modifiers << ", ispressed=" << isPress << oendl; |
261 | 264 | ||
262 | if (!enabled) { | 265 | if (!enabled) { |
263 | return false; | 266 | return false; |
264 | } | 267 | } |
265 | 268 | ||
266 | // the second check is workaround to make suspend work if | 269 | // the second check is workaround to make suspend work if |
267 | // the user pressed it right after he did resume. for some | 270 | // the user pressed it right after he did resume. for some |
268 | // reason the event sent by qt has autoRepeat true in this | 271 | // reason the event sent by qt has autoRepeat true in this |
269 | // case | 272 | // case |
270 | if (autoRepeat && keycode != 4177) { | 273 | if (autoRepeat && keycode != 4177) { |
271 | return true; | 274 | return true; |
272 | } | 275 | } |
273 | 276 | ||
274 | (void) unicode; (void) modifiers; | 277 | (void) unicode; (void) modifiers; |
275 | 278 | ||
276 | Action* action = currentState->get(keycode, isPress, true); | 279 | Action* action = currentState->get(keycode, isPress, true); |
277 | if (action==0 || !action->isDefined()) { | 280 | if (action==0 || !action->isDefined()) { |
278 | return true; | 281 | return true; |
279 | } | 282 | } |
280 | 283 | ||
281 | if (action->hasEvent()) { | 284 | if (action->hasEvent()) { |
282 | odebug << "filter:<<< unicode=" << action->getUnicode() << ", keycode=" << action->getKeycode() | 285 | odebug << "filter:<<< unicode=" << action->getUnicode() << ", keycode=" << action->getKeycode() |
283 | << ", modifiers=" << action->getModifiers() << ", ispressed=" << action->isPressed() << oendl; | 286 | << ", modifiers=" << action->getModifiers() << ", ispressed=" << action->isPressed() << oendl; |
284 | 287 | ||
285 | QWSServer::sendKeyEvent(action->getUnicode(), | 288 | QWSServer::sendKeyEvent(action->getUnicode(), |
286 | action->getKeycode(), action->getModifiers(), | 289 | action->getKeycode(), action->getModifiers(), |
287 | action->isPressed(), false); | 290 | action->isPressed(), false); |
288 | } | 291 | } |
289 | 292 | ||
290 | if (action->isAutorepeat()) { | 293 | if (action->isAutorepeat()) { |
291 | autoRepeatAction = action; | 294 | autoRepeatAction = action; |
292 | repeater.start(repeatDelay, TRUE); | 295 | repeater.start(repeatDelay, TRUE); |
293 | } else { | 296 | } else { |
294 | autoRepeatAction = 0; | 297 | autoRepeatAction = 0; |
295 | } | 298 | } |
296 | 299 | ||
297 | State* nstate = action->getState(); | 300 | State* nstate = action->getState(); |
298 | if (nstate != 0) { | 301 | if (nstate != 0) { |
299 | setCurrentState(nstate); | 302 | setCurrentState(nstate); |
300 | QString lbl = getCurrentLabel(); | 303 | QString lbl = getCurrentLabel(); |
301 | if (!lbl.isEmpty()) { | 304 | if (!lbl.isEmpty()) { |
302 | emit stateChanged(lbl); | 305 | emit stateChanged(lbl); |
303 | } | 306 | } |
304 | } | 307 | } |
305 | 308 | ||
306 | 309 | ||
307 | return true; | 310 | return true; |
308 | } | 311 | } |
309 | 312 | ||
310 | void Keymap::enable() { | 313 | void Keymap::enable() { |
311 | enabled = true; | 314 | enabled = true; |
312 | } | 315 | } |
313 | 316 | ||
314 | void Keymap::disable() { | 317 | void Keymap::disable() { |
315 | enabled = false; | 318 | enabled = false; |
316 | } | 319 | } |
317 | 320 | ||
318 | QStringList Keymap::listStates() { | 321 | QStringList Keymap::listStates() { |
319 | QStringList ret; | 322 | QStringList ret; |
320 | 323 | ||
321 | QMap<QString, State*>::Iterator it; | 324 | QMap<QString, State*>::Iterator it; |
322 | for(it = states.begin(); it != states.end(); ++it) { | 325 | for(it = states.begin(); it != states.end(); ++it) { |
323 | ret.append(it.key()); | 326 | ret.append(it.key()); |
324 | } | 327 | } |
325 | 328 | ||
326 | return ret; | 329 | return ret; |
327 | } | 330 | } |
328 | 331 | ||
329 | State* Keymap::getStateByName(const QString& name) { | 332 | State* Keymap::getStateByName(const QString& name) { |
330 | QMap<QString, State*>::Iterator it = states.find(name); | 333 | QMap<QString, State*>::Iterator it = states.find(name); |
331 | 334 | ||
332 | if (it == states.end()) { | 335 | if (it == states.end()) { |
333 | return 0; | 336 | return 0; |
334 | } | 337 | } |
335 | 338 | ||
336 | return it.data(); | 339 | return it.data(); |
337 | } | 340 | } |
338 | 341 | ||
339 | QStringList Keymap::listLabels() { | 342 | QStringList Keymap::listLabels() { |
340 | QStringList ret; | 343 | QStringList ret; |
341 | 344 | ||
342 | for(uint i = 0; i < labelList.count(); i++) { | 345 | for(uint i = 0; i < labelList.count(); i++) { |
343 | ret.append(*labelList.at(i)); | 346 | ret.append(*labelList.at(i)); |
344 | } | 347 | } |
345 | 348 | ||
346 | return ret; | 349 | return ret; |
347 | } | 350 | } |
348 | 351 | ||
349 | State* Keymap::getStateByLabel(const QString& label) { | 352 | State* Keymap::getStateByLabel(const QString& label) { |
350 | QMap<QString, QString>::Iterator lit = labels.find(label); | 353 | QMap<QString, QString>::Iterator lit = labels.find(label); |
351 | State* state = 0; | 354 | State* state = 0; |
352 | 355 | ||
353 | if (lit == labels.end()) { | 356 | if (lit == labels.end()) { |
354 | return 0; | 357 | return 0; |
355 | } | 358 | } |
356 | 359 | ||
357 | QString name = lit.data(); | 360 | QString name = lit.data(); |
358 | 361 | ||
359 | int n = name.find(":*"); | 362 | int n = name.find(":*"); |
360 | if (n>=0 && n==(int)(name.length()-2)) { | 363 | if (n>=0 && n==(int)(name.length()-2)) { |
361 | name=name.left(name.length() - 1); | 364 | name=name.left(name.length() - 1); |
362 | 365 | ||
363 | n = currentStateName.findRev(":"); | 366 | n = currentStateName.findRev(":"); |
364 | if (n >= 0) { | 367 | if (n >= 0) { |
365 | name += currentStateName.mid(n+1); | 368 | name += currentStateName.mid(n+1); |
366 | } | 369 | } |
367 | } | 370 | } |
368 | 371 | ||
369 | // odebug << "look for: " << name.utf8() << "\n" << oendl; | 372 | // odebug << "look for: " << name.utf8() << "\n" << oendl; |
370 | QMap<QString, State*>::Iterator sit = states.find(name); | 373 | QMap<QString, State*>::Iterator sit = states.find(name); |
371 | if (sit != states.end()) { | 374 | if (sit != states.end()) { |
372 | state = sit.data(); | 375 | state = sit.data(); |
373 | } | 376 | } |
374 | 377 | ||
375 | return state; | 378 | return state; |
376 | } | 379 | } |
377 | 380 | ||
378 | bool Keymap::addState(const QString& name, State* state) { | 381 | bool Keymap::addState(const QString& name, State* state) { |
379 | if (states.find(name) != states.end()) { | 382 | if (states.find(name) != states.end()) { |
380 | return false; | 383 | return false; |
381 | } | 384 | } |
382 | 385 | ||
383 | states.insert(name, state); | 386 | states.insert(name, state); |
384 | lsmapInSync = false; | 387 | lsmapInSync = false; |
385 | 388 | ||
386 | if (currentState == 0) { | 389 | if (currentState == 0) { |
387 | setCurrentState(state); | 390 | setCurrentState(state); |
388 | } | 391 | } |
389 | 392 | ||
390 | return true; | 393 | return true; |
391 | } | 394 | } |
392 | 395 | ||
393 | State* Keymap::getCurrentState() const { | 396 | State* Keymap::getCurrentState() const { |
394 | return currentState; | 397 | return currentState; |
395 | } | 398 | } |
396 | 399 | ||
397 | QString Keymap::getCurrentLabel() { | 400 | QString Keymap::getCurrentLabel() { |
398 | return currentLabel; | 401 | return currentLabel; |
399 | } | 402 | } |
400 | 403 | ||
401 | bool Keymap::setCurrentState(State* state) { | 404 | bool Keymap::setCurrentState(State* state) { |
402 | QMap<QString, State*>::Iterator it; | 405 | QMap<QString, State*>::Iterator it; |
403 | for(it = states.begin(); it != states.end(); ++it) { | 406 | for(it = states.begin(); it != states.end(); ++it) { |
404 | State* s = it.data(); | 407 | State* s = it.data(); |
405 | if (s == state) { | 408 | if (s == state) { |
406 | currentState = s; | 409 | currentState = s; |
407 | currentStateName = it.key(); | 410 | currentStateName = it.key(); |
408 | 411 | ||
409 | odebug << "state changed: " << (const char*)currentStateName.utf8() << oendl; | 412 | odebug << "state changed: " << (const char*)currentStateName.utf8() << oendl; |
410 | 413 | ||
411 | if (!lsmapInSync) { | 414 | if (!lsmapInSync) { |
412 | generateLabelStateMaps(); | 415 | generateLabelStateMaps(); |
413 | } | 416 | } |
414 | 417 | ||
415 | QMap<State*, QString>::Iterator tit; | 418 | QMap<State*, QString>::Iterator tit; |
416 | tit = stateLabelMap.find(state); | 419 | tit = stateLabelMap.find(state); |
417 | if (tit != stateLabelMap.end()) { | 420 | if (tit != stateLabelMap.end()) { |
418 | currentLabel = tit.data(); | 421 | currentLabel = tit.data(); |
419 | } else { | 422 | } else { |
420 | // odebug << "no label for: " + currentStateName + "\n" << oendl; | 423 | // odebug << "no label for: " + currentStateName + "\n" << oendl; |
421 | currentLabel = ""; | 424 | currentLabel = ""; |
422 | } | 425 | } |
423 | 426 | ||
424 | return true; | 427 | return true; |
425 | } | 428 | } |
426 | } | 429 | } |
427 | 430 | ||
428 | return false; | 431 | return false; |
429 | } | 432 | } |
430 | 433 | ||
431 | bool Keymap::removeState(const QString& name, bool force) { | 434 | bool Keymap::removeState(const QString& name, bool force) { |
432 | QMap<QString, State*>::Iterator it = states.find(name); | 435 | QMap<QString, State*>::Iterator it = states.find(name); |
433 | 436 | ||
434 | if (it == states.end()) { | 437 | if (it == states.end()) { |
435 | return false; | 438 | return false; |
436 | } | 439 | } |
437 | 440 | ||
438 | State* state = it.data(); | 441 | State* state = it.data(); |
439 | QList<Action> acts = findStateUsage(state); | 442 | QList<Action> acts = findStateUsage(state); |
440 | 443 | ||
441 | if (!acts.isEmpty()) { | 444 | if (!acts.isEmpty()) { |
442 | if (!force) { | 445 | if (!force) { |
443 | return false; | 446 | return false; |
444 | } else { | 447 | } else { |
445 | for(Action* a = acts.first(); a != 0; a = acts.next()) { | 448 | for(Action* a = acts.first(); a != 0; a = acts.next()) { |
446 | a->setState(0); | 449 | a->setState(0); |
447 | } | 450 | } |
448 | } | 451 | } |
449 | } | 452 | } |
450 | 453 | ||
451 | if (state == currentState) { | 454 | if (state == currentState) { |
452 | if (states.begin() != states.end()) { | 455 | if (states.begin() != states.end()) { |
453 | setCurrentState(states.begin().data()); | 456 | setCurrentState(states.begin().data()); |
454 | } | 457 | } |
455 | } | 458 | } |
456 | 459 | ||
457 | states.remove(it); | 460 | states.remove(it); |
458 | delete state; | 461 | delete state; |
459 | 462 | ||
460 | lsmapInSync = false; | 463 | lsmapInSync = false; |
461 | 464 | ||
462 | return true; | 465 | return true; |
463 | } | 466 | } |
464 | 467 | ||
465 | void Keymap::autoRepeat() { | 468 | void Keymap::autoRepeat() { |
466 | if (autoRepeatAction != 0) { | 469 | if (autoRepeatAction != 0) { |
467 | odebug << "filter:<<< unicode=" << autoRepeatAction->getUnicode() | 470 | odebug << "filter:<<< unicode=" << autoRepeatAction->getUnicode() |
468 | << ", keycode=" << autoRepeatAction->getKeycode() | 471 | << ", keycode=" << autoRepeatAction->getKeycode() |
469 | << ", modifiers=" << autoRepeatAction->getModifiers() | 472 | << ", modifiers=" << autoRepeatAction->getModifiers() |
470 | << "ispressed=" << autoRepeatAction->isPressed() << oendl; | 473 | << "ispressed=" << autoRepeatAction->isPressed() << oendl; |
471 | 474 | ||
472 | QWSServer::sendKeyEvent(autoRepeatAction->getUnicode(), | 475 | QWSServer::sendKeyEvent(autoRepeatAction->getUnicode(), |
473 | autoRepeatAction->getKeycode(), | 476 | autoRepeatAction->getKeycode(), |
474 | autoRepeatAction->getModifiers(), | 477 | autoRepeatAction->getModifiers(), |
475 | autoRepeatAction->isPressed(), true); | 478 | autoRepeatAction->isPressed(), true); |
476 | } | 479 | } |
477 | 480 | ||
478 | repeater.start(repeatPeriod, TRUE); | 481 | repeater.start(repeatPeriod, TRUE); |
479 | } | 482 | } |
480 | 483 | ||
481 | bool Keymap::addLabel(const QString& label, const QString& state, int index) { | 484 | bool Keymap::addLabel(const QString& label, const QString& state, int index) { |
482 | if (labels.find(label) != labels.end()) { | 485 | if (labels.find(label) != labels.end()) { |
483 | return false; | 486 | return false; |
484 | } | 487 | } |
485 | 488 | ||
486 | labels.insert(label, state); | 489 | labels.insert(label, state); |
487 | const QString& l = labels.find(label).key(); | 490 | const QString& l = labels.find(label).key(); |
488 | if (index == -1) { | 491 | if (index == -1) { |
489 | labelList.append(l); | 492 | labelList.append(l); |
490 | } else { | 493 | } else { |
491 | labelList.insert(labelList.at(index), l); | 494 | labelList.insert(labelList.at(index), l); |
492 | } | 495 | } |
493 | 496 | ||
494 | lsmapInSync = false; | 497 | lsmapInSync = false; |
495 | 498 | ||
496 | return true; | 499 | return true; |
497 | } | 500 | } |
498 | 501 | ||
499 | bool Keymap::removeLabel(const QString& label) { | 502 | bool Keymap::removeLabel(const QString& label) { |
500 | 503 | ||
501 | if (labels.find(label) == labels.end()) { | 504 | if (labels.find(label) == labels.end()) { |
502 | return false; | 505 | return false; |
503 | } | 506 | } |
504 | 507 | ||
505 | labels.remove(label); | 508 | labels.remove(label); |
506 | labelList.remove(label); | 509 | labelList.remove(label); |
507 | lsmapInSync = false; | 510 | lsmapInSync = false; |
508 | 511 | ||
509 | if (label == currentLabel) { | 512 | if (label == currentLabel) { |
510 | currentLabel = ""; | 513 | currentLabel = ""; |
511 | } | 514 | } |
512 | 515 | ||
513 | return true; | 516 | return true; |
514 | } | 517 | } |
515 | 518 | ||
516 | int Keymap::getAutorepeatDelay() const { | 519 | int Keymap::getAutorepeatDelay() const { |
517 | return repeatDelay; | 520 | return repeatDelay; |
518 | } | 521 | } |
519 | 522 | ||
520 | void Keymap::setAutorepeatDelay(int n) { | 523 | void Keymap::setAutorepeatDelay(int n) { |
521 | repeatDelay = n; | 524 | repeatDelay = n; |
522 | } | 525 | } |
523 | 526 | ||
524 | int Keymap::getAutorepeatPeriod() const { | 527 | int Keymap::getAutorepeatPeriod() const { |
525 | return repeatPeriod; | 528 | return repeatPeriod; |
526 | } | 529 | } |
527 | 530 | ||
528 | void Keymap::setAutorepeatPeriod(int n) { | 531 | void Keymap::setAutorepeatPeriod(int n) { |
529 | repeatPeriod = n; | 532 | repeatPeriod = n; |
530 | } | 533 | } |
531 | 534 | ||
532 | QList<Action> Keymap::findStateUsage(State* s) { | 535 | QList<Action> Keymap::findStateUsage(State* s) { |
533 | QList<Action> ret; | 536 | QList<Action> ret; |
534 | 537 | ||
535 | QMap<QString, State*>::Iterator it; | 538 | QMap<QString, State*>::Iterator it; |
536 | for(it = states.begin(); it != states.end(); ++it) { | 539 | for(it = states.begin(); it != states.end(); ++it) { |
537 | State* state = it.data(); | 540 | State* state = it.data(); |
538 | 541 | ||
539 | for(int i = 0; i < 0x1100; i++) { | 542 | for(int i = 0; i < 0x1100; i++) { |
540 | Action* action = state->get(i, false); | 543 | Action* action = state->get(i, false); |
541 | if (action!=0 && action->getState()==s) { | 544 | if (action!=0 && action->getState()==s) { |
542 | ret.append(action); | 545 | ret.append(action); |
543 | } | 546 | } |
544 | 547 | ||
545 | action = state->get(i, true); | 548 | action = state->get(i, true); |
546 | if (action!=0 && action->getState()==s) { | 549 | if (action!=0 && action->getState()==s) { |
547 | ret.append(action); | 550 | ret.append(action); |
548 | } | 551 | } |
549 | } | 552 | } |
550 | } | 553 | } |
551 | 554 | ||
552 | return ret; | 555 | return ret; |
553 | } | 556 | } |
554 | 557 | ||
555 | void Keymap::generateLabelStateMaps() { | 558 | void Keymap::generateLabelStateMaps() { |
556 | stateLabelMap.clear(); | 559 | stateLabelMap.clear(); |
557 | 560 | ||
558 | QMap<QString, QString>::Iterator lit; | 561 | QMap<QString, QString>::Iterator lit; |
559 | for(lit = labels.begin(); lit != labels.end(); ++lit) { | 562 | for(lit = labels.begin(); lit != labels.end(); ++lit) { |
560 | QString label = lit.key(); | 563 | QString label = lit.key(); |
561 | QString name = lit.data(); | 564 | QString name = lit.data(); |
562 | 565 | ||
563 | bool wc = false; | 566 | bool wc = false; |
564 | int n = name.find("*"); | 567 | int n = name.find("*"); |
565 | if (n>=0 && n==(int)(name.length()-1)) { | 568 | if (n>=0 && n==(int)(name.length()-1)) { |
566 | name=name.left(name.length() - 1); | 569 | name=name.left(name.length() - 1); |
567 | wc = true; | 570 | wc = true; |
568 | } | 571 | } |
569 | 572 | ||
570 | QMap<QString, State*>::Iterator sit; | 573 | QMap<QString, State*>::Iterator sit; |
571 | for(sit = states.begin(); sit != states.end(); ++sit) { | 574 | for(sit = states.begin(); sit != states.end(); ++sit) { |
572 | QString sname = sit.key(); | 575 | QString sname = sit.key(); |
573 | State* state = sit.data(); | 576 | State* state = sit.data(); |
574 | 577 | ||
575 | if (sname.length() < name.length()) { | 578 | if (sname.length() < name.length()) { |
576 | continue; | 579 | continue; |
577 | } | 580 | } |
578 | 581 | ||
579 | if (sname.left(name.length()) == name) { | 582 | if (sname.left(name.length()) == name) { |
580 | if (wc || sname.length()==name.length()) { | 583 | if (wc || sname.length()==name.length()) { |
581 | stateLabelMap.insert(state, label); | 584 | stateLabelMap.insert(state, label); |
582 | } | 585 | } |
583 | 586 | ||
584 | } | 587 | } |
585 | } | 588 | } |
586 | } | 589 | } |
587 | 590 | ||
588 | lsmapInSync = true; | 591 | lsmapInSync = true; |
589 | } | 592 | } |