author | mickeyl <mickeyl> | 2004-01-04 14:22:59 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-01-04 14:22:59 (UTC) |
commit | 5c4c2a789c19e727bb9ca323ea1fec1b7d1bd057 (patch) (unidiff) | |
tree | c2e1b4a090ca53efd3b3e0c20d12a633e01470d4 /core/applets | |
parent | 84f039ef3799c5310a4f94057b9d76d4ee55f499 (diff) | |
download | opie-5c4c2a789c19e727bb9ca323ea1fec1b7d1bd057.zip opie-5c4c2a789c19e727bb9ca323ea1fec1b7d1bd057.tar.gz opie-5c4c2a789c19e727bb9ca323ea1fec1b7d1bd057.tar.bz2 |
more patches to multikey+applet courtesy Anton Kachalov <mouse@altlinux.ru>
-rw-r--r-- | core/applets/multikeyapplet/multikey.cpp | 22 | ||||
-rw-r--r-- | core/applets/multikeyapplet/multikey.h | 2 |
2 files changed, 21 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 | ||
27 | Multikey::Multikey( QWidget *parent ) : QLabel( parent ), current("EN") | 27 | Multikey::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 | ||
40 | void Multikey::mousePressEvent( QMouseEvent * ) | 41 | void 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 | ||
49 | void Multikey::message(const QCString &message, const QByteArray &data) | 63 | void 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); |
diff --git a/core/applets/multikeyapplet/multikey.h b/core/applets/multikeyapplet/multikey.h index 2cb7b29..b525074 100644 --- a/core/applets/multikeyapplet/multikey.h +++ b/core/applets/multikeyapplet/multikey.h | |||
@@ -7,32 +7,34 @@ | |||
7 | ** Foundation and appearing in the file LICENSE.GPL included in the | 7 | ** Foundation and appearing in the file LICENSE.GPL included in the |
8 | ** packaging of this file. | 8 | ** packaging of this file. |
9 | ** | 9 | ** |
10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
12 | ** | 12 | ** |
13 | **********************************************************************/ | 13 | **********************************************************************/ |
14 | #ifndef __MULTIKEY_H__ | 14 | #ifndef __MULTIKEY_H__ |
15 | #define __MULTIKEY_H__ | 15 | #define __MULTIKEY_H__ |
16 | 16 | ||
17 | #include <qlabel.h> | 17 | #include <qlabel.h> |
18 | #include <qstringlist.h> | 18 | #include <qstringlist.h> |
19 | #include <qpopupmenu.h> | ||
19 | #include <qcopchannel_qws.h> | 20 | #include <qcopchannel_qws.h> |
20 | 21 | ||
21 | class Multikey : public QLabel | 22 | class Multikey : public QLabel |
22 | { | 23 | { |
23 | Q_OBJECT | 24 | Q_OBJECT |
24 | public: | 25 | public: |
25 | Multikey( QWidget *parent ); | 26 | Multikey( QWidget *parent ); |
26 | 27 | ||
27 | public slots: | 28 | public slots: |
28 | void message(const QCString &message, const QByteArray &data); | 29 | void message(const QCString &message, const QByteArray &data); |
29 | 30 | ||
30 | protected: | 31 | protected: |
31 | void mousePressEvent( QMouseEvent * ); | 32 | void mousePressEvent( QMouseEvent * ); |
32 | QStringList sw_maps; | 33 | QStringList sw_maps; |
33 | QStringList labels; | 34 | QStringList labels; |
35 | QPopupMenu popupMenu; | ||
34 | QString current; | 36 | QString current; |
35 | uint lang; | 37 | uint lang; |
36 | }; | 38 | }; |
37 | 39 | ||
38 | #endif /* __MULTIKEY_H__ */ | 40 | #endif /* __MULTIKEY_H__ */ |