summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2004-01-17 22:19:17 (UTC)
committer llornkcor <llornkcor>2004-01-17 22:19:17 (UTC)
commite9700698b2d664a688af20008095551624c995ae (patch) (unidiff)
tree0beaf08275a67e674c7cdd06df5c8431f538d59a
parent839775ea257f2c9be752a77c41a09416469df591 (diff)
downloadopie-e9700698b2d664a688af20008095551624c995ae.zip
opie-e9700698b2d664a688af20008095551624c995ae.tar.gz
opie-e9700698b2d664a688af20008095551624c995ae.tar.bz2
fix for ascii char width
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/embeddedkonsole/TEWidget.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/core/apps/embeddedkonsole/TEWidget.cpp b/core/apps/embeddedkonsole/TEWidget.cpp
index d0850e3..ec1b30c 100644
--- a/core/apps/embeddedkonsole/TEWidget.cpp
+++ b/core/apps/embeddedkonsole/TEWidget.cpp
@@ -199,98 +199,108 @@ unsigned short vt100_graphics[32] =
199static QChar vt100extended(QChar c) 199static QChar vt100extended(QChar c)
200{ 200{
201 switch (c.unicode()) 201 switch (c.unicode())
202 { 202 {
203 case 0x25c6 : return 1; 203 case 0x25c6 : return 1;
204 case 0x2592 : return 2; 204 case 0x2592 : return 2;
205 case 0x2409 : return 3; 205 case 0x2409 : return 3;
206 case 0x240c : return 4; 206 case 0x240c : return 4;
207 case 0x240d : return 5; 207 case 0x240d : return 5;
208 case 0x240a : return 6; 208 case 0x240a : return 6;
209 case 0x00b0 : return 7; 209 case 0x00b0 : return 7;
210 case 0x00b1 : return 8; 210 case 0x00b1 : return 8;
211 case 0x2424 : return 9; 211 case 0x2424 : return 9;
212 case 0x240b : return 10; 212 case 0x240b : return 10;
213 case 0x2518 : return 11; 213 case 0x2518 : return 11;
214 case 0x2510 : return 12; 214 case 0x2510 : return 12;
215 case 0x250c : return 13; 215 case 0x250c : return 13;
216 case 0x2514 : return 14; 216 case 0x2514 : return 14;
217 case 0x253c : return 15; 217 case 0x253c : return 15;
218 case 0xf800 : return 16; 218 case 0xf800 : return 16;
219 case 0xf801 : return 17; 219 case 0xf801 : return 17;
220 case 0x2500 : return 18; 220 case 0x2500 : return 18;
221 case 0xf803 : return 19; 221 case 0xf803 : return 19;
222 case 0xf804 : return 20; 222 case 0xf804 : return 20;
223 case 0x251c : return 21; 223 case 0x251c : return 21;
224 case 0x2524 : return 22; 224 case 0x2524 : return 22;
225 case 0x2534 : return 23; 225 case 0x2534 : return 23;
226 case 0x252c : return 24; 226 case 0x252c : return 24;
227 case 0x2502 : return 25; 227 case 0x2502 : return 25;
228 case 0x2264 : return 26; 228 case 0x2264 : return 26;
229 case 0x2265 : return 27; 229 case 0x2265 : return 27;
230 case 0x03c0 : return 28; 230 case 0x03c0 : return 28;
231 case 0x2260 : return 29; 231 case 0x2260 : return 29;
232 case 0x00a3 : return 30; 232 case 0x00a3 : return 30;
233 case 0x00b7 : return 31; 233 case 0x00b7 : return 31;
234 } 234 }
235 return c; 235 return c;
236} 236}
237 237
238static QChar identicalMap(QChar c) 238static QChar identicalMap(QChar c)
239{ 239{
240 return c; 240 return c;
241} 241}
242 242
243void TEWidget::fontChange(const QFont &) 243void TEWidget::fontChange(const QFont &)
244{ 244{
245 QFontMetrics fm(font()); 245 QFontMetrics fm(font());
246 font_h = fm.height(); 246 font_h = fm.height();
247 font_w = fm.maxWidth(); 247
248 font_a = fm.ascent(); 248 // font_w = max width of ASCII chars (U.B.)
249 font_w = 0;
250 int fw;
251 for (int i = 0x20; i < 0x80; i++) {
252 if (isprint(i) && font_w < (fw = fm.width(i))) {
253 font_w = fw;
254 }
255 }
256 //font_w = fm.maxWidth();
257
258 font_a = fm.ascent();
249//printf("font_h: %d\n",font_h); 259//printf("font_h: %d\n",font_h);
250//printf("font_w: %d\n",font_w); 260//printf("font_w: %d\n",font_w);
251//printf("font_a: %d\n",font_a); 261//printf("font_a: %d\n",font_a);
252//printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii()); 262//printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii());
253//printf("rawname: %s\n",font().rawName().ascii()); 263//printf("rawname: %s\n",font().rawName().ascii());
254 fontMap = 264 fontMap =
255#if QT_VERSION < 300 265#if QT_VERSION < 300
256 strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646") 266 strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646")
257 ? vt100extended 267 ? vt100extended
258 : 268 :
259#endif 269#endif
260 identicalMap; 270 identicalMap;
261 propagateSize(); 271 propagateSize();
262 update(); 272 update();
263} 273}
264 274
265void TEWidget::setVTFont(const QFont& f) 275void TEWidget::setVTFont(const QFont& f)
266{ 276{
267 QFrame::setFont(f); 277 QFrame::setFont(f);
268} 278}
269 279
270QFont TEWidget::getVTFont() { 280QFont TEWidget::getVTFont() {
271 return font(); 281 return font();
272} 282}
273 283
274void TEWidget::setFont(const QFont &) 284void TEWidget::setFont(const QFont &)
275{ 285{
276 // ignore font change request if not coming from konsole itself 286 // ignore font change request if not coming from konsole itself
277} 287}
278 288
279/* ------------------------------------------------------------------------- */ 289/* ------------------------------------------------------------------------- */
280/* */ 290/* */
281/* Constructor / Destructor */ 291/* Constructor / Destructor */
282/* */ 292/* */
283/* ------------------------------------------------------------------------- */ 293/* ------------------------------------------------------------------------- */
284 294
285TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name) 295TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name)
286{ 296{
287#ifndef QT_NO_CLIPBOARD 297#ifndef QT_NO_CLIPBOARD
288 cb = QApplication::clipboard(); 298 cb = QApplication::clipboard();
289 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), 299 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()),
290 this, SLOT(onClearSelection()) ); 300 this, SLOT(onClearSelection()) );
291#endif 301#endif
292 302
293 scrollbar = new QScrollBar(this); 303 scrollbar = new QScrollBar(this);
294 scrollbar->setCursor( arrowCursor ); 304 scrollbar->setCursor( arrowCursor );
295 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); 305 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
296 306
@@ -975,135 +985,140 @@ void TEWidget::onClearSelection()
975 985
976/* ------------------------------------------------------------------------- */ 986/* ------------------------------------------------------------------------- */
977/* */ 987/* */
978/* Keyboard */ 988/* Keyboard */
979/* */ 989/* */
980/* ------------------------------------------------------------------------- */ 990/* ------------------------------------------------------------------------- */
981 991
982//FIXME: an `eventFilter' has been installed instead of a `keyPressEvent' 992//FIXME: an `eventFilter' has been installed instead of a `keyPressEvent'
983// due to a bug in `QT' or the ignorance of the author to prevent 993// due to a bug in `QT' or the ignorance of the author to prevent
984// repaint events being emitted to the screen whenever one leaves 994// repaint events being emitted to the screen whenever one leaves
985// or reenters the screen to/from another application. 995// or reenters the screen to/from another application.
986// 996//
987// Troll says one needs to change focusInEvent() and focusOutEvent(), 997// Troll says one needs to change focusInEvent() and focusOutEvent(),
988// which would also let you have an in-focus cursor and an out-focus 998// which would also let you have an in-focus cursor and an out-focus
989// cursor like xterm does. 999// cursor like xterm does.
990 1000
991// for the auto-hide cursor feature, I added empty focusInEvent() and 1001// for the auto-hide cursor feature, I added empty focusInEvent() and
992// focusOutEvent() so that update() isn't called. 1002// focusOutEvent() so that update() isn't called.
993// For auto-hide, we need to get keypress-events, but we only get them when 1003// For auto-hide, we need to get keypress-events, but we only get them when
994// we have focus. 1004// we have focus.
995 1005
996void TEWidget::doScroll(int lines) 1006void TEWidget::doScroll(int lines)
997{ 1007{
998 scrollbar->setValue(scrollbar->value()+lines); 1008 scrollbar->setValue(scrollbar->value()+lines);
999} 1009}
1000 1010
1001void TEWidget::doHScroll(int lines) { 1011void TEWidget::doHScroll(int lines) {
1002 hScrollbar->setValue( hScrollbar->value()+lines); 1012 hScrollbar->setValue( hScrollbar->value()+lines);
1003} 1013}
1004 1014
1005bool TEWidget::eventFilter( QObject *obj, QEvent *e ) 1015bool TEWidget::eventFilter( QObject *obj, QEvent *e )
1006{ 1016{
1007 if ( (e->type() == QEvent::Accel || 1017 if ( (e->type() == QEvent::Accel ||
1008 e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) { 1018 e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) {
1009 static_cast<QKeyEvent *>( e )->ignore(); 1019 static_cast<QKeyEvent *>( e )->ignore();
1010 return true; 1020 return true;
1011 } 1021 }
1012 if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) 1022 if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ )
1013 return FALSE; // not us 1023 return FALSE; // not us
1014 if ( e->type() == QEvent::Wheel) { 1024 if ( e->type() == QEvent::Wheel) {
1015 QApplication::sendEvent(scrollbar, e); 1025 QApplication::sendEvent(scrollbar, e);
1016 } 1026 }
1017 1027
1018#ifdef FAKE_CTRL_AND_ALT 1028#ifdef FAKE_CTRL_AND_ALT
1019 static bool control = FALSE; 1029 static bool control = FALSE;
1020 static bool alt = FALSE; 1030 static bool alt = FALSE;
1021// qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:"); 1031// qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:");
1022 bool dele=FALSE; 1032 bool dele=FALSE;
1033
1023 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 1034 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
1024 QKeyEvent* ke = (QKeyEvent*)e; 1035 QKeyEvent* ke = (QKeyEvent*)e;
1025 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); 1036 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat();
1026 switch (ke->key()) { 1037 switch (ke->key()) {
1027 case Key_F9: // let this be "Control" 1038 case Key_F9: // let this be "Control"
1028 control = keydown; 1039 control = keydown;
1029 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); 1040 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state());
1030 dele=TRUE; 1041 dele=TRUE;
1031 break; 1042 break;
1032 case Key_F13: // let this be "Alt" 1043 case Key_F13: // let this be "Alt"
1033 alt = keydown; 1044 alt = keydown;
1034 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); 1045 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state());
1035 dele=TRUE; 1046 dele=TRUE;
1036 break; 1047 break;
1037 default: 1048 default:
1038 if ( control ) { 1049 if ( control ) {
1039 int a = toupper(ke->ascii())-64; 1050 int a = toupper(ke->ascii())-64;
1040 if ( a >= 0 && a < ' ' ) { 1051 if ( a >= 0 && a < ' ' ) {
1041 e = new QKeyEvent(e->type(), ke->key(), 1052 e = new QKeyEvent(e->type(), ke->key(),
1042 a, ke->state()|ControlButton, QChar(a,0)); 1053 a, ke->state()|ControlButton, QChar(a,0));
1043 dele=TRUE; 1054 dele=TRUE;
1044 } 1055 }
1045 } 1056 }
1046 if ( alt ) { 1057 if ( alt ) {
1047 e = new QKeyEvent(e->type(), ke->key(), 1058 e = new QKeyEvent(e->type(), ke->key(),
1048 ke->ascii(), ke->state()|AltButton, ke->text()); 1059 ke->ascii(), ke->state()|AltButton, ke->text());
1049 dele=TRUE; 1060 dele=TRUE;
1050 } 1061 }
1051 } 1062 }
1052 } 1063 }
1053#endif 1064#endif
1054 1065
1055 if ( e->type() == QEvent::KeyPress ) { 1066 if ( e->type() == QEvent::KeyPress ) {
1056 QKeyEvent* ke = (QKeyEvent*)e; 1067 QKeyEvent* ke = (QKeyEvent*)e;
1057 actSel=0; // Key stroke implies a screen update, so TEWidget won't 1068 actSel=0; // Key stroke implies a screen update, so TEWidget won't
1058 // know where the current selection is. 1069 // know where the current selection is.
1059 1070
1060// qDebug("key pressed is 0x%x, ascii is 0x%x, state %d", ke->key(), ke->ascii(), ke->state()); 1071// qDebug("key pressed is 0x%x, ascii is 0x%x, state %d", ke->key(), ke->ascii(), ke->state());
1061 1072 if(ke->key() == Key_Escape) {
1073 qDebug("key pressed is 0x%x, ascii is 0x%x, state %d", ke->key(), ke->ascii(), ke->state());
1074
1075 }
1076
1062 if( ke->state() == ShiftButton && ke->key() == Key_Tab) { 1077 if( ke->state() == ShiftButton && ke->key() == Key_Tab) {
1063 //lets hardcode this sucker 1078 //lets hardcode this sucker
1064 1079
1065// qDebug("key pressed 2 is 0x%x", ke->key()); 1080// qDebug("key pressed 2 is 0x%x", ke->key());
1066 emitText("\\"); // expose 1081 emitText("\\"); // expose
1067 } 1082 }
1068 else if( ke->state() == ControlButton && ke->key() == Key_V) { 1083 else if( ke->state() == ControlButton && ke->key() == Key_V) {
1069 pasteClipboard(); 1084 pasteClipboard();
1070 } 1085 }
1071// else if( ke->state() == ControlButton && ke->key() == Key_C) { 1086// else if( ke->state() == ControlButton && ke->key() == Key_C) {
1072// pasteClipboard(); 1087// pasteClipboard();
1073// } 1088// }
1074 else 1089 else
1075 emit keyPressedSignal(ke); // expose 1090 emit keyPressedSignal(ke); // expose
1076 ke->accept(); 1091 ke->accept();
1077#ifdef FAKE_CTRL_AND_ALT 1092#ifdef FAKE_CTRL_AND_ALT
1078 if ( dele ) delete e; 1093 if ( dele ) delete e;
1079#endif 1094#endif
1080 return true; // stop the event 1095 return true; // stop the event
1081 } 1096 }
1082 if ( e->type() == QEvent::Enter ) { 1097 if ( e->type() == QEvent::Enter ) {
1083 QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()), 1098 QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()),
1084 this, SLOT(onClearSelection()) ); 1099 this, SLOT(onClearSelection()) );
1085 } 1100 }
1086 if ( e->type() == QEvent::Leave ) { 1101 if ( e->type() == QEvent::Leave ) {
1087 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), 1102 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()),
1088 this, SLOT(onClearSelection()) ); 1103 this, SLOT(onClearSelection()) );
1089 } 1104 }
1090 return QFrame::eventFilter( obj, e ); 1105 return QFrame::eventFilter( obj, e );
1091} 1106}
1092 1107
1093/* ------------------------------------------------------------------------- */ 1108/* ------------------------------------------------------------------------- */
1094/* */ 1109/* */
1095/* Frame */ 1110/* Frame */
1096/* */ 1111/* */
1097/* ------------------------------------------------------------------------- */ 1112/* ------------------------------------------------------------------------- */
1098 1113
1099void TEWidget::frameChanged() 1114void TEWidget::frameChanged()
1100{ 1115{
1101 propagateSize(); 1116 propagateSize();
1102 update(); 1117 update();
1103} 1118}
1104 1119
1105/* ------------------------------------------------------------------------- */ 1120/* ------------------------------------------------------------------------- */
1106/* */ 1121/* */
1107/* Sound */ 1122/* Sound */
1108/* */ 1123/* */
1109/* ------------------------------------------------------------------------- */ 1124/* ------------------------------------------------------------------------- */