Diffstat (limited to 'noncore/applets/zkbapplet/applet') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/applets/zkbapplet/applet/applet.pro | 20 | ||||
-rw-r--r-- | noncore/applets/zkbapplet/applet/zkbwidget.cpp | 168 | ||||
-rw-r--r-- | noncore/applets/zkbapplet/applet/zkbwidget.h | 39 |
3 files changed, 227 insertions, 0 deletions
diff --git a/noncore/applets/zkbapplet/applet/applet.pro b/noncore/applets/zkbapplet/applet/applet.pro new file mode 100644 index 0000000..20a4c89 --- a/dev/null +++ b/noncore/applets/zkbapplet/applet/applet.pro | |||
@@ -0,0 +1,20 @@ | |||
1 | TEMPLATE = lib | ||
2 | CONFIG += qt plugin warn_on | ||
3 | HEADERS = zkbwidget.h \ | ||
4 | ../keyz-cfg/zkbcfg.h \ | ||
5 | ../keyz-cfg/zkbnames.h \ | ||
6 | ../keyz-cfg/zkbxml.h \ | ||
7 | ../keyz-cfg/zkb.h | ||
8 | SOURCES = zkbwidget.cpp \ | ||
9 | ../keyz-cfg/zkbcfg.cpp \ | ||
10 | ../keyz-cfg/zkbnames.cpp \ | ||
11 | ../keyz-cfg/zkbxml.cpp \ | ||
12 | ../keyz-cfg/zkb.cpp | ||
13 | TARGET = zkbapplet | ||
14 | DESTDIR = $(OPIEDIR)/plugins/applets | ||
15 | INCLUDEPATH += $(OPIEDIR)/include ../keyz-cfg | ||
16 | DEPENDPATH += | ||
17 | VERSION = 0.7.0 | ||
18 | LIBS += -lqpe -lopiecore2 | ||
19 | |||
20 | include ( $(OPIEDIR)/include.pro ) | ||
diff --git a/noncore/applets/zkbapplet/applet/zkbwidget.cpp b/noncore/applets/zkbapplet/applet/zkbwidget.cpp new file mode 100644 index 0000000..8499500 --- a/dev/null +++ b/noncore/applets/zkbapplet/applet/zkbwidget.cpp | |||
@@ -0,0 +1,168 @@ | |||
1 | #include <opie2/otaskbarapplet.h> | ||
2 | #include <opie2/okeyfilter.h> | ||
3 | #include <qpe/qcopenvelope_qws.h> | ||
4 | #include <qpe/applnk.h> | ||
5 | #include <qpe/qpeapplication.h> | ||
6 | #include <qpe/resource.h> | ||
7 | #include <stdio.h> | ||
8 | #include <unistd.h> | ||
9 | #include "zkbwidget.h" | ||
10 | #include "zkbcfg.h" | ||
11 | |||
12 | using namespace Opie::Ui; | ||
13 | |||
14 | ZkbWidget::ZkbWidget(QWidget* parent) | ||
15 | :QLabel(parent),keymap(0),disabled(Resource::loadPixmap("zkb-disabled")) { | ||
16 | |||
17 | labels = new QPopupMenu(); | ||
18 | connect(labels, SIGNAL(activated(int)), this, | ||
19 | SLOT(labelChanged(int))); | ||
20 | |||
21 | loadKeymap(); | ||
22 | |||
23 | channel = new QCopChannel("QPE/zkb", this); | ||
24 | connect(channel, SIGNAL(received(const QCString&,const QByteArray&)), | ||
25 | this, SLOT(signalReceived(const QCString&,const QByteArray&))); | ||
26 | setFixedWidth ( AppLnk::smallIconSize() ); | ||
27 | setFixedHeight ( AppLnk::smallIconSize() ); | ||
28 | } | ||
29 | |||
30 | ZkbWidget::~ZkbWidget() | ||
31 | { | ||
32 | if (keymap != 0) { | ||
33 | delete keymap; | ||
34 | keymap = 0; | ||
35 | } | ||
36 | } | ||
37 | |||
38 | int ZkbWidget::position() | ||
39 | { | ||
40 | return 8; | ||
41 | } | ||
42 | |||
43 | bool ZkbWidget::loadKeymap() { | ||
44 | ZkbConfig c(QPEApplication::qpeDir()+"/share/zkb"); | ||
45 | QFontMetrics fm(font()); | ||
46 | |||
47 | if (keymap != 0) { | ||
48 | delete keymap; | ||
49 | keymap = 0; | ||
50 | } | ||
51 | |||
52 | Keymap* km = new Keymap(); | ||
53 | |||
54 | if (!c.load("zkb.xml", *km, "")) { | ||
55 | delete km; | ||
56 | setPixmap(disabled); | ||
57 | return false; | ||
58 | } | ||
59 | |||
60 | connect(km, SIGNAL(stateChanged(const QString&)), | ||
61 | this, SLOT(stateChanged(const QString&))); | ||
62 | |||
63 | Opie::Core::OKeyFilter::inst()->addHandler(km); | ||
64 | |||
65 | Keymap* oldkm = keymap; | ||
66 | keymap = km; | ||
67 | |||
68 | if (oldkm != 0) { | ||
69 | delete oldkm; | ||
70 | } | ||
71 | |||
72 | QString ltext = keymap->getCurrentLabel(); | ||
73 | if (ltext.length()==0) ltext = "??"; | ||
74 | setText(ltext); | ||
75 | |||
76 | labels->clear(); | ||
77 | QStringList l = keymap->listLabels(); | ||
78 | labels->insertItem(disabled, 0, 0); | ||
79 | int n = 1; | ||
80 | w = 0; | ||
81 | for(QStringList::Iterator it = l.begin(); it != l.end(); | ||
82 | ++it, n++) { | ||
83 | |||
84 | // printf("label: %s\n", (const char*) (*it).utf8()); | ||
85 | |||
86 | labels->insertItem(*it, n, n); | ||
87 | int lw = fm.width(*it); | ||
88 | if (lw > w) { | ||
89 | w = lw; | ||
90 | } | ||
91 | } | ||
92 | |||
93 | if (w == 0) { | ||
94 | hide(); | ||
95 | } else { | ||
96 | show(); | ||
97 | } | ||
98 | return true; | ||
99 | } | ||
100 | |||
101 | QSize ZkbWidget::sizeHint() const { | ||
102 | return QSize(AppLnk::smallIconSize(),AppLnk::smallIconSize()); | ||
103 | } | ||
104 | |||
105 | void ZkbWidget::stateChanged(const QString& s) { | ||
106 | // odebug << "stateChanged: " << s.utf8() << "\n" << oendl; | ||
107 | setText(s); | ||
108 | } | ||
109 | |||
110 | void ZkbWidget::labelChanged(int id) { | ||
111 | if (id == 0) { | ||
112 | keymap->disable(); | ||
113 | setPixmap(disabled); | ||
114 | return; | ||
115 | } | ||
116 | |||
117 | keymap->enable(); | ||
118 | |||
119 | QStringList l = keymap->listLabels(); | ||
120 | QString lbl = l[id-1]; | ||
121 | |||
122 | // printf("labelChanged: %s\n", (const char*) lbl.utf8()); | ||
123 | State* state = keymap->getStateByLabel(lbl); | ||
124 | if (state != 0) { | ||
125 | keymap->setCurrentState(state); | ||
126 | setText(lbl); | ||
127 | } | ||
128 | } | ||
129 | |||
130 | void ZkbWidget::mouseReleaseEvent(QMouseEvent*) { | ||
131 | QSize sh = labels->sizeHint(); | ||
132 | QPoint p = mapToGlobal(QPoint((width()-sh.width())/2,-sh.height())); | ||
133 | labels->exec(p); | ||
134 | } | ||
135 | |||
136 | void ZkbWidget::signalReceived(const QCString& msg, const QByteArray& data) { | ||
137 | QDataStream stream(data, IO_ReadOnly); | ||
138 | |||
139 | if (msg == "enable()") { | ||
140 | keymap->enable(); | ||
141 | } else if (msg == "disable()") { | ||
142 | keymap->disable(); | ||
143 | } else if (msg == "reload()") { | ||
144 | QCopEnvelope("QPE/System", "busy()"); | ||
145 | QTimer::singleShot(0, this, SLOT(reload())); | ||
146 | } else if (msg == "switch(QString)") { | ||
147 | QString lbl; | ||
148 | stream >> lbl; | ||
149 | |||
150 | if (keymap != 0) { | ||
151 | State* state = keymap->getStateByLabel(lbl); | ||
152 | if (state != 0) { | ||
153 | keymap->setCurrentState(state); | ||
154 | setText(lbl); | ||
155 | } | ||
156 | } | ||
157 | } else if (msg == "debug(QString)") { | ||
158 | QString flag; | ||
159 | stream >> flag; | ||
160 | } | ||
161 | } | ||
162 | |||
163 | void ZkbWidget::reload() { | ||
164 | loadKeymap(); | ||
165 | QCopEnvelope("QPE/System", "notBusy()"); | ||
166 | } | ||
167 | |||
168 | EXPORT_OPIE_APPLET_v1( ZkbWidget ) | ||
diff --git a/noncore/applets/zkbapplet/applet/zkbwidget.h b/noncore/applets/zkbapplet/applet/zkbwidget.h new file mode 100644 index 0000000..9bce85a --- a/dev/null +++ b/noncore/applets/zkbapplet/applet/zkbwidget.h | |||
@@ -0,0 +1,39 @@ | |||
1 | #ifndef ZKBWIDGET_H | ||
2 | #define ZKBWIDGET_H | ||
3 | |||
4 | #include <qwidget.h> | ||
5 | #include <qlabel.h> | ||
6 | #include <qpopupmenu.h> | ||
7 | #include <qpixmap.h> | ||
8 | #include <qcopchannel_qws.h> | ||
9 | |||
10 | #include "zkb.h" | ||
11 | |||
12 | class ZkbWidget : public QLabel { | ||
13 | Q_OBJECT | ||
14 | |||
15 | public: | ||
16 | ZkbWidget(QWidget* parent); | ||
17 | ~ZkbWidget(); | ||
18 | static int position(); | ||
19 | |||
20 | QSize sizeHint() const; | ||
21 | |||
22 | protected: | ||
23 | QLabel* label; | ||
24 | Keymap* keymap; | ||
25 | QPopupMenu* labels; | ||
26 | QCopChannel* channel; | ||
27 | int w, h; | ||
28 | QPixmap disabled; | ||
29 | |||
30 | bool loadKeymap(); | ||
31 | void mouseReleaseEvent(QMouseEvent*); | ||
32 | |||
33 | protected slots: | ||
34 | void stateChanged(const QString&); | ||
35 | void labelChanged(int id); | ||
36 | void signalReceived(const QCString& msg, const QByteArray& data); | ||
37 | void reload(); | ||
38 | }; | ||
39 | #endif | ||