summaryrefslogtreecommitdiff
authorharlekin <harlekin>2002-10-17 17:19:20 (UTC)
committer harlekin <harlekin>2002-10-17 17:19:20 (UTC)
commitdf5a8d26c398ad65f09bd26c492c08f6c0ee22e0 (patch) (unidiff)
treee1fcefde6e4942f65fa2b5ad253f40a190caa78a
parentcedc9eed0c0b8d1685c3ca745eafd77988d394dc (diff)
downloadopie-df5a8d26c398ad65f09bd26c492c08f6c0ee22e0.zip
opie-df5a8d26c398ad65f09bd26c492c08f6c0ee22e0.tar.gz
opie-df5a8d26c398ad65f09bd26c492c08f6c0ee22e0.tar.bz2
fullscreen mode ready
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/TEWidget.cpp20
-rw-r--r--noncore/apps/opie-console/TEWidget.h30
-rw-r--r--noncore/apps/opie-console/emulation_handler.cpp5
-rw-r--r--noncore/apps/opie-console/emulation_handler.h3
-rw-r--r--noncore/apps/opie-console/io_bt.cpp1
-rw-r--r--noncore/apps/opie-console/mainwindow.cpp40
6 files changed, 62 insertions, 37 deletions
diff --git a/noncore/apps/opie-console/TEWidget.cpp b/noncore/apps/opie-console/TEWidget.cpp
index 75c438c..f3f462f 100644
--- a/noncore/apps/opie-console/TEWidget.cpp
+++ b/noncore/apps/opie-console/TEWidget.cpp
@@ -1,1264 +1,1278 @@
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#include <qapplication.h> 55#include <qapplication.h>
56#include <qcursor.h> 56#include <qcursor.h>
57#include <qregexp.h> 57#include <qregexp.h>
58#include <qpainter.h> 58#include <qpainter.h>
59#include <qclipboard.h> 59#include <qclipboard.h>
60#include <qstyle.h> 60#include <qstyle.h>
61#include <qfile.h> 61#include <qfile.h>
62#include <qdragobject.h> 62#include <qdragobject.h>
63#include <qvbox.h>
63 64
64#include <stdio.h> 65#include <stdio.h>
65#include <stdlib.h> 66#include <stdlib.h>
66#include <unistd.h> 67#include <unistd.h>
67#include <ctype.h> 68#include <ctype.h>
68#include <sys/stat.h> 69#include <sys/stat.h>
69#include <sys/types.h> 70#include <sys/types.h>
70#include <signal.h> 71#include <signal.h>
71 72
72#include <assert.h> 73#include <assert.h>
73 74
75
76
74// #include "TEWidget.moc" 77// #include "TEWidget.moc"
75//#include <kapp.h> 78//#include <kapp.h>
76//#include <kcursor.h> 79//#include <kcursor.h>
77//#include <kurl.h> 80//#include <kurl.h>
78//#include <kdebug.h> 81//#include <kdebug.h>
79//#include <klocale.h> 82//#include <klocale.h>
80 83
81#define HERE printf("%s(%d): %s\n",__FILE__,__LINE__,__FUNCTION__) 84#define HERE printf("%s(%d): %s\n",__FILE__,__LINE__,__FUNCTION__)
82#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++); }
83 86
84#define loc(X,Y) ((Y)*columns+(X)) 87#define loc(X,Y) ((Y)*columns+(X))
85 88
86//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.
87#define rimX 0 // left/right rim width 90#define rimX 0 // left/right rim width
88#define rimY 0 // top/bottom rim high 91#define rimY 0 // top/bottom rim high
89 92
90#define SCRWIDTH 16 // width of the scrollbar 93#define SCRWIDTH 16 // width of the scrollbar
91 94
92#define yMouseScroll 1 95#define yMouseScroll 1
93// scroll increment used when dragging selection at top/bottom of window. 96// scroll increment used when dragging selection at top/bottom of window.
94 97
95/* ------------------------------------------------------------------------- */ 98/* ------------------------------------------------------------------------- */
96/* */ 99/* */
97/* Colors */ 100/* Colors */
98/* */ 101/* */
99/* ------------------------------------------------------------------------- */ 102/* ------------------------------------------------------------------------- */
100 103
101//FIXME: the default color table is in session.C now. 104//FIXME: the default color table is in session.C now.
102// We need a way to get rid of this one, here. 105// We need a way to get rid of this one, here.
103static const ColorEntry base_color_table[TABLE_COLORS] = 106static const ColorEntry base_color_table[TABLE_COLORS] =
104// The following are almost IBM standard color codes, with some slight 107// The following are almost IBM standard color codes, with some slight
105// 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.
106// It contains the 8 ansiterm/xterm colors in 2 intensities. 109// It contains the 8 ansiterm/xterm colors in 2 intensities.
107{ 110{
108 // Fixme: could add faint colors here, also. 111 // Fixme: could add faint colors here, also.
109 // normal 112 // normal
110 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
111 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
112 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
113 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
114 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
115 // intensiv 118 // intensiv
116 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 ),
117 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 ),
118 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 ),
119 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 ),
120 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 )
121}; 124};
122 125
123/* 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)
124 127
125 Code 0 1 2 3 4 5 6 7 128 Code 0 1 2 3 4 5 6 7
126 ----------- ------- ------- ------- ------- ------- ------- ------- ------- 129 ----------- ------- ------- ------- ------- ------- ------- ------- -------
127 ANSI (bgr) Black Red Green Yellow Blue Magenta Cyan White 130 ANSI (bgr) Black Red Green Yellow Blue Magenta Cyan White
128 IBMPC (rgb) Black Blue Green Cyan Red Magenta Yellow White 131 IBMPC (rgb) Black Blue Green Cyan Red Magenta Yellow White
129*/ 132*/
130 133
131QColor TEWidget::getDefaultBackColor() 134QColor TEWidget::getDefaultBackColor()
132{ 135{
133 return color_table[DEFAULT_BACK_COLOR].color; 136 return color_table[DEFAULT_BACK_COLOR].color;
134} 137}
135 138
136const ColorEntry* TEWidget::getColorTable() const 139const ColorEntry* TEWidget::getColorTable() const
137{ 140{
138 return color_table; 141 return color_table;
139} 142}
140 143
141const ColorEntry* TEWidget::getdefaultColorTable() const 144const ColorEntry* TEWidget::getdefaultColorTable() const
142{ 145{
143 return base_color_table; 146 return base_color_table;
144} 147}
145 148
146 149
147const QPixmap *TEWidget::backgroundPixmap() 150const QPixmap *TEWidget::backgroundPixmap()
148{ 151{
149 static QPixmap *bg = new QPixmap("~/qpim/main/pics/faded_bg.xpm"); 152 static QPixmap *bg = new QPixmap("~/qpim/main/pics/faded_bg.xpm");
150 const QPixmap *pm = bg; 153 const QPixmap *pm = bg;
151 return pm; 154 return pm;
152} 155}
153 156
154void TEWidget::setColorTable(const ColorEntry table[]) 157void TEWidget::setColorTable(const ColorEntry table[])
155{ 158{
156 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];
157 160
158 const QPixmap* pm = backgroundPixmap(); 161 const QPixmap* pm = backgroundPixmap();
159 if (!pm) setBackgroundColor(color_table[DEFAULT_BACK_COLOR].color); 162 if (!pm) setBackgroundColor(color_table[DEFAULT_BACK_COLOR].color);
160 update(); 163 update();
161} 164}
162 165
163//FIXME: add backgroundPixmapChanged. 166//FIXME: add backgroundPixmapChanged.
164 167
165/* ------------------------------------------------------------------------- */ 168/* ------------------------------------------------------------------------- */
166/* */ 169/* */
167/* Font */ 170/* Font */
168/* */ 171/* */
169/* ------------------------------------------------------------------------- */ 172/* ------------------------------------------------------------------------- */
170 173
171/* 174/*
172 The VT100 has 32 special graphical characters. The usual vt100 extended 175 The VT100 has 32 special graphical characters. The usual vt100 extended
173 xterm fonts have these at 0x00..0x1f. 176 xterm fonts have these at 0x00..0x1f.
174 177
175 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
176 come in here as proper unicode characters. 179 come in here as proper unicode characters.
177 180
178 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
179 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
180 QCodec. 183 QCodec.
181*/ 184*/
182 185
183// assert for i in [0..31] : vt100extended(vt100_graphics[i]) == i. 186// assert for i in [0..31] : vt100extended(vt100_graphics[i]) == i.
184 187
185unsigned short vt100_graphics[32] = 188unsigned short vt100_graphics[32] =
186{ // 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
187 0x0020, 0x25C6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, 190 0x0020, 0x25C6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0,
188 0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 191 0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c,
189 0xF800, 0xF801, 0x2500, 0xF803, 0xF804, 0x251c, 0x2524, 0x2534, 192 0xF800, 0xF801, 0x2500, 0xF803, 0xF804, 0x251c, 0x2524, 0x2534,
190 0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7 193 0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7
191}; 194};
192 195
193static QChar vt100extended(QChar c) 196static QChar vt100extended(QChar c)
194{ 197{
195 switch (c.unicode()) 198 switch (c.unicode())
196 { 199 {
197 case 0x25c6 : return 1; 200 case 0x25c6 : return 1;
198 case 0x2592 : return 2; 201 case 0x2592 : return 2;
199 case 0x2409 : return 3; 202 case 0x2409 : return 3;
200 case 0x240c : return 4; 203 case 0x240c : return 4;
201 case 0x240d : return 5; 204 case 0x240d : return 5;
202 case 0x240a : return 6; 205 case 0x240a : return 6;
203 case 0x00b0 : return 7; 206 case 0x00b0 : return 7;
204 case 0x00b1 : return 8; 207 case 0x00b1 : return 8;
205 case 0x2424 : return 9; 208 case 0x2424 : return 9;
206 case 0x240b : return 10; 209 case 0x240b : return 10;
207 case 0x2518 : return 11; 210 case 0x2518 : return 11;
208 case 0x2510 : return 12; 211 case 0x2510 : return 12;
209 case 0x250c : return 13; 212 case 0x250c : return 13;
210 case 0x2514 : return 14; 213 case 0x2514 : return 14;
211 case 0x253c : return 15; 214 case 0x253c : return 15;
212 case 0xf800 : return 16; 215 case 0xf800 : return 16;
213 case 0xf801 : return 17; 216 case 0xf801 : return 17;
214 case 0x2500 : return 18; 217 case 0x2500 : return 18;
215 case 0xf803 : return 19; 218 case 0xf803 : return 19;
216 case 0xf804 : return 20; 219 case 0xf804 : return 20;
217 case 0x251c : return 21; 220 case 0x251c : return 21;
218 case 0x2524 : return 22; 221 case 0x2524 : return 22;
219 case 0x2534 : return 23; 222 case 0x2534 : return 23;
220 case 0x252c : return 24; 223 case 0x252c : return 24;
221 case 0x2502 : return 25; 224 case 0x2502 : return 25;
222 case 0x2264 : return 26; 225 case 0x2264 : return 26;
223 case 0x2265 : return 27; 226 case 0x2265 : return 27;
224 case 0x03c0 : return 28; 227 case 0x03c0 : return 28;
225 case 0x2260 : return 29; 228 case 0x2260 : return 29;
226 case 0x00a3 : return 30; 229 case 0x00a3 : return 30;
227 case 0x00b7 : return 31; 230 case 0x00b7 : return 31;
228 } 231 }
229 return c; 232 return c;
230} 233}
231 234
232static QChar identicalMap(QChar c) 235static QChar identicalMap(QChar c)
233{ 236{
234 return c; 237 return c;
235} 238}
236 239
237void TEWidget::fontChange(const QFont &) 240void TEWidget::fontChange(const QFont &)
238{ 241{
239 QFontMetrics fm(font()); 242 QFontMetrics fm(font());
240 font_h = fm.height(); 243 font_h = fm.height();
241 font_w = fm.maxWidth(); 244 font_w = fm.maxWidth();
242 font_a = fm.ascent(); 245 font_a = fm.ascent();
243//printf("font_h: %d\n",font_h); 246//printf("font_h: %d\n",font_h);
244//printf("font_w: %d\n",font_w); 247//printf("font_w: %d\n",font_w);
245//printf("font_a: %d\n",font_a); 248//printf("font_a: %d\n",font_a);
246//printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii()); 249//printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii());
247//printf("rawname: %s\n",font().rawName().ascii()); 250//printf("rawname: %s\n",font().rawName().ascii());
248 fontMap = 251 fontMap =
249#if QT_VERSION < 300 252#if QT_VERSION < 300
250 strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646") 253 strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646")
251 ? vt100extended 254 ? vt100extended
252 : 255 :
253#endif 256#endif
254 identicalMap; 257 identicalMap;
255 propagateSize(); 258 propagateSize();
256 update(); 259 update();
257} 260}
258 261
259void TEWidget::setVTFont(const QFont& f) 262void TEWidget::setVTFont(const QFont& f)
260{ 263{
261 QFrame::setFont(f); 264 QFrame::setFont(f);
262} 265}
263 266
264QFont TEWidget::getVTFont() { 267QFont TEWidget::getVTFont() {
265 return font(); 268 return font();
266} 269}
267 270
268void TEWidget::setFont(const QFont &) 271void TEWidget::setFont(const QFont &)
269{ 272{
270 // ignore font change request if not coming from konsole itself 273 // ignore font change request if not coming from konsole itself
271} 274}
272 275
273/* ------------------------------------------------------------------------- */ 276/* ------------------------------------------------------------------------- */
274/* */ 277/* */
275/* Constructor / Destructor */ 278/* Constructor / Destructor */
276/* */ 279/* */
277/* ------------------------------------------------------------------------- */ 280/* ----------------------------------------------------------------------- */
281
282
278 283
279TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name) 284TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name)
280{ 285{
281#ifndef QT_NO_CLIPBOARD 286#ifndef QT_NO_CLIPBOARD
282 cb = QApplication::clipboard(); 287 cb = QApplication::clipboard();
283 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), 288 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()),
284 this, SLOT(onClearSelection()) ); 289 this, SLOT(onClearSelection()) );
285#endif 290#endif
286 291
287 scrollbar = new QScrollBar(this); 292
293 scrollbar = new QScrollBar( this );
288 scrollbar->setCursor( arrowCursor ); 294 scrollbar->setCursor( arrowCursor );
289 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); 295 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
290 296
297 m_cornerButton = new QPushButton( this );
298 m_cornerButton->setPixmap( QPixmap( (const char**)menu_xpm ) );
299 m_cornerButton->setMaximumSize( 14, 14 );
300 m_cornerButton->hide();
301
291 Config cfg("Konsole"); 302 Config cfg("Konsole");
292 cfg.setGroup("ScrollBar"); 303 cfg.setGroup("ScrollBar");
293 switch( cfg.readNumEntry("Position",2)){ 304 switch( cfg.readNumEntry("Position",2)){
294 case 0: 305 case 0:
295 scrollLoc = SCRNONE; 306 scrollLoc = SCRNONE;
296 break; 307 break;
297 case 1: 308 case 1:
298 scrollLoc = SCRLEFT; 309 scrollLoc = SCRLEFT;
299 break; 310 break;
300 case 2: 311 case 2:
301 scrollLoc = SCRRIGHT; 312 scrollLoc = SCRRIGHT;
302 break; 313 break;
303 }; 314 };
304 315
305 blinkT = new QTimer(this); 316 blinkT = new QTimer(this);
306 connect(blinkT, SIGNAL(timeout()), this, SLOT(blinkEvent())); 317 connect(blinkT, SIGNAL(timeout()), this, SLOT(blinkEvent()));
307 // blinking = FALSE; 318 // blinking = FALSE;
308 blinking = TRUE; 319 blinking = TRUE;
309 320
310 resizing = FALSE; 321 resizing = FALSE;
311 actSel = 0; 322 actSel = 0;
312 image = 0; 323 image = 0;
313 lines = 1; 324 lines = 1;
314 columns = 1; 325 columns = 1;
315 font_w = 1; 326 font_w = 1;
316 font_h = 1; 327 font_h = 1;
317 font_a = 1; 328 font_a = 1;
318 word_selection_mode = FALSE; 329 word_selection_mode = FALSE;
319 330
320 setMouseMarks(TRUE); 331 setMouseMarks(TRUE);
321 setVTFont( QFont("fixed") ); 332 setVTFont( QFont("fixed") );
322 setColorTable(base_color_table); // init color table 333 setColorTable(base_color_table); // init color table
323 334
324 qApp->installEventFilter( this ); //FIXME: see below 335 qApp->installEventFilter( this ); //FIXME: see below
325// KCursor::setAutoHideCursor( this, true ); 336// KCursor::setAutoHideCursor( this, true );
326 337
327 // Init DnD //////////////////////////////////////////////////////////////// 338 // Init DnD ////////////////////////////////////////////////////////////////
328 currentSession = NULL; 339 currentSession = NULL;
329// setAcceptDrops(true); // attempt 340// setAcceptDrops(true); // attempt
330// m_drop = new QPopupMenu(this); 341// m_drop = new QPopupMenu(this);
331// m_drop->insertItem( QString("Paste"), 0); 342// m_drop->insertItem( QString("Paste"), 0);
332// m_drop->insertItem( QString("cd"), 1); 343// m_drop->insertItem( QString("cd"), 1);
333// connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int))); 344// connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int)));
334 345
335 // we need focus so that the auto-hide cursor feature works 346 // we need focus so that the auto-hide cursor feature works
336 setFocus(); 347 setFocus();
337 setFocusPolicy( WheelFocus ); 348 setFocusPolicy( WheelFocus );
338} 349}
339 350
340//FIXME: make proper destructor 351//FIXME: make proper destructor
341// Here's a start (David) 352// Here's a start (David)
342TEWidget::~TEWidget() 353TEWidget::~TEWidget()
343{ 354{
344 qApp->removeEventFilter( this ); 355 qApp->removeEventFilter( this );
345 if (image) free(image); 356 if (image) free(image);
346} 357}
347 358
348/* ------------------------------------------------------------------------- */ 359/* ------------------------------------------------------------------------- */
349/* */ 360/* */
350/* Display Operations */ 361/* Display Operations */
351/* */ 362/* */
352/* ------------------------------------------------------------------------- */ 363/* ------------------------------------------------------------------------- */
353 364
354/*! 365/*!
355 attributed string draw primitive 366 attributed string draw primitive
356*/ 367*/
357 368
358void TEWidget::drawAttrStr(QPainter &paint, QRect rect, 369void TEWidget::drawAttrStr(QPainter &paint, QRect rect,
359 QString& str, ca attr, BOOL pm, BOOL clear) 370 QString& str, ca attr, BOOL pm, BOOL clear)
360{ 371{
361 if (pm && color_table[attr.b].transparent) 372 if (pm && color_table[attr.b].transparent)
362 { 373 {
363 paint.setBackgroundMode( TransparentMode ); 374 paint.setBackgroundMode( TransparentMode );
364 if (clear) erase(rect); 375 if (clear) erase(rect);
365 } 376 }
366 else 377 else
367 { 378 {
368 if (blinking) 379 if (blinking)
369 paint.fillRect(rect, color_table[attr.b].color); 380 paint.fillRect(rect, color_table[attr.b].color);
370 else 381 else
371 { 382 {
372 paint.setBackgroundMode( OpaqueMode ); 383 paint.setBackgroundMode( OpaqueMode );
373 paint.setBackgroundColor( color_table[attr.b].color ); 384 paint.setBackgroundColor( color_table[attr.b].color );
374 } 385 }
375 } 386 }
376 387
377 if (color_table[attr.f].bold) 388 if (color_table[attr.f].bold)
378 paint.setPen(QColor( 0x8F, 0x00, 0x00 )); 389 paint.setPen(QColor( 0x8F, 0x00, 0x00 ));
379 else 390 else
380 paint.setPen(color_table[attr.f].color); 391 paint.setPen(color_table[attr.f].color);
381 392
382 paint.drawText(rect.x(),rect.y()+font_a, str); 393 paint.drawText(rect.x(),rect.y()+font_a, str);
383 394
384 if (attr.r & RE_UNDERLINE) 395 if (attr.r & RE_UNDERLINE)
385 paint.drawLine(rect.left(), rect.y()+font_a+1, rect.right(),rect.y()+font_a+1 ); 396 paint.drawLine(rect.left(), rect.y()+font_a+1, rect.right(),rect.y()+font_a+1 );
386} 397}
387 398
388/*! 399/*!
389 The image can only be set completely. 400 The image can only be set completely.
390 401
391 The size of the new image may or may not match the size of the widget. 402 The size of the new image may or may not match the size of the widget.
392*/ 403*/
393 404
394void TEWidget::setImage(const ca* const newimg, int lines, int columns) 405void TEWidget::setImage(const ca* const newimg, int lines, int columns)
395{ int y,x,len; 406{ int y,x,len;
396 const QPixmap* pm = backgroundPixmap(); 407 const QPixmap* pm = backgroundPixmap();
397 QPainter paint; 408 QPainter paint;
398 setUpdatesEnabled(FALSE); 409 setUpdatesEnabled(FALSE);
399 paint.begin( this ); 410 paint.begin( this );
400HCNT("setImage"); 411HCNT("setImage");
401 412
402 QPoint tL = contentsRect().topLeft(); 413 QPoint tL = contentsRect().topLeft();
403 int tLx = tL.x(); 414 int tLx = tL.x();
404 int tLy = tL.y(); 415 int tLy = tL.y();
405 hasBlinker = FALSE; 416 hasBlinker = FALSE;
406 417
407 int cf = -1; // undefined 418 int cf = -1; // undefined
408 int cb = -1; // undefined 419 int cb = -1; // undefined
409 int cr = -1; // undefined 420 int cr = -1; // undefined
410 421
411 int lins = QMIN(this->lines, QMAX(0,lines )); 422 int lins = QMIN(this->lines, QMAX(0,lines ));
412 int cols = QMIN(this->columns,QMAX(0,columns)); 423 int cols = QMIN(this->columns,QMAX(0,columns));
413 QChar *disstrU = new QChar[cols]; 424 QChar *disstrU = new QChar[cols];
414 425
415//{ static int cnt = 0; printf("setImage %d\n",cnt++); } 426//{ static int cnt = 0; printf("setImage %d\n",cnt++); }
416 for (y = 0; y < lins; y++) 427 for (y = 0; y < lins; y++)
417 { 428 {
418 const ca* lcl = &image[y*this->columns]; 429 const ca* lcl = &image[y*this->columns];
419 const ca* const ext = &newimg[y*columns]; 430 const ca* const ext = &newimg[y*columns];
420 if (!resizing) // not while resizing, we're expecting a paintEvent 431 if (!resizing) // not while resizing, we're expecting a paintEvent
421 for (x = 0; x < cols; x++) 432 for (x = 0; x < cols; x++)
422 { 433 {
423 hasBlinker |= (ext[x].r & RE_BLINK); 434 hasBlinker |= (ext[x].r & RE_BLINK);
424 if (ext[x] != lcl[x]) 435 if (ext[x] != lcl[x])
425 { 436 {
426 cr = ext[x].r; 437 cr = ext[x].r;
427 cb = ext[x].b; 438 cb = ext[x].b;
428 if (ext[x].f != cf) cf = ext[x].f; 439 if (ext[x].f != cf) cf = ext[x].f;
429 int lln = cols - x; 440 int lln = cols - x;
430 disstrU[0] = fontMap(ext[x+0].c); 441 disstrU[0] = fontMap(ext[x+0].c);
431 for (len = 1; len < lln; len++) 442 for (len = 1; len < lln; len++)
432 { 443 {
433 if (ext[x+len].f != cf || ext[x+len].b != cb || ext[x+len].r != cr || 444 if (ext[x+len].f != cf || ext[x+len].b != cb || ext[x+len].r != cr ||
434 ext[x+len] == lcl[x+len] ) 445 ext[x+len] == lcl[x+len] )
435 break; 446 break;
436 disstrU[len] = fontMap(ext[x+len].c); 447 disstrU[len] = fontMap(ext[x+len].c);
437 } 448 }
438 QString unistr(disstrU,len); 449 QString unistr(disstrU,len);
439 drawAttrStr(paint, 450 drawAttrStr(paint,
440 QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), 451 QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h),
441 unistr, ext[x], pm != NULL, true); 452 unistr, ext[x], pm != NULL, true);
442 x += len - 1; 453 x += len - 1;
443 } 454 }
444 } 455 }
445 // finally, make `image' become `newimg'. 456 // finally, make `image' become `newimg'.
446 memcpy((void*)lcl,(const void*)ext,cols*sizeof(ca)); 457 memcpy((void*)lcl,(const void*)ext,cols*sizeof(ca));
447 } 458 }
448 drawFrame( &paint ); 459 drawFrame( &paint );
449 paint.end(); 460 paint.end();
450 setUpdatesEnabled(TRUE); 461 setUpdatesEnabled(TRUE);
451 if ( hasBlinker && !blinkT->isActive()) blinkT->start(1000); // 1000 ms 462 if ( hasBlinker && !blinkT->isActive()) blinkT->start(1000); // 1000 ms
452 if (!hasBlinker && blinkT->isActive()) { blinkT->stop(); blinking = FALSE; } 463 if (!hasBlinker && blinkT->isActive()) { blinkT->stop(); blinking = FALSE; }
453 delete [] disstrU; 464 delete [] disstrU;
454} 465}
455 466
456// paint Event //////////////////////////////////////////////////// 467// paint Event ////////////////////////////////////////////////////
457 468
458/*! 469/*!
459 The difference of this routine vs. the `setImage' is, 470 The difference of this routine vs. the `setImage' is,
460 that the drawing does not include a difference analysis 471 that the drawing does not include a difference analysis
461 between the old and the new image. Instead, the internal 472 between the old and the new image. Instead, the internal
462 image is used and the painting bound by the PaintEvent box. 473 image is used and the painting bound by the PaintEvent box.
463*/ 474*/
464 475
465void TEWidget::paintEvent( QPaintEvent* pe ) 476void TEWidget::paintEvent( QPaintEvent* pe )
466{ 477{
467 478
468//{ static int cnt = 0; printf("paint %d\n",cnt++); } 479//{ static int cnt = 0; printf("paint %d\n",cnt++); }
469 const QPixmap* pm = backgroundPixmap(); 480 const QPixmap* pm = backgroundPixmap();
470 QPainter paint; 481 QPainter paint;
471 setUpdatesEnabled(FALSE); 482 setUpdatesEnabled(FALSE);
472 paint.begin( this ); 483 paint.begin( this );
473 paint.setBackgroundMode( TransparentMode ); 484 paint.setBackgroundMode( TransparentMode );
474HCNT("paintEvent"); 485HCNT("paintEvent");
475 486
476 // Note that the actual widget size can be slightly larger 487 // Note that the actual widget size can be slightly larger
477 // that the image (the size is truncated towards the smaller 488 // that the image (the size is truncated towards the smaller
478 // number of characters in `resizeEvent'. The paint rectangle 489 // number of characters in `resizeEvent'. The paint rectangle
479 // can thus be larger than the image, but less then the size 490 // can thus be larger than the image, but less then the size
480 // of one character. 491 // of one character.
481 492
482 QRect rect = pe->rect().intersect(contentsRect()); 493 QRect rect = pe->rect().intersect(contentsRect());
483 494
484 QPoint tL = contentsRect().topLeft(); 495 QPoint tL = contentsRect().topLeft();
485 int tLx = tL.x(); 496 int tLx = tL.x();
486 int tLy = tL.y(); 497 int tLy = tL.y();
487 498
488 int lux = QMIN(columns-1, QMAX(0,(rect.left() - tLx - blX ) / font_w)); 499 int lux = QMIN(columns-1, QMAX(0,(rect.left() - tLx - blX ) / font_w));
489 int luy = QMIN(lines-1, QMAX(0,(rect.top() - tLy - bY ) / font_h)); 500 int luy = QMIN(lines-1, QMAX(0,(rect.top() - tLy - bY ) / font_h));
490 int rlx = QMIN(columns-1, QMAX(0,(rect.right() - tLx - blX ) / font_w)); 501 int rlx = QMIN(columns-1, QMAX(0,(rect.right() - tLx - blX ) / font_w));
491 int rly = QMIN(lines-1, QMAX(0,(rect.bottom() - tLy - bY ) / font_h)); 502 int rly = QMIN(lines-1, QMAX(0,(rect.bottom() - tLy - bY ) / font_h));
492 503
493 /* 504 /*
494 printf("paintEvent: %d..%d, %d..%d (%d..%d, %d..%d)\n",lux,rlx,luy,rly, 505 printf("paintEvent: %d..%d, %d..%d (%d..%d, %d..%d)\n",lux,rlx,luy,rly,
495 rect.left(), rect.right(), rect.top(), rect.bottom()); 506 rect.left(), rect.right(), rect.top(), rect.bottom());
496 */ 507 */
497 508
498 // if (pm != NULL && color_table[image->b].transparent) 509 // if (pm != NULL && color_table[image->b].transparent)
499 // erase(rect); 510 // erase(rect);
500 // BL: I have no idea why we need this, and it breaks the refresh. 511 // BL: I have no idea why we need this, and it breaks the refresh.
501 512
502 QChar *disstrU = new QChar[columns]; 513 QChar *disstrU = new QChar[columns];
503 for (int y = luy; y <= rly; y++) 514 for (int y = luy; y <= rly; y++)
504 for (int x = lux; x <= rlx; x++) 515 for (int x = lux; x <= rlx; x++)
505 { 516 {
506 int len = 1; 517 int len = 1;
507 disstrU[0] = fontMap(image[loc(x,y)].c); 518 disstrU[0] = fontMap(image[loc(x,y)].c);
508 int cf = image[loc(x,y)].f; 519 int cf = image[loc(x,y)].f;
509 int cb = image[loc(x,y)].b; 520 int cb = image[loc(x,y)].b;
510 int cr = image[loc(x,y)].r; 521 int cr = image[loc(x,y)].r;
511 while (x+len <= rlx && 522 while (x+len <= rlx &&
512 image[loc(x+len,y)].f == cf && 523 image[loc(x+len,y)].f == cf &&
513 image[loc(x+len,y)].b == cb && 524 image[loc(x+len,y)].b == cb &&
514 image[loc(x+len,y)].r == cr ) 525 image[loc(x+len,y)].r == cr )
515 { 526 {
516 disstrU[len] = fontMap(image[loc(x+len,y)].c); 527 disstrU[len] = fontMap(image[loc(x+len,y)].c);
517 len += 1; 528 len += 1;
518 } 529 }
519 QString unistr(disstrU,len); 530 QString unistr(disstrU,len);
520 drawAttrStr(paint, 531 drawAttrStr(paint,
521 QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), 532 QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h),
522 unistr, image[loc(x,y)], pm != NULL, false); 533 unistr, image[loc(x,y)], pm != NULL, false);
523 x += len - 1; 534 x += len - 1;
524 } 535 }
525 delete [] disstrU; 536 delete [] disstrU;
526 drawFrame( &paint ); 537 drawFrame( &paint );
527 paint.end(); 538 paint.end();
528 setUpdatesEnabled(TRUE); 539 setUpdatesEnabled(TRUE);
529} 540}
530 541
531void TEWidget::blinkEvent() 542void TEWidget::blinkEvent()
532{ 543{
533 blinking = !blinking; 544 blinking = !blinking;
534 repaint(FALSE); 545 repaint(FALSE);
535} 546}
536 547
537/* ------------------------------------------------------------------------- */ 548/* ------------------------------------------------------------------------- */
538/* */ 549/* */
539/* Resizing */ 550/* Resizing */
540/* */ 551/* */
541/* ------------------------------------------------------------------------- */ 552/* ------------------------------------------------------------------------- */
542 553
543void TEWidget::resizeEvent(QResizeEvent* ev) 554void TEWidget::resizeEvent(QResizeEvent* ev)
544{ 555{
545// printf("resize: %d,%d\n",ev->size().width(),ev->size().height()); 556// printf("resize: %d,%d\n",ev->size().width(),ev->size().height());
546 //printf("approx: %d,%d\n",ev->size().width()/font_w,ev->size().height()/font_h); 557 //printf("approx: %d,%d\n",ev->size().width()/font_w,ev->size().height()/font_h);
547 //printf("leaves: %d,%d\n",ev->size().width()%font_w,ev->size().height()%font_h); 558 //printf("leaves: %d,%d\n",ev->size().width()%font_w,ev->size().height()%font_h);
548 //printf("curren: %d,%d\n",width(),height()); 559 //printf("curren: %d,%d\n",width(),height());
549HCNT("resizeEvent"); 560HCNT("resizeEvent");
550 561
551 // see comment in `paintEvent' concerning the rounding. 562 // see comment in `paintEvent' concerning the rounding.
552 //FIXME: could make a routine here; check width(),height() 563 //FIXME: could make a routine here; check width(),height()
553 assert(ev->size().width() == width()); 564 assert(ev->size().width() == width());
554 assert(ev->size().height() == height()); 565 assert(ev->size().height() == height());
555 566
556 propagateSize(); 567 propagateSize();
557} 568}
558 569
559void TEWidget::propagateSize() 570void TEWidget::propagateSize()
560{ 571{
561 ca* oldimg = image; 572 ca* oldimg = image;
562 int oldlin = lines; 573 int oldlin = lines;
563 int oldcol = columns; 574 int oldcol = columns;
564 makeImage(); 575 makeImage();
565 // we copy the old image to reduce flicker 576 // we copy the old image to reduce flicker
566 int lins = QMIN(oldlin,lines); 577 int lins = QMIN(oldlin,lines);
567 int cols = QMIN(oldcol,columns); 578 int cols = QMIN(oldcol,columns);
568 if (oldimg) 579 if (oldimg)
569 { 580 {
570 for (int lin = 0; lin < lins; lin++) 581 for (int lin = 0; lin < lins; lin++)
571 memcpy((void*)&image[columns*lin], 582 memcpy((void*)&image[columns*lin],
572 (void*)&oldimg[oldcol*lin],cols*sizeof(ca)); 583 (void*)&oldimg[oldcol*lin],cols*sizeof(ca));
573 free(oldimg); //FIXME: try new,delete 584 free(oldimg); //FIXME: try new,delete
574 } 585 }
575 else 586 else
576 clearImage(); 587 clearImage();
577 588
578 //NOTE: control flows from the back through the chest right into the eye. 589 //NOTE: control flows from the back through the chest right into the eye.
579 // `emu' will call back via `setImage'. 590 // `emu' will call back via `setImage'.
580 591
581 resizing = TRUE; 592 resizing = TRUE;
582 emit changedImageSizeSignal(lines, columns); // expose resizeEvent 593 emit changedImageSizeSignal(lines, columns); // expose resizeEvent
583 resizing = FALSE; 594 resizing = FALSE;
584} 595}
585 596
586/* ------------------------------------------------------------------------- */ 597/* ------------------------------------------------------------------------- */
587/* */ 598/* */
588/* Scrollbar */ 599/* Scrollbar */
589/* */ 600/* */
590/* ------------------------------------------------------------------------- */ 601/* ------------------------------------------------------------------------- */
591 602
592void TEWidget::scrollChanged(int) 603void TEWidget::scrollChanged(int)
593{ 604{
594 emit changedHistoryCursor(scrollbar->value()); //expose 605 emit changedHistoryCursor(scrollbar->value()); //expose
595} 606}
596 607
597void TEWidget::setScroll(int cursor, int slines) 608void TEWidget::setScroll(int cursor, int slines)
598{ 609{
599 disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); 610 disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
600 scrollbar->setRange(0,slines); 611 scrollbar->setRange(0,slines);
601 scrollbar->setSteps(1,lines); 612 scrollbar->setSteps(1,lines);
602 scrollbar->setValue(cursor); 613 scrollbar->setValue(cursor);
603 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); 614 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
604} 615}
605 616
606void TEWidget::setScrollbarLocation(int loc) 617void TEWidget::setScrollbarLocation(int loc)
607{ 618{
608 if (scrollLoc == loc) return; // quickly 619 if (scrollLoc == loc) return; // quickly
609 scrollLoc = loc; 620 scrollLoc = loc;
610 propagateSize(); 621 propagateSize();
611 update(); 622 update();
612} 623}
613 624
614/* ------------------------------------------------------------------------- */ 625/* ------------------------------------------------------------------------- */
615/* */ 626/* */
616/* Mouse */ 627/* Mouse */
617/* */ 628/* */
618/* ------------------------------------------------------------------------- */ 629/* ------------------------------------------------------------------------- */
619 630
620/*! 631/*!
621 Three different operations can be performed using the mouse, and the 632 Three different operations can be performed using the mouse, and the
622 routines in this section serve all of them: 633 routines in this section serve all of them:
623 634
624 1) The press/release events are exposed to the application 635 1) The press/release events are exposed to the application
625 2) Marking (press and move left button) and Pasting (press middle button) 636 2) Marking (press and move left button) and Pasting (press middle button)
626 3) The right mouse button is used from the configuration menu 637 3) The right mouse button is used from the configuration menu
627 638
628 NOTE: During the marking process we attempt to keep the cursor within 639 NOTE: During the marking process we attempt to keep the cursor within
629 the bounds of the text as being displayed by setting the mouse position 640 the bounds of the text as being displayed by setting the mouse position
630 whenever the mouse has left the text area. 641 whenever the mouse has left the text area.
631 642
632 Two reasons to do so: 643 Two reasons to do so:
633 1) QT does not allow the `grabMouse' to confine-to the TEWidget. 644 1) QT does not allow the `grabMouse' to confine-to the TEWidget.
634 Thus a `XGrapPointer' would have to be used instead. 645 Thus a `XGrapPointer' would have to be used instead.
635 2) Even if so, this would not help too much, since the text area 646 2) Even if so, this would not help too much, since the text area
636 of the TEWidget is normally not identical with it's bounds. 647 of the TEWidget is normally not identical with it's bounds.
637 648
638 The disadvantage of the current handling is, that the mouse can visibly 649 The disadvantage of the current handling is, that the mouse can visibly
639 leave the bounds of the widget and is then moved back. Because of the 650 leave the bounds of the widget and is then moved back. Because of the
640 current construction, and the reasons mentioned above, we cannot do better 651 current construction, and the reasons mentioned above, we cannot do better
641 without changing the overall construction. 652 without changing the overall construction.
642*/ 653*/
643 654
644/*! 655/*!
645*/ 656*/
646 657
647void TEWidget::mousePressEvent(QMouseEvent* ev) 658void TEWidget::mousePressEvent(QMouseEvent* ev)
648{ 659{
649//printf("press [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); 660//printf("press [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button());
650 if ( !contentsRect().contains(ev->pos()) ) return; 661 if ( !contentsRect().contains(ev->pos()) ) return;
651 QPoint tL = contentsRect().topLeft(); 662 QPoint tL = contentsRect().topLeft();
652 int tLx = tL.x(); 663 int tLx = tL.x();
653 int tLy = tL.y(); 664 int tLy = tL.y();
654 665
655 word_selection_mode = FALSE; 666 word_selection_mode = FALSE;
656 667
657//printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY); 668//printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY);
658 if ( ev->button() == LeftButton) 669 if ( ev->button() == LeftButton)
659 { 670 {
660 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); 671 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
661 672
662 if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ; 673 if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ;
663 674
664 if (mouse_marks || (ev->state() & ShiftButton)) 675 if (mouse_marks || (ev->state() & ShiftButton))
665 { 676 {
666 emit clearSelectionSignal(); 677 emit clearSelectionSignal();
667 iPntSel = pntSel = pos; 678 iPntSel = pntSel = pos;
668 actSel = 1; // left mouse button pressed but nothing selected yet. 679 actSel = 1; // left mouse button pressed but nothing selected yet.
669 grabMouse( /*crossCursor*/ ); // handle with care! 680 grabMouse( /*crossCursor*/ ); // handle with care!
670 } 681 }
671 else 682 else
672 { 683 {
673 emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button 684 emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button
674 } 685 }
675 } 686 }
676 if ( ev->button() == MidButton ) 687 if ( ev->button() == MidButton )
677 { 688 {
678 emitSelection(); 689 emitSelection();
679 } 690 }
680 if ( ev->button() == RightButton ) // Configure 691 if ( ev->button() == RightButton ) // Configure
681 { 692 {
682 emit configureRequest( this, ev->state()&(ShiftButton|ControlButton), ev->x(), ev->y() ); 693 emit configureRequest( this, ev->state()&(ShiftButton|ControlButton), ev->x(), ev->y() );
683 } 694 }
684} 695}
685 696
686void TEWidget::mouseMoveEvent(QMouseEvent* ev) 697void TEWidget::mouseMoveEvent(QMouseEvent* ev)
687{ 698{
688 // for auto-hiding the cursor, we need mouseTracking 699 // for auto-hiding the cursor, we need mouseTracking
689 if (ev->state() == NoButton ) return; 700 if (ev->state() == NoButton ) return;
690 701
691 if (actSel == 0) return; 702 if (actSel == 0) return;
692 703
693 // don't extend selection while pasting 704 // don't extend selection while pasting
694 if (ev->state() & MidButton) return; 705 if (ev->state() & MidButton) return;
695 706
696 //if ( !contentsRect().contains(ev->pos()) ) return; 707 //if ( !contentsRect().contains(ev->pos()) ) return;
697 QPoint tL = contentsRect().topLeft(); 708 QPoint tL = contentsRect().topLeft();
698 int tLx = tL.x(); 709 int tLx = tL.x();
699 int tLy = tL.y(); 710 int tLy = tL.y();
700 int scroll = scrollbar->value(); 711 int scroll = scrollbar->value();
701 712
702 // we're in the process of moving the mouse with the left button pressed 713 // we're in the process of moving the mouse with the left button pressed
703 // the mouse cursor will kept catched within the bounds of the text in 714 // the mouse cursor will kept catched within the bounds of the text in
704 // this widget. 715 // this widget.
705 716
706 // Adjust position within text area bounds. See FIXME above. 717 // Adjust position within text area bounds. See FIXME above.
707 QPoint pos = ev->pos(); 718 QPoint pos = ev->pos();
708 if ( pos.x() < tLx+blX ) pos.setX( tLx+blX ); 719 if ( pos.x() < tLx+blX ) pos.setX( tLx+blX );
709 if ( pos.x() > tLx+blX+columns*font_w-1 ) pos.setX( tLx+blX+columns*font_w ); 720 if ( pos.x() > tLx+blX+columns*font_w-1 ) pos.setX( tLx+blX+columns*font_w );
710 if ( pos.y() < tLy+bY ) pos.setY( tLy+bY ); 721 if ( pos.y() < tLy+bY ) pos.setY( tLy+bY );
711 if ( pos.y() > tLy+bY+lines*font_h-1 ) pos.setY( tLy+bY+lines*font_h-1 ); 722 if ( pos.y() > tLy+bY+lines*font_h-1 ) pos.setY( tLy+bY+lines*font_h-1 );
712 // check if we produce a mouse move event by this 723 // check if we produce a mouse move event by this
713 if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos)); 724 if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos));
714 725
715 if ( pos.y() == tLy+bY+lines*font_h-1 ) 726 if ( pos.y() == tLy+bY+lines*font_h-1 )
716 { 727 {
717 scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward 728 scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward
718 } 729 }
719 if ( pos.y() == tLy+bY ) 730 if ( pos.y() == tLy+bY )
720 { 731 {
721 scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback 732 scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback
722 } 733 }
723 734
724 QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h); 735 QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h);
725 QPoint ohere; 736 QPoint ohere;
726 bool swapping = FALSE; 737 bool swapping = FALSE;
727 738
728 if ( word_selection_mode ) 739 if ( word_selection_mode )
729 { 740 {
730 // Extend to word boundaries 741 // Extend to word boundaries
731 int i; 742 int i;
732 int selClass; 743 int selClass;
733 744
734 bool left_not_right = ( here.y() < iPntSel.y() || 745 bool left_not_right = ( here.y() < iPntSel.y() ||
735 here.y() == iPntSel.y() && here.x() < iPntSel.x() ); 746 here.y() == iPntSel.y() && here.x() < iPntSel.x() );
736 bool old_left_not_right = ( pntSel.y() < iPntSel.y() || 747 bool old_left_not_right = ( pntSel.y() < iPntSel.y() ||
737 pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() ); 748 pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() );
738 swapping = left_not_right != old_left_not_right; 749 swapping = left_not_right != old_left_not_right;
739 750
740 // Find left (left_not_right ? from here : from start) 751 // Find left (left_not_right ? from here : from start)
741 QPoint left = left_not_right ? here : iPntSel; 752 QPoint left = left_not_right ? here : iPntSel;
742 i = loc(left.x(),left.y()); 753 i = loc(left.x(),left.y());
743 selClass = charClass(image[i].c); 754 selClass = charClass(image[i].c);
744 while ( left.x() > 0 && charClass(image[i-1].c) == selClass ) 755 while ( left.x() > 0 && charClass(image[i-1].c) == selClass )
745 { i--; left.rx()--; } 756 { i--; left.rx()--; }
746 757
747 // Find left (left_not_right ? from start : from here) 758 // Find left (left_not_right ? from start : from here)
748 QPoint right = left_not_right ? iPntSel : here; 759 QPoint right = left_not_right ? iPntSel : here;
749 i = loc(right.x(),right.y()); 760 i = loc(right.x(),right.y());
750 selClass = charClass(image[i].c); 761 selClass = charClass(image[i].c);
751 while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass ) 762 while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass )
752 { i++; right.rx()++; } 763 { i++; right.rx()++; }
753 764
754 // Pick which is start (ohere) and which is extension (here) 765 // Pick which is start (ohere) and which is extension (here)
755 if ( left_not_right ) 766 if ( left_not_right )
756 { 767 {
757 here = left; ohere = right; 768 here = left; ohere = right;
758 } 769 }
759 else 770 else
760 { 771 {
761 here = right; ohere = left; 772 here = right; ohere = left;
762 } 773 }
763 } 774 }
764 775
765 if (here == pntSel && scroll == scrollbar->value()) return; // not moved 776 if (here == pntSel && scroll == scrollbar->value()) return; // not moved
766 777
767 if ( word_selection_mode ) { 778 if ( word_selection_mode ) {
768 if ( actSel < 2 || swapping ) { 779 if ( actSel < 2 || swapping ) {
769 emit beginSelectionSignal( ohere.x(), ohere.y() ); 780 emit beginSelectionSignal( ohere.x(), ohere.y() );
770 } 781 }
771 } else if ( actSel < 2 ) { 782 } else if ( actSel < 2 ) {
772 emit beginSelectionSignal( pntSel.x(), pntSel.y() ); 783 emit beginSelectionSignal( pntSel.x(), pntSel.y() );
773 } 784 }
774 785
775 actSel = 2; // within selection 786 actSel = 2; // within selection
776 pntSel = here; 787 pntSel = here;
777 emit extendSelectionSignal( here.x(), here.y() ); 788 emit extendSelectionSignal( here.x(), here.y() );
778} 789}
779 790
780void TEWidget::mouseReleaseEvent(QMouseEvent* ev) 791void TEWidget::mouseReleaseEvent(QMouseEvent* ev)
781{ 792{
782//printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); 793//printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button());
783 if ( ev->button() == LeftButton) 794 if ( ev->button() == LeftButton)
784 { 795 {
785 if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks); 796 if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks);
786 preserve_line_breaks = TRUE; 797 preserve_line_breaks = TRUE;
787 actSel = 0; 798 actSel = 0;
788 799
789 //FIXME: emits a release event even if the mouse is 800 //FIXME: emits a release event even if the mouse is
790 // outside the range. The procedure used in `mouseMoveEvent' 801 // outside the range. The procedure used in `mouseMoveEvent'
791 // applies here, too. 802 // applies here, too.
792 803
793 QPoint tL = contentsRect().topLeft(); 804 QPoint tL = contentsRect().topLeft();
794 int tLx = tL.x(); 805 int tLx = tL.x();
795 int tLy = tL.y(); 806 int tLy = tL.y();
796 807
797 if (!mouse_marks && !(ev->state() & ShiftButton)) 808 if (!mouse_marks && !(ev->state() & ShiftButton))
798 emit mouseSignal( 3, // release 809 emit mouseSignal( 3, // release
799 (ev->x()-tLx-blX)/font_w + 1, 810 (ev->x()-tLx-blX)/font_w + 1,
800 (ev->y()-tLy-bY)/font_h + 1 ); 811 (ev->y()-tLy-bY)/font_h + 1 );
801 releaseMouse(); 812 releaseMouse();
802 } 813 }
803} 814}
804 815
805void TEWidget::mouseDoubleClickEvent(QMouseEvent* ev) 816void TEWidget::mouseDoubleClickEvent(QMouseEvent* ev)
806{ 817{
807 if ( ev->button() != LeftButton) return; 818 if ( ev->button() != LeftButton) return;
808 819
809 QPoint tL = contentsRect().topLeft(); 820 QPoint tL = contentsRect().topLeft();
810 int tLx = tL.x(); 821 int tLx = tL.x();
811 int tLy = tL.y(); 822 int tLy = tL.y();
812 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); 823 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
813 824
814 // pass on double click as two clicks. 825 // pass on double click as two clicks.
815 if (!mouse_marks && !(ev->state() & ShiftButton)) 826 if (!mouse_marks && !(ev->state() & ShiftButton))
816 { 827 {
817 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button 828 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button
818 emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release 829 emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release
819 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button 830 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button
820 return; 831 return;
821 } 832 }
822 833
823 834
824 emit clearSelectionSignal(); 835 emit clearSelectionSignal();
825 QPoint bgnSel = pos; 836 QPoint bgnSel = pos;
826 QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); 837 QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
827 int i = loc(bgnSel.x(),bgnSel.y()); 838 int i = loc(bgnSel.x(),bgnSel.y());
828 iPntSel = bgnSel; 839 iPntSel = bgnSel;
829 840
830 word_selection_mode = TRUE; 841 word_selection_mode = TRUE;
831 842
832 // find word boundaries... 843 // find word boundaries...
833 int selClass = charClass(image[i].c); 844 int selClass = charClass(image[i].c);
834 { 845 {
835 // set the start... 846 // set the start...
836 int x = bgnSel.x(); 847 int x = bgnSel.x();
837 while ( x > 0 && charClass(image[i-1].c) == selClass ) 848 while ( x > 0 && charClass(image[i-1].c) == selClass )
838 { i--; x--; } 849 { i--; x--; }
839 bgnSel.setX(x); 850 bgnSel.setX(x);
840 emit beginSelectionSignal( bgnSel.x(), bgnSel.y() ); 851 emit beginSelectionSignal( bgnSel.x(), bgnSel.y() );
841 852
842 // set the end... 853 // set the end...
843 i = loc( endSel.x(), endSel.y() ); 854 i = loc( endSel.x(), endSel.y() );
844 x = endSel.x(); 855 x = endSel.x();
845 while( x < columns-1 && charClass(image[i+1].c) == selClass ) 856 while( x < columns-1 && charClass(image[i+1].c) == selClass )
846 { i++; x++ ; } 857 { i++; x++ ; }
847 endSel.setX(x); 858 endSel.setX(x);
848 actSel = 2; // within selection 859 actSel = 2; // within selection
849 emit extendSelectionSignal( endSel.x(), endSel.y() ); 860 emit extendSelectionSignal( endSel.x(), endSel.y() );
850 emit endSelectionSignal(preserve_line_breaks); 861 emit endSelectionSignal(preserve_line_breaks);
851 preserve_line_breaks = TRUE; 862 preserve_line_breaks = TRUE;
852 } 863 }
853} 864}
854 865
855void TEWidget::focusInEvent( QFocusEvent * ) 866void TEWidget::focusInEvent( QFocusEvent * )
856{ 867{
857 868
858 // do nothing, to prevent repainting 869 // do nothing, to prevent repainting
859} 870}
860 871
861 872
862void TEWidget::focusOutEvent( QFocusEvent * ) 873void TEWidget::focusOutEvent( QFocusEvent * )
863{ 874{
864 // do nothing, to prevent repainting 875 // do nothing, to prevent repainting
865} 876}
866 877
867bool TEWidget::focusNextPrevChild( bool next ) 878bool TEWidget::focusNextPrevChild( bool next )
868{ 879{
869 if (next) 880 if (next)
870 return false; // This disables changing the active part in konqueror 881 return false; // This disables changing the active part in konqueror
871 // when pressing Tab 882 // when pressing Tab
872 return QFrame::focusNextPrevChild( next ); 883 return QFrame::focusNextPrevChild( next );
873} 884}
874 885
875 886
876int TEWidget::charClass(char ch) const 887int TEWidget::charClass(char ch) const
877{ 888{
878 // This might seem like overkill, but imagine if ch was a Unicode 889 // This might seem like overkill, but imagine if ch was a Unicode
879 // character (Qt 2.0 QChar) - it might then be sensible to separate 890 // character (Qt 2.0 QChar) - it might then be sensible to separate
880 // the different language ranges, etc. 891 // the different language ranges, etc.
881 892
882 if ( isspace(ch) ) return ' '; 893 if ( isspace(ch) ) return ' ';
883 894
884 static const char *word_characters = ":@-./_~"; 895 static const char *word_characters = ":@-./_~";
885 if ( isalnum(ch) || strchr(word_characters, ch) ) 896 if ( isalnum(ch) || strchr(word_characters, ch) )
886 return 'a'; 897 return 'a';
887 898
888 // Everything else is weird 899 // Everything else is weird
889 return 1; 900 return 1;
890} 901}
891 902
892void TEWidget::setMouseMarks(bool on) 903void TEWidget::setMouseMarks(bool on)
893{ 904{
894 mouse_marks = on; 905 mouse_marks = on;
895 setCursor( mouse_marks ? ibeamCursor : arrowCursor ); 906 setCursor( mouse_marks ? ibeamCursor : arrowCursor );
896} 907}
897 908
898/* ------------------------------------------------------------------------- */ 909/* ------------------------------------------------------------------------- */
899/* */ 910/* */
900/* Clipboard */ 911/* Clipboard */
901/* */ 912/* */
902/* ------------------------------------------------------------------------- */ 913/* ------------------------------------------------------------------------- */
903 914
904#undef KeyPress 915#undef KeyPress
905 916
906void TEWidget::emitSelection() 917void TEWidget::emitSelection()
907// Paste Clipboard by simulating keypress events 918// Paste Clipboard by simulating keypress events
908{ 919{
909#ifndef QT_NO_CLIPBOARD 920#ifndef QT_NO_CLIPBOARD
910 QString text = QApplication::clipboard()->text(); 921 QString text = QApplication::clipboard()->text();
911 if ( ! text.isNull() ) 922 if ( ! text.isNull() )
912 { 923 {
913 text.replace(QRegExp("\n"), "\r"); 924 text.replace(QRegExp("\n"), "\r");
914 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); 925 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text);
915 emit keyPressedSignal(&e); // expose as a big fat keypress event 926 emit keyPressedSignal(&e); // expose as a big fat keypress event
916 emit clearSelectionSignal(); 927 emit clearSelectionSignal();
917 } 928 }
918#endif 929#endif
919} 930}
920 931
921void TEWidget::emitText(QString text) 932void TEWidget::emitText(QString text)
922{ 933{
923 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); 934 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text);
924 emit keyPressedSignal(&e); // expose as a big fat keypress event 935 emit keyPressedSignal(&e); // expose as a big fat keypress event
925} 936}
926 937
927void TEWidget::pasteClipboard( ) 938void TEWidget::pasteClipboard( )
928{ 939{
929 emitSelection(); 940 emitSelection();
930} 941}
931 942
932void TEWidget::setSelection(const QString& t) 943void TEWidget::setSelection(const QString& t)
933{ 944{
934#ifndef QT_NO_CLIPBOARD 945#ifndef QT_NO_CLIPBOARD
935 // Disconnect signal while WE set the clipboard 946 // Disconnect signal while WE set the clipboard
936 QObject *cb = QApplication::clipboard(); 947 QObject *cb = QApplication::clipboard();
937 QObject::disconnect( cb, SIGNAL(dataChanged()), 948 QObject::disconnect( cb, SIGNAL(dataChanged()),
938 this, SLOT(onClearSelection()) ); 949 this, SLOT(onClearSelection()) );
939 950
940 QApplication::clipboard()->setText(t); 951 QApplication::clipboard()->setText(t);
941 952
942 QObject::connect( cb, SIGNAL(dataChanged()), 953 QObject::connect( cb, SIGNAL(dataChanged()),
943 this, SLOT(onClearSelection()) ); 954 this, SLOT(onClearSelection()) );
944#endif 955#endif
945} 956}
946 957
947void TEWidget::onClearSelection() 958void TEWidget::onClearSelection()
948{ 959{
949 emit clearSelectionSignal(); 960 emit clearSelectionSignal();
950} 961}
951 962
952/* ------------------------------------------------------------------------- */ 963/* ------------------------------------------------------------------------- */
953/* */ 964/* */
954/* Keyboard */ 965/* Keyboard */
955/* */ 966/* */
956/* ------------------------------------------------------------------------- */ 967/* ------------------------------------------------------------------------- */
957 968
958//FIXME: an `eventFilter' has been installed instead of a `keyPressEvent' 969//FIXME: an `eventFilter' has been installed instead of a `keyPressEvent'
959// due to a bug in `QT' or the ignorance of the author to prevent 970// due to a bug in `QT' or the ignorance of the author to prevent
960// repaint events being emitted to the screen whenever one leaves 971// repaint events being emitted to the screen whenever one leaves
961// or reenters the screen to/from another application. 972// or reenters the screen to/from another application.
962// 973//
963// Troll says one needs to change focusInEvent() and focusOutEvent(), 974// Troll says one needs to change focusInEvent() and focusOutEvent(),
964// which would also let you have an in-focus cursor and an out-focus 975// which would also let you have an in-focus cursor and an out-focus
965// cursor like xterm does. 976// cursor like xterm does.
966 977
967// for the auto-hide cursor feature, I added empty focusInEvent() and 978// for the auto-hide cursor feature, I added empty focusInEvent() and
968// focusOutEvent() so that update() isn't called. 979// focusOutEvent() so that update() isn't called.
969// For auto-hide, we need to get keypress-events, but we only get them when 980// For auto-hide, we need to get keypress-events, but we only get them when
970// we have focus. 981// we have focus.
971 982
972void TEWidget::doScroll(int lines) 983void TEWidget::doScroll(int lines)
973{ 984{
974 scrollbar->setValue(scrollbar->value()+lines); 985 scrollbar->setValue(scrollbar->value()+lines);
975} 986}
976 987
977bool TEWidget::eventFilter( QObject *obj, QEvent *e ) 988bool TEWidget::eventFilter( QObject *obj, QEvent *e )
978{ 989{
979 if ( (e->type() == QEvent::Accel || 990 if ( (e->type() == QEvent::Accel ||
980 e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) { 991 e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) {
981 static_cast<QKeyEvent *>( e )->ignore(); 992 static_cast<QKeyEvent *>( e )->ignore();
982 return true; 993 return true;
983 } 994 }
984 if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) 995 if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ )
985 return FALSE; // not us 996 return FALSE; // not us
986 if ( e->type() == QEvent::Wheel) { 997 if ( e->type() == QEvent::Wheel) {
987 QApplication::sendEvent(scrollbar, e); 998 QApplication::sendEvent(scrollbar, e);
988 } 999 }
989 1000
990#ifdef FAKE_CTRL_AND_ALT 1001#ifdef FAKE_CTRL_AND_ALT
991 static bool control = FALSE; 1002 static bool control = FALSE;
992 static bool alt = FALSE; 1003 static bool alt = FALSE;
993// qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:"); 1004// qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:");
994 bool dele=FALSE; 1005 bool dele=FALSE;
995 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 1006 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
996 QKeyEvent* ke = (QKeyEvent*)e; 1007 QKeyEvent* ke = (QKeyEvent*)e;
997 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); 1008 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat();
998 switch (ke->key()) { 1009 switch (ke->key()) {
999 case Key_F9: // let this be "Control" 1010 case Key_F9: // let this be "Control"
1000 control = keydown; 1011 control = keydown;
1001 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); 1012 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state());
1002 dele=TRUE; 1013 dele=TRUE;
1003 break; 1014 break;
1004 case Key_F13: // let this be "Alt" 1015 case Key_F13: // let this be "Alt"
1005 alt = keydown; 1016 alt = keydown;
1006 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); 1017 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state());
1007 dele=TRUE; 1018 dele=TRUE;
1008 break; 1019 break;
1009 default: 1020 default:
1010 if ( control ) { 1021 if ( control ) {
1011 int a = toupper(ke->ascii())-64; 1022 int a = toupper(ke->ascii())-64;
1012 if ( a >= 0 && a < ' ' ) { 1023 if ( a >= 0 && a < ' ' ) {
1013 e = new QKeyEvent(e->type(), ke->key(), 1024 e = new QKeyEvent(e->type(), ke->key(),
1014 a, ke->state()|ControlButton, QChar(a,0)); 1025 a, ke->state()|ControlButton, QChar(a,0));
1015 dele=TRUE; 1026 dele=TRUE;
1016 } 1027 }
1017 } 1028 }
1018 if ( alt ) { 1029 if ( alt ) {
1019 e = new QKeyEvent(e->type(), ke->key(), 1030 e = new QKeyEvent(e->type(), ke->key(),
1020 ke->ascii(), ke->state()|AltButton, ke->text()); 1031 ke->ascii(), ke->state()|AltButton, ke->text());
1021 dele=TRUE; 1032 dele=TRUE;
1022 } 1033 }
1023 } 1034 }
1024 } 1035 }
1025#endif 1036#endif
1026 1037
1027 if ( e->type() == QEvent::KeyPress ) { 1038 if ( e->type() == QEvent::KeyPress ) {
1028 QKeyEvent* ke = (QKeyEvent*)e; 1039 QKeyEvent* ke = (QKeyEvent*)e;
1029 actSel=0; // Key stroke implies a screen update, so TEWidget won't 1040 actSel=0; // Key stroke implies a screen update, so TEWidget won't
1030 // know where the current selection is. 1041 // know where the current selection is.
1031 1042
1032// qDebug("key pressed is 0x%x",ke->key()); 1043// qDebug("key pressed is 0x%x",ke->key());
1033 1044
1034 if( ke->state() == ShiftButton && ke->key() == Key_Tab) { //lets hardcode this sucker 1045 if( ke->state() == ShiftButton && ke->key() == Key_Tab) { //lets hardcode this sucker
1035 1046
1036// qDebug("key pressed 2 is 0x%x",ke->key()); 1047// qDebug("key pressed 2 is 0x%x",ke->key());
1037 emitText("\\"); // expose 1048 emitText("\\"); // expose
1038 } else 1049 } else
1039 emit keyPressedSignal(ke); // expose 1050 emit keyPressedSignal(ke); // expose
1040 ke->accept(); 1051 ke->accept();
1041#ifdef FAKE_CTRL_AND_ALT 1052#ifdef FAKE_CTRL_AND_ALT
1042 if ( dele ) delete e; 1053 if ( dele ) delete e;
1043#endif 1054#endif
1044 return true; // stop the event 1055 return true; // stop the event
1045 } 1056 }
1046 if ( e->type() == QEvent::Enter ) { 1057 if ( e->type() == QEvent::Enter ) {
1047 QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()), 1058 QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()),
1048 this, SLOT(onClearSelection()) ); 1059 this, SLOT(onClearSelection()) );
1049 } 1060 }
1050 if ( e->type() == QEvent::Leave ) { 1061 if ( e->type() == QEvent::Leave ) {
1051 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), 1062 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()),
1052 this, SLOT(onClearSelection()) ); 1063 this, SLOT(onClearSelection()) );
1053 } 1064 }
1054 return QFrame::eventFilter( obj, e ); 1065 return QFrame::eventFilter( obj, e );
1055} 1066}
1056 1067
1057/* ------------------------------------------------------------------------- */ 1068/* ------------------------------------------------------------------------- */
1058/* */ 1069/* */
1059/* Frame */ 1070/* Frame */
1060/* */ 1071/* */
1061/* ------------------------------------------------------------------------- */ 1072/* ------------------------------------------------------------------------- */
1062 1073
1063void TEWidget::frameChanged() 1074void TEWidget::frameChanged()
1064{ 1075{
1065 propagateSize(); 1076 propagateSize();
1066 update(); 1077 update();
1067} 1078}
1068 1079
1069/* ------------------------------------------------------------------------- */ 1080/* ------------------------------------------------------------------------- */
1070/* */ 1081/* */
1071/* Sound */ 1082/* Sound */
1072/* */ 1083/* */
1073/* ------------------------------------------------------------------------- */ 1084/* ------------------------------------------------------------------------- */
1074 1085
1075void TEWidget::Bell() 1086void TEWidget::Bell()
1076{ 1087{
1077 QApplication::beep(); 1088 QApplication::beep();
1078} 1089}
1079 1090
1080/* ------------------------------------------------------------------------- */ 1091/* ------------------------------------------------------------------------- */
1081/* */ 1092/* */
1082/* Auxiluary */ 1093/* Auxiluary */
1083/* */ 1094/* */
1084/* ------------------------------------------------------------------------- */ 1095/* ------------------------------------------------------------------------- */
1085 1096
1086void TEWidget::clearImage() 1097void TEWidget::clearImage()
1087// initialize the image 1098// initialize the image
1088// for internal use only 1099// for internal use only
1089{ 1100{
1090 for (int y = 0; y < lines; y++) 1101 for (int y = 0; y < lines; y++)
1091 for (int x = 0; x < columns; x++) 1102 for (int x = 0; x < columns; x++)
1092 { 1103 {
1093 image[loc(x,y)].c = 0xff; //' '; 1104 image[loc(x,y)].c = 0xff; //' ';
1094 image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR; 1105 image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR;
1095 image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR; 1106 image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR;
1096 image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION; 1107 image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION;
1097 } 1108 }
1098} 1109}
1099 1110
1100// Create Image /////////////////////////////////////////////////////// 1111// Create Image ///////////////////////////////////////////////////////
1101 1112
1102void TEWidget::calcGeometry() 1113void TEWidget::calcGeometry()
1103{ 1114{
1104 //FIXME: set rimX == rimY == 0 when running in full screen mode. 1115 //FIXME: set rimX == rimY == 0 when running in full screen mode.
1105 1116
1106 scrollbar->resize(QApplication::style().scrollBarExtent().width(), 1117 scrollbar->resize(QApplication::style().scrollBarExtent().width(),
1107 contentsRect().height()); 1118 contentsRect().height());
1108 switch(scrollLoc) 1119 switch(scrollLoc)
1109 { 1120 {
1110 case SCRNONE : 1121 case SCRNONE :
1111 columns = ( contentsRect().width() - 2 * rimX ) / font_w; 1122 columns = ( contentsRect().width() - 2 * rimX ) / font_w;
1112 blX = (contentsRect().width() - (columns*font_w) ) / 2; 1123 blX = (contentsRect().width() - (columns*font_w) ) / 2;
1113 brX = blX; 1124 brX = blX;
1114 scrollbar->hide(); 1125 scrollbar->hide();
1115 break; 1126 break;
1116 case SCRLEFT : 1127 case SCRLEFT :
1117 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; 1128 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w;
1118 brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; 1129 brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2;
1119 blX = brX + scrollbar->width(); 1130 blX = brX + scrollbar->width();
1120 scrollbar->move(contentsRect().topLeft()); 1131 scrollbar->move(contentsRect().topLeft());
1121 scrollbar->show(); 1132 scrollbar->show();
1122 break; 1133 break;
1123 case SCRRIGHT: 1134 case SCRRIGHT:
1124 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; 1135 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w;
1125 blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; 1136 blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2;
1126 brX = blX; 1137 brX = blX;
1127 scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0)); 1138 scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0));
1128 scrollbar->show(); 1139 scrollbar->show();
1129 break; 1140 break;
1130 } 1141 }
1131 //FIXME: support 'rounding' styles 1142 //FIXME: support 'rounding' styles
1132 lines = ( contentsRect().height() - 2 * rimY ) / font_h; 1143 lines = ( contentsRect().height() - 2 * rimY ) / font_h;
1133 bY = (contentsRect().height() - (lines *font_h)) / 2; 1144 bY = (contentsRect().height() - (lines *font_h)) / 2;
1134} 1145}
1135 1146
1136void TEWidget::makeImage() 1147void TEWidget::makeImage()
1137//FIXME: rename 'calcGeometry? 1148//FIXME: rename 'calcGeometry?
1138{ 1149{
1139 calcGeometry(); 1150 calcGeometry();
1140 image = (ca*) malloc(lines*columns*sizeof(ca)); 1151 image = (ca*) malloc(lines*columns*sizeof(ca));
1141 clearImage(); 1152 clearImage();
1142} 1153}
1143 1154
1144// calculate the needed size 1155// calculate the needed size
1145QSize TEWidget::calcSize(int cols, int lins) const 1156QSize TEWidget::calcSize(int cols, int lins) const
1146{ 1157{
1147 int frw = width() - contentsRect().width(); 1158 int frw = width() - contentsRect().width();
1148 int frh = height() - contentsRect().height(); 1159 int frh = height() - contentsRect().height();
1149 int scw = (scrollLoc==SCRNONE?0:scrollbar->width()); 1160 int scw = (scrollLoc==SCRNONE?0:scrollbar->width());
1150 return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh ); 1161 return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh );
1151} 1162}
1152 1163
1153QSize TEWidget::sizeHint() const 1164QSize TEWidget::sizeHint() const
1154{ 1165{
1155 return size(); 1166 return size();
1156} 1167}
1157 1168
1158void TEWidget::styleChange(QStyle &) 1169void TEWidget::styleChange(QStyle &)
1159{ 1170{
1160 propagateSize(); 1171 propagateSize();
1161} 1172}
1162 1173
1163#ifndef QT_NO_DRAGANDDROP 1174#ifndef QT_NO_DRAGANDDROP
1164 1175
1165/* --------------------------------------------------------------------- */ 1176/* --------------------------------------------------------------------- */
1166/* */ 1177/* */
1167/* Drag & Drop */ 1178/* Drag & Drop */
1168/* */ 1179/* */
1169/* --------------------------------------------------------------------- */ 1180/* --------------------------------------------------------------------- */
1170 1181
1171 1182
1172void TEWidget::dragEnterEvent(QDragEnterEvent* e) 1183void TEWidget::dragEnterEvent(QDragEnterEvent* e)
1173{ 1184{
1174 e->accept(QTextDrag::canDecode(e) || 1185 e->accept(QTextDrag::canDecode(e) ||
1175 QUriDrag::canDecode(e)); 1186 QUriDrag::canDecode(e));
1176} 1187}
1177 1188
1178void TEWidget::dropEvent(QDropEvent* event) 1189void TEWidget::dropEvent(QDropEvent* event)
1179{ 1190{
1180 // The current behaviour when url(s) are dropped is 1191 // The current behaviour when url(s) are dropped is
1181 // * if there is only ONE url and if it's a LOCAL one, ask for paste or cd 1192 // * if there is only ONE url and if it's a LOCAL one, ask for paste or cd
1182 // * in all other cases, just paste 1193 // * in all other cases, just paste
1183 // (for non-local ones, or for a list of URLs, 'cd' is nonsense) 1194 // (for non-local ones, or for a list of URLs, 'cd' is nonsense)
1184 QStrList strlist; 1195 QStrList strlist;
1185 int file_count = 0; 1196 int file_count = 0;
1186 dropText = ""; 1197 dropText = "";
1187 bool bPopup = true; 1198 bool bPopup = true;
1188 1199
1189 if(QUriDrag::decode(event, strlist)) { 1200 if(QUriDrag::decode(event, strlist)) {
1190 if (strlist.count()) { 1201 if (strlist.count()) {
1191 for(const char* p = strlist.first(); p; p = strlist.next()) { 1202 for(const char* p = strlist.first(); p; p = strlist.next()) {
1192 if(file_count++ > 0) { 1203 if(file_count++ > 0) {
1193 dropText += " "; 1204 dropText += " ";
1194 bPopup = false; // more than one file, don't popup 1205 bPopup = false; // more than one file, don't popup
1195 } 1206 }
1196 1207
1197/* 1208/*
1198 KURL url(p); 1209 KURL url(p);
1199 if (url.isLocalFile()) { 1210 if (url.isLocalFile()) {
1200 dropText += url.path(); // local URL : remove protocol 1211 dropText += url.path(); // local URL : remove protocol
1201 } 1212 }
1202 else { 1213 else {
1203 dropText += url.prettyURL(); 1214 dropText += url.prettyURL();
1204 bPopup = false; // a non-local file, don't popup 1215 bPopup = false; // a non-local file, don't popup
1205 } 1216 }
1206*/ 1217*/
1207 1218
1208 } 1219 }
1209 1220
1210 if (bPopup) 1221 if (bPopup)
1211 // m_drop->popup(pos() + event->pos()); 1222 // m_drop->popup(pos() + event->pos());
1212 m_drop->popup(mapToGlobal(event->pos())); 1223 m_drop->popup(mapToGlobal(event->pos()));
1213 else 1224 else
1214 { 1225 {
1215 if (currentSession) { 1226 if (currentSession) {
1216 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1227 currentSession->getEmulation()->sendString(dropText.local8Bit());
1217 } 1228 }
1218// kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; 1229// kdDebug() << "Drop:" << dropText.local8Bit() << "\n";
1219 } 1230 }
1220 } 1231 }
1221 } 1232 }
1222 else if(QTextDrag::decode(event, dropText)) { 1233 else if(QTextDrag::decode(event, dropText)) {
1223// kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; 1234// kdDebug() << "Drop:" << dropText.local8Bit() << "\n";
1224 if (currentSession) { 1235 if (currentSession) {
1225 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1236 currentSession->getEmulation()->sendString(dropText.local8Bit());
1226 } 1237 }
1227 // Paste it 1238 // Paste it
1228 } 1239 }
1229} 1240}
1230#endif 1241#endif
1231 1242
1232 1243
1233void TEWidget::drop_menu_activated(int item) 1244void TEWidget::drop_menu_activated(int item)
1234{ 1245{
1235#ifndef QT_NO_DRAGANDDROP 1246#ifndef QT_NO_DRAGANDDROP
1236 switch (item) 1247 switch (item)
1237 { 1248 {
1238 case 0: // paste 1249 case 0: // paste
1239 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1250 currentSession->getEmulation()->sendString(dropText.local8Bit());
1240// KWM::activate((Window)this->winId()); 1251// KWM::activate((Window)this->winId());
1241 break; 1252 break;
1242 case 1: // cd ... 1253 case 1: // cd ...
1243 currentSession->getEmulation()->sendString("cd "); 1254 currentSession->getEmulation()->sendString("cd ");
1244 struct stat statbuf; 1255 struct stat statbuf;
1245 if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 ) 1256 if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 )
1246 { 1257 {
1247 if ( !S_ISDIR(statbuf.st_mode) ) 1258 if ( !S_ISDIR(statbuf.st_mode) )
1248 { 1259 {
1249/* 1260/*
1250 KURL url; 1261 KURL url;
1251 url.setPath( dropText ); 1262 url.setPath( dropText );
1252 dropText = url.directory( true, false ); // remove filename 1263 dropText = url.directory( true, false ); // remove filename
1253*/ 1264*/
1254 } 1265 }
1255 } 1266 }
1256 dropText.replace(QRegExp(" "), "\\ "); // escape spaces 1267 dropText.replace(QRegExp(" "), "\\ "); // escape spaces
1257 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1268 currentSession->getEmulation()->sendString(dropText.local8Bit());
1258 currentSession->getEmulation()->sendString("\n"); 1269 currentSession->getEmulation()->sendString("\n");
1259// KWM::activate((Window)this->winId()); 1270// KWM::activate((Window)this->winId());
1260 break; 1271 break;
1261 } 1272 }
1262#endif 1273#endif
1263} 1274}
1264 1275
1276QPushButton* TEWidget::cornerButton() {
1277 return m_cornerButton;
1278}
diff --git a/noncore/apps/opie-console/TEWidget.h b/noncore/apps/opie-console/TEWidget.h
index 40e1aea..1b5300f 100644
--- a/noncore/apps/opie-console/TEWidget.h
+++ b/noncore/apps/opie-console/TEWidget.h
@@ -1,202 +1,228 @@
1/* ----------------------------------------------------------------------- */ 1/* ----------------------------------------------------------------------- */
2/* */ 2/* */
3/* [te_widget.h] Terminal Emulation Widget */ 3/* [te_widget.h] 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#ifndef TE_WIDGET_H 18#ifndef TE_WIDGET_H
19#define TE_WIDGET_H 19#define TE_WIDGET_H
20 20
21#include <qwidget.h> 21#include <qwidget.h>
22#include <qlabel.h> 22#include <qlabel.h>
23#include <qtimer.h> 23#include <qtimer.h>
24#include <qcolor.h> 24#include <qcolor.h>
25#include <qkeycode.h> 25#include <qkeycode.h>
26#include <qscrollbar.h> 26#include <qscrollbar.h>
27 27
28#include <qpopupmenu.h> 28#include <qpopupmenu.h>
29#include <qpushbutton.h>
29 30
30#include "TECommon.h" 31#include "TECommon.h"
31 32
32extern unsigned short vt100_graphics[32]; 33extern unsigned short vt100_graphics[32];
33 34
35
36
37static char * menu_xpm[] = {
38"12 12 5 1",
39 " c None",
40 ".c #000000",
41 "+c #FFFDAD",
42 "@c #FFFF00",
43 "#c #E5E100",
44" ",
45" ",
46" ......... ",
47" .+++++++. ",
48" .+@@@@#. ",
49" .+@@@#. ",
50" .+@@#. ",
51" .+@#. ",
52" .+#. ",
53" .+. ",
54" .. ",
55" "};
56
34class TESession; 57class TESession;
35 58
36// class Konsole; 59// class Konsole;
37 60
38class TEWidget : public QFrame 61class TEWidget : public QFrame
39// a widget representing attributed text 62// a widget representing attributed text
40{ Q_OBJECT 63{
64 Q_OBJECT
41 65
42// friend class Konsole; 66// friend class Konsole;
43 67
44public: 68public:
45 69
46 TEWidget(QWidget *parent=0, const char *name=0); 70 TEWidget(QWidget *parent=0, const char *name=0);
47 virtual ~TEWidget(); 71 virtual ~TEWidget();
48 72
49public: 73public:
50 74
51 QColor getDefaultBackColor(); 75 QColor getDefaultBackColor();
76 QPushButton *cornerButton();
52 77
53 const ColorEntry* getColorTable() const; 78 const ColorEntry* getColorTable() const;
54 const ColorEntry* getdefaultColorTable() const; 79 const ColorEntry* getdefaultColorTable() const;
55 void setColorTable(const ColorEntry table[]); 80 void setColorTable(const ColorEntry table[]);
56 81
57 void setScrollbarLocation(int loc); 82 void setScrollbarLocation(int loc);
58 enum { SCRNONE=0, SCRLEFT=1, SCRRIGHT=2 }; 83 enum { SCRNONE=0, SCRLEFT=1, SCRRIGHT=2 };
59 84
60 void setScroll(int cursor, int lines); 85 void setScroll(int cursor, int lines);
61 void doScroll(int lines); 86 void doScroll(int lines);
62 87
63 void emitSelection(); 88 void emitSelection();
64 89
65public: 90public:
66 91
67 void setImage(const ca* const newimg, int lines, int columns); 92 void setImage(const ca* const newimg, int lines, int columns);
68 93
69 int Lines() { return lines; } 94 int Lines() { return lines; }
70 int Columns() { return columns; } 95 int Columns() { return columns; }
71 96
72 void calcGeometry(); 97 void calcGeometry();
73 void propagateSize(); 98 void propagateSize();
74 QSize calcSize(int cols, int lins) const; 99 QSize calcSize(int cols, int lins) const;
75 100
76 QSize sizeHint() const; 101 QSize sizeHint() const;
77 102
78public: 103public:
79 104
80 void Bell(); 105 void Bell();
81 void emitText(QString text); 106 void emitText(QString text);
82 void pasteClipboard(); 107 void pasteClipboard();
83 108
84signals: 109signals:
85 110
86 void keyPressedSignal(QKeyEvent *e); 111 void keyPressedSignal(QKeyEvent *e);
87 void mouseSignal(int cb, int cx, int cy); 112 void mouseSignal(int cb, int cx, int cy);
88 void changedImageSizeSignal(int lines, int columns); 113 void changedImageSizeSignal(int lines, int columns);
89 void changedHistoryCursor(int value); 114 void changedHistoryCursor(int value);
90 void configureRequest( TEWidget*, int state, int x, int y ); 115 void configureRequest( TEWidget*, int state, int x, int y );
91 116
92 void clearSelectionSignal(); 117 void clearSelectionSignal();
93 void beginSelectionSignal( const int x, const int y ); 118 void beginSelectionSignal( const int x, const int y );
94 void extendSelectionSignal( const int x, const int y ); 119 void extendSelectionSignal( const int x, const int y );
95 void endSelectionSignal(const BOOL preserve_line_breaks); 120 void endSelectionSignal(const BOOL preserve_line_breaks);
96 121
97 122
98protected: 123protected:
99 124
100 virtual void styleChange( QStyle& ); 125 virtual void styleChange( QStyle& );
101 126
102 bool eventFilter( QObject *, QEvent * ); 127 bool eventFilter( QObject *, QEvent * );
103 128
104 void drawAttrStr(QPainter &paint, QRect rect, 129 void drawAttrStr(QPainter &paint, QRect rect,
105 QString& str, ca attr, BOOL pm, BOOL clear); 130 QString& str, ca attr, BOOL pm, BOOL clear);
106 void paintEvent( QPaintEvent * ); 131 void paintEvent( QPaintEvent * );
107 132
108 void resizeEvent(QResizeEvent*); 133 void resizeEvent(QResizeEvent*);
109 134
110 void fontChange(const QFont &font); 135 void fontChange(const QFont &font);
111 void frameChanged(); 136 void frameChanged();
112 137
113 void mouseDoubleClickEvent(QMouseEvent* ev); 138 void mouseDoubleClickEvent(QMouseEvent* ev);
114 void mousePressEvent( QMouseEvent* ); 139 void mousePressEvent( QMouseEvent* );
115 void mouseReleaseEvent( QMouseEvent* ); 140 void mouseReleaseEvent( QMouseEvent* );
116 void mouseMoveEvent( QMouseEvent* ); 141 void mouseMoveEvent( QMouseEvent* );
117 142
118 void focusInEvent( QFocusEvent * ); 143 void focusInEvent( QFocusEvent * );
119 void focusOutEvent( QFocusEvent * ); 144 void focusOutEvent( QFocusEvent * );
120 bool focusNextPrevChild( bool next ); 145 bool focusNextPrevChild( bool next );
121 146
122#ifndef QT_NO_DRAGANDDROP 147#ifndef QT_NO_DRAGANDDROP
123 // Dnd 148 // Dnd
124 void dragEnterEvent(QDragEnterEvent* event); 149 void dragEnterEvent(QDragEnterEvent* event);
125 void dropEvent(QDropEvent* event); 150 void dropEvent(QDropEvent* event);
126#endif 151#endif
127 152
128 virtual int charClass(char) const; 153 virtual int charClass(char) const;
129 154
130 void clearImage(); 155 void clearImage();
131 156
132public: 157public:
133 const QPixmap *backgroundPixmap(); 158 const QPixmap *backgroundPixmap();
134 159
135 void setSelection(const QString &t); 160 void setSelection(const QString &t);
136 161
137 virtual void setFont(const QFont &); 162 virtual void setFont(const QFont &);
138 void setVTFont(const QFont &); 163 void setVTFont(const QFont &);
139 QFont getVTFont(); 164 QFont getVTFont();
140 165
141 void setMouseMarks(bool on); 166 void setMouseMarks(bool on);
142 167
143public slots: 168public slots:
144 169
145 void onClearSelection(); 170 void onClearSelection();
146 171
147protected slots: 172protected slots:
148 173
149 void scrollChanged(int value); 174 void scrollChanged(int value);
150 void blinkEvent(); 175 void blinkEvent();
151 176
152private: 177private:
153 178
154 QChar (*fontMap)(QChar); // possible vt100 font extention 179 QChar (*fontMap)(QChar); // possible vt100 font extention
155 180
156 bool fixed_font; // has fixed pitch 181 bool fixed_font; // has fixed pitch
157 int font_h; // height 182 int font_h; // height
158 int font_w; // width 183 int font_w; // width
159 int font_a; // ascend 184 int font_a; // ascend
160 185
161 int blX; // actual offset (left) 186 int blX; // actual offset (left)
162 int brX; // actual offset (right) 187 int brX; // actual offset (right)
163 int bY; // actual offset 188 int bY; // actual offset
164 189
165 int lines; 190 int lines;
166 int columns; 191 int columns;
167 ca *image; // [lines][columns] 192 ca *image; // [lines][columns]
168 193
169 ColorEntry color_table[TABLE_COLORS]; 194 ColorEntry color_table[TABLE_COLORS];
170 195
171 BOOL resizing; 196 BOOL resizing;
172 bool mouse_marks; 197 bool mouse_marks;
173 198
174 void makeImage(); 199 void makeImage();
175 200
176 QPoint iPntSel; // initial selection point 201 QPoint iPntSel; // initial selection point
177 QPoint pntSel; // current selection point 202 QPoint pntSel; // current selection point
178 int actSel; // selection state 203 int actSel; // selection state
179 BOOL word_selection_mode; 204 BOOL word_selection_mode;
180 BOOL preserve_line_breaks; 205 BOOL preserve_line_breaks;
181 206
207 QPushButton *m_cornerButton;
182 QClipboard* cb; 208 QClipboard* cb;
183 QScrollBar* scrollbar; 209 QScrollBar* scrollbar;
184 int scrollLoc; 210 int scrollLoc;
185 211
186//#define SCRNONE 0 212//#define SCRNONE 0
187//#define SCRLEFT 1 213//#define SCRLEFT 1
188//#define SCRRIGHT 2 214//#define SCRRIGHT 2
189 215
190 BOOL blinking; // hide text in paintEvent 216 BOOL blinking; // hide text in paintEvent
191 BOOL hasBlinker; // has characters to blink 217 BOOL hasBlinker; // has characters to blink
192 QTimer* blinkT; // active when hasBlinker 218 QTimer* blinkT; // active when hasBlinker
193 QPopupMenu* m_drop; 219 QPopupMenu* m_drop;
194 QString dropText; 220 QString dropText;
195 public: 221 public:
196 // current session in this widget 222 // current session in this widget
197 TESession *currentSession; 223 TESession *currentSession;
198private slots: 224private slots:
199 void drop_menu_activated(int item); 225 void drop_menu_activated(int item);
200}; 226};
201 227
202#endif // TE_WIDGET_H 228#endif // TE_WIDGET_H
diff --git a/noncore/apps/opie-console/emulation_handler.cpp b/noncore/apps/opie-console/emulation_handler.cpp
index b2cd348..8846959 100644
--- a/noncore/apps/opie-console/emulation_handler.cpp
+++ b/noncore/apps/opie-console/emulation_handler.cpp
@@ -1,142 +1,147 @@
1#include <qwidget.h> 1#include <qwidget.h>
2#include <qpushbutton.h>
2 3
3#include "TEWidget.h" 4#include "TEWidget.h"
4#include "TEmuVt102.h" 5#include "TEmuVt102.h"
5 6
6#include "profile.h" 7#include "profile.h"
7#include "emulation_handler.h" 8#include "emulation_handler.h"
8 9
9 10
10EmulationHandler::EmulationHandler( const Profile& prof, QWidget* parent,const char* name ) 11EmulationHandler::EmulationHandler( const Profile& prof, QWidget* parent,const char* name )
11 : QObject(0, name ) 12 : QObject(0, name )
12{ 13{
13 m_teWid = new TEWidget( parent, "TerminalMain"); 14 m_teWid = new TEWidget( parent, "TerminalMain");
14 m_teWid->setMinimumSize(150, 70 ); 15 m_teWid->setMinimumSize(150, 70 );
15 parent->resize( m_teWid->calcSize(80, 24 ) ); 16 parent->resize( m_teWid->calcSize(80, 24 ) );
16 m_teEmu = new TEmuVt102(m_teWid ); 17 m_teEmu = new TEmuVt102(m_teWid );
17 18
18 connect(m_teEmu,SIGNAL(ImageSizeChanged(int, int) ), 19 connect(m_teEmu,SIGNAL(ImageSizeChanged(int, int) ),
19 this, SIGNAL(changeSize(int, int) ) ); 20 this, SIGNAL(changeSize(int, int) ) );
20 connect(m_teEmu, SIGNAL(sndBlock(const char*, int) ), 21 connect(m_teEmu, SIGNAL(sndBlock(const char*, int) ),
21 this, SLOT(recvEmulation(const char*, int) ) ); 22 this, SLOT(recvEmulation(const char*, int) ) );
22 m_teEmu->setConnect( true ); 23 m_teEmu->setConnect( true );
23 m_teEmu->setHistory( TRUE ); 24 m_teEmu->setHistory( TRUE );
24 load( prof ); 25 load( prof );
25 26
26 27
27 28
28} 29}
29EmulationHandler::~EmulationHandler() { 30EmulationHandler::~EmulationHandler() {
30 delete m_teEmu; 31 delete m_teEmu;
31 delete m_teWid; 32 delete m_teWid;
32} 33}
33void EmulationHandler::load( const Profile& prof) { 34void EmulationHandler::load( const Profile& prof) {
34 m_teWid->setVTFont( font( prof.readNumEntry("Font") ) ); 35 m_teWid->setVTFont( font( prof.readNumEntry("Font") ) );
35 int num = prof.readNumEntry("Color"); 36 int num = prof.readNumEntry("Color");
36 setColor( foreColor(num), backColor(num) ); 37 setColor( foreColor(num), backColor(num) );
37 m_teWid->setBackgroundColor(backColor(num) ); 38 m_teWid->setBackgroundColor(backColor(num) );
38} 39}
39void EmulationHandler::recv( const QByteArray& ar) { 40void EmulationHandler::recv( const QByteArray& ar) {
40 m_teEmu->onRcvBlock(ar.data(), ar.count() ); 41 m_teEmu->onRcvBlock(ar.data(), ar.count() );
41} 42}
42void EmulationHandler::recvEmulation(const char* src, int len ) { 43void EmulationHandler::recvEmulation(const char* src, int len ) {
43 QByteArray ar(len); 44 QByteArray ar(len);
44 45
45 memcpy(ar.data(), src, sizeof(char) * len ); 46 memcpy(ar.data(), src, sizeof(char) * len );
46 47
47 emit send(ar); 48 emit send(ar);
48} 49}
49QWidget* EmulationHandler::widget() { 50QWidget* EmulationHandler::widget() {
50 return m_teWid; 51 return m_teWid;
51} 52}
52/* 53/*
53 * allocate a new table of colors 54 * allocate a new table of colors
54 */ 55 */
55void EmulationHandler::setColor( const QColor& fore, const QColor& back ) { 56void EmulationHandler::setColor( const QColor& fore, const QColor& back ) {
56 ColorEntry table[TABLE_COLORS]; 57 ColorEntry table[TABLE_COLORS];
57 const ColorEntry *defaultCt = m_teWid->getdefaultColorTable(); 58 const ColorEntry *defaultCt = m_teWid->getdefaultColorTable();
58 59
59 for (int i = 0; i < TABLE_COLORS; i++ ) { 60 for (int i = 0; i < TABLE_COLORS; i++ ) {
60 if ( i == 0 || i == 10 ) { 61 if ( i == 0 || i == 10 ) {
61 table[i].color = fore; 62 table[i].color = fore;
62 }else if ( i == 1 || i == 11 ) { 63 }else if ( i == 1 || i == 11 ) {
63 table[i].color = back; 64 table[i].color = back;
64 table[i].transparent = 0; 65 table[i].transparent = 0;
65 }else { 66 }else {
66 table[i].color = defaultCt[i].color; 67 table[i].color = defaultCt[i].color;
67 } 68 }
68 } 69 }
69 m_teWid->setColorTable(table ); 70 m_teWid->setColorTable(table );
70 m_teWid->update(); 71 m_teWid->update();
71} 72}
72QFont EmulationHandler::font( int id ) { 73QFont EmulationHandler::font( int id ) {
73 QString name; 74 QString name;
74 int size = 0; 75 int size = 0;
75 switch(id ) { 76 switch(id ) {
76 default: // fall through 77 default: // fall through
77 case 0: 78 case 0:
78 name = QString::fromLatin1("Micro"); 79 name = QString::fromLatin1("Micro");
79 size = 4; 80 size = 4;
80 break; 81 break;
81 case 1: 82 case 1:
82 name = QString::fromLatin1("Fixed"); 83 name = QString::fromLatin1("Fixed");
83 size = 7; 84 size = 7;
84 break; 85 break;
85 case 2: 86 case 2:
86 name = QString::fromLatin1("Fixed"); 87 name = QString::fromLatin1("Fixed");
87 size = 12; 88 size = 12;
88 break; 89 break;
89 } 90 }
90 QFont font(name, size, QFont::Normal ); 91 QFont font(name, size, QFont::Normal );
91 font.setFixedPitch(TRUE ); 92 font.setFixedPitch(TRUE );
92 return font; 93 return font;
93} 94}
94QColor EmulationHandler::foreColor(int col) { 95QColor EmulationHandler::foreColor(int col) {
95 QColor co; 96 QColor co;
96 /* we need to switch it */ 97 /* we need to switch it */
97 switch( col ) { 98 switch( col ) {
98 default: 99 default:
99 case Profile::White: 100 case Profile::White:
100 /* color is black */ 101 /* color is black */
101 co = Qt::white; 102 co = Qt::white;
102 break; 103 break;
103 case Profile::Black: 104 case Profile::Black:
104 co = Qt::black; 105 co = Qt::black;
105 break; 106 break;
106 case Profile::Green: 107 case Profile::Green:
107 qWarning("Foreground green"); 108 qWarning("Foreground green");
108 co = Qt::green; 109 co = Qt::green;
109 break; 110 break;
110 case Profile::Orange: 111 case Profile::Orange:
111 qWarning("Foreground orange"); 112 qWarning("Foreground orange");
112 // FIXME needs better color here 113 // FIXME needs better color here
113 co = Qt::darkYellow; 114 co = Qt::darkYellow;
114 break; 115 break;
115 } 116 }
116 117
117 return co; 118 return co;
118} 119}
119QColor EmulationHandler::backColor(int col ) { 120QColor EmulationHandler::backColor(int col ) {
120 QColor co; 121 QColor co;
121 /* we need to switch it */ 122 /* we need to switch it */
122 switch( col ) { 123 switch( col ) {
123 default: 124 default:
124 case Profile::White: 125 case Profile::White:
125 /* color is white */ 126 /* color is white */
126 co = Qt::black; 127 co = Qt::black;
127 break; 128 break;
128 case Profile::Black: 129 case Profile::Black:
129 co = Qt::white; 130 co = Qt::white;
130 break; 131 break;
131 case Profile::Green: 132 case Profile::Green:
132 qWarning("Background black"); 133 qWarning("Background black");
133 co = Qt::black; 134 co = Qt::black;
134 break; 135 break;
135 case Profile::Orange: 136 case Profile::Orange:
136 qWarning("Background black"); 137 qWarning("Background black");
137 co = Qt::black; 138 co = Qt::black;
138 break; 139 break;
139 } 140 }
140 141
141 return co; 142 return co;
142} 143}
144
145QPushButton* EmulationHandler::cornerButton() {
146 return m_teWid->cornerButton();
147}
diff --git a/noncore/apps/opie-console/emulation_handler.h b/noncore/apps/opie-console/emulation_handler.h
index 9af7680..9ceafc6 100644
--- a/noncore/apps/opie-console/emulation_handler.h
+++ b/noncore/apps/opie-console/emulation_handler.h
@@ -1,70 +1,73 @@
1#ifndef OPIE_EMULATION_HANDLER_H 1#ifndef OPIE_EMULATION_HANDLER_H
2#define OPIE_EMULATION_HANDLER_H 2#define OPIE_EMULATION_HANDLER_H
3 3
4#include <qobject.h> 4#include <qobject.h>
5#include <qcolor.h> 5#include <qcolor.h>
6#include <qcstring.h> 6#include <qcstring.h>
7 7
8/* 8/*
9 * Badly ibotty lacks the time to finish 9 * Badly ibotty lacks the time to finish
10 * his widget in time.. 10 * his widget in time..
11 * Never the less we've to have an EmulationWidget 11 * Never the less we've to have an EmulationWidget
12 * This is why I'm taking the inferior not cleaned 12 * This is why I'm taking the inferior not cleaned
13 * up TE* KDE STUFF 13 * up TE* KDE STUFF
14 */ 14 */
15 15
16/** 16/**
17 * This is the layer above the IOLayer* 17 * This is the layer above the IOLayer*
18 * This nice QObject here will get stuff from 18 * This nice QObject here will get stuff from
19 * got a slot and a signal 19 * got a slot and a signal
20 * the signal for data 20 * the signal for data
21 * the slot for receiving 21 * the slot for receiving
22 * it'll set up the widget internally 22 * it'll set up the widget internally
23 * and manage the communication between 23 * and manage the communication between
24 * the pre QByteArray world! 24 * the pre QByteArray world!
25 */ 25 */
26class Profile; 26class Profile;
27class QWidget; 27class QWidget;
28class QPushButton;
28class TEWidget; 29class TEWidget;
29class TEmulation; 30class TEmulation;
30class QFont; 31class QFont;
31class EmulationHandler : public QObject { 32class EmulationHandler : public QObject {
32 Q_OBJECT 33 Q_OBJECT
33public: 34public:
34 /** 35 /**
35 * simple c'tor the parent of the TEWdiget 36 * simple c'tor the parent of the TEWdiget
36 * and a name 37 * and a name
37 * and a Profile 38 * and a Profile
38 */ 39 */
39 EmulationHandler( const Profile&, QWidget* parent, const char* name = 0l ); 40 EmulationHandler( const Profile&, QWidget* parent, const char* name = 0l );
40 41
41 /** 42 /**
42 * delete all components 43 * delete all components
43 */ 44 */
44 ~EmulationHandler(); 45 ~EmulationHandler();
45 46
46 void load( const Profile& ); 47 void load( const Profile& );
47 QWidget* widget(); 48 QWidget* widget();
48 void setColor( const QColor& fore, const QColor& back ); 49 void setColor( const QColor& fore, const QColor& back );
50 QPushButton* cornerButton();
51
49signals: 52signals:
50 void send( const QByteArray& ); 53 void send( const QByteArray& );
51 void changeSize(int rows, int cols ); 54 void changeSize(int rows, int cols );
52 55
53 56
54public slots: 57public slots:
55 void recv( const QByteArray& ); 58 void recv( const QByteArray& );
56 59
57private slots: 60private slots:
58 void recvEmulation( const char*, int len ); 61 void recvEmulation( const char*, int len );
59private: 62private:
60 QFont font( int ); 63 QFont font( int );
61 QColor foreColor(int ); 64 QColor foreColor(int );
62 QColor backColor(int ); 65 QColor backColor(int );
63 66
64private: 67private:
65 TEWidget* m_teWid; 68 TEWidget* m_teWid;
66 TEmulation* m_teEmu; 69 TEmulation* m_teEmu;
67 70
68}; 71};
69 72
70#endif 73#endif
diff --git a/noncore/apps/opie-console/io_bt.cpp b/noncore/apps/opie-console/io_bt.cpp
index d71aacc..4486eea 100644
--- a/noncore/apps/opie-console/io_bt.cpp
+++ b/noncore/apps/opie-console/io_bt.cpp
@@ -1,78 +1,77 @@
1 1
2#include "io_bt.h" 2#include "io_bt.h"
3 3
4IOBt::IOBt( const Profile &config ) : IOSerial( config ) { 4IOBt::IOBt( const Profile &config ) : IOSerial( config ) {
5 m_attach = 0; 5 m_attach = 0;
6} 6}
7 7
8 8
9IOBt::~IOBt() { 9IOBt::~IOBt() {
10 if ( m_attach ) { 10 if ( m_attach ) {
11 delete m_attach; 11 delete m_attach;
12 } 12 }
13} 13}
14 14
15 15
16void IOBt::close() { 16void IOBt::close() {
17 17
18 IOSerial::close(); 18 IOSerial::close();
19 // still need error handling 19 // still need error handling
20 if ( m_attach ) { 20 if ( m_attach ) {
21 delete m_attach; 21 delete m_attach;
22 m_attach = 0; 22 m_attach = 0;
23 } 23 }
24} 24}
25 25
26bool IOBt::open() { 26bool IOBt::open() {
27 27
28 // only set up bt stuff if mac address was set, otherwise use the device set 28 // only set up bt stuff if mac address was set, otherwise use the device set
29 if ( !m_mac.isEmpty() ) { 29 if ( !m_mac.isEmpty() ) {
30 30
31 // now it should also be checked, if there is a connection to the device with that mac allready 31 // now it should also be checked, if there is a connection to the device with that mac allready
32
33 // hciattach here 32 // hciattach here
34 m_attach = new OProcess(); 33 m_attach = new OProcess();
35 *m_attach << "hciattach /dev/ttyS2 any 57600"; 34 *m_attach << "hciattach /dev/ttyS2 any 57600";
36 35
37 // then start hcid, then rcfomm handling (m_mac) 36 // then start hcid, then rcfomm handling (m_mac)
38 37
39 connect( m_attach, SIGNAL( processExited( OProcess* ) ), 38 connect( m_attach, SIGNAL( processExited( OProcess* ) ),
40 this, SLOT( slotExited( OProcess* ) ) ); 39 this, SLOT( slotExited( OProcess* ) ) );
41 40
42 if ( m_attach->start() ) { 41 if ( m_attach->start() ) {
43 IOSerial::open(); 42 IOSerial::open();
44 } else { 43 } else {
45 qWarning("could not attach to device"); 44 qWarning("could not attach to device");
46 delete m_attach; 45 delete m_attach;
47 m_attach = 0; 46 m_attach = 0;
48 } 47 }
49 } else { 48 } else {
50 // directly to the normal serial 49 // directly to the normal serial
51 // TODO: look first if the connection really exists. ( is set up ) 50 // TODO: look first if the connection really exists. ( is set up )
52 51
53 IOSerial::open(); 52 IOSerial::open();
54 } 53 }
55} 54}
56 55
57void IOBt::reload( const Profile &config ) { 56void IOBt::reload( const Profile &config ) {
58 m_device = config.readEntry("Device", BT_DEFAULT_DEVICE); 57 m_device = config.readEntry("Device", BT_DEFAULT_DEVICE);
59 m_mac = config.readEntry("Mac", BT_DEFAULT_MAC); 58 m_mac = config.readEntry("Mac", BT_DEFAULT_MAC);
60 m_baud = config.readNumEntry("Baud", BT_DEFAULT_BAUD); 59 m_baud = config.readNumEntry("Baud", BT_DEFAULT_BAUD);
61 m_parity = config.readNumEntry("Parity", BT_DEFAULT_PARITY); 60 m_parity = config.readNumEntry("Parity", BT_DEFAULT_PARITY);
62 m_dbits = config.readNumEntry("DataBits", BT_DEFAULT_DBITS); 61 m_dbits = config.readNumEntry("DataBits", BT_DEFAULT_DBITS);
63 m_sbits = config.readNumEntry("StopBits", BT_DEFAULT_SBITS); 62 m_sbits = config.readNumEntry("StopBits", BT_DEFAULT_SBITS);
64 m_flow = config.readNumEntry("Flow", BT_DEFAULT_FLOW); 63 m_flow = config.readNumEntry("Flow", BT_DEFAULT_FLOW);
65} 64}
66 65
67 66
68QString IOBt::identifier() const { 67QString IOBt::identifier() const {
69 return "bluetooth"; 68 return "bluetooth";
70} 69}
71 70
72QString IOBt::name() const { 71QString IOBt::name() const {
73 return "BLuetooth IO Layer"; 72 return "BLuetooth IO Layer";
74} 73}
75 74
76void IOBt::slotExited( OProcess* proc ){ 75void IOBt::slotExited( OProcess* proc ){
77 close(); 76 close();
78} 77}
diff --git a/noncore/apps/opie-console/mainwindow.cpp b/noncore/apps/opie-console/mainwindow.cpp
index 5295600..408d3dd 100644
--- a/noncore/apps/opie-console/mainwindow.cpp
+++ b/noncore/apps/opie-console/mainwindow.cpp
@@ -1,498 +1,476 @@
1#include <assert.h> 1#include <assert.h>
2 2
3 3
4 4
5#include <qaction.h> 5#include <qaction.h>
6#include <qmenubar.h> 6#include <qmenubar.h>
7#include <qlabel.h> 7#include <qlabel.h>
8#include <qpopupmenu.h> 8#include <qpopupmenu.h>
9#include <qtoolbar.h> 9#include <qtoolbar.h>
10#include <qmessagebox.h> 10#include <qmessagebox.h>
11#include <qpushbutton.h> 11#include <qpushbutton.h>
12#include <qwhatsthis.h> 12#include <qwhatsthis.h>
13 13
14#include <qpe/resource.h> 14#include <qpe/resource.h>
15#include <opie/ofiledialog.h> 15#include <opie/ofiledialog.h>
16 16
17 17
18#include "keytrans.h" 18#include "keytrans.h"
19#include "profileeditordialog.h" 19#include "profileeditordialog.h"
20#include "configdialog.h" 20#include "configdialog.h"
21#include "default.h" 21#include "default.h"
22#include "metafactory.h" 22#include "metafactory.h"
23#include "profile.h" 23#include "profile.h"
24#include "profilemanager.h" 24#include "profilemanager.h"
25#include "mainwindow.h" 25#include "mainwindow.h"
26#include "tabwidget.h" 26#include "tabwidget.h"
27#include "transferdialog.h" 27#include "transferdialog.h"
28#include "function_keyboard.h" 28#include "function_keyboard.h"
29#include "emulation_handler.h"
29#include "script.h" 30#include "script.h"
30 31
31 32
32 33
33static char * menu_xpm[] = {
34"12 12 5 1",
35 " c None",
36 ".c #000000",
37 "+c #FFFDAD",
38 "@c #FFFF00",
39 "#c #E5E100",
40" ",
41" ",
42" ......... ",
43" .+++++++. ",
44" .+@@@@#. ",
45" .+@@@#. ",
46" .+@@#. ",
47" .+@#. ",
48" .+#. ",
49" .+. ",
50" .. ",
51" "};
52
53
54MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow(parent, name, WStyle_ContextHelp) { 34MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow(parent, name, WStyle_ContextHelp) {
55 KeyTrans::loadAll(); 35 KeyTrans::loadAll();
56 for (int i = 0; i < KeyTrans::count(); i++ ) { 36 for (int i = 0; i < KeyTrans::count(); i++ ) {
57 KeyTrans* s = KeyTrans::find(i ); 37 KeyTrans* s = KeyTrans::find(i );
58 assert( s ); 38 assert( s );
59 } 39 }
60 m_factory = new MetaFactory(); 40 m_factory = new MetaFactory();
61 Default def(m_factory); 41 Default def(m_factory);
62 m_sessions.setAutoDelete( TRUE ); 42 m_sessions.setAutoDelete( TRUE );
63 m_curSession = 0; 43 m_curSession = 0;
64 m_manager = new ProfileManager( m_factory ); 44 m_manager = new ProfileManager( m_factory );
65 m_manager->load(); 45 m_manager->load();
66 46
67 initUI(); 47 initUI();
68 populateProfiles(); 48 populateProfiles();
69} 49}
70void MainWindow::initUI() { 50void MainWindow::initUI() {
71 setToolBarsMovable( FALSE ); 51 setToolBarsMovable( FALSE );
72 52
73 /* tool bar for the menu */ 53 /* tool bar for the menu */
74 m_tool = new QToolBar( this ); 54 m_tool = new QToolBar( this );
75 m_tool->setHorizontalStretchable( TRUE ); 55 m_tool->setHorizontalStretchable( TRUE );
76 56
77 m_bar = new QMenuBar( m_tool ); 57 m_bar = new QMenuBar( m_tool );
78 m_console = new QPopupMenu( this ); 58 m_console = new QPopupMenu( this );
79 m_scripts = new QPopupMenu( this ); 59 m_scripts = new QPopupMenu( this );
80 m_sessionsPop= new QPopupMenu( this ); 60 m_sessionsPop= new QPopupMenu( this );
81 m_settings = new QPopupMenu( this ); 61 m_settings = new QPopupMenu( this );
82 62
83 /* add a toolbar for icons */ 63 /* add a toolbar for icons */
84 m_icons = new QToolBar(this); 64 m_icons = new QToolBar(this);
85 65
86 /* 66 /*
87 * new Action for new sessions 67 * new Action for new sessions
88 */ 68 */
89 QAction* a = new QAction(tr("New Connection"), 69 QAction* a = new QAction(tr("New Connection"),
90 Resource::loadPixmap( "new" ), 70 Resource::loadPixmap( "new" ),
91 QString::null, 0, this, 0); 71 QString::null, 0, this, 0);
92 a->addTo( m_console ); 72 a->addTo( m_console );
93 a->addTo( m_icons ); 73 a->addTo( m_icons );
94 connect(a, SIGNAL(activated() ), 74 connect(a, SIGNAL(activated() ),
95 this, SLOT(slotNew() ) ); 75 this, SLOT(slotNew() ) );
96 76
97 /* 77 /*
98 * connect action 78 * connect action
99 */ 79 */
100 m_connect = new QAction(); 80 m_connect = new QAction();
101 m_connect->setText( tr("Connect") ); 81 m_connect->setText( tr("Connect") );
102 m_connect->addTo( m_console ); 82 m_connect->addTo( m_console );
103 connect(m_connect, SIGNAL(activated() ), 83 connect(m_connect, SIGNAL(activated() ),
104 this, SLOT(slotConnect() ) ); 84 this, SLOT(slotConnect() ) );
105 85
106 /* 86 /*
107 * disconnect action 87 * disconnect action
108 */ 88 */
109 m_disconnect = new QAction(); 89 m_disconnect = new QAction();
110 m_disconnect->setText( tr("Disconnect") ); 90 m_disconnect->setText( tr("Disconnect") );
111 m_disconnect->addTo( m_console ); 91 m_disconnect->addTo( m_console );
112 connect(m_disconnect, SIGNAL(activated() ), 92 connect(m_disconnect, SIGNAL(activated() ),
113 this, SLOT(slotDisconnect() ) ); 93 this, SLOT(slotDisconnect() ) );
114 94
115 m_transfer = new QAction(); 95 m_transfer = new QAction();
116 m_transfer->setText( tr("Transfer file...") ); 96 m_transfer->setText( tr("Transfer file...") );
117 m_transfer->addTo( m_console ); 97 m_transfer->addTo( m_console );
118 connect(m_transfer, SIGNAL(activated() ), 98 connect(m_transfer, SIGNAL(activated() ),
119 this, SLOT(slotTransfer() ) ); 99 this, SLOT(slotTransfer() ) );
120 100
121 101
122 /* 102 /*
123 * fullscreen 103 * fullscreen
124 */ 104 */
125 m_isFullscreen = false; 105 m_isFullscreen = false;
126 106
127 m_fullscreen = new QAction( tr("Full screen"), Resource::loadPixmap( "fullscreen" ) 107 m_fullscreen = new QAction( tr("Full screen"), Resource::loadPixmap( "fullscreen" )
128 , QString::null, 0, this, 0); 108 , QString::null, 0, this, 0);
129 m_fullscreen->addTo( m_console ); 109 m_fullscreen->addTo( m_console );
130 m_fullscreen->addTo( m_icons ); 110 m_fullscreen->addTo( m_icons );
131 connect( m_fullscreen, SIGNAL( activated() ), 111 connect( m_fullscreen, SIGNAL( activated() ),
132 this, SLOT( slotFullscreen() ) ); 112 this, SLOT( slotFullscreen() ) );
133 113
134 /* 114 /*
135 * terminate action 115 * terminate action
136 */ 116 */
137 m_terminate = new QAction(); 117 m_terminate = new QAction();
138 m_terminate->setText( tr("Terminate") ); 118 m_terminate->setText( tr("Terminate") );
139 m_terminate->addTo( m_console ); 119 m_terminate->addTo( m_console );
140 connect(m_terminate, SIGNAL(activated() ), 120 connect(m_terminate, SIGNAL(activated() ),
141 this, SLOT(slotTerminate() ) ); 121 this, SLOT(slotTerminate() ) );
142 122
143 m_closewindow = new QAction(); 123 m_closewindow = new QAction();
144 m_closewindow->setText( tr("Close Window") ); 124 m_closewindow->setText( tr("Close Window") );
145 m_closewindow->addTo( m_console ); 125 m_closewindow->addTo( m_console );
146 connect( m_closewindow, SIGNAL(activated() ), 126 connect( m_closewindow, SIGNAL(activated() ),
147 this, SLOT(slotClose() ) ); 127 this, SLOT(slotClose() ) );
148 128
149 /* 129 /*
150 * the settings action 130 * the settings action
151 */ 131 */
152 m_setProfiles = new QAction(tr("Configure Profiles"), 132 m_setProfiles = new QAction(tr("Configure Profiles"),
153 Resource::loadPixmap( "SettingsIcon" ), 133 Resource::loadPixmap( "SettingsIcon" ),
154 QString::null, 0, this, 0); 134 QString::null, 0, this, 0);
155 m_setProfiles->addTo( m_settings ); 135 m_setProfiles->addTo( m_settings );
156 m_setProfiles->addTo( m_icons ); 136 m_setProfiles->addTo( m_icons );
157 connect( m_setProfiles, SIGNAL(activated() ), 137 connect( m_setProfiles, SIGNAL(activated() ),
158 this, SLOT(slotConfigure() ) ); 138 this, SLOT(slotConfigure() ) );
159 139
160 /* 140 /*
161 * script actions 141 * script actions
162 */ 142 */
163 m_recordScript = new QAction(tr("Record Script"), QString::null, 0, this, 0); 143 m_recordScript = new QAction(tr("Record Script"), QString::null, 0, this, 0);
164 m_recordScript->addTo(m_scripts); 144 m_recordScript->addTo(m_scripts);
165 connect(m_recordScript, SIGNAL(activated()), this, SLOT(slotRecordScript())); 145 connect(m_recordScript, SIGNAL(activated()), this, SLOT(slotRecordScript()));
166 146
167 m_saveScript = new QAction(tr("Save Script"), QString::null, 0, this, 0); 147 m_saveScript = new QAction(tr("Save Script"), QString::null, 0, this, 0);
168 m_saveScript->addTo(m_scripts); 148 m_saveScript->addTo(m_scripts);
169 connect(m_saveScript, SIGNAL(activated()), this, SLOT(slotSaveScript())); 149 connect(m_saveScript, SIGNAL(activated()), this, SLOT(slotSaveScript()));
170 150
171 m_runScript = new QAction(tr("Run Script"), QString::null, 0, this, 0); 151 m_runScript = new QAction(tr("Run Script"), QString::null, 0, this, 0);
172 m_runScript->addTo(m_scripts); 152 m_runScript->addTo(m_scripts);
173 connect(m_runScript, SIGNAL(activated()), this, SLOT(slotRunScript())); 153 connect(m_runScript, SIGNAL(activated()), this, SLOT(slotRunScript()));
174 154
175 /* 155 /*
176 * action that open/closes the keyboard 156 * action that open/closes the keyboard
177 */ 157 */
178 m_openKeys = new QAction (tr("Open Keyboard..."), 158 m_openKeys = new QAction (tr("Open Keyboard..."),
179 Resource::loadPixmap( "down" ), 159 Resource::loadPixmap( "down" ),
180 QString::null, 0, this, 0); 160 QString::null, 0, this, 0);
181 161
182 m_openKeys->setToggleAction(true); 162 m_openKeys->setToggleAction(true);
183 163
184 connect (m_openKeys, SIGNAL(toggled(bool)), 164 connect (m_openKeys, SIGNAL(toggled(bool)),
185 this, SLOT(slotOpenKeb(bool))); 165 this, SLOT(slotOpenKeb(bool)));
186 m_openKeys->addTo(m_icons); 166 m_openKeys->addTo(m_icons);
187 167
188 168
189 /* insert the submenu */ 169 /* insert the submenu */
190 m_console->insertItem(tr("New from Profile"), m_sessionsPop, 170 m_console->insertItem(tr("New from Profile"), m_sessionsPop,
191 -1, 0); 171 -1, 0);
192 172
193 /* insert the connection menu */ 173 /* insert the connection menu */
194 m_bar->insertItem( tr("Connection"), m_console ); 174 m_bar->insertItem( tr("Connection"), m_console );
195 175
196 /* the scripts menu */ 176 /* the scripts menu */
197 m_bar->insertItem( tr("Scripts"), m_scripts ); 177 m_bar->insertItem( tr("Scripts"), m_scripts );
198 178
199 /* the settings menu */ 179 /* the settings menu */
200 m_bar->insertItem( tr("Settings"), m_settings ); 180 m_bar->insertItem( tr("Settings"), m_settings );
201 181
202 /* and the keyboard */ 182 /* and the keyboard */
203 m_keyBar = new QToolBar(this); 183 m_keyBar = new QToolBar(this);
204 addToolBar( m_keyBar, "Keyboard", QMainWindow::Top, TRUE ); 184 addToolBar( m_keyBar, "Keyboard", QMainWindow::Top, TRUE );
205 m_keyBar->setHorizontalStretchable( TRUE ); 185 m_keyBar->setHorizontalStretchable( TRUE );
206 m_keyBar->hide(); 186 m_keyBar->hide();
207 187
208 m_kb = new FunctionKeyboard(m_keyBar); 188 m_kb = new FunctionKeyboard(m_keyBar);
209 connect(m_kb, SIGNAL(keyPressed(ushort, ushort, bool, bool, bool)), 189 connect(m_kb, SIGNAL(keyPressed(ushort, ushort, bool, bool, bool)),
210 this, SLOT(slotKeyReceived(ushort, ushort, bool, bool, bool))); 190 this, SLOT(slotKeyReceived(ushort, ushort, bool, bool, bool)));
211 191
212 192
213 193
214 m_connect->setEnabled( false ); 194 m_connect->setEnabled( false );
215 m_disconnect->setEnabled( false ); 195 m_disconnect->setEnabled( false );
216 m_terminate->setEnabled( false ); 196 m_terminate->setEnabled( false );
217 m_transfer->setEnabled( false ); 197 m_transfer->setEnabled( false );
218 m_recordScript->setEnabled( false ); 198 m_recordScript->setEnabled( false );
219 m_saveScript->setEnabled( false ); 199 m_saveScript->setEnabled( false );
220 m_runScript->setEnabled( false ); 200 m_runScript->setEnabled( false );
221 m_fullscreen->setEnabled( false ); 201 m_fullscreen->setEnabled( false );
222 m_closewindow->setEnabled( false ); 202 m_closewindow->setEnabled( false );
223 203
224 /* 204 /*
225 * connect to the menu activation 205 * connect to the menu activation
226 */ 206 */
227 connect( m_sessionsPop, SIGNAL(activated( int ) ), 207 connect( m_sessionsPop, SIGNAL(activated( int ) ),
228 this, SLOT(slotProfile( int ) ) ); 208 this, SLOT(slotProfile( int ) ) );
229 209
230 m_consoleWindow = new TabWidget( this, "blah"); 210 m_consoleWindow = new TabWidget( this, "blah");
231 connect(m_consoleWindow, SIGNAL(activated(Session*) ), 211 connect(m_consoleWindow, SIGNAL(activated(Session*) ),
232 this, SLOT(slotSessionChanged(Session*) ) ); 212 this, SLOT(slotSessionChanged(Session*) ) );
233 setCentralWidget( m_consoleWindow ); 213 setCentralWidget( m_consoleWindow );
234 214
235} 215}
236 216
237ProfileManager* MainWindow::manager() { 217ProfileManager* MainWindow::manager() {
238 return m_manager; 218 return m_manager;
239} 219}
240TabWidget* MainWindow::tabWidget() { 220TabWidget* MainWindow::tabWidget() {
241 return m_consoleWindow; 221 return m_consoleWindow;
242} 222}
243void MainWindow::populateProfiles() { 223void MainWindow::populateProfiles() {
244 m_sessionsPop->clear(); 224 m_sessionsPop->clear();
245 Profile::ValueList list = manager()->all(); 225 Profile::ValueList list = manager()->all();
246 for (Profile::ValueList::Iterator it = list.begin(); it != list.end(); ++it ) { 226 for (Profile::ValueList::Iterator it = list.begin(); it != list.end(); ++it ) {
247 m_sessionsPop->insertItem( (*it).name() ); 227 m_sessionsPop->insertItem( (*it).name() );
248 } 228 }
249 229
250} 230}
251MainWindow::~MainWindow() { 231MainWindow::~MainWindow() {
252 delete m_factory; 232 delete m_factory;
253 manager()->save(); 233 manager()->save();
254} 234}
255 235
256MetaFactory* MainWindow::factory() { 236MetaFactory* MainWindow::factory() {
257 return m_factory; 237 return m_factory;
258} 238}
259 239
260Session* MainWindow::currentSession() { 240Session* MainWindow::currentSession() {
261 return m_curSession; 241 return m_curSession;
262} 242}
263 243
264QList<Session> MainWindow::sessions() { 244QList<Session> MainWindow::sessions() {
265 return m_sessions; 245 return m_sessions;
266} 246}
267 247
268void MainWindow::slotNew() { 248void MainWindow::slotNew() {
269 ProfileEditorDialog dlg(factory() ); 249 ProfileEditorDialog dlg(factory() );
270 dlg.showMaximized(); 250 dlg.showMaximized();
271 int ret = dlg.exec(); 251 int ret = dlg.exec();
272 252
273 if ( ret == QDialog::Accepted ) { 253 if ( ret == QDialog::Accepted ) {
274 create( dlg.profile() ); 254 create( dlg.profile() );
275 } 255 }
276} 256}
277 257
278void MainWindow::slotRecordScript() { 258void MainWindow::slotRecordScript() {
279/* if (currentSession()) { 259/* if (currentSession()) {
280 currentSession()->emulationLayer()->startRecording(); 260 currentSession()->emulationLayer()->startRecording();
281 } 261 }
282 */ 262 */
283} 263}
284 264
285void MainWindow::slotSaveScript() { 265void MainWindow::slotSaveScript() {
286/* if (currentSession() && currentSession()->emulationLayer()->isRecording()) { 266/* if (currentSession() && currentSession()->emulationLayer()->isRecording()) {
287 MimeTypes types; 267 MimeTypes types;
288 QStringList script; 268 QStringList script;
289 script << "text/plain"; 269 script << "text/plain";
290 types.insert("Script", script); 270 types.insert("Script", script);
291 QString filename = OFileDialog::getSaveFileName(2, "/", QString::null, types); 271 QString filename = OFileDialog::getSaveFileName(2, "/", QString::null, types);
292 if (!filename.isEmpty()) { 272 if (!filename.isEmpty()) {
293 currentSession()->emulationLayer()->script()->saveTo(filename); 273 currentSession()->emulationLayer()->script()->saveTo(filename);
294 currentSession()->emulationLayer()->clearScript(); 274 currentSession()->emulationLayer()->clearScript();
295 } 275 }
296 } 276 }
297 */ 277 */
298} 278}
299 279
300void MainWindow::slotRunScript() { 280void MainWindow::slotRunScript() {
301/* 281/*
302 if (currentSession()) { 282 if (currentSession()) {
303 MimeTypes types; 283 MimeTypes types;
304 QStringList script; 284 QStringList script;
305 script << "text/plain"; 285 script << "text/plain";
306 types.insert("Script", script); 286 types.insert("Script", script);
307 QString filename = OFileDialog::getOpenFileName(2, "/", QString::null, types); 287 QString filename = OFileDialog::getOpenFileName(2, "/", QString::null, types);
308 if (!filename.isEmpty()) { 288 if (!filename.isEmpty()) {
309 Script script(DocLnk(filename).file()); 289 Script script(DocLnk(filename).file());
310 currentSession()->emulationLayer()->runScript(&script); 290 currentSession()->emulationLayer()->runScript(&script);
311 } 291 }
312 } 292 }
313 */ 293 */
314} 294}
315 295
316void MainWindow::slotConnect() { 296void MainWindow::slotConnect() {
317 if ( currentSession() ) { 297 if ( currentSession() ) {
318 bool ret = currentSession()->layer()->open(); 298 bool ret = currentSession()->layer()->open();
319 if(!ret) QMessageBox::warning(currentSession()->widgetStack(), 299 if(!ret) QMessageBox::warning(currentSession()->widgetStack(),
320 QObject::tr("Failed"), 300 QObject::tr("Failed"),
321 QObject::tr("Connecting failed for this session.")); 301 QObject::tr("Connecting failed for this session."));
322 else { 302 else {
323 m_connect->setEnabled( false ); 303 m_connect->setEnabled( false );
324 m_disconnect->setEnabled( true ); 304 m_disconnect->setEnabled( true );
325 } 305 }
326 } 306 }
327} 307}
328 308
329void MainWindow::slotDisconnect() { 309void MainWindow::slotDisconnect() {
330 if ( currentSession() ) { 310 if ( currentSession() ) {
331 currentSession()->layer()->close(); 311 currentSession()->layer()->close();
332 m_connect->setEnabled( true ); 312 m_connect->setEnabled( true );
333 m_disconnect->setEnabled( false ); 313 m_disconnect->setEnabled( false );
334 } 314 }
335} 315}
336 316
337void MainWindow::slotTerminate() { 317void MainWindow::slotTerminate() {
338 if ( currentSession() ) 318 if ( currentSession() )
339 currentSession()->layer()->close(); 319 currentSession()->layer()->close();
340 320
341 slotClose(); 321 slotClose();
342 /* FIXME move to the next session */ 322 /* FIXME move to the next session */
343} 323}
344 324
345void MainWindow::slotConfigure() { 325void MainWindow::slotConfigure() {
346 ConfigDialog conf( manager()->all(), factory() ); 326 ConfigDialog conf( manager()->all(), factory() );
347 conf.showMaximized(); 327 conf.showMaximized();
348 328
349 int ret = conf.exec(); 329 int ret = conf.exec();
350 330
351 if ( QDialog::Accepted == ret ) { 331 if ( QDialog::Accepted == ret ) {
352 manager()->setProfiles( conf.list() ); 332 manager()->setProfiles( conf.list() );
353 manager()->save(); 333 manager()->save();
354 populateProfiles(); 334 populateProfiles();
355 } 335 }
356} 336}
357/* 337/*
358 * we will remove 338 * we will remove
359 * this window from the tabwidget 339 * this window from the tabwidget
360 * remove it from the list 340 * remove it from the list
361 * delete it 341 * delete it
362 * and set the currentSession() 342 * and set the currentSession()
363 */ 343 */
364void MainWindow::slotClose() { 344void MainWindow::slotClose() {
365 if (!currentSession() ) 345 if (!currentSession() )
366 return; 346 return;
367 347
368 Session* ses = currentSession(); 348 Session* ses = currentSession();
369 qWarning("removing! currentSession %s", currentSession()->name().latin1() ); 349 qWarning("removing! currentSession %s", currentSession()->name().latin1() );
370 /* set to NULL to be safe, if its needed slotSessionChanged resets it automatically */ 350 /* set to NULL to be safe, if its needed slotSessionChanged resets it automatically */
371 m_curSession = NULL; 351 m_curSession = NULL;
372 tabWidget()->remove( /*currentSession()*/ses ); 352 tabWidget()->remove( /*currentSession()*/ses );
373 /*it's autodelete */ 353 /*it's autodelete */
374 m_sessions.remove( ses ); 354 m_sessions.remove( ses );
375 qWarning("after remove!!"); 355 qWarning("after remove!!");
376 356
377 if (!currentSession() ) { 357 if (!currentSession() ) {
378 m_connect->setEnabled( false ); 358 m_connect->setEnabled( false );
379 m_disconnect->setEnabled( false ); 359 m_disconnect->setEnabled( false );
380 m_terminate->setEnabled( false ); 360 m_terminate->setEnabled( false );
381 m_transfer->setEnabled( false ); 361 m_transfer->setEnabled( false );
382 m_recordScript->setEnabled( false ); 362 m_recordScript->setEnabled( false );
383 m_saveScript->setEnabled( false ); 363 m_saveScript->setEnabled( false );
384 m_runScript->setEnabled( false ); 364 m_runScript->setEnabled( false );
385 m_fullscreen->setEnabled( false ); 365 m_fullscreen->setEnabled( false );
386 m_closewindow->setEnabled( false ); 366 m_closewindow->setEnabled( false );
387 } 367 }
388} 368}
389 369
390/* 370/*
391 * We will get the name 371 * We will get the name
392 * Then the profile 372 * Then the profile
393 * and then we will make a profile 373 * and then we will make a profile
394 */ 374 */
395void MainWindow::slotProfile( int id) { 375void MainWindow::slotProfile( int id) {
396 Profile prof = manager()->profile( m_sessionsPop->text( id) ); 376 Profile prof = manager()->profile( m_sessionsPop->text( id) );
397 create( prof ); 377 create( prof );
398} 378}
399void MainWindow::create( const Profile& prof ) { 379void MainWindow::create( const Profile& prof ) {
400 Session *ses = manager()->fromProfile( prof, tabWidget() ); 380 Session *ses = manager()->fromProfile( prof, tabWidget() );
401 381
402 if((!ses) || (!ses->layer()) || (!ses->widgetStack())) 382 if((!ses) || (!ses->layer()) || (!ses->widgetStack()))
403 { 383 {
404 QMessageBox::warning(this, 384 QMessageBox::warning(this,
405 QObject::tr("Session failed"), 385 QObject::tr("Session failed"),
406 QObject::tr("<qt>Cannot open session: Not all components were found.</qt>")); 386 QObject::tr("<qt>Cannot open session: Not all components were found.</qt>"));
407 //if(ses) delete ses; 387 //if(ses) delete ses;
408 return; 388 return;
409 } 389 }
410 390
411 m_sessions.append( ses ); 391 m_sessions.append( ses );
412 tabWidget()->add( ses ); 392 tabWidget()->add( ses );
413 m_curSession = ses; 393 m_curSession = ses;
414 394
415 // dicide if its a local term ( then no connction and no tranfer), maybe make a wrapper method out of it 395 // dicide if its a local term ( then no connction and no tranfer), maybe make a wrapper method out of it
416 m_connect->setEnabled( true ); 396 m_connect->setEnabled( true );
417 m_disconnect->setEnabled( false ); 397 m_disconnect->setEnabled( false );
418 m_terminate->setEnabled( true ); 398 m_terminate->setEnabled( true );
419 m_transfer->setEnabled( true ); 399 m_transfer->setEnabled( true );
420 m_recordScript->setEnabled( true ); 400 m_recordScript->setEnabled( true );
421 m_saveScript->setEnabled( true ); 401 m_saveScript->setEnabled( true );
422 m_runScript->setEnabled( true ); 402 m_runScript->setEnabled( true );
423 m_fullscreen->setEnabled( true ); 403 m_fullscreen->setEnabled( true );
424 m_closewindow->setEnabled( true ); 404 m_closewindow->setEnabled( true );
425} 405}
426 406
427void MainWindow::slotTransfer() 407void MainWindow::slotTransfer()
428{ 408{
429 if ( currentSession() ) { 409 if ( currentSession() ) {
430 TransferDialog dlg(this); 410 TransferDialog dlg(this);
431 dlg.showMaximized(); 411 dlg.showMaximized();
432 dlg.exec(); 412 dlg.exec();
433 } 413 }
434} 414}
435 415
436 416
437void MainWindow::slotOpenKeb(bool state) { 417void MainWindow::slotOpenKeb(bool state) {
438 418
439 if (state) m_keyBar->show(); 419 if (state) m_keyBar->show();
440 else m_keyBar->hide(); 420 else m_keyBar->hide();
441 421
442} 422}
443void MainWindow::slotSessionChanged( Session* ses ) { 423void MainWindow::slotSessionChanged( Session* ses ) {
444 qWarning("changed!"); 424 qWarning("changed!");
445 if ( ses ) { 425 if ( ses ) {
446 m_curSession = ses; 426 m_curSession = ses;
447 qDebug(QString("is connected : %1").arg( m_curSession->layer()->isConnected() ) ); 427 qDebug(QString("is connected : %1").arg( m_curSession->layer()->isConnected() ) );
448 if ( m_curSession->layer()->isConnected() ) { 428 if ( m_curSession->layer()->isConnected() ) {
449 m_connect->setEnabled( false ); 429 m_connect->setEnabled( false );
450 m_disconnect->setEnabled( true ); 430 m_disconnect->setEnabled( true );
451 } else { 431 } else {
452 m_connect->setEnabled( true ); 432 m_connect->setEnabled( true );
453 m_disconnect->setEnabled( false ); 433 m_disconnect->setEnabled( false );
454 } 434 }
455 } 435 }
456} 436}
457 437
458void MainWindow::slotFullscreen() { 438void MainWindow::slotFullscreen() {
459 439
460 if ( m_isFullscreen ) { 440 if ( m_isFullscreen ) {
461 ( m_curSession->widgetStack() )->reparent( m_consoleWindow, 0, QPoint(0,0), false ); 441 ( m_curSession->widgetStack() )->reparent( m_consoleWindow, 0, QPoint(0,0), false );
462 ( m_curSession->widgetStack() )->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 442 ( m_curSession->widgetStack() )->setFrameStyle( QFrame::Panel | QFrame::Sunken );
463 setCentralWidget( m_consoleWindow ); 443 setCentralWidget( m_consoleWindow );
464 ( m_curSession->widgetStack() )->show(); 444 ( m_curSession->widgetStack() )->show();
465 m_fullscreen->setText( tr("Full screen") ); 445 ( m_curSession->emulationHandler() )->cornerButton()->hide();
446 disconnect( ( m_curSession->emulationHandler() )->cornerButton(), SIGNAL( pressed() ), this, SLOT( slotFullscreen() ) );
466 447
467 } else { 448 } else {
468 ( m_curSession->widgetStack() )->setFrameStyle( QFrame::NoFrame ); 449 ( m_curSession->widgetStack() )->setFrameStyle( QFrame::NoFrame );
469 ( m_curSession->widgetStack() )->reparent( 0,WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop 450 ( m_curSession->widgetStack() )->reparent( 0,WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop
470 , QPoint(0,0), false); 451 , QPoint(0,0), false );
471 ( m_curSession->widgetStack() )->resize(qApp->desktop()->width(), qApp->desktop()->height()); 452 ( m_curSession->widgetStack() )->resize( qApp->desktop()->width(), qApp->desktop()->height() );
472 ( m_curSession->widgetStack() )->setFocus(); 453 ( m_curSession->widgetStack() )->setFocus();
473 ( m_curSession->widgetStack() )->show(); 454 ( m_curSession->widgetStack() )->show();
474 455
475 QPushButton *cornerButton = new QPushButton( m_curSession->widgetStack() ); 456 ( ( m_curSession->emulationHandler() )->cornerButton() )->show();
476 cornerButton->setPixmap( QPixmap( (const char**)menu_xpm ) ); 457
477 connect( cornerButton, SIGNAL( pressed() ), this, SLOT( slotFullscreen() ) ); 458 connect( ( m_curSession->emulationHandler() )->cornerButton(), SIGNAL( pressed() ), this, SLOT( slotFullscreen() ) );
478 // would need a scrollview
479 // ( m_curSession->widgetStack() )->setCornerWidget( cornerButton );
480 m_fullscreen->setText( tr("Stop full screen") );
481 } 459 }
482 m_isFullscreen = !m_isFullscreen;
483 460
461 m_isFullscreen = !m_isFullscreen;
484} 462}
485 463
486 464
487void MainWindow::slotKeyReceived(ushort u, ushort q, bool, bool, bool) { 465void MainWindow::slotKeyReceived(ushort u, ushort q, bool, bool, bool) {
488 466
489 qWarning("received key event! relay to TE widget"); 467 qWarning("received key event! relay to TE widget");
490 468
491 if ( m_curSession ) { 469 if ( m_curSession ) {
492 QKeyEvent ke(QEvent::KeyPress, q, u, 0); 470 QKeyEvent ke(QEvent::KeyPress, q, u, 0);
493 471
494 ke.ignore(); 472 ke.ignore();
495 // where should i send this event? doesnt work sending it here 473 // where should i send this event? doesnt work sending it here
496 QApplication::sendEvent((QObject *)m_curSession->widgetStack(), &ke); 474 QApplication::sendEvent((QObject *)m_curSession->widgetStack(), &ke);
497 } 475 }
498} 476}