summaryrefslogtreecommitdiff
authorhash <hash>2002-10-15 16:26:14 (UTC)
committer hash <hash>2002-10-15 16:26:14 (UTC)
commit9861ca46526e65ecb00641008b9e8c1105ba1dc9 (patch) (unidiff)
tree457e4a90667bbc1c133b9eca91f31f7e641b1e4c
parentd0cd09e4a68ca8dc3acf50c13a0acce39cd36b55 (diff)
downloadopie-9861ca46526e65ecb00641008b9e8c1105ba1dc9.zip
opie-9861ca46526e65ecb00641008b9e8c1105ba1dc9.tar.gz
opie-9861ca46526e65ecb00641008b9e8c1105ba1dc9.tar.bz2
still trying to figure out how to get those events out wihtout crashing the damn thing
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/function_keyboard.cpp24
-rw-r--r--noncore/apps/opie-console/function_keyboard.h6
2 files changed, 23 insertions, 7 deletions
diff --git a/noncore/apps/opie-console/function_keyboard.cpp b/noncore/apps/opie-console/function_keyboard.cpp
index a5b19c0..ac35d1c 100644
--- a/noncore/apps/opie-console/function_keyboard.cpp
+++ b/noncore/apps/opie-console/function_keyboard.cpp
@@ -1,142 +1,152 @@
1#include "function_keyboard.h" 1#include "function_keyboard.h"
2#include <qsizepolicy.h> 2#include <qsizepolicy.h>
3#include <qevent.h> 3#include <qevent.h>
4#include <qwindowsystem_qws.h>
4#include <qapplication.h> 5#include <qapplication.h>
5 6
6FunctionKeyboard::FunctionKeyboard(QWidget *parent) : 7FunctionKeyboard::FunctionKeyboard(QWidget *parent) :
7 QFrame(parent), numRows(1), numCols(11), 8 QFrame(parent), numRows(1), numCols(11),
8 pressedRow(0), pressedCol(0) { 9 pressedRow(0), pressedCol(0) {
9 10
10 setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed)); 11 setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed));
11 12
12 Config conf("opie-console-keys"); 13 Config conf("opie-console-keys");
13 conf.setGroup("keys"); 14 conf.setGroup("keys");
14 for (int r = 0; r < numRows; r++) 15 for (int r = 0; r < numRows; r++)
15 for (int c = 0; c < numCols; c++) { 16 for (int c = 0; c < numCols; c++) {
16 17
17 QString handle = "r" + QString::number(r) + "c" + QString::number(c); 18 QString handle = "r" + QString::number(r) + "c" + QString::number(c);
18 QStringList value_list = conf.readListEntry( handle, '|'); 19 QStringList value_list = conf.readListEntry( handle, '|');
19 20
20 if (value_list.isEmpty()) continue; 21 if (value_list.isEmpty()) continue;
21 22
22 keys.insert( 23 keys.insert(
23 24
24 handle, 25 handle,
25 FKey (value_list[0], value_list[1].toUShort(), value_list[2].toUShort()) 26 FKey (value_list[0], value_list[1].toUShort(), value_list[2].toUShort())
26 ); 27 );
27 } 28 }
28 qWarning("loaded %d keys", keys.count()); 29 qWarning("loaded %d keys", keys.count());
29 30
30 31
31 32
32} 33}
33 34
34FunctionKeyboard::~FunctionKeyboard() { 35FunctionKeyboard::~FunctionKeyboard() {
35 36
36} 37}
37 38
38void FunctionKeyboard::paintEvent(QPaintEvent *e) { 39void FunctionKeyboard::paintEvent(QPaintEvent *e) {
39 40
40 QPainter p(this); 41 QPainter p(this);
41 p.setClipRect(e->rect()); 42 p.setClipRect(e->rect());
42 p.fillRect(0, 0, width(), height(), QColor(255,255,255)); 43 p.fillRect(0, 0, width(), height(), QColor(255,255,255));
43 44
44 p.setPen(QColor(0,0,0)); 45 p.setPen(QColor(0,0,0));
45 46
46 /* those decimals do count! becomes short if use plain int */ 47 /* those decimals do count! becomes short if use plain int */
47 for (double i = 0; i <= width(); i += keyWidth) { 48 for (double i = 0; i <= width(); i += keyWidth) {
48 49
49 p.drawLine((int)i, 0, (int)i, height()); 50 p.drawLine((int)i, 0, (int)i, height());
50 } 51 }
51 52
52 // sometimes the last line doesnt get drawn 53 // sometimes the last line doesnt get drawn
53 p.drawLine(width() -1, 0, width() -1, height()); 54 p.drawLine(width() -1, 0, width() -1, height());
54 55
55 for (int i = 0; i <= height(); i += keyHeight) { 56 for (int i = 0; i <= height(); i += keyHeight) {
56 57
57 p.drawLine(0, i, width(), i); 58 p.drawLine(0, i, width(), i);
58 } 59 }
59 60
60 for (int r = 0; r < numRows; r++) { 61 for (int r = 0; r < numRows; r++) {
61 for (int c = 0; c < numCols; c++) { 62 for (int c = 0; c < numCols; c++) {
62 63
63 QString handle = "r" + QString::number(r) + "c" + QString::number(c); 64 QString handle = "r" + QString::number(r) + "c" + QString::number(c);
64 if (keys.contains(handle)) { 65 if (keys.contains(handle)) {
65 66
66 p.drawText( 67 p.drawText(
67 c * keyWidth + 1, r * keyHeight + 1, 68 c * keyWidth + 1, r * keyHeight + 1,
68 keyWidth, keyHeight, 69 keyWidth, keyHeight,
69 Qt::AlignHCenter | Qt::AlignVCenter, 70 Qt::AlignHCenter | Qt::AlignVCenter,
70 keys[handle].getL() 71 keys[handle].getL()
71 ); 72 );
72 } 73 }
73 } 74 }
74 } 75 }
75} 76}
76 77
77void FunctionKeyboard::paintKey(int row, int col) { 78void FunctionKeyboard::paintKey(int row, int col) {
78 79
79 QPainter p(this); 80 QPainter p(this);
80 81
81 p.fillRect(QRect(QPoint(col * keyWidth + 1, row * keyHeight + 1), 82 p.fillRect(QRect(QPoint(col * keyWidth + 1, row * keyHeight + 1),
82 QPoint((col + 1) * keyWidth - 1, row * keyHeight + keyHeight- 1)), 83 QPoint((col + 1) * keyWidth - 1, row * keyHeight + keyHeight- 1)),
83 (pressedRow != -1 && pressedCol != -1 ) ? QColor(97,119,155) : QColor(255,255,255)); 84 (pressedRow != -1 && pressedCol != -1 ) ? QColor(97,119,155) : QColor(255,255,255));
84 p.drawText( 85 p.drawText(
85 col * keyWidth + 1, row * keyHeight + 1, 86 col * keyWidth + 1, row * keyHeight + 1,
86 keyWidth, keyHeight, 87 keyWidth, keyHeight,
87 Qt::AlignHCenter | Qt::AlignVCenter, 88 Qt::AlignHCenter | Qt::AlignVCenter,
88 keys["r" + QString::number(row) + "c" + QString::number(col)].getL() 89 keys["r" + QString::number(row) + "c" + QString::number(col)].getL()
89 ); 90 );
90 91
91} 92}
92 93
93void FunctionKeyboard::mousePressEvent(QMouseEvent *e) { 94void FunctionKeyboard::mousePressEvent(QMouseEvent *e) {
94 95
95 pressedRow = e->y() / keyHeight; 96 pressedRow = e->y() / keyHeight;
96 pressedCol = (int) (e->x() / keyWidth); 97 pressedCol = (int) (e->x() / keyWidth);
97 98
98 paintKey(pressedRow, pressedCol); 99 paintKey(pressedRow, pressedCol);
99 100
100 // emit that sucker! 101 // emit that sucker!
101 FKey k = keys["r" + QString::number(pressedRow) + "c" + QString::number(pressedCol)]; 102 FKey k = keys["r" + QString::number(pressedRow) + "c" + QString::number(pressedCol)];
102 //QWSServer::sendKeyEvent(k.getU(), k.getQ(), 0, 1, 0); 103 emit keyPressed(k.getU(), k.getQ(), 0, 1, 0);
103 //qwsServer->sendKeyEvent(k.getU(), k.getQ(), 0, 1, 0); 104 /*
104 //qwsServer->sendKeyEvent(0x41, 0, 0, 1, 0); 105 *
106 QWSServer::sendKeyEvent(k.getU(), k.getQ(), 0, 1, 0);
107 qwsServer->sendKeyEvent(k.getU(), k.getQ(), 0, 1, 0);
108 qwsServer->sendKeyEvent(0x41, 0, 0, 1, 0);
105 109
106 QKeyEvent ke(QEvent::KeyPress, k.getQ(), k.getU(), 0); 110 QKeyEvent ke(QEvent::KeyPress, k.getQ(), k.getU(), 0);
107 QApplication::sendEvent(this, &ke); 111 QApplication::sendEvent((QObject *)parent, &ke);
112 */
108 113
109} 114}
110 115
111void FunctionKeyboard::mouseReleaseEvent(QMouseEvent *) { 116void FunctionKeyboard::mouseReleaseEvent(QMouseEvent *) {
112 117
113 if (pressedRow != -1 && pressedRow != -1) { 118 if (pressedRow != -1 && pressedRow != -1) {
114 119
115 int row = pressedRow; pressedRow = -1; 120 int row = pressedRow; pressedRow = -1;
116 int col = pressedCol; pressedCol = -1; 121 int col = pressedCol; pressedCol = -1;
117 paintKey(row, col); 122 paintKey(row, col);
118 123
119 FKey k = keys["r" + QString::number(row) + "c" + QString::number(col)]; 124 FKey k = keys["r" + QString::number(row) + "c" + QString::number(col)];
120 //QWSServer::sendKeyEvent(k.getU(), k.getQ(), 0, 0, 0); 125 emit keyPressed(k.getU(), k.getQ(), 0, 0, 0);
121 //qwsServer->sendKeyEvent(k.getU(), k.getQ(), 0, 0, 0); 126
127 /*
128 QWSServer::sendKeyEvent(k.getU(), k.getQ(), 0, 0, 0);
129 qwsServer->sendKeyEvent(k.getU(), k.getQ(), 0, 0, 0);
130
122 QKeyEvent ke(QEvent::KeyRelease, k.getQ(), k.getU(), 0); 131 QKeyEvent ke(QEvent::KeyRelease, k.getQ(), k.getU(), 0);
123 QApplication::sendEvent(this, &ke); 132 QApplication::sendEvent((QObject *)parent, &ke);
133 */
124 } 134 }
125 135
126} 136}
127 137
128 138
129void FunctionKeyboard::resizeEvent(QResizeEvent*) { 139void FunctionKeyboard::resizeEvent(QResizeEvent*) {
130 140
131 /* set he default font height/width */ 141 /* set he default font height/width */
132 QFontMetrics fm=fontMetrics(); 142 QFontMetrics fm=fontMetrics();
133 keyHeight = fm.lineSpacing() + 2; 143 keyHeight = fm.lineSpacing() + 2;
134 keyWidth = (double)width()/numCols; 144 keyWidth = (double)width()/numCols;
135 145
136} 146}
137 147
138QSize FunctionKeyboard::sizeHint() const { 148QSize FunctionKeyboard::sizeHint() const {
139 149
140 return QSize(width(), keyHeight * numRows + 1); 150 return QSize(width(), keyHeight * numRows + 1);
141} 151}
142 152
diff --git a/noncore/apps/opie-console/function_keyboard.h b/noncore/apps/opie-console/function_keyboard.h
index bc3e25c..b8420ae 100644
--- a/noncore/apps/opie-console/function_keyboard.h
+++ b/noncore/apps/opie-console/function_keyboard.h
@@ -1,58 +1,64 @@
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 <qpe/config.h>
5#include <qframe.h> 5#include <qframe.h>
6#include <qpainter.h> 6#include <qpainter.h>
7#include <qmap.h> 7#include <qmap.h>
8 8
9class FKey { 9class FKey {
10 10
11public: 11public:
12 12
13 FKey(): qcode(0), unicode(0) {}; 13 FKey(): qcode(0), unicode(0) {};
14 FKey(const QString &l, ushort q, ushort u): label(l), qcode(q), unicode(u) {}; 14 FKey(const QString &l, ushort q, ushort u): label(l), qcode(q), unicode(u) {};
15 15
16 QString getL() { return label; } 16 QString getL() { return label; }
17 ushort getQ() { return qcode; } 17 ushort getQ() { return qcode; }
18 ushort getU() { return unicode; } 18 ushort getU() { return unicode; }
19 19
20private: 20private:
21 21
22 QString label; 22 QString label;
23 ushort qcode; 23 ushort qcode;
24 ushort unicode; 24 ushort unicode;
25}; 25};
26 26
27class FunctionKeyboard : public QFrame { 27class FunctionKeyboard : public QFrame {
28 Q_OBJECT 28 Q_OBJECT
29 29
30public: 30public:
31 FunctionKeyboard(QWidget *parent = 0); 31 FunctionKeyboard(QWidget *parent = 0);
32 ~FunctionKeyboard(); 32 ~FunctionKeyboard();
33 33
34 void paintEvent(QPaintEvent *); 34 void paintEvent(QPaintEvent *);
35 void paintKey(int, int); 35 void paintKey(int, int);
36 void mousePressEvent(QMouseEvent*); 36 void mousePressEvent(QMouseEvent*);
37 void mouseReleaseEvent(QMouseEvent*); 37 void mouseReleaseEvent(QMouseEvent*);
38 void resizeEvent(QResizeEvent*); 38 void resizeEvent(QResizeEvent*);
39 39
40 40
41 41
42 QSize sizeHint() const; 42 QSize sizeHint() const;
43 43
44signals:
45
46 void keyPressed(ushort, ushort, bool, bool, bool);
47
44private: 48private:
45 49
46 // thie key for the map is the row/col 50 // thie key for the map is the row/col
47 QMap<QString, FKey> keys; 51 QMap<QString, FKey> keys;
48 52
49 uint numRows; 53 uint numRows;
50 uint numCols; 54 uint numCols;
51 uint keyHeight; 55 uint keyHeight;
52 double keyWidth; // decimal point matters! 56 double keyWidth; // decimal point matters!
53 57
54 int pressedRow, pressedCol; 58 int pressedRow, pressedCol;
55 59
60 QObject *parent;
61
56}; 62};
57 63
58#endif 64#endif