summaryrefslogtreecommitdiff
authorhash <hash>2002-10-24 08:14:54 (UTC)
committer hash <hash>2002-10-24 08:14:54 (UTC)
commit541035d4308ca1931d5068ced83b0cb5350b0766 (patch) (unidiff)
tree6f236ae8499f4aefcb7405d8beaed59230155276
parent7c670be31a6a60e03e7dba4e366aa8f3e02bae6c (diff)
downloadopie-541035d4308ca1931d5068ced83b0cb5350b0766.zip
opie-541035d4308ca1931d5068ced83b0cb5350b0766.tar.gz
opie-541035d4308ca1931d5068ced83b0cb5350b0766.tar.bz2
editing/loading/saving works. now the keyboard in mainwidget needs to load the right profile when the tab is switched
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/function_keyboard.cpp151
-rw-r--r--noncore/apps/opie-console/function_keyboard.h5
2 files changed, 108 insertions, 48 deletions
diff --git a/noncore/apps/opie-console/function_keyboard.cpp b/noncore/apps/opie-console/function_keyboard.cpp
index 9d58383..538bed4 100644
--- a/noncore/apps/opie-console/function_keyboard.cpp
+++ b/noncore/apps/opie-console/function_keyboard.cpp
@@ -5,24 +5,30 @@
5#include <qsizepolicy.h> 5#include <qsizepolicy.h>
6#include <qevent.h> 6#include <qevent.h>
7#include <qwindowsystem_qws.h> 7#include <qwindowsystem_qws.h>
8#include <qapplication.h> 8#include <qapplication.h>
9#include <qlayout.h> 9#include <qlayout.h>
10#include <qspinbox.h> 10#include <qspinbox.h>
11#include <qlistbox.h>
11#include <qlabel.h> 12#include <qlabel.h>
12#include <qcombobox.h> 13#include <qcombobox.h>
13#include <qdir.h> 14#include <qdir.h>
14 15
15/* FunctionKeyboard {{{1 */ 16/* FunctionKeyboard {{{1 */
16 17
17FunctionKeyboard::FunctionKeyboard(QWidget *parent) : 18FunctionKeyboard::FunctionKeyboard(QWidget *parent) :
18 QFrame(parent), numRows(2), numCols(11), 19 QFrame(parent), numRows(2), numCols(11),
19 pressedRow(0), pressedCol(0) { 20 pressedRow(0), pressedCol(0) {
20 21
21 setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed)); 22 setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed));
22 23
24 /*
25 * all the saving/loading is now done in a profile. downside is that you cant modify
26 * the keyboard for all profiles, but must do it on a profile-basis
27 *
28
23 Config conf("opie-console-keys"); 29 Config conf("opie-console-keys");
24 conf.setGroup("keys"); 30 conf.setGroup("keys");
25 for (uint r = 0; r < numRows; r++) 31 for (uint r = 0; r < numRows; r++)
26 for (uint c = 0; c < numCols; c++) { 32 for (uint c = 0; c < numCols; c++) {
27 33
28 QString handle = "r" + QString::number(r) + "c" + QString::number(c); 34 QString handle = "r" + QString::number(r) + "c" + QString::number(c);
@@ -34,12 +40,13 @@ FunctionKeyboard::FunctionKeyboard(QWidget *parent) :
34 40
35 handle, 41 handle,
36 FKey (value_list[0], value_list[1], value_list[2].toUShort(), value_list[3].toUShort()) 42 FKey (value_list[0], value_list[1], value_list[2].toUShort(), value_list[3].toUShort())
37 ); 43 );
38 } 44 }
39 //qWarning("loaded %d keys", keys.count()); 45 //qWarning("loaded %d keys", keys.count());
46 */
40 if (keys.isEmpty()) loadDefaults(); 47 if (keys.isEmpty()) loadDefaults();
41 48
42 49
43 50
44} 51}
45 52
@@ -56,19 +63,12 @@ void FunctionKeyboard::changeCols(int c) {
56 63
57 numCols = c; 64 numCols = c;
58 keyWidth = (double)width()/numCols; // have to reset this thing too 65 keyWidth = (double)width()/numCols; // have to reset this thing too
59 repaint(false); 66 repaint(false);
60} 67}
61 68
62/*
63Key getKey(int row, int col) {
64
65 return keys[ "r" + QString::number(row) + "c" + QString::number(col) ];
66}
67*/
68
69void FunctionKeyboard::paintEvent(QPaintEvent *e) { 69void FunctionKeyboard::paintEvent(QPaintEvent *e) {
70 70
71 QPainter p(this); 71 QPainter p(this);
72 p.setClipRect(e->rect()); 72 p.setClipRect(e->rect());
73 p.fillRect(0, 0, width(), height(), QColor(255,255,255)); 73 p.fillRect(0, 0, width(), height(), QColor(255,255,255));
74 74
@@ -91,42 +91,58 @@ void FunctionKeyboard::paintEvent(QPaintEvent *e) {
91 for (uint r = 0; r < numRows; r++) { 91 for (uint r = 0; r < numRows; r++) {
92 for (uint c = 0; c < numCols; c++) { 92 for (uint c = 0; c < numCols; c++) {
93 93
94 QString handle = "r" + QString::number(r) + "c" + QString::number(c); 94 QString handle = "r" + QString::number(r) + "c" + QString::number(c);
95 if (keys.contains(handle)) { 95 if (keys.contains(handle)) {
96 96
97 p.drawText( 97 if (keys[handle].pixFile.isEmpty())
98 c * keyWidth + 1, r * keyHeight + 1, 98 p.drawText( c * keyWidth + 1, r * keyHeight + 1,
99 keyWidth, keyHeight, 99 keyWidth, keyHeight,
100 Qt::AlignHCenter | Qt::AlignVCenter, 100 Qt::AlignHCenter | Qt::AlignVCenter,
101 keys[handle].label 101 keys[handle].label
102 ); 102 );
103 else {
104
105 ushort centerX = c *keyWidth + (keyWidth - keys[handle].pix->width()) / 2;
106 ushort centerY = r * keyHeight + (keyHeight - keys[handle].pix->height()) / 2;
107 p.drawPixmap(centerX, centerY, *keys[handle].pix);
108 }
103 } 109 }
104 } 110 }
105 } 111 }
106} 112}
107 113
108void FunctionKeyboard::paintKey(uint row, uint col) { 114void FunctionKeyboard::paintKey(uint row, uint col) {
109 115
110 QPainter p(this); 116 QPainter p(this);
111 117
112 p.fillRect(QRect(QPoint(col * keyWidth + 1, row * keyHeight + 1), 118 p.fillRect(QRect(QPoint(col * keyWidth + 1, row * keyHeight + 1),
113 QPoint((col + 1) * keyWidth - 1, row * keyHeight + keyHeight- 1)), 119 QPoint((col + 1) * keyWidth - 1, row * keyHeight + keyHeight- 1)),
114 (pressedRow != -1 && pressedCol != -1 ) ? QColor(97,119,155) : QColor(255,255,255)); 120 (pressedRow != -1 && pressedCol != -1 ) ? QColor(97,119,155) : QColor(255,255,255));
115 p.drawText( 121
122 QString handle ("r" + QString::number(row) + "c" + QString::number(col));
123 if (keys[handle].pixFile.isEmpty())
124 p.drawText(
116 col * keyWidth + 1, row * keyHeight + 1, 125 col * keyWidth + 1, row * keyHeight + 1,
117 keyWidth, keyHeight, 126 keyWidth, keyHeight,
118 Qt::AlignHCenter | Qt::AlignVCenter, 127 Qt::AlignHCenter | Qt::AlignVCenter,
119 keys["r" + QString::number(row) + "c" + QString::number(col)].label 128 keys[handle].label
120 ); 129 );
130 else {
131
132 ushort centerX = col *keyWidth + (keyWidth - keys[handle].pix->width()) / 2;
133 ushort centerY = row * keyHeight + (keyHeight - keys[handle].pix->height()) / 2;
134 p.drawPixmap(centerX, centerY, *keys[handle].pix);
135 }
121 136
122 if (row == numRows) { 137 if (col == numCols - 1) {
123 138
124 // sometimes it doesnt draw the last line 139 // sometimes it doesnt draw the last line
125 p.drawLine((col+1) * keyWidth -2, row * keyHeight, 140
126 (col+1) * keyWidth -2, (row + 1) * keyHeight 141 p.drawLine((col+1) * keyWidth -1, row * keyHeight,
142 (col+1) * keyWidth -1, (row + 1) * keyHeight
127 ); 143 );
128 } 144 }
129 145
130} 146}
131 147
132void FunctionKeyboard::mousePressEvent(QMouseEvent *e) { 148void FunctionKeyboard::mousePressEvent(QMouseEvent *e) {
@@ -170,38 +186,43 @@ QSize FunctionKeyboard::sizeHint() const {
170 186
171 return QSize(width(), keyHeight * numRows + 1); 187 return QSize(width(), keyHeight * numRows + 1);
172} 188}
173 189
174void FunctionKeyboard::loadDefaults() { 190void FunctionKeyboard::loadDefaults() {
175 191
176 /* what keys should be default? 192 keys.insert( "r0c0", FKey ("Enter", "enter.png", Qt::Key_Enter, 0));
177 keys.insert( "r0c0", FKey ("F1", 0, 4144, 0)); 193 keys.insert( "r0c1", FKey ("Space", "space.png", Qt::Key_Space, Qt::Key_Space));
178 keys.insert( "r0c1", FKey ("F2", 0, 4145, 0)); 194 keys.insert( "r0c2", FKey ("Tab", "tab.png", Qt::Key_Tab, 0));
179 keys.insert( "r0c2", FKey ("F3", 0, 4146, 0)); 195 keys.insert( "r0c3", FKey ("Up", "up.png", Qt::Key_Up, 0));
180 keys.insert( "r0c3", FKey ("F4", 0, 4147, 0)); 196 keys.insert( "r0c4", FKey ("Down", "down.png", Qt::Key_Down, 0));
181 keys.insert( "r0c4", FKey ("F5", 0, 4148, 0)); 197
182 keys.insert( "r0c5", FKey ("F6", 0, 4149, 0)); 198 keys.insert( "r0c7", FKey ("Ho", 0, 4112, 0));
183 keys.insert( "r0c6", FKey ("F7", 0, 4150, 0)); 199 keys.insert( "r0c8", FKey ("End", 0, 4113, 0));
184 keys.insert( "r0c7", FKey ("F8", 0, 4151, 0)); 200 keys.insert( "r0c9", FKey ("PU", 0, 4118, 0));
185 keys.insert( "r0c8", FKey ("F9", 0, 4152, 0)); 201 keys.insert( "r0c10", FKey ("PD", 0, 4119, 0));
186 keys.insert( "r0c9", FKey ("F10", 0, 4153, 0)); 202
187 keys.insert( "r0c10", FKey ("F11", 0, 4154, 0)); 203 keys.insert( "r1c0", FKey ("F1", 0, 4144, 0));
188 204 keys.insert( "r1c1", FKey ("F2", 0, 4145, 0));
189 keys.insert( "r1c7", FKey ("Ho", 0, 4112, 0)); 205 keys.insert( "r1c2", FKey ("F3", 0, 4146, 0));
190 keys.insert( "r1c8", FKey ("End", 0, 4113, 0)); 206 keys.insert( "r1c3", FKey ("F4", 0, 4147, 0));
191 keys.insert( "r1c9", FKey ("PU", 0, 4118, 0)); 207 keys.insert( "r1c4", FKey ("F5", 0, 4148, 0));
192 keys.insert( "r1c10", FKey ("PD", 0, 4119, 0)); 208 keys.insert( "r1c5", FKey ("F6", 0, 4149, 0));
193 */ 209 keys.insert( "r1c6", FKey ("F7", 0, 4150, 0));
210 keys.insert( "r1c7", FKey ("F8", 0, 4151, 0));
211 keys.insert( "r1c8", FKey ("F9", 0, 4152, 0));
212 keys.insert( "r1c9", FKey ("F10", 0, 4153, 0));
213 keys.insert( "r1c10", FKey ("F11", 0, 4154, 0));
214
194 215
195} 216}
196 217
197/* FunctionKeyboardConfig {{{1 */ 218/* FunctionKeyboardConfig {{{1 */
198 219
199FunctionKeyboardConfig::FunctionKeyboardConfig(const QString& name, QWidget* parent, const char* na ) 220FunctionKeyboardConfig::FunctionKeyboardConfig(const QString& name, QWidget* parent, const char* na )
200 : ProfileDialogKeyWidget(name, parent, na), 221 : ProfileDialogKeyWidget(name, parent, na),
201 selectedRow(0), selectedCol(0) 222 selectedRow(0), selectedCol(0)
202{ 223{
203 qWarning("FunctionKeyboardConfig"); 224 qWarning("FunctionKeyboardConfig");
204 225
205 226
206 kb = new FunctionKeyboard(this); 227 kb = new FunctionKeyboard(this);
207 connect (kb, SIGNAL(keyPressed(FKey, ushort, ushort, bool)), 228 connect (kb, SIGNAL(keyPressed(FKey, ushort, ushort, bool)),
@@ -216,27 +237,36 @@ FunctionKeyboardConfig::FunctionKeyboardConfig(const QString& name, QWidget* par
216 connect (m_colBox, SIGNAL(valueChanged(int)), this, SLOT(slotChangeCols(int))); 237 connect (m_colBox, SIGNAL(valueChanged(int)), this, SLOT(slotChangeCols(int)));
217 238
218 QGroupBox *editKey = new QGroupBox(2, Qt::Horizontal, tr("Edit Key"), this); 239 QGroupBox *editKey = new QGroupBox(2, Qt::Horizontal, tr("Edit Key"), this);
219 l = new QLabel("Label", editKey); 240 l = new QLabel("Label", editKey);
220 m_labels = new QComboBox(true, editKey); 241 m_labels = new QComboBox(true, editKey);
221 m_labels->setInsertionPolicy(QComboBox::AtCurrent); 242 m_labels->setInsertionPolicy(QComboBox::AtCurrent);
222 m_labels->insertItem("custom"); 243 m_labels->insertItem("");
223 244
224 QStringList files = QDir(QPEApplication::qpeDir() + "pics/console/keys/", "*.png").entryList(); 245 QStringList files = QDir(QPEApplication::qpeDir() + "pics/console/keys/", "*.png").entryList();
225 246
226 for (uint i = 0; i < files.count(); i++) { 247 for (uint i = 0; i < files.count(); i++) {
227 248
228 m_labels->insertItem(Resource::loadPixmap("console/keys/" + files[i])); 249 m_labels->insertItem(Resource::loadPixmap("console/keys/" + files[i]), files[i]);
229 } 250 }
230 connect (m_labels, SIGNAL(activated(int)), this, SLOT(slotChangeIcon(int))); 251 connect (m_labels, SIGNAL(activated(int)), this, SLOT(slotChangeIcon(int)));
231 connect (m_labels, SIGNAL(textChanged(const QString &)), this, SLOT(slotChangeLabelText(const QString&))); 252 connect (m_labels, SIGNAL(textChanged(const QString &)), this, SLOT(slotChangeLabelText(const QString&)));
232 253
233 l = new QLabel("KeyValue", editKey); 254 l = new QLabel("Q Keycode", editKey);
234 m_qvalues = new QComboBox(false, editKey); 255 m_qvalues = new QComboBox(true, editKey);
235 m_qvalues->setInsertionPolicy(QComboBox::AtCurrent); 256 m_qvalues->setInsertionPolicy(QComboBox::AtTop);
236 m_qvalues->insertItem("custom"); 257 m_qvalues->setDuplicatesEnabled(false);
258 m_qvalues->insertItem("");
259 connect (m_qvalues, SIGNAL(textChanged(const QString &)), this, SLOT(slotChangeQCode(const QString&)));
260
261 l = new QLabel("Unicode Value", editKey);
262 m_uniValues = new QComboBox(true, editKey);
263 m_uniValues->setInsertionPolicy(QComboBox::AtTop);
264 m_uniValues->setDuplicatesEnabled(false);
265 m_uniValues->insertItem("");
266 connect (m_uniValues, SIGNAL(textChanged(const QString &)), this, SLOT(slotChangeUnicode(const QString&)));
237 267
238 QVBoxLayout *root = new QVBoxLayout(this, 2); 268 QVBoxLayout *root = new QVBoxLayout(this, 2);
239 root->addWidget(kb); 269 root->addWidget(kb);
240 root->addWidget(dimentions); 270 root->addWidget(dimentions);
241 root->addWidget(editKey); 271 root->addWidget(editKey);
242} 272}
@@ -256,13 +286,18 @@ void FunctionKeyboardConfig::load (const Profile& prof) {
256 QString values = prof.readEntry("keb_" + h); 286 QString values = prof.readEntry("keb_" + h);
257 287
258 if (!values.isEmpty()) { 288 if (!values.isEmpty()) {
259 289
260 QStringList l = QStringList::split(QChar('|'), values, TRUE); 290 QStringList l = QStringList::split(QChar('|'), values, TRUE);
261 kb->keys[h] = FKey(l[0], l[1], l[2].toInt(), l[3].toInt()); 291 kb->keys[h] = FKey(l[0], l[1], l[2].toInt(), l[3].toInt());
262 //qWarning("loading key... %s %s %s %d %d", values.ascii(), l[0].ascii(), l[1].ascii(), l[2].toInt(), l[3].toInt()); 292
293 // load pixmap if used
294 if (!l[1].isEmpty()) {
295
296 kb->keys[h].pix = new QPixmap(QPEApplication::qpeDir() + "pics/console/keys/" + l[1]);
297 }
263 } 298 }
264 } 299 }
265 300
266} 301}
267void FunctionKeyboardConfig::save (Profile& prof) { 302void FunctionKeyboardConfig::save (Profile& prof) {
268 303
@@ -295,39 +330,61 @@ void FunctionKeyboardConfig::slotChangeCols(int c) {
295 kb->changeCols(c); 330 kb->changeCols(c);
296} 331}
297void FunctionKeyboardConfig::slotKeyPressed(FKey k, ushort r, ushort c, bool pressed) { 332void FunctionKeyboardConfig::slotKeyPressed(FKey k, ushort r, ushort c, bool pressed) {
298 333
299 if (!pressed) return; 334 if (!pressed) return;
300 335
301 selectedRow = r, selectedCol = c; 336 selectedHandle = "r" + QString::number(r) +
337 "c" + QString::number(c);
338 selectedRow = r;
339 selectedCol = c;
302 340
303 if (k.pixFile.isEmpty()) { 341 if (k.pixFile.isEmpty()) {
304 342
343 m_labels->setEditable(true);
305 m_labels->setCurrentItem(0); 344 m_labels->setCurrentItem(0);
306 m_labels->changeItem(k.label, 0); 345 m_labels->changeItem(k.label, 0);
307 m_labels->setEditable(true);
308 346
347 } else {
348
349 // any better way to select the pixmap?
350 m_labels->setCurrentItem((m_labels->listBox())->index((m_labels->listBox())->findItem(kb->keys[selectedHandle].pixFile)));
351 m_labels->setEditable(false);
309 } 352 }
310 m_qvalues->changeItem(QString::number(k.qcode), 0); 353 m_qvalues->changeItem(QString::number(k.qcode), 0);
354 m_uniValues->changeItem(QString::number(k.unicode), 0);
311} 355}
312void FunctionKeyboardConfig::slotChangeIcon(int index) { 356void FunctionKeyboardConfig::slotChangeIcon(int index) {
313 357
314 if (index == 0) { 358 if (index == 0) {
315 359
316 // is text 360 // is text
317 m_labels->setEditable(true); 361 m_labels->setEditable(true);
318 // why tf does the text get erased unless i do this? 362 // why tf does the text get erased unless i do this?
319 m_labels->changeItem(m_labels->text(0), 0); 363 m_labels->changeItem(m_labels->text(0), 0);
320 364
365 kb->keys[selectedHandle].pixFile = "";
366 delete kb->keys[selectedHandle].pix;
367
321 } else { 368 } else {
322 369
323 // is a pixmap 370 // is a pixmap
324 m_labels->setEditable(false); 371 m_labels->setEditable(false);
372 kb->keys[selectedHandle].pixFile = m_labels->currentText();
373 kb->keys[selectedHandle].pix = new QPixmap(QPEApplication::qpeDir() + "pics/console/keys/" + m_labels->currentText());
325 } 374 }
375 kb->paintKey(selectedRow, selectedCol);
326} 376}
327void FunctionKeyboardConfig::slotChangeLabelText(const QString &label) { 377void FunctionKeyboardConfig::slotChangeLabelText(const QString &label) {
328 378
329 kb->keys["r" + QString::number(selectedRow) + 379 kb->keys[selectedHandle].label = label;
330 "c" + QString::number(selectedCol)].label = label;
331 380
332 kb->paintKey(selectedRow, selectedCol); 381 kb->paintKey(selectedRow, selectedCol);
333} 382}
383void FunctionKeyboardConfig::slotChangeQCode(const QString& qcode) {
384
385 kb->keys[selectedHandle].qcode = qcode.toUInt();
386}
387void FunctionKeyboardConfig::slotChangeUnicode(const QString& uni) {
388
389 kb->keys[selectedHandle].unicode = uni.toUInt();
390}
diff --git a/noncore/apps/opie-console/function_keyboard.h b/noncore/apps/opie-console/function_keyboard.h
index 496d932..7f313d6 100644
--- a/noncore/apps/opie-console/function_keyboard.h
+++ b/noncore/apps/opie-console/function_keyboard.h
@@ -95,18 +95,21 @@ private slots:
95 95
96 void slotKeyPressed(FKey, ushort, ushort, bool); 96 void slotKeyPressed(FKey, ushort, ushort, bool);
97 void slotChangeRows(int); 97 void slotChangeRows(int);
98 void slotChangeCols(int); 98 void slotChangeCols(int);
99 void slotChangeIcon(int); 99 void slotChangeIcon(int);
100 void slotChangeLabelText(const QString &); 100 void slotChangeLabelText(const QString &);
101 void slotChangeQCode(const QString &);
102 void slotChangeUnicode(const QString &);
101 103
102private: 104private:
103 105
106 QString selectedHandle;
104 ushort selectedRow, selectedCol; 107 ushort selectedRow, selectedCol;
105 108
106 FunctionKeyboard *kb; 109 FunctionKeyboard *kb;
107 QSpinBox *m_rowBox, *m_colBox; 110 QSpinBox *m_rowBox, *m_colBox;
108 QComboBox *m_labels, *m_qvalues; 111 QComboBox *m_labels, *m_qvalues, *m_uniValues;
109 112
110}; 113};
111 114
112#endif 115#endif