summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/function_keyboard.cpp22
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,137 +1,115 @@
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
14FunctionKeyboard::FunctionKeyboard(QWidget *parent) : 14FunctionKeyboard::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
48FunctionKeyboard::~FunctionKeyboard() {} 26FunctionKeyboard::~FunctionKeyboard() {}
49 27
50void FunctionKeyboard::changeRows(int r) { 28void 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}
57void FunctionKeyboard::changeCols(int c) { 35void 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}
63void FunctionKeyboard::load (const Profile& prof) { 41void 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
98void FunctionKeyboard::paintEvent(QPaintEvent *e) { 76void 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 }