summaryrefslogtreecommitdiff
path: root/core/apps/embeddedkonsole/TEWidget.cpp
Unidiff
Diffstat (limited to 'core/apps/embeddedkonsole/TEWidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/embeddedkonsole/TEWidget.cpp98
1 files changed, 51 insertions, 47 deletions
diff --git a/core/apps/embeddedkonsole/TEWidget.cpp b/core/apps/embeddedkonsole/TEWidget.cpp
index dc83998..f10bfb2 100644
--- a/core/apps/embeddedkonsole/TEWidget.cpp
+++ b/core/apps/embeddedkonsole/TEWidget.cpp
@@ -1,30 +1,29 @@
1/* ------------------------------------------------------------------------ */ 1/* ------------------------------------------------------------------------ */
2/* */ 2/* */
3/* [TEWidget.C] Terminal Emulation Widget */ 3/* [TEWidget.C] Terminal Emulation Widget */
4/* */ 4/* */
5/* ------------------------------------------------------------------------ */ 5/* ------------------------------------------------------------------------ */
6/* */ 6/* */
7/* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ 7/* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */
8/* */ 8/* */
9/* This file is part of Konsole - an X terminal for KDE */ 9/* This file is part of Konsole - an X terminal for KDE */
10/* */ 10/* */
11/* ------------------------------------------------------------------------ */ 11/* ------------------------------------------------------------------------ */
12 /* */ 12/* */
13/* Ported Konsole to Qt/Embedded */ 13/* Ported Konsole to Qt/Embedded */
14 /* */ 14/* */
15/* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ 15/* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */
16 /* */ 16/* */
17/* -------------------------------------------------------------------------- */ 17/* -------------------------------------------------------------------------- */
18
19/*! \class TEWidget 18/*! \class TEWidget
20 19
21 \brief Visible screen contents 20 \brief Visible screen contents
22 21
23 This class is responsible to map the `image' of a terminal emulation to the 22 This class is responsible to map the `image' of a terminal emulation to the
24 display. All the dependency of the emulation to a specific GUI or toolkit is 23 display. All the dependency of the emulation to a specific GUI or toolkit is
25 localized here. Further, this widget has no knowledge about being part of an 24 localized here. Further, this widget has no knowledge about being part of an
26 emulation, it simply work within the terminal emulation framework by exposing 25 emulation, it simply work within the terminal emulation framework by exposing
27 size and key events and by being ordered to show a new image. 26 size and key events and by being ordered to show a new image.
28 27
29 <ul> 28 <ul>
30 <li> The internal image has the size of the widget (evtl. rounded up) 29 <li> The internal image has the size of the widget (evtl. rounded up)
@@ -106,46 +105,52 @@ static const ColorEntry base_color_table[TABLE_COLORS] =
106{ 105{
107 // Fixme: could add faint colors here, also. 106 // Fixme: could add faint colors here, also.
108 // normal 107 // normal
109 ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 1, 0 ), // Dfore, Dback 108 ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 1, 0 ), // Dfore, Dback
110 ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0x18), 0, 0 ), // Black, Red 109 ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0x18), 0, 0 ), // Black, Red
111 ColorEntry(QColor(0x18,0xB2,0x18), 0, 0 ), ColorEntry( QColor(0xB2,0x68,0x18), 0, 0 ), // Green, Yellow 110 ColorEntry(QColor(0x18,0xB2,0x18), 0, 0 ), ColorEntry( QColor(0xB2,0x68,0x18), 0, 0 ), // Green, Yellow
112 ColorEntry(QColor(0x18,0x18,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), // Blue, Magenta 111 ColorEntry(QColor(0x18,0x18,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), // Blue, Magenta
113 ColorEntry(QColor(0x18,0xB2,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 0, 0 ), // Cyan, White 112 ColorEntry(QColor(0x18,0xB2,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 0, 0 ), // Cyan, White
114 // intensiv 113 // intensiv
115 ColorEntry(QColor(0x00,0x00,0x00), 0, 1 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 1, 0 ), 114 ColorEntry(QColor(0x00,0x00,0x00), 0, 1 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 1, 0 ),
116 ColorEntry(QColor(0x68,0x68,0x68), 0, 0 ), ColorEntry( QColor(0xFF,0x54,0x54), 0, 0 ), 115 ColorEntry(QColor(0x68,0x68,0x68), 0, 0 ), ColorEntry( QColor(0xFF,0x54,0x54), 0, 0 ),
117 ColorEntry(QColor(0x54,0xFF,0x54), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0x54), 0, 0 ), 116 ColorEntry(QColor(0x54,0xFF,0x54), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0x54), 0, 0 ),
118 ColorEntry(QColor(0x54,0x54,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0x54,0xFF), 0, 0 ), 117 ColorEntry(QColor(0x54,0x54,0xFF), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ),
119 ColorEntry(QColor(0x54,0xFF,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 0, 0 ) 118 ColorEntry(QColor(0x54,0xFF,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 0, 0 )
120}; 119};
121 120
122/* Note that we use ANSI color order (bgr), while IBMPC color order is (rgb) 121/* Note that we use ANSI color order (bgr), while IBMPC color order is (rgb)
123 122
124 Code 0 1 2 3 4 5 6 7 123 Code 0 1 2 3 4 5 6 7
125 ----------- ------- ------- ------- ------- ------- ------- ------- ------- 124 ----------- ------- ------- ------- ------- ------- ------- ------- -------
126 ANSI (bgr) Black Red Green Yellow Blue Magenta Cyan White 125 ANSI (bgr) Black Red Green Yellow Blue Magenta Cyan White
127 IBMPC (rgb) Black Blue Green Cyan Red Magenta Yellow White 126 IBMPC (rgb) Black Blue Green Cyan Red Magenta Yellow White
128*/ 127*/
129 128
130QColor TEWidget::getDefaultBackColor() 129QColor TEWidget::getDefaultBackColor()
131{ 130{
132 return color_table[DEFAULT_BACK_COLOR].color; 131 return color_table[DEFAULT_BACK_COLOR].color;
133} 132}
134 133
135const ColorEntry* TEWidget::getColorTable() const 134const ColorEntry* TEWidget::getColorTable() const
136{ 135{
137 return color_table; 136 return color_table;
138} 137}
139 138
139const ColorEntry* TEWidget::getdefaultColorTable() const
140{
141 return base_color_table;
142}
143
144
140const QPixmap *TEWidget::backgroundPixmap() 145const QPixmap *TEWidget::backgroundPixmap()
141{ 146{
142 static QPixmap *bg = new QPixmap("~/qpim/main/pics/faded_bg.xpm"); 147 static QPixmap *bg = new QPixmap("~/qpim/main/pics/faded_bg.xpm");
143 const QPixmap *pm = bg; 148 const QPixmap *pm = bg;
144 return pm; 149 return pm;
145} 150}
146 151
147void TEWidget::setColorTable(const ColorEntry table[]) 152void TEWidget::setColorTable(const ColorEntry table[])
148{ 153{
149 for (int i = 0; i < TABLE_COLORS; i++) color_table[i] = table[i]; 154 for (int i = 0; i < TABLE_COLORS; i++) color_table[i] = table[i];
150 155
151 const QPixmap* pm = backgroundPixmap(); 156 const QPixmap* pm = backgroundPixmap();
@@ -231,40 +236,39 @@ void TEWidget::fontChange(const QFont &)
231{ 236{
232 QFontMetrics fm(font()); 237 QFontMetrics fm(font());
233 font_h = fm.height(); 238 font_h = fm.height();
234 font_w = fm.maxWidth(); 239 font_w = fm.maxWidth();
235 font_a = fm.ascent(); 240 font_a = fm.ascent();
236//printf("font_h: %d\n",font_h); 241//printf("font_h: %d\n",font_h);
237//printf("font_w: %d\n",font_w); 242//printf("font_w: %d\n",font_w);
238//printf("font_a: %d\n",font_a); 243//printf("font_a: %d\n",font_a);
239//printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii()); 244//printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii());
240//printf("rawname: %s\n",font().rawName().ascii()); 245//printf("rawname: %s\n",font().rawName().ascii());
241 fontMap = 246 fontMap =
242#if QT_VERSION < 300 247#if QT_VERSION < 300
243 strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646") 248 strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646")
244 ? vt100extended 249 ? vt100extended
245 : 250 :
246#endif 251#endif
247 identicalMap; 252 identicalMap;
248 propagateSize(); 253 propagateSize();
249 update(); 254 update();
250} 255}
251 256
252void TEWidget::setVTFont(const QFont& f) 257void TEWidget::setVTFont(const QFont& f)
253{ 258{
254 QFrame::setFont(f); 259 QFrame::setFont(f);
255} 260}
256 261
257QFont TEWidget::getVTFont() 262QFont TEWidget::getVTFont() {
258{
259 return font(); 263 return font();
260} 264}
261 265
262void TEWidget::setFont(const QFont &) 266void TEWidget::setFont(const QFont &)
263{ 267{
264 // ignore font change request if not coming from konsole itself 268 // ignore font change request if not coming from konsole itself
265} 269}
266 270
267/* ------------------------------------------------------------------------- */ 271/* ------------------------------------------------------------------------- */
268/* */ 272/* */
269/* Constructor / Destructor */ 273/* Constructor / Destructor */
270/* */ 274/* */
@@ -638,25 +642,25 @@ void TEWidget::mousePressEvent(QMouseEvent* ev)
638//printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY); 642//printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY);
639 if ( ev->button() == LeftButton) 643 if ( ev->button() == LeftButton)
640 { 644 {
641 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); 645 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
642 646
643 if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ; 647 if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ;
644 648
645 if (mouse_marks || (ev->state() & ShiftButton)) 649 if (mouse_marks || (ev->state() & ShiftButton))
646 { 650 {
647 emit clearSelectionSignal(); 651 emit clearSelectionSignal();
648 iPntSel = pntSel = pos; 652 iPntSel = pntSel = pos;
649 actSel = 1; // left mouse button pressed but nothing selected yet. 653 actSel = 1; // left mouse button pressed but nothing selected yet.
650 grabMouse( /*crossCursor*/ ); // handle with care! 654 grabMouse( /*crossCursor*/ ); // handle with care!
651 } 655 }
652 else 656 else
653 { 657 {
654 emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button 658 emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button
655 } 659 }
656 } 660 }
657 if ( ev->button() == MidButton ) 661 if ( ev->button() == MidButton )
658 { 662 {
659 emitSelection(); 663 emitSelection();
660 } 664 }
661 if ( ev->button() == RightButton ) // Configure 665 if ( ev->button() == RightButton ) // Configure
662 { 666 {
@@ -704,27 +708,27 @@ void TEWidget::mouseMoveEvent(QMouseEvent* ev)
704 708
705 QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h); 709 QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h);
706 QPoint ohere; 710 QPoint ohere;
707 bool swapping = FALSE; 711 bool swapping = FALSE;
708 712
709 if ( word_selection_mode ) 713 if ( word_selection_mode )
710 { 714 {
711 // Extend to word boundaries 715 // Extend to word boundaries
712 int i; 716 int i;
713 int selClass; 717 int selClass;
714 718
715 bool left_not_right = ( here.y() < iPntSel.y() || 719 bool left_not_right = ( here.y() < iPntSel.y() ||
716 here.y() == iPntSel.y() && here.x() < iPntSel.x() ); 720 here.y() == iPntSel.y() && here.x() < iPntSel.x() );
717 bool old_left_not_right = ( pntSel.y() < iPntSel.y() || 721 bool old_left_not_right = ( pntSel.y() < iPntSel.y() ||
718 pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() ); 722 pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() );
719 swapping = left_not_right != old_left_not_right; 723 swapping = left_not_right != old_left_not_right;
720 724
721 // Find left (left_not_right ? from here : from start) 725 // Find left (left_not_right ? from here : from start)
722 QPoint left = left_not_right ? here : iPntSel; 726 QPoint left = left_not_right ? here : iPntSel;
723 i = loc(left.x(),left.y()); 727 i = loc(left.x(),left.y());
724 selClass = charClass(image[i].c); 728 selClass = charClass(image[i].c);
725 while ( left.x() > 0 && charClass(image[i-1].c) == selClass ) 729 while ( left.x() > 0 && charClass(image[i-1].c) == selClass )
726 { i--; left.rx()--; } 730 { i--; left.rx()--; }
727 731
728 // Find left (left_not_right ? from start : from here) 732 // Find left (left_not_right ? from start : from here)
729 QPoint right = left_not_right ? iPntSel : here; 733 QPoint right = left_not_right ? iPntSel : here;
730 i = loc(right.x(),right.y()); 734 i = loc(right.x(),right.y());
@@ -966,52 +970,52 @@ bool TEWidget::eventFilter( QObject *obj, QEvent *e )
966 return FALSE; // not us 970 return FALSE; // not us
967 if ( e->type() == QEvent::Wheel) 971 if ( e->type() == QEvent::Wheel)
968 { 972 {
969 QApplication::sendEvent(scrollbar, e); 973 QApplication::sendEvent(scrollbar, e);
970 } 974 }
971 975
972#ifdef FAKE_CTRL_AND_ALT 976#ifdef FAKE_CTRL_AND_ALT
973 static bool control = FALSE; 977 static bool control = FALSE;
974 static bool alt = FALSE; 978 static bool alt = FALSE;
975 // Has a keyboard with no CTRL and ALT keys, but we fake it: 979 // Has a keyboard with no CTRL and ALT keys, but we fake it:
976 bool dele=FALSE; 980 bool dele=FALSE;
977 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 981 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
978 QKeyEvent* ke = (QKeyEvent*)e; 982 QKeyEvent* ke = (QKeyEvent*)e;
979 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); 983 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat();
980 switch (ke->key()) { 984 switch (ke->key()) {
981 case Key_F9: // let this be "Control" 985 case Key_F9: // let this be "Control"
982 control = keydown; 986 control = keydown;
983 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); 987 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state());
984 dele=TRUE; 988 dele=TRUE;
985 break; 989 break;
986 case Key_F13: // let this be "Alt" 990 case Key_F13: // let this be "Alt"
987 alt = keydown; 991 alt = keydown;
988 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); 992 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state());
989 dele=TRUE; 993 dele=TRUE;
990 break; 994 break;
991 default: 995 default:
992 if ( control ) { 996 if ( control ) {
993 int a = toupper(ke->ascii())-64; 997 int a = toupper(ke->ascii())-64;
994 if ( a >= 0 && a < ' ' ) { 998 if ( a >= 0 && a < ' ' ) {
995 e = new QKeyEvent(e->type(), ke->key(), 999 e = new QKeyEvent(e->type(), ke->key(),
996 a, ke->state()|ControlButton, QChar(a,0)); 1000 a, ke->state()|ControlButton, QChar(a,0));
997 dele=TRUE; 1001 dele=TRUE;
998 } 1002 }
999 } 1003 }
1000 if ( alt ) { 1004 if ( alt ) {
1001 e = new QKeyEvent(e->type(), ke->key(), 1005 e = new QKeyEvent(e->type(), ke->key(),
1002 ke->ascii(), ke->state()|AltButton, ke->text()); 1006 ke->ascii(), ke->state()|AltButton, ke->text());
1003 dele=TRUE; 1007 dele=TRUE;
1004 } 1008 }
1005 } 1009 }
1006 } 1010 }
1007#endif 1011#endif
1008 1012
1009 if ( e->type() == QEvent::KeyPress ) 1013 if ( e->type() == QEvent::KeyPress )
1010 { 1014 {
1011 QKeyEvent* ke = (QKeyEvent*)e; 1015 QKeyEvent* ke = (QKeyEvent*)e;
1012 1016
1013 actSel=0; // Key stroke implies a screen update, so TEWidget won't 1017 actSel=0; // Key stroke implies a screen update, so TEWidget won't
1014 // know where the current selection is. 1018 // know where the current selection is.
1015 1019
1016 emit keyPressedSignal(ke); // expose 1020 emit keyPressedSignal(ke); // expose
1017 ke->accept(); 1021 ke->accept();
@@ -1179,32 +1183,32 @@ void TEWidget::dropEvent(QDropEvent* event)
1179 dropText += url.path(); // local URL : remove protocol 1183 dropText += url.path(); // local URL : remove protocol
1180 } 1184 }
1181 else { 1185 else {
1182 dropText += url.prettyURL(); 1186 dropText += url.prettyURL();
1183 bPopup = false; // a non-local file, don't popup 1187 bPopup = false; // a non-local file, don't popup
1184 } 1188 }
1185*/ 1189*/
1186 1190
1187 } 1191 }
1188 1192
1189 if (bPopup) 1193 if (bPopup)
1190 // m_drop->popup(pos() + event->pos()); 1194 // m_drop->popup(pos() + event->pos());
1191 m_drop->popup(mapToGlobal(event->pos())); 1195 m_drop->popup(mapToGlobal(event->pos()));
1192 else 1196 else
1193 { 1197 {
1194 if (currentSession) { 1198 if (currentSession) {
1195 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1199 currentSession->getEmulation()->sendString(dropText.local8Bit());
1196 } 1200 }
1197 // kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; 1201// kdDebug() << "Drop:" << dropText.local8Bit() << "\n";
1198 } 1202 }
1199 } 1203 }
1200 } 1204 }
1201 else if(QTextDrag::decode(event, dropText)) { 1205 else if(QTextDrag::decode(event, dropText)) {
1202// kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; 1206// kdDebug() << "Drop:" << dropText.local8Bit() << "\n";
1203 if (currentSession) { 1207 if (currentSession) {
1204 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1208 currentSession->getEmulation()->sendString(dropText.local8Bit());
1205 } 1209 }
1206 // Paste it 1210 // Paste it
1207 } 1211 }
1208} 1212}
1209#endif 1213#endif
1210 1214