summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console/function_keyboard.cpp
Unidiff
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.cpp77
1 files changed, 77 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