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.cpp92
1 files changed, 86 insertions, 6 deletions
diff --git a/noncore/apps/opie-console/function_keyboard.cpp b/noncore/apps/opie-console/function_keyboard.cpp
index 100fdfc..977a384 100644
--- a/noncore/apps/opie-console/function_keyboard.cpp
+++ b/noncore/apps/opie-console/function_keyboard.cpp
@@ -1,12 +1,21 @@
1#include "function_keyboard.h" 1#include "function_keyboard.h"
2
3#include <qpe/resource.h>
4#include <qpe/qpeapplication.h>
2#include <qsizepolicy.h> 5#include <qsizepolicy.h>
3#include <qevent.h> 6#include <qevent.h>
4#include <qwindowsystem_qws.h> 7#include <qwindowsystem_qws.h>
5#include <qapplication.h> 8#include <qapplication.h>
6#include <qlayout.h> 9#include <qlayout.h>
10#include <qspinbox.h>
11#include <qlabel.h>
12#include <qcombobox.h>
13#include <qdir.h>
14
15/* FunctionKeyboard {{{1 */
7 16
8FunctionKeyboard::FunctionKeyboard(QWidget *parent) : 17FunctionKeyboard::FunctionKeyboard(QWidget *parent) :
9 QFrame(parent), numRows(2), numCols(11), 18 QFrame(parent), numRows(2), numCols(11),
10 pressedRow(0), pressedCol(0) { 19 pressedRow(0), pressedCol(0) {
11 20
12 setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed)); 21 setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed));
@@ -35,12 +44,24 @@ FunctionKeyboard::FunctionKeyboard(QWidget *parent) :
35} 44}
36 45
37FunctionKeyboard::~FunctionKeyboard() { 46FunctionKeyboard::~FunctionKeyboard() {
38 47
39} 48}
40 49
50void FunctionKeyboard::changeRows(int r) {
51
52 numRows = r;
53 repaint(false);
54}
55void FunctionKeyboard::changeCols(int c) {
56
57 numCols = c;
58 keyWidth = (double)width()/numCols; // have to reset this thing too
59 repaint(false);
60}
61
41void FunctionKeyboard::paintEvent(QPaintEvent *e) { 62void FunctionKeyboard::paintEvent(QPaintEvent *e) {
42 63
43 QPainter p(this); 64 QPainter p(this);
44 p.setClipRect(e->rect()); 65 p.setClipRect(e->rect());
45 p.fillRect(0, 0, width(), height(), QColor(255,255,255)); 66 p.fillRect(0, 0, width(), height(), QColor(255,255,255));
46 67
@@ -88,37 +109,45 @@ void FunctionKeyboard::paintKey(int row, int col) {
88 col * keyWidth + 1, row * keyHeight + 1, 109 col * keyWidth + 1, row * keyHeight + 1,
89 keyWidth, keyHeight, 110 keyWidth, keyHeight,
90 Qt::AlignHCenter | Qt::AlignVCenter, 111 Qt::AlignHCenter | Qt::AlignVCenter,
91 keys["r" + QString::number(row) + "c" + QString::number(col)].getL() 112 keys["r" + QString::number(row) + "c" + QString::number(col)].getL()
92 ); 113 );
93 114
115 if (row == numRows) {
116
117 // sometimes it doesnt draw the last line
118 p.drawLine((col+1) * keyWidth -2, row * keyHeight,
119 (col+1) * keyWidth -2, (row + 1) * keyHeight
120 );
121 }
122
94} 123}
95 124
96void FunctionKeyboard::mousePressEvent(QMouseEvent *e) { 125void FunctionKeyboard::mousePressEvent(QMouseEvent *e) {
97 126
98 pressedRow = e->y() / keyHeight; 127 pressedRow = e->y() / keyHeight;
99 pressedCol = (int) (e->x() / keyWidth); 128 pressedCol = (int) (e->x() / keyWidth);
100 129
101 paintKey(pressedRow, pressedCol); 130 paintKey(pressedRow, pressedCol);
102 131
103 // emit that sucker! 132 // emit that sucker!
104 FKey k = keys["r" + QString::number(pressedRow) + "c" + QString::number(pressedCol)]; 133 FKey k = keys["r" + QString::number(pressedRow) + "c" + QString::number(pressedCol)];
105 emit keyPressed(k.getU(), k.getQ(), 0, 1, 0); 134 emit keyPressed(k.getU(), k.getQ(), 0, 1, 0, pressedRow, pressedCol);
106 135
107} 136}
108 137
109void FunctionKeyboard::mouseReleaseEvent(QMouseEvent *) { 138void FunctionKeyboard::mouseReleaseEvent(QMouseEvent *) {
110 139
111 if (pressedRow != -1 && pressedRow != -1) { 140 if (pressedRow != -1 && pressedRow != -1) {
112 141
113 int row = pressedRow; pressedRow = -1; 142 int row = pressedRow; pressedRow = -1;
114 int col = pressedCol; pressedCol = -1; 143 int col = pressedCol; pressedCol = -1;
115 paintKey(row, col); 144 paintKey(row, col);
116 145
117 FKey k = keys["r" + QString::number(row) + "c" + QString::number(col)]; 146 FKey k = keys["r" + QString::number(row) + "c" + QString::number(col)];
118 emit keyPressed(k.getU(), k.getQ(), 0, 0, 0); 147 emit keyPressed(k.getU(), k.getQ(), 0, 0, 0, pressedRow, pressedCol);
119 } 148 }
120 149
121} 150}
122 151
123 152
124void FunctionKeyboard::resizeEvent(QResizeEvent*) { 153void FunctionKeyboard::resizeEvent(QResizeEvent*) {
@@ -154,29 +183,80 @@ void FunctionKeyboard::loadDefaults() {
154 keys.insert( "r1c8", FKey ("End", 4113, 0)); 183 keys.insert( "r1c8", FKey ("End", 4113, 0));
155 keys.insert( "r1c9", FKey ("PU", 4118, 0)); 184 keys.insert( "r1c9", FKey ("PU", 4118, 0));
156 keys.insert( "r1c10", FKey ("PD", 4119, 0)); 185 keys.insert( "r1c10", FKey ("PD", 4119, 0));
157 186
158} 187}
159 188
189/* FunctionKeyboardConfig {{{1 */
160 190
161FunctionKeyboardConfig::FunctionKeyboardConfig(const QString& name, QWidget* parent) : 191FunctionKeyboardConfig::FunctionKeyboardConfig(const QString& name, QWidget* parent) :
162 ProfileDialogKeyWidget(name, parent) { 192 ProfileDialogKeyWidget(name, parent) {
163 193
164 194
165 FunctionKeyboard *kb = new FunctionKeyboard(this); 195 kb = new FunctionKeyboard(this);
196
166 QGroupBox *dimentions = new QGroupBox(2, Qt::Horizontal, tr("Dimentions"), this); 197 QGroupBox *dimentions = new QGroupBox(2, Qt::Horizontal, tr("Dimentions"), this);
167 QGroupBox *editKey = new QGroupBox(2, Qt::Horizontal, tr("Edit"), this); 198 QLabel *l = new QLabel("Rows", dimentions);
199 QSpinBox *m_rowBox = new QSpinBox(1, 15, 1, dimentions);
200 connect (m_rowBox, SIGNAL(valueChanged(int)), this, SLOT(slotChangeRows(int)));
201 l = new QLabel("Columns", dimentions);
202 m_colBox = new QSpinBox(1, 15, 1, dimentions);
203 connect (m_colBox, SIGNAL(valueChanged(int)), this, SLOT(slotChangeCols(int)));
204
205 QGroupBox *editKey = new QGroupBox(2, Qt::Horizontal, tr("Edit Key"), this);
206 l = new QLabel("Label", editKey);
207 /*
208 m_labels = new QComboBox(false, editKey);
209 labels->insertItem("text");
210
211 QStringList files = QDir(QPEApplication::qpeDir() + "pics/console/keys/", "*.png").entryList();
212
213 for (uint i = 0; i < files.count(); i++) {
214
215 m_labels->insertItem(Resource::loadPixmap("console/keys/" + files[i]));
216 }
217 connect (m_labels, SIGNAL(activated(int)), this, SLOT(slotChangeIcon(int)));
218 */
168 219
169 QVBoxLayout *root = new QVBoxLayout(this, 2); 220 QVBoxLayout *root = new QVBoxLayout(this, 2);
170 root->addWidget(kb); 221 root->addWidget(kb);
171 root->addWidget(dimentions); 222 root->addWidget(dimentions);
172 root->addWidget(editKey); 223 root->addWidget(editKey);
173} 224}
174FunctionKeyboardConfig::~FunctionKeyboardConfig() { 225FunctionKeyboardConfig::~FunctionKeyboardConfig() {
175 226
176} 227}
177void FunctionKeyboardConfig::load (const Profile& ) { 228void FunctionKeyboardConfig::load (const Profile& prof) {
229 int i = prof.readNumEntry("keb_rows", 1);
230 //m_rowBox->setValue(i);
231}
232void FunctionKeyboardConfig::save (Profile& prof) {
233
234 //prof.writeEntry("keb_rows", m_rowBox->value());
235
236}
237void FunctionKeyboardConfig::slotChangeRows(int r) {
238
239 kb->changeRows(r);
240
241 // have to do this so the whole thing gets redrawn
242 kb->hide(); kb->show();
243}
244void FunctionKeyboardConfig::slotChangeCols(int c) {
245
246 kb->changeCols(c);
247}
248void FunctionKeyboardConfig::slotKeyPressed(ushort, ushort, bool, bool, bool, ushort row, ushort col) {
178 249
179} 250}
180void FunctionKeyboardConfig::save (Profile& ) { 251void FunctionKeyboardConfig::slotChangeIcon(int index) {
181 252
253 if (index == 0) {
254
255 // is text
256 //if(!labels->editable()) labels->setEditable(true);
257 } else {
258
259 // is a pixmap
260 //if (labels->editable()) labels->setEditable(false);
261 }
182} 262}