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