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