summaryrefslogtreecommitdiff
authorhash <hash>2002-10-11 19:46:50 (UTC)
committer hash <hash>2002-10-11 19:46:50 (UTC)
commitcef14e20ffcf1aa5dc62f0f3d6774efcbffcd6b7 (patch) (unidiff)
tree539bb692e4a5c2be489ac1c70645ae3b36631ed7
parent4826955529ea98afbad60f18ae81aebc59cbfdcd (diff)
downloadopie-cef14e20ffcf1aa5dc62f0f3d6774efcbffcd6b7.zip
opie-cef14e20ffcf1aa5dc62f0f3d6774efcbffcd6b7.tar.gz
opie-cef14e20ffcf1aa5dc62f0f3d6774efcbffcd6b7.tar.bz2
initial upload for the keyboard widget
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/function_keyboard.cpp77
-rw-r--r--noncore/apps/opie-console/function_keyboard.h33
2 files changed, 110 insertions, 0 deletions
diff --git a/noncore/apps/opie-console/function_keyboard.cpp b/noncore/apps/opie-console/function_keyboard.cpp
new file mode 100644
index 0000000..a3da5b2
--- a/dev/null
+++ b/noncore/apps/opie-console/function_keyboard.cpp
@@ -0,0 +1,77 @@
1#include "function_keyboard.h"
2#include <qsizepolicy.h>
3
4FunctionKeyboard::FunctionKeyboard(QWidget *parent) :
5 QFrame(parent), numRows(2), numCols(15),
6 pressedRow(0), pressedCol(0) {
7
8 setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
9
10}
11
12FunctionKeyboard::~FunctionKeyboard() {
13
14}
15
16void FunctionKeyboard::paintEvent(QPaintEvent *e) {
17
18 QPainter p(this);
19 p.setClipRect(e->rect());
20 p.fillRect(0, 0, width(), height(), QColor(255,255,255));
21
22 /* those decimals do count! becomes short if use plain int */
23 for (double i = 0; i <= width(); i += keyWidth) {
24
25 p.setPen(QColor(0,0,0));
26 p.drawLine((int)i, 0, (int)i, height());
27 }
28
29 for (int i = 0; i <= height(); i += height()/numRows) {
30
31 p.setPen(QColor(0,0,0));
32 p.drawLine(0, i, width(), i);
33 }
34
35}
36
37void FunctionKeyboard::paintKey(int row, int col) {
38
39 QPainter p(this);
40 p.fillRect(QRect(QPoint(col * keyWidth + 1, row * keyHeight + 1),
41 QPoint((col + 1) * keyWidth - 1, row * keyHeight + keyHeight- 1)),
42 (pressedRow != -1 && pressedCol != -1 ) ? QColor(97,119,155) : QColor(255,255,255));
43}
44
45void FunctionKeyboard::mousePressEvent(QMouseEvent *e) {
46
47 pressedRow = e->y() / keyHeight;
48 pressedCol = e->x() / keyWidth;
49
50 paintKey(pressedRow, pressedCol);
51}
52
53void FunctionKeyboard::mouseReleaseEvent(QMouseEvent *) {
54
55 if (pressedRow != -1 && pressedRow != -1) {
56
57 int row = pressedRow; pressedRow = -1;
58 int col = pressedCol; pressedCol = -1;
59 paintKey(row, col);
60 }
61}
62
63
64void FunctionKeyboard::resizeEvent(QResizeEvent*) {
65
66 /* set he default font height/width */
67 QFontMetrics fm=fontMetrics();
68 keyHeight = fm.lineSpacing() + 2;
69 keyWidth = (double)width()/numCols;
70
71}
72
73QSize FunctionKeyboard::sizeHint() const {
74
75 return QSize(width(), keyHeight * numRows + 1);
76}
77
diff --git a/noncore/apps/opie-console/function_keyboard.h b/noncore/apps/opie-console/function_keyboard.h
new file mode 100644
index 0000000..f1ca037
--- a/dev/null
+++ b/noncore/apps/opie-console/function_keyboard.h
@@ -0,0 +1,33 @@
1#ifndef OPIE_FUNCTION_KEYBOARD_H
2#define OPIE_FUNCTION_KEYBOARD_H
3
4#include <qframe.h>
5#include <qpainter.h>
6
7class FunctionKeyboard : public QFrame {
8 Q_OBJECT
9
10public:
11 FunctionKeyboard(QWidget *parent = 0);
12 ~FunctionKeyboard();
13
14 void paintEvent(QPaintEvent *);
15 void paintKey(int, int);
16 void mousePressEvent(QMouseEvent*);
17 void mouseReleaseEvent(QMouseEvent*);
18 void resizeEvent(QResizeEvent*);
19
20
21 QSize sizeHint() const;
22
23private:
24 uint numRows;
25 uint numCols;
26 uint keyHeight;
27 double keyWidth; // decimal point matters!
28
29 int pressedRow, pressedCol;
30
31};
32
33#endif