summaryrefslogtreecommitdiff
path: root/noncore
authorhash <hash>2002-10-11 19:46:50 (UTC)
committer hash <hash>2002-10-11 19:46:50 (UTC)
commitcef14e20ffcf1aa5dc62f0f3d6774efcbffcd6b7 (patch) (side-by-side diff)
tree539bb692e4a5c2be489ac1c70645ae3b36631ed7 /noncore
parent4826955529ea98afbad60f18ae81aebc59cbfdcd (diff)
downloadopie-cef14e20ffcf1aa5dc62f0f3d6774efcbffcd6b7.zip
opie-cef14e20ffcf1aa5dc62f0f3d6774efcbffcd6b7.tar.gz
opie-cef14e20ffcf1aa5dc62f0f3d6774efcbffcd6b7.tar.bz2
initial upload for the keyboard widget
Diffstat (limited to 'noncore') (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 @@
+#include "function_keyboard.h"
+#include <qsizepolicy.h>
+
+FunctionKeyboard::FunctionKeyboard(QWidget *parent) :
+ QFrame(parent), numRows(2), numCols(15),
+ pressedRow(0), pressedCol(0) {
+
+ setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
+
+}
+
+FunctionKeyboard::~FunctionKeyboard() {
+
+}
+
+void FunctionKeyboard::paintEvent(QPaintEvent *e) {
+
+ QPainter p(this);
+ p.setClipRect(e->rect());
+ p.fillRect(0, 0, width(), height(), QColor(255,255,255));
+
+ /* 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) {
+
+ p.setPen(QColor(0,0,0));
+ p.drawLine(0, i, width(), i);
+ }
+
+}
+
+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));
+}
+
+void FunctionKeyboard::mousePressEvent(QMouseEvent *e) {
+
+ pressedRow = e->y() / keyHeight;
+ pressedCol = e->x() / keyWidth;
+
+ paintKey(pressedRow, pressedCol);
+}
+
+void FunctionKeyboard::mouseReleaseEvent(QMouseEvent *) {
+
+ if (pressedRow != -1 && pressedRow != -1) {
+
+ int row = pressedRow; pressedRow = -1;
+ int col = pressedCol; pressedCol = -1;
+ paintKey(row, col);
+ }
+}
+
+
+void FunctionKeyboard::resizeEvent(QResizeEvent*) {
+
+ /* set he default font height/width */
+ QFontMetrics fm=fontMetrics();
+ keyHeight = fm.lineSpacing() + 2;
+ keyWidth = (double)width()/numCols;
+
+}
+
+QSize FunctionKeyboard::sizeHint() const {
+
+ return QSize(width(), keyHeight * numRows + 1);
+}
+
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 @@
+#ifndef OPIE_FUNCTION_KEYBOARD_H
+#define OPIE_FUNCTION_KEYBOARD_H
+
+#include <qframe.h>
+#include <qpainter.h>
+
+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:
+ uint numRows;
+ uint numCols;
+ uint keyHeight;
+ double keyWidth; // decimal point matters!
+
+ int pressedRow, pressedCol;
+
+};
+
+#endif