-rw-r--r-- | noncore/apps/opie-console/function_keyboard.cpp | 43 | ||||
-rw-r--r-- | noncore/apps/opie-console/function_keyboard.h | 9 | ||||
-rw-r--r-- | noncore/apps/opie-console/mainwindow.cpp | 2 |
3 files changed, 31 insertions, 23 deletions
diff --git a/noncore/apps/opie-console/function_keyboard.cpp b/noncore/apps/opie-console/function_keyboard.cpp index ac35d1c..4119ad4 100644 --- a/noncore/apps/opie-console/function_keyboard.cpp +++ b/noncore/apps/opie-console/function_keyboard.cpp | |||
@@ -1,41 +1,42 @@ | |||
1 | #include "function_keyboard.h" | 1 | #include "function_keyboard.h" |
2 | #include <qsizepolicy.h> | 2 | #include <qsizepolicy.h> |
3 | #include <qevent.h> | 3 | #include <qevent.h> |
4 | #include <qwindowsystem_qws.h> | 4 | #include <qwindowsystem_qws.h> |
5 | #include <qapplication.h> | 5 | #include <qapplication.h> |
6 | 6 | ||
7 | FunctionKeyboard::FunctionKeyboard(QWidget *parent) : | 7 | FunctionKeyboard::FunctionKeyboard(QWidget *parent) : |
8 | QFrame(parent), numRows(1), numCols(11), | 8 | QFrame(parent), numRows(2), numCols(11), |
9 | pressedRow(0), pressedCol(0) { | 9 | pressedRow(0), pressedCol(0) { |
10 | 10 | ||
11 | setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed)); | 11 | setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed)); |
12 | 12 | ||
13 | Config conf("opie-console-keys"); | 13 | Config conf("opie-console-keys"); |
14 | conf.setGroup("keys"); | 14 | conf.setGroup("keys"); |
15 | for (int r = 0; r < numRows; r++) | 15 | for (int r = 0; r < numRows; r++) |
16 | for (int c = 0; c < numCols; c++) { | 16 | for (int c = 0; c < numCols; c++) { |
17 | 17 | ||
18 | QString handle = "r" + QString::number(r) + "c" + QString::number(c); | 18 | QString handle = "r" + QString::number(r) + "c" + QString::number(c); |
19 | QStringList value_list = conf.readListEntry( handle, '|'); | 19 | QStringList value_list = conf.readListEntry( handle, '|'); |
20 | 20 | ||
21 | if (value_list.isEmpty()) continue; | 21 | if (value_list.isEmpty()) continue; |
22 | 22 | ||
23 | keys.insert( | 23 | keys.insert( |
24 | 24 | ||
25 | handle, | 25 | handle, |
26 | FKey (value_list[0], value_list[1].toUShort(), value_list[2].toUShort()) | 26 | FKey (value_list[0], value_list[1].toUShort(), value_list[2].toUShort()) |
27 | ); | 27 | ); |
28 | } | 28 | } |
29 | qWarning("loaded %d keys", keys.count()); | 29 | //qWarning("loaded %d keys", keys.count()); |
30 | if (keys.isEmpty()) loadDefaults(); | ||
30 | 31 | ||
31 | 32 | ||
32 | 33 | ||
33 | } | 34 | } |
34 | 35 | ||
35 | FunctionKeyboard::~FunctionKeyboard() { | 36 | FunctionKeyboard::~FunctionKeyboard() { |
36 | 37 | ||
37 | } | 38 | } |
38 | 39 | ||
39 | void FunctionKeyboard::paintEvent(QPaintEvent *e) { | 40 | void FunctionKeyboard::paintEvent(QPaintEvent *e) { |
40 | 41 | ||
41 | QPainter p(this); | 42 | QPainter p(this); |
@@ -92,61 +93,65 @@ void FunctionKeyboard::paintKey(int row, int col) { | |||
92 | } | 93 | } |
93 | 94 | ||
94 | void FunctionKeyboard::mousePressEvent(QMouseEvent *e) { | 95 | void FunctionKeyboard::mousePressEvent(QMouseEvent *e) { |
95 | 96 | ||
96 | pressedRow = e->y() / keyHeight; | 97 | pressedRow = e->y() / keyHeight; |
97 | pressedCol = (int) (e->x() / keyWidth); | 98 | pressedCol = (int) (e->x() / keyWidth); |
98 | 99 | ||
99 | paintKey(pressedRow, pressedCol); | 100 | paintKey(pressedRow, pressedCol); |
100 | 101 | ||
101 | // emit that sucker! | 102 | // emit that sucker! |
102 | FKey k = keys["r" + QString::number(pressedRow) + "c" + QString::number(pressedCol)]; | 103 | FKey k = keys["r" + QString::number(pressedRow) + "c" + QString::number(pressedCol)]; |
103 | emit keyPressed(k.getU(), k.getQ(), 0, 1, 0); | 104 | emit keyPressed(k.getU(), k.getQ(), 0, 1, 0); |
104 | /* | ||
105 | * | ||
106 | QWSServer::sendKeyEvent(k.getU(), k.getQ(), 0, 1, 0); | ||
107 | qwsServer->sendKeyEvent(k.getU(), k.getQ(), 0, 1, 0); | ||
108 | qwsServer->sendKeyEvent(0x41, 0, 0, 1, 0); | ||
109 | |||
110 | QKeyEvent ke(QEvent::KeyPress, k.getQ(), k.getU(), 0); | ||
111 | QApplication::sendEvent((QObject *)parent, &ke); | ||
112 | */ | ||
113 | 105 | ||
114 | } | 106 | } |
115 | 107 | ||
116 | void FunctionKeyboard::mouseReleaseEvent(QMouseEvent *) { | 108 | void FunctionKeyboard::mouseReleaseEvent(QMouseEvent *) { |
117 | 109 | ||
118 | if (pressedRow != -1 && pressedRow != -1) { | 110 | if (pressedRow != -1 && pressedRow != -1) { |
119 | 111 | ||
120 | int row = pressedRow; pressedRow = -1; | 112 | int row = pressedRow; pressedRow = -1; |
121 | int col = pressedCol; pressedCol = -1; | 113 | int col = pressedCol; pressedCol = -1; |
122 | paintKey(row, col); | 114 | paintKey(row, col); |
123 | 115 | ||
124 | FKey k = keys["r" + QString::number(row) + "c" + QString::number(col)]; | 116 | FKey k = keys["r" + QString::number(row) + "c" + QString::number(col)]; |
125 | emit keyPressed(k.getU(), k.getQ(), 0, 0, 0); | 117 | emit keyPressed(k.getU(), k.getQ(), 0, 0, 0); |
126 | |||
127 | /* | ||
128 | QWSServer::sendKeyEvent(k.getU(), k.getQ(), 0, 0, 0); | ||
129 | qwsServer->sendKeyEvent(k.getU(), k.getQ(), 0, 0, 0); | ||
130 | |||
131 | QKeyEvent ke(QEvent::KeyRelease, k.getQ(), k.getU(), 0); | ||
132 | QApplication::sendEvent((QObject *)parent, &ke); | ||
133 | */ | ||
134 | } | 118 | } |
135 | 119 | ||
136 | } | 120 | } |
137 | 121 | ||
138 | 122 | ||
139 | void FunctionKeyboard::resizeEvent(QResizeEvent*) { | 123 | void FunctionKeyboard::resizeEvent(QResizeEvent*) { |
140 | 124 | ||
141 | /* set he default font height/width */ | 125 | /* set he default font height/width */ |
142 | QFontMetrics fm=fontMetrics(); | 126 | QFontMetrics fm=fontMetrics(); |
143 | keyHeight = fm.lineSpacing() + 2; | 127 | keyHeight = fm.lineSpacing() + 2; |
144 | keyWidth = (double)width()/numCols; | 128 | keyWidth = (double)width()/numCols; |
145 | 129 | ||
146 | } | 130 | } |
147 | 131 | ||
148 | QSize FunctionKeyboard::sizeHint() const { | 132 | QSize FunctionKeyboard::sizeHint() const { |
149 | 133 | ||
150 | return QSize(width(), keyHeight * numRows + 1); | 134 | return QSize(width(), keyHeight * numRows + 1); |
151 | } | 135 | } |
152 | 136 | ||
137 | void FunctionKeyboard::loadDefaults() { | ||
138 | |||
139 | /* what keys should be default? */ | ||
140 | keys.insert( "r0c0", FKey ("F1", 4144, 0)); | ||
141 | keys.insert( "r0c1", FKey ("F2", 4145, 0)); | ||
142 | keys.insert( "r0c2", FKey ("F3", 4145, 0)); | ||
143 | keys.insert( "r0c3", FKey ("F4", 4146, 0)); | ||
144 | keys.insert( "r0c4", FKey ("F5", 4147, 0)); | ||
145 | keys.insert( "r0c5", FKey ("F6", 4148, 0)); | ||
146 | keys.insert( "r0c6", FKey ("F7", 4149, 0)); | ||
147 | keys.insert( "r0c7", FKey ("F8", 4150, 0)); | ||
148 | keys.insert( "r0c8", FKey ("F9", 4151, 0)); | ||
149 | keys.insert( "r0c9", FKey ("F10", 4152, 0)); | ||
150 | keys.insert( "r0c10", FKey ("F11", 4153, 0)); | ||
151 | |||
152 | keys.insert( "r1c7", FKey ("Ho", 4112, 0)); | ||
153 | keys.insert( "r1c8", FKey ("End", 4113, 0)); | ||
154 | keys.insert( "r1c9", FKey ("PU", 4118, 0)); | ||
155 | keys.insert( "r1c10", FKey ("PD", 4119, 0)); | ||
156 | |||
157 | } | ||
diff --git a/noncore/apps/opie-console/function_keyboard.h b/noncore/apps/opie-console/function_keyboard.h index b8420ae..8d05e2b 100644 --- a/noncore/apps/opie-console/function_keyboard.h +++ b/noncore/apps/opie-console/function_keyboard.h | |||
@@ -8,54 +8,57 @@ | |||
8 | 8 | ||
9 | class FKey { | 9 | class FKey { |
10 | 10 | ||
11 | public: | 11 | public: |
12 | 12 | ||
13 | FKey(): qcode(0), unicode(0) {}; | 13 | FKey(): qcode(0), unicode(0) {}; |
14 | FKey(const QString &l, ushort q, ushort u): label(l), qcode(q), unicode(u) {}; | 14 | FKey(const QString &l, ushort q, ushort u): label(l), qcode(q), unicode(u) {}; |
15 | 15 | ||
16 | QString getL() { return label; } | 16 | QString getL() { return label; } |
17 | ushort getQ() { return qcode; } | 17 | ushort getQ() { return qcode; } |
18 | ushort getU() { return unicode; } | 18 | ushort getU() { return unicode; } |
19 | 19 | ||
20 | |||
20 | private: | 21 | private: |
21 | 22 | ||
22 | QString label; | 23 | QString label; |
23 | ushort qcode; | 24 | ushort qcode; |
24 | ushort unicode; | 25 | ushort unicode; |
25 | }; | 26 | }; |
26 | 27 | ||
27 | class FunctionKeyboard : public QFrame { | 28 | class FunctionKeyboard : public QFrame { |
28 | Q_OBJECT | 29 | Q_OBJECT |
29 | 30 | ||
30 | public: | 31 | public: |
31 | FunctionKeyboard(QWidget *parent = 0); | 32 | FunctionKeyboard(QWidget *parent = 0); |
32 | ~FunctionKeyboard(); | 33 | ~FunctionKeyboard(); |
33 | 34 | ||
34 | void paintEvent(QPaintEvent *); | 35 | void paintEvent(QPaintEvent *); |
35 | void paintKey(int, int); | 36 | void paintKey(int, int); |
36 | void mousePressEvent(QMouseEvent*); | 37 | void mousePressEvent(QMouseEvent*); |
37 | void mouseReleaseEvent(QMouseEvent*); | 38 | void mouseReleaseEvent(QMouseEvent*); |
38 | void resizeEvent(QResizeEvent*); | 39 | void resizeEvent(QResizeEvent*); |
39 | |||
40 | |||
41 | |||
42 | QSize sizeHint() const; | 40 | QSize sizeHint() const; |
43 | 41 | ||
44 | signals: | 42 | signals: |
45 | 43 | ||
46 | void keyPressed(ushort, ushort, bool, bool, bool); | 44 | void keyPressed(ushort, ushort, bool, bool, bool); |
47 | 45 | ||
48 | private: | 46 | private: |
49 | 47 | ||
48 | void loadDefaults(); | ||
49 | |||
50 | |||
51 | private: | ||
52 | |||
50 | // thie key for the map is the row/col | 53 | // thie key for the map is the row/col |
51 | QMap<QString, FKey> keys; | 54 | QMap<QString, FKey> keys; |
52 | 55 | ||
53 | uint numRows; | 56 | uint numRows; |
54 | uint numCols; | 57 | uint numCols; |
55 | uint keyHeight; | 58 | uint keyHeight; |
56 | double keyWidth; // decimal point matters! | 59 | double keyWidth; // decimal point matters! |
57 | 60 | ||
58 | int pressedRow, pressedCol; | 61 | int pressedRow, pressedCol; |
59 | 62 | ||
60 | QObject *parent; | 63 | QObject *parent; |
61 | 64 | ||
diff --git a/noncore/apps/opie-console/mainwindow.cpp b/noncore/apps/opie-console/mainwindow.cpp index 5900785..0c89620 100644 --- a/noncore/apps/opie-console/mainwindow.cpp +++ b/noncore/apps/opie-console/mainwindow.cpp | |||
@@ -152,25 +152,25 @@ void MainWindow::initUI() { | |||
152 | m_saveScript = new QAction(tr("Save Script"), QString::null, 0, this, 0); | 152 | m_saveScript = new QAction(tr("Save Script"), QString::null, 0, this, 0); |
153 | m_saveScript->addTo(m_scripts); | 153 | m_saveScript->addTo(m_scripts); |
154 | connect(m_saveScript, SIGNAL(activated()), this, SLOT(slotSaveScript())); | 154 | connect(m_saveScript, SIGNAL(activated()), this, SLOT(slotSaveScript())); |
155 | 155 | ||
156 | m_runScript = new QAction(tr("Run Script"), QString::null, 0, this, 0); | 156 | m_runScript = new QAction(tr("Run Script"), QString::null, 0, this, 0); |
157 | m_runScript->addTo(m_scripts); | 157 | m_runScript->addTo(m_scripts); |
158 | connect(m_runScript, SIGNAL(activated()), this, SLOT(slotRunScript())); | 158 | connect(m_runScript, SIGNAL(activated()), this, SLOT(slotRunScript())); |
159 | 159 | ||
160 | /* | 160 | /* |
161 | * action that open/closes the keyboard | 161 | * action that open/closes the keyboard |
162 | */ | 162 | */ |
163 | m_openKeys = new QAction (tr("Open Keyboard..."), | 163 | m_openKeys = new QAction (tr("Open Keyboard..."), |
164 | Resource::loadPixmap( "down" ), | 164 | Resource::loadPixmap( "console/keyboard_icon.png" ), |
165 | QString::null, 0, this, 0); | 165 | QString::null, 0, this, 0); |
166 | 166 | ||
167 | m_openKeys->setToggleAction(true); | 167 | m_openKeys->setToggleAction(true); |
168 | 168 | ||
169 | connect (m_openKeys, SIGNAL(toggled(bool)), | 169 | connect (m_openKeys, SIGNAL(toggled(bool)), |
170 | this, SLOT(slotOpenKeb(bool))); | 170 | this, SLOT(slotOpenKeb(bool))); |
171 | m_openKeys->addTo(m_icons); | 171 | m_openKeys->addTo(m_icons); |
172 | 172 | ||
173 | 173 | ||
174 | /* | 174 | /* |
175 | * action that open/closes the keyboard | 175 | * action that open/closes the keyboard |
176 | */ | 176 | */ |