summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-console/function_keyboard.cpp68
-rw-r--r--noncore/apps/opie-console/function_keyboard.h25
2 files changed, 88 insertions, 5 deletions
diff --git a/noncore/apps/opie-console/function_keyboard.cpp b/noncore/apps/opie-console/function_keyboard.cpp
index a3da5b2..9b036f3 100644
--- a/noncore/apps/opie-console/function_keyboard.cpp
+++ b/noncore/apps/opie-console/function_keyboard.cpp
@@ -1,11 +1,32 @@
1#include "function_keyboard.h" 1#include "function_keyboard.h"
2#include <qsizepolicy.h> 2#include <qsizepolicy.h>
3#include <qwindowsystem_qws.h>
3 4
4FunctionKeyboard::FunctionKeyboard(QWidget *parent) : 5FunctionKeyboard::FunctionKeyboard(QWidget *parent) :
5 QFrame(parent), numRows(2), numCols(15), 6 QFrame(parent), numRows(1), numCols(11),
6 pressedRow(0), pressedCol(0) { 7 pressedRow(0), pressedCol(0) {
7 8
8 setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); 9 setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed));
10
11 Config conf("opie-console-keys");
12 conf.setGroup("keys");
13 for (int r = 0; r < numRows; r++)
14 for (int c = 0; c < numCols; c++) {
15
16 QString handle = "r" + QString::number(r) + "c" + QString::number(c);
17 QStringList value_list = conf.readListEntry( handle, '|');
18
19 if (value_list.isEmpty()) continue;
20
21 keys.insert(
22
23 handle,
24 FKey (value_list[0], value_list[1].toUShort(), value_list[2].toUShort())
25 );
26 }
27 qWarning("loaded %d keys", keys.count());
28
29
9 30
10} 31}
11 32
@@ -19,27 +40,53 @@ void FunctionKeyboard::paintEvent(QPaintEvent *e) {
19 p.setClipRect(e->rect()); 40 p.setClipRect(e->rect());
20 p.fillRect(0, 0, width(), height(), QColor(255,255,255)); 41 p.fillRect(0, 0, width(), height(), QColor(255,255,255));
21 42
43 p.setPen(QColor(0,0,0));
44
22 /* those decimals do count! becomes short if use plain int */ 45 /* those decimals do count! becomes short if use plain int */
23 for (double i = 0; i <= width(); i += keyWidth) { 46 for (double i = 0; i <= width(); i += keyWidth) {
24 47
25 p.setPen(QColor(0,0,0));
26 p.drawLine((int)i, 0, (int)i, height()); 48 p.drawLine((int)i, 0, (int)i, height());
27 } 49 }
28 50
29 for (int i = 0; i <= height(); i += height()/numRows) { 51 // sometimes the last line doesnt get drawn
52 p.drawLine(width() -1, 0, width() -1, height());
53
54 for (int i = 0; i <= height(); i += keyHeight) {
30 55
31 p.setPen(QColor(0,0,0));
32 p.drawLine(0, i, width(), i); 56 p.drawLine(0, i, width(), i);
33 } 57 }
34 58
59 for (int r = 0; r < numRows; r++) {
60 for (int c = 0; c < numCols; c++) {
61
62 QString handle = "r" + QString::number(r) + "c" + QString::number(c);
63 if (keys.contains(handle)) {
64
65 p.drawText(
66 c * keyWidth + 1, r * keyHeight + 1,
67 keyWidth, keyHeight,
68 Qt::AlignHCenter | Qt::AlignVCenter,
69 keys[handle].getL()
70 );
71 }
72 }
73 }
35} 74}
36 75
37void FunctionKeyboard::paintKey(int row, int col) { 76void FunctionKeyboard::paintKey(int row, int col) {
38 77
39 QPainter p(this); 78 QPainter p(this);
79
40 p.fillRect(QRect(QPoint(col * keyWidth + 1, row * keyHeight + 1), 80 p.fillRect(QRect(QPoint(col * keyWidth + 1, row * keyHeight + 1),
41 QPoint((col + 1) * keyWidth - 1, row * keyHeight + keyHeight- 1)), 81 QPoint((col + 1) * keyWidth - 1, row * keyHeight + keyHeight- 1)),
42 (pressedRow != -1 && pressedCol != -1 ) ? QColor(97,119,155) : QColor(255,255,255)); 82 (pressedRow != -1 && pressedCol != -1 ) ? QColor(97,119,155) : QColor(255,255,255));
83 p.drawText(
84 col * keyWidth + 1, row * keyHeight + 1,
85 keyWidth, keyHeight,
86 Qt::AlignHCenter | Qt::AlignVCenter,
87 keys["r" + QString::number(row) + "c" + QString::number(col)].getL()
88 );
89
43} 90}
44 91
45void FunctionKeyboard::mousePressEvent(QMouseEvent *e) { 92void FunctionKeyboard::mousePressEvent(QMouseEvent *e) {
@@ -48,6 +95,12 @@ void FunctionKeyboard::mousePressEvent(QMouseEvent *e) {
48 pressedCol = e->x() / keyWidth; 95 pressedCol = e->x() / keyWidth;
49 96
50 paintKey(pressedRow, pressedCol); 97 paintKey(pressedRow, pressedCol);
98
99 // emit that sucker!
100 FKey k = keys["r" + QString::number(pressedRow) + "c" + QString::number(pressedCol)];
101 //QWSServer::sendKeyEvent(k.getU(), k.getQ(), 0, 1, 0);
102 //qwsServer->sendKeyEvent(k.getU(), k.getQ(), 0, 1, 0);
103 qwsServer->sendKeyEvent(0x41, 0, 0, 1, 0);
51} 104}
52 105
53void FunctionKeyboard::mouseReleaseEvent(QMouseEvent *) { 106void FunctionKeyboard::mouseReleaseEvent(QMouseEvent *) {
@@ -57,7 +110,12 @@ void FunctionKeyboard::mouseReleaseEvent(QMouseEvent *) {
57 int row = pressedRow; pressedRow = -1; 110 int row = pressedRow; pressedRow = -1;
58 int col = pressedCol; pressedCol = -1; 111 int col = pressedCol; pressedCol = -1;
59 paintKey(row, col); 112 paintKey(row, col);
113
114 FKey k = keys["r" + QString::number(row) + "c" + QString::number(col)];
115 //QWSServer::sendKeyEvent(k.getU(), k.getQ(), 0, 0, 0);
116 //qwsServer->sendKeyEvent(k.getU(), k.getQ(), 0, 0, 0);
60 } 117 }
118
61} 119}
62 120
63 121
diff --git a/noncore/apps/opie-console/function_keyboard.h b/noncore/apps/opie-console/function_keyboard.h
index f1ca037..bc3e25c 100644
--- a/noncore/apps/opie-console/function_keyboard.h
+++ b/noncore/apps/opie-console/function_keyboard.h
@@ -1,8 +1,28 @@
1#ifndef OPIE_FUNCTION_KEYBOARD_H 1#ifndef OPIE_FUNCTION_KEYBOARD_H
2#define OPIE_FUNCTION_KEYBOARD_H 2#define OPIE_FUNCTION_KEYBOARD_H
3 3
4#include <qpe/config.h>
4#include <qframe.h> 5#include <qframe.h>
5#include <qpainter.h> 6#include <qpainter.h>
7#include <qmap.h>
8
9class FKey {
10
11public:
12
13 FKey(): qcode(0), unicode(0) {};
14 FKey(const QString &l, ushort q, ushort u): label(l), qcode(q), unicode(u) {};
15
16 QString getL() { return label; }
17 ushort getQ() { return qcode; }
18 ushort getU() { return unicode; }
19
20private:
21
22 QString label;
23 ushort qcode;
24 ushort unicode;
25};
6 26
7class FunctionKeyboard : public QFrame { 27class FunctionKeyboard : public QFrame {
8 Q_OBJECT 28 Q_OBJECT
@@ -18,9 +38,14 @@ public:
18 void resizeEvent(QResizeEvent*); 38 void resizeEvent(QResizeEvent*);
19 39
20 40
41
21 QSize sizeHint() const; 42 QSize sizeHint() const;
22 43
23private: 44private:
45
46 // thie key for the map is the row/col
47 QMap<QString, FKey> keys;
48
24 uint numRows; 49 uint numRows;
25 uint numCols; 50 uint numCols;
26 uint keyHeight; 51 uint keyHeight;