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
@@ -63,12 +63,13 @@
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>
@@ -241,24 +242,18 @@ static QChar identicalMap(QChar 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 =
@@ -304,17 +299,17 @@ TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name)
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:
@@ -681,19 +676,22 @@ void TEWidget::mousePressEvent(QMouseEvent* ev)
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;
@@ -812,12 +810,18 @@ void TEWidget::mouseMoveEvent(QMouseEvent* ev)
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'
@@ -1027,13 +1031,12 @@ bool TEWidget::eventFilter( QObject *obj, QEvent *e )
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;
@@ -1066,30 +1069,88 @@ bool TEWidget::eventFilter( QObject *obj, QEvent *e )
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
@@ -1113,13 +1174,12 @@ bool TEWidget::eventFilter( QObject *obj, QEvent *e )
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
@@ -1164,13 +1224,13 @@ void TEWidget::clearImage()
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