summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console/TEWidget.cpp
authorjosef <josef>2002-10-26 13:41:03 (UTC)
committer josef <josef>2002-10-26 13:41:03 (UTC)
commitffa4d7c4df80207411c27746ae884cbcead4e619 (patch) (unidiff)
tree2e37f5137deebc5f2e36452ca7fed78630cafeb9 /noncore/apps/opie-console/TEWidget.cpp
parent0d58e14f2bcfa2a1f5c9a197d5bb544571824207 (diff)
downloadopie-ffa4d7c4df80207411c27746ae884cbcead4e619.zip
opie-ffa4d7c4df80207411c27746ae884cbcead4e619.tar.gz
opie-ffa4d7c4df80207411c27746ae884cbcead4e619.tar.bz2
- implement horizontal line wrap
If Line Wrap is enabled for the terminal, the traditional behaviour is kept. Otherwise, a horizontal scroll bar is added and 80 columns are assumed. TODO: - handle modes when there's no vertical scroll bar or it's on the left side - initialize correctly (currently, sometimes moving the scrollbar must be done at first)
Diffstat (limited to 'noncore/apps/opie-console/TEWidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/TEWidget.cpp52
1 files changed, 49 insertions, 3 deletions
diff --git a/noncore/apps/opie-console/TEWidget.cpp b/noncore/apps/opie-console/TEWidget.cpp
index e4415dc..bf9a313 100644
--- a/noncore/apps/opie-console/TEWidget.cpp
+++ b/noncore/apps/opie-console/TEWidget.cpp
@@ -69,50 +69,48 @@
69#include <sys/stat.h> 69#include <sys/stat.h>
70#include <sys/types.h> 70#include <sys/types.h>
71#include <signal.h> 71#include <signal.h>
72 72
73#include <assert.h> 73#include <assert.h>
74 74
75 75
76 76
77// #include "TEWidget.moc" 77// #include "TEWidget.moc"
78//#include <kapp.h> 78//#include <kapp.h>
79//#include <kcursor.h> 79//#include <kcursor.h>
80//#include <kurl.h> 80//#include <kurl.h>
81//#include <kdebug.h> 81//#include <kdebug.h>
82//#include <klocale.h> 82//#include <klocale.h>
83 83
84#define HERE printf("%s(%d): %s\n",__FILE__,__LINE__,__FUNCTION__) 84#define HERE printf("%s(%d): %s\n",__FILE__,__LINE__,__FUNCTION__)
85#define HCNT(Name) // { static int cnt = 1; printf("%s(%d): %s %d\n",__FILE__,__LINE__,Name,cnt++); } 85#define HCNT(Name) // { static int cnt = 1; printf("%s(%d): %s %d\n",__FILE__,__LINE__,Name,cnt++); }
86 86
87#define loc(X,Y) ((Y)*columns+(X)) 87#define loc(X,Y) ((Y)*columns+(X))
88 88
89//FIXME: the rim should normally be 1, 0 only when running in full screen mode. 89//FIXME: the rim should normally be 1, 0 only when running in full screen mode.
90#define rimX 0 // left/right rim width 90#define rimX 0 // left/right rim width
91#define rimY 0 // top/bottom rim high 91#define rimY 0 // top/bottom rim high
92 92
93#define SCRWIDTH 16 // width of the scrollbar
94
95#define yMouseScroll 1 93#define yMouseScroll 1
96// scroll increment used when dragging selection at top/bottom of window. 94// scroll increment used when dragging selection at top/bottom of window.
97 95
98/* Button XPM */ 96/* Button XPM */
99namespace { 97namespace {
100static char * menu_xpm[] = { 98static char * menu_xpm[] = {
101"12 12 5 1", 99"12 12 5 1",
102 " c None", 100 " c None",
103 ".c #000000", 101 ".c #000000",
104 "+c #FFFDAD", 102 "+c #FFFDAD",
105 "@c #FFFF00", 103 "@c #FFFF00",
106 "#c #E5E100", 104 "#c #E5E100",
107" ", 105" ",
108" ", 106" ",
109" ......... ", 107" ......... ",
110" .+++++++. ", 108" .+++++++. ",
111" .+@@@@#. ", 109" .+@@@@#. ",
112" .+@@@#. ", 110" .+@@@#. ",
113" .+@@#. ", 111" .+@@#. ",
114" .+@#. ", 112" .+@#. ",
115" .+#. ", 113" .+#. ",
116" .+. ", 114" .+. ",
117" .. ", 115" .. ",
118" "}; 116" "};
@@ -298,81 +296,86 @@ void TEWidget::setFont(const QFont &)
298 // ignore font change request if not coming from konsole itself 296 // ignore font change request if not coming from konsole itself
299} 297}
300 298
301/* ------------------------------------------------------------------------- */ 299/* ------------------------------------------------------------------------- */
302/* */ 300/* */
303/* Constructor / Destructor */ 301/* Constructor / Destructor */
304/* */ 302/* */
305/* ----------------------------------------------------------------------- */ 303/* ----------------------------------------------------------------------- */
306 304
307 305
308 306
309TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name) 307TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name)
310{ 308{
311#ifndef QT_NO_CLIPBOARD 309#ifndef QT_NO_CLIPBOARD
312 cb = QApplication::clipboard(); 310 cb = QApplication::clipboard();
313 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), 311 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()),
314 this, SLOT(onClearSelection()) ); 312 this, SLOT(onClearSelection()) );
315#endif 313#endif
316 314
317 315
318 scrollbar = new QScrollBar( this ); 316 scrollbar = new QScrollBar( this );
319 scrollbar->setCursor( arrowCursor ); 317 scrollbar->setCursor( arrowCursor );
320 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); 318 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
321 319
320 hscrollbar = new QScrollBar( Qt::Horizontal, this );
321 hscrollbar->setCursor( arrowCursor );
322 connect(hscrollbar, SIGNAL(valueChanged(int)), this, SLOT(hscrollChanged(int)));
323
322 m_cornerButton = new QPushButton( this ); 324 m_cornerButton = new QPushButton( this );
323 m_cornerButton->setPixmap( QPixmap( (const char**)menu_xpm ) ); 325 m_cornerButton->setPixmap( QPixmap( (const char**)menu_xpm ) );
324 m_cornerButton->setMaximumSize( 14, 14 ); 326 m_cornerButton->setMaximumSize( 14, 14 );
325 m_cornerButton->hide(); 327 m_cornerButton->hide();
326 328
327 Config cfg("Konsole"); 329 Config cfg("Konsole");
328 cfg.setGroup("ScrollBar"); 330 cfg.setGroup("ScrollBar");
329 switch( cfg.readNumEntry("Position",2)){ 331 switch( cfg.readNumEntry("Position",2)){
330 case 0: 332 case 0:
331 scrollLoc = SCRNONE; 333 scrollLoc = SCRNONE;
332 break; 334 break;
333 case 1: 335 case 1:
334 scrollLoc = SCRLEFT; 336 scrollLoc = SCRLEFT;
335 break; 337 break;
336 case 2: 338 case 2:
337 scrollLoc = SCRRIGHT; 339 scrollLoc = SCRRIGHT;
338 break; 340 break;
339 }; 341 };
340 342
341 blinkT = new QTimer(this); 343 blinkT = new QTimer(this);
342 connect(blinkT, SIGNAL(timeout()), this, SLOT(blinkEvent())); 344 connect(blinkT, SIGNAL(timeout()), this, SLOT(blinkEvent()));
343 // blinking = FALSE; 345 // blinking = FALSE;
344 blinking = TRUE; 346 blinking = TRUE;
345 347
346 resizing = FALSE; 348 resizing = FALSE;
347 actSel = 0; 349 actSel = 0;
348 image = 0; 350 image = 0;
349 lines = 1; 351 lines = 1;
350 columns = 1; 352 columns = 1;
351 font_w = 1; 353 font_w = 1;
352 font_h = 1; 354 font_h = 1;
353 font_a = 1; 355 font_a = 1;
354 word_selection_mode = FALSE; 356 word_selection_mode = FALSE;
357 vcolumns = 0;
355 358
356 setMouseMarks(TRUE); 359 setMouseMarks(TRUE);
357 setVTFont( QFont("fixed") ); 360 setVTFont( QFont("fixed") );
358 setColorTable(base_color_table); // init color table 361 setColorTable(base_color_table); // init color table
359 362
360 qApp->installEventFilter( this ); //FIXME: see below 363 qApp->installEventFilter( this ); //FIXME: see below
361// KCursor::setAutoHideCursor( this, true ); 364// KCursor::setAutoHideCursor( this, true );
362 365
363 // Init DnD //////////////////////////////////////////////////////////////// 366 // Init DnD ////////////////////////////////////////////////////////////////
364 currentSession = NULL; 367 currentSession = NULL;
365// setAcceptDrops(true); // attempt 368// setAcceptDrops(true); // attempt
366// m_drop = new QPopupMenu(this); 369// m_drop = new QPopupMenu(this);
367// m_drop->insertItem( QString("Paste"), 0); 370// m_drop->insertItem( QString("Paste"), 0);
368// m_drop->insertItem( QString("cd"), 1); 371// m_drop->insertItem( QString("cd"), 1);
369// connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int))); 372// connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int)));
370 373
371 // we need focus so that the auto-hide cursor feature works 374 // we need focus so that the auto-hide cursor feature works
372 setFocus(); 375 setFocus();
373 setFocusPolicy( WheelFocus ); 376 setFocusPolicy( WheelFocus );
374} 377}
375 378
376//FIXME: make proper destructor 379//FIXME: make proper destructor
377// Here's a start (David) 380// Here's a start (David)
378TEWidget::~TEWidget() 381TEWidget::~TEWidget()
@@ -609,48 +612,55 @@ void TEWidget::propagateSize()
609 free(oldimg); //FIXME: try new,delete 612 free(oldimg); //FIXME: try new,delete
610 } 613 }
611 else 614 else
612 clearImage(); 615 clearImage();
613 616
614 //NOTE: control flows from the back through the chest right into the eye. 617 //NOTE: control flows from the back through the chest right into the eye.
615 // `emu' will call back via `setImage'. 618 // `emu' will call back via `setImage'.
616 619
617 resizing = TRUE; 620 resizing = TRUE;
618 emit changedImageSizeSignal(lines, columns); // expose resizeEvent 621 emit changedImageSizeSignal(lines, columns); // expose resizeEvent
619 resizing = FALSE; 622 resizing = FALSE;
620} 623}
621 624
622/* ------------------------------------------------------------------------- */ 625/* ------------------------------------------------------------------------- */
623/* */ 626/* */
624/* Scrollbar */ 627/* Scrollbar */
625/* */ 628/* */
626/* ------------------------------------------------------------------------- */ 629/* ------------------------------------------------------------------------- */
627 630
628void TEWidget::scrollChanged(int) 631void TEWidget::scrollChanged(int)
629{ 632{
630 emit changedHistoryCursor(scrollbar->value()); //expose 633 emit changedHistoryCursor(scrollbar->value()); //expose
631} 634}
632 635
636void TEWidget::hscrollChanged(int loc)
637{
638 hposition = loc;
639 propagateSize();
640 update();
641}
642
633void TEWidget::setScroll(int cursor, int slines) 643void TEWidget::setScroll(int cursor, int slines)
634{ 644{
635 disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); 645 disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
636 scrollbar->setRange(0,slines); 646 scrollbar->setRange(0,slines);
637 scrollbar->setSteps(1,lines); 647 scrollbar->setSteps(1,lines);
638 scrollbar->setValue(cursor); 648 scrollbar->setValue(cursor);
639 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); 649 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
640} 650}
641 651
642void TEWidget::setScrollbarLocation(int loc) 652void TEWidget::setScrollbarLocation(int loc)
643{ 653{
644 if (scrollLoc == loc) return; // quickly 654 if (scrollLoc == loc) return; // quickly
645 scrollLoc = loc; 655 scrollLoc = loc;
646 propagateSize(); 656 propagateSize();
647 update(); 657 update();
648} 658}
649 659
650/* ------------------------------------------------------------------------- */ 660/* ------------------------------------------------------------------------- */
651/* */ 661/* */
652/* Mouse */ 662/* Mouse */
653/* */ 663/* */
654/* ------------------------------------------------------------------------- */ 664/* ------------------------------------------------------------------------- */
655 665
656/*! 666/*!
@@ -1118,76 +1128,105 @@ void TEWidget::Bell()
1118/* Auxiluary */ 1128/* Auxiluary */
1119/* */ 1129/* */
1120/* ------------------------------------------------------------------------- */ 1130/* ------------------------------------------------------------------------- */
1121 1131
1122void TEWidget::clearImage() 1132void TEWidget::clearImage()
1123// initialize the image 1133// initialize the image
1124// for internal use only 1134// for internal use only
1125{ 1135{
1126 for (int y = 0; y < lines; y++) 1136 for (int y = 0; y < lines; y++)
1127 for (int x = 0; x < columns; x++) 1137 for (int x = 0; x < columns; x++)
1128 { 1138 {
1129 image[loc(x,y)].c = 0xff; //' '; 1139 image[loc(x,y)].c = 0xff; //' ';
1130 image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR; 1140 image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR;
1131 image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR; 1141 image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR;
1132 image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION; 1142 image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION;
1133 } 1143 }
1134} 1144}
1135 1145
1136// Create Image /////////////////////////////////////////////////////// 1146// Create Image ///////////////////////////////////////////////////////
1137 1147
1138void TEWidget::calcGeometry() 1148void TEWidget::calcGeometry()
1139{ 1149{
1140 //FIXME: set rimX == rimY == 0 when running in full screen mode. 1150 //FIXME: set rimX == rimY == 0 when running in full screen mode.
1141 1151
1152 int showhscrollbar = 1;
1153 int hwidth = 0;
1154
1155 if(vcolumns == 0) showhscrollbar = 0;
1156 if(showhscrollbar == 1) hwidth = QApplication::style().scrollBarExtent().width();
1157
1142 scrollbar->resize(QApplication::style().scrollBarExtent().width(), 1158 scrollbar->resize(QApplication::style().scrollBarExtent().width(),
1143 contentsRect().height()); 1159 contentsRect().height() - hwidth);
1160
1161 if(showhscrollbar == 1)
1162 {
1163 hscrollbar->resize(contentsRect().width() - hwidth, hwidth);
1164 hscrollbar->setRange(0, 40);
1165
1166 QPoint p = contentsRect().bottomLeft();
1167 hscrollbar->move(QPoint(p.x(), p.y() - hwidth));
1168 hscrollbar->show();
1169 }
1170 else hscrollbar->hide();
1171
1144 switch(scrollLoc) 1172 switch(scrollLoc)
1145 { 1173 {
1146 case SCRNONE : 1174 case SCRNONE :
1147 columns = ( contentsRect().width() - 2 * rimX ) / font_w; 1175 columns = ( contentsRect().width() - 2 * rimX ) / font_w;
1176 if(vcolumns) columns = vcolumns;
1148 blX = (contentsRect().width() - (columns*font_w) ) / 2; 1177 blX = (contentsRect().width() - (columns*font_w) ) / 2;
1149 brX = blX; 1178 brX = blX;
1150 scrollbar->hide(); 1179 scrollbar->hide();
1151 break; 1180 break;
1152 case SCRLEFT : 1181 case SCRLEFT :
1153 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; 1182 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w;
1183 if(vcolumns) columns = vcolumns;
1154 brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; 1184 brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2;
1155 blX = brX + scrollbar->width(); 1185 blX = brX + scrollbar->width();
1156 scrollbar->move(contentsRect().topLeft()); 1186 scrollbar->move(contentsRect().topLeft());
1157 scrollbar->show(); 1187 scrollbar->show();
1158 break; 1188 break;
1159 case SCRRIGHT: 1189 case SCRRIGHT:
1160 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; 1190 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w;
1191 if(vcolumns) columns = vcolumns;
1161 blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; 1192 blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2;
1193 if(showhscrollbar)
1194 blX = -hposition * font_w;
1162 brX = blX; 1195 brX = blX;
1163 scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0)); 1196 scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0));
1164 scrollbar->show(); 1197 scrollbar->show();
1165 break; 1198 break;
1166 } 1199 }
1167 //FIXME: support 'rounding' styles 1200 //FIXME: support 'rounding' styles
1168 lines = ( contentsRect().height() - 2 * rimY ) / font_h; 1201 lines = ( contentsRect().height() - 2 * rimY ) / font_h;
1169 bY = (contentsRect().height() - (lines *font_h)) / 2; 1202 bY = (contentsRect().height() - (lines *font_h)) / 2;
1203
1204 if(showhscrollbar == 1)
1205 {
1206 //bY = bY - 10;
1207 lines = lines - 1;
1208 }
1170} 1209}
1171 1210
1172void TEWidget::makeImage() 1211void TEWidget::makeImage()
1173//FIXME: rename 'calcGeometry? 1212//FIXME: rename 'calcGeometry?
1174{ 1213{
1175 calcGeometry(); 1214 calcGeometry();
1176 image = (ca*) malloc(lines*columns*sizeof(ca)); 1215 image = (ca*) malloc(lines*columns*sizeof(ca));
1177 clearImage(); 1216 clearImage();
1178} 1217}
1179 1218
1180// calculate the needed size 1219// calculate the needed size
1181QSize TEWidget::calcSize(int cols, int lins) const 1220QSize TEWidget::calcSize(int cols, int lins) const
1182{ 1221{
1183 int frw = width() - contentsRect().width(); 1222 int frw = width() - contentsRect().width();
1184 int frh = height() - contentsRect().height(); 1223 int frh = height() - contentsRect().height();
1185 int scw = (scrollLoc==SCRNONE?0:scrollbar->width()); 1224 int scw = (scrollLoc==SCRNONE?0:scrollbar->width());
1186 return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh ); 1225 return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh );
1187} 1226}
1188 1227
1189QSize TEWidget::sizeHint() const 1228QSize TEWidget::sizeHint() const
1190{ 1229{
1191 return size(); 1230 return size();
1192} 1231}
1193 1232
@@ -1280,24 +1319,31 @@ void TEWidget::drop_menu_activated(int)
1280 struct stat statbuf; 1319 struct stat statbuf;
1281 if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 ) 1320 if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 )
1282 { 1321 {
1283 if ( !S_ISDIR(statbuf.st_mode) ) 1322 if ( !S_ISDIR(statbuf.st_mode) )
1284 { 1323 {
1285/* 1324/*
1286 KURL url; 1325 KURL url;
1287 url.setPath( dropText ); 1326 url.setPath( dropText );
1288 dropText = url.directory( true, false ); // remove filename 1327 dropText = url.directory( true, false ); // remove filename
1289*/ 1328*/
1290 } 1329 }
1291 } 1330 }
1292 dropText.replace(QRegExp(" "), "\\ "); // escape spaces 1331 dropText.replace(QRegExp(" "), "\\ "); // escape spaces
1293 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1332 currentSession->getEmulation()->sendString(dropText.local8Bit());
1294 currentSession->getEmulation()->sendString("\n"); 1333 currentSession->getEmulation()->sendString("\n");
1295// KWM::activate((Window)this->winId()); 1334// KWM::activate((Window)this->winId());
1296 break; 1335 break;
1297 } 1336 }
1298#endif 1337#endif
1299} 1338}
1300 1339
1301QPushButton* TEWidget::cornerButton() { 1340QPushButton* TEWidget::cornerButton() {
1302 return m_cornerButton; 1341 return m_cornerButton;
1303} 1342}
1343
1344void TEWidget::setWrapAt(int columns)
1345{
1346 vcolumns = columns;
1347}
1348
1349