author | mickeyl <mickeyl> | 2004-10-29 12:38:37 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-10-29 12:38:37 (UTC) |
commit | dca4423e3b0966fe26ba4183e5b6ad4666c61e86 (patch) (unidiff) | |
tree | 8a06619edc609164f45b6a2d92ec3fe264fc3fb1 | |
parent | e1ab37a7bc09619958037be7ecddc67fd334227d (diff) | |
download | opie-dca4423e3b0966fe26ba4183e5b6ad4666c61e86.zip opie-dca4423e3b0966fe26ba4183e5b6ad4666c61e86.tar.gz opie-dca4423e3b0966fe26ba4183e5b6ad4666c61e86.tar.bz2 |
- no longer hardcode the font size
- add fixme for initial keyboard setting
-rw-r--r-- | core/applets/multikeyapplet/multikey.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/core/applets/multikeyapplet/multikey.cpp b/core/applets/multikeyapplet/multikey.cpp index 8cb9083..f3d8375 100644 --- a/core/applets/multikeyapplet/multikey.cpp +++ b/core/applets/multikeyapplet/multikey.cpp | |||
@@ -1,142 +1,142 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2004 Anton Kachalov mouse@altlinux.ru | 2 | ** Copyright (C) 2004 Anton Kachalov mouse@altlinux.ru |
3 | ** All rights reserved. | 3 | ** All rights reserved. |
4 | ** | 4 | ** |
5 | ** This file may be distributed and/or modified under the terms of the | 5 | ** This file may be distributed and/or modified under the terms of the |
6 | ** GNU General Public License version 2 as published by the Free Software | 6 | ** GNU General Public License version 2 as published by the Free Software |
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 | 14 | ||
15 | #include "multikey.h" | 15 | #include "multikey.h" |
16 | 16 | ||
17 | /* OPIE */ | 17 | /* OPIE */ |
18 | #include <opie2/otaskbarapplet.h> | 18 | #include <opie2/otaskbarapplet.h> |
19 | #include <qpe/qcopenvelope_qws.h> | 19 | #include <qpe/qcopenvelope_qws.h> |
20 | #include <qpe/qpeapplication.h> | 20 | #include <qpe/qpeapplication.h> |
21 | using namespace Opie::Ui; | ||
21 | 22 | ||
22 | /* QT */ | 23 | /* QT */ |
23 | #include <qdir.h> | 24 | #include <qdir.h> |
24 | 25 | ||
25 | using namespace Opie::Ui; | 26 | //FIXME: Better read appropriate initial setting from LOCALE, not hardcode it "EN" |
26 | Multikey::Multikey(QWidget *parent) : QLabel(parent), popupMenu(this), current("EN") | 27 | Multikey::Multikey(QWidget *parent) : QLabel(parent), popupMenu(this), current("EN") |
27 | { | 28 | { |
28 | QCopChannel* swChannel = new QCopChannel("MultiKey/Switcher", this); | 29 | QCopChannel* swChannel = new QCopChannel("MultiKey/Switcher", this); |
29 | connect( swChannel, SIGNAL(received(const QCString&,const QByteArray&)), | 30 | connect( swChannel, SIGNAL(received(const QCString&,const QByteArray&)), |
30 | this, SLOT(message(const QCString&,const QByteArray&))); | 31 | this, SLOT(message(const QCString&,const QByteArray&))); |
31 | 32 | ||
32 | setFont( QFont( "Helvetica", 10, QFont::Normal ) ); | ||
33 | QPEApplication::setStylusOperation(this, QPEApplication::RightOnHold); | 33 | QPEApplication::setStylusOperation(this, QPEApplication::RightOnHold); |
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", 0); | 37 | popupMenu.insertItem("EN", 0); |
38 | show(); | 38 | show(); |
39 | } | 39 | } |
40 | 40 | ||
41 | void Multikey::mousePressEvent(QMouseEvent *ev) | 41 | void Multikey::mousePressEvent(QMouseEvent *ev) |
42 | { | 42 | { |
43 | if (!sw_maps.count()) | 43 | if (!sw_maps.count()) |
44 | return; | 44 | return; |
45 | 45 | ||
46 | if (ev->button() == RightButton) { | 46 | if (ev->button() == RightButton) { |
47 | 47 | ||
48 | QPoint p = mapToGlobal(QPoint(0, 0)); | 48 | QPoint p = mapToGlobal(QPoint(0, 0)); |
49 | QSize s = popupMenu.sizeHint(); | 49 | QSize s = popupMenu.sizeHint(); |
50 | int opt = popupMenu.exec(QPoint(p.x() + (width() / 2) - (s.width() / 2), | 50 | int opt = popupMenu.exec(QPoint(p.x() + (width() / 2) - (s.width() / 2), |
51 | p.y() - s.height()), 0); | 51 | p.y() - s.height()), 0); |
52 | 52 | ||
53 | if (opt == -1) | 53 | if (opt == -1) |
54 | return; | 54 | return; |
55 | lang = opt; | 55 | lang = opt; |
56 | 56 | ||
57 | QCopEnvelope e("MultiKey/Keyboard", "setmultikey(QString)"); | 57 | QCopEnvelope e("MultiKey/Keyboard", "setmultikey(QString)"); |
58 | e << sw_maps[lang]; | 58 | e << sw_maps[lang]; |
59 | setText(labels[lang]); | 59 | setText(labels[lang]); |
60 | } | 60 | } |
61 | QWidget::mousePressEvent(ev); | 61 | QWidget::mousePressEvent(ev); |
62 | } | 62 | } |
63 | 63 | ||
64 | void Multikey::mouseReleaseEvent(QMouseEvent *ev) | 64 | void Multikey::mouseReleaseEvent(QMouseEvent *ev) |
65 | { | 65 | { |
66 | if (!sw_maps.count()) | 66 | if (!sw_maps.count()) |
67 | return; | 67 | return; |
68 | 68 | ||
69 | lang = lang < sw_maps.count()-1 ? lang+1 : 0; | 69 | lang = lang < sw_maps.count()-1 ? lang+1 : 0; |
70 | QCopEnvelope e("MultiKey/Keyboard", "setmultikey(QString)"); | 70 | QCopEnvelope e("MultiKey/Keyboard", "setmultikey(QString)"); |
71 | //odebug << "Lang=" << lang << ", count=" << sw_maps.count() << ", lab=" << labels[lang].ascii() << "" << oendl; | 71 | //odebug << "Lang=" << lang << ", count=" << sw_maps.count() << ", lab=" << labels[lang].ascii() << "" << oendl; |
72 | e << sw_maps[lang]; | 72 | e << sw_maps[lang]; |
73 | setText(labels[lang]); | 73 | setText(labels[lang]); |
74 | } | 74 | } |
75 | 75 | ||
76 | void Multikey::message(const QCString &message, const QByteArray &data) | 76 | void Multikey::message(const QCString &message, const QByteArray &data) |
77 | { | 77 | { |
78 | if ( message == "setsw(QString,QString)" ) { | 78 | if ( message == "setsw(QString,QString)" ) { |
79 | 79 | ||
80 | QDataStream stream(data, IO_ReadOnly); | 80 | QDataStream stream(data, IO_ReadOnly); |
81 | QString maps, current_map; | 81 | QString maps, current_map; |
82 | stream >> maps >> current_map; | 82 | stream >> maps >> current_map; |
83 | QStringList sw = QStringList::split(QChar('|'), maps); | 83 | QStringList sw = QStringList::split(QChar('|'), maps); |
84 | sw.append(current_map); | 84 | sw.append(current_map); |
85 | 85 | ||
86 | QDir map_dir(QPEApplication::qpeDir() + "share/multikey/", "*.keymap"); | 86 | QDir map_dir(QPEApplication::qpeDir() + "share/multikey/", "*.keymap"); |
87 | lang = 0; | 87 | lang = 0; |
88 | labels.clear(); | 88 | labels.clear(); |
89 | sw_maps.clear(); | 89 | sw_maps.clear(); |
90 | popupMenu.clear(); | 90 | popupMenu.clear(); |
91 | 91 | ||
92 | for (uint i = 0; i < sw.count(); ++i) { | 92 | for (uint i = 0; i < sw.count(); ++i) { |
93 | QString keymap_map; | 93 | QString keymap_map; |
94 | if (sw[i][0] != '/') { | 94 | if (sw[i][0] != '/') { |
95 | 95 | ||
96 | keymap_map = map_dir.absPath() + "/" + sw[i]; | 96 | keymap_map = map_dir.absPath() + "/" + sw[i]; |
97 | } else { | 97 | } else { |
98 | 98 | ||
99 | if ((map_dir.exists(QFileInfo(sw[i]).fileName(), false) | 99 | if ((map_dir.exists(QFileInfo(sw[i]).fileName(), false) |
100 | && i != sw.count()-1) || !QFile::exists(sw[i])) { | 100 | && i != sw.count()-1) || !QFile::exists(sw[i])) { |
101 | continue; | 101 | continue; |
102 | } | 102 | } |
103 | keymap_map = sw[i]; | 103 | keymap_map = sw[i]; |
104 | } | 104 | } |
105 | 105 | ||
106 | QFile map(keymap_map); | 106 | QFile map(keymap_map); |
107 | if (map.open(IO_ReadOnly)) { | 107 | if (map.open(IO_ReadOnly)) { |
108 | QString line; | 108 | QString line; |
109 | 109 | ||
110 | map.readLine(line, 1024); | 110 | map.readLine(line, 1024); |
111 | while (!map.atEnd()) { | 111 | while (!map.atEnd()) { |
112 | 112 | ||
113 | if (line.find(QRegExp("^sw\\s*=\\s*")) != -1) { | 113 | if (line.find(QRegExp("^sw\\s*=\\s*")) != -1) { |
114 | 114 | ||
115 | if (i != sw.count()-1) { | 115 | if (i != sw.count()-1) { |
116 | if (keymap_map == current_map) { | 116 | if (keymap_map == current_map) { |
117 | lang = i; | 117 | lang = i; |
118 | } | 118 | } |
119 | sw_maps.append(keymap_map); | 119 | sw_maps.append(keymap_map); |
120 | labels.append(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace()); | 120 | labels.append(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace()); |
121 | popupMenu.insertItem(labels[labels.count()-1], labels.count()-1); | 121 | popupMenu.insertItem(labels[labels.count()-1], labels.count()-1); |
122 | } else { | 122 | } else { |
123 | current = line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace(); | 123 | current = line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace(); |
124 | } | 124 | } |
125 | break; | 125 | break; |
126 | } | 126 | } |
127 | map.readLine(line, 1024); | 127 | map.readLine(line, 1024); |
128 | } | 128 | } |
129 | map.close(); | 129 | map.close(); |
130 | } | 130 | } |
131 | } | 131 | } |
132 | 132 | ||
133 | setText(current); | 133 | setText(current); |
134 | } | 134 | } |
135 | } | 135 | } |
136 | 136 | ||
137 | int Multikey::position() | 137 | int Multikey::position() |
138 | { | 138 | { |
139 | return 10; | 139 | return 10; |
140 | } | 140 | } |
141 | 141 | ||
142 | EXPORT_OPIE_APPLET_v1( Multikey ) | 142 | EXPORT_OPIE_APPLET_v1( Multikey ) |