summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2004-12-28 23:17:43 (UTC)
committer llornkcor <llornkcor>2004-12-28 23:17:43 (UTC)
commite2d6f156eacc312f270a1b5c3830e58be8941460 (patch) (unidiff)
tree85cc827910cd5617f01de4ded6cbc302ffd73bfe
parent47b3f934ed4f5d84356b5b052aed018dc97ab6a7 (diff)
downloadopie-e2d6f156eacc312f270a1b5c3830e58be8941460.zip
opie-e2d6f156eacc312f270a1b5c3830e58be8941460.tar.gz
opie-e2d6f156eacc312f270a1b5c3830e58be8941460.tar.bz2
fix compile
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/embeddedkonsole/TEWidget.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/core/apps/embeddedkonsole/TEWidget.cpp b/core/apps/embeddedkonsole/TEWidget.cpp
index 3cb1c0a..5171bf1 100644
--- a/core/apps/embeddedkonsole/TEWidget.cpp
+++ b/core/apps/embeddedkonsole/TEWidget.cpp
@@ -1,1429 +1,1431 @@
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/*! \class TEWidget 18/*! \class TEWidget
19 19
20 \brief Visible screen contents 20 \brief Visible screen contents
21 21
22 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
23 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
24 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
25 emulation, it simply work within the terminal emulation framework by exposing 25 emulation, it simply work within the terminal emulation framework by exposing
26 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.
27 27
28 <ul> 28 <ul>
29 <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)
30 <li> The external image used in setImage can have any size. 30 <li> The external image used in setImage can have any size.
31 <li> (internally) the external image is simply copied to the internal 31 <li> (internally) the external image is simply copied to the internal
32 when a setImage happens. During a resizeEvent no painting is done 32 when a setImage happens. During a resizeEvent no painting is done
33 a paintEvent is expected to follow anyway. 33 a paintEvent is expected to follow anyway.
34 </ul> 34 </ul>
35 35
36 \sa TEScreen \sa Emulation 36 \sa TEScreen \sa Emulation
37*/ 37*/
38 38
39/* FIXME: 39/* FIXME:
40 - 'image' may also be used uninitialized (it isn't in fact) in resizeEvent 40 - 'image' may also be used uninitialized (it isn't in fact) in resizeEvent
41 - 'font_a' not used in mouse events 41 - 'font_a' not used in mouse events
42 - add destructor 42 - add destructor
43*/ 43*/
44 44
45/* TODO 45/* TODO
46 - evtl. be sensitive to `paletteChange' while using default colors. 46 - evtl. be sensitive to `paletteChange' while using default colors.
47 - set different 'rounding' styles? I.e. have a mode to show clipped chars? 47 - set different 'rounding' styles? I.e. have a mode to show clipped chars?
48*/ 48*/
49 49
50// #include "config.h" 50// #include "config.h"
51#include "TEWidget.h" 51#include "TEWidget.h"
52#include "session.h" 52#include "session.h"
53#include <qpe/config.h> 53#include <qpe/config.h>
54 54
55 55
56#if !(QT_NO_COP) 56#if !(QT_NO_COP)
57#include <qpe/qcopenvelope_qws.h> 57#include <qpe/qcopenvelope_qws.h>
58#endif 58#endif
59 59
60#include <qclipboard.h> 60#include <qclipboard.h>
61 61
62#ifndef QT_NO_DRAGANDDROP 62#ifndef QT_NO_DRAGANDDROP
63#include <qdragobject.h> 63#include <qdragobject.h>
64#include <qfile.h> 64#include <qfile.h>
65#endif 65#endif
66 66
67#include <stdio.h> 67#include <stdio.h>
68#include <stdlib.h> 68#include <stdlib.h>
69#include <unistd.h> 69#include <unistd.h>
70#include <ctype.h> 70#include <ctype.h>
71#include <sys/stat.h> 71#include <sys/stat.h>
72#include <sys/types.h> 72#include <sys/types.h>
73#include <signal.h> 73#include <signal.h>
74 74
75#include <assert.h> 75#include <assert.h>
76 76
77// #include "TEWidget.moc" 77// #include "TEWidget.moc"
78//#include <kapp.h> 78//#include <kapp.h>
79//#include <kcursor.h> 79//#include <kcursor.h>
80//#include <kurl.h> 80//#include <kurl.h>
81//#include <kdebug.h> 81//#include <kdebug.h>
82//#include <klocale.h> 82//#include <klocale.h>
83 83
84#define HERE printf("%s(%d): %s\n",__FILE__,__LINE__,__FUNCTION__) 84#define HERE printf("%s(%d): %s\n",__FILE__,__LINE__,__FUNCTION__)
85#define HCNT(Name) // { static int cnt = 1; printf("%s(%d): %s %d\n",__FILE__,__LINE__,Name,cnt++); } 85#define HCNT(Name) // { static int cnt = 1; printf("%s(%d): %s %d\n",__FILE__,__LINE__,Name,cnt++); }
86 86
87#define loc(X,Y) ((Y)*columns+(X)) 87#define loc(X,Y) ((Y)*columns+(X))
88 88
89//FIXME: the rim should normally be 1, 0 only when running in full screen mode. 89//FIXME: the rim should normally be 1, 0 only when running in full screen mode.
90#define rimX 0 // left/right rim width 90#define rimX 0 // left/right rim width
91#define rimY 0 // top/bottom rim high 91#define rimY 0 // top/bottom rim high
92 92
93#define SCRWIDTH 16 // width of the scrollbar 93#define SCRWIDTH 16 // width of the scrollbar
94 94
95#define yMouseScroll 1 95#define yMouseScroll 1
96// scroll increment used when dragging selection at top/bottom of window. 96// scroll increment used when dragging selection at top/bottom of window.
97 97
98/* ------------------------------------------------------------------------- */ 98/* ------------------------------------------------------------------------- */
99/* */ 99/* */
100/* Colors */ 100/* Colors */
101/* */ 101/* */
102/* ------------------------------------------------------------------------- */ 102/* ------------------------------------------------------------------------- */
103 103
104//FIXME: the default color table is in session.C now. 104//FIXME: the default color table is in session.C now.
105// We need a way to get rid of this one, here. 105// We need a way to get rid of this one, here.
106static const ColorEntry base_color_table[TABLE_COLORS] = 106static const ColorEntry base_color_table[TABLE_COLORS] =
107// The following are almost IBM standard color codes, with some slight 107// The following are almost IBM standard color codes, with some slight
108// gamma correction for the dim colors to compensate for bright X screens. 108// gamma correction for the dim colors to compensate for bright X screens.
109// It contains the 8 ansiterm/xterm colors in 2 intensities. 109// It contains the 8 ansiterm/xterm colors in 2 intensities.
110{ 110{
111 // Fixme: could add faint colors here, also. 111 // Fixme: could add faint colors here, also.
112 // normal 112 // normal
113 ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 1, 0 ), // Dfore, Dback 113 ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 1, 0 ), // Dfore, Dback
114 ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0x18), 0, 0 ), // Black, Red 114 ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0x18), 0, 0 ), // Black, Red
115 ColorEntry(QColor(0x18,0xB2,0x18), 0, 0 ), ColorEntry( QColor(0xB2,0x68,0x18), 0, 0 ), // Green, Yellow 115 ColorEntry(QColor(0x18,0xB2,0x18), 0, 0 ), ColorEntry( QColor(0xB2,0x68,0x18), 0, 0 ), // Green, Yellow
116 ColorEntry(QColor(0x18,0x18,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), // Blue, Magenta 116 ColorEntry(QColor(0x18,0x18,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), // Blue, Magenta
117 ColorEntry(QColor(0x18,0xB2,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 0, 0 ), // Cyan, White 117 ColorEntry(QColor(0x18,0xB2,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 0, 0 ), // Cyan, White
118 // intensiv 118 // intensiv
119 ColorEntry(QColor(0x00,0x00,0x00), 0, 1 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 1, 0 ), 119 ColorEntry(QColor(0x00,0x00,0x00), 0, 1 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 1, 0 ),
120 ColorEntry(QColor(0x68,0x68,0x68), 0, 0 ), ColorEntry( QColor(0xFF,0x54,0x54), 0, 0 ), 120 ColorEntry(QColor(0x68,0x68,0x68), 0, 0 ), ColorEntry( QColor(0xFF,0x54,0x54), 0, 0 ),
121 ColorEntry(QColor(0x54,0xFF,0x54), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0x54), 0, 0 ), 121 ColorEntry(QColor(0x54,0xFF,0x54), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0x54), 0, 0 ),
122 ColorEntry(QColor(0x54,0x54,0xFF), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), 122 ColorEntry(QColor(0x54,0x54,0xFF), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ),
123 ColorEntry(QColor(0x54,0xFF,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 0, 0 ) 123 ColorEntry(QColor(0x54,0xFF,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 0, 0 )
124}; 124};
125 125
126/* Note that we use ANSI color order (bgr), while IBMPC color order is (rgb) 126/* Note that we use ANSI color order (bgr), while IBMPC color order is (rgb)
127 127
128 Code 0 1 2 3 4 5 6 7 128 Code 0 1 2 3 4 5 6 7
129 ----------- ------- ------- ------- ------- ------- ------- ------- ------- 129 ----------- ------- ------- ------- ------- ------- ------- ------- -------
130 ANSI (bgr) Black Red Green Yellow Blue Magenta Cyan White 130 ANSI (bgr) Black Red Green Yellow Blue Magenta Cyan White
131 IBMPC (rgb) Black Blue Green Cyan Red Magenta Yellow White 131 IBMPC (rgb) Black Blue Green Cyan Red Magenta Yellow White
132*/ 132*/
133 133
134QColor TEWidget::getDefaultBackColor() 134QColor TEWidget::getDefaultBackColor()
135{ 135{
136 return color_table[DEFAULT_BACK_COLOR].color; 136 return color_table[DEFAULT_BACK_COLOR].color;
137} 137}
138 138
139const ColorEntry* TEWidget::getColorTable() const 139const ColorEntry* TEWidget::getColorTable() const
140{ 140{
141 return color_table; 141 return color_table;
142} 142}
143 143
144const ColorEntry* TEWidget::getdefaultColorTable() const 144const ColorEntry* TEWidget::getdefaultColorTable() const
145{ 145{
146 return base_color_table; 146 return base_color_table;
147} 147}
148 148
149 149
150const QPixmap *TEWidget::backgroundPixmap() 150const QPixmap *TEWidget::backgroundPixmap()
151{ 151{
152 static QPixmap *bg = new QPixmap("~/qpim/main/pics/faded_bg.xpm"); 152 static QPixmap *bg = new QPixmap("~/qpim/main/pics/faded_bg.xpm");
153 const QPixmap *pm = bg; 153 const QPixmap *pm = bg;
154 return pm; 154 return pm;
155} 155}
156 156
157void TEWidget::setColorTable(const ColorEntry table[]) 157void TEWidget::setColorTable(const ColorEntry table[])
158{ 158{
159 for (int i = 0; i < TABLE_COLORS; i++) color_table[i] = table[i]; 159 for (int i = 0; i < TABLE_COLORS; i++) color_table[i] = table[i];
160 160
161 const QPixmap* pm = backgroundPixmap(); 161 const QPixmap* pm = backgroundPixmap();
162 if (!pm) setBackgroundColor(color_table[DEFAULT_BACK_COLOR].color); 162 if (!pm) setBackgroundColor(color_table[DEFAULT_BACK_COLOR].color);
163 update(); 163 update();
164} 164}
165 165
166//FIXME: add backgroundPixmapChanged. 166//FIXME: add backgroundPixmapChanged.
167 167
168/* ------------------------------------------------------------------------- */ 168/* ------------------------------------------------------------------------- */
169/* */ 169/* */
170/* Font */ 170/* Font */
171/* */ 171/* */
172/* ------------------------------------------------------------------------- */ 172/* ------------------------------------------------------------------------- */
173 173
174/* 174/*
175 The VT100 has 32 special graphical characters. The usual vt100 extended 175 The VT100 has 32 special graphical characters. The usual vt100 extended
176 xterm fonts have these at 0x00..0x1f. 176 xterm fonts have these at 0x00..0x1f.
177 177
178 QT's iso mapping leaves 0x00..0x7f without any changes. But the graphicals 178 QT's iso mapping leaves 0x00..0x7f without any changes. But the graphicals
179 come in here as proper unicode characters. 179 come in here as proper unicode characters.
180 180
181 We treat non-iso10646 fonts as VT100 extended and do the requiered mapping 181 We treat non-iso10646 fonts as VT100 extended and do the requiered mapping
182 from unicode to 0x00..0x1f. The remaining translation is then left to the 182 from unicode to 0x00..0x1f. The remaining translation is then left to the
183 QCodec. 183 QCodec.
184*/ 184*/
185 185
186// assert for i in [0..31] : vt100extended(vt100_graphics[i]) == i. 186// assert for i in [0..31] : vt100extended(vt100_graphics[i]) == i.
187 187
188unsigned short vt100_graphics[32] = 188unsigned short vt100_graphics[32] =
189{ // 0/8 1/9 2/10 3/11 4/12 5/13 6/14 7/15 189{ // 0/8 1/9 2/10 3/11 4/12 5/13 6/14 7/15
190 0x0020, 0x25C6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, 190 0x0020, 0x25C6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0,
191 0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 191 0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c,
192 0xF800, 0xF801, 0x2500, 0xF803, 0xF804, 0x251c, 0x2524, 0x2534, 192 0xF800, 0xF801, 0x2500, 0xF803, 0xF804, 0x251c, 0x2524, 0x2534,
193 0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7 193 0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7
194}; 194};
195 195
196static QChar vt100extended(QChar c) 196static QChar vt100extended(QChar c)
197{ 197{
198 switch (c.unicode()) 198 switch (c.unicode())
199 { 199 {
200 case 0x25c6 : return 1; 200 case 0x25c6 : return 1;
201 case 0x2592 : return 2; 201 case 0x2592 : return 2;
202 case 0x2409 : return 3; 202 case 0x2409 : return 3;
203 case 0x240c : return 4; 203 case 0x240c : return 4;
204 case 0x240d : return 5; 204 case 0x240d : return 5;
205 case 0x240a : return 6; 205 case 0x240a : return 6;
206 case 0x00b0 : return 7; 206 case 0x00b0 : return 7;
207 case 0x00b1 : return 8; 207 case 0x00b1 : return 8;
208 case 0x2424 : return 9; 208 case 0x2424 : return 9;
209 case 0x240b : return 10; 209 case 0x240b : return 10;
210 case 0x2518 : return 11; 210 case 0x2518 : return 11;
211 case 0x2510 : return 12; 211 case 0x2510 : return 12;
212 case 0x250c : return 13; 212 case 0x250c : return 13;
213 case 0x2514 : return 14; 213 case 0x2514 : return 14;
214 case 0x253c : return 15; 214 case 0x253c : return 15;
215 case 0xf800 : return 16; 215 case 0xf800 : return 16;
216 case 0xf801 : return 17; 216 case 0xf801 : return 17;
217 case 0x2500 : return 18; 217 case 0x2500 : return 18;
218 case 0xf803 : return 19; 218 case 0xf803 : return 19;
219 case 0xf804 : return 20; 219 case 0xf804 : return 20;
220 case 0x251c : return 21; 220 case 0x251c : return 21;
221 case 0x2524 : return 22; 221 case 0x2524 : return 22;
222 case 0x2534 : return 23; 222 case 0x2534 : return 23;
223 case 0x252c : return 24; 223 case 0x252c : return 24;
224 case 0x2502 : return 25; 224 case 0x2502 : return 25;
225 case 0x2264 : return 26; 225 case 0x2264 : return 26;
226 case 0x2265 : return 27; 226 case 0x2265 : return 27;
227 case 0x03c0 : return 28; 227 case 0x03c0 : return 28;
228 case 0x2260 : return 29; 228 case 0x2260 : return 29;
229 case 0x00a3 : return 30; 229 case 0x00a3 : return 30;
230 case 0x00b7 : return 31; 230 case 0x00b7 : return 31;
231 } 231 }
232 return c; 232 return c;
233} 233}
234 234
235static QChar identicalMap(QChar c) 235static QChar identicalMap(QChar c)
236{ 236{
237 return c; 237 return c;
238} 238}
239 239
240void TEWidget::fontChange(const QFont &) 240void TEWidget::fontChange(const QFont &)
241{ 241{
242 QFontMetrics fm(font()); 242 QFontMetrics fm(font());
243 font_h = fm.height(); 243 font_h = fm.height();
244 // font_w = fm.maxWidth(); 244 // font_w = fm.maxWidth();
245 font_w = fm.width("m"); 245 font_w = fm.width("m");
246 font_a = fm.ascent(); 246 font_a = fm.ascent();
247 printf("font h=%d max_width=%d width_m=%d assent=%d\n", font_h, 247 printf("font h=%d max_width=%d width_m=%d assent=%d\n", font_h,
248 fm.maxWidth(), font_w, font_a); 248 fm.maxWidth(), font_w, font_a);
249 249
250 //printf("font_h: %d\n",font_h); 250 //printf("font_h: %d\n",font_h);
251 //printf("font_w: %d\n",font_w); 251 //printf("font_w: %d\n",font_w);
252 //printf("font_a: %d\n",font_a); 252 //printf("font_a: %d\n",font_a);
253 //printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii()); 253 //printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii());
254 //printf("rawname: %s\n",font().rawName().ascii()); 254 //printf("rawname: %s\n",font().rawName().ascii());
255 fontMap = 255 fontMap =
256#if QT_VERSION < 300 256#if QT_VERSION < 300
257 strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646") 257 strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646")
258 ? vt100extended 258 ? vt100extended
259 : 259 :
260#endif 260#endif
261 identicalMap; 261 identicalMap;
262 propagateSize(); 262 propagateSize();
263 update(); 263 update();
264} 264}
265 265
266void TEWidget::setVTFont(const QFont& f) 266void TEWidget::setVTFont(const QFont& f)
267{ 267{
268 QFrame::setFont(f); 268 QFrame::setFont(f);
269} 269}
270 270
271QFont TEWidget::getVTFont() { 271QFont TEWidget::getVTFont() {
272 return font(); 272 return font();
273} 273}
274 274
275void TEWidget::setFont(const QFont &) 275void TEWidget::setFont(const QFont &)
276{ 276{
277 // ignore font change request if not coming from konsole itself 277 // ignore font change request if not coming from konsole itself
278} 278}
279 279
280/* ------------------------------------------------------------------------- */ 280/* ------------------------------------------------------------------------- */
281/* */ 281/* */
282/* Constructor / Destructor */ 282/* Constructor / Destructor */
283/* */ 283/* */
284/* ------------------------------------------------------------------------- */ 284/* ------------------------------------------------------------------------- */
285 285
286TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name) 286TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name)
287{ 287{
288#ifndef QT_NO_CLIPBOARD 288#ifndef QT_NO_CLIPBOARD
289 cb = QApplication::clipboard(); 289 cb = QApplication::clipboard();
290 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), 290 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()),
291 this, SLOT(onClearSelection()) ); 291 this, SLOT(onClearSelection()) );
292#endif 292#endif
293 293
294 scrollbar = new QScrollBar(this); 294 scrollbar = new QScrollBar(this);
295 scrollbar->setCursor( arrowCursor ); 295 scrollbar->setCursor( arrowCursor );
296 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); 296 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
297 297
298 hScrollbar = new QScrollBar(this); 298 hScrollbar = new QScrollBar(this);
299 hScrollbar->setCursor( arrowCursor ); 299 hScrollbar->setCursor( arrowCursor );
300 hScrollbar->setOrientation(QScrollBar::Horizontal); 300 hScrollbar->setOrientation(QScrollBar::Horizontal);
301 // hScrollbar->setMaximumHeight(16); 301 // hScrollbar->setMaximumHeight(16);
302 302
303 connect( hScrollbar, SIGNAL(valueChanged(int)), this, SLOT( hScrollChanged(int))); 303 connect( hScrollbar, SIGNAL(valueChanged(int)), this, SLOT( hScrollChanged(int)));
304 304
305 Config cfg( "Konsole" ); 305 Config cfg( "Konsole" );
306 cfg.setGroup("ScrollBar"); 306 cfg.setGroup("ScrollBar");
307 switch( cfg.readNumEntry("Position",2)){ 307 switch( cfg.readNumEntry("Position",2)){
308 case 0: 308 case 0:
309 scrollLoc = SCRNONE; 309 scrollLoc = SCRNONE;
310 break; 310 break;
311 case 1: 311 case 1:
312 scrollLoc = SCRLEFT; 312 scrollLoc = SCRLEFT;
313 break; 313 break;
314 case 2: 314 case 2:
315 scrollLoc = SCRRIGHT; 315 scrollLoc = SCRRIGHT;
316 break; 316 break;
317 }; 317 };
318 318
319 useHorzScroll=cfg.readBoolEntry("HorzScroll",0); 319 useHorzScroll=cfg.readBoolEntry("HorzScroll",0);
320 320
321 blinkT = new QTimer(this); 321 blinkT = new QTimer(this);
322 connect(blinkT, SIGNAL(timeout()), this, SLOT(blinkEvent())); 322 connect(blinkT, SIGNAL(timeout()), this, SLOT(blinkEvent()));
323 // blinking = FALSE; 323 // blinking = FALSE;
324 blinking = TRUE; 324 blinking = TRUE;
325 325
326 resizing = FALSE; 326 resizing = FALSE;
327 actSel = 0; 327 actSel = 0;
328 image = 0; 328 image = 0;
329 lines = 1; 329 lines = 1;
330 columns = 1; 330 columns = 1;
331 font_w = 1; 331 font_w = 1;
332 font_h = 1; 332 font_h = 1;
333 font_a = 1; 333 font_a = 1;
334 word_selection_mode = FALSE; 334 word_selection_mode = FALSE;
335 hposition = 0; 335 hposition = 0;
336 vcolumns = 0; 336 vcolumns = 0;
337 useBeep = true; 337 useBeep = true;
338 338
339 setMouseMarks(TRUE); 339 setMouseMarks(TRUE);
340 setVTFont( QFont("fixed") ); 340 setVTFont( QFont("fixed") );
341 setColorTable(base_color_table); // init color table 341 setColorTable(base_color_table); // init color table
342 342
343 qApp->installEventFilter( this ); //FIXME: see below 343 qApp->installEventFilter( this ); //FIXME: see below
344// KCursor::setAutoHideCursor( this, true ); 344// KCursor::setAutoHideCursor( this, true );
345 345
346 // Init DnD //////////////////////////////////////////////////////////////// 346 // Init DnD ////////////////////////////////////////////////////////////////
347 currentSession = NULL; 347 currentSession = NULL;
348// setAcceptDrops(true); // attempt 348// setAcceptDrops(true); // attempt
349// m_drop = new QPopupMenu(this); 349// m_drop = new QPopupMenu(this);
350// m_drop->insertItem( QString("Paste"), 0); 350// m_drop->insertItem( QString("Paste"), 0);
351// m_drop->insertItem( QString("cd"), 1); 351// m_drop->insertItem( QString("cd"), 1);
352// connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int))); 352// connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int)));
353 353
354 // we need focus so that the auto-hide cursor feature works 354 // we need focus so that the auto-hide cursor feature works
355 setFocus(); 355 setFocus();
356 setFocusPolicy( WheelFocus ); 356 setFocusPolicy( WheelFocus );
357} 357}
358 358
359//FIXME: make proper destructor 359//FIXME: make proper destructor
360// Here's a start (David) 360// Here's a start (David)
361TEWidget::~TEWidget() 361TEWidget::~TEWidget()
362{ 362{
363 qApp->removeEventFilter( this ); 363 qApp->removeEventFilter( this );
364 if (image) free(image); 364 if (image) free(image);
365} 365}
366 366
367/* ------------------------------------------------------------------------- */ 367/* ------------------------------------------------------------------------- */
368/* */ 368/* */
369/* Display Operations */ 369/* Display Operations */
370/* */ 370/* */
371/* ------------------------------------------------------------------------- */ 371/* ------------------------------------------------------------------------- */
372 372
373/*! 373/*!
374 attributed string draw primitive 374 attributed string draw primitive
375*/ 375*/
376 376
377void TEWidget::drawAttrStr(QPainter &paint, QRect rect, 377void TEWidget::drawAttrStr(QPainter &paint, QRect rect,
378 QString& str, ca attr, BOOL pm, BOOL clear) 378 QString& str, ca attr, BOOL pm, BOOL clear)
379{ 379{
380 if (pm && color_table[attr.b].transparent) 380 if (pm && color_table[attr.b].transparent)
381 { 381 {
382 paint.setBackgroundMode( TransparentMode ); 382 paint.setBackgroundMode( TransparentMode );
383 if (clear) erase(rect); 383 if (clear) erase(rect);
384 } 384 }
385 else 385 else
386 { 386 {
387 if (blinking) 387 if (blinking)
388 paint.fillRect(rect, color_table[attr.b].color); 388 paint.fillRect(rect, color_table[attr.b].color);
389 else 389 else
390 { 390 {
391 paint.setBackgroundMode( OpaqueMode ); 391 paint.setBackgroundMode( OpaqueMode );
392 paint.setBackgroundColor( color_table[attr.b].color ); 392 paint.setBackgroundColor( color_table[attr.b].color );
393 } 393 }
394 } 394 }
395 395
396 if (color_table[attr.f].bold) 396 if (color_table[attr.f].bold)
397 paint.setPen(QColor( 0x8F, 0x00, 0x00 )); 397 paint.setPen(QColor( 0x8F, 0x00, 0x00 ));
398 else 398 else
399 paint.setPen(color_table[attr.f].color); 399 paint.setPen(color_table[attr.f].color);
400 400
401 paint.drawText(rect.x(),rect.y()+font_a, str); 401 paint.drawText(rect.x(),rect.y()+font_a, str);
402 402
403 if (attr.r & RE_UNDERLINE) 403 if (attr.r & RE_UNDERLINE)
404 paint.drawLine(rect.left(), rect.y()+font_a+1, rect.right(),rect.y()+font_a+1 ); 404 paint.drawLine(rect.left(), rect.y()+font_a+1, rect.right(),rect.y()+font_a+1 );
405} 405}
406 406
407/*! 407/*!
408 The image can only be set completely. 408 The image can only be set completely.
409 409
410 The size of the new image may or may not match the size of the widget. 410 The size of the new image may or may not match the size of the widget.
411*/ 411*/
412 412
413void TEWidget::setImage(const ca* const newimg, int lines, int columns) 413void TEWidget::setImage(const ca* const newimg, int lines, int columns)
414{ int y,x,len; 414{ int y,x,len;
415 const QPixmap* pm = backgroundPixmap(); 415 const QPixmap* pm = backgroundPixmap();
416 QPainter paint; 416 QPainter paint;
417 setUpdatesEnabled(FALSE); 417 setUpdatesEnabled(FALSE);
418 paint.begin( this ); 418 paint.begin( this );
419HCNT("setImage"); 419HCNT("setImage");
420 420
421 QPoint tL = contentsRect().topLeft(); 421 QPoint tL = contentsRect().topLeft();
422 int tLx = tL.x(); 422 int tLx = tL.x();
423 int tLy = tL.y(); 423 int tLy = tL.y();
424 hasBlinker = FALSE; 424 hasBlinker = FALSE;
425 425
426 int cf = -1; // undefined 426 int cf = -1; // undefined
427 int cb = -1; // undefined 427 int cb = -1; // undefined
428 int cr = -1; // undefined 428 int cr = -1; // undefined
429 429
430 int lins = QMIN(this->lines, QMAX(0,lines )); 430 int lins = QMIN(this->lines, QMAX(0,lines ));
431 int cols = QMIN(this->columns,QMAX(0,columns)); 431 int cols = QMIN(this->columns,QMAX(0,columns));
432 QChar *disstrU = new QChar[cols]; 432 QChar *disstrU = new QChar[cols];
433 for (y = 0; y < lins; y++) { 433 for (y = 0; y < lins; y++) {
434 const ca* lcl = &image[y*this->columns]; 434 const ca* lcl = &image[y*this->columns];
435 const ca* const ext = &newimg[y*columns]; 435 const ca* const ext = &newimg[y*columns];
436 if (!resizing) // not while resizing, we're expecting a paintEvent 436 if (!resizing) // not while resizing, we're expecting a paintEvent
437 for (x = 0; x < cols; x++) 437 for (x = 0; x < cols; x++)
438 { 438 {
439 hasBlinker |= (ext[x].r & RE_BLINK); 439 hasBlinker |= (ext[x].r & RE_BLINK);
440 if (ext[x] != lcl[x]) 440 if (ext[x] != lcl[x])
441 { 441 {
442 cr = ext[x].r; 442 cr = ext[x].r;
443 cb = ext[x].b; 443 cb = ext[x].b;
444 if (ext[x].f != cf) cf = ext[x].f; 444 if (ext[x].f != cf) cf = ext[x].f;
445 int lln = cols - x; 445 int lln = cols - x;
446 disstrU[0] = fontMap(ext[x+0].c); 446 disstrU[0] = fontMap(ext[x+0].c);
447 for (len = 1; len < lln; len++) 447 for (len = 1; len < lln; len++)
448 { 448 {
449 if (ext[x+len].f != cf || ext[x+len].b != cb || ext[x+len].r != cr || 449 if (ext[x+len].f != cf || ext[x+len].b != cb || ext[x+len].r != cr ||
450 ext[x+len] == lcl[x+len] ) 450 ext[x+len] == lcl[x+len] )
451 break; 451 break;
452 disstrU[len] = fontMap(ext[x+len].c); 452 disstrU[len] = fontMap(ext[x+len].c);
453 } 453 }
454 QString unistr(disstrU,len); 454 QString unistr(disstrU,len);
455 drawAttrStr(paint, 455 drawAttrStr(paint,
456 QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), 456 QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h),
457 unistr, ext[x], pm != NULL, true); 457 unistr, ext[x], pm != NULL, true);
458 x += len - 1; 458 x += len - 1;
459 } 459 }
460 } 460 }
461 // finally, make `image' become `newimg'. 461 // finally, make `image' become `newimg'.
462 memcpy((void*)lcl,(const void*)ext,cols*sizeof(ca)); 462 memcpy((void*)lcl,(const void*)ext,cols*sizeof(ca));
463 } 463 }
464 drawFrame( &paint ); 464 drawFrame( &paint );
465 paint.end(); 465 paint.end();
466 setUpdatesEnabled(TRUE); 466 setUpdatesEnabled(TRUE);
467 if ( hasBlinker && !blinkT->isActive()) blinkT->start(1000); // 1000 ms 467 if ( hasBlinker && !blinkT->isActive()) blinkT->start(1000); // 1000 ms
468 if (!hasBlinker && blinkT->isActive()) { blinkT->stop(); blinking = FALSE; } 468 if (!hasBlinker && blinkT->isActive()) { blinkT->stop(); blinking = FALSE; }
469 delete [] disstrU; 469 delete [] disstrU;
470} 470}
471 471
472// paint Event //////////////////////////////////////////////////// 472// paint Event ////////////////////////////////////////////////////
473 473
474/*! 474/*!
475 The difference of this routine vs. the `setImage' is, 475 The difference of this routine vs. the `setImage' is,
476 that the drawing does not include a difference analysis 476 that the drawing does not include a difference analysis
477 between the old and the new image. Instead, the internal 477 between the old and the new image. Instead, the internal
478 image is used and the painting bound by the PaintEvent box. 478 image is used and the painting bound by the PaintEvent box.
479*/ 479*/
480 480
481void TEWidget::paintEvent( QPaintEvent* pe ) 481void TEWidget::paintEvent( QPaintEvent* pe )
482{ 482{
483 483
484//{ static int cnt = 0; printf("paint %d\n",cnt++); } 484//{ static int cnt = 0; printf("paint %d\n",cnt++); }
485 const QPixmap* pm = backgroundPixmap(); 485 const QPixmap* pm = backgroundPixmap();
486 QPainter paint; 486 QPainter paint;
487 setUpdatesEnabled(FALSE); 487 setUpdatesEnabled(FALSE);
488 paint.begin( this ); 488 paint.begin( this );
489 paint.setBackgroundMode( TransparentMode ); 489 paint.setBackgroundMode( TransparentMode );
490HCNT("paintEvent"); 490HCNT("paintEvent");
491 491
492 // Note that the actual widget size can be slightly larger 492 // Note that the actual widget size can be slightly larger
493 // that the image (the size is truncated towards the smaller 493 // that the image (the size is truncated towards the smaller
494 // number of characters in `resizeEvent'. The paint rectangle 494 // number of characters in `resizeEvent'. The paint rectangle
495 // can thus be larger than the image, but less then the size 495 // can thus be larger than the image, but less then the size
496 // of one character. 496 // of one character.
497 497
498 QRect rect = pe->rect().intersect(contentsRect()); 498 QRect rect = pe->rect().intersect(contentsRect());
499 499
500 QPoint tL = contentsRect().topLeft(); 500 QPoint tL = contentsRect().topLeft();
501 int tLx = tL.x(); 501 int tLx = tL.x();
502 int tLy = tL.y(); 502 int tLy = tL.y();
503 503
504 int lux = QMIN(columns-1, QMAX(0,(rect.left() - tLx - blX ) / font_w)); 504 int lux = QMIN(columns-1, QMAX(0,(rect.left() - tLx - blX ) / font_w));
505 int luy = QMIN(lines-1, QMAX(0,(rect.top() - tLy - bY ) / font_h)); 505 int luy = QMIN(lines-1, QMAX(0,(rect.top() - tLy - bY ) / font_h));
506 int rlx = QMIN(columns-1, QMAX(0,(rect.right() - tLx - blX ) / font_w)); 506 int rlx = QMIN(columns-1, QMAX(0,(rect.right() - tLx - blX ) / font_w));
507 int rly = QMIN(lines-1, QMAX(0,(rect.bottom() - tLy - bY ) / font_h)); 507 int rly = QMIN(lines-1, QMAX(0,(rect.bottom() - tLy - bY ) / font_h));
508 508
509 /* 509 /*
510 printf("paintEvent: %d..%d, %d..%d (%d..%d, %d..%d)\n",lux,rlx,luy,rly, 510 printf("paintEvent: %d..%d, %d..%d (%d..%d, %d..%d)\n",lux,rlx,luy,rly,
511 rect.left(), rect.right(), rect.top(), rect.bottom()); 511 rect.left(), rect.right(), rect.top(), rect.bottom());
512 */ 512 */
513 513
514 // if (pm != NULL && color_table[image->b].transparent) 514 // if (pm != NULL && color_table[image->b].transparent)
515 // erase(rect); 515 // erase(rect);
516 // BL: I have no idea why we need this, and it breaks the refresh. 516 // BL: I have no idea why we need this, and it breaks the refresh.
517 517
518 QChar *disstrU = new QChar[columns]; 518 QChar *disstrU = new QChar[columns];
519 for (int y = luy; y <= rly; y++) 519 for (int y = luy; y <= rly; y++)
520 for (int x = lux; x <= rlx; x++) 520 for (int x = lux; x <= rlx; x++)
521 { 521 {
522 int len = 1; 522 int len = 1;
523 disstrU[0] = fontMap(image[loc(x,y)].c); 523 disstrU[0] = fontMap(image[loc(x,y)].c);
524 int cf = image[loc(x,y)].f; 524 int cf = image[loc(x,y)].f;
525 int cb = image[loc(x,y)].b; 525 int cb = image[loc(x,y)].b;
526 int cr = image[loc(x,y)].r; 526 int cr = image[loc(x,y)].r;
527 while (x+len <= rlx && 527 while (x+len <= rlx &&
528 image[loc(x+len,y)].f == cf && 528 image[loc(x+len,y)].f == cf &&
529 image[loc(x+len,y)].b == cb && 529 image[loc(x+len,y)].b == cb &&
530 image[loc(x+len,y)].r == cr ) 530 image[loc(x+len,y)].r == cr )
531 { 531 {
532 disstrU[len] = fontMap(image[loc(x+len,y)].c); 532 disstrU[len] = fontMap(image[loc(x+len,y)].c);
533 len += 1; 533 len += 1;
534 } 534 }
535 QString unistr(disstrU,len); 535 QString unistr(disstrU,len);
536 drawAttrStr(paint, 536 drawAttrStr(paint,
537 QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), 537 QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h),
538 unistr, image[loc(x,y)], pm != NULL, false); 538 unistr, image[loc(x,y)], pm != NULL, false);
539 x += len - 1; 539 x += len - 1;
540 } 540 }
541 delete [] disstrU; 541 delete [] disstrU;
542 drawFrame( &paint ); 542 drawFrame( &paint );
543 paint.end(); 543 paint.end();
544 setUpdatesEnabled(TRUE); 544 setUpdatesEnabled(TRUE);
545} 545}
546 546
547void TEWidget::blinkEvent() 547void TEWidget::blinkEvent()
548{ 548{
549 blinking = !blinking; 549 blinking = !blinking;
550 repaint(FALSE); 550 repaint(FALSE);
551} 551}
552 552
553/* ------------------------------------------------------------------------- */ 553/* ------------------------------------------------------------------------- */
554/* */ 554/* */
555/* Resizing */ 555/* Resizing */
556/* */ 556/* */
557/* ------------------------------------------------------------------------- */ 557/* ------------------------------------------------------------------------- */
558 558
559void TEWidget::resizeEvent(QResizeEvent* ev) 559void TEWidget::resizeEvent(QResizeEvent* ev)
560{ 560{
561// printf("resize: %d,%d\n",ev->size().width(),ev->size().height()); 561// printf("resize: %d,%d\n",ev->size().width(),ev->size().height());
562 //printf("approx: %d,%d\n",ev->size().width()/font_w,ev->size().height()/font_h); 562 //printf("approx: %d,%d\n",ev->size().width()/font_w,ev->size().height()/font_h);
563 //printf("leaves: %d,%d\n",ev->size().width()%font_w,ev->size().height()%font_h); 563 //printf("leaves: %d,%d\n",ev->size().width()%font_w,ev->size().height()%font_h);
564 //printf("curren: %d,%d\n",width(),height()); 564 //printf("curren: %d,%d\n",width(),height());
565HCNT("resizeEvent"); 565HCNT("resizeEvent");
566 566
567 // see comment in `paintEvent' concerning the rounding. 567 // see comment in `paintEvent' concerning the rounding.
568 //FIXME: could make a routine here; check width(),height() 568 //FIXME: could make a routine here; check width(),height()
569 assert(ev->size().width() == width()); 569 assert(ev->size().width() == width());
570 assert(ev->size().height() == height()); 570 assert(ev->size().height() == height());
571 571
572 propagateSize(); 572 propagateSize();
573} 573}
574 574
575void TEWidget::propagateSize() 575void TEWidget::propagateSize()
576{ 576{
577 ca* oldimg = image; 577 ca* oldimg = image;
578 int oldlin = lines; 578 int oldlin = lines;
579 int oldcol = columns; 579 int oldcol = columns;
580 makeImage(); 580 makeImage();
581 // we copy the old image to reduce flicker 581 // we copy the old image to reduce flicker
582 int lins = QMIN(oldlin,lines); 582 int lins = QMIN(oldlin,lines);
583 int cols = QMIN(oldcol,columns); 583 int cols = QMIN(oldcol,columns);
584 if (oldimg) 584 if (oldimg)
585 { 585 {
586 for (int lin = 0; lin < lins; lin++) 586 for (int lin = 0; lin < lins; lin++)
587 memcpy((void*)&image[columns*lin], 587 memcpy((void*)&image[columns*lin],
588 (void*)&oldimg[oldcol*lin],cols*sizeof(ca)); 588 (void*)&oldimg[oldcol*lin],cols*sizeof(ca));
589 free(oldimg); //FIXME: try new,delete 589 free(oldimg); //FIXME: try new,delete
590 } 590 }
591 else 591 else
592 clearImage(); 592 clearImage();
593 593
594 //NOTE: control flows from the back through the chest right into the eye. 594 //NOTE: control flows from the back through the chest right into the eye.
595 // `emu' will call back via `setImage'. 595 // `emu' will call back via `setImage'.
596 596
597 resizing = TRUE; 597 resizing = TRUE;
598 emit changedImageSizeSignal(lines, columns); // expose resizeEvent 598 emit changedImageSizeSignal(lines, columns); // expose resizeEvent
599 resizing = FALSE; 599 resizing = FALSE;
600} 600}
601 601
602/* ------------------------------------------------------------------------- */ 602/* ------------------------------------------------------------------------- */
603/* */ 603/* */
604/* Scrollbar */ 604/* Scrollbar */
605/* */ 605/* */
606/* ------------------------------------------------------------------------- */ 606/* ------------------------------------------------------------------------- */
607 607
608void TEWidget::scrollChanged(int) { 608void TEWidget::scrollChanged(int) {
609 emit changedHistoryCursor(scrollbar->value()); //expose 609 emit changedHistoryCursor(scrollbar->value()); //expose
610} 610}
611 611
612void TEWidget::hScrollChanged(int loc) { 612void TEWidget::hScrollChanged(int loc) {
613 hposition = loc; 613 hposition = loc;
614 propagateSize(); 614 propagateSize();
615 update(); 615 update();
616 616
617// emit changedHorzCursor( hScrollbar->value()); //expose 617// emit changedHorzCursor( hScrollbar->value()); //expose
618} 618}
619 619
620void TEWidget::setScroll(int cursor, int slines) 620void TEWidget::setScroll(int cursor, int slines)
621{ 621{
622 disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); 622 disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
623 scrollbar->setRange(0,slines); 623 scrollbar->setRange(0,slines);
624 scrollbar->setSteps(1,lines); 624 scrollbar->setSteps(1,lines);
625 scrollbar->setValue(cursor); 625 scrollbar->setValue(cursor);
626 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); 626 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
627} 627}
628 628
629void TEWidget::setScrollbarLocation(int loc) 629void TEWidget::setScrollbarLocation(int loc)
630{ 630{
631 if (scrollLoc == loc) return; // quickly 631 if (scrollLoc == loc) return; // quickly
632 scrollLoc = loc; 632 scrollLoc = loc;
633 propagateSize(); 633 propagateSize();
634 update(); 634 update();
635} 635}
636 636
637/* ------------------------------------------------------------------------- */ 637/* ------------------------------------------------------------------------- */
638/* */ 638/* */
639/* Mouse */ 639/* Mouse */
640/* */ 640/* */
641/* ------------------------------------------------------------------------- */ 641/* ------------------------------------------------------------------------- */
642 642
643/*! 643/*!
644 Three different operations can be performed using the mouse, and the 644 Three different operations can be performed using the mouse, and the
645 routines in this section serve all of them: 645 routines in this section serve all of them:
646 646
647 1) The press/release events are exposed to the application 647 1) The press/release events are exposed to the application
648 2) Marking (press and move left button) and Pasting (press middle button) 648 2) Marking (press and move left button) and Pasting (press middle button)
649 3) The right mouse button is used from the configuration menu 649 3) The right mouse button is used from the configuration menu
650 650
651 NOTE: During the marking process we attempt to keep the cursor within 651 NOTE: During the marking process we attempt to keep the cursor within
652 the bounds of the text as being displayed by setting the mouse position 652 the bounds of the text as being displayed by setting the mouse position
653 whenever the mouse has left the text area. 653 whenever the mouse has left the text area.
654 654
655 Two reasons to do so: 655 Two reasons to do so:
656 1) QT does not allow the `grabMouse' to confine-to the TEWidget. 656 1) QT does not allow the `grabMouse' to confine-to the TEWidget.
657 Thus a `XGrapPointer' would have to be used instead. 657 Thus a `XGrapPointer' would have to be used instead.
658 2) Even if so, this would not help too much, since the text area 658 2) Even if so, this would not help too much, since the text area
659 of the TEWidget is normally not identical with it's bounds. 659 of the TEWidget is normally not identical with it's bounds.
660 660
661 The disadvantage of the current handling is, that the mouse can visibly 661 The disadvantage of the current handling is, that the mouse can visibly
662 leave the bounds of the widget and is then moved back. Because of the 662 leave the bounds of the widget and is then moved back. Because of the
663 current construction, and the reasons mentioned above, we cannot do better 663 current construction, and the reasons mentioned above, we cannot do better
664 without changing the overall construction. 664 without changing the overall construction.
665*/ 665*/
666 666
667/*! 667/*!
668*/ 668*/
669 669
670void TEWidget::mousePressEvent(QMouseEvent* ev) 670void TEWidget::mousePressEvent(QMouseEvent* ev)
671{ 671{
672//printf("press [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); 672//printf("press [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button());
673 if ( !contentsRect().contains(ev->pos()) ) return; 673 if ( !contentsRect().contains(ev->pos()) ) return;
674 QPoint tL = contentsRect().topLeft(); 674 QPoint tL = contentsRect().topLeft();
675 int tLx = tL.x(); 675 int tLx = tL.x();
676 int tLy = tL.y(); 676 int tLy = tL.y();
677 677
678 mouse_down_x = ev->x(); 678 mouse_down_x = ev->x();
679 mouse_down_y = ev->y(); 679 mouse_down_y = ev->y();
680 680
681//printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY); 681//printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY);
682 if ( ev->button() == LeftButton) 682 if ( ev->button() == LeftButton)
683 { 683 {
684 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); 684 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
685 685
686 word_selection_mode = (ev->state() & ShiftButton); 686 word_selection_mode = (ev->state() & ShiftButton);
687 687
688 if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ; 688 if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ;
689 689
690 if (mouse_marks || (ev->state() & ShiftButton)) 690 if (mouse_marks || (ev->state() & ShiftButton))
691 { 691 {
692 emit clearSelectionSignal(); 692 emit clearSelectionSignal();
693 iPntSel = pntSel = pos; 693 iPntSel = pntSel = pos;
694 actSel = 1; // left mouse button pressed but nothing selected yet. 694 actSel = 1; // left mouse button pressed but nothing selected yet.
695 grabMouse( /*crossCursor*/ ); // handle with care! 695 grabMouse( /*crossCursor*/ ); // handle with care!
696 } 696 }
697 else 697 else
698 { 698 {
699 emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button 699 emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button
700 } 700 }
701 } 701 }
702 if ( ev->button() == MidButton ) 702 if ( ev->button() == MidButton )
703 { 703 {
704 emitSelection(); 704 emitSelection();
705 } 705 }
706 if ( ev->button() == RightButton ) // Configure 706 if ( ev->button() == RightButton ) // Configure
707 { 707 {
708 emit configureRequest( this, ev->state()&(ShiftButton|ControlButton), ev->x(), ev->y() ); 708 emit configureRequest( this, ev->state()&(ShiftButton|ControlButton), ev->x(), ev->y() );
709 } 709 }
710} 710}
711 711
712void TEWidget::mouseMoveEvent(QMouseEvent* ev) 712void TEWidget::mouseMoveEvent(QMouseEvent* ev)
713{ 713{
714 // for auto-hiding the cursor, we need mouseTracking 714 // for auto-hiding the cursor, we need mouseTracking
715 if (ev->state() == NoButton ) return; 715 if (ev->state() == NoButton ) return;
716 716
717 if (actSel == 0) return; 717 if (actSel == 0) return;
718 718
719 // don't extend selection while pasting 719 // don't extend selection while pasting
720 if (ev->state() & MidButton) return; 720 if (ev->state() & MidButton) return;
721 721
722 //if ( !contentsRect().contains(ev->pos()) ) return; 722 //if ( !contentsRect().contains(ev->pos()) ) return;
723 QPoint tL = contentsRect().topLeft(); 723 QPoint tL = contentsRect().topLeft();
724 int tLx = tL.x(); 724 int tLx = tL.x();
725 int tLy = tL.y(); 725 int tLy = tL.y();
726 int scroll = scrollbar->value(); 726 int scroll = scrollbar->value();
727// int hScroll = hScrollbar->value(); 727// int hScroll = hScrollbar->value();
728 728
729 // we're in the process of moving the mouse with the left button pressed 729 // we're in the process of moving the mouse with the left button pressed
730 // the mouse cursor will kept catched within the bounds of the text in 730 // the mouse cursor will kept catched within the bounds of the text in
731 // this widget. 731 // this widget.
732 732
733 // Adjust position within text area bounds. See FIXME above. 733 // Adjust position within text area bounds. See FIXME above.
734 QPoint pos = ev->pos(); 734 QPoint pos = ev->pos();
735 if ( pos.x() < tLx+blX ) pos.setX( tLx+blX ); 735 if ( pos.x() < tLx+blX ) pos.setX( tLx+blX );
736 if ( pos.x() > tLx+blX+columns*font_w-1 ) pos.setX( tLx+blX+columns*font_w ); 736 if ( pos.x() > tLx+blX+columns*font_w-1 ) pos.setX( tLx+blX+columns*font_w );
737 if ( pos.y() < tLy+bY ) pos.setY( tLy+bY ); 737 if ( pos.y() < tLy+bY ) pos.setY( tLy+bY );
738 if ( pos.y() > tLy+bY+lines*font_h-1 ) pos.setY( tLy+bY+lines*font_h-1 ); 738 if ( pos.y() > tLy+bY+lines*font_h-1 ) pos.setY( tLy+bY+lines*font_h-1 );
739 // check if we produce a mouse move event by this 739 // check if we produce a mouse move event by this
740 if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos)); 740 if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos));
741 741
742 if ( pos.y() == tLy+bY+lines*font_h-1 ) 742 if ( pos.y() == tLy+bY+lines*font_h-1 )
743 { 743 {
744 scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward 744 scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward
745 } 745 }
746 if ( pos.y() == tLy+bY ) 746 if ( pos.y() == tLy+bY )
747 { 747 {
748 scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback 748 scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback
749 } 749 }
750 750
751 QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h); 751 QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h);
752 QPoint ohere; 752 QPoint ohere;
753 bool swapping = FALSE; 753 bool swapping = FALSE;
754 754
755 if ( word_selection_mode ) 755 if ( word_selection_mode )
756 { 756 {
757 // Extend to word boundaries 757 // Extend to word boundaries
758 int i; 758 int i;
759 int selClass; 759 int selClass;
760 760
761 bool left_not_right = ( here.y() < iPntSel.y() || 761 bool left_not_right = ( here.y() < iPntSel.y() ||
762 here.y() == iPntSel.y() && here.x() < iPntSel.x() ); 762 here.y() == iPntSel.y() && here.x() < iPntSel.x() );
763 bool old_left_not_right = ( pntSel.y() < iPntSel.y() || 763 bool old_left_not_right = ( pntSel.y() < iPntSel.y() ||
764 pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() ); 764 pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() );
765 swapping = left_not_right != old_left_not_right; 765 swapping = left_not_right != old_left_not_right;
766 766
767 // Find left (left_not_right ? from here : from start) 767 // Find left (left_not_right ? from here : from start)
768 QPoint left = left_not_right ? here : iPntSel; 768 QPoint left = left_not_right ? here : iPntSel;
769 i = loc(left.x(),left.y()); 769 i = loc(left.x(),left.y());
770 selClass = charClass(image[i].c); 770 selClass = charClass(image[i].c);
771 while ( left.x() > 0 && charClass(image[i-1].c) == selClass ) 771 while ( left.x() > 0 && charClass(image[i-1].c) == selClass )
772 { i--; left.rx()--; } 772 { i--; left.rx()--; }
773 773
774 // Find left (left_not_right ? from start : from here) 774 // Find left (left_not_right ? from start : from here)
775 QPoint right = left_not_right ? iPntSel : here; 775 QPoint right = left_not_right ? iPntSel : here;
776 i = loc(right.x(),right.y()); 776 i = loc(right.x(),right.y());
777 selClass = charClass(image[i].c); 777 selClass = charClass(image[i].c);
778 while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass ) 778 while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass )
779 { i++; right.rx()++; } 779 { i++; right.rx()++; }
780 780
781 // Pick which is start (ohere) and which is extension (here) 781 // Pick which is start (ohere) and which is extension (here)
782 if ( left_not_right ) 782 if ( left_not_right )
783 { 783 {
784 here = left; ohere = right; 784 here = left; ohere = right;
785 } 785 }
786 else 786 else
787 { 787 {
788 here = right; ohere = left; 788 here = right; ohere = left;
789 } 789 }
790 } 790 }
791 791
792 if (here == pntSel && scroll == scrollbar->value()) return; // not moved 792 if (here == pntSel && scroll == scrollbar->value()) return; // not moved
793 793
794 if ( word_selection_mode ) { 794 if ( word_selection_mode ) {
795 if ( actSel < 2 || swapping ) { 795 if ( actSel < 2 || swapping ) {
796 emit beginSelectionSignal( ohere.x(), ohere.y() ); 796 emit beginSelectionSignal( ohere.x(), ohere.y() );
797 } 797 }
798 } else if ( actSel < 2 ) { 798 } else if ( actSel < 2 ) {
799 emit beginSelectionSignal( pntSel.x(), pntSel.y() ); 799 emit beginSelectionSignal( pntSel.x(), pntSel.y() );
800 } 800 }
801 801
802 actSel = 2; // within selection 802 actSel = 2; // within selection
803 pntSel = here; 803 pntSel = here;
804 emit extendSelectionSignal( here.x(), here.y() ); 804 emit extendSelectionSignal( here.x(), here.y() );
805} 805}
806 806
807void TEWidget::mouseReleaseEvent(QMouseEvent* ev) 807void TEWidget::mouseReleaseEvent(QMouseEvent* ev)
808{ 808{
809//printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); 809//printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button());
810 if ( ev->button() == LeftButton) 810 if ( ev->button() == LeftButton)
811 { 811 {
812 if (QABS(ev->x() - mouse_down_x) < 3 812 if (QABS(ev->x() - mouse_down_x) < 3
813 && QABS(ev->y() - mouse_down_y) < 3 813 && QABS(ev->y() - mouse_down_y) < 3
814 && ev->y() < qApp->desktop()->height()/8) { 814 && ev->y() < qApp->desktop()->height()/8) {
815 emit setFullScreen(false); 815 emit setFullScreen(false);
816 } 816 }
817 817
818 if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks); 818 if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks);
819 preserve_line_breaks = TRUE; 819 preserve_line_breaks = TRUE;
820 actSel = 0; 820 actSel = 0;
821 821
822 //FIXME: emits a release event even if the mouse is 822 //FIXME: emits a release event even if the mouse is
823 // outside the range. The procedure used in `mouseMoveEvent' 823 // outside the range. The procedure used in `mouseMoveEvent'
824 // applies here, too. 824 // applies here, too.
825 825
826 QPoint tL = contentsRect().topLeft(); 826 QPoint tL = contentsRect().topLeft();
827 int tLx = tL.x(); 827 int tLx = tL.x();
828 int tLy = tL.y(); 828 int tLy = tL.y();
829 829
830 if (!mouse_marks && !(ev->state() & ShiftButton)) 830 if (!mouse_marks && !(ev->state() & ShiftButton))
831 emit mouseSignal( 3, // release 831 emit mouseSignal( 3, // release
832 (ev->x()-tLx-blX)/font_w + 1, 832 (ev->x()-tLx-blX)/font_w + 1,
833 (ev->y()-tLy-bY)/font_h + 1 ); 833 (ev->y()-tLy-bY)/font_h + 1 );
834 releaseMouse(); 834 releaseMouse();
835 } 835 }
836} 836}
837 837
838void TEWidget::mouseDoubleClickEvent(QMouseEvent* ev) 838void TEWidget::mouseDoubleClickEvent(QMouseEvent* ev)
839{ 839{
840 if ( ev->button() != LeftButton) return; 840 if ( ev->button() != LeftButton) return;
841 841
842 QPoint tL = contentsRect().topLeft(); 842 QPoint tL = contentsRect().topLeft();
843 int tLx = tL.x(); 843 int tLx = tL.x();
844 int tLy = tL.y(); 844 int tLy = tL.y();
845 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); 845 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
846 846
847 // pass on double click as two clicks. 847 // pass on double click as two clicks.
848 if (!mouse_marks && !(ev->state() & ShiftButton)) 848 if (!mouse_marks && !(ev->state() & ShiftButton))
849 { 849 {
850 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button 850 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button
851 emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release 851 emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release
852 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button 852 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button
853 return; 853 return;
854 } 854 }
855 855
856 856
857 emit clearSelectionSignal(); 857 emit clearSelectionSignal();
858 QPoint bgnSel = pos; 858 QPoint bgnSel = pos;
859 QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); 859 QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
860 int i = loc(bgnSel.x(),bgnSel.y()); 860 int i = loc(bgnSel.x(),bgnSel.y());
861 iPntSel = bgnSel; 861 iPntSel = bgnSel;
862 862
863 word_selection_mode = TRUE; 863 word_selection_mode = TRUE;
864 864
865 // find word boundaries... 865 // find word boundaries...
866 int selClass = charClass(image[i].c); 866 int selClass = charClass(image[i].c);
867 { 867 {
868 // set the start... 868 // set the start...
869 int x = bgnSel.x(); 869 int x = bgnSel.x();
870 while ( x > 0 && charClass(image[i-1].c) == selClass ) 870 while ( x > 0 && charClass(image[i-1].c) == selClass )
871 { i--; x--; } 871 { i--; x--; }
872 bgnSel.setX(x); 872 bgnSel.setX(x);
873 emit beginSelectionSignal( bgnSel.x(), bgnSel.y() ); 873 emit beginSelectionSignal( bgnSel.x(), bgnSel.y() );
874 874
875 // set the end... 875 // set the end...
876 i = loc( endSel.x(), endSel.y() ); 876 i = loc( endSel.x(), endSel.y() );
877 x = endSel.x(); 877 x = endSel.x();
878 while( x < columns-1 && charClass(image[i+1].c) == selClass ) 878 while( x < columns-1 && charClass(image[i+1].c) == selClass )
879 { i++; x++ ; } 879 { i++; x++ ; }
880 endSel.setX(x); 880 endSel.setX(x);
881 actSel = 2; // within selection 881 actSel = 2; // within selection
882 emit extendSelectionSignal( endSel.x(), endSel.y() ); 882 emit extendSelectionSignal( endSel.x(), endSel.y() );
883 emit endSelectionSignal(preserve_line_breaks); 883 emit endSelectionSignal(preserve_line_breaks);
884 preserve_line_breaks = TRUE; 884 preserve_line_breaks = TRUE;
885 } 885 }
886} 886}
887 887
888void TEWidget::focusInEvent( QFocusEvent * ) 888void TEWidget::focusInEvent( QFocusEvent * )
889{ 889{
890 890
891 // do nothing, to prevent repainting 891 // do nothing, to prevent repainting
892} 892}
893 893
894 894
895void TEWidget::focusOutEvent( QFocusEvent * ) 895void TEWidget::focusOutEvent( QFocusEvent * )
896{ 896{
897 // do nothing, to prevent repainting 897 // do nothing, to prevent repainting
898} 898}
899 899
900bool TEWidget::focusNextPrevChild( bool next ) 900bool TEWidget::focusNextPrevChild( bool next )
901{ 901{
902 if (next) 902 if (next)
903 return false; // This disables changing the active part in konqueror 903 return false; // This disables changing the active part in konqueror
904 // when pressing Tab 904 // when pressing Tab
905 return QFrame::focusNextPrevChild( next ); 905 return QFrame::focusNextPrevChild( next );
906} 906}
907 907
908 908
909int TEWidget::charClass(char ch) const 909int TEWidget::charClass(char ch) const
910{ 910{
911 // This might seem like overkill, but imagine if ch was a Unicode 911 // This might seem like overkill, but imagine if ch was a Unicode
912 // character (Qt 2.0 QChar) - it might then be sensible to separate 912 // character (Qt 2.0 QChar) - it might then be sensible to separate
913 // the different language ranges, etc. 913 // the different language ranges, etc.
914 914
915 if ( isspace(ch) ) return ' '; 915 if ( isspace(ch) ) return ' ';
916 916
917 static const char *word_characters = ":@-./_~"; 917 static const char *word_characters = ":@-./_~";
918 if ( isalnum(ch) || strchr(word_characters, ch) ) 918 if ( isalnum(ch) || strchr(word_characters, ch) )
919 return 'a'; 919 return 'a';
920 920
921 // Everything else is weird 921 // Everything else is weird
922 return 1; 922 return 1;
923} 923}
924 924
925void TEWidget::setMouseMarks(bool on) 925void TEWidget::setMouseMarks(bool on)
926{ 926{
927 mouse_marks = on; 927 mouse_marks = on;
928 setCursor( mouse_marks ? ibeamCursor : arrowCursor ); 928 setCursor( mouse_marks ? ibeamCursor : arrowCursor );
929} 929}
930 930
931/* ------------------------------------------------------------------------- */ 931/* ------------------------------------------------------------------------- */
932/* */ 932/* */
933/* Clipboard */ 933/* Clipboard */
934/* */ 934/* */
935/* ------------------------------------------------------------------------- */ 935/* ------------------------------------------------------------------------- */
936 936
937#undef KeyPress 937#undef KeyPress
938 938
939void TEWidget::emitSelection() 939void TEWidget::emitSelection()
940// Paste Clipboard by simulating keypress events 940// Paste Clipboard by simulating keypress events
941{ 941{
942#ifndef QT_NO_CLIPBOARD 942#ifndef QT_NO_CLIPBOARD
943 QString text = QApplication::clipboard()->text(); 943 QString text = QApplication::clipboard()->text();
944 //odebug << text << oendl; 944 //odebug << text << oendl;
945 if ( ! text.isNull()) 945 if ( ! text.isNull())
946 { 946 {
947 text.replace(QRegExp("\n"), "\r"); 947 text.replace(QRegExp("\n"), "\r");
948 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); 948 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text);
949 emit keyPressedSignal(&e); // expose as a big fat keypress event 949 emit keyPressedSignal(&e); // expose as a big fat keypress event
950 emit clearSelectionSignal(); 950 emit clearSelectionSignal();
951 } 951 }
952#endif 952#endif
953} 953}
954 954
955void TEWidget::emitText(QString text) 955void TEWidget::emitText(QString text)
956{ 956{
957 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); 957 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text);
958 emit keyPressedSignal(&e); // expose as a big fat keypress event 958 emit keyPressedSignal(&e); // expose as a big fat keypress event
959} 959}
960 960
961void TEWidget::pasteClipboard( ) 961void TEWidget::pasteClipboard( )
962{ 962{
963 emitSelection(); 963 emitSelection();
964} 964}
965 965
966void TEWidget::setSelection(const QString& t) 966void TEWidget::setSelection(const QString& t)
967{ 967{
968#ifndef QT_NO_CLIPBOARD 968#ifndef QT_NO_CLIPBOARD
969 // Disconnect signal while WE set the clipboard 969 // Disconnect signal while WE set the clipboard
970 QObject *cb = QApplication::clipboard(); 970 QObject *cb = QApplication::clipboard();
971 QObject::disconnect( cb, SIGNAL(dataChanged()), 971 QObject::disconnect( cb, SIGNAL(dataChanged()),
972 this, SLOT(onClearSelection()) ); 972 this, SLOT(onClearSelection()) );
973 973
974 QApplication::clipboard()->setText(t); 974 QApplication::clipboard()->setText(t);
975 975
976 QObject::connect( cb, SIGNAL(dataChanged()), 976 QObject::connect( cb, SIGNAL(dataChanged()),
977 this, SLOT(onClearSelection()) ); 977 this, SLOT(onClearSelection()) );
978#endif 978#endif
979} 979}
980 980
981void TEWidget::onClearSelection() 981void TEWidget::onClearSelection()
982{ 982{
983 emit clearSelectionSignal(); 983 emit clearSelectionSignal();
984} 984}
985 985
986/* ------------------------------------------------------------------------- */ 986/* ------------------------------------------------------------------------- */
987/* */ 987/* */
988/* Keyboard */ 988/* Keyboard */
989/* */ 989/* */
990/* ------------------------------------------------------------------------- */ 990/* ------------------------------------------------------------------------- */
991 991
992//FIXME: an `eventFilter' has been installed instead of a `keyPressEvent' 992//FIXME: an `eventFilter' has been installed instead of a `keyPressEvent'
993// 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
994// repaint events being emitted to the screen whenever one leaves 994// repaint events being emitted to the screen whenever one leaves
995// or reenters the screen to/from another application. 995// or reenters the screen to/from another application.
996// 996//
997// Troll says one needs to change focusInEvent() and focusOutEvent(), 997// Troll says one needs to change focusInEvent() and focusOutEvent(),
998// 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
999// cursor like xterm does. 999// cursor like xterm does.
1000 1000
1001// for the auto-hide cursor feature, I added empty focusInEvent() and 1001// for the auto-hide cursor feature, I added empty focusInEvent() and
1002// focusOutEvent() so that update() isn't called. 1002// focusOutEvent() so that update() isn't called.
1003// 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
1004// we have focus. 1004// we have focus.
1005 1005
1006void TEWidget::doScroll(int lines) 1006void TEWidget::doScroll(int lines)
1007{ 1007{
1008 scrollbar->setValue(scrollbar->value()+lines); 1008 scrollbar->setValue(scrollbar->value()+lines);
1009} 1009}
1010 1010
1011void TEWidget::doHScroll(int lines) { 1011void TEWidget::doHScroll(int lines) {
1012 hScrollbar->setValue( hScrollbar->value()+lines); 1012 hScrollbar->setValue( hScrollbar->value()+lines);
1013} 1013}
1014 1014
1015bool TEWidget::eventFilter( QObject *obj, QEvent *e ) 1015bool TEWidget::eventFilter( QObject *obj, QEvent *e )
1016{ 1016{
1017 if ( (e->type() == QEvent::Accel || 1017 if ( (e->type() == QEvent::Accel ||
1018 e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) { 1018 e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) {
1019 static_cast<QKeyEvent *>( e )->ignore(); 1019 static_cast<QKeyEvent *>( e )->ignore();
1020 return true; 1020 return true;
1021 } 1021 }
1022 if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) 1022 if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ )
1023 return FALSE; // not us 1023 return FALSE; // not us
1024 if ( e->type() == QEvent::Wheel) { 1024 if ( e->type() == QEvent::Wheel) {
1025 QApplication::sendEvent(scrollbar, e); 1025 QApplication::sendEvent(scrollbar, e);
1026 } 1026 }
1027 1027
1028#ifdef FAKE_CTRL_AND_ALT 1028#ifdef FAKE_CTRL_AND_ALT
1029 static bool control = FALSE; 1029 static bool control = FALSE;
1030 static bool alt = FALSE; 1030 static bool alt = FALSE;
1031// odebug << " Has a keyboard with no CTRL and ALT keys, but we fake it:" << oendl; 1031// odebug << " Has a keyboard with no CTRL and ALT keys, but we fake it:" << oendl;
1032 bool dele=FALSE; 1032 bool dele=FALSE;
1033 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 1033 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
1034 QKeyEvent* ke = (QKeyEvent*)e; 1034 QKeyEvent* ke = (QKeyEvent*)e;
1035 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); 1035 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat();
1036 switch (ke->key()) { 1036 switch (ke->key()) {
1037 case Key_F9: // let this be "Control" 1037 case Key_F9: // let this be "Control"
1038 control = keydown; 1038 control = keydown;
1039 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); 1039 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state());
1040 dele=TRUE; 1040 dele=TRUE;
1041 break; 1041 break;
1042 case Key_F13: // let this be "Alt" 1042 case Key_F13: // let this be "Alt"
1043 alt = keydown; 1043 alt = keydown;
1044 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); 1044 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state());
1045 dele=TRUE; 1045 dele=TRUE;
1046 break; 1046 break;
1047 default: 1047 default:
1048 if ( control ) { 1048 if ( control ) {
1049 int a = toupper(ke->ascii())-64; 1049 int a = toupper(ke->ascii())-64;
1050 if ( a >= 0 && a < ' ' ) { 1050 if ( a >= 0 && a < ' ' ) {
1051 e = new QKeyEvent(e->type(), ke->key(), 1051 e = new QKeyEvent(e->type(), ke->key(),
1052 a, ke->state()|ControlButton, QChar(a,0)); 1052 a, ke->state()|ControlButton, QChar(a,0));
1053 dele=TRUE; 1053 dele=TRUE;
1054 } 1054 }
1055 } 1055 }
1056 if ( alt ) { 1056 if ( alt ) {
1057 e = new QKeyEvent(e->type(), ke->key(), 1057 e = new QKeyEvent(e->type(), ke->key(),
1058 ke->ascii(), ke->state()|AltButton, ke->text()); 1058 ke->ascii(), ke->state()|AltButton, ke->text());
1059 dele=TRUE; 1059 dele=TRUE;
1060 } 1060 }
1061 } 1061 }
1062 } 1062 }
1063#endif 1063#endif
1064 1064
1065 if ( e->type() == QEvent::KeyPress ) { 1065 if ( e->type() == QEvent::KeyPress ) {
1066 QKeyEvent* ke = (QKeyEvent*)e; 1066 QKeyEvent* ke = (QKeyEvent*)e;
1067 actSel=0; // Key stroke implies a screen update, so TEWidget won't 1067 actSel=0; // Key stroke implies a screen update, so TEWidget won't
1068 // know where the current selection is. 1068 // know where the current selection is.
1069 1069
1070// odebug << "key pressed is 0x" << ke->key() << ", ascii is 0x" << ke->ascii() << ", state " << ke->state() << "" << oendl; 1070// odebug << "key pressed is 0x" << ke->key() << ", ascii is 0x" << ke->ascii() << ", state " << ke->state() << "" << oendl;
1071 1071
1072 bool special_function = true; 1072 bool special_function = true;
1073 switch(ke->key()) { 1073 switch(ke->key()) {
1074 //case 0x201b: // fn-5 1074 //case 0x201b: // fn-5
1075 //case Key_F1: 1075 //case Key_F1:
1076 // switch sessions (?) 1076 // switch sessions (?)
1077 // emitText("\\"); // expose (??) 1077 // emitText("\\"); // expose (??)
1078 // break; 1078 // break;
1079 1079
1080 case 0x2016: // fn-p 1080 case 0x2016: // fn-p
1081 case Key_F2: 1081 case Key_F2:
1082 pasteClipboard(); 1082 pasteClipboard();
1083 break; 1083 break;
1084 1084
1085 case 0x2018: // fn-S 1085 case 0x2018: // fn-S
1086 case Key_F3: 1086 case Key_F3:
1087 emit changeSession(1); 1087 emit changeSession(1);
1088 break; 1088 break;
1089 1089
1090 case 0x2019: // fn-n 1090 case 0x2019: // fn-n
1091 emit newSession(); 1091 emit newSession();
1092 break; 1092 break;
1093 1093
1094 case Qt::Key_Tab: 1094 case Qt::Key_Tab:
1095 if (ke->state() == ControlButton) { 1095 if (ke->state() == ControlButton) {
1096 emit changeSession(1); 1096 emit changeSession(1);
1097 } else { 1097 } else {
1098 special_function = false; 1098 special_function = false;
1099 } 1099 }
1100 break; 1100 break;
1101 1101
1102#if 0 1102#if 0
1103 case Qt::Key_Left: 1103 case Qt::Key_Left:
1104 if (vcolumns == 0) { 1104 if (vcolumns == 0) {
1105 emit changeSession(-1); 1105 emit changeSession(-1);
1106 } else { 1106 } else {
1107 special_function = false; 1107 special_function = false;
1108 } 1108 }
1109 break; 1109 break;
1110 1110
1111 case Qt::Key_Right: 1111 case Qt::Key_Right:
1112 if (vcolumns == 0) { 1112 if (vcolumns == 0) {
1113 emit changeSession(1); 1113 emit changeSession(1);
1114 } else { 1114 } else {
1115 special_function = false; 1115 special_function = false;
1116 } 1116 }
1117 break; 1117 break;
1118#endif 1118#endif
1119 1119
1120 case 0x201b: // fn-5 1120 case 0x201b: // fn-5
1121 case Key_F4: 1121 case Key_F4:
1122 emit toggleFullScreen(); 1122 emit toggleFullScreen();
1123 break; 1123 break;
1124 1124
1125 case 0x200f: // fn-1 magnify minus 1125 case 0x200f: // fn-1 magnify minus
1126 case Key_F5: 1126 case Key_F5:
1127 emit changeFontSize(-1); 1127 emit changeFontSize(-1);
1128 break; 1128 break;
1129 1129
1130 case 0x2010: // fn-2 magnify plus 1130 case 0x2010: // fn-2 magnify plus
1131 case Key_F6: 1131 case Key_F6:
1132 emit changeFontSize(1); 1132 emit changeFontSize(1);
1133 break; 1133 break;
1134 1134
1135 default: 1135 default:
1136 special_function = false; 1136 special_function = false;
1137 } 1137 }
1138 if (special_function) { 1138 if (special_function) {
1139 return true; 1139 return true;
1140 } 1140 }
1141 // else if( ke->state() == ControlButton && ke->key() == Key_V) { 1141 // else if( ke->state() == ControlButton && ke->key() == Key_V) {
1142 // pasteClipboard(); 1142 // pasteClipboard();
1143 // } 1143 // }
1144 // else if( ke->state() == ControlButton && ke->key() == Key_C) { 1144 // else if( ke->state() == ControlButton && ke->key() == Key_C) {
1145 // pasteClipboard(); 1145 // pasteClipboard();
1146 // } 1146 // }
1147 emit keyPressedSignal(ke); // expose 1147 emit keyPressedSignal(ke); // expose
1148 ke->accept(); 1148 ke->accept();
1149#ifdef FAKE_CTRL_AND_ALT 1149#ifdef FAKE_CTRL_AND_ALT
1150 if ( dele ) delete e; 1150 if ( dele ) delete e;
1151#endif 1151#endif
1152 return true; // stop the event 1152 return true; // stop the event
1153 } 1153 }
1154 if ( e->type() == QEvent::Enter ) { 1154 if ( e->type() == QEvent::Enter ) {
1155 QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()), 1155 QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()),
1156 this, SLOT(onClearSelection()) ); 1156 this, SLOT(onClearSelection()) );
1157 } 1157 }
1158 if ( e->type() == QEvent::Leave ) { 1158 if ( e->type() == QEvent::Leave ) {
1159 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), 1159 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()),
1160 this, SLOT(onClearSelection()) ); 1160 this, SLOT(onClearSelection()) );
1161 } 1161 }
1162 return QFrame::eventFilter( obj, e ); 1162 return QFrame::eventFilter( obj, e );
1163} 1163}
1164 1164
1165/* ------------------------------------------------------------------------- */ 1165/* ------------------------------------------------------------------------- */
1166/* */ 1166/* */
1167/* Frame */ 1167/* Frame */
1168/* */ 1168/* */
1169/* ------------------------------------------------------------------------- */ 1169/* ------------------------------------------------------------------------- */
1170 1170
1171void TEWidget::frameChanged() 1171void TEWidget::frameChanged()
1172{ 1172{
1173 propagateSize(); 1173 propagateSize();
1174 update(); 1174 update();
1175} 1175}
1176/* ------------------------------------------------------------------------- */ 1176/* ------------------------------------------------------------------------- */
1177/* */ 1177/* */
1178/* Sound */ 1178/* Sound */
1179/* */ 1179/* */
1180/* ------------------------------------------------------------------------- */ 1180/* ------------------------------------------------------------------------- */
1181 1181
1182void TEWidget::Bell() 1182void TEWidget::Bell()
1183{ 1183{
1184//#ifdef QT_QWS_SL5XXX 1184//#ifdef QT_QWS_SL5XXX
1185//# ifndef QT_NO_COP 1185//# ifndef QT_NO_COP
1186 if(useBeep) 1186 if(useBeep)
1187 QCopEnvelope( "QPE/TaskBar", "soundAlarm()" ); 1187 QCopEnvelope( "QPE/TaskBar", "soundAlarm()" );
1188 1188
1189//# endif 1189//# endif
1190//#else 1190//#else
1191//# ifndef QT_NO_SOUND 1191//# ifndef QT_NO_SOUND
1192// QSound::play(Resource::findSound("alarm")); 1192// QSound::play(Resource::findSound("alarm"));
1193//# endif 1193//# endif
1194//#endif 1194//#endif
1195 1195
1196// QApplication::beep(); 1196// QApplication::beep();
1197} 1197}
1198 1198
1199/* ------------------------------------------------------------------------- */ 1199/* ------------------------------------------------------------------------- */
1200/* */ 1200/* */
1201/* Auxiluary */ 1201/* Auxiluary */
1202/* */ 1202/* */
1203/* ------------------------------------------------------------------------- */ 1203/* ------------------------------------------------------------------------- */
1204 1204
1205void TEWidget::clearImage() 1205void TEWidget::clearImage()
1206// initialize the image 1206// initialize the image
1207// for internal use only 1207// for internal use only
1208{ 1208{
1209 for (int y = 0; y < lines; y++) 1209 for (int y = 0; y < lines; y++)
1210 for (int x = 0; x < columns; x++) 1210 for (int x = 0; x < columns; x++)
1211 { 1211 {
1212 image[loc(x,y)].c = 0xff; //' '; 1212 image[loc(x,y)].c = 0xff; //' ';
1213 image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR; 1213 image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR;
1214 image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR; 1214 image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR;
1215 image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION; 1215 image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION;
1216 } 1216 }
1217} 1217}
1218 1218
1219// Create Image /////////////////////////////////////////////////////// 1219// Create Image ///////////////////////////////////////////////////////
1220 1220
1221void TEWidget::calcGeometry() 1221void TEWidget::calcGeometry()
1222{ 1222{
1223 int showhscrollbar = 1; 1223 int showhscrollbar = 1;
1224 int hwidth = 0; 1224 int hwidth = 0;
1225 int dcolumns = 0; 1225 int dcolumns = 0;
1226 Config cfg( "Konsole" ); 1226 Config cfg( "Konsole" );
1227 cfg.setGroup("ScrollBar"); 1227 cfg.setGroup("ScrollBar");
1228 useHorzScroll=cfg.readBoolEntry("HorzScroll",0); 1228 useHorzScroll=cfg.readBoolEntry("HorzScroll",0);
1229 1229
1230 if(vcolumns == 0) showhscrollbar = 0; 1230 if(vcolumns == 0) showhscrollbar = 0;
1231 if(showhscrollbar == 1) hwidth = QApplication::style().scrollBarExtent().width(); 1231 if(showhscrollbar == 1) hwidth = QApplication::style().scrollBarExtent().width();
1232 1232
1233 scrollbar->resize(QApplication::style().scrollBarExtent().width(), 1233 scrollbar->resize(QApplication::style().scrollBarExtent().width(),
1234 contentsRect().height() - hwidth); 1234 contentsRect().height() - hwidth);
1235 1235
1236 switch(scrollLoc) { 1236 switch(scrollLoc) {
1237 case SCRNONE : 1237 case SCRNONE :
1238 columns = ( contentsRect().width() - 2 * rimX ) / font_w; 1238 columns = ( contentsRect().width() - 2 * rimX ) / font_w;
1239 dcolumns = columns; 1239 dcolumns = columns;
1240 if(vcolumns) columns = vcolumns; 1240 if(vcolumns) columns = vcolumns;
1241 blX = (contentsRect().width() - (columns*font_w) ) / 2; 1241 blX = (contentsRect().width() - (columns*font_w) ) / 2;
1242 if(showhscrollbar) 1242 if(showhscrollbar)
1243 blX = -hposition * font_w; 1243 blX = -hposition * font_w;
1244 brX = blX; 1244 brX = blX;
1245 scrollbar->hide(); 1245 scrollbar->hide();
1246 break; 1246 break;
1247 case SCRLEFT : 1247 case SCRLEFT :
1248 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; 1248 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w;
1249 dcolumns = columns; 1249 dcolumns = columns;
1250 if(vcolumns) columns = vcolumns; 1250 if(vcolumns) columns = vcolumns;
1251 brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; 1251 brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2;
1252 if(showhscrollbar) 1252 if(showhscrollbar)
1253 brX = -hposition * font_w; 1253 brX = -hposition * font_w;
1254 blX = brX + scrollbar->width(); 1254 blX = brX + scrollbar->width();
1255 scrollbar->move(contentsRect().topLeft()); 1255 scrollbar->move(contentsRect().topLeft());
1256 scrollbar->show(); 1256 scrollbar->show();
1257 break; 1257 break;
1258 case SCRRIGHT: 1258 case SCRRIGHT:
1259 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; 1259 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w;
1260 dcolumns = columns; 1260 dcolumns = columns;
1261 if(vcolumns) columns = vcolumns; 1261 if(vcolumns) columns = vcolumns;
1262 blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; 1262 blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2;
1263 if(showhscrollbar) 1263 if(showhscrollbar)
1264 blX = -hposition * font_w; 1264 blX = -hposition * font_w;
1265 brX = blX; 1265 brX = blX;
1266 scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0)); 1266 scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0));
1267 scrollbar->show(); 1267 scrollbar->show();
1268 break; 1268 break;
1269 } 1269 }
1270 //FIXME: support 'rounding' styles 1270 //FIXME: support 'rounding' styles
1271 lines = ( contentsRect().height() - 2 * rimY ) / font_h; 1271 lines = ( contentsRect().height() - 2 * rimY ) / font_h;
1272 bY = (contentsRect().height() - (lines *font_h)) / 2; 1272 bY = (contentsRect().height() - (lines *font_h)) / 2;
1273 1273
1274 if(showhscrollbar == 1) { 1274 if(showhscrollbar == 1) {
1275 hScrollbar->resize(contentsRect().width() - hwidth, hwidth); 1275 hScrollbar->resize(contentsRect().width() - hwidth, hwidth);
1276 hScrollbar->setRange(0, vcolumns - dcolumns); 1276 hScrollbar->setRange(0, vcolumns - dcolumns);
1277 1277
1278 QPoint p = contentsRect().bottomLeft(); 1278 QPoint p = contentsRect().bottomLeft();
1279 if(scrollLoc == SCRLEFT) 1279 if(scrollLoc == SCRLEFT)
1280 hScrollbar->move(QPoint(p.x()+hwidth, p.y() - hwidth)); 1280 hScrollbar->move(QPoint(p.x()+hwidth, p.y() - hwidth));
1281 else 1281 else
1282 hScrollbar->move(QPoint(p.x(), p.y() - hwidth)); 1282 hScrollbar->move(QPoint(p.x(), p.y() - hwidth));
1283 1283
1284 hScrollbar->show(); 1284 hScrollbar->show();
1285 } 1285 }
1286 else hScrollbar->hide(); 1286 else hScrollbar->hide();
1287 1287
1288 if(showhscrollbar == 1) { 1288 if(showhscrollbar == 1) {
1289 lines = lines - (hwidth / font_h) - 1; 1289 lines = lines - (hwidth / font_h) - 1;
1290 if(lines < 1) lines = 1; 1290 if(lines < 1) lines = 1;
1291 } 1291 }
1292 //FIXME: support 'rounding' styles 1292 //FIXME: support 'rounding' styles
1293} 1293}
1294 1294
1295void TEWidget::makeImage() 1295void TEWidget::makeImage()
1296//FIXME: rename 'calcGeometry? 1296//FIXME: rename 'calcGeometry?
1297{ 1297{
1298 calcGeometry(); 1298 calcGeometry();
1299 image = (ca*) malloc(lines*columns*sizeof(ca)); 1299 image = (ca*) malloc(lines*columns*sizeof(ca));
1300 clearImage(); 1300 clearImage();
1301} 1301}
1302 1302
1303// calculate the needed size 1303// calculate the needed size
1304QSize TEWidget::calcSize(int cols, int lins) const 1304QSize TEWidget::calcSize(int cols, int lins) const
1305{ 1305{
1306 int frw = width() - contentsRect().width(); 1306 int frw = width() - contentsRect().width();
1307 int frh = height() - contentsRect().height(); 1307 int frh = height() - contentsRect().height();
1308 int scw = (scrollLoc==SCRNONE?0:scrollbar->width()); 1308 int scw = (scrollLoc==SCRNONE?0:scrollbar->width());
1309 return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh ); 1309 return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh );
1310} 1310}
1311 1311
1312QSize TEWidget::sizeHint() const 1312QSize TEWidget::sizeHint() const
1313{ 1313{
1314 return size(); 1314 return size();
1315} 1315}
1316 1316
1317void TEWidget::styleChange(QStyle &) 1317void TEWidget::styleChange(QStyle &)
1318{ 1318{
1319 propagateSize(); 1319 propagateSize();
1320} 1320}
1321 1321
1322#ifndef QT_NO_DRAGANDDROP 1322#ifndef QT_NO_DRAGANDDROP
1323 1323
1324/* --------------------------------------------------------------------- */ 1324/* --------------------------------------------------------------------- */
1325/* */ 1325/* */
1326/* Drag & Drop */ 1326/* Drag & Drop */
1327/* */ 1327/* */
1328/* --------------------------------------------------------------------- */ 1328/* --------------------------------------------------------------------- */
1329 1329
1330 1330
1331void TEWidget::dragEnterEvent(QDragEnterEvent* e) 1331void TEWidget::dragEnterEvent(QDragEnterEvent* e)
1332{ 1332{
1333 e->accept(QTextDrag::canDecode(e) || 1333 e->accept(QTextDrag::canDecode(e) ||
1334 QUriDrag::canDecode(e)); 1334 QUriDrag::canDecode(e));
1335} 1335}
1336 1336
1337void TEWidget::dropEvent(QDropEvent* event) 1337void TEWidget::dropEvent(QDropEvent* event)
1338{ 1338{
1339 // The current behaviour when url(s) are dropped is 1339 // The current behaviour when url(s) are dropped is
1340 // * if there is only ONE url and if it's a LOCAL one, ask for paste or cd 1340 // * if there is only ONE url and if it's a LOCAL one, ask for paste or cd
1341 // * in all other cases, just paste 1341 // * in all other cases, just paste
1342 // (for non-local ones, or for a list of URLs, 'cd' is nonsense) 1342 // (for non-local ones, or for a list of URLs, 'cd' is nonsense)
1343 QStrList strlist; 1343 QStrList strlist;
1344 int file_count = 0; 1344 int file_count = 0;
1345 dropText = ""; 1345 dropText = "";
1346 bool bPopup = true; 1346 bool bPopup = true;
1347 1347
1348 if(QUriDrag::decode(event, strlist)) { 1348 if(QUriDrag::decode(event, strlist)) {
1349 if (strlist.count()) { 1349 if (strlist.count()) {
1350 for(const char* p = strlist.first(); p; p = strlist.next()) { 1350 for(const char* p = strlist.first(); p; p = strlist.next()) {
1351 if(file_count++ > 0) { 1351 if(file_count++ > 0) {
1352 dropText += " "; 1352 dropText += " ";
1353 bPopup = false; // more than one file, don't popup 1353 bPopup = false; // more than one file, don't popup
1354 } 1354 }
1355 1355
1356/* 1356/*
1357 KURL url(p); 1357 KURL url(p);
1358 if (url.isLocalFile()) { 1358 if (url.isLocalFile()) {
1359 dropText += url.path(); // local URL : remove protocol 1359 dropText += url.path(); // local URL : remove protocol
1360 } 1360 }
1361 else { 1361 else {
1362 dropText += url.prettyURL(); 1362 dropText += url.prettyURL();
1363 bPopup = false; // a non-local file, don't popup 1363 bPopup = false; // a non-local file, don't popup
1364 } 1364 }
1365*/ 1365*/
1366 1366
1367 } 1367 }
1368 1368
1369 if (bPopup) 1369 if (bPopup)
1370 // m_drop->popup(pos() + event->pos()); 1370 // m_drop->popup(pos() + event->pos());
1371 m_drop->popup(mapToGlobal(event->pos())); 1371 m_drop->popup(mapToGlobal(event->pos()));
1372 else 1372 else
1373 { 1373 {
1374 if (currentSession) { 1374 if (currentSession) {
1375 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1375 currentSession->getEmulation()->sendString(dropText.local8Bit());
1376 } 1376 }
1377// kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; 1377// kdDebug() << "Drop:" << dropText.local8Bit() << "\n";
1378 } 1378 }
1379 } 1379 }
1380 } 1380 }
1381 else if(QTextDrag::decode(event, dropText)) { 1381 else if(QTextDrag::decode(event, dropText)) {
1382// kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; 1382// kdDebug() << "Drop:" << dropText.local8Bit() << "\n";
1383 if (currentSession) { 1383 if (currentSession) {
1384 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1384 currentSession->getEmulation()->sendString(dropText.local8Bit());
1385 } 1385 }
1386 // Paste it 1386 // Paste it
1387 } 1387 }
1388} 1388}
1389#endif 1389#endif
1390 1390
1391 1391
1392void TEWidget::drop_menu_activated(int /*item*/) 1392void TEWidget::drop_menu_activated(int item)
1393{ 1393{
1394#ifndef QT_NO_DRAGANDDROP 1394#ifndef QT_NO_DRAGANDDROP
1395 switch (item) 1395 switch (item)
1396 { 1396 {
1397 case 0: // paste 1397 case 0: // paste
1398 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1398 currentSession->getEmulation()->sendString(dropText.local8Bit());
1399// KWM::activate((Window)this->winId()); 1399// KWM::activate((Window)this->winId());
1400 break; 1400 break;
1401 case 1: // cd ... 1401 case 1: // cd ...
1402 currentSession->getEmulation()->sendString("cd "); 1402 currentSession->getEmulation()->sendString("cd ");
1403 struct stat statbuf; 1403 struct stat statbuf;
1404 if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 ) 1404 if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 )
1405 { 1405 {
1406 if ( !S_ISDIR(statbuf.st_mode) ) 1406 if ( !S_ISDIR(statbuf.st_mode) )
1407 { 1407 {
1408/* 1408/*
1409 KURL url; 1409 KURL url;
1410 url.setPath( dropText ); 1410 url.setPath( dropText );
1411 dropText = url.directory( true, false ); // remove filename 1411 dropText = url.directory( true, false ); // remove filename
1412*/ 1412*/
1413 } 1413 }
1414 } 1414 }
1415 dropText.replace(QRegExp(" "), "\\ "); // escape spaces 1415 dropText.replace(QRegExp(" "), "\\ "); // escape spaces
1416 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1416 currentSession->getEmulation()->sendString(dropText.local8Bit());
1417 currentSession->getEmulation()->sendString("\n"); 1417 currentSession->getEmulation()->sendString("\n");
1418// KWM::activate((Window)this->winId()); 1418// KWM::activate((Window)this->winId());
1419 break; 1419 break;
1420 } 1420 }
1421#else
1422 Q_UNUSED(item);
1421#endif 1423#endif
1422} 1424}
1423 1425
1424void TEWidget::setWrapAt(int columns) 1426void TEWidget::setWrapAt(int columns)
1425{ 1427{
1426 vcolumns = columns; 1428 vcolumns = columns;
1427 propagateSize(); 1429 propagateSize();
1428 update(); 1430 update();
1429} 1431}