summaryrefslogtreecommitdiff
path: root/core/apps/embeddedkonsole/TEWidget.cpp
Unidiff
Diffstat (limited to 'core/apps/embeddedkonsole/TEWidget.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/apps/embeddedkonsole/TEWidget.cpp110
1 files changed, 85 insertions, 25 deletions
diff --git a/core/apps/embeddedkonsole/TEWidget.cpp b/core/apps/embeddedkonsole/TEWidget.cpp
index ec1b30c..98c3cdf 100644
--- a/core/apps/embeddedkonsole/TEWidget.cpp
+++ b/core/apps/embeddedkonsole/TEWidget.cpp
@@ -57,24 +57,25 @@
57 57
58#if !(QT_NO_COP) 58#if !(QT_NO_COP)
59#include <qpe/qcopenvelope_qws.h> 59#include <qpe/qcopenvelope_qws.h>
60#endif 60#endif
61 61
62#include <qcursor.h> 62#include <qcursor.h>
63#include <qregexp.h> 63#include <qregexp.h>
64#include <qpainter.h> 64#include <qpainter.h>
65#include <qclipboard.h> 65#include <qclipboard.h>
66#include <qstyle.h> 66#include <qstyle.h>
67#include <qfile.h> 67#include <qfile.h>
68#include <qdragobject.h> 68#include <qdragobject.h>
69#include <qnamespace.h>
69 70
70#include <stdio.h> 71#include <stdio.h>
71#include <stdlib.h> 72#include <stdlib.h>
72#include <unistd.h> 73#include <unistd.h>
73#include <ctype.h> 74#include <ctype.h>
74#include <sys/stat.h> 75#include <sys/stat.h>
75#include <sys/types.h> 76#include <sys/types.h>
76#include <signal.h> 77#include <signal.h>
77 78
78#include <assert.h> 79#include <assert.h>
79 80
80// #include "TEWidget.moc" 81// #include "TEWidget.moc"
@@ -235,36 +236,30 @@ static QChar vt100extended(QChar c)
235 return c; 236 return c;
236} 237}
237 238
238static QChar identicalMap(QChar c) 239static QChar identicalMap(QChar c)
239{ 240{
240 return c; 241 return c;
241} 242}
242 243
243void TEWidget::fontChange(const QFont &) 244void TEWidget::fontChange(const QFont &)
244{ 245{
245 QFontMetrics fm(font()); 246 QFontMetrics fm(font());
246 font_h = fm.height(); 247 font_h = fm.height();
247
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(); 248 //font_w = fm.maxWidth();
257 249 font_w = fm.width("m");
258 font_a = fm.ascent(); 250 font_a = fm.ascent();
251 printf("font h=%d max_width=%d width_m=%d assent=%d\n", font_h,
252 fm.maxWidth(), font_w, font_a);
253
259//printf("font_h: %d\n",font_h); 254//printf("font_h: %d\n",font_h);
260//printf("font_w: %d\n",font_w); 255//printf("font_w: %d\n",font_w);
261//printf("font_a: %d\n",font_a); 256//printf("font_a: %d\n",font_a);
262//printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii()); 257//printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii());
263//printf("rawname: %s\n",font().rawName().ascii()); 258//printf("rawname: %s\n",font().rawName().ascii());
264 fontMap = 259 fontMap =
265#if QT_VERSION < 300 260#if QT_VERSION < 300
266 strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646") 261 strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646")
267 ? vt100extended 262 ? vt100extended
268 : 263 :
269#endif 264#endif
270 identicalMap; 265 identicalMap;
@@ -298,29 +293,29 @@ TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name)
298 cb = QApplication::clipboard(); 293 cb = QApplication::clipboard();
299 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), 294 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()),
300 this, SLOT(onClearSelection()) ); 295 this, SLOT(onClearSelection()) );
301#endif 296#endif
302 297
303 scrollbar = new QScrollBar(this); 298 scrollbar = new QScrollBar(this);
304 scrollbar->setCursor( arrowCursor ); 299 scrollbar->setCursor( arrowCursor );
305 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); 300 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
306 301
307 hScrollbar = new QScrollBar(this); 302 hScrollbar = new QScrollBar(this);
308 hScrollbar->setCursor( arrowCursor ); 303 hScrollbar->setCursor( arrowCursor );
309 hScrollbar->setOrientation(QScrollBar::Horizontal); 304 hScrollbar->setOrientation(QScrollBar::Horizontal);
310 hScrollbar->setMaximumHeight(16); 305 // hScrollbar->setMaximumHeight(16);
311 306
312 connect( hScrollbar, SIGNAL(valueChanged(int)), this, SLOT( hScrollChanged(int))); 307 connect( hScrollbar, SIGNAL(valueChanged(int)), this, SLOT( hScrollChanged(int)));
313 308
314 Config cfg("Konsole"); 309 Config cfg("Qkonsole");
315 cfg.setGroup("ScrollBar"); 310 cfg.setGroup("ScrollBar");
316 switch( cfg.readNumEntry("Position",2)){ 311 switch( cfg.readNumEntry("Position",2)){
317 case 0: 312 case 0:
318 scrollLoc = SCRNONE; 313 scrollLoc = SCRNONE;
319 break; 314 break;
320 case 1: 315 case 1:
321 scrollLoc = SCRLEFT; 316 scrollLoc = SCRLEFT;
322 break; 317 break;
323 case 2: 318 case 2:
324 scrollLoc = SCRRIGHT; 319 scrollLoc = SCRRIGHT;
325 break; 320 break;
326 }; 321 };
@@ -675,31 +670,34 @@ void TEWidget::setScrollbarLocation(int loc)
675 670
676/*! 671/*!
677*/ 672*/
678 673
679void TEWidget::mousePressEvent(QMouseEvent* ev) 674void TEWidget::mousePressEvent(QMouseEvent* ev)
680{ 675{
681//printf("press [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); 676//printf("press [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button());
682 if ( !contentsRect().contains(ev->pos()) ) return; 677 if ( !contentsRect().contains(ev->pos()) ) return;
683 QPoint tL = contentsRect().topLeft(); 678 QPoint tL = contentsRect().topLeft();
684 int tLx = tL.x(); 679 int tLx = tL.x();
685 int tLy = tL.y(); 680 int tLy = tL.y();
686 681
687 word_selection_mode = FALSE; 682 mouse_down_x = ev->x();
683 mouse_down_y = ev->y();
688 684
689//printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY); 685//printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY);
690 if ( ev->button() == LeftButton) 686 if ( ev->button() == LeftButton)
691 { 687 {
692 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); 688 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
693 689
690 word_selection_mode = (ev->state() & ShiftButton);
691
694 if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ; 692 if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ;
695 693
696 if (mouse_marks || (ev->state() & ShiftButton)) 694 if (mouse_marks || (ev->state() & ShiftButton))
697 { 695 {
698 emit clearSelectionSignal(); 696 emit clearSelectionSignal();
699 iPntSel = pntSel = pos; 697 iPntSel = pntSel = pos;
700 actSel = 1; // left mouse button pressed but nothing selected yet. 698 actSel = 1; // left mouse button pressed but nothing selected yet.
701 grabMouse( /*crossCursor*/ ); // handle with care! 699 grabMouse( /*crossCursor*/ ); // handle with care!
702 } 700 }
703 else 701 else
704 { 702 {
705 emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button 703 emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button
@@ -806,24 +804,30 @@ void TEWidget::mouseMoveEvent(QMouseEvent* ev)
806 } 804 }
807 805
808 actSel = 2; // within selection 806 actSel = 2; // within selection
809 pntSel = here; 807 pntSel = here;
810 emit extendSelectionSignal( here.x(), here.y() ); 808 emit extendSelectionSignal( here.x(), here.y() );
811} 809}
812 810
813void TEWidget::mouseReleaseEvent(QMouseEvent* ev) 811void TEWidget::mouseReleaseEvent(QMouseEvent* ev)
814{ 812{
815//printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); 813//printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button());
816 if ( ev->button() == LeftButton) 814 if ( ev->button() == LeftButton)
817 { 815 {
816 if (QABS(ev->x() - mouse_down_x) < 3
817 && QABS(ev->y() - mouse_down_y) < 3
818 && ev->y() < qApp->desktop()->height()/8) {
819 emit setFullScreen(false);
820 }
821
818 if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks); 822 if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks);
819 preserve_line_breaks = TRUE; 823 preserve_line_breaks = TRUE;
820 actSel = 0; 824 actSel = 0;
821 825
822 //FIXME: emits a release event even if the mouse is 826 //FIXME: emits a release event even if the mouse is
823 // outside the range. The procedure used in `mouseMoveEvent' 827 // outside the range. The procedure used in `mouseMoveEvent'
824 // applies here, too. 828 // applies here, too.
825 829
826 QPoint tL = contentsRect().topLeft(); 830 QPoint tL = contentsRect().topLeft();
827 int tLx = tL.x(); 831 int tLx = tL.x();
828 int tLy = tL.y(); 832 int tLy = tL.y();
829 833
@@ -1021,25 +1025,24 @@ bool TEWidget::eventFilter( QObject *obj, QEvent *e )
1021 } 1025 }
1022 if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) 1026 if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ )
1023 return FALSE; // not us 1027 return FALSE; // not us
1024 if ( e->type() == QEvent::Wheel) { 1028 if ( e->type() == QEvent::Wheel) {
1025 QApplication::sendEvent(scrollbar, e); 1029 QApplication::sendEvent(scrollbar, e);
1026 } 1030 }
1027 1031
1028#ifdef FAKE_CTRL_AND_ALT 1032#ifdef FAKE_CTRL_AND_ALT
1029 static bool control = FALSE; 1033 static bool control = FALSE;
1030 static bool alt = FALSE; 1034 static bool alt = FALSE;
1031// qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:"); 1035// qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:");
1032 bool dele=FALSE; 1036 bool dele=FALSE;
1033
1034 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 1037 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
1035 QKeyEvent* ke = (QKeyEvent*)e; 1038 QKeyEvent* ke = (QKeyEvent*)e;
1036 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); 1039 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat();
1037 switch (ke->key()) { 1040 switch (ke->key()) {
1038 case Key_F9: // let this be "Control" 1041 case Key_F9: // let this be "Control"
1039 control = keydown; 1042 control = keydown;
1040 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); 1043 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state());
1041 dele=TRUE; 1044 dele=TRUE;
1042 break; 1045 break;
1043 case Key_F13: // let this be "Alt" 1046 case Key_F13: // let this be "Alt"
1044 alt = keydown; 1047 alt = keydown;
1045 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); 1048 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state());
@@ -1060,42 +1063,100 @@ bool TEWidget::eventFilter( QObject *obj, QEvent *e )
1060 dele=TRUE; 1063 dele=TRUE;
1061 } 1064 }
1062 } 1065 }
1063 } 1066 }
1064#endif 1067#endif
1065 1068
1066 if ( e->type() == QEvent::KeyPress ) { 1069 if ( e->type() == QEvent::KeyPress ) {
1067 QKeyEvent* ke = (QKeyEvent*)e; 1070 QKeyEvent* ke = (QKeyEvent*)e;
1068 actSel=0; // Key stroke implies a screen update, so TEWidget won't 1071 actSel=0; // Key stroke implies a screen update, so TEWidget won't
1069 // know where the current selection is. 1072 // know where the current selection is.
1070 1073
1071// qDebug("key pressed is 0x%x, ascii is 0x%x, state %d", ke->key(), ke->ascii(), ke->state()); 1074// qDebug("key pressed is 0x%x, ascii is 0x%x, state %d", ke->key(), ke->ascii(), ke->state());
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 bool special_function = true;
1077 switch(ke->key()) {
1078 //case 0x201b: // fn-5
1079 //case Key_F1:
1080 // switch sessions (?)
1081 // emitText("\\"); // expose (??)
1082 // break;
1083
1084 case 0x2016: // fn-p
1085 case Key_F2:
1086 pasteClipboard();
1087 break;
1088
1089 case 0x2018: // fn-S
1090 case Key_F3:
1091 emit changeSession(1);
1092 break;
1093
1094 case 0x2019: // fn-n
1095 emit newSession();
1096 break;
1097
1098 case Qt::Key_Tab:
1099 if (ke->state() == ControlButton) {
1100 emit changeSession(1);
1101 } else {
1102 special_function = false;
1103 }
1104 break;
1105
1106#if 0
1107 case Qt::Key_Left:
1108 if (vcolumns == 0) {
1109 emit changeSession(-1);
1110 } else {
1111 special_function = false;
1112 }
1113 break;
1114
1115 case Qt::Key_Right:
1116 if (vcolumns == 0) {
1117 emit changeSession(1);
1118 } else {
1119 special_function = false;
1075 } 1120 }
1121 break;
1122#endif
1076 1123
1077 if( ke->state() == ShiftButton && ke->key() == Key_Tab) { 1124 case 0x201b: // fn-5
1078 //lets hardcode this sucker 1125 case Key_F4:
1126 emit toggleFullScreen();
1127 break;
1128
1129 case 0x200f: // fn-1 magnify minus
1130 case Key_F5:
1131 emit changeFontSize(-1);
1132 break;
1079 1133
1080// qDebug("key pressed 2 is 0x%x", ke->key()); 1134 case 0x2010: // fn-2 magnify plus
1081 emitText("\\"); // expose 1135 case Key_F6:
1136 emit changeFontSize(1);
1137 break;
1138
1139 default:
1140 special_function = false;
1082 } 1141 }
1083 else if( ke->state() == ControlButton && ke->key() == Key_V) { 1142 if (special_function) {
1084 pasteClipboard(); 1143 return true;
1085 } 1144 }
1145 // else if( ke->state() == ControlButton && ke->key() == Key_V) {
1146 // pasteClipboard();
1147 // }
1086// else if( ke->state() == ControlButton && ke->key() == Key_C) { 1148// else if( ke->state() == ControlButton && ke->key() == Key_C) {
1087// pasteClipboard(); 1149// pasteClipboard();
1088// } 1150// }
1089 else
1090 emit keyPressedSignal(ke); // expose 1151 emit keyPressedSignal(ke); // expose
1091 ke->accept(); 1152 ke->accept();
1092#ifdef FAKE_CTRL_AND_ALT 1153#ifdef FAKE_CTRL_AND_ALT
1093 if ( dele ) delete e; 1154 if ( dele ) delete e;
1094#endif 1155#endif
1095 return true; // stop the event 1156 return true; // stop the event
1096 } 1157 }
1097 if ( e->type() == QEvent::Enter ) { 1158 if ( e->type() == QEvent::Enter ) {
1098 QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()), 1159 QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()),
1099 this, SLOT(onClearSelection()) ); 1160 this, SLOT(onClearSelection()) );
1100 } 1161 }
1101 if ( e->type() == QEvent::Leave ) { 1162 if ( e->type() == QEvent::Leave ) {
@@ -1107,25 +1168,24 @@ bool TEWidget::eventFilter( QObject *obj, QEvent *e )
1107 1168
1108/* ------------------------------------------------------------------------- */ 1169/* ------------------------------------------------------------------------- */
1109/* */ 1170/* */
1110/* Frame */ 1171/* Frame */
1111/* */ 1172/* */
1112/* ------------------------------------------------------------------------- */ 1173/* ------------------------------------------------------------------------- */
1113 1174
1114void TEWidget::frameChanged() 1175void TEWidget::frameChanged()
1115{ 1176{
1116 propagateSize(); 1177 propagateSize();
1117 update(); 1178 update();
1118} 1179}
1119
1120/* ------------------------------------------------------------------------- */ 1180/* ------------------------------------------------------------------------- */
1121/* */ 1181/* */
1122/* Sound */ 1182/* Sound */
1123/* */ 1183/* */
1124/* ------------------------------------------------------------------------- */ 1184/* ------------------------------------------------------------------------- */
1125 1185
1126void TEWidget::Bell() 1186void TEWidget::Bell()
1127{ 1187{
1128//#ifdef QT_QWS_SL5XXX 1188//#ifdef QT_QWS_SL5XXX
1129//# ifndef QT_NO_COP 1189//# ifndef QT_NO_COP
1130 if(useBeep) 1190 if(useBeep)
1131 QCopEnvelope( "QPE/TaskBar", "soundAlarm()" ); 1191 QCopEnvelope( "QPE/TaskBar", "soundAlarm()" );
@@ -1158,25 +1218,25 @@ void TEWidget::clearImage()
1158 image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR; 1218 image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR;
1159 image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION; 1219 image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION;
1160 } 1220 }
1161} 1221}
1162 1222
1163// Create Image /////////////////////////////////////////////////////// 1223// Create Image ///////////////////////////////////////////////////////
1164 1224
1165void TEWidget::calcGeometry() 1225void TEWidget::calcGeometry()
1166{ 1226{
1167 int showhscrollbar = 1; 1227 int showhscrollbar = 1;
1168 int hwidth = 0; 1228 int hwidth = 0;
1169 int dcolumns; 1229 int dcolumns;
1170 Config cfg("Konsole"); 1230 Config cfg("Qkonsole");
1171 cfg.setGroup("ScrollBar"); 1231 cfg.setGroup("ScrollBar");
1172 useHorzScroll=cfg.readBoolEntry("HorzScroll",0); 1232 useHorzScroll=cfg.readBoolEntry("HorzScroll",0);
1173 1233
1174 if(vcolumns == 0) showhscrollbar = 0; 1234 if(vcolumns == 0) showhscrollbar = 0;
1175 if(showhscrollbar == 1) hwidth = QApplication::style().scrollBarExtent().width(); 1235 if(showhscrollbar == 1) hwidth = QApplication::style().scrollBarExtent().width();
1176 1236
1177 scrollbar->resize(QApplication::style().scrollBarExtent().width(), 1237 scrollbar->resize(QApplication::style().scrollBarExtent().width(),
1178 contentsRect().height() - hwidth); 1238 contentsRect().height() - hwidth);
1179 1239
1180 switch(scrollLoc) { 1240 switch(scrollLoc) {
1181 case SCRNONE : 1241 case SCRNONE :
1182 columns = ( contentsRect().width() - 2 * rimX ) / font_w; 1242 columns = ( contentsRect().width() - 2 * rimX ) / font_w;