-rw-r--r-- | core/apps/embeddedkonsole/TEWidget.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/core/apps/embeddedkonsole/TEWidget.cpp b/core/apps/embeddedkonsole/TEWidget.cpp index a111e18..6d5c6e9 100644 --- a/core/apps/embeddedkonsole/TEWidget.cpp +++ b/core/apps/embeddedkonsole/TEWidget.cpp | |||
@@ -519,743 +519,745 @@ HCNT("paintEvent"); | |||
519 | drawAttrStr(paint, | 519 | drawAttrStr(paint, |
520 | QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), | 520 | QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), |
521 | unistr, image[loc(x,y)], pm != NULL, false); | 521 | unistr, image[loc(x,y)], pm != NULL, false); |
522 | x += len - 1; | 522 | x += len - 1; |
523 | } | 523 | } |
524 | delete [] disstrU; | 524 | delete [] disstrU; |
525 | drawFrame( &paint ); | 525 | drawFrame( &paint ); |
526 | paint.end(); | 526 | paint.end(); |
527 | setUpdatesEnabled(TRUE); | 527 | setUpdatesEnabled(TRUE); |
528 | } | 528 | } |
529 | 529 | ||
530 | void TEWidget::blinkEvent() | 530 | void TEWidget::blinkEvent() |
531 | { | 531 | { |
532 | blinking = !blinking; | 532 | blinking = !blinking; |
533 | repaint(FALSE); | 533 | repaint(FALSE); |
534 | } | 534 | } |
535 | 535 | ||
536 | /* ------------------------------------------------------------------------- */ | 536 | /* ------------------------------------------------------------------------- */ |
537 | /* */ | 537 | /* */ |
538 | /* Resizing */ | 538 | /* Resizing */ |
539 | /* */ | 539 | /* */ |
540 | /* ------------------------------------------------------------------------- */ | 540 | /* ------------------------------------------------------------------------- */ |
541 | 541 | ||
542 | void TEWidget::resizeEvent(QResizeEvent* ev) | 542 | void TEWidget::resizeEvent(QResizeEvent* ev) |
543 | { | 543 | { |
544 | // printf("resize: %d,%d\n",ev->size().width(),ev->size().height()); | 544 | // printf("resize: %d,%d\n",ev->size().width(),ev->size().height()); |
545 | //printf("approx: %d,%d\n",ev->size().width()/font_w,ev->size().height()/font_h); | 545 | //printf("approx: %d,%d\n",ev->size().width()/font_w,ev->size().height()/font_h); |
546 | //printf("leaves: %d,%d\n",ev->size().width()%font_w,ev->size().height()%font_h); | 546 | //printf("leaves: %d,%d\n",ev->size().width()%font_w,ev->size().height()%font_h); |
547 | //printf("curren: %d,%d\n",width(),height()); | 547 | //printf("curren: %d,%d\n",width(),height()); |
548 | HCNT("resizeEvent"); | 548 | HCNT("resizeEvent"); |
549 | 549 | ||
550 | // see comment in `paintEvent' concerning the rounding. | 550 | // see comment in `paintEvent' concerning the rounding. |
551 | //FIXME: could make a routine here; check width(),height() | 551 | //FIXME: could make a routine here; check width(),height() |
552 | assert(ev->size().width() == width()); | 552 | assert(ev->size().width() == width()); |
553 | assert(ev->size().height() == height()); | 553 | assert(ev->size().height() == height()); |
554 | 554 | ||
555 | propagateSize(); | 555 | propagateSize(); |
556 | } | 556 | } |
557 | 557 | ||
558 | void TEWidget::propagateSize() | 558 | void TEWidget::propagateSize() |
559 | { | 559 | { |
560 | ca* oldimg = image; | 560 | ca* oldimg = image; |
561 | int oldlin = lines; | 561 | int oldlin = lines; |
562 | int oldcol = columns; | 562 | int oldcol = columns; |
563 | makeImage(); | 563 | makeImage(); |
564 | // we copy the old image to reduce flicker | 564 | // we copy the old image to reduce flicker |
565 | int lins = QMIN(oldlin,lines); | 565 | int lins = QMIN(oldlin,lines); |
566 | int cols = QMIN(oldcol,columns); | 566 | int cols = QMIN(oldcol,columns); |
567 | if (oldimg) | 567 | if (oldimg) |
568 | { | 568 | { |
569 | for (int lin = 0; lin < lins; lin++) | 569 | for (int lin = 0; lin < lins; lin++) |
570 | memcpy((void*)&image[columns*lin], | 570 | memcpy((void*)&image[columns*lin], |
571 | (void*)&oldimg[oldcol*lin],cols*sizeof(ca)); | 571 | (void*)&oldimg[oldcol*lin],cols*sizeof(ca)); |
572 | free(oldimg); //FIXME: try new,delete | 572 | free(oldimg); //FIXME: try new,delete |
573 | } | 573 | } |
574 | else | 574 | else |
575 | clearImage(); | 575 | clearImage(); |
576 | 576 | ||
577 | //NOTE: control flows from the back through the chest right into the eye. | 577 | //NOTE: control flows from the back through the chest right into the eye. |
578 | // `emu' will call back via `setImage'. | 578 | // `emu' will call back via `setImage'. |
579 | 579 | ||
580 | resizing = TRUE; | 580 | resizing = TRUE; |
581 | emit changedImageSizeSignal(lines, columns); // expose resizeEvent | 581 | emit changedImageSizeSignal(lines, columns); // expose resizeEvent |
582 | resizing = FALSE; | 582 | resizing = FALSE; |
583 | } | 583 | } |
584 | 584 | ||
585 | /* ------------------------------------------------------------------------- */ | 585 | /* ------------------------------------------------------------------------- */ |
586 | /* */ | 586 | /* */ |
587 | /* Scrollbar */ | 587 | /* Scrollbar */ |
588 | /* */ | 588 | /* */ |
589 | /* ------------------------------------------------------------------------- */ | 589 | /* ------------------------------------------------------------------------- */ |
590 | 590 | ||
591 | void TEWidget::scrollChanged(int) | 591 | void TEWidget::scrollChanged(int) |
592 | { | 592 | { |
593 | emit changedHistoryCursor(scrollbar->value()); //expose | 593 | emit changedHistoryCursor(scrollbar->value()); //expose |
594 | } | 594 | } |
595 | 595 | ||
596 | void TEWidget::setScroll(int cursor, int slines) | 596 | void TEWidget::setScroll(int cursor, int slines) |
597 | { | 597 | { |
598 | disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); | 598 | disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); |
599 | scrollbar->setRange(0,slines); | 599 | scrollbar->setRange(0,slines); |
600 | scrollbar->setSteps(1,lines); | 600 | scrollbar->setSteps(1,lines); |
601 | scrollbar->setValue(cursor); | 601 | scrollbar->setValue(cursor); |
602 | connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); | 602 | connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); |
603 | } | 603 | } |
604 | 604 | ||
605 | void TEWidget::setScrollbarLocation(int loc) | 605 | void TEWidget::setScrollbarLocation(int loc) |
606 | { | 606 | { |
607 | if (scrollLoc == loc) return; // quickly | 607 | if (scrollLoc == loc) return; // quickly |
608 | scrollLoc = loc; | 608 | scrollLoc = loc; |
609 | propagateSize(); | 609 | propagateSize(); |
610 | update(); | 610 | update(); |
611 | } | 611 | } |
612 | 612 | ||
613 | /* ------------------------------------------------------------------------- */ | 613 | /* ------------------------------------------------------------------------- */ |
614 | /* */ | 614 | /* */ |
615 | /* Mouse */ | 615 | /* Mouse */ |
616 | /* */ | 616 | /* */ |
617 | /* ------------------------------------------------------------------------- */ | 617 | /* ------------------------------------------------------------------------- */ |
618 | 618 | ||
619 | /*! | 619 | /*! |
620 | Three different operations can be performed using the mouse, and the | 620 | Three different operations can be performed using the mouse, and the |
621 | routines in this section serve all of them: | 621 | routines in this section serve all of them: |
622 | 622 | ||
623 | 1) The press/release events are exposed to the application | 623 | 1) The press/release events are exposed to the application |
624 | 2) Marking (press and move left button) and Pasting (press middle button) | 624 | 2) Marking (press and move left button) and Pasting (press middle button) |
625 | 3) The right mouse button is used from the configuration menu | 625 | 3) The right mouse button is used from the configuration menu |
626 | 626 | ||
627 | NOTE: During the marking process we attempt to keep the cursor within | 627 | NOTE: During the marking process we attempt to keep the cursor within |
628 | the bounds of the text as being displayed by setting the mouse position | 628 | the bounds of the text as being displayed by setting the mouse position |
629 | whenever the mouse has left the text area. | 629 | whenever the mouse has left the text area. |
630 | 630 | ||
631 | Two reasons to do so: | 631 | Two reasons to do so: |
632 | 1) QT does not allow the `grabMouse' to confine-to the TEWidget. | 632 | 1) QT does not allow the `grabMouse' to confine-to the TEWidget. |
633 | Thus a `XGrapPointer' would have to be used instead. | 633 | Thus a `XGrapPointer' would have to be used instead. |
634 | 2) Even if so, this would not help too much, since the text area | 634 | 2) Even if so, this would not help too much, since the text area |
635 | of the TEWidget is normally not identical with it's bounds. | 635 | of the TEWidget is normally not identical with it's bounds. |
636 | 636 | ||
637 | The disadvantage of the current handling is, that the mouse can visibly | 637 | The disadvantage of the current handling is, that the mouse can visibly |
638 | leave the bounds of the widget and is then moved back. Because of the | 638 | leave the bounds of the widget and is then moved back. Because of the |
639 | current construction, and the reasons mentioned above, we cannot do better | 639 | current construction, and the reasons mentioned above, we cannot do better |
640 | without changing the overall construction. | 640 | without changing the overall construction. |
641 | */ | 641 | */ |
642 | 642 | ||
643 | /*! | 643 | /*! |
644 | */ | 644 | */ |
645 | 645 | ||
646 | void TEWidget::mousePressEvent(QMouseEvent* ev) | 646 | void TEWidget::mousePressEvent(QMouseEvent* ev) |
647 | { | 647 | { |
648 | //printf("press [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); | 648 | //printf("press [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); |
649 | if ( !contentsRect().contains(ev->pos()) ) return; | 649 | if ( !contentsRect().contains(ev->pos()) ) return; |
650 | QPoint tL = contentsRect().topLeft(); | 650 | QPoint tL = contentsRect().topLeft(); |
651 | int tLx = tL.x(); | 651 | int tLx = tL.x(); |
652 | int tLy = tL.y(); | 652 | int tLy = tL.y(); |
653 | 653 | ||
654 | word_selection_mode = FALSE; | 654 | word_selection_mode = FALSE; |
655 | 655 | ||
656 | //printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY); | 656 | //printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY); |
657 | if ( ev->button() == LeftButton) | 657 | if ( ev->button() == LeftButton) |
658 | { | 658 | { |
659 | QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); | 659 | QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); |
660 | 660 | ||
661 | if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ; | 661 | if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ; |
662 | 662 | ||
663 | if (mouse_marks || (ev->state() & ShiftButton)) | 663 | if (mouse_marks || (ev->state() & ShiftButton)) |
664 | { | 664 | { |
665 | emit clearSelectionSignal(); | 665 | emit clearSelectionSignal(); |
666 | iPntSel = pntSel = pos; | 666 | iPntSel = pntSel = pos; |
667 | actSel = 1; // left mouse button pressed but nothing selected yet. | 667 | actSel = 1; // left mouse button pressed but nothing selected yet. |
668 | grabMouse( /*crossCursor*/ ); // handle with care! | 668 | grabMouse( /*crossCursor*/ ); // handle with care! |
669 | } | 669 | } |
670 | else | 670 | else |
671 | { | 671 | { |
672 | emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button | 672 | emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button |
673 | } | 673 | } |
674 | } | 674 | } |
675 | if ( ev->button() == MidButton ) | 675 | if ( ev->button() == MidButton ) |
676 | { | 676 | { |
677 | emitSelection(); | 677 | emitSelection(); |
678 | } | 678 | } |
679 | if ( ev->button() == RightButton ) // Configure | 679 | if ( ev->button() == RightButton ) // Configure |
680 | { | 680 | { |
681 | emit configureRequest( this, ev->state()&(ShiftButton|ControlButton), ev->x(), ev->y() ); | 681 | emit configureRequest( this, ev->state()&(ShiftButton|ControlButton), ev->x(), ev->y() ); |
682 | } | 682 | } |
683 | } | 683 | } |
684 | 684 | ||
685 | void TEWidget::mouseMoveEvent(QMouseEvent* ev) | 685 | void TEWidget::mouseMoveEvent(QMouseEvent* ev) |
686 | { | 686 | { |
687 | // for auto-hiding the cursor, we need mouseTracking | 687 | // for auto-hiding the cursor, we need mouseTracking |
688 | if (ev->state() == NoButton ) return; | 688 | if (ev->state() == NoButton ) return; |
689 | 689 | ||
690 | if (actSel == 0) return; | 690 | if (actSel == 0) return; |
691 | 691 | ||
692 | // don't extend selection while pasting | 692 | // don't extend selection while pasting |
693 | if (ev->state() & MidButton) return; | 693 | if (ev->state() & MidButton) return; |
694 | 694 | ||
695 | //if ( !contentsRect().contains(ev->pos()) ) return; | 695 | //if ( !contentsRect().contains(ev->pos()) ) return; |
696 | QPoint tL = contentsRect().topLeft(); | 696 | QPoint tL = contentsRect().topLeft(); |
697 | int tLx = tL.x(); | 697 | int tLx = tL.x(); |
698 | int tLy = tL.y(); | 698 | int tLy = tL.y(); |
699 | int scroll = scrollbar->value(); | 699 | int scroll = scrollbar->value(); |
700 | 700 | ||
701 | // we're in the process of moving the mouse with the left button pressed | 701 | // we're in the process of moving the mouse with the left button pressed |
702 | // the mouse cursor will kept catched within the bounds of the text in | 702 | // the mouse cursor will kept catched within the bounds of the text in |
703 | // this widget. | 703 | // this widget. |
704 | 704 | ||
705 | // Adjust position within text area bounds. See FIXME above. | 705 | // Adjust position within text area bounds. See FIXME above. |
706 | QPoint pos = ev->pos(); | 706 | QPoint pos = ev->pos(); |
707 | if ( pos.x() < tLx+blX ) pos.setX( tLx+blX ); | 707 | if ( pos.x() < tLx+blX ) pos.setX( tLx+blX ); |
708 | if ( pos.x() > tLx+blX+columns*font_w-1 ) pos.setX( tLx+blX+columns*font_w ); | 708 | if ( pos.x() > tLx+blX+columns*font_w-1 ) pos.setX( tLx+blX+columns*font_w ); |
709 | if ( pos.y() < tLy+bY ) pos.setY( tLy+bY ); | 709 | if ( pos.y() < tLy+bY ) pos.setY( tLy+bY ); |
710 | if ( pos.y() > tLy+bY+lines*font_h-1 ) pos.setY( tLy+bY+lines*font_h-1 ); | 710 | if ( pos.y() > tLy+bY+lines*font_h-1 ) pos.setY( tLy+bY+lines*font_h-1 ); |
711 | // check if we produce a mouse move event by this | 711 | // check if we produce a mouse move event by this |
712 | if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos)); | 712 | if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos)); |
713 | 713 | ||
714 | if ( pos.y() == tLy+bY+lines*font_h-1 ) | 714 | if ( pos.y() == tLy+bY+lines*font_h-1 ) |
715 | { | 715 | { |
716 | scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward | 716 | scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward |
717 | } | 717 | } |
718 | if ( pos.y() == tLy+bY ) | 718 | if ( pos.y() == tLy+bY ) |
719 | { | 719 | { |
720 | scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback | 720 | scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback |
721 | } | 721 | } |
722 | 722 | ||
723 | QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h); | 723 | QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h); |
724 | QPoint ohere; | 724 | QPoint ohere; |
725 | bool swapping = FALSE; | 725 | bool swapping = FALSE; |
726 | 726 | ||
727 | if ( word_selection_mode ) | 727 | if ( word_selection_mode ) |
728 | { | 728 | { |
729 | // Extend to word boundaries | 729 | // Extend to word boundaries |
730 | int i; | 730 | int i; |
731 | int selClass; | 731 | int selClass; |
732 | 732 | ||
733 | bool left_not_right = ( here.y() < iPntSel.y() || | 733 | bool left_not_right = ( here.y() < iPntSel.y() || |
734 | here.y() == iPntSel.y() && here.x() < iPntSel.x() ); | 734 | here.y() == iPntSel.y() && here.x() < iPntSel.x() ); |
735 | bool old_left_not_right = ( pntSel.y() < iPntSel.y() || | 735 | bool old_left_not_right = ( pntSel.y() < iPntSel.y() || |
736 | pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() ); | 736 | pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() ); |
737 | swapping = left_not_right != old_left_not_right; | 737 | swapping = left_not_right != old_left_not_right; |
738 | 738 | ||
739 | // Find left (left_not_right ? from here : from start) | 739 | // Find left (left_not_right ? from here : from start) |
740 | QPoint left = left_not_right ? here : iPntSel; | 740 | QPoint left = left_not_right ? here : iPntSel; |
741 | i = loc(left.x(),left.y()); | 741 | i = loc(left.x(),left.y()); |
742 | selClass = charClass(image[i].c); | 742 | selClass = charClass(image[i].c); |
743 | while ( left.x() > 0 && charClass(image[i-1].c) == selClass ) | 743 | while ( left.x() > 0 && charClass(image[i-1].c) == selClass ) |
744 | { i--; left.rx()--; } | 744 | { i--; left.rx()--; } |
745 | 745 | ||
746 | // Find left (left_not_right ? from start : from here) | 746 | // Find left (left_not_right ? from start : from here) |
747 | QPoint right = left_not_right ? iPntSel : here; | 747 | QPoint right = left_not_right ? iPntSel : here; |
748 | i = loc(right.x(),right.y()); | 748 | i = loc(right.x(),right.y()); |
749 | selClass = charClass(image[i].c); | 749 | selClass = charClass(image[i].c); |
750 | while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass ) | 750 | while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass ) |
751 | { i++; right.rx()++; } | 751 | { i++; right.rx()++; } |
752 | 752 | ||
753 | // Pick which is start (ohere) and which is extension (here) | 753 | // Pick which is start (ohere) and which is extension (here) |
754 | if ( left_not_right ) | 754 | if ( left_not_right ) |
755 | { | 755 | { |
756 | here = left; ohere = right; | 756 | here = left; ohere = right; |
757 | } | 757 | } |
758 | else | 758 | else |
759 | { | 759 | { |
760 | here = right; ohere = left; | 760 | here = right; ohere = left; |
761 | } | 761 | } |
762 | } | 762 | } |
763 | 763 | ||
764 | if (here == pntSel && scroll == scrollbar->value()) return; // not moved | 764 | if (here == pntSel && scroll == scrollbar->value()) return; // not moved |
765 | 765 | ||
766 | if ( word_selection_mode ) { | 766 | if ( word_selection_mode ) { |
767 | if ( actSel < 2 || swapping ) { | 767 | if ( actSel < 2 || swapping ) { |
768 | emit beginSelectionSignal( ohere.x(), ohere.y() ); | 768 | emit beginSelectionSignal( ohere.x(), ohere.y() ); |
769 | } | 769 | } |
770 | } else if ( actSel < 2 ) { | 770 | } else if ( actSel < 2 ) { |
771 | emit beginSelectionSignal( pntSel.x(), pntSel.y() ); | 771 | emit beginSelectionSignal( pntSel.x(), pntSel.y() ); |
772 | } | 772 | } |
773 | 773 | ||
774 | actSel = 2; // within selection | 774 | actSel = 2; // within selection |
775 | pntSel = here; | 775 | pntSel = here; |
776 | emit extendSelectionSignal( here.x(), here.y() ); | 776 | emit extendSelectionSignal( here.x(), here.y() ); |
777 | } | 777 | } |
778 | 778 | ||
779 | void TEWidget::mouseReleaseEvent(QMouseEvent* ev) | 779 | void TEWidget::mouseReleaseEvent(QMouseEvent* ev) |
780 | { | 780 | { |
781 | //printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); | 781 | //printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); |
782 | if ( ev->button() == LeftButton) | 782 | if ( ev->button() == LeftButton) |
783 | { | 783 | { |
784 | if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks); | 784 | if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks); |
785 | preserve_line_breaks = TRUE; | 785 | preserve_line_breaks = TRUE; |
786 | actSel = 0; | 786 | actSel = 0; |
787 | 787 | ||
788 | //FIXME: emits a release event even if the mouse is | 788 | //FIXME: emits a release event even if the mouse is |
789 | // outside the range. The procedure used in `mouseMoveEvent' | 789 | // outside the range. The procedure used in `mouseMoveEvent' |
790 | // applies here, too. | 790 | // applies here, too. |
791 | 791 | ||
792 | QPoint tL = contentsRect().topLeft(); | 792 | QPoint tL = contentsRect().topLeft(); |
793 | int tLx = tL.x(); | 793 | int tLx = tL.x(); |
794 | int tLy = tL.y(); | 794 | int tLy = tL.y(); |
795 | 795 | ||
796 | if (!mouse_marks && !(ev->state() & ShiftButton)) | 796 | if (!mouse_marks && !(ev->state() & ShiftButton)) |
797 | emit mouseSignal( 3, // release | 797 | emit mouseSignal( 3, // release |
798 | (ev->x()-tLx-blX)/font_w + 1, | 798 | (ev->x()-tLx-blX)/font_w + 1, |
799 | (ev->y()-tLy-bY)/font_h + 1 ); | 799 | (ev->y()-tLy-bY)/font_h + 1 ); |
800 | releaseMouse(); | 800 | releaseMouse(); |
801 | } | 801 | } |
802 | } | 802 | } |
803 | 803 | ||
804 | void TEWidget::mouseDoubleClickEvent(QMouseEvent* ev) | 804 | void TEWidget::mouseDoubleClickEvent(QMouseEvent* ev) |
805 | { | 805 | { |
806 | if ( ev->button() != LeftButton) return; | 806 | if ( ev->button() != LeftButton) return; |
807 | 807 | ||
808 | QPoint tL = contentsRect().topLeft(); | 808 | QPoint tL = contentsRect().topLeft(); |
809 | int tLx = tL.x(); | 809 | int tLx = tL.x(); |
810 | int tLy = tL.y(); | 810 | int tLy = tL.y(); |
811 | QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); | 811 | QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); |
812 | 812 | ||
813 | // pass on double click as two clicks. | 813 | // pass on double click as two clicks. |
814 | if (!mouse_marks && !(ev->state() & ShiftButton)) | 814 | if (!mouse_marks && !(ev->state() & ShiftButton)) |
815 | { | 815 | { |
816 | emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button | 816 | emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button |
817 | emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release | 817 | emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release |
818 | emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button | 818 | emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button |
819 | return; | 819 | return; |
820 | } | 820 | } |
821 | 821 | ||
822 | 822 | ||
823 | emit clearSelectionSignal(); | 823 | emit clearSelectionSignal(); |
824 | QPoint bgnSel = pos; | 824 | QPoint bgnSel = pos; |
825 | QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); | 825 | QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); |
826 | int i = loc(bgnSel.x(),bgnSel.y()); | 826 | int i = loc(bgnSel.x(),bgnSel.y()); |
827 | iPntSel = bgnSel; | 827 | iPntSel = bgnSel; |
828 | 828 | ||
829 | word_selection_mode = TRUE; | 829 | word_selection_mode = TRUE; |
830 | 830 | ||
831 | // find word boundaries... | 831 | // find word boundaries... |
832 | int selClass = charClass(image[i].c); | 832 | int selClass = charClass(image[i].c); |
833 | { | 833 | { |
834 | // set the start... | 834 | // set the start... |
835 | int x = bgnSel.x(); | 835 | int x = bgnSel.x(); |
836 | while ( x > 0 && charClass(image[i-1].c) == selClass ) | 836 | while ( x > 0 && charClass(image[i-1].c) == selClass ) |
837 | { i--; x--; } | 837 | { i--; x--; } |
838 | bgnSel.setX(x); | 838 | bgnSel.setX(x); |
839 | emit beginSelectionSignal( bgnSel.x(), bgnSel.y() ); | 839 | emit beginSelectionSignal( bgnSel.x(), bgnSel.y() ); |
840 | 840 | ||
841 | // set the end... | 841 | // set the end... |
842 | i = loc( endSel.x(), endSel.y() ); | 842 | i = loc( endSel.x(), endSel.y() ); |
843 | x = endSel.x(); | 843 | x = endSel.x(); |
844 | while( x < columns-1 && charClass(image[i+1].c) == selClass ) | 844 | while( x < columns-1 && charClass(image[i+1].c) == selClass ) |
845 | { i++; x++ ; } | 845 | { i++; x++ ; } |
846 | endSel.setX(x); | 846 | endSel.setX(x); |
847 | actSel = 2; // within selection | 847 | actSel = 2; // within selection |
848 | emit extendSelectionSignal( endSel.x(), endSel.y() ); | 848 | emit extendSelectionSignal( endSel.x(), endSel.y() ); |
849 | emit endSelectionSignal(preserve_line_breaks); | 849 | emit endSelectionSignal(preserve_line_breaks); |
850 | preserve_line_breaks = TRUE; | 850 | preserve_line_breaks = TRUE; |
851 | } | 851 | } |
852 | } | 852 | } |
853 | 853 | ||
854 | void TEWidget::focusInEvent( QFocusEvent * ) | 854 | void TEWidget::focusInEvent( QFocusEvent * ) |
855 | { | 855 | { |
856 | 856 | ||
857 | // do nothing, to prevent repainting | 857 | // do nothing, to prevent repainting |
858 | } | 858 | } |
859 | 859 | ||
860 | 860 | ||
861 | void TEWidget::focusOutEvent( QFocusEvent * ) | 861 | void TEWidget::focusOutEvent( QFocusEvent * ) |
862 | { | 862 | { |
863 | // do nothing, to prevent repainting | 863 | // do nothing, to prevent repainting |
864 | } | 864 | } |
865 | 865 | ||
866 | bool TEWidget::focusNextPrevChild( bool next ) | 866 | bool TEWidget::focusNextPrevChild( bool next ) |
867 | { | 867 | { |
868 | if (next) | 868 | if (next) |
869 | return false; // This disables changing the active part in konqueror | 869 | return false; // This disables changing the active part in konqueror |
870 | // when pressing Tab | 870 | // when pressing Tab |
871 | return QFrame::focusNextPrevChild( next ); | 871 | return QFrame::focusNextPrevChild( next ); |
872 | } | 872 | } |
873 | 873 | ||
874 | 874 | ||
875 | int TEWidget::charClass(char ch) const | 875 | int TEWidget::charClass(char ch) const |
876 | { | 876 | { |
877 | // This might seem like overkill, but imagine if ch was a Unicode | 877 | // This might seem like overkill, but imagine if ch was a Unicode |
878 | // character (Qt 2.0 QChar) - it might then be sensible to separate | 878 | // character (Qt 2.0 QChar) - it might then be sensible to separate |
879 | // the different language ranges, etc. | 879 | // the different language ranges, etc. |
880 | 880 | ||
881 | if ( isspace(ch) ) return ' '; | 881 | if ( isspace(ch) ) return ' '; |
882 | 882 | ||
883 | static const char *word_characters = ":@-./_~"; | 883 | static const char *word_characters = ":@-./_~"; |
884 | if ( isalnum(ch) || strchr(word_characters, ch) ) | 884 | if ( isalnum(ch) || strchr(word_characters, ch) ) |
885 | return 'a'; | 885 | return 'a'; |
886 | 886 | ||
887 | // Everything else is weird | 887 | // Everything else is weird |
888 | return 1; | 888 | return 1; |
889 | } | 889 | } |
890 | 890 | ||
891 | void TEWidget::setMouseMarks(bool on) | 891 | void TEWidget::setMouseMarks(bool on) |
892 | { | 892 | { |
893 | mouse_marks = on; | 893 | mouse_marks = on; |
894 | setCursor( mouse_marks ? ibeamCursor : arrowCursor ); | 894 | setCursor( mouse_marks ? ibeamCursor : arrowCursor ); |
895 | } | 895 | } |
896 | 896 | ||
897 | /* ------------------------------------------------------------------------- */ | 897 | /* ------------------------------------------------------------------------- */ |
898 | /* */ | 898 | /* */ |
899 | /* Clipboard */ | 899 | /* Clipboard */ |
900 | /* */ | 900 | /* */ |
901 | /* ------------------------------------------------------------------------- */ | 901 | /* ------------------------------------------------------------------------- */ |
902 | 902 | ||
903 | #undef KeyPress | 903 | #undef KeyPress |
904 | 904 | ||
905 | void TEWidget::emitSelection() | 905 | void TEWidget::emitSelection() |
906 | // Paste Clipboard by simulating keypress events | 906 | // Paste Clipboard by simulating keypress events |
907 | { | 907 | { |
908 | #ifndef QT_NO_CLIPBOARD | 908 | #ifndef QT_NO_CLIPBOARD |
909 | QString text = QApplication::clipboard()->text(); | 909 | QString text = QApplication::clipboard()->text(); |
910 | if ( ! text.isNull() ) | 910 | if ( ! text.isNull() ) |
911 | { | 911 | { |
912 | text.replace(QRegExp("\n"), "\r"); | 912 | text.replace(QRegExp("\n"), "\r"); |
913 | QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); | 913 | QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); |
914 | emit keyPressedSignal(&e); // expose as a big fat keypress event | 914 | emit keyPressedSignal(&e); // expose as a big fat keypress event |
915 | emit clearSelectionSignal(); | 915 | emit clearSelectionSignal(); |
916 | } | 916 | } |
917 | #endif | 917 | #endif |
918 | } | 918 | } |
919 | 919 | ||
920 | void TEWidget::emitText(QString text) | 920 | void TEWidget::emitText(QString text) |
921 | { | 921 | { |
922 | QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); | 922 | QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); |
923 | emit keyPressedSignal(&e); // expose as a big fat keypress event | 923 | emit keyPressedSignal(&e); // expose as a big fat keypress event |
924 | } | 924 | } |
925 | 925 | ||
926 | void TEWidget::pasteClipboard( ) | 926 | void TEWidget::pasteClipboard( ) |
927 | { | 927 | { |
928 | emitSelection(); | 928 | emitSelection(); |
929 | } | 929 | } |
930 | 930 | ||
931 | void TEWidget::setSelection(const QString& t) | 931 | void TEWidget::setSelection(const QString& t) |
932 | { | 932 | { |
933 | #ifndef QT_NO_CLIPBOARD | 933 | #ifndef QT_NO_CLIPBOARD |
934 | // Disconnect signal while WE set the clipboard | 934 | // Disconnect signal while WE set the clipboard |
935 | QObject *cb = QApplication::clipboard(); | 935 | QObject *cb = QApplication::clipboard(); |
936 | QObject::disconnect( cb, SIGNAL(dataChanged()), | 936 | QObject::disconnect( cb, SIGNAL(dataChanged()), |
937 | this, SLOT(onClearSelection()) ); | 937 | this, SLOT(onClearSelection()) ); |
938 | 938 | ||
939 | QApplication::clipboard()->setText(t); | 939 | QApplication::clipboard()->setText(t); |
940 | 940 | ||
941 | QObject::connect( cb, SIGNAL(dataChanged()), | 941 | QObject::connect( cb, SIGNAL(dataChanged()), |
942 | this, SLOT(onClearSelection()) ); | 942 | this, SLOT(onClearSelection()) ); |
943 | #endif | 943 | #endif |
944 | } | 944 | } |
945 | 945 | ||
946 | void TEWidget::onClearSelection() | 946 | void TEWidget::onClearSelection() |
947 | { | 947 | { |
948 | emit clearSelectionSignal(); | 948 | emit clearSelectionSignal(); |
949 | } | 949 | } |
950 | 950 | ||
951 | /* ------------------------------------------------------------------------- */ | 951 | /* ------------------------------------------------------------------------- */ |
952 | /* */ | 952 | /* */ |
953 | /* Keyboard */ | 953 | /* Keyboard */ |
954 | /* */ | 954 | /* */ |
955 | /* ------------------------------------------------------------------------- */ | 955 | /* ------------------------------------------------------------------------- */ |
956 | 956 | ||
957 | //FIXME: an `eventFilter' has been installed instead of a `keyPressEvent' | 957 | //FIXME: an `eventFilter' has been installed instead of a `keyPressEvent' |
958 | // due to a bug in `QT' or the ignorance of the author to prevent | 958 | // due to a bug in `QT' or the ignorance of the author to prevent |
959 | // repaint events being emitted to the screen whenever one leaves | 959 | // repaint events being emitted to the screen whenever one leaves |
960 | // or reenters the screen to/from another application. | 960 | // or reenters the screen to/from another application. |
961 | // | 961 | // |
962 | // Troll says one needs to change focusInEvent() and focusOutEvent(), | 962 | // Troll says one needs to change focusInEvent() and focusOutEvent(), |
963 | // which would also let you have an in-focus cursor and an out-focus | 963 | // which would also let you have an in-focus cursor and an out-focus |
964 | // cursor like xterm does. | 964 | // cursor like xterm does. |
965 | 965 | ||
966 | // for the auto-hide cursor feature, I added empty focusInEvent() and | 966 | // for the auto-hide cursor feature, I added empty focusInEvent() and |
967 | // focusOutEvent() so that update() isn't called. | 967 | // focusOutEvent() so that update() isn't called. |
968 | // For auto-hide, we need to get keypress-events, but we only get them when | 968 | // For auto-hide, we need to get keypress-events, but we only get them when |
969 | // we have focus. | 969 | // we have focus. |
970 | 970 | ||
971 | void TEWidget::doScroll(int lines) | 971 | void TEWidget::doScroll(int lines) |
972 | { | 972 | { |
973 | scrollbar->setValue(scrollbar->value()+lines); | 973 | scrollbar->setValue(scrollbar->value()+lines); |
974 | } | 974 | } |
975 | 975 | ||
976 | bool TEWidget::eventFilter( QObject *obj, QEvent *e ) | 976 | bool TEWidget::eventFilter( QObject *obj, QEvent *e ) |
977 | { | 977 | { |
978 | if ( (e->type() == QEvent::Accel || | 978 | if ( (e->type() == QEvent::Accel || |
979 | e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) { | 979 | e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) { |
980 | static_cast<QKeyEvent *>( e )->ignore(); | 980 | static_cast<QKeyEvent *>( e )->ignore(); |
981 | return true; | 981 | return true; |
982 | } | 982 | } |
983 | if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) | 983 | if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) |
984 | return FALSE; // not us | 984 | return FALSE; // not us |
985 | if ( e->type() == QEvent::Wheel) { | 985 | if ( e->type() == QEvent::Wheel) { |
986 | QApplication::sendEvent(scrollbar, e); | 986 | QApplication::sendEvent(scrollbar, e); |
987 | } | 987 | } |
988 | 988 | ||
989 | #ifdef FAKE_CTRL_AND_ALT | 989 | #ifdef FAKE_CTRL_AND_ALT |
990 | static bool control = FALSE; | 990 | static bool control = FALSE; |
991 | static bool alt = FALSE; | 991 | static bool alt = FALSE; |
992 | // qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:"); | 992 | // qDebug(" Has a keyboard with no CTRL and ALT keys, but we fake it:"); |
993 | bool dele=FALSE; | 993 | bool dele=FALSE; |
994 | if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { | 994 | if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { |
995 | QKeyEvent* ke = (QKeyEvent*)e; | 995 | QKeyEvent* ke = (QKeyEvent*)e; |
996 | bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); | 996 | bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); |
997 | switch (ke->key()) { | 997 | switch (ke->key()) { |
998 | case Key_F9: // let this be "Control" | 998 | case Key_F9: // let this be "Control" |
999 | control = keydown; | 999 | control = keydown; |
1000 | e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); | 1000 | e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); |
1001 | dele=TRUE; | 1001 | dele=TRUE; |
1002 | break; | 1002 | break; |
1003 | case Key_F13: // let this be "Alt" | 1003 | case Key_F13: // let this be "Alt" |
1004 | alt = keydown; | 1004 | alt = keydown; |
1005 | e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); | 1005 | e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); |
1006 | dele=TRUE; | 1006 | dele=TRUE; |
1007 | break; | 1007 | break; |
1008 | default: | 1008 | default: |
1009 | if ( control ) { | 1009 | if ( control ) { |
1010 | int a = toupper(ke->ascii())-64; | 1010 | int a = toupper(ke->ascii())-64; |
1011 | if ( a >= 0 && a < ' ' ) { | 1011 | if ( a >= 0 && a < ' ' ) { |
1012 | e = new QKeyEvent(e->type(), ke->key(), | 1012 | e = new QKeyEvent(e->type(), ke->key(), |
1013 | a, ke->state()|ControlButton, QChar(a,0)); | 1013 | a, ke->state()|ControlButton, QChar(a,0)); |
1014 | dele=TRUE; | 1014 | dele=TRUE; |
1015 | } | 1015 | } |
1016 | } | 1016 | } |
1017 | if ( alt ) { | 1017 | if ( alt ) { |
1018 | e = new QKeyEvent(e->type(), ke->key(), | 1018 | e = new QKeyEvent(e->type(), ke->key(), |
1019 | ke->ascii(), ke->state()|AltButton, ke->text()); | 1019 | ke->ascii(), ke->state()|AltButton, ke->text()); |
1020 | dele=TRUE; | 1020 | dele=TRUE; |
1021 | } | 1021 | } |
1022 | } | 1022 | } |
1023 | } | 1023 | } |
1024 | #endif | 1024 | #endif |
1025 | 1025 | ||
1026 | if ( e->type() == QEvent::KeyPress ) { | 1026 | if ( e->type() == QEvent::KeyPress ) { |
1027 | QKeyEvent* ke = (QKeyEvent*)e; | 1027 | QKeyEvent* ke = (QKeyEvent*)e; |
1028 | actSel=0; // Key stroke implies a screen update, so TEWidget won't | 1028 | actSel=0; // Key stroke implies a screen update, so TEWidget won't |
1029 | // know where the current selection is. | 1029 | // know where the current selection is. |
1030 | 1030 | ||
1031 | qDebug("key pressed is 0x%x",ke->key()); | 1031 | // qDebug("key pressed is 0x%x",ke->key()); |
1032 | |||
1032 | if( ke->state() == ShiftButton && ke->key() == Key_Tab) { //lets hardcode this sucker | 1033 | if( ke->state() == ShiftButton && ke->key() == Key_Tab) { //lets hardcode this sucker |
1033 | qDebug("key pressed 2 is 0x%x",ke->key()); | 1034 | |
1035 | // qDebug("key pressed 2 is 0x%x",ke->key()); | ||
1034 | emitText("\\"); // expose | 1036 | emitText("\\"); // expose |
1035 | } else | 1037 | } else |
1036 | emit keyPressedSignal(ke); // expose | 1038 | emit keyPressedSignal(ke); // expose |
1037 | ke->accept(); | 1039 | ke->accept(); |
1038 | #ifdef FAKE_CTRL_AND_ALT | 1040 | #ifdef FAKE_CTRL_AND_ALT |
1039 | if ( dele ) delete e; | 1041 | if ( dele ) delete e; |
1040 | #endif | 1042 | #endif |
1041 | return true; // stop the event | 1043 | return true; // stop the event |
1042 | } | 1044 | } |
1043 | if ( e->type() == QEvent::Enter ) { | 1045 | if ( e->type() == QEvent::Enter ) { |
1044 | QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()), | 1046 | QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()), |
1045 | this, SLOT(onClearSelection()) ); | 1047 | this, SLOT(onClearSelection()) ); |
1046 | } | 1048 | } |
1047 | if ( e->type() == QEvent::Leave ) { | 1049 | if ( e->type() == QEvent::Leave ) { |
1048 | QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), | 1050 | QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), |
1049 | this, SLOT(onClearSelection()) ); | 1051 | this, SLOT(onClearSelection()) ); |
1050 | } | 1052 | } |
1051 | return QFrame::eventFilter( obj, e ); | 1053 | return QFrame::eventFilter( obj, e ); |
1052 | } | 1054 | } |
1053 | 1055 | ||
1054 | /* ------------------------------------------------------------------------- */ | 1056 | /* ------------------------------------------------------------------------- */ |
1055 | /* */ | 1057 | /* */ |
1056 | /* Frame */ | 1058 | /* Frame */ |
1057 | /* */ | 1059 | /* */ |
1058 | /* ------------------------------------------------------------------------- */ | 1060 | /* ------------------------------------------------------------------------- */ |
1059 | 1061 | ||
1060 | void TEWidget::frameChanged() | 1062 | void TEWidget::frameChanged() |
1061 | { | 1063 | { |
1062 | propagateSize(); | 1064 | propagateSize(); |
1063 | update(); | 1065 | update(); |
1064 | } | 1066 | } |
1065 | 1067 | ||
1066 | /* ------------------------------------------------------------------------- */ | 1068 | /* ------------------------------------------------------------------------- */ |
1067 | /* */ | 1069 | /* */ |
1068 | /* Sound */ | 1070 | /* Sound */ |
1069 | /* */ | 1071 | /* */ |
1070 | /* ------------------------------------------------------------------------- */ | 1072 | /* ------------------------------------------------------------------------- */ |
1071 | 1073 | ||
1072 | void TEWidget::Bell() | 1074 | void TEWidget::Bell() |
1073 | { | 1075 | { |
1074 | QApplication::beep(); | 1076 | QApplication::beep(); |
1075 | } | 1077 | } |
1076 | 1078 | ||
1077 | /* ------------------------------------------------------------------------- */ | 1079 | /* ------------------------------------------------------------------------- */ |
1078 | /* */ | 1080 | /* */ |
1079 | /* Auxiluary */ | 1081 | /* Auxiluary */ |
1080 | /* */ | 1082 | /* */ |
1081 | /* ------------------------------------------------------------------------- */ | 1083 | /* ------------------------------------------------------------------------- */ |
1082 | 1084 | ||
1083 | void TEWidget::clearImage() | 1085 | void TEWidget::clearImage() |
1084 | // initialize the image | 1086 | // initialize the image |
1085 | // for internal use only | 1087 | // for internal use only |
1086 | { | 1088 | { |
1087 | for (int y = 0; y < lines; y++) | 1089 | for (int y = 0; y < lines; y++) |
1088 | for (int x = 0; x < columns; x++) | 1090 | for (int x = 0; x < columns; x++) |
1089 | { | 1091 | { |
1090 | image[loc(x,y)].c = 0xff; //' '; | 1092 | image[loc(x,y)].c = 0xff; //' '; |
1091 | image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR; | 1093 | image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR; |
1092 | image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR; | 1094 | image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR; |
1093 | image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION; | 1095 | image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION; |
1094 | } | 1096 | } |
1095 | } | 1097 | } |
1096 | 1098 | ||
1097 | // Create Image /////////////////////////////////////////////////////// | 1099 | // Create Image /////////////////////////////////////////////////////// |
1098 | 1100 | ||
1099 | void TEWidget::calcGeometry() | 1101 | void TEWidget::calcGeometry() |
1100 | { | 1102 | { |
1101 | //FIXME: set rimX == rimY == 0 when running in full screen mode. | 1103 | //FIXME: set rimX == rimY == 0 when running in full screen mode. |
1102 | 1104 | ||
1103 | scrollbar->resize(QApplication::style().scrollBarExtent().width(), | 1105 | scrollbar->resize(QApplication::style().scrollBarExtent().width(), |
1104 | contentsRect().height()); | 1106 | contentsRect().height()); |
1105 | switch(scrollLoc) | 1107 | switch(scrollLoc) |
1106 | { | 1108 | { |
1107 | case SCRNONE : | 1109 | case SCRNONE : |
1108 | columns = ( contentsRect().width() - 2 * rimX ) / font_w; | 1110 | columns = ( contentsRect().width() - 2 * rimX ) / font_w; |
1109 | blX = (contentsRect().width() - (columns*font_w) ) / 2; | 1111 | blX = (contentsRect().width() - (columns*font_w) ) / 2; |
1110 | brX = blX; | 1112 | brX = blX; |
1111 | scrollbar->hide(); | 1113 | scrollbar->hide(); |
1112 | break; | 1114 | break; |
1113 | case SCRLEFT : | 1115 | case SCRLEFT : |
1114 | columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; | 1116 | columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; |
1115 | brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; | 1117 | brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; |
1116 | blX = brX + scrollbar->width(); | 1118 | blX = brX + scrollbar->width(); |
1117 | scrollbar->move(contentsRect().topLeft()); | 1119 | scrollbar->move(contentsRect().topLeft()); |
1118 | scrollbar->show(); | 1120 | scrollbar->show(); |
1119 | break; | 1121 | break; |
1120 | case SCRRIGHT: | 1122 | case SCRRIGHT: |
1121 | columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; | 1123 | columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; |
1122 | blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; | 1124 | blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; |
1123 | brX = blX; | 1125 | brX = blX; |
1124 | scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0)); | 1126 | scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0)); |
1125 | scrollbar->show(); | 1127 | scrollbar->show(); |
1126 | break; | 1128 | break; |
1127 | } | 1129 | } |
1128 | //FIXME: support 'rounding' styles | 1130 | //FIXME: support 'rounding' styles |
1129 | lines = ( contentsRect().height() - 2 * rimY ) / font_h; | 1131 | lines = ( contentsRect().height() - 2 * rimY ) / font_h; |
1130 | bY = (contentsRect().height() - (lines *font_h)) / 2; | 1132 | bY = (contentsRect().height() - (lines *font_h)) / 2; |
1131 | } | 1133 | } |
1132 | 1134 | ||
1133 | void TEWidget::makeImage() | 1135 | void TEWidget::makeImage() |
1134 | //FIXME: rename 'calcGeometry? | 1136 | //FIXME: rename 'calcGeometry? |
1135 | { | 1137 | { |
1136 | calcGeometry(); | 1138 | calcGeometry(); |
1137 | image = (ca*) malloc(lines*columns*sizeof(ca)); | 1139 | image = (ca*) malloc(lines*columns*sizeof(ca)); |
1138 | clearImage(); | 1140 | clearImage(); |
1139 | } | 1141 | } |
1140 | 1142 | ||
1141 | // calculate the needed size | 1143 | // calculate the needed size |
1142 | QSize TEWidget::calcSize(int cols, int lins) const | 1144 | QSize TEWidget::calcSize(int cols, int lins) const |
1143 | { | 1145 | { |
1144 | int frw = width() - contentsRect().width(); | 1146 | int frw = width() - contentsRect().width(); |
1145 | int frh = height() - contentsRect().height(); | 1147 | int frh = height() - contentsRect().height(); |
1146 | int scw = (scrollLoc==SCRNONE?0:scrollbar->width()); | 1148 | int scw = (scrollLoc==SCRNONE?0:scrollbar->width()); |
1147 | return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh ); | 1149 | return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh ); |
1148 | } | 1150 | } |
1149 | 1151 | ||
1150 | QSize TEWidget::sizeHint() const | 1152 | QSize TEWidget::sizeHint() const |
1151 | { | 1153 | { |
1152 | return size(); | 1154 | return size(); |
1153 | } | 1155 | } |
1154 | 1156 | ||
1155 | void TEWidget::styleChange(QStyle &) | 1157 | void TEWidget::styleChange(QStyle &) |
1156 | { | 1158 | { |
1157 | propagateSize(); | 1159 | propagateSize(); |
1158 | } | 1160 | } |
1159 | 1161 | ||
1160 | #ifndef QT_NO_DRAGANDDROP | 1162 | #ifndef QT_NO_DRAGANDDROP |
1161 | 1163 | ||
1162 | /* --------------------------------------------------------------------- */ | 1164 | /* --------------------------------------------------------------------- */ |
1163 | /* */ | 1165 | /* */ |
1164 | /* Drag & Drop */ | 1166 | /* Drag & Drop */ |
1165 | /* */ | 1167 | /* */ |
1166 | /* --------------------------------------------------------------------- */ | 1168 | /* --------------------------------------------------------------------- */ |
1167 | 1169 | ||
1168 | 1170 | ||
1169 | void TEWidget::dragEnterEvent(QDragEnterEvent* e) | 1171 | void TEWidget::dragEnterEvent(QDragEnterEvent* e) |
1170 | { | 1172 | { |
1171 | e->accept(QTextDrag::canDecode(e) || | 1173 | e->accept(QTextDrag::canDecode(e) || |
1172 | QUriDrag::canDecode(e)); | 1174 | QUriDrag::canDecode(e)); |
1173 | } | 1175 | } |
1174 | 1176 | ||
1175 | void TEWidget::dropEvent(QDropEvent* event) | 1177 | void TEWidget::dropEvent(QDropEvent* event) |
1176 | { | 1178 | { |
1177 | // The current behaviour when url(s) are dropped is | 1179 | // The current behaviour when url(s) are dropped is |
1178 | // * if there is only ONE url and if it's a LOCAL one, ask for paste or cd | 1180 | // * if there is only ONE url and if it's a LOCAL one, ask for paste or cd |
1179 | // * in all other cases, just paste | 1181 | // * in all other cases, just paste |
1180 | // (for non-local ones, or for a list of URLs, 'cd' is nonsense) | 1182 | // (for non-local ones, or for a list of URLs, 'cd' is nonsense) |
1181 | QStrList strlist; | 1183 | QStrList strlist; |
1182 | int file_count = 0; | 1184 | int file_count = 0; |
1183 | dropText = ""; | 1185 | dropText = ""; |
1184 | bool bPopup = true; | 1186 | bool bPopup = true; |
1185 | 1187 | ||
1186 | if(QUriDrag::decode(event, strlist)) { | 1188 | if(QUriDrag::decode(event, strlist)) { |
1187 | if (strlist.count()) { | 1189 | if (strlist.count()) { |
1188 | for(const char* p = strlist.first(); p; p = strlist.next()) { | 1190 | for(const char* p = strlist.first(); p; p = strlist.next()) { |
1189 | if(file_count++ > 0) { | 1191 | if(file_count++ > 0) { |
1190 | dropText += " "; | 1192 | dropText += " "; |
1191 | bPopup = false; // more than one file, don't popup | 1193 | bPopup = false; // more than one file, don't popup |
1192 | } | 1194 | } |
1193 | 1195 | ||
1194 | /* | 1196 | /* |
1195 | KURL url(p); | 1197 | KURL url(p); |
1196 | if (url.isLocalFile()) { | 1198 | if (url.isLocalFile()) { |
1197 | dropText += url.path(); // local URL : remove protocol | 1199 | dropText += url.path(); // local URL : remove protocol |
1198 | } | 1200 | } |
1199 | else { | 1201 | else { |
1200 | dropText += url.prettyURL(); | 1202 | dropText += url.prettyURL(); |
1201 | bPopup = false; // a non-local file, don't popup | 1203 | bPopup = false; // a non-local file, don't popup |
1202 | } | 1204 | } |
1203 | */ | 1205 | */ |
1204 | 1206 | ||
1205 | } | 1207 | } |
1206 | 1208 | ||
1207 | if (bPopup) | 1209 | if (bPopup) |
1208 | // m_drop->popup(pos() + event->pos()); | 1210 | // m_drop->popup(pos() + event->pos()); |
1209 | m_drop->popup(mapToGlobal(event->pos())); | 1211 | m_drop->popup(mapToGlobal(event->pos())); |
1210 | else | 1212 | else |
1211 | { | 1213 | { |
1212 | if (currentSession) { | 1214 | if (currentSession) { |
1213 | currentSession->getEmulation()->sendString(dropText.local8Bit()); | 1215 | currentSession->getEmulation()->sendString(dropText.local8Bit()); |
1214 | } | 1216 | } |
1215 | // kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; | 1217 | // kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; |
1216 | } | 1218 | } |
1217 | } | 1219 | } |
1218 | } | 1220 | } |
1219 | else if(QTextDrag::decode(event, dropText)) { | 1221 | else if(QTextDrag::decode(event, dropText)) { |
1220 | // kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; | 1222 | // kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; |
1221 | if (currentSession) { | 1223 | if (currentSession) { |
1222 | currentSession->getEmulation()->sendString(dropText.local8Bit()); | 1224 | currentSession->getEmulation()->sendString(dropText.local8Bit()); |
1223 | } | 1225 | } |
1224 | // Paste it | 1226 | // Paste it |
1225 | } | 1227 | } |
1226 | } | 1228 | } |
1227 | #endif | 1229 | #endif |
1228 | 1230 | ||
1229 | 1231 | ||
1230 | void TEWidget::drop_menu_activated(int item) | 1232 | void TEWidget::drop_menu_activated(int item) |
1231 | { | 1233 | { |
1232 | #ifndef QT_NO_DRAGANDDROP | 1234 | #ifndef QT_NO_DRAGANDDROP |
1233 | switch (item) | 1235 | switch (item) |
1234 | { | 1236 | { |
1235 | case 0: // paste | 1237 | case 0: // paste |
1236 | currentSession->getEmulation()->sendString(dropText.local8Bit()); | 1238 | currentSession->getEmulation()->sendString(dropText.local8Bit()); |
1237 | // KWM::activate((Window)this->winId()); | 1239 | // KWM::activate((Window)this->winId()); |
1238 | break; | 1240 | break; |
1239 | case 1: // cd ... | 1241 | case 1: // cd ... |
1240 | currentSession->getEmulation()->sendString("cd "); | 1242 | currentSession->getEmulation()->sendString("cd "); |
1241 | struct stat statbuf; | 1243 | struct stat statbuf; |
1242 | if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 ) | 1244 | if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 ) |
1243 | { | 1245 | { |
1244 | if ( !S_ISDIR(statbuf.st_mode) ) | 1246 | if ( !S_ISDIR(statbuf.st_mode) ) |
1245 | { | 1247 | { |
1246 | /* | 1248 | /* |
1247 | KURL url; | 1249 | KURL url; |
1248 | url.setPath( dropText ); | 1250 | url.setPath( dropText ); |
1249 | dropText = url.directory( true, false ); // remove filename | 1251 | dropText = url.directory( true, false ); // remove filename |
1250 | */ | 1252 | */ |
1251 | } | 1253 | } |
1252 | } | 1254 | } |
1253 | dropText.replace(QRegExp(" "), "\\ "); // escape spaces | 1255 | dropText.replace(QRegExp(" "), "\\ "); // escape spaces |
1254 | currentSession->getEmulation()->sendString(dropText.local8Bit()); | 1256 | currentSession->getEmulation()->sendString(dropText.local8Bit()); |
1255 | currentSession->getEmulation()->sendString("\n"); | 1257 | currentSession->getEmulation()->sendString("\n"); |
1256 | // KWM::activate((Window)this->winId()); | 1258 | // KWM::activate((Window)this->winId()); |
1257 | break; | 1259 | break; |
1258 | } | 1260 | } |
1259 | #endif | 1261 | #endif |
1260 | } | 1262 | } |
1261 | 1263 | ||