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
@@ -8,6 +8,7 @@
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>
@@ -20,6 +21,11 @@ FunctionKeyboard::FunctionKeyboard(QWidget *parent) :
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++)
@@ -37,6 +43,7 @@ FunctionKeyboard::FunctionKeyboard(QWidget *parent) :
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
@@ -59,13 +66,6 @@ void FunctionKeyboard::changeCols(int c) {
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);
@@ -94,12 +94,18 @@ void FunctionKeyboard::paintEvent(QPaintEvent *e) {
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 }
@@ -112,18 +118,28 @@ void FunctionKeyboard::paintKey(uint row, uint col) {
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
@@ -173,32 +189,37 @@ QSize FunctionKeyboard::sizeHint() const {
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
@@ -219,21 +240,30 @@ FunctionKeyboardConfig::FunctionKeyboardConfig(const QString& name, QWidget* par
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);
@@ -259,7 +289,12 @@ void FunctionKeyboardConfig::load (const Profile& prof) {
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
@@ -298,16 +333,25 @@ void FunctionKeyboardConfig::slotKeyPressed(FKey k, ushort r, ushort c, bool pre
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
@@ -318,16 +362,29 @@ void FunctionKeyboardConfig::slotChangeIcon(int index) {
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
@@ -98,14 +98,17 @@ private slots:
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