summaryrefslogtreecommitdiff
authorjosef <josef>2002-10-26 14:23:48 (UTC)
committer josef <josef>2002-10-26 14:23:48 (UTC)
commit2bd985c4f5a5c27260e6057a1ca8a2e0e586acbb (patch) (unidiff)
treef31bed6961ee2cea8b0412adc80fc5c60cadaefb
parent2de7003cd700685e0c3696d51656f54d54c81f43 (diff)
downloadopie-2bd985c4f5a5c27260e6057a1ca8a2e0e586acbb.zip
opie-2bd985c4f5a5c27260e6057a1ca8a2e0e586acbb.tar.gz
opie-2bd985c4f5a5c27260e6057a1ca8a2e0e586acbb.tar.bz2
- reduce number of lines correctly (fixes problems with small fonts)
- when using fullscreen, move corner widget into lower right corner :)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/TEWidget.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/noncore/apps/opie-console/TEWidget.cpp b/noncore/apps/opie-console/TEWidget.cpp
index 2db214c..d1ff85e 100644
--- a/noncore/apps/opie-console/TEWidget.cpp
+++ b/noncore/apps/opie-console/TEWidget.cpp
@@ -393,963 +393,967 @@ TEWidget::~TEWidget()
393/*! 393/*!
394 attributed string draw primitive 394 attributed string draw primitive
395*/ 395*/
396 396
397void TEWidget::drawAttrStr(QPainter &paint, QRect rect, 397void TEWidget::drawAttrStr(QPainter &paint, QRect rect,
398 QString& str, ca attr, BOOL pm, BOOL clear) 398 QString& str, ca attr, BOOL pm, BOOL clear)
399{ 399{
400 if (pm && color_table[attr.b].transparent) 400 if (pm && color_table[attr.b].transparent)
401 { 401 {
402 paint.setBackgroundMode( TransparentMode ); 402 paint.setBackgroundMode( TransparentMode );
403 if (clear) erase(rect); 403 if (clear) erase(rect);
404 } 404 }
405 else 405 else
406 { 406 {
407 if (blinking) 407 if (blinking)
408 paint.fillRect(rect, color_table[attr.b].color); 408 paint.fillRect(rect, color_table[attr.b].color);
409 else 409 else
410 { 410 {
411 paint.setBackgroundMode( OpaqueMode ); 411 paint.setBackgroundMode( OpaqueMode );
412 paint.setBackgroundColor( color_table[attr.b].color ); 412 paint.setBackgroundColor( color_table[attr.b].color );
413 } 413 }
414 } 414 }
415 415
416 if (color_table[attr.f].bold) 416 if (color_table[attr.f].bold)
417 paint.setPen(QColor( 0x8F, 0x00, 0x00 )); 417 paint.setPen(QColor( 0x8F, 0x00, 0x00 ));
418 else 418 else
419 paint.setPen(color_table[attr.f].color); 419 paint.setPen(color_table[attr.f].color);
420 420
421 paint.drawText(rect.x(),rect.y()+font_a, str); 421 paint.drawText(rect.x(),rect.y()+font_a, str);
422 422
423 if (attr.r & RE_UNDERLINE) 423 if (attr.r & RE_UNDERLINE)
424 paint.drawLine(rect.left(), rect.y()+font_a+1, rect.right(),rect.y()+font_a+1 ); 424 paint.drawLine(rect.left(), rect.y()+font_a+1, rect.right(),rect.y()+font_a+1 );
425} 425}
426 426
427/*! 427/*!
428 The image can only be set completely. 428 The image can only be set completely.
429 429
430 The size of the new image may or may not match the size of the widget. 430 The size of the new image may or may not match the size of the widget.
431*/ 431*/
432 432
433void TEWidget::setImage(const ca* const newimg, int lines, int columns) 433void TEWidget::setImage(const ca* const newimg, int lines, int columns)
434{ int y,x,len; 434{ int y,x,len;
435 const QPixmap* pm = backgroundPixmap(); 435 const QPixmap* pm = backgroundPixmap();
436 QPainter paint; 436 QPainter paint;
437 setUpdatesEnabled(FALSE); 437 setUpdatesEnabled(FALSE);
438 paint.begin( this ); 438 paint.begin( this );
439HCNT("setImage"); 439HCNT("setImage");
440 440
441 QPoint tL = contentsRect().topLeft(); 441 QPoint tL = contentsRect().topLeft();
442 int tLx = tL.x(); 442 int tLx = tL.x();
443 int tLy = tL.y(); 443 int tLy = tL.y();
444 hasBlinker = FALSE; 444 hasBlinker = FALSE;
445 445
446 int cf = -1; // undefined 446 int cf = -1; // undefined
447 int cb = -1; // undefined 447 int cb = -1; // undefined
448 int cr = -1; // undefined 448 int cr = -1; // undefined
449 449
450 int lins = QMIN(this->lines, QMAX(0,lines )); 450 int lins = QMIN(this->lines, QMAX(0,lines ));
451 int cols = QMIN(this->columns,QMAX(0,columns)); 451 int cols = QMIN(this->columns,QMAX(0,columns));
452 QChar *disstrU = new QChar[cols]; 452 QChar *disstrU = new QChar[cols];
453 453
454//{ static int cnt = 0; printf("setImage %d\n",cnt++); } 454//{ static int cnt = 0; printf("setImage %d\n",cnt++); }
455 for (y = 0; y < lins; y++) 455 for (y = 0; y < lins; y++)
456 { 456 {
457 const ca* lcl = &image[y*this->columns]; 457 const ca* lcl = &image[y*this->columns];
458 const ca* const ext = &newimg[y*columns]; 458 const ca* const ext = &newimg[y*columns];
459 if (!resizing) // not while resizing, we're expecting a paintEvent 459 if (!resizing) // not while resizing, we're expecting a paintEvent
460 for (x = 0; x < cols; x++) 460 for (x = 0; x < cols; x++)
461 { 461 {
462 hasBlinker |= (ext[x].r & RE_BLINK); 462 hasBlinker |= (ext[x].r & RE_BLINK);
463 if (ext[x] != lcl[x]) 463 if (ext[x] != lcl[x])
464 { 464 {
465 cr = ext[x].r; 465 cr = ext[x].r;
466 cb = ext[x].b; 466 cb = ext[x].b;
467 if (ext[x].f != cf) cf = ext[x].f; 467 if (ext[x].f != cf) cf = ext[x].f;
468 int lln = cols - x; 468 int lln = cols - x;
469 disstrU[0] = fontMap(ext[x+0].c); 469 disstrU[0] = fontMap(ext[x+0].c);
470 for (len = 1; len < lln; len++) 470 for (len = 1; len < lln; len++)
471 { 471 {
472 if (ext[x+len].f != cf || ext[x+len].b != cb || ext[x+len].r != cr || 472 if (ext[x+len].f != cf || ext[x+len].b != cb || ext[x+len].r != cr ||
473 ext[x+len] == lcl[x+len] ) 473 ext[x+len] == lcl[x+len] )
474 break; 474 break;
475 disstrU[len] = fontMap(ext[x+len].c); 475 disstrU[len] = fontMap(ext[x+len].c);
476 } 476 }
477 QString unistr(disstrU,len); 477 QString unistr(disstrU,len);
478 drawAttrStr(paint, 478 drawAttrStr(paint,
479 QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), 479 QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h),
480 unistr, ext[x], pm != NULL, true); 480 unistr, ext[x], pm != NULL, true);
481 x += len - 1; 481 x += len - 1;
482 } 482 }
483 } 483 }
484 // finally, make `image' become `newimg'. 484 // finally, make `image' become `newimg'.
485 memcpy((void*)lcl,(const void*)ext,cols*sizeof(ca)); 485 memcpy((void*)lcl,(const void*)ext,cols*sizeof(ca));
486 } 486 }
487 drawFrame( &paint ); 487 drawFrame( &paint );
488 paint.end(); 488 paint.end();
489 setUpdatesEnabled(TRUE); 489 setUpdatesEnabled(TRUE);
490 if ( hasBlinker && !blinkT->isActive()) blinkT->start(1000); // 1000 ms 490 if ( hasBlinker && !blinkT->isActive()) blinkT->start(1000); // 1000 ms
491 if (!hasBlinker && blinkT->isActive()) { blinkT->stop(); blinking = FALSE; } 491 if (!hasBlinker && blinkT->isActive()) { blinkT->stop(); blinking = FALSE; }
492 delete [] disstrU; 492 delete [] disstrU;
493} 493}
494 494
495// paint Event //////////////////////////////////////////////////// 495// paint Event ////////////////////////////////////////////////////
496 496
497/*! 497/*!
498 The difference of this routine vs. the `setImage' is, 498 The difference of this routine vs. the `setImage' is,
499 that the drawing does not include a difference analysis 499 that the drawing does not include a difference analysis
500 between the old and the new image. Instead, the internal 500 between the old and the new image. Instead, the internal
501 image is used and the painting bound by the PaintEvent box. 501 image is used and the painting bound by the PaintEvent box.
502*/ 502*/
503 503
504void TEWidget::paintEvent( QPaintEvent* pe ) 504void TEWidget::paintEvent( QPaintEvent* pe )
505{ 505{
506 506
507//{ static int cnt = 0; printf("paint %d\n",cnt++); } 507//{ static int cnt = 0; printf("paint %d\n",cnt++); }
508 const QPixmap* pm = backgroundPixmap(); 508 const QPixmap* pm = backgroundPixmap();
509 QPainter paint; 509 QPainter paint;
510 setUpdatesEnabled(FALSE); 510 setUpdatesEnabled(FALSE);
511 paint.begin( this ); 511 paint.begin( this );
512 paint.setBackgroundMode( TransparentMode ); 512 paint.setBackgroundMode( TransparentMode );
513HCNT("paintEvent"); 513HCNT("paintEvent");
514 514
515 // Note that the actual widget size can be slightly larger 515 // Note that the actual widget size can be slightly larger
516 // that the image (the size is truncated towards the smaller 516 // that the image (the size is truncated towards the smaller
517 // number of characters in `resizeEvent'. The paint rectangle 517 // number of characters in `resizeEvent'. The paint rectangle
518 // can thus be larger than the image, but less then the size 518 // can thus be larger than the image, but less then the size
519 // of one character. 519 // of one character.
520 520
521 QRect rect = pe->rect().intersect(contentsRect()); 521 QRect rect = pe->rect().intersect(contentsRect());
522 522
523 QPoint tL = contentsRect().topLeft(); 523 QPoint tL = contentsRect().topLeft();
524 int tLx = tL.x(); 524 int tLx = tL.x();
525 int tLy = tL.y(); 525 int tLy = tL.y();
526 526
527 int lux = QMIN(columns-1, QMAX(0,(rect.left() - tLx - blX ) / font_w)); 527 int lux = QMIN(columns-1, QMAX(0,(rect.left() - tLx - blX ) / font_w));
528 int luy = QMIN(lines-1, QMAX(0,(rect.top() - tLy - bY ) / font_h)); 528 int luy = QMIN(lines-1, QMAX(0,(rect.top() - tLy - bY ) / font_h));
529 int rlx = QMIN(columns-1, QMAX(0,(rect.right() - tLx - blX ) / font_w)); 529 int rlx = QMIN(columns-1, QMAX(0,(rect.right() - tLx - blX ) / font_w));
530 int rly = QMIN(lines-1, QMAX(0,(rect.bottom() - tLy - bY ) / font_h)); 530 int rly = QMIN(lines-1, QMAX(0,(rect.bottom() - tLy - bY ) / font_h));
531 531
532 /* 532 /*
533 printf("paintEvent: %d..%d, %d..%d (%d..%d, %d..%d)\n",lux,rlx,luy,rly, 533 printf("paintEvent: %d..%d, %d..%d (%d..%d, %d..%d)\n",lux,rlx,luy,rly,
534 rect.left(), rect.right(), rect.top(), rect.bottom()); 534 rect.left(), rect.right(), rect.top(), rect.bottom());
535 */ 535 */
536 536
537 // if (pm != NULL && color_table[image->b].transparent) 537 // if (pm != NULL && color_table[image->b].transparent)
538 // erase(rect); 538 // erase(rect);
539 // BL: I have no idea why we need this, and it breaks the refresh. 539 // BL: I have no idea why we need this, and it breaks the refresh.
540 540
541 QChar *disstrU = new QChar[columns]; 541 QChar *disstrU = new QChar[columns];
542 for (int y = luy; y <= rly; y++) 542 for (int y = luy; y <= rly; y++)
543 for (int x = lux; x <= rlx; x++) 543 for (int x = lux; x <= rlx; x++)
544 { 544 {
545 int len = 1; 545 int len = 1;
546 disstrU[0] = fontMap(image[loc(x,y)].c); 546 disstrU[0] = fontMap(image[loc(x,y)].c);
547 int cf = image[loc(x,y)].f; 547 int cf = image[loc(x,y)].f;
548 int cb = image[loc(x,y)].b; 548 int cb = image[loc(x,y)].b;
549 int cr = image[loc(x,y)].r; 549 int cr = image[loc(x,y)].r;
550 while (x+len <= rlx && 550 while (x+len <= rlx &&
551 image[loc(x+len,y)].f == cf && 551 image[loc(x+len,y)].f == cf &&
552 image[loc(x+len,y)].b == cb && 552 image[loc(x+len,y)].b == cb &&
553 image[loc(x+len,y)].r == cr ) 553 image[loc(x+len,y)].r == cr )
554 { 554 {
555 disstrU[len] = fontMap(image[loc(x+len,y)].c); 555 disstrU[len] = fontMap(image[loc(x+len,y)].c);
556 len += 1; 556 len += 1;
557 } 557 }
558 QString unistr(disstrU,len); 558 QString unistr(disstrU,len);
559 drawAttrStr(paint, 559 drawAttrStr(paint,
560 QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), 560 QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h),
561 unistr, image[loc(x,y)], pm != NULL, false); 561 unistr, image[loc(x,y)], pm != NULL, false);
562 x += len - 1; 562 x += len - 1;
563 } 563 }
564 delete [] disstrU; 564 delete [] disstrU;
565 drawFrame( &paint ); 565 drawFrame( &paint );
566 paint.end(); 566 paint.end();
567 setUpdatesEnabled(TRUE); 567 setUpdatesEnabled(TRUE);
568} 568}
569 569
570void TEWidget::blinkEvent() 570void TEWidget::blinkEvent()
571{ 571{
572 blinking = !blinking; 572 blinking = !blinking;
573 repaint(FALSE); 573 repaint(FALSE);
574} 574}
575 575
576/* ------------------------------------------------------------------------- */ 576/* ------------------------------------------------------------------------- */
577/* */ 577/* */
578/* Resizing */ 578/* Resizing */
579/* */ 579/* */
580/* ------------------------------------------------------------------------- */ 580/* ------------------------------------------------------------------------- */
581 581
582void TEWidget::resizeEvent(QResizeEvent* ev) 582void TEWidget::resizeEvent(QResizeEvent* ev)
583{ 583{
584// printf("resize: %d,%d\n",ev->size().width(),ev->size().height()); 584// printf("resize: %d,%d\n",ev->size().width(),ev->size().height());
585 //printf("approx: %d,%d\n",ev->size().width()/font_w,ev->size().height()/font_h); 585 //printf("approx: %d,%d\n",ev->size().width()/font_w,ev->size().height()/font_h);
586 //printf("leaves: %d,%d\n",ev->size().width()%font_w,ev->size().height()%font_h); 586 //printf("leaves: %d,%d\n",ev->size().width()%font_w,ev->size().height()%font_h);
587 //printf("curren: %d,%d\n",width(),height()); 587 //printf("curren: %d,%d\n",width(),height());
588HCNT("resizeEvent"); 588HCNT("resizeEvent");
589 589
590 // see comment in `paintEvent' concerning the rounding. 590 // see comment in `paintEvent' concerning the rounding.
591 //FIXME: could make a routine here; check width(),height() 591 //FIXME: could make a routine here; check width(),height()
592 assert(ev->size().width() == width()); 592 assert(ev->size().width() == width());
593 assert(ev->size().height() == height()); 593 assert(ev->size().height() == height());
594 594
595 propagateSize(); 595 propagateSize();
596} 596}
597 597
598void TEWidget::propagateSize() 598void TEWidget::propagateSize()
599{ 599{
600 ca* oldimg = image; 600 ca* oldimg = image;
601 int oldlin = lines; 601 int oldlin = lines;
602 int oldcol = columns; 602 int oldcol = columns;
603 makeImage(); 603 makeImage();
604 // we copy the old image to reduce flicker 604 // we copy the old image to reduce flicker
605 int lins = QMIN(oldlin,lines); 605 int lins = QMIN(oldlin,lines);
606 int cols = QMIN(oldcol,columns); 606 int cols = QMIN(oldcol,columns);
607 if (oldimg) 607 if (oldimg)
608 { 608 {
609 for (int lin = 0; lin < lins; lin++) 609 for (int lin = 0; lin < lins; lin++)
610 memcpy((void*)&image[columns*lin], 610 memcpy((void*)&image[columns*lin],
611 (void*)&oldimg[oldcol*lin],cols*sizeof(ca)); 611 (void*)&oldimg[oldcol*lin],cols*sizeof(ca));
612 free(oldimg); //FIXME: try new,delete 612 free(oldimg); //FIXME: try new,delete
613 } 613 }
614 else 614 else
615 clearImage(); 615 clearImage();
616 616
617 //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.
618 // `emu' will call back via `setImage'. 618 // `emu' will call back via `setImage'.
619 619
620 resizing = TRUE; 620 resizing = TRUE;
621 emit changedImageSizeSignal(lines, columns); // expose resizeEvent 621 emit changedImageSizeSignal(lines, columns); // expose resizeEvent
622 resizing = FALSE; 622 resizing = FALSE;
623} 623}
624 624
625/* ------------------------------------------------------------------------- */ 625/* ------------------------------------------------------------------------- */
626/* */ 626/* */
627/* Scrollbar */ 627/* Scrollbar */
628/* */ 628/* */
629/* ------------------------------------------------------------------------- */ 629/* ------------------------------------------------------------------------- */
630 630
631void TEWidget::scrollChanged(int) 631void TEWidget::scrollChanged(int)
632{ 632{
633 emit changedHistoryCursor(scrollbar->value()); //expose 633 emit changedHistoryCursor(scrollbar->value()); //expose
634} 634}
635 635
636void TEWidget::hscrollChanged(int loc) 636void TEWidget::hscrollChanged(int loc)
637{ 637{
638 hposition = loc; 638 hposition = loc;
639 propagateSize(); 639 propagateSize();
640 update(); 640 update();
641} 641}
642 642
643void TEWidget::setScroll(int cursor, int slines) 643void TEWidget::setScroll(int cursor, int slines)
644{ 644{
645 disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); 645 disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
646 scrollbar->setRange(0,slines); 646 scrollbar->setRange(0,slines);
647 scrollbar->setSteps(1,lines); 647 scrollbar->setSteps(1,lines);
648 scrollbar->setValue(cursor); 648 scrollbar->setValue(cursor);
649 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); 649 connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));
650} 650}
651 651
652void TEWidget::setScrollbarLocation(int loc) 652void TEWidget::setScrollbarLocation(int loc)
653{ 653{
654 if (scrollLoc == loc) return; // quickly 654 if (scrollLoc == loc) return; // quickly
655 scrollLoc = loc; 655 scrollLoc = loc;
656 propagateSize(); 656 propagateSize();
657 update(); 657 update();
658} 658}
659 659
660/* ------------------------------------------------------------------------- */ 660/* ------------------------------------------------------------------------- */
661/* */ 661/* */
662/* Mouse */ 662/* Mouse */
663/* */ 663/* */
664/* ------------------------------------------------------------------------- */ 664/* ------------------------------------------------------------------------- */
665 665
666/*! 666/*!
667 Three different operations can be performed using the mouse, and the 667 Three different operations can be performed using the mouse, and the
668 routines in this section serve all of them: 668 routines in this section serve all of them:
669 669
670 1) The press/release events are exposed to the application 670 1) The press/release events are exposed to the application
671 2) Marking (press and move left button) and Pasting (press middle button) 671 2) Marking (press and move left button) and Pasting (press middle button)
672 3) The right mouse button is used from the configuration menu 672 3) The right mouse button is used from the configuration menu
673 673
674 NOTE: During the marking process we attempt to keep the cursor within 674 NOTE: During the marking process we attempt to keep the cursor within
675 the bounds of the text as being displayed by setting the mouse position 675 the bounds of the text as being displayed by setting the mouse position
676 whenever the mouse has left the text area. 676 whenever the mouse has left the text area.
677 677
678 Two reasons to do so: 678 Two reasons to do so:
679 1) QT does not allow the `grabMouse' to confine-to the TEWidget. 679 1) QT does not allow the `grabMouse' to confine-to the TEWidget.
680 Thus a `XGrapPointer' would have to be used instead. 680 Thus a `XGrapPointer' would have to be used instead.
681 2) Even if so, this would not help too much, since the text area 681 2) Even if so, this would not help too much, since the text area
682 of the TEWidget is normally not identical with it's bounds. 682 of the TEWidget is normally not identical with it's bounds.
683 683
684 The disadvantage of the current handling is, that the mouse can visibly 684 The disadvantage of the current handling is, that the mouse can visibly
685 leave the bounds of the widget and is then moved back. Because of the 685 leave the bounds of the widget and is then moved back. Because of the
686 current construction, and the reasons mentioned above, we cannot do better 686 current construction, and the reasons mentioned above, we cannot do better
687 without changing the overall construction. 687 without changing the overall construction.
688*/ 688*/
689 689
690/*! 690/*!
691*/ 691*/
692 692
693void TEWidget::mousePressEvent(QMouseEvent* ev) 693void TEWidget::mousePressEvent(QMouseEvent* ev)
694{ 694{
695//printf("press [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); 695//printf("press [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button());
696 if ( !contentsRect().contains(ev->pos()) ) return; 696 if ( !contentsRect().contains(ev->pos()) ) return;
697 QPoint tL = contentsRect().topLeft(); 697 QPoint tL = contentsRect().topLeft();
698 int tLx = tL.x(); 698 int tLx = tL.x();
699 int tLy = tL.y(); 699 int tLy = tL.y();
700 700
701 word_selection_mode = FALSE; 701 word_selection_mode = FALSE;
702 702
703//printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY); 703//printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY);
704 if ( ev->button() == LeftButton) 704 if ( ev->button() == LeftButton)
705 { 705 {
706 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); 706 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
707 707
708 if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ; 708 if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ;
709 709
710 if (mouse_marks || (ev->state() & ShiftButton)) 710 if (mouse_marks || (ev->state() & ShiftButton))
711 { 711 {
712 emit clearSelectionSignal(); 712 emit clearSelectionSignal();
713 iPntSel = pntSel = pos; 713 iPntSel = pntSel = pos;
714 actSel = 1; // left mouse button pressed but nothing selected yet. 714 actSel = 1; // left mouse button pressed but nothing selected yet.
715 grabMouse( /*crossCursor*/ ); // handle with care! 715 grabMouse( /*crossCursor*/ ); // handle with care!
716 } 716 }
717 else 717 else
718 { 718 {
719 emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button 719 emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button
720 } 720 }
721 } 721 }
722 if ( ev->button() == MidButton ) 722 if ( ev->button() == MidButton )
723 { 723 {
724 emitSelection(); 724 emitSelection();
725 } 725 }
726 if ( ev->button() == RightButton ) // Configure 726 if ( ev->button() == RightButton ) // Configure
727 { 727 {
728 emit configureRequest( this, ev->state()&(ShiftButton|ControlButton), ev->x(), ev->y() ); 728 emit configureRequest( this, ev->state()&(ShiftButton|ControlButton), ev->x(), ev->y() );
729 } 729 }
730} 730}
731 731
732void TEWidget::mouseMoveEvent(QMouseEvent* ev) 732void TEWidget::mouseMoveEvent(QMouseEvent* ev)
733{ 733{
734 // for auto-hiding the cursor, we need mouseTracking 734 // for auto-hiding the cursor, we need mouseTracking
735 if (ev->state() == NoButton ) return; 735 if (ev->state() == NoButton ) return;
736 736
737 if (actSel == 0) return; 737 if (actSel == 0) return;
738 738
739 // don't extend selection while pasting 739 // don't extend selection while pasting
740 if (ev->state() & MidButton) return; 740 if (ev->state() & MidButton) return;
741 741
742 //if ( !contentsRect().contains(ev->pos()) ) return; 742 //if ( !contentsRect().contains(ev->pos()) ) return;
743 QPoint tL = contentsRect().topLeft(); 743 QPoint tL = contentsRect().topLeft();
744 int tLx = tL.x(); 744 int tLx = tL.x();
745 int tLy = tL.y(); 745 int tLy = tL.y();
746 int scroll = scrollbar->value(); 746 int scroll = scrollbar->value();
747 747
748 // we're in the process of moving the mouse with the left button pressed 748 // we're in the process of moving the mouse with the left button pressed
749 // the mouse cursor will kept catched within the bounds of the text in 749 // the mouse cursor will kept catched within the bounds of the text in
750 // this widget. 750 // this widget.
751 751
752 // Adjust position within text area bounds. See FIXME above. 752 // Adjust position within text area bounds. See FIXME above.
753 QPoint pos = ev->pos(); 753 QPoint pos = ev->pos();
754 if ( pos.x() < tLx+blX ) pos.setX( tLx+blX ); 754 if ( pos.x() < tLx+blX ) pos.setX( tLx+blX );
755 if ( pos.x() > tLx+blX+columns*font_w-1 ) pos.setX( tLx+blX+columns*font_w ); 755 if ( pos.x() > tLx+blX+columns*font_w-1 ) pos.setX( tLx+blX+columns*font_w );
756 if ( pos.y() < tLy+bY ) pos.setY( tLy+bY ); 756 if ( pos.y() < tLy+bY ) pos.setY( tLy+bY );
757 if ( pos.y() > tLy+bY+lines*font_h-1 ) pos.setY( tLy+bY+lines*font_h-1 ); 757 if ( pos.y() > tLy+bY+lines*font_h-1 ) pos.setY( tLy+bY+lines*font_h-1 );
758 // check if we produce a mouse move event by this 758 // check if we produce a mouse move event by this
759 if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos)); 759 if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos));
760 760
761 if ( pos.y() == tLy+bY+lines*font_h-1 ) 761 if ( pos.y() == tLy+bY+lines*font_h-1 )
762 { 762 {
763 scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward 763 scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward
764 } 764 }
765 if ( pos.y() == tLy+bY ) 765 if ( pos.y() == tLy+bY )
766 { 766 {
767 scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback 767 scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback
768 } 768 }
769 769
770 QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h); 770 QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h);
771 QPoint ohere; 771 QPoint ohere;
772 bool swapping = FALSE; 772 bool swapping = FALSE;
773 773
774 if ( word_selection_mode ) 774 if ( word_selection_mode )
775 { 775 {
776 // Extend to word boundaries 776 // Extend to word boundaries
777 int i; 777 int i;
778 int selClass; 778 int selClass;
779 779
780 bool left_not_right = ( here.y() < iPntSel.y() || 780 bool left_not_right = ( here.y() < iPntSel.y() ||
781 here.y() == iPntSel.y() && here.x() < iPntSel.x() ); 781 here.y() == iPntSel.y() && here.x() < iPntSel.x() );
782 bool old_left_not_right = ( pntSel.y() < iPntSel.y() || 782 bool old_left_not_right = ( pntSel.y() < iPntSel.y() ||
783 pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() ); 783 pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() );
784 swapping = left_not_right != old_left_not_right; 784 swapping = left_not_right != old_left_not_right;
785 785
786 // Find left (left_not_right ? from here : from start) 786 // Find left (left_not_right ? from here : from start)
787 QPoint left = left_not_right ? here : iPntSel; 787 QPoint left = left_not_right ? here : iPntSel;
788 i = loc(left.x(),left.y()); 788 i = loc(left.x(),left.y());
789 selClass = charClass(image[i].c); 789 selClass = charClass(image[i].c);
790 while ( left.x() > 0 && charClass(image[i-1].c) == selClass ) 790 while ( left.x() > 0 && charClass(image[i-1].c) == selClass )
791 { i--; left.rx()--; } 791 { i--; left.rx()--; }
792 792
793 // Find left (left_not_right ? from start : from here) 793 // Find left (left_not_right ? from start : from here)
794 QPoint right = left_not_right ? iPntSel : here; 794 QPoint right = left_not_right ? iPntSel : here;
795 i = loc(right.x(),right.y()); 795 i = loc(right.x(),right.y());
796 selClass = charClass(image[i].c); 796 selClass = charClass(image[i].c);
797 while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass ) 797 while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass )
798 { i++; right.rx()++; } 798 { i++; right.rx()++; }
799 799
800 // Pick which is start (ohere) and which is extension (here) 800 // Pick which is start (ohere) and which is extension (here)
801 if ( left_not_right ) 801 if ( left_not_right )
802 { 802 {
803 here = left; ohere = right; 803 here = left; ohere = right;
804 } 804 }
805 else 805 else
806 { 806 {
807 here = right; ohere = left; 807 here = right; ohere = left;
808 } 808 }
809 } 809 }
810 810
811 if (here == pntSel && scroll == scrollbar->value()) return; // not moved 811 if (here == pntSel && scroll == scrollbar->value()) return; // not moved
812 812
813 if ( word_selection_mode ) { 813 if ( word_selection_mode ) {
814 if ( actSel < 2 || swapping ) { 814 if ( actSel < 2 || swapping ) {
815 emit beginSelectionSignal( ohere.x(), ohere.y() ); 815 emit beginSelectionSignal( ohere.x(), ohere.y() );
816 } 816 }
817 } else if ( actSel < 2 ) { 817 } else if ( actSel < 2 ) {
818 emit beginSelectionSignal( pntSel.x(), pntSel.y() ); 818 emit beginSelectionSignal( pntSel.x(), pntSel.y() );
819 } 819 }
820 820
821 actSel = 2; // within selection 821 actSel = 2; // within selection
822 pntSel = here; 822 pntSel = here;
823 emit extendSelectionSignal( here.x(), here.y() ); 823 emit extendSelectionSignal( here.x(), here.y() );
824} 824}
825 825
826void TEWidget::mouseReleaseEvent(QMouseEvent* ev) 826void TEWidget::mouseReleaseEvent(QMouseEvent* ev)
827{ 827{
828//printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); 828//printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button());
829 if ( ev->button() == LeftButton) 829 if ( ev->button() == LeftButton)
830 { 830 {
831 if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks); 831 if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks);
832 preserve_line_breaks = TRUE; 832 preserve_line_breaks = TRUE;
833 actSel = 0; 833 actSel = 0;
834 834
835 //FIXME: emits a release event even if the mouse is 835 //FIXME: emits a release event even if the mouse is
836 // outside the range. The procedure used in `mouseMoveEvent' 836 // outside the range. The procedure used in `mouseMoveEvent'
837 // applies here, too. 837 // applies here, too.
838 838
839 QPoint tL = contentsRect().topLeft(); 839 QPoint tL = contentsRect().topLeft();
840 int tLx = tL.x(); 840 int tLx = tL.x();
841 int tLy = tL.y(); 841 int tLy = tL.y();
842 842
843 if (!mouse_marks && !(ev->state() & ShiftButton)) 843 if (!mouse_marks && !(ev->state() & ShiftButton))
844 emit mouseSignal( 3, // release 844 emit mouseSignal( 3, // release
845 (ev->x()-tLx-blX)/font_w + 1, 845 (ev->x()-tLx-blX)/font_w + 1,
846 (ev->y()-tLy-bY)/font_h + 1 ); 846 (ev->y()-tLy-bY)/font_h + 1 );
847 releaseMouse(); 847 releaseMouse();
848 } 848 }
849} 849}
850 850
851void TEWidget::mouseDoubleClickEvent(QMouseEvent* ev) 851void TEWidget::mouseDoubleClickEvent(QMouseEvent* ev)
852{ 852{
853 if ( ev->button() != LeftButton) return; 853 if ( ev->button() != LeftButton) return;
854 854
855 QPoint tL = contentsRect().topLeft(); 855 QPoint tL = contentsRect().topLeft();
856 int tLx = tL.x(); 856 int tLx = tL.x();
857 int tLy = tL.y(); 857 int tLy = tL.y();
858 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); 858 QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
859 859
860 // pass on double click as two clicks. 860 // pass on double click as two clicks.
861 if (!mouse_marks && !(ev->state() & ShiftButton)) 861 if (!mouse_marks && !(ev->state() & ShiftButton))
862 { 862 {
863 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button 863 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button
864 emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release 864 emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release
865 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button 865 emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button
866 return; 866 return;
867 } 867 }
868 868
869 869
870 emit clearSelectionSignal(); 870 emit clearSelectionSignal();
871 QPoint bgnSel = pos; 871 QPoint bgnSel = pos;
872 QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); 872 QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h);
873 int i = loc(bgnSel.x(),bgnSel.y()); 873 int i = loc(bgnSel.x(),bgnSel.y());
874 iPntSel = bgnSel; 874 iPntSel = bgnSel;
875 875
876 word_selection_mode = TRUE; 876 word_selection_mode = TRUE;
877 877
878 // find word boundaries... 878 // find word boundaries...
879 int selClass = charClass(image[i].c); 879 int selClass = charClass(image[i].c);
880 { 880 {
881 // set the start... 881 // set the start...
882 int x = bgnSel.x(); 882 int x = bgnSel.x();
883 while ( x > 0 && charClass(image[i-1].c) == selClass ) 883 while ( x > 0 && charClass(image[i-1].c) == selClass )
884 { i--; x--; } 884 { i--; x--; }
885 bgnSel.setX(x); 885 bgnSel.setX(x);
886 emit beginSelectionSignal( bgnSel.x(), bgnSel.y() ); 886 emit beginSelectionSignal( bgnSel.x(), bgnSel.y() );
887 887
888 // set the end... 888 // set the end...
889 i = loc( endSel.x(), endSel.y() ); 889 i = loc( endSel.x(), endSel.y() );
890 x = endSel.x(); 890 x = endSel.x();
891 while( x < columns-1 && charClass(image[i+1].c) == selClass ) 891 while( x < columns-1 && charClass(image[i+1].c) == selClass )
892 { i++; x++ ; } 892 { i++; x++ ; }
893 endSel.setX(x); 893 endSel.setX(x);
894 actSel = 2; // within selection 894 actSel = 2; // within selection
895 emit extendSelectionSignal( endSel.x(), endSel.y() ); 895 emit extendSelectionSignal( endSel.x(), endSel.y() );
896 emit endSelectionSignal(preserve_line_breaks); 896 emit endSelectionSignal(preserve_line_breaks);
897 preserve_line_breaks = TRUE; 897 preserve_line_breaks = TRUE;
898 } 898 }
899} 899}
900 900
901void TEWidget::focusInEvent( QFocusEvent * ) 901void TEWidget::focusInEvent( QFocusEvent * )
902{ 902{
903 903
904 // do nothing, to prevent repainting 904 // do nothing, to prevent repainting
905} 905}
906 906
907 907
908void TEWidget::focusOutEvent( QFocusEvent * ) 908void TEWidget::focusOutEvent( QFocusEvent * )
909{ 909{
910 // do nothing, to prevent repainting 910 // do nothing, to prevent repainting
911} 911}
912 912
913bool TEWidget::focusNextPrevChild( bool next ) 913bool TEWidget::focusNextPrevChild( bool next )
914{ 914{
915 if (next) 915 if (next)
916 return false; // This disables changing the active part in konqueror 916 return false; // This disables changing the active part in konqueror
917 // when pressing Tab 917 // when pressing Tab
918 return QFrame::focusNextPrevChild( next ); 918 return QFrame::focusNextPrevChild( next );
919} 919}
920 920
921 921
922int TEWidget::charClass(char ch) const 922int TEWidget::charClass(char ch) const
923{ 923{
924 // This might seem like overkill, but imagine if ch was a Unicode 924 // This might seem like overkill, but imagine if ch was a Unicode
925 // character (Qt 2.0 QChar) - it might then be sensible to separate 925 // character (Qt 2.0 QChar) - it might then be sensible to separate
926 // the different language ranges, etc. 926 // the different language ranges, etc.
927 927
928 if ( isspace(ch) ) return ' '; 928 if ( isspace(ch) ) return ' ';
929 929
930 static const char *word_characters = ":@-./_~"; 930 static const char *word_characters = ":@-./_~";
931 if ( isalnum(ch) || strchr(word_characters, ch) ) 931 if ( isalnum(ch) || strchr(word_characters, ch) )
932 return 'a'; 932 return 'a';
933 933
934 // Everything else is weird 934 // Everything else is weird
935 return 1; 935 return 1;
936} 936}
937 937
938void TEWidget::setMouseMarks(bool on) 938void TEWidget::setMouseMarks(bool on)
939{ 939{
940 mouse_marks = on; 940 mouse_marks = on;
941 setCursor( mouse_marks ? ibeamCursor : arrowCursor ); 941 setCursor( mouse_marks ? ibeamCursor : arrowCursor );
942} 942}
943 943
944/* ------------------------------------------------------------------------- */ 944/* ------------------------------------------------------------------------- */
945/* */ 945/* */
946/* Clipboard */ 946/* Clipboard */
947/* */ 947/* */
948/* ------------------------------------------------------------------------- */ 948/* ------------------------------------------------------------------------- */
949 949
950#undef KeyPress 950#undef KeyPress
951 951
952void TEWidget::emitSelection() 952void TEWidget::emitSelection()
953// Paste Clipboard by simulating keypress events 953// Paste Clipboard by simulating keypress events
954{ 954{
955#ifndef QT_NO_CLIPBOARD 955#ifndef QT_NO_CLIPBOARD
956 QString text = QApplication::clipboard()->text(); 956 QString text = QApplication::clipboard()->text();
957 if ( ! text.isNull() ) 957 if ( ! text.isNull() )
958 { 958 {
959 text.replace(QRegExp("\n"), "\r"); 959 text.replace(QRegExp("\n"), "\r");
960 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); 960 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text);
961 emit keyPressedSignal(&e); // expose as a big fat keypress event 961 emit keyPressedSignal(&e); // expose as a big fat keypress event
962 emit clearSelectionSignal(); 962 emit clearSelectionSignal();
963 } 963 }
964#endif 964#endif
965} 965}
966 966
967void TEWidget::emitText(QString text) 967void TEWidget::emitText(QString text)
968{ 968{
969 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); 969 QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text);
970 emit keyPressedSignal(&e); // expose as a big fat keypress event 970 emit keyPressedSignal(&e); // expose as a big fat keypress event
971} 971}
972 972
973void TEWidget::pasteClipboard( ) 973void TEWidget::pasteClipboard( )
974{ 974{
975 emitSelection(); 975 emitSelection();
976} 976}
977 977
978void TEWidget::setSelection(const QString& t) 978void TEWidget::setSelection(const QString& t)
979{ 979{
980#ifndef QT_NO_CLIPBOARD 980#ifndef QT_NO_CLIPBOARD
981 // Disconnect signal while WE set the clipboard 981 // Disconnect signal while WE set the clipboard
982 QObject *cb = QApplication::clipboard(); 982 QObject *cb = QApplication::clipboard();
983 QObject::disconnect( cb, SIGNAL(dataChanged()), 983 QObject::disconnect( cb, SIGNAL(dataChanged()),
984 this, SLOT(onClearSelection()) ); 984 this, SLOT(onClearSelection()) );
985 985
986 QApplication::clipboard()->setText(t); 986 QApplication::clipboard()->setText(t);
987 987
988 QObject::connect( cb, SIGNAL(dataChanged()), 988 QObject::connect( cb, SIGNAL(dataChanged()),
989 this, SLOT(onClearSelection()) ); 989 this, SLOT(onClearSelection()) );
990#endif 990#endif
991} 991}
992 992
993void TEWidget::onClearSelection() 993void TEWidget::onClearSelection()
994{ 994{
995 emit clearSelectionSignal(); 995 emit clearSelectionSignal();
996} 996}
997 997
998/* ------------------------------------------------------------------------- */ 998/* ------------------------------------------------------------------------- */
999/* */ 999/* */
1000/* Keyboard */ 1000/* Keyboard */
1001/* */ 1001/* */
1002/* ------------------------------------------------------------------------- */ 1002/* ------------------------------------------------------------------------- */
1003 1003
1004//FIXME: an `eventFilter' has been installed instead of a `keyPressEvent' 1004//FIXME: an `eventFilter' has been installed instead of a `keyPressEvent'
1005// due to a bug in `QT' or the ignorance of the author to prevent 1005// due to a bug in `QT' or the ignorance of the author to prevent
1006// repaint events being emitted to the screen whenever one leaves 1006// repaint events being emitted to the screen whenever one leaves
1007// or reenters the screen to/from another application. 1007// or reenters the screen to/from another application.
1008// 1008//
1009// Troll says one needs to change focusInEvent() and focusOutEvent(), 1009// Troll says one needs to change focusInEvent() and focusOutEvent(),
1010// which would also let you have an in-focus cursor and an out-focus 1010// which would also let you have an in-focus cursor and an out-focus
1011// cursor like xterm does. 1011// cursor like xterm does.
1012 1012
1013// for the auto-hide cursor feature, I added empty focusInEvent() and 1013// for the auto-hide cursor feature, I added empty focusInEvent() and
1014// focusOutEvent() so that update() isn't called. 1014// focusOutEvent() so that update() isn't called.
1015// For auto-hide, we need to get keypress-events, but we only get them when 1015// For auto-hide, we need to get keypress-events, but we only get them when
1016// we have focus. 1016// we have focus.
1017 1017
1018void TEWidget::doScroll(int lines) 1018void TEWidget::doScroll(int lines)
1019{ 1019{
1020 scrollbar->setValue(scrollbar->value()+lines); 1020 scrollbar->setValue(scrollbar->value()+lines);
1021} 1021}
1022 1022
1023bool TEWidget::eventFilter( QObject *obj, QEvent *e ) 1023bool TEWidget::eventFilter( QObject *obj, QEvent *e )
1024{ 1024{
1025 if ( (e->type() == QEvent::Accel || 1025 if ( (e->type() == QEvent::Accel ||
1026 e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) { 1026 e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) {
1027 static_cast<QKeyEvent *>( e )->ignore(); 1027 static_cast<QKeyEvent *>( e )->ignore();
1028 return true; 1028 return true;
1029 } 1029 }
1030 if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) 1030 if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ )
1031 return FALSE; // not us 1031 return FALSE; // not us
1032 if ( e->type() == QEvent::Wheel) { 1032 if ( e->type() == QEvent::Wheel) {
1033 QApplication::sendEvent(scrollbar, e); 1033 QApplication::sendEvent(scrollbar, e);
1034 } 1034 }
1035 1035
1036#ifdef FAKE_CTRL_AND_ALT 1036#ifdef FAKE_CTRL_AND_ALT
1037 static bool control = FALSE; 1037 static bool control = FALSE;
1038 static bool alt = FALSE; 1038 static bool alt = FALSE;
1039// qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:"); 1039// qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:");
1040 bool dele=FALSE; 1040 bool dele=FALSE;
1041 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 1041 if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
1042 QKeyEvent* ke = (QKeyEvent*)e; 1042 QKeyEvent* ke = (QKeyEvent*)e;
1043 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); 1043 bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat();
1044 switch (ke->key()) { 1044 switch (ke->key()) {
1045 case Key_F9: // let this be "Control" 1045 case Key_F9: // let this be "Control"
1046 control = keydown; 1046 control = keydown;
1047 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); 1047 e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state());
1048 dele=TRUE; 1048 dele=TRUE;
1049 break; 1049 break;
1050 case Key_F13: // let this be "Alt" 1050 case Key_F13: // let this be "Alt"
1051 alt = keydown; 1051 alt = keydown;
1052 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); 1052 e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state());
1053 dele=TRUE; 1053 dele=TRUE;
1054 break; 1054 break;
1055 default: 1055 default:
1056 if ( control ) { 1056 if ( control ) {
1057 int a = toupper(ke->ascii())-64; 1057 int a = toupper(ke->ascii())-64;
1058 if ( a >= 0 && a < ' ' ) { 1058 if ( a >= 0 && a < ' ' ) {
1059 e = new QKeyEvent(e->type(), ke->key(), 1059 e = new QKeyEvent(e->type(), ke->key(),
1060 a, ke->state()|ControlButton, QChar(a,0)); 1060 a, ke->state()|ControlButton, QChar(a,0));
1061 dele=TRUE; 1061 dele=TRUE;
1062 } 1062 }
1063 } 1063 }
1064 if ( alt ) { 1064 if ( alt ) {
1065 e = new QKeyEvent(e->type(), ke->key(), 1065 e = new QKeyEvent(e->type(), ke->key(),
1066 ke->ascii(), ke->state()|AltButton, ke->text()); 1066 ke->ascii(), ke->state()|AltButton, ke->text());
1067 dele=TRUE; 1067 dele=TRUE;
1068 } 1068 }
1069 } 1069 }
1070 } 1070 }
1071#endif 1071#endif
1072 1072
1073 if ( e->type() == QEvent::KeyPress ) { 1073 if ( e->type() == QEvent::KeyPress ) {
1074 QKeyEvent* ke = (QKeyEvent*)e; 1074 QKeyEvent* ke = (QKeyEvent*)e;
1075 actSel=0; // Key stroke implies a screen update, so TEWidget won't 1075 actSel=0; // Key stroke implies a screen update, so TEWidget won't
1076 // know where the current selection is. 1076 // know where the current selection is.
1077 1077
1078// qDebug("key pressed is 0x%x",ke->key()); 1078// qDebug("key pressed is 0x%x",ke->key());
1079 1079
1080 if( ke->state() == ShiftButton && ke->key() == Key_Tab) { //lets hardcode this sucker 1080 if( ke->state() == ShiftButton && ke->key() == Key_Tab) { //lets hardcode this sucker
1081 1081
1082// qDebug("key pressed 2 is 0x%x",ke->key()); 1082// qDebug("key pressed 2 is 0x%x",ke->key());
1083 emitText("\\"); // expose 1083 emitText("\\"); // expose
1084 } else 1084 } else
1085 emit keyPressedSignal(ke); // expose 1085 emit keyPressedSignal(ke); // expose
1086 ke->accept(); 1086 ke->accept();
1087#ifdef FAKE_CTRL_AND_ALT 1087#ifdef FAKE_CTRL_AND_ALT
1088 if ( dele ) delete e; 1088 if ( dele ) delete e;
1089#endif 1089#endif
1090 return true; // stop the event 1090 return true; // stop the event
1091 } 1091 }
1092 if ( e->type() == QEvent::Enter ) { 1092 if ( e->type() == QEvent::Enter ) {
1093 QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()), 1093 QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()),
1094 this, SLOT(onClearSelection()) ); 1094 this, SLOT(onClearSelection()) );
1095 } 1095 }
1096 if ( e->type() == QEvent::Leave ) { 1096 if ( e->type() == QEvent::Leave ) {
1097 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), 1097 QObject::connect( (QObject*)cb, SIGNAL(dataChanged()),
1098 this, SLOT(onClearSelection()) ); 1098 this, SLOT(onClearSelection()) );
1099 } 1099 }
1100 return QFrame::eventFilter( obj, e ); 1100 return QFrame::eventFilter( obj, e );
1101} 1101}
1102 1102
1103/* ------------------------------------------------------------------------- */ 1103/* ------------------------------------------------------------------------- */
1104/* */ 1104/* */
1105/* Frame */ 1105/* Frame */
1106/* */ 1106/* */
1107/* ------------------------------------------------------------------------- */ 1107/* ------------------------------------------------------------------------- */
1108 1108
1109void TEWidget::frameChanged() 1109void TEWidget::frameChanged()
1110{ 1110{
1111 propagateSize(); 1111 propagateSize();
1112 update(); 1112 update();
1113} 1113}
1114 1114
1115/* ------------------------------------------------------------------------- */ 1115/* ------------------------------------------------------------------------- */
1116/* */ 1116/* */
1117/* Sound */ 1117/* Sound */
1118/* */ 1118/* */
1119/* ------------------------------------------------------------------------- */ 1119/* ------------------------------------------------------------------------- */
1120 1120
1121void TEWidget::Bell() 1121void TEWidget::Bell()
1122{ 1122{
1123 QApplication::beep(); 1123 QApplication::beep();
1124} 1124}
1125 1125
1126/* ------------------------------------------------------------------------- */ 1126/* ------------------------------------------------------------------------- */
1127/* */ 1127/* */
1128/* Auxiluary */ 1128/* Auxiluary */
1129/* */ 1129/* */
1130/* ------------------------------------------------------------------------- */ 1130/* ------------------------------------------------------------------------- */
1131 1131
1132void TEWidget::clearImage() 1132void TEWidget::clearImage()
1133// initialize the image 1133// initialize the image
1134// for internal use only 1134// for internal use only
1135{ 1135{
1136 for (int y = 0; y < lines; y++) 1136 for (int y = 0; y < lines; y++)
1137 for (int x = 0; x < columns; x++) 1137 for (int x = 0; x < columns; x++)
1138 { 1138 {
1139 image[loc(x,y)].c = 0xff; //' '; 1139 image[loc(x,y)].c = 0xff; //' ';
1140 image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR; 1140 image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR;
1141 image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR; 1141 image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR;
1142 image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION; 1142 image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION;
1143 } 1143 }
1144} 1144}
1145 1145
1146// Create Image /////////////////////////////////////////////////////// 1146// Create Image ///////////////////////////////////////////////////////
1147 1147
1148void TEWidget::calcGeometry() 1148void TEWidget::calcGeometry()
1149{ 1149{
1150 //FIXME: set rimX == rimY == 0 when running in full screen mode. 1150 //FIXME: set rimX == rimY == 0 when running in full screen mode.
1151 1151
1152 int showhscrollbar = 1; 1152 int showhscrollbar = 1;
1153 int hwidth = 0; 1153 int hwidth = 0;
1154 1154
1155 if(vcolumns == 0) showhscrollbar = 0; 1155 if(vcolumns == 0) showhscrollbar = 0;
1156 if(showhscrollbar == 1) hwidth = QApplication::style().scrollBarExtent().width(); 1156 if(showhscrollbar == 1) hwidth = QApplication::style().scrollBarExtent().width();
1157 1157
1158 scrollbar->resize(QApplication::style().scrollBarExtent().width(), 1158 scrollbar->resize(QApplication::style().scrollBarExtent().width(),
1159 contentsRect().height() - hwidth); 1159 contentsRect().height() - hwidth);
1160 1160
1161 if(!showhscrollbar) cornerButton()->move(0, 0);
1162 else cornerButton()->move(contentsRect().width() - hwidth, contentsRect().height() - hwidth);
1163
1164
1161 if(showhscrollbar == 1) 1165 if(showhscrollbar == 1)
1162 { 1166 {
1163 hscrollbar->resize(contentsRect().width() - hwidth, hwidth); 1167 hscrollbar->resize(contentsRect().width() - hwidth, hwidth);
1164 hscrollbar->setRange(0, 40); 1168 hscrollbar->setRange(0, 40);
1165 1169
1166 QPoint p = contentsRect().bottomLeft(); 1170 QPoint p = contentsRect().bottomLeft();
1167 hscrollbar->move(QPoint(p.x(), p.y() - hwidth)); 1171 hscrollbar->move(QPoint(p.x(), p.y() - hwidth));
1168 hscrollbar->show(); 1172 hscrollbar->show();
1169 } 1173 }
1170 else hscrollbar->hide(); 1174 else hscrollbar->hide();
1171 1175
1172 switch(scrollLoc) 1176 switch(scrollLoc)
1173 { 1177 {
1174 case SCRNONE : 1178 case SCRNONE :
1175 columns = ( contentsRect().width() - 2 * rimX ) / font_w; 1179 columns = ( contentsRect().width() - 2 * rimX ) / font_w;
1176 if(vcolumns) columns = vcolumns; 1180 if(vcolumns) columns = vcolumns;
1177 blX = (contentsRect().width() - (columns*font_w) ) / 2; 1181 blX = (contentsRect().width() - (columns*font_w) ) / 2;
1178 if(showhscrollbar) 1182 if(showhscrollbar)
1179 blX = -hposition * font_w; 1183 blX = -hposition * font_w;
1180 brX = blX; 1184 brX = blX;
1181 scrollbar->hide(); 1185 scrollbar->hide();
1182 break; 1186 break;
1183 case SCRLEFT : 1187 case SCRLEFT :
1184 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; 1188 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w;
1185 if(vcolumns) columns = vcolumns; 1189 if(vcolumns) columns = vcolumns;
1186 brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; 1190 brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2;
1187 if(showhscrollbar) 1191 if(showhscrollbar)
1188 brX = -hposition * font_w; 1192 brX = -hposition * font_w;
1189 blX = brX + scrollbar->width(); 1193 blX = brX + scrollbar->width();
1190 scrollbar->move(contentsRect().topLeft()); 1194 scrollbar->move(contentsRect().topLeft());
1191 scrollbar->show(); 1195 scrollbar->show();
1192 break; 1196 break;
1193 case SCRRIGHT: 1197 case SCRRIGHT:
1194 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; 1198 columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w;
1195 if(vcolumns) columns = vcolumns; 1199 if(vcolumns) columns = vcolumns;
1196 blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; 1200 blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2;
1197 if(showhscrollbar) 1201 if(showhscrollbar)
1198 blX = -hposition * font_w; 1202 blX = -hposition * font_w;
1199 brX = blX; 1203 brX = blX;
1200 scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0)); 1204 scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0));
1201 scrollbar->show(); 1205 scrollbar->show();
1202 break; 1206 break;
1203 } 1207 }
1204 //FIXME: support 'rounding' styles 1208 //FIXME: support 'rounding' styles
1205 lines = ( contentsRect().height() - 2 * rimY ) / font_h; 1209 lines = ( contentsRect().height() - 2 * rimY ) / font_h;
1206 bY = (contentsRect().height() - (lines *font_h)) / 2; 1210 bY = (contentsRect().height() - (lines *font_h)) / 2;
1207 1211
1208 if(showhscrollbar == 1) 1212 if(showhscrollbar == 1)
1209 { 1213 {
1210 //bY = bY - 10; 1214 lines = lines - (hwidth / font_h) - 1;
1211 lines = lines - 1; 1215 if(lines < 1) lines = 1;
1212 } 1216 }
1213} 1217}
1214 1218
1215void TEWidget::makeImage() 1219void TEWidget::makeImage()
1216//FIXME: rename 'calcGeometry? 1220//FIXME: rename 'calcGeometry?
1217{ 1221{
1218 calcGeometry(); 1222 calcGeometry();
1219 image = (ca*) malloc(lines*columns*sizeof(ca)); 1223 image = (ca*) malloc(lines*columns*sizeof(ca));
1220 clearImage(); 1224 clearImage();
1221} 1225}
1222 1226
1223// calculate the needed size 1227// calculate the needed size
1224QSize TEWidget::calcSize(int cols, int lins) const 1228QSize TEWidget::calcSize(int cols, int lins) const
1225{ 1229{
1226 int frw = width() - contentsRect().width(); 1230 int frw = width() - contentsRect().width();
1227 int frh = height() - contentsRect().height(); 1231 int frh = height() - contentsRect().height();
1228 int scw = (scrollLoc==SCRNONE?0:scrollbar->width()); 1232 int scw = (scrollLoc==SCRNONE?0:scrollbar->width());
1229 return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh ); 1233 return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh );
1230} 1234}
1231 1235
1232QSize TEWidget::sizeHint() const 1236QSize TEWidget::sizeHint() const
1233{ 1237{
1234 return size(); 1238 return size();
1235} 1239}
1236 1240
1237void TEWidget::styleChange(QStyle &) 1241void TEWidget::styleChange(QStyle &)
1238{ 1242{
1239 propagateSize(); 1243 propagateSize();
1240} 1244}
1241 1245
1242#ifndef QT_NO_DRAGANDDROP 1246#ifndef QT_NO_DRAGANDDROP
1243 1247
1244/* --------------------------------------------------------------------- */ 1248/* --------------------------------------------------------------------- */
1245/* */ 1249/* */
1246/* Drag & Drop */ 1250/* Drag & Drop */
1247/* */ 1251/* */
1248/* --------------------------------------------------------------------- */ 1252/* --------------------------------------------------------------------- */
1249 1253
1250 1254
1251void TEWidget::dragEnterEvent(QDragEnterEvent* e) 1255void TEWidget::dragEnterEvent(QDragEnterEvent* e)
1252{ 1256{
1253 e->accept(QTextDrag::canDecode(e) || 1257 e->accept(QTextDrag::canDecode(e) ||
1254 QUriDrag::canDecode(e)); 1258 QUriDrag::canDecode(e));
1255} 1259}
1256 1260
1257void TEWidget::dropEvent(QDropEvent* event) 1261void TEWidget::dropEvent(QDropEvent* event)
1258{ 1262{
1259 // The current behaviour when url(s) are dropped is 1263 // The current behaviour when url(s) are dropped is
1260 // * if there is only ONE url and if it's a LOCAL one, ask for paste or cd 1264 // * if there is only ONE url and if it's a LOCAL one, ask for paste or cd
1261 // * in all other cases, just paste 1265 // * in all other cases, just paste
1262 // (for non-local ones, or for a list of URLs, 'cd' is nonsense) 1266 // (for non-local ones, or for a list of URLs, 'cd' is nonsense)
1263 QStrList strlist; 1267 QStrList strlist;
1264 int file_count = 0; 1268 int file_count = 0;
1265 dropText = ""; 1269 dropText = "";
1266 bool bPopup = true; 1270 bool bPopup = true;
1267 1271
1268 if(QUriDrag::decode(event, strlist)) { 1272 if(QUriDrag::decode(event, strlist)) {
1269 if (strlist.count()) { 1273 if (strlist.count()) {
1270 for(const char* p = strlist.first(); p; p = strlist.next()) { 1274 for(const char* p = strlist.first(); p; p = strlist.next()) {
1271 if(file_count++ > 0) { 1275 if(file_count++ > 0) {
1272 dropText += " "; 1276 dropText += " ";
1273 bPopup = false; // more than one file, don't popup 1277 bPopup = false; // more than one file, don't popup
1274 } 1278 }
1275 1279
1276/* 1280/*
1277 KURL url(p); 1281 KURL url(p);
1278 if (url.isLocalFile()) { 1282 if (url.isLocalFile()) {
1279 dropText += url.path(); // local URL : remove protocol 1283 dropText += url.path(); // local URL : remove protocol
1280 } 1284 }
1281 else { 1285 else {
1282 dropText += url.prettyURL(); 1286 dropText += url.prettyURL();
1283 bPopup = false; // a non-local file, don't popup 1287 bPopup = false; // a non-local file, don't popup
1284 } 1288 }
1285*/ 1289*/
1286 1290
1287 } 1291 }
1288 1292
1289 if (bPopup) 1293 if (bPopup)
1290 // m_drop->popup(pos() + event->pos()); 1294 // m_drop->popup(pos() + event->pos());
1291 m_drop->popup(mapToGlobal(event->pos())); 1295 m_drop->popup(mapToGlobal(event->pos()));
1292 else 1296 else
1293 { 1297 {
1294 if (currentSession) { 1298 if (currentSession) {
1295 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1299 currentSession->getEmulation()->sendString(dropText.local8Bit());
1296 } 1300 }
1297// kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; 1301// kdDebug() << "Drop:" << dropText.local8Bit() << "\n";
1298 } 1302 }
1299 } 1303 }
1300 } 1304 }
1301 else if(QTextDrag::decode(event, dropText)) { 1305 else if(QTextDrag::decode(event, dropText)) {
1302// kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; 1306// kdDebug() << "Drop:" << dropText.local8Bit() << "\n";
1303 if (currentSession) { 1307 if (currentSession) {
1304 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1308 currentSession->getEmulation()->sendString(dropText.local8Bit());
1305 } 1309 }
1306 // Paste it 1310 // Paste it
1307 } 1311 }
1308} 1312}
1309#endif 1313#endif
1310 1314
1311 1315
1312void TEWidget::drop_menu_activated(int) 1316void TEWidget::drop_menu_activated(int)
1313{ 1317{
1314#ifndef QT_NO_DRAGANDDROP 1318#ifndef QT_NO_DRAGANDDROP
1315 switch (item) 1319 switch (item)
1316 { 1320 {
1317 case 0: // paste 1321 case 0: // paste
1318 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1322 currentSession->getEmulation()->sendString(dropText.local8Bit());
1319// KWM::activate((Window)this->winId()); 1323// KWM::activate((Window)this->winId());
1320 break; 1324 break;
1321 case 1: // cd ... 1325 case 1: // cd ...
1322 currentSession->getEmulation()->sendString("cd "); 1326 currentSession->getEmulation()->sendString("cd ");
1323 struct stat statbuf; 1327 struct stat statbuf;
1324 if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 ) 1328 if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 )
1325 { 1329 {
1326 if ( !S_ISDIR(statbuf.st_mode) ) 1330 if ( !S_ISDIR(statbuf.st_mode) )
1327 { 1331 {
1328/* 1332/*
1329 KURL url; 1333 KURL url;
1330 url.setPath( dropText ); 1334 url.setPath( dropText );
1331 dropText = url.directory( true, false ); // remove filename 1335 dropText = url.directory( true, false ); // remove filename
1332*/ 1336*/
1333 } 1337 }
1334 } 1338 }
1335 dropText.replace(QRegExp(" "), "\\ "); // escape spaces 1339 dropText.replace(QRegExp(" "), "\\ "); // escape spaces
1336 currentSession->getEmulation()->sendString(dropText.local8Bit()); 1340 currentSession->getEmulation()->sendString(dropText.local8Bit());
1337 currentSession->getEmulation()->sendString("\n"); 1341 currentSession->getEmulation()->sendString("\n");
1338// KWM::activate((Window)this->winId()); 1342// KWM::activate((Window)this->winId());
1339 break; 1343 break;
1340 } 1344 }
1341#endif 1345#endif
1342} 1346}
1343 1347
1344QPushButton* TEWidget::cornerButton() { 1348QPushButton* TEWidget::cornerButton() {
1345 return m_cornerButton; 1349 return m_cornerButton;
1346} 1350}
1347 1351
1348void TEWidget::setWrapAt(int columns) 1352void TEWidget::setWrapAt(int columns)
1349{ 1353{
1350 vcolumns = columns; 1354 vcolumns = columns;
1351 propagateSize(); 1355 propagateSize();
1352 update(); 1356 update();
1353} 1357}
1354 1358
1355 1359