author | hash <hash> | 2002-10-24 08:14:54 (UTC) |
---|---|---|
committer | hash <hash> | 2002-10-24 08:14:54 (UTC) |
commit | 541035d4308ca1931d5068ced83b0cb5350b0766 (patch) (unidiff) | |
tree | 6f236ae8499f4aefcb7405d8beaed59230155276 /noncore | |
parent | 7c670be31a6a60e03e7dba4e366aa8f3e02bae6c (diff) | |
download | opie-541035d4308ca1931d5068ced83b0cb5350b0766.zip opie-541035d4308ca1931d5068ced83b0cb5350b0766.tar.gz opie-541035d4308ca1931d5068ced83b0cb5350b0766.tar.bz2 |
editing/loading/saving works. now the keyboard in mainwidget needs to load the right profile when the tab is switched
-rw-r--r-- | noncore/apps/opie-console/function_keyboard.cpp | 151 | ||||
-rw-r--r-- | noncore/apps/opie-console/function_keyboard.h | 5 |
2 files changed, 108 insertions, 48 deletions
diff --git a/noncore/apps/opie-console/function_keyboard.cpp b/noncore/apps/opie-console/function_keyboard.cpp index 9d58383..538bed4 100644 --- a/noncore/apps/opie-console/function_keyboard.cpp +++ b/noncore/apps/opie-console/function_keyboard.cpp | |||
@@ -1,150 +1,166 @@ | |||
1 | #include "function_keyboard.h" | 1 | #include "function_keyboard.h" |
2 | 2 | ||
3 | #include <qpe/resource.h> | 3 | #include <qpe/resource.h> |
4 | #include <qpe/qpeapplication.h> | 4 | #include <qpe/qpeapplication.h> |
5 | #include <qsizepolicy.h> | 5 | #include <qsizepolicy.h> |
6 | #include <qevent.h> | 6 | #include <qevent.h> |
7 | #include <qwindowsystem_qws.h> | 7 | #include <qwindowsystem_qws.h> |
8 | #include <qapplication.h> | 8 | #include <qapplication.h> |
9 | #include <qlayout.h> | 9 | #include <qlayout.h> |
10 | #include <qspinbox.h> | 10 | #include <qspinbox.h> |
11 | #include <qlistbox.h> | ||
11 | #include <qlabel.h> | 12 | #include <qlabel.h> |
12 | #include <qcombobox.h> | 13 | #include <qcombobox.h> |
13 | #include <qdir.h> | 14 | #include <qdir.h> |
14 | 15 | ||
15 | /* FunctionKeyboard {{{1 */ | 16 | /* FunctionKeyboard {{{1 */ |
16 | 17 | ||
17 | FunctionKeyboard::FunctionKeyboard(QWidget *parent) : | 18 | FunctionKeyboard::FunctionKeyboard(QWidget *parent) : |
18 | QFrame(parent), numRows(2), numCols(11), | 19 | QFrame(parent), numRows(2), numCols(11), |
19 | pressedRow(0), pressedCol(0) { | 20 | pressedRow(0), pressedCol(0) { |
20 | 21 | ||
21 | setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed)); | 22 | setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed)); |
22 | 23 | ||
24 | /* | ||
25 | * all the saving/loading is now done in a profile. downside is that you cant modify | ||
26 | * the keyboard for all profiles, but must do it on a profile-basis | ||
27 | * | ||
28 | |||
23 | Config conf("opie-console-keys"); | 29 | Config conf("opie-console-keys"); |
24 | conf.setGroup("keys"); | 30 | conf.setGroup("keys"); |
25 | for (uint r = 0; r < numRows; r++) | 31 | for (uint r = 0; r < numRows; r++) |
26 | for (uint c = 0; c < numCols; c++) { | 32 | for (uint c = 0; c < numCols; c++) { |
27 | 33 | ||
28 | QString handle = "r" + QString::number(r) + "c" + QString::number(c); | 34 | QString handle = "r" + QString::number(r) + "c" + QString::number(c); |
29 | QStringList value_list = conf.readListEntry( handle, '|'); | 35 | QStringList value_list = conf.readListEntry( handle, '|'); |
30 | 36 | ||
31 | if (value_list.isEmpty()) continue; | 37 | if (value_list.isEmpty()) continue; |
32 | 38 | ||
33 | keys.insert( | 39 | keys.insert( |
34 | 40 | ||
35 | handle, | 41 | handle, |
36 | FKey (value_list[0], value_list[1], value_list[2].toUShort(), value_list[3].toUShort()) | 42 | FKey (value_list[0], value_list[1], value_list[2].toUShort(), value_list[3].toUShort()) |
37 | ); | 43 | ); |
38 | } | 44 | } |
39 | //qWarning("loaded %d keys", keys.count()); | 45 | //qWarning("loaded %d keys", keys.count()); |
46 | */ | ||
40 | if (keys.isEmpty()) loadDefaults(); | 47 | if (keys.isEmpty()) loadDefaults(); |
41 | 48 | ||
42 | 49 | ||
43 | 50 | ||
44 | } | 51 | } |
45 | 52 | ||
46 | FunctionKeyboard::~FunctionKeyboard() { | 53 | FunctionKeyboard::~FunctionKeyboard() { |
47 | 54 | ||
48 | } | 55 | } |
49 | 56 | ||
50 | void FunctionKeyboard::changeRows(int r) { | 57 | void FunctionKeyboard::changeRows(int r) { |
51 | 58 | ||
52 | numRows = r; | 59 | numRows = r; |
53 | repaint(false); | 60 | repaint(false); |
54 | } | 61 | } |
55 | void FunctionKeyboard::changeCols(int c) { | 62 | void FunctionKeyboard::changeCols(int c) { |
56 | 63 | ||
57 | numCols = c; | 64 | numCols = c; |
58 | keyWidth = (double)width()/numCols; // have to reset this thing too | 65 | keyWidth = (double)width()/numCols; // have to reset this thing too |
59 | repaint(false); | 66 | repaint(false); |
60 | } | 67 | } |
61 | 68 | ||
62 | /* | ||
63 | Key getKey(int row, int col) { | ||
64 | |||
65 | return keys[ "r" + QString::number(row) + "c" + QString::number(col) ]; | ||
66 | } | ||
67 | */ | ||
68 | |||
69 | void FunctionKeyboard::paintEvent(QPaintEvent *e) { | 69 | void FunctionKeyboard::paintEvent(QPaintEvent *e) { |
70 | 70 | ||
71 | QPainter p(this); | 71 | QPainter p(this); |
72 | p.setClipRect(e->rect()); | 72 | p.setClipRect(e->rect()); |
73 | p.fillRect(0, 0, width(), height(), QColor(255,255,255)); | 73 | p.fillRect(0, 0, width(), height(), QColor(255,255,255)); |
74 | 74 | ||
75 | p.setPen(QColor(0,0,0)); | 75 | p.setPen(QColor(0,0,0)); |
76 | 76 | ||
77 | /* those decimals do count! becomes short if use plain int */ | 77 | /* those decimals do count! becomes short if use plain int */ |
78 | for (double i = 0; i <= width(); i += keyWidth) { | 78 | for (double i = 0; i <= width(); i += keyWidth) { |
79 | 79 | ||
80 | p.drawLine((int)i, 0, (int)i, height()); | 80 | p.drawLine((int)i, 0, (int)i, height()); |
81 | } | 81 | } |
82 | 82 | ||
83 | // sometimes the last line doesnt get drawn | 83 | // sometimes the last line doesnt get drawn |
84 | p.drawLine(width() -1, 0, width() -1, height()); | 84 | p.drawLine(width() -1, 0, width() -1, height()); |
85 | 85 | ||
86 | for (int i = 0; i <= height(); i += keyHeight) { | 86 | for (int i = 0; i <= height(); i += keyHeight) { |
87 | 87 | ||
88 | p.drawLine(0, i, width(), i); | 88 | p.drawLine(0, i, width(), i); |
89 | } | 89 | } |
90 | 90 | ||
91 | for (uint r = 0; r < numRows; r++) { | 91 | for (uint r = 0; r < numRows; r++) { |
92 | for (uint c = 0; c < numCols; c++) { | 92 | for (uint c = 0; c < numCols; c++) { |
93 | 93 | ||
94 | QString handle = "r" + QString::number(r) + "c" + QString::number(c); | 94 | QString handle = "r" + QString::number(r) + "c" + QString::number(c); |
95 | if (keys.contains(handle)) { | 95 | if (keys.contains(handle)) { |
96 | 96 | ||
97 | p.drawText( | 97 | if (keys[handle].pixFile.isEmpty()) |
98 | c * keyWidth + 1, r * keyHeight + 1, | 98 | p.drawText( c * keyWidth + 1, r * keyHeight + 1, |
99 | keyWidth, keyHeight, | 99 | keyWidth, keyHeight, |
100 | Qt::AlignHCenter | Qt::AlignVCenter, | 100 | Qt::AlignHCenter | Qt::AlignVCenter, |
101 | keys[handle].label | 101 | keys[handle].label |
102 | ); | 102 | ); |
103 | else { | ||
104 | |||
105 | ushort centerX = c *keyWidth + (keyWidth - keys[handle].pix->width()) / 2; | ||
106 | ushort centerY = r * keyHeight + (keyHeight - keys[handle].pix->height()) / 2; | ||
107 | p.drawPixmap(centerX, centerY, *keys[handle].pix); | ||
108 | } | ||
103 | } | 109 | } |
104 | } | 110 | } |
105 | } | 111 | } |
106 | } | 112 | } |
107 | 113 | ||
108 | void FunctionKeyboard::paintKey(uint row, uint col) { | 114 | void FunctionKeyboard::paintKey(uint row, uint col) { |
109 | 115 | ||
110 | QPainter p(this); | 116 | QPainter p(this); |
111 | 117 | ||
112 | p.fillRect(QRect(QPoint(col * keyWidth + 1, row * keyHeight + 1), | 118 | p.fillRect(QRect(QPoint(col * keyWidth + 1, row * keyHeight + 1), |
113 | QPoint((col + 1) * keyWidth - 1, row * keyHeight + keyHeight- 1)), | 119 | QPoint((col + 1) * keyWidth - 1, row * keyHeight + keyHeight- 1)), |
114 | (pressedRow != -1 && pressedCol != -1 ) ? QColor(97,119,155) : QColor(255,255,255)); | 120 | (pressedRow != -1 && pressedCol != -1 ) ? QColor(97,119,155) : QColor(255,255,255)); |
115 | p.drawText( | 121 | |
122 | QString handle ("r" + QString::number(row) + "c" + QString::number(col)); | ||
123 | if (keys[handle].pixFile.isEmpty()) | ||
124 | p.drawText( | ||
116 | col * keyWidth + 1, row * keyHeight + 1, | 125 | col * keyWidth + 1, row * keyHeight + 1, |
117 | keyWidth, keyHeight, | 126 | keyWidth, keyHeight, |
118 | Qt::AlignHCenter | Qt::AlignVCenter, | 127 | Qt::AlignHCenter | Qt::AlignVCenter, |
119 | keys["r" + QString::number(row) + "c" + QString::number(col)].label | 128 | keys[handle].label |
120 | ); | 129 | ); |
130 | else { | ||
131 | |||
132 | ushort centerX = col *keyWidth + (keyWidth - keys[handle].pix->width()) / 2; | ||
133 | ushort centerY = row * keyHeight + (keyHeight - keys[handle].pix->height()) / 2; | ||
134 | p.drawPixmap(centerX, centerY, *keys[handle].pix); | ||
135 | } | ||
121 | 136 | ||
122 | if (row == numRows) { | 137 | if (col == numCols - 1) { |
123 | 138 | ||
124 | // sometimes it doesnt draw the last line | 139 | // sometimes it doesnt draw the last line |
125 | p.drawLine((col+1) * keyWidth -2, row * keyHeight, | 140 | |
126 | (col+1) * keyWidth -2, (row + 1) * keyHeight | 141 | p.drawLine((col+1) * keyWidth -1, row * keyHeight, |
142 | (col+1) * keyWidth -1, (row + 1) * keyHeight | ||
127 | ); | 143 | ); |
128 | } | 144 | } |
129 | 145 | ||
130 | } | 146 | } |
131 | 147 | ||
132 | void FunctionKeyboard::mousePressEvent(QMouseEvent *e) { | 148 | void FunctionKeyboard::mousePressEvent(QMouseEvent *e) { |
133 | 149 | ||
134 | pressedRow = e->y() / keyHeight; | 150 | pressedRow = e->y() / keyHeight; |
135 | pressedCol = (int) (e->x() / keyWidth); | 151 | pressedCol = (int) (e->x() / keyWidth); |
136 | 152 | ||
137 | paintKey(pressedRow, pressedCol); | 153 | paintKey(pressedRow, pressedCol); |
138 | 154 | ||
139 | // emit that sucker! | 155 | // emit that sucker! |
140 | FKey k = keys["r" + QString::number(pressedRow) + "c" + QString::number(pressedCol)]; | 156 | FKey k = keys["r" + QString::number(pressedRow) + "c" + QString::number(pressedCol)]; |
141 | emit keyPressed(k, pressedRow, pressedCol, 1); | 157 | emit keyPressed(k, pressedRow, pressedCol, 1); |
142 | 158 | ||
143 | } | 159 | } |
144 | 160 | ||
145 | void FunctionKeyboard::mouseReleaseEvent(QMouseEvent *) { | 161 | void FunctionKeyboard::mouseReleaseEvent(QMouseEvent *) { |
146 | 162 | ||
147 | if (pressedRow != -1 && pressedRow != -1) { | 163 | if (pressedRow != -1 && pressedRow != -1) { |
148 | 164 | ||
149 | int row = pressedRow; pressedRow = -1; | 165 | int row = pressedRow; pressedRow = -1; |
150 | int col = pressedCol; pressedCol = -1; | 166 | int col = pressedCol; pressedCol = -1; |
@@ -152,182 +168,223 @@ void FunctionKeyboard::mouseReleaseEvent(QMouseEvent *) { | |||
152 | 168 | ||
153 | FKey k = keys["r" + QString::number(row) + "c" + QString::number(col)]; | 169 | FKey k = keys["r" + QString::number(row) + "c" + QString::number(col)]; |
154 | emit keyPressed(k, row, col, 0); | 170 | emit keyPressed(k, row, col, 0); |
155 | } | 171 | } |
156 | 172 | ||
157 | } | 173 | } |
158 | 174 | ||
159 | 175 | ||
160 | void FunctionKeyboard::resizeEvent(QResizeEvent*) { | 176 | void FunctionKeyboard::resizeEvent(QResizeEvent*) { |
161 | 177 | ||
162 | /* set he default font height/width */ | 178 | /* set he default font height/width */ |
163 | QFontMetrics fm=fontMetrics(); | 179 | QFontMetrics fm=fontMetrics(); |
164 | keyHeight = fm.lineSpacing() + 2; | 180 | keyHeight = fm.lineSpacing() + 2; |
165 | keyWidth = (double)width()/numCols; | 181 | keyWidth = (double)width()/numCols; |
166 | 182 | ||
167 | } | 183 | } |
168 | 184 | ||
169 | QSize FunctionKeyboard::sizeHint() const { | 185 | QSize FunctionKeyboard::sizeHint() const { |
170 | 186 | ||
171 | return QSize(width(), keyHeight * numRows + 1); | 187 | return QSize(width(), keyHeight * numRows + 1); |
172 | } | 188 | } |
173 | 189 | ||
174 | void FunctionKeyboard::loadDefaults() { | 190 | void FunctionKeyboard::loadDefaults() { |
175 | 191 | ||
176 | /* what keys should be default? | 192 | keys.insert( "r0c0", FKey ("Enter", "enter.png", Qt::Key_Enter, 0)); |
177 | keys.insert( "r0c0", FKey ("F1", 0, 4144, 0)); | 193 | keys.insert( "r0c1", FKey ("Space", "space.png", Qt::Key_Space, Qt::Key_Space)); |
178 | keys.insert( "r0c1", FKey ("F2", 0, 4145, 0)); | 194 | keys.insert( "r0c2", FKey ("Tab", "tab.png", Qt::Key_Tab, 0)); |
179 | keys.insert( "r0c2", FKey ("F3", 0, 4146, 0)); | 195 | keys.insert( "r0c3", FKey ("Up", "up.png", Qt::Key_Up, 0)); |
180 | keys.insert( "r0c3", FKey ("F4", 0, 4147, 0)); | 196 | keys.insert( "r0c4", FKey ("Down", "down.png", Qt::Key_Down, 0)); |
181 | keys.insert( "r0c4", FKey ("F5", 0, 4148, 0)); | 197 | |
182 | keys.insert( "r0c5", FKey ("F6", 0, 4149, 0)); | 198 | keys.insert( "r0c7", FKey ("Ho", 0, 4112, 0)); |
183 | keys.insert( "r0c6", FKey ("F7", 0, 4150, 0)); | 199 | keys.insert( "r0c8", FKey ("End", 0, 4113, 0)); |
184 | keys.insert( "r0c7", FKey ("F8", 0, 4151, 0)); | 200 | keys.insert( "r0c9", FKey ("PU", 0, 4118, 0)); |
185 | keys.insert( "r0c8", FKey ("F9", 0, 4152, 0)); | 201 | keys.insert( "r0c10", FKey ("PD", 0, 4119, 0)); |
186 | keys.insert( "r0c9", FKey ("F10", 0, 4153, 0)); | 202 | |
187 | keys.insert( "r0c10", FKey ("F11", 0, 4154, 0)); | 203 | keys.insert( "r1c0", FKey ("F1", 0, 4144, 0)); |
188 | 204 | keys.insert( "r1c1", FKey ("F2", 0, 4145, 0)); | |
189 | keys.insert( "r1c7", FKey ("Ho", 0, 4112, 0)); | 205 | keys.insert( "r1c2", FKey ("F3", 0, 4146, 0)); |
190 | keys.insert( "r1c8", FKey ("End", 0, 4113, 0)); | 206 | keys.insert( "r1c3", FKey ("F4", 0, 4147, 0)); |
191 | keys.insert( "r1c9", FKey ("PU", 0, 4118, 0)); | 207 | keys.insert( "r1c4", FKey ("F5", 0, 4148, 0)); |
192 | keys.insert( "r1c10", FKey ("PD", 0, 4119, 0)); | 208 | keys.insert( "r1c5", FKey ("F6", 0, 4149, 0)); |
193 | */ | 209 | keys.insert( "r1c6", FKey ("F7", 0, 4150, 0)); |
210 | keys.insert( "r1c7", FKey ("F8", 0, 4151, 0)); | ||
211 | keys.insert( "r1c8", FKey ("F9", 0, 4152, 0)); | ||
212 | keys.insert( "r1c9", FKey ("F10", 0, 4153, 0)); | ||
213 | keys.insert( "r1c10", FKey ("F11", 0, 4154, 0)); | ||
214 | |||
194 | 215 | ||
195 | } | 216 | } |
196 | 217 | ||
197 | /* FunctionKeyboardConfig {{{1 */ | 218 | /* FunctionKeyboardConfig {{{1 */ |
198 | 219 | ||
199 | FunctionKeyboardConfig::FunctionKeyboardConfig(const QString& name, QWidget* parent, const char* na ) | 220 | FunctionKeyboardConfig::FunctionKeyboardConfig(const QString& name, QWidget* parent, const char* na ) |
200 | : ProfileDialogKeyWidget(name, parent, na), | 221 | : ProfileDialogKeyWidget(name, parent, na), |
201 | selectedRow(0), selectedCol(0) | 222 | selectedRow(0), selectedCol(0) |
202 | { | 223 | { |
203 | qWarning("FunctionKeyboardConfig"); | 224 | qWarning("FunctionKeyboardConfig"); |
204 | 225 | ||
205 | 226 | ||
206 | kb = new FunctionKeyboard(this); | 227 | kb = new FunctionKeyboard(this); |
207 | connect (kb, SIGNAL(keyPressed(FKey, ushort, ushort, bool)), | 228 | connect (kb, SIGNAL(keyPressed(FKey, ushort, ushort, bool)), |
208 | this, SLOT(slotKeyPressed(FKey, ushort, ushort, bool))); | 229 | this, SLOT(slotKeyPressed(FKey, ushort, ushort, bool))); |
209 | 230 | ||
210 | QGroupBox *dimentions = new QGroupBox(2, Qt::Horizontal, tr("Dimentions"), this); | 231 | QGroupBox *dimentions = new QGroupBox(2, Qt::Horizontal, tr("Dimentions"), this); |
211 | QLabel *l = new QLabel("Rows", dimentions); | 232 | QLabel *l = new QLabel("Rows", dimentions); |
212 | m_rowBox = new QSpinBox(1, 15, 1, dimentions); | 233 | m_rowBox = new QSpinBox(1, 15, 1, dimentions); |
213 | connect (m_rowBox, SIGNAL(valueChanged(int)), this, SLOT(slotChangeRows(int))); | 234 | connect (m_rowBox, SIGNAL(valueChanged(int)), this, SLOT(slotChangeRows(int))); |
214 | l = new QLabel("Columns", dimentions); | 235 | l = new QLabel("Columns", dimentions); |
215 | m_colBox = new QSpinBox(1, 15, 1, dimentions); | 236 | m_colBox = new QSpinBox(1, 15, 1, dimentions); |
216 | connect (m_colBox, SIGNAL(valueChanged(int)), this, SLOT(slotChangeCols(int))); | 237 | connect (m_colBox, SIGNAL(valueChanged(int)), this, SLOT(slotChangeCols(int))); |
217 | 238 | ||
218 | QGroupBox *editKey = new QGroupBox(2, Qt::Horizontal, tr("Edit Key"), this); | 239 | QGroupBox *editKey = new QGroupBox(2, Qt::Horizontal, tr("Edit Key"), this); |
219 | l = new QLabel("Label", editKey); | 240 | l = new QLabel("Label", editKey); |
220 | m_labels = new QComboBox(true, editKey); | 241 | m_labels = new QComboBox(true, editKey); |
221 | m_labels->setInsertionPolicy(QComboBox::AtCurrent); | 242 | m_labels->setInsertionPolicy(QComboBox::AtCurrent); |
222 | m_labels->insertItem("custom"); | 243 | m_labels->insertItem(""); |
223 | 244 | ||
224 | QStringList files = QDir(QPEApplication::qpeDir() + "pics/console/keys/", "*.png").entryList(); | 245 | QStringList files = QDir(QPEApplication::qpeDir() + "pics/console/keys/", "*.png").entryList(); |
225 | 246 | ||
226 | for (uint i = 0; i < files.count(); i++) { | 247 | for (uint i = 0; i < files.count(); i++) { |
227 | 248 | ||
228 | m_labels->insertItem(Resource::loadPixmap("console/keys/" + files[i])); | 249 | m_labels->insertItem(Resource::loadPixmap("console/keys/" + files[i]), files[i]); |
229 | } | 250 | } |
230 | connect (m_labels, SIGNAL(activated(int)), this, SLOT(slotChangeIcon(int))); | 251 | connect (m_labels, SIGNAL(activated(int)), this, SLOT(slotChangeIcon(int))); |
231 | connect (m_labels, SIGNAL(textChanged(const QString &)), this, SLOT(slotChangeLabelText(const QString&))); | 252 | connect (m_labels, SIGNAL(textChanged(const QString &)), this, SLOT(slotChangeLabelText(const QString&))); |
232 | 253 | ||
233 | l = new QLabel("KeyValue", editKey); | 254 | l = new QLabel("Q Keycode", editKey); |
234 | m_qvalues = new QComboBox(false, editKey); | 255 | m_qvalues = new QComboBox(true, editKey); |
235 | m_qvalues->setInsertionPolicy(QComboBox::AtCurrent); | 256 | m_qvalues->setInsertionPolicy(QComboBox::AtTop); |
236 | m_qvalues->insertItem("custom"); | 257 | m_qvalues->setDuplicatesEnabled(false); |
258 | m_qvalues->insertItem(""); | ||
259 | connect (m_qvalues, SIGNAL(textChanged(const QString &)), this, SLOT(slotChangeQCode(const QString&))); | ||
260 | |||
261 | l = new QLabel("Unicode Value", editKey); | ||
262 | m_uniValues = new QComboBox(true, editKey); | ||
263 | m_uniValues->setInsertionPolicy(QComboBox::AtTop); | ||
264 | m_uniValues->setDuplicatesEnabled(false); | ||
265 | m_uniValues->insertItem(""); | ||
266 | connect (m_uniValues, SIGNAL(textChanged(const QString &)), this, SLOT(slotChangeUnicode(const QString&))); | ||
237 | 267 | ||
238 | QVBoxLayout *root = new QVBoxLayout(this, 2); | 268 | QVBoxLayout *root = new QVBoxLayout(this, 2); |
239 | root->addWidget(kb); | 269 | root->addWidget(kb); |
240 | root->addWidget(dimentions); | 270 | root->addWidget(dimentions); |
241 | root->addWidget(editKey); | 271 | root->addWidget(editKey); |
242 | } | 272 | } |
243 | FunctionKeyboardConfig::~FunctionKeyboardConfig() { | 273 | FunctionKeyboardConfig::~FunctionKeyboardConfig() { |
244 | 274 | ||
245 | } | 275 | } |
246 | void FunctionKeyboardConfig::load (const Profile& prof) { | 276 | void FunctionKeyboardConfig::load (const Profile& prof) { |
247 | 277 | ||
248 | m_rowBox->setValue(prof.readNumEntry("keb_rows", 2)); | 278 | m_rowBox->setValue(prof.readNumEntry("keb_rows", 2)); |
249 | m_colBox->setValue(prof.readNumEntry("keb_cols", 10)); | 279 | m_colBox->setValue(prof.readNumEntry("keb_cols", 10)); |
250 | 280 | ||
251 | /* load all the keys to the keyboard */ | 281 | /* load all the keys to the keyboard */ |
252 | for (int i = 0; i <= m_rowBox->value() -1; i++) | 282 | for (int i = 0; i <= m_rowBox->value() -1; i++) |
253 | for (int j = 0; j <= m_colBox->value() -1; j++) { | 283 | for (int j = 0; j <= m_colBox->value() -1; j++) { |
254 | 284 | ||
255 | QString h = "r" + QString::number(i) + "c" + QString::number(j); | 285 | QString h = "r" + QString::number(i) + "c" + QString::number(j); |
256 | QString values = prof.readEntry("keb_" + h); | 286 | QString values = prof.readEntry("keb_" + h); |
257 | 287 | ||
258 | if (!values.isEmpty()) { | 288 | if (!values.isEmpty()) { |
259 | 289 | ||
260 | QStringList l = QStringList::split(QChar('|'), values, TRUE); | 290 | QStringList l = QStringList::split(QChar('|'), values, TRUE); |
261 | kb->keys[h] = FKey(l[0], l[1], l[2].toInt(), l[3].toInt()); | 291 | kb->keys[h] = FKey(l[0], l[1], l[2].toInt(), l[3].toInt()); |
262 | //qWarning("loading key... %s %s %s %d %d", values.ascii(), l[0].ascii(), l[1].ascii(), l[2].toInt(), l[3].toInt()); | 292 | |
293 | // load pixmap if used | ||
294 | if (!l[1].isEmpty()) { | ||
295 | |||
296 | kb->keys[h].pix = new QPixmap(QPEApplication::qpeDir() + "pics/console/keys/" + l[1]); | ||
297 | } | ||
263 | } | 298 | } |
264 | } | 299 | } |
265 | 300 | ||
266 | } | 301 | } |
267 | void FunctionKeyboardConfig::save (Profile& prof) { | 302 | void FunctionKeyboardConfig::save (Profile& prof) { |
268 | 303 | ||
269 | prof.writeEntry("keb_rows", m_rowBox->value()); | 304 | prof.writeEntry("keb_rows", m_rowBox->value()); |
270 | prof.writeEntry("keb_cols", m_colBox->value()); | 305 | prof.writeEntry("keb_cols", m_colBox->value()); |
271 | 306 | ||
272 | QMap<QString, FKey>::Iterator it; | 307 | QMap<QString, FKey>::Iterator it; |
273 | for ( it = kb->keys.begin(); it != kb->keys.end(); it++) { | 308 | for ( it = kb->keys.begin(); it != kb->keys.end(); it++) { |
274 | 309 | ||
275 | FKey k = it.data(); | 310 | FKey k = it.data(); |
276 | QString entry = k.label + "|" | 311 | QString entry = k.label + "|" |
277 | + k.pixFile + "|" | 312 | + k.pixFile + "|" |
278 | + QString::number(k.qcode) + "|" | 313 | + QString::number(k.qcode) + "|" |
279 | + QString::number(k.unicode); | 314 | + QString::number(k.unicode); |
280 | 315 | ||
281 | prof.writeEntry("keb_" + it.key(), entry); | 316 | prof.writeEntry("keb_" + it.key(), entry); |
282 | 317 | ||
283 | } | 318 | } |
284 | 319 | ||
285 | } | 320 | } |
286 | void FunctionKeyboardConfig::slotChangeRows(int r) { | 321 | void FunctionKeyboardConfig::slotChangeRows(int r) { |
287 | 322 | ||
288 | kb->changeRows(r); | 323 | kb->changeRows(r); |
289 | 324 | ||
290 | // have to do this so the whole thing gets redrawn | 325 | // have to do this so the whole thing gets redrawn |
291 | kb->hide(); kb->show(); | 326 | kb->hide(); kb->show(); |
292 | } | 327 | } |
293 | void FunctionKeyboardConfig::slotChangeCols(int c) { | 328 | void FunctionKeyboardConfig::slotChangeCols(int c) { |
294 | 329 | ||
295 | kb->changeCols(c); | 330 | kb->changeCols(c); |
296 | } | 331 | } |
297 | void FunctionKeyboardConfig::slotKeyPressed(FKey k, ushort r, ushort c, bool pressed) { | 332 | void FunctionKeyboardConfig::slotKeyPressed(FKey k, ushort r, ushort c, bool pressed) { |
298 | 333 | ||
299 | if (!pressed) return; | 334 | if (!pressed) return; |
300 | 335 | ||
301 | selectedRow = r, selectedCol = c; | 336 | selectedHandle = "r" + QString::number(r) + |
337 | "c" + QString::number(c); | ||
338 | selectedRow = r; | ||
339 | selectedCol = c; | ||
302 | 340 | ||
303 | if (k.pixFile.isEmpty()) { | 341 | if (k.pixFile.isEmpty()) { |
304 | 342 | ||
343 | m_labels->setEditable(true); | ||
305 | m_labels->setCurrentItem(0); | 344 | m_labels->setCurrentItem(0); |
306 | m_labels->changeItem(k.label, 0); | 345 | m_labels->changeItem(k.label, 0); |
307 | m_labels->setEditable(true); | ||
308 | 346 | ||
347 | } else { | ||
348 | |||
349 | // any better way to select the pixmap? | ||
350 | m_labels->setCurrentItem((m_labels->listBox())->index((m_labels->listBox())->findItem(kb->keys[selectedHandle].pixFile))); | ||
351 | m_labels->setEditable(false); | ||
309 | } | 352 | } |
310 | m_qvalues->changeItem(QString::number(k.qcode), 0); | 353 | m_qvalues->changeItem(QString::number(k.qcode), 0); |
354 | m_uniValues->changeItem(QString::number(k.unicode), 0); | ||
311 | } | 355 | } |
312 | void FunctionKeyboardConfig::slotChangeIcon(int index) { | 356 | void FunctionKeyboardConfig::slotChangeIcon(int index) { |
313 | 357 | ||
314 | if (index == 0) { | 358 | if (index == 0) { |
315 | 359 | ||
316 | // is text | 360 | // is text |
317 | m_labels->setEditable(true); | 361 | m_labels->setEditable(true); |
318 | // why tf does the text get erased unless i do this? | 362 | // why tf does the text get erased unless i do this? |
319 | m_labels->changeItem(m_labels->text(0), 0); | 363 | m_labels->changeItem(m_labels->text(0), 0); |
320 | 364 | ||
365 | kb->keys[selectedHandle].pixFile = ""; | ||
366 | delete kb->keys[selectedHandle].pix; | ||
367 | |||
321 | } else { | 368 | } else { |
322 | 369 | ||
323 | // is a pixmap | 370 | // is a pixmap |
324 | m_labels->setEditable(false); | 371 | m_labels->setEditable(false); |
372 | kb->keys[selectedHandle].pixFile = m_labels->currentText(); | ||
373 | kb->keys[selectedHandle].pix = new QPixmap(QPEApplication::qpeDir() + "pics/console/keys/" + m_labels->currentText()); | ||
325 | } | 374 | } |
375 | kb->paintKey(selectedRow, selectedCol); | ||
326 | } | 376 | } |
327 | void FunctionKeyboardConfig::slotChangeLabelText(const QString &label) { | 377 | void FunctionKeyboardConfig::slotChangeLabelText(const QString &label) { |
328 | 378 | ||
329 | kb->keys["r" + QString::number(selectedRow) + | 379 | kb->keys[selectedHandle].label = label; |
330 | "c" + QString::number(selectedCol)].label = label; | ||
331 | 380 | ||
332 | kb->paintKey(selectedRow, selectedCol); | 381 | kb->paintKey(selectedRow, selectedCol); |
333 | } | 382 | } |
383 | void FunctionKeyboardConfig::slotChangeQCode(const QString& qcode) { | ||
384 | |||
385 | kb->keys[selectedHandle].qcode = qcode.toUInt(); | ||
386 | } | ||
387 | void FunctionKeyboardConfig::slotChangeUnicode(const QString& uni) { | ||
388 | |||
389 | kb->keys[selectedHandle].unicode = uni.toUInt(); | ||
390 | } | ||
diff --git a/noncore/apps/opie-console/function_keyboard.h b/noncore/apps/opie-console/function_keyboard.h index 496d932..7f313d6 100644 --- a/noncore/apps/opie-console/function_keyboard.h +++ b/noncore/apps/opie-console/function_keyboard.h | |||
@@ -77,36 +77,39 @@ private: | |||
77 | int pressedRow, pressedCol; | 77 | int pressedRow, pressedCol; |
78 | 78 | ||
79 | QObject *parent; | 79 | QObject *parent; |
80 | 80 | ||
81 | }; | 81 | }; |
82 | 82 | ||
83 | class FunctionKeyboardConfig : public ProfileDialogKeyWidget { | 83 | class FunctionKeyboardConfig : public ProfileDialogKeyWidget { |
84 | 84 | ||
85 | Q_OBJECT | 85 | Q_OBJECT |
86 | 86 | ||
87 | public: | 87 | public: |
88 | FunctionKeyboardConfig(const QString& name, QWidget *wid, const char* name = 0l ); | 88 | FunctionKeyboardConfig(const QString& name, QWidget *wid, const char* name = 0l ); |
89 | ~FunctionKeyboardConfig(); | 89 | ~FunctionKeyboardConfig(); |
90 | 90 | ||
91 | void load(const Profile&); | 91 | void load(const Profile&); |
92 | void save(Profile&); | 92 | void save(Profile&); |
93 | 93 | ||
94 | private slots: | 94 | private slots: |
95 | 95 | ||
96 | void slotKeyPressed(FKey, ushort, ushort, bool); | 96 | void slotKeyPressed(FKey, ushort, ushort, bool); |
97 | void slotChangeRows(int); | 97 | void slotChangeRows(int); |
98 | void slotChangeCols(int); | 98 | void slotChangeCols(int); |
99 | void slotChangeIcon(int); | 99 | void slotChangeIcon(int); |
100 | void slotChangeLabelText(const QString &); | 100 | void slotChangeLabelText(const QString &); |
101 | void slotChangeQCode(const QString &); | ||
102 | void slotChangeUnicode(const QString &); | ||
101 | 103 | ||
102 | private: | 104 | private: |
103 | 105 | ||
106 | QString selectedHandle; | ||
104 | ushort selectedRow, selectedCol; | 107 | ushort selectedRow, selectedCol; |
105 | 108 | ||
106 | FunctionKeyboard *kb; | 109 | FunctionKeyboard *kb; |
107 | QSpinBox *m_rowBox, *m_colBox; | 110 | QSpinBox *m_rowBox, *m_colBox; |
108 | QComboBox *m_labels, *m_qvalues; | 111 | QComboBox *m_labels, *m_qvalues, *m_uniValues; |
109 | 112 | ||
110 | }; | 113 | }; |
111 | 114 | ||
112 | #endif | 115 | #endif |