-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,2 +1,3 @@ | |||
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> |
@@ -11,14 +12,15 @@ | |||
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() ); |
@@ -27,3 +29,8 @@ ZkbWidget::ZkbWidget(QWidget* parent):QLabel(parent),keymap(0), | |||
27 | 29 | ||
28 | ZkbWidget::~ZkbWidget() { | 30 | ZkbWidget::~ZkbWidget() |
31 | { | ||
32 | if (keymap != 0) { | ||
33 | delete keymap; | ||
34 | keymap = 0; | ||
35 | } | ||
29 | } | 36 | } |
@@ -32,3 +39,3 @@ int ZkbWidget::position() | |||
32 | { | 39 | { |
33 | return 8; | 40 | return 8; |
34 | } | 41 | } |
@@ -36,55 +43,57 @@ int ZkbWidget::position() | |||
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 | } |
@@ -96,4 +105,4 @@ QSize ZkbWidget::sizeHint() const { | |||
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 | } |
@@ -101,19 +110,19 @@ void ZkbWidget::stateChanged(const QString& s) { | |||
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 | } |
@@ -121,5 +130,5 @@ void ZkbWidget::labelChanged(int id) { | |||
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 | } |
@@ -127,26 +136,26 @@ void ZkbWidget::mouseReleaseEvent(QMouseEvent*) { | |||
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 | } |
@@ -154,4 +163,4 @@ void ZkbWidget::signalReceived(const QCString& msg, const QByteArray& data) { | |||
154 | void ZkbWidget::reload() { | 163 | void ZkbWidget::reload() { |
155 | loadKeymap(); | 164 | loadKeymap(); |
156 | QCopEnvelope("QPE/System", "notBusy()"); | 165 | QCopEnvelope("QPE/System", "notBusy()"); |
157 | } | 166 | } |
@@ -159,3 +168 @@ void ZkbWidget::reload() { | |||
159 | EXPORT_OPIE_APPLET_v1( ZkbWidget ) | 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 | |||
@@ -15,24 +15,24 @@ Q_OBJECT | |||
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 | }; |
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 | |||
@@ -4,2 +4,3 @@ | |||
4 | #include <opie2/odebug.h> | 4 | #include <opie2/odebug.h> |
5 | #include <opie2/okeyfilter.h> | ||
5 | 6 | ||
@@ -248,2 +249,4 @@ Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(t | |||
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; |