author | hash <hash> | 2002-08-22 16:30:01 (UTC) |
---|---|---|
committer | hash <hash> | 2002-08-22 16:30:01 (UTC) |
commit | 4b0db964f77e4b3caa1f95ea753c89094b86e0d6 (patch) (unidiff) | |
tree | 1be74ef5d6bf3101815b5ecdafb21c0db470715e | |
parent | 8503abdc93f6f3ce93cee0f1176faa919dbd04f5 (diff) | |
download | opie-4b0db964f77e4b3caa1f95ea753c89094b86e0d6.zip opie-4b0db964f77e4b3caa1f95ea753c89094b86e0d6.tar.gz opie-4b0db964f77e4b3caa1f95ea753c89094b86e0d6.tar.bz2 |
xpm images now are the same color as the text
-rw-r--r-- | inputmethods/multikey/keyboard.cpp | 19 | ||||
-rw-r--r-- | inputmethods/multikey/keyboard.h | 6 |
2 files changed, 13 insertions, 12 deletions
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp index e3d3928..3f6f73b 100644 --- a/inputmethods/multikey/keyboard.cpp +++ b/inputmethods/multikey/keyboard.cpp | |||
@@ -172,17 +172,17 @@ void Keyboard::drawKeyboard(QPainter &p, int row, int col) | |||
172 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); | 172 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); |
173 | 173 | ||
174 | int keyWidth = keys->width(row, col); | 174 | int keyWidth = keys->width(row, col); |
175 | 175 | ||
176 | p.fillRect(x + 1, y + 1, | 176 | p.fillRect(x + 1, y + 1, |
177 | keyWidth * defaultKeyWidth - 1, keyHeight - 1, | 177 | keyWidth * defaultKeyWidth - 1, keyHeight - 1, |
178 | pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor); | 178 | pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor); |
179 | 179 | ||
180 | QPixmap *pix = keys->pix(row,col); | 180 | QImage *pix = keys->pix(row,col); |
181 | 181 | ||
182 | ushort c = keys->uni(row, col); | 182 | ushort c = keys->uni(row, col); |
183 | 183 | ||
184 | p.setPen(textcolor); | 184 | p.setPen(textcolor); |
185 | if (!pix) { | 185 | if (!pix) { |
186 | if (shift || lock) | 186 | if (shift || lock) |
187 | c = keys->shift(c); | 187 | c = keys->shift(c); |
188 | if (meta) { | 188 | if (meta) { |
@@ -190,17 +190,17 @@ void Keyboard::drawKeyboard(QPainter &p, int row, int col) | |||
190 | c = keys->meta(c); | 190 | c = keys->meta(c); |
191 | } | 191 | } |
192 | p.drawText(x, y, | 192 | p.drawText(x, y, |
193 | defaultKeyWidth * keyWidth + 3, keyHeight, | 193 | defaultKeyWidth * keyWidth + 3, keyHeight, |
194 | AlignCenter, (QChar)c); | 194 | AlignCenter, (QChar)c); |
195 | } | 195 | } |
196 | else | 196 | else |
197 | // center the image in the middle of the key | 197 | // center the image in the middle of the key |
198 | p.drawPixmap( x + (defaultKeyWidth * keyWidth - pix->width())/2, | 198 | p.drawImage( x + (defaultKeyWidth * keyWidth - pix->width())/2, |
199 | y + (keyHeight - pix->height())/2 + 1, | 199 | y + (keyHeight - pix->height())/2 + 1, |
200 | *pix ); | 200 | *pix ); |
201 | 201 | ||
202 | // this fixes the problem that the very right end of the board's vertical line | 202 | // this fixes the problem that the very right end of the board's vertical line |
203 | // gets painted over, because it's one pixel shorter than all other keys | 203 | // gets painted over, because it's one pixel shorter than all other keys |
204 | p.setPen(keycolor_lines); | 204 | p.setPen(keycolor_lines); |
205 | p.drawLine(width() - 1, 0, width() - 1, height()); | 205 | p.drawLine(width() - 1, 0, width() - 1, height()); |
206 | 206 | ||
@@ -214,17 +214,17 @@ void Keyboard::drawKeyboard(QPainter &p, int row, int col) | |||
214 | int x = 0; | 214 | int x = 0; |
215 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); | 215 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); |
216 | 216 | ||
217 | p.setPen(keycolor_lines); | 217 | p.setPen(keycolor_lines); |
218 | p.drawLine(x, y, x + width(), y); | 218 | p.drawLine(x, y, x + width(), y); |
219 | 219 | ||
220 | for (int col = 0; col < keys->numKeys(row); col++) { | 220 | for (int col = 0; col < keys->numKeys(row); col++) { |
221 | 221 | ||
222 | QPixmap *pix = keys->pix(row, col); | 222 | QImage *pix = keys->pix(row, col); |
223 | int keyWidth = keys->width(row, col); | 223 | int keyWidth = keys->width(row, col); |
224 | 224 | ||
225 | 225 | ||
226 | int keyWidthPix = defaultKeyWidth * keyWidth; | 226 | int keyWidthPix = defaultKeyWidth * keyWidth; |
227 | 227 | ||
228 | if (keys->pressed(row, col)) | 228 | if (keys->pressed(row, col)) |
229 | p.fillRect(x+1, y+1, keyWidthPix - 1, | 229 | p.fillRect(x+1, y+1, keyWidthPix - 1, |
230 | keyHeight - 1, keycolor_pressed); | 230 | keyHeight - 1, keycolor_pressed); |
@@ -239,19 +239,20 @@ void Keyboard::drawKeyboard(QPainter &p, int row, int col) | |||
239 | c = keys->meta(c); | 239 | c = keys->meta(c); |
240 | 240 | ||
241 | p.drawText(x, y, | 241 | p.drawText(x, y, |
242 | keyWidthPix + 3, keyHeight, | 242 | keyWidthPix + 3, keyHeight, |
243 | AlignCenter, (QChar)c); | 243 | AlignCenter, (QChar)c); |
244 | } | 244 | } |
245 | else { | 245 | else { |
246 | // center the image in the middle of the key | 246 | // center the image in the middle of the key |
247 | p.drawPixmap( x + (keyWidthPix - pix->width())/2, | 247 | pix->setColor(1, textcolor.rgb()); |
248 | p.drawImage( x + (keyWidthPix - pix->width())/2, | ||
248 | y + (keyHeight - pix->height())/2 + 1, | 249 | y + (keyHeight - pix->height())/2 + 1, |
249 | QPixmap(*pix) ); | 250 | QImage(*pix) ); |
250 | } | 251 | } |
251 | 252 | ||
252 | p.setPen(keycolor_lines); | 253 | p.setPen(keycolor_lines); |
253 | p.drawLine(x, y, x, y + keyHeight); | 254 | p.drawLine(x, y, x, y + keyHeight); |
254 | 255 | ||
255 | x += keyWidthPix; | 256 | x += keyWidthPix; |
256 | } | 257 | } |
257 | 258 | ||
@@ -1039,17 +1040,17 @@ void Keys::setKeysFromFile(const char * filename) { | |||
1039 | QTextStream t(&f); | 1040 | QTextStream t(&f); |
1040 | int row; | 1041 | int row; |
1041 | int qcode; | 1042 | int qcode; |
1042 | ushort unicode; | 1043 | ushort unicode; |
1043 | int width; | 1044 | int width; |
1044 | QString buf; | 1045 | QString buf; |
1045 | QString comment; | 1046 | QString comment; |
1046 | char * xpm[256]; //couldnt be larger than that... could it? | 1047 | char * xpm[256]; //couldnt be larger than that... could it? |
1047 | QPixmap *xpm2pix = 0; | 1048 | QImage *xpm2pix = 0; |
1048 | 1049 | ||
1049 | buf = t.readLine(); | 1050 | buf = t.readLine(); |
1050 | while (buf) { | 1051 | while (buf) { |
1051 | 1052 | ||
1052 | // get rid of comments | 1053 | // get rid of comments |
1053 | buf.replace(QRegExp("#.*$", FALSE, FALSE), ""); | 1054 | buf.replace(QRegExp("#.*$", FALSE, FALSE), ""); |
1054 | 1055 | ||
1055 | // key definition | 1056 | // key definition |
@@ -1085,17 +1086,17 @@ void Keys::setKeysFromFile(const char * filename) { | |||
1085 | // have to close that facker up | 1086 | // have to close that facker up |
1086 | ((char *)xpm[xpmLineCount])[j] = '\0'; | 1087 | ((char *)xpm[xpmLineCount])[j] = '\0'; |
1087 | 1088 | ||
1088 | xpmLineCount++; | 1089 | xpmLineCount++; |
1089 | buf = t.readLine(); | 1090 | buf = t.readLine(); |
1090 | } | 1091 | } |
1091 | if (xpmLineCount) { | 1092 | if (xpmLineCount) { |
1092 | 1093 | ||
1093 | xpm2pix = new QPixmap((const char **)xpm); | 1094 | xpm2pix = new QImage((const char **)xpm); |
1094 | for (int i = 0; i < xpmLineCount; i++) | 1095 | for (int i = 0; i < xpmLineCount; i++) |
1095 | 1096 | ||
1096 | delete [] (xpm[i]); | 1097 | delete [] (xpm[i]); |
1097 | 1098 | ||
1098 | } | 1099 | } |
1099 | setKey(row, qcode, unicode, width, xpm2pix); | 1100 | setKey(row, qcode, unicode, width, xpm2pix); |
1100 | } | 1101 | } |
1101 | 1102 | ||
@@ -1154,17 +1155,17 @@ void Keys::setKeysFromFile(const char * filename) { | |||
1154 | } | 1155 | } |
1155 | f.close(); | 1156 | f.close(); |
1156 | } | 1157 | } |
1157 | 1158 | ||
1158 | } | 1159 | } |
1159 | 1160 | ||
1160 | // Keys::setKey {{{2 | 1161 | // Keys::setKey {{{2 |
1161 | void Keys::setKey(const int row, const int qcode, const ushort unicode, | 1162 | void Keys::setKey(const int row, const int qcode, const ushort unicode, |
1162 | const int width, QPixmap *pix) { | 1163 | const int width, QImage *pix) { |
1163 | 1164 | ||
1164 | Key * key; | 1165 | Key * key; |
1165 | key = new Key; | 1166 | key = new Key; |
1166 | key->qcode = qcode; | 1167 | key->qcode = qcode; |
1167 | key->unicode = unicode; | 1168 | key->unicode = unicode; |
1168 | key->width = width; | 1169 | key->width = width; |
1169 | 1170 | ||
1170 | // share key->pressed between same keys | 1171 | // share key->pressed between same keys |
@@ -1211,17 +1212,17 @@ ushort Keys::uni(const int row, const int col) { | |||
1211 | 1212 | ||
1212 | } | 1213 | } |
1213 | 1214 | ||
1214 | int Keys::qcode(const int row, const int col) { | 1215 | int Keys::qcode(const int row, const int col) { |
1215 | 1216 | ||
1216 | return keys[row].at(col)->qcode; | 1217 | return keys[row].at(col)->qcode; |
1217 | } | 1218 | } |
1218 | 1219 | ||
1219 | QPixmap *Keys::pix(const int row, const int col) { | 1220 | QImage *Keys::pix(const int row, const int col) { |
1220 | 1221 | ||
1221 | return keys[row].at(col)->pix; | 1222 | return keys[row].at(col)->pix; |
1222 | 1223 | ||
1223 | } | 1224 | } |
1224 | bool Keys::pressed(const int row, const int col) { | 1225 | bool Keys::pressed(const int row, const int col) { |
1225 | 1226 | ||
1226 | return *(keys[row].at(col)->pressed); | 1227 | return *(keys[row].at(col)->pressed); |
1227 | } | 1228 | } |
diff --git a/inputmethods/multikey/keyboard.h b/inputmethods/multikey/keyboard.h index b692975..1aa7a35 100644 --- a/inputmethods/multikey/keyboard.h +++ b/inputmethods/multikey/keyboard.h | |||
@@ -58,35 +58,35 @@ public: | |||
58 | ~Keys(); | 58 | ~Keys(); |
59 | ushort uni(const int row, const int col); | 59 | ushort uni(const int row, const int col); |
60 | int qcode(const int row, const int col); | 60 | int qcode(const int row, const int col); |
61 | int width(const int row, const int col); | 61 | int width(const int row, const int col); |
62 | bool pressed(const int row, const int col); | 62 | bool pressed(const int row, const int col); |
63 | bool *pressedPtr(const int row, const int col); | 63 | bool *pressedPtr(const int row, const int col); |
64 | ushort shift(const ushort); | 64 | ushort shift(const ushort); |
65 | ushort meta(const ushort); | 65 | ushort meta(const ushort); |
66 | QPixmap *pix(const int row, const int col); | 66 | QImage *pix(const int row, const int col); |
67 | int numKeys(const int row); | 67 | int numKeys(const int row); |
68 | void setKeysFromFile(const char *filename); | 68 | void setKeysFromFile(const char *filename); |
69 | void setKey(const int row, const int qcode, const ushort unicode, | 69 | void setKey(const int row, const int qcode, const ushort unicode, |
70 | const int width, QPixmap *pix); | 70 | const int width, QImage *pix); |
71 | void setPressed(const int row, const int col, const bool pressed); | 71 | void setPressed(const int row, const int col, const bool pressed); |
72 | QString lang; | 72 | QString lang; |
73 | QString label; | 73 | QString label; |
74 | 74 | ||
75 | private: | 75 | private: |
76 | 76 | ||
77 | typedef struct Key { | 77 | typedef struct Key { |
78 | int qcode; // are qt key codes just unicode values? | 78 | int qcode; // are qt key codes just unicode values? |
79 | ushort unicode; | 79 | ushort unicode; |
80 | int width; // not pixels but relative key width. normal key is 2 | 80 | int width; // not pixels but relative key width. normal key is 2 |
81 | 81 | ||
82 | // only needed for keys like ctrl that can have multiple keys pressed at once | 82 | // only needed for keys like ctrl that can have multiple keys pressed at once |
83 | bool *pressed; | 83 | bool *pressed; |
84 | QPixmap *pix; | 84 | QImage *pix; |
85 | }; | 85 | }; |
86 | 86 | ||
87 | QList<Key> keys[6]; | 87 | QList<Key> keys[6]; |
88 | QMap<ushort,ushort> shiftMap; | 88 | QMap<ushort,ushort> shiftMap; |
89 | QMap<ushort,ushort> metaMap; | 89 | QMap<ushort,ushort> metaMap; |
90 | 90 | ||
91 | }; | 91 | }; |
92 | 92 | ||