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