summaryrefslogtreecommitdiff
path: root/core/applets/multikeyapplet/multikey.cpp
Unidiff
Diffstat (limited to 'core/applets/multikeyapplet/multikey.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/applets/multikeyapplet/multikey.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/core/applets/multikeyapplet/multikey.cpp b/core/applets/multikeyapplet/multikey.cpp
index 0a056b0..f1227ef 100644
--- a/core/applets/multikeyapplet/multikey.cpp
+++ b/core/applets/multikeyapplet/multikey.cpp
@@ -15,60 +15,75 @@
15#include "multikey.h" 15#include "multikey.h"
16 16
17#include <qpe/global.h> 17#include <qpe/global.h>
18#include <qpe/config.h> 18#include <qpe/config.h>
19#include <qpe/qcopenvelope_qws.h> 19#include <qpe/qcopenvelope_qws.h>
20#include <qpe/qpeapplication.h> 20#include <qpe/qpeapplication.h>
21 21
22#include <qlabel.h> 22#include <qlabel.h>
23#include <qdir.h> 23#include <qdir.h>
24#include <qfileinfo.h> 24#include <qfileinfo.h>
25#include <qcopchannel_qws.h> 25#include <qcopchannel_qws.h>
26 26
27Multikey::Multikey( QWidget *parent ) : QLabel( parent ), current("EN") 27Multikey::Multikey(QWidget *parent) : QLabel(parent), popupMenu(this), current("EN")
28{ 28{
29 QCopChannel* swChannel = new QCopChannel("MultiKey/Switcher", this); 29 QCopChannel* swChannel = new QCopChannel("MultiKey/Switcher", this);
30 connect( swChannel, SIGNAL(received(const QCString &, const QByteArray &)), 30 connect( swChannel, SIGNAL(received(const QCString &, const QByteArray &)),
31 this, SLOT(message(const QCString &, const QByteArray &))); 31 this, SLOT(message(const QCString &, const QByteArray &)));
32 32
33 setFont( QFont( "Helvetica", 10, QFont::Normal ) ); 33 setFont( QFont( "Helvetica", 10, QFont::Normal ) );
34 lang = 0; 34 lang = 0;
35 QCopEnvelope e("MultiKey/Keyboard", "getmultikey()"); 35 QCopEnvelope e("MultiKey/Keyboard", "getmultikey()");
36 setText("EN"); 36 setText("EN");
37 popupMenu.insertItem("EN", -1);
37 show(); 38 show();
38} 39}
39 40
40void Multikey::mousePressEvent( QMouseEvent * ) 41void Multikey::mousePressEvent(QMouseEvent *ev)
41{ 42{
42 QCopEnvelope e("MultiKey/Keyboard", "setmultikey(QString)"); 43 if (ev->button() == RightButton) {
44
45 QPoint p = mapToGlobal(QPoint(0, 0));
46 QSize s = popupMenu.sizeHint();
47 int opt = popupMenu.exec(QPoint(p.x() + (width() / 2) - (s.width() / 2),
48 p.y() - s.height()), 0);
49
50 if (opt == -1)
51 return;
52 lang = opt;
53 } else {
43 lang = lang < sw_maps.count()-1 ? lang+1 : 0; 54 lang = lang < sw_maps.count()-1 ? lang+1 : 0;
55 }
56
57 QCopEnvelope e("MultiKey/Keyboard", "setmultikey(QString)");
44 //qDebug("Lang=%d, count=%d, lab=%s", lang, sw_maps.count(), labels[lang].ascii()); 58 //qDebug("Lang=%d, count=%d, lab=%s", lang, sw_maps.count(), labels[lang].ascii());
45 e << sw_maps[lang]; 59 e << sw_maps[lang];
46 setText(labels[lang]); 60 setText(labels[lang]);
47} 61}
48 62
49void Multikey::message(const QCString &message, const QByteArray &data) 63void Multikey::message(const QCString &message, const QByteArray &data)
50{ 64{
51 if ( message == "setsw(QString,QString)" ) { 65 if ( message == "setsw(QString,QString)" ) {
52 66
53 QDataStream stream(data, IO_ReadOnly); 67 QDataStream stream(data, IO_ReadOnly);
54 QString maps, current_map; 68 QString maps, current_map;
55 stream >> maps >> current_map; 69 stream >> maps >> current_map;
56 QStringList sw = QStringList::split(QChar('|'), maps); 70 QStringList sw = QStringList::split(QChar('|'), maps);
57 sw.append(current_map); 71 sw.append(current_map);
58 72
59 QDir map_dir(QPEApplication::qpeDir() + "/share/multikey/", "*.keymap"); 73 QDir map_dir(QPEApplication::qpeDir() + "/share/multikey/", "*.keymap");
60 lang = 0; 74 lang = 0;
61 labels.clear(); 75 labels.clear();
62 sw_maps.clear(); 76 sw_maps.clear();
77 popupMenu.clear();
63 78
64 for (uint i = 0; i < sw.count(); ++i) { 79 for (uint i = 0; i < sw.count(); ++i) {
65 QString keymap_map; 80 QString keymap_map;
66 if (sw[i][0] != '/') { 81 if (sw[i][0] != '/') {
67 82
68 keymap_map = map_dir.absPath() + "/" + sw[i]; 83 keymap_map = map_dir.absPath() + "/" + sw[i];
69 } else { 84 } else {
70 85
71 if ((map_dir.exists(QFileInfo(sw[i]).fileName(), false) 86 if ((map_dir.exists(QFileInfo(sw[i]).fileName(), false)
72 && i != sw.count()-1) || !QFile::exists(sw[i])) { 87 && i != sw.count()-1) || !QFile::exists(sw[i])) {
73 continue; 88 continue;
74 } 89 }
@@ -81,24 +96,25 @@ void Multikey::message(const QCString &message, const QByteArray &data)
81 96
82 map.readLine(line, 1024); 97 map.readLine(line, 1024);
83 while (!map.atEnd()) { 98 while (!map.atEnd()) {
84 99
85 if (line.find(QRegExp("^sw\\s*=\\s*")) != -1) { 100 if (line.find(QRegExp("^sw\\s*=\\s*")) != -1) {
86 101
87 if (i != sw.count()-1) { 102 if (i != sw.count()-1) {
88 if (keymap_map == current_map) { 103 if (keymap_map == current_map) {
89 lang = i; 104 lang = i;
90 } 105 }
91 sw_maps.append(keymap_map); 106 sw_maps.append(keymap_map);
92 labels.append(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace()); 107 labels.append(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace());
108 popupMenu.insertItem(labels[labels.count()-1], labels.count()-1);
93 } else { 109 } else {
94 current = line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace(); 110 current = line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace();
95 } 111 }
96 break; 112 break;
97 } 113 }
98 map.readLine(line, 1024); 114 map.readLine(line, 1024);
99 } 115 }
100 map.close(); 116 map.close();
101 } 117 }
102 } 118 }
103 119
104 setText(current); 120 setText(current);