Diffstat (limited to 'noncore/applets/zkbapplet/zkbwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/applets/zkbapplet/zkbwidget.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/applets/zkbapplet/zkbwidget.cpp b/noncore/applets/zkbapplet/zkbwidget.cpp index 0b5ab78..0083e9b 100644 --- a/noncore/applets/zkbapplet/zkbwidget.cpp +++ b/noncore/applets/zkbapplet/zkbwidget.cpp | |||
@@ -1,118 +1,118 @@ | |||
1 | #include <opie2/otaskbarapplet.h> | 1 | #include <opie2/otaskbarapplet.h> |
2 | #include <qpe/qcopenvelope_qws.h> | 2 | #include <qpe/qcopenvelope_qws.h> |
3 | #include <qpe/applnk.h> | 3 | #include <qpe/applnk.h> |
4 | #include <qpe/qpeapplication.h> | 4 | #include <qpe/qpeapplication.h> |
5 | #include <qpe/resource.h> | 5 | #include <qpe/resource.h> |
6 | #include <stdio.h> | 6 | #include <stdio.h> |
7 | #include <unistd.h> | 7 | #include <unistd.h> |
8 | #include "zkbwidget.h" | 8 | #include "zkbwidget.h" |
9 | #include "zkbcfg.h" | 9 | #include "zkbcfg.h" |
10 | 10 | ||
11 | ZkbWidget::ZkbWidget(QWidget* parent):QLabel(parent),keymap(0), | 11 | ZkbWidget::ZkbWidget(QWidget* parent):QLabel(parent),keymap(0), |
12 | disabled(Resource::loadPixmap("zkb-disabled")) { | 12 | disabled(Resource::loadPixmap("zkb-disabled")) { |
13 | 13 | ||
14 | labels = new QPopupMenu(); | 14 | labels = new QPopupMenu(); |
15 | connect(labels, SIGNAL(activated(int)), this, | 15 | connect(labels, SIGNAL(activated(int)), this, |
16 | SLOT(labelChanged(int))); | 16 | SLOT(labelChanged(int))); |
17 | 17 | ||
18 | loadKeymap(); | 18 | loadKeymap(); |
19 | 19 | ||
20 | channel = new QCopChannel("QPE/zkb", this); | 20 | channel = new QCopChannel("QPE/zkb", this); |
21 | connect(channel, SIGNAL(received(const QCString&, const QByteArray&)), | 21 | connect(channel, SIGNAL(received(const QCString&,const QByteArray&)), |
22 | this, SLOT(signalReceived(const QCString&, const QByteArray&))); | 22 | this, SLOT(signalReceived(const QCString&,const QByteArray&))); |
23 | setFixedWidth ( AppLnk::smallIconSize() ); | 23 | setFixedWidth ( AppLnk::smallIconSize() ); |
24 | setFixedHeight ( AppLnk::smallIconSize() ); | 24 | setFixedHeight ( AppLnk::smallIconSize() ); |
25 | } | 25 | } |
26 | 26 | ||
27 | ZkbWidget::~ZkbWidget() { | 27 | ZkbWidget::~ZkbWidget() { |
28 | } | 28 | } |
29 | 29 | ||
30 | int ZkbWidget::position() | 30 | int ZkbWidget::position() |
31 | { | 31 | { |
32 | return 8; | 32 | return 8; |
33 | } | 33 | } |
34 | 34 | ||
35 | bool ZkbWidget::loadKeymap() { | 35 | bool ZkbWidget::loadKeymap() { |
36 | ZkbConfig c(QPEApplication::qpeDir()+"/share/zkb"); | 36 | ZkbConfig c(QPEApplication::qpeDir()+"/share/zkb"); |
37 | QFontMetrics fm(font()); | 37 | QFontMetrics fm(font()); |
38 | 38 | ||
39 | if (keymap != 0) { | 39 | if (keymap != 0) { |
40 | delete keymap; | 40 | delete keymap; |
41 | keymap = 0; | 41 | keymap = 0; |
42 | } | 42 | } |
43 | 43 | ||
44 | Keymap* km = new Keymap(); | 44 | Keymap* km = new Keymap(); |
45 | 45 | ||
46 | if (!c.load("zkb.xml", *km, "")) { | 46 | if (!c.load("zkb.xml", *km, "")) { |
47 | delete km; | 47 | delete km; |
48 | setPixmap(disabled); | 48 | setPixmap(disabled); |
49 | return false; | 49 | return false; |
50 | } | 50 | } |
51 | 51 | ||
52 | connect(km, SIGNAL(stateChanged(const QString&)), | 52 | connect(km, SIGNAL(stateChanged(const QString&)), |
53 | this, SLOT(stateChanged(const QString&))); | 53 | this, SLOT(stateChanged(const QString&))); |
54 | 54 | ||
55 | qwsServer->setKeyboardFilter(km); | 55 | qwsServer->setKeyboardFilter(km); |
56 | 56 | ||
57 | Keymap* oldkm = keymap; | 57 | Keymap* oldkm = keymap; |
58 | keymap = km; | 58 | keymap = km; |
59 | 59 | ||
60 | if (oldkm != 0) { | 60 | if (oldkm != 0) { |
61 | delete oldkm; | 61 | delete oldkm; |
62 | } | 62 | } |
63 | 63 | ||
64 | setText(keymap->getCurrentLabel()); | 64 | setText(keymap->getCurrentLabel()); |
65 | 65 | ||
66 | labels->clear(); | 66 | labels->clear(); |
67 | QStringList l = keymap->listLabels(); | 67 | QStringList l = keymap->listLabels(); |
68 | labels->insertItem(disabled, 0, 0); | 68 | labels->insertItem(disabled, 0, 0); |
69 | int n = 1; | 69 | int n = 1; |
70 | w = 0; | 70 | w = 0; |
71 | for(QStringList::Iterator it = l.begin(); it != l.end(); | 71 | for(QStringList::Iterator it = l.begin(); it != l.end(); |
72 | ++it, n++) { | 72 | ++it, n++) { |
73 | 73 | ||
74 | // printf("label: %s\n", (const char*) (*it).utf8()); | 74 | // printf("label: %s\n", (const char*) (*it).utf8()); |
75 | 75 | ||
76 | labels->insertItem(*it, n, n); | 76 | labels->insertItem(*it, n, n); |
77 | int lw = fm.width(*it); | 77 | int lw = fm.width(*it); |
78 | if (lw > w) { | 78 | if (lw > w) { |
79 | w = lw; | 79 | w = lw; |
80 | } | 80 | } |
81 | } | 81 | } |
82 | 82 | ||
83 | if (w == 0) { | 83 | if (w == 0) { |
84 | hide(); | 84 | hide(); |
85 | } else { | 85 | } else { |
86 | show(); | 86 | show(); |
87 | } | 87 | } |
88 | return true; | 88 | return true; |
89 | } | 89 | } |
90 | 90 | ||
91 | QSize ZkbWidget::sizeHint() const { | 91 | QSize ZkbWidget::sizeHint() const { |
92 | return QSize(AppLnk::smallIconSize(),AppLnk::smallIconSize()); | 92 | return QSize(AppLnk::smallIconSize(),AppLnk::smallIconSize()); |
93 | } | 93 | } |
94 | 94 | ||
95 | void ZkbWidget::stateChanged(const QString& s) { | 95 | void ZkbWidget::stateChanged(const QString& s) { |
96 | //qDebug("stateChanged: %s\n", (const char*) s.utf8()); | 96 | //qDebug("stateChanged: %s\n", (const char*) s.utf8()); |
97 | setText(s); | 97 | setText(s); |
98 | } | 98 | } |
99 | 99 | ||
100 | void ZkbWidget::labelChanged(int id) { | 100 | void ZkbWidget::labelChanged(int id) { |
101 | if (id == 0) { | 101 | if (id == 0) { |
102 | keymap->disable(); | 102 | keymap->disable(); |
103 | setPixmap(disabled); | 103 | setPixmap(disabled); |
104 | return; | 104 | return; |
105 | } | 105 | } |
106 | 106 | ||
107 | keymap->enable(); | 107 | keymap->enable(); |
108 | 108 | ||
109 | QStringList l = keymap->listLabels(); | 109 | QStringList l = keymap->listLabels(); |
110 | QString lbl = l[id-1]; | 110 | QString lbl = l[id-1]; |
111 | 111 | ||
112 | //printf("labelChanged: %s\n", (const char*) lbl.utf8()); | 112 | //printf("labelChanged: %s\n", (const char*) lbl.utf8()); |
113 | State* state = keymap->getStateByLabel(lbl); | 113 | State* state = keymap->getStateByLabel(lbl); |
114 | if (state != 0) { | 114 | if (state != 0) { |
115 | keymap->setCurrentState(state); | 115 | keymap->setCurrentState(state); |
116 | setText(lbl); | 116 | setText(lbl); |
117 | } | 117 | } |
118 | } | 118 | } |