author | hash <hash> | 2002-10-13 00:58:30 (UTC) |
---|---|---|
committer | hash <hash> | 2002-10-13 00:58:30 (UTC) |
commit | b977a4bc4a8ac2b8685c4fa13534f630dabbf956 (patch) (side-by-side diff) | |
tree | 60da6513fe4085857f447469031ad596ef2a13b8 | |
parent | 9333a4005b30aaa723447a044c9fce5a1e580317 (diff) | |
download | opie-b977a4bc4a8ac2b8685c4fa13534f630dabbf956.zip opie-b977a4bc4a8ac2b8685c4fa13534f630dabbf956.tar.gz opie-b977a4bc4a8ac2b8685c4fa13534f630dabbf956.tar.bz2 |
cant figure out why this segfaults when emits key
-rw-r--r-- | noncore/apps/opie-console/function_keyboard.cpp | 68 | ||||
-rw-r--r-- | noncore/apps/opie-console/function_keyboard.h | 25 |
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,72 +1,130 @@ #include "function_keyboard.h" #include <qsizepolicy.h> +#include <qwindowsystem_qws.h> FunctionKeyboard::FunctionKeyboard(QWidget *parent) : - QFrame(parent), numRows(2), numCols(15), + QFrame(parent), numRows(1), numCols(11), pressedRow(0), pressedCol(0) { - setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); + setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed)); + + Config conf("opie-console-keys"); + conf.setGroup("keys"); + for (int r = 0; r < numRows; r++) + for (int c = 0; c < numCols; c++) { + + QString handle = "r" + QString::number(r) + "c" + QString::number(c); + QStringList value_list = conf.readListEntry( handle, '|'); + + if (value_list.isEmpty()) continue; + + keys.insert( + + handle, + FKey (value_list[0], value_list[1].toUShort(), value_list[2].toUShort()) + ); + } + qWarning("loaded %d keys", keys.count()); + + } FunctionKeyboard::~FunctionKeyboard() { } void FunctionKeyboard::paintEvent(QPaintEvent *e) { QPainter p(this); p.setClipRect(e->rect()); p.fillRect(0, 0, width(), height(), QColor(255,255,255)); + p.setPen(QColor(0,0,0)); + /* those decimals do count! becomes short if use plain int */ for (double i = 0; i <= width(); i += keyWidth) { - p.setPen(QColor(0,0,0)); p.drawLine((int)i, 0, (int)i, height()); } - for (int i = 0; i <= height(); i += height()/numRows) { + // sometimes the last line doesnt get drawn + p.drawLine(width() -1, 0, width() -1, height()); + + for (int i = 0; i <= height(); i += keyHeight) { - p.setPen(QColor(0,0,0)); p.drawLine(0, i, width(), i); } + for (int r = 0; r < numRows; r++) { + for (int c = 0; c < numCols; c++) { + + QString handle = "r" + QString::number(r) + "c" + QString::number(c); + if (keys.contains(handle)) { + + p.drawText( + c * keyWidth + 1, r * keyHeight + 1, + keyWidth, keyHeight, + Qt::AlignHCenter | Qt::AlignVCenter, + keys[handle].getL() + ); + } + } + } } void FunctionKeyboard::paintKey(int row, int col) { QPainter p(this); + p.fillRect(QRect(QPoint(col * keyWidth + 1, row * keyHeight + 1), QPoint((col + 1) * keyWidth - 1, row * keyHeight + keyHeight- 1)), (pressedRow != -1 && pressedCol != -1 ) ? QColor(97,119,155) : QColor(255,255,255)); + p.drawText( + col * keyWidth + 1, row * keyHeight + 1, + keyWidth, keyHeight, + Qt::AlignHCenter | Qt::AlignVCenter, + keys["r" + QString::number(row) + "c" + QString::number(col)].getL() + ); + } void FunctionKeyboard::mousePressEvent(QMouseEvent *e) { pressedRow = e->y() / keyHeight; pressedCol = e->x() / keyWidth; paintKey(pressedRow, pressedCol); + + // emit that sucker! + FKey k = keys["r" + QString::number(pressedRow) + "c" + QString::number(pressedCol)]; + //QWSServer::sendKeyEvent(k.getU(), k.getQ(), 0, 1, 0); + //qwsServer->sendKeyEvent(k.getU(), k.getQ(), 0, 1, 0); + qwsServer->sendKeyEvent(0x41, 0, 0, 1, 0); } void FunctionKeyboard::mouseReleaseEvent(QMouseEvent *) { if (pressedRow != -1 && pressedRow != -1) { int row = pressedRow; pressedRow = -1; int col = pressedCol; pressedCol = -1; paintKey(row, col); + + FKey k = keys["r" + QString::number(row) + "c" + QString::number(col)]; + //QWSServer::sendKeyEvent(k.getU(), k.getQ(), 0, 0, 0); + //qwsServer->sendKeyEvent(k.getU(), k.getQ(), 0, 0, 0); } + } void FunctionKeyboard::resizeEvent(QResizeEvent*) { /* set he default font height/width */ QFontMetrics fm=fontMetrics(); keyHeight = fm.lineSpacing() + 2; keyWidth = (double)width()/numCols; } 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,33 +1,58 @@ #ifndef OPIE_FUNCTION_KEYBOARD_H #define OPIE_FUNCTION_KEYBOARD_H +#include <qpe/config.h> #include <qframe.h> #include <qpainter.h> +#include <qmap.h> + +class FKey { + +public: + + FKey(): qcode(0), unicode(0) {}; + FKey(const QString &l, ushort q, ushort u): label(l), qcode(q), unicode(u) {}; + + QString getL() { return label; } + ushort getQ() { return qcode; } + ushort getU() { return unicode; } + +private: + + QString label; + ushort qcode; + ushort unicode; +}; class FunctionKeyboard : public QFrame { Q_OBJECT public: FunctionKeyboard(QWidget *parent = 0); ~FunctionKeyboard(); void paintEvent(QPaintEvent *); void paintKey(int, int); void mousePressEvent(QMouseEvent*); void mouseReleaseEvent(QMouseEvent*); void resizeEvent(QResizeEvent*); + QSize sizeHint() const; private: + + // thie key for the map is the row/col + QMap<QString, FKey> keys; + uint numRows; uint numCols; uint keyHeight; double keyWidth; // decimal point matters! int pressedRow, pressedCol; }; #endif |