author | alwin <alwin> | 2004-08-01 10:33:38 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-08-01 10:33:38 (UTC) |
commit | ecd0e7c523c9f190eb2b8765ef2d629aa399d635 (patch) (side-by-side diff) | |
tree | 1ac230cbfd75b94f7d1496dc16ccb1c9af1a81be /noncore/applets/zkbapplet | |
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 |
2 files changed, 137 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 @@ #include <opie2/otaskbarapplet.h> +#include <opie2/okeyfilter.h> #include <qpe/qcopenvelope_qws.h> @@ -11,14 +12,15 @@ using namespace Opie::Ui; -ZkbWidget::ZkbWidget(QWidget* parent):QLabel(parent),keymap(0), - disabled(Resource::loadPixmap("zkb-disabled")) { - labels = new QPopupMenu(); - connect(labels, SIGNAL(activated(int)), this, - SLOT(labelChanged(int))); +ZkbWidget::ZkbWidget(QWidget* parent) + :QLabel(parent),keymap(0),disabled(Resource::loadPixmap("zkb-disabled")) { - loadKeymap(); + labels = new QPopupMenu(); + connect(labels, SIGNAL(activated(int)), this, + SLOT(labelChanged(int))); - channel = new QCopChannel("QPE/zkb", this); - connect(channel, SIGNAL(received(const QCString&,const QByteArray&)), - this, SLOT(signalReceived(const QCString&,const QByteArray&))); + loadKeymap(); + + channel = new QCopChannel("QPE/zkb", this); + connect(channel, SIGNAL(received(const QCString&,const QByteArray&)), + this, SLOT(signalReceived(const QCString&,const QByteArray&))); setFixedWidth ( AppLnk::smallIconSize() ); @@ -27,3 +29,8 @@ ZkbWidget::ZkbWidget(QWidget* parent):QLabel(parent),keymap(0), -ZkbWidget::~ZkbWidget() { +ZkbWidget::~ZkbWidget() +{ + if (keymap != 0) { + delete keymap; + keymap = 0; + } } @@ -32,3 +39,3 @@ int ZkbWidget::position() { - return 8; + return 8; } @@ -36,55 +43,57 @@ int ZkbWidget::position() bool ZkbWidget::loadKeymap() { - ZkbConfig c(QPEApplication::qpeDir()+"/share/zkb"); - QFontMetrics fm(font()); - - if (keymap != 0) { - delete keymap; - keymap = 0; - } - - Keymap* km = new Keymap(); - - if (!c.load("zkb.xml", *km, "")) { - delete km; - setPixmap(disabled); - return false; - } - - connect(km, SIGNAL(stateChanged(const QString&)), - this, SLOT(stateChanged(const QString&))); - - qwsServer->setKeyboardFilter(km); - - Keymap* oldkm = keymap; - keymap = km; - - if (oldkm != 0) { - delete oldkm; - } - - setText(keymap->getCurrentLabel()); - - labels->clear(); - QStringList l = keymap->listLabels(); - labels->insertItem(disabled, 0, 0); - int n = 1; - w = 0; - for(QStringList::Iterator it = l.begin(); it != l.end(); - ++it, n++) { - -// printf("label: %s\n", (const char*) (*it).utf8()); - - labels->insertItem(*it, n, n); - int lw = fm.width(*it); - if (lw > w) { - w = lw; - } - } - - if (w == 0) { - hide(); - } else { - show(); - } - return true; + ZkbConfig c(QPEApplication::qpeDir()+"/share/zkb"); + QFontMetrics fm(font()); + + if (keymap != 0) { + delete keymap; + keymap = 0; + } + + Keymap* km = new Keymap(); + + if (!c.load("zkb.xml", *km, "")) { + delete km; + setPixmap(disabled); + return false; + } + + connect(km, SIGNAL(stateChanged(const QString&)), + this, SLOT(stateChanged(const QString&))); + + Opie::Core::OKeyFilter::inst()->addHandler(km); + + Keymap* oldkm = keymap; + keymap = km; + + if (oldkm != 0) { + delete oldkm; + } + + QString ltext = keymap->getCurrentLabel(); + if (ltext.length()==0) ltext = "??"; + setText(ltext); + + labels->clear(); + QStringList l = keymap->listLabels(); + labels->insertItem(disabled, 0, 0); + int n = 1; + w = 0; + for(QStringList::Iterator it = l.begin(); it != l.end(); + ++it, n++) { + +// printf("label: %s\n", (const char*) (*it).utf8()); + + labels->insertItem(*it, n, n); + int lw = fm.width(*it); + if (lw > w) { + w = lw; + } + } + + if (w == 0) { + hide(); + } else { + show(); + } + return true; } @@ -96,4 +105,4 @@ QSize ZkbWidget::sizeHint() const { void ZkbWidget::stateChanged(const QString& s) { -// odebug << "stateChanged: " << s.utf8() << "\n" << oendl; - setText(s); +// odebug << "stateChanged: " << s.utf8() << "\n" << oendl; + setText(s); } @@ -101,19 +110,19 @@ void ZkbWidget::stateChanged(const QString& s) { void ZkbWidget::labelChanged(int id) { - if (id == 0) { - keymap->disable(); - setPixmap(disabled); - return; - } - - keymap->enable(); - - QStringList l = keymap->listLabels(); - QString lbl = l[id-1]; - -// printf("labelChanged: %s\n", (const char*) lbl.utf8()); - State* state = keymap->getStateByLabel(lbl); - if (state != 0) { - keymap->setCurrentState(state); - setText(lbl); - } + if (id == 0) { + keymap->disable(); + setPixmap(disabled); + return; + } + + keymap->enable(); + + QStringList l = keymap->listLabels(); + QString lbl = l[id-1]; + +// printf("labelChanged: %s\n", (const char*) lbl.utf8()); + State* state = keymap->getStateByLabel(lbl); + if (state != 0) { + keymap->setCurrentState(state); + setText(lbl); + } } @@ -121,5 +130,5 @@ void ZkbWidget::labelChanged(int id) { void ZkbWidget::mouseReleaseEvent(QMouseEvent*) { - QSize sh = labels->sizeHint(); - QPoint p = mapToGlobal(QPoint((width()-sh.width())/2,-sh.height())); - labels->exec(p); + QSize sh = labels->sizeHint(); + QPoint p = mapToGlobal(QPoint((width()-sh.width())/2,-sh.height())); + labels->exec(p); } @@ -127,26 +136,26 @@ void ZkbWidget::mouseReleaseEvent(QMouseEvent*) { void ZkbWidget::signalReceived(const QCString& msg, const QByteArray& data) { - QDataStream stream(data, IO_ReadOnly); - - if (msg == "enable()") { - keymap->enable(); - } else if (msg == "disable()") { - keymap->disable(); - } else if (msg == "reload()") { - QCopEnvelope("QPE/System", "busy()"); - QTimer::singleShot(0, this, SLOT(reload())); - } else if (msg == "switch(QString)") { - QString lbl; - stream >> lbl; - - if (keymap != 0) { - State* state = keymap->getStateByLabel(lbl); - if (state != 0) { - keymap->setCurrentState(state); - setText(lbl); - } - } - } else if (msg == "debug(QString)") { - QString flag; - stream >> flag; - } + QDataStream stream(data, IO_ReadOnly); + + if (msg == "enable()") { + keymap->enable(); + } else if (msg == "disable()") { + keymap->disable(); + } else if (msg == "reload()") { + QCopEnvelope("QPE/System", "busy()"); + QTimer::singleShot(0, this, SLOT(reload())); + } else if (msg == "switch(QString)") { + QString lbl; + stream >> lbl; + + if (keymap != 0) { + State* state = keymap->getStateByLabel(lbl); + if (state != 0) { + keymap->setCurrentState(state); + setText(lbl); + } + } + } else if (msg == "debug(QString)") { + QString flag; + stream >> flag; + } } @@ -154,4 +163,4 @@ void ZkbWidget::signalReceived(const QCString& msg, const QByteArray& data) { void ZkbWidget::reload() { - loadKeymap(); - QCopEnvelope("QPE/System", "notBusy()"); + loadKeymap(); + QCopEnvelope("QPE/System", "notBusy()"); } @@ -159,3 +168 @@ void ZkbWidget::reload() { EXPORT_OPIE_APPLET_v1( ZkbWidget ) - - 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 public: - ZkbWidget(QWidget* parent); - ~ZkbWidget(); - static int position(); + ZkbWidget(QWidget* parent); + ~ZkbWidget(); + static int position(); - QSize sizeHint() const; + QSize sizeHint() const; protected: - QLabel* label; - Keymap* keymap; - QPopupMenu* labels; - QCopChannel* channel; - int w, h; - QPixmap disabled; + QLabel* label; + Keymap* keymap; + QPopupMenu* labels; + QCopChannel* channel; + int w, h; + QPixmap disabled; - bool loadKeymap(); - void mouseReleaseEvent(QMouseEvent*); + bool loadKeymap(); + void mouseReleaseEvent(QMouseEvent*); protected slots: - void stateChanged(const QString&); - void labelChanged(int id); - void signalReceived(const QCString& msg, const QByteArray& data); - void reload(); + void stateChanged(const QString&); + void labelChanged(int id); + void signalReceived(const QCString& msg, const QByteArray& data); + void reload(); }; |