summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console/function_keyboard.cpp
authorhash <hash>2002-10-13 00:58:30 (UTC)
committer hash <hash>2002-10-13 00:58:30 (UTC)
commitb977a4bc4a8ac2b8685c4fa13534f630dabbf956 (patch) (unidiff)
tree60da6513fe4085857f447469031ad596ef2a13b8 /noncore/apps/opie-console/function_keyboard.cpp
parent9333a4005b30aaa723447a044c9fce5a1e580317 (diff)
downloadopie-b977a4bc4a8ac2b8685c4fa13534f630dabbf956.zip
opie-b977a4bc4a8ac2b8685c4fa13534f630dabbf956.tar.gz
opie-b977a4bc4a8ac2b8685c4fa13534f630dabbf956.tar.bz2
cant figure out why this segfaults when emits key
Diffstat (limited to 'noncore/apps/opie-console/function_keyboard.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/function_keyboard.cpp68
1 files changed, 63 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