summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-write/qtextedit.cpp2469
1 files changed, 1235 insertions, 1234 deletions
diff --git a/noncore/apps/opie-write/qtextedit.cpp b/noncore/apps/opie-write/qtextedit.cpp
index 73b7b7b..bba8a65 100644
--- a/noncore/apps/opie-write/qtextedit.cpp
+++ b/noncore/apps/opie-write/qtextedit.cpp
@@ -59,10 +59,10 @@ class QTextEditPrivate
59{ 59{
60public: 60public:
61 QTextEditPrivate() 61 QTextEditPrivate()
62 :preeditStart(-1),preeditLength(-1),ensureCursorVisibleInShowEvent(FALSE) 62 :preeditStart(-1),preeditLength(-1),ensureCursorVisibleInShowEvent(FALSE)
63 { 63 {
64 for ( int i=0; i<7; i++ ) 64 for ( int i=0; i<7; i++ )
65 id[i] = 0; 65 id[i] = 0;
66 } 66 }
67 int id[ 7 ]; 67 int id[ 7 ];
68 int preeditStart; 68 int preeditStart;
@@ -95,21 +95,21 @@ static bool block_set_alignment = FALSE;
95 \table 95 \table
96 \header \i Mode \i Command \i Notes 96 \header \i Mode \i Command \i Notes
97 \row \i Plain Text Editor \i setTextFormat(PlainText) 97 \row \i Plain Text Editor \i setTextFormat(PlainText)
98 \i Set text with setText(); text() returns plain text. Text 98 \i Set text with setText(); text() returns plain text. Text
99 attributes (e.g. colors) can be set, but plain text is always 99 attributes (e.g. colors) can be set, but plain text is always
100 returned.<sup>1.</sup> 100 returned.<sup>1.</sup>
101 \row \i Rich Text Editor \i setTextFormat(RichText) 101 \row \i Rich Text Editor \i setTextFormat(RichText)
102 \i Set text with setText(); text() returns rich text. Rich 102 \i Set text with setText(); text() returns rich text. Rich
103 text editing is fairly limited. You can't set margins or 103 text editing is fairly limited. You can't set margins or
104 insert images for example (although you can read and 104 insert images for example (although you can read and
105 correctly display files that have margins set and that 105 correctly display files that have margins set and that
106 include images). This mode is mostly useful for editing small 106 include images). This mode is mostly useful for editing small
107 amounts of rich text. <sup>2.</sup> 107 amounts of rich text. <sup>2.</sup>
108 \row \i Text Viewer<sup>3.</sup> \i setReadOnly(TRUE) 108 \row \i Text Viewer<sup>3.</sup> \i setReadOnly(TRUE)
109 \i Set text with setText() or append() (which has no undo 109 \i Set text with setText() or append() (which has no undo
110 history so is faster and uses less memory); text() returns 110 history so is faster and uses less memory); text() returns
111 plain or rich text depending on the textFormat(). This mode 111 plain or rich text depending on the textFormat(). This mode
112 can correctly display a large subset of HTML tags. 112 can correctly display a large subset of HTML tags.
113 \endtable 113 \endtable
114 114
115 <sup>1.</sup><small>We do \e not recommend using QTextEdit to 115 <sup>1.</sup><small>We do \e not recommend using QTextEdit to
@@ -207,16 +207,16 @@ static bool block_set_alignment = FALSE;
207 \code 207 \code
208 QFile file( fileName ); // Read the text from a file 208 QFile file( fileName ); // Read the text from a file
209 if ( file.open( IO_ReadOnly ) ) { 209 if ( file.open( IO_ReadOnly ) ) {
210 QTextStream ts( &file ); 210 QTextStream ts( &file );
211 textEdit->setText( ts.read() ); 211 textEdit->setText( ts.read() );
212 } 212 }
213 \endcode 213 \endcode
214 \code 214 \code
215 QFile file( fileName ); // Write the text to a file 215 QFile file( fileName ); // Write the text to a file
216 if ( file.open( IO_WriteOnly ) ) { 216 if ( file.open( IO_WriteOnly ) ) {
217 QTextStream ts( &file ); 217 QTextStream ts( &file );
218 ts << textEdit->text(); 218 ts << textEdit->text();
219 textEdit->setModified( FALSE ); 219 textEdit->setModified( FALSE );
220 } 220 }
221 \endcode 221 \endcode
222 222
@@ -339,7 +339,7 @@ static bool block_set_alignment = FALSE;
339 \row \i \e{Ctrl+A} \i Move the cursor to the beginning of the line 339 \row \i \e{Ctrl+A} \i Move the cursor to the beginning of the line
340 \row \i \e{Ctrl+B} \i Move the cursor one character left 340 \row \i \e{Ctrl+B} \i Move the cursor one character left
341 \row \i \e{Ctrl+C} \i Copy the marked text to the clipboard (also 341 \row \i \e{Ctrl+C} \i Copy the marked text to the clipboard (also
342 \e{Ctrl+Insert} under Windows) 342 \e{Ctrl+Insert} under Windows)
343 \row \i \e{Ctrl+D} \i Delete the character to the right of the cursor 343 \row \i \e{Ctrl+D} \i Delete the character to the right of the cursor
344 \row \i \e{Ctrl+E} \i Move the cursor to the end of the line 344 \row \i \e{Ctrl+E} \i Move the cursor to the end of the line
345 \row \i \e{Ctrl+F} \i Move the cursor one character right 345 \row \i \e{Ctrl+F} \i Move the cursor one character right
@@ -348,9 +348,9 @@ static bool block_set_alignment = FALSE;
348 \row \i \e{Ctrl+N} \i Move the cursor one line down 348 \row \i \e{Ctrl+N} \i Move the cursor one line down
349 \row \i \e{Ctrl+P} \i Move the cursor one line up 349 \row \i \e{Ctrl+P} \i Move the cursor one line up
350 \row \i \e{Ctrl+V} \i Paste the clipboard text into line edit 350 \row \i \e{Ctrl+V} \i Paste the clipboard text into line edit
351 (also \e{Shift+Insert} under Windows) 351 (also \e{Shift+Insert} under Windows)
352 \row \i \e{Ctrl+X} \i Cut the marked text, copy to clipboard 352 \row \i \e{Ctrl+X} \i Cut the marked text, copy to clipboard
353 (also \e{Shift+Delete} under Windows) 353 (also \e{Shift+Delete} under Windows)
354 \row \i \e{Ctrl+Z} \i Undo the last operation 354 \row \i \e{Ctrl+Z} \i Undo the last operation
355 \row \i \e{Ctrl+Y} \i Redo the last operation 355 \row \i \e{Ctrl+Y} \i Redo the last operation
356 \row \i \e{LeftArrow} \i Move the cursor one character left 356 \row \i \e{LeftArrow} \i Move the cursor one character left
@@ -368,7 +368,7 @@ static bool block_set_alignment = FALSE;
368 \row \i \e{End} \i Move the cursor to the end of the line 368 \row \i \e{End} \i Move the cursor to the end of the line
369 \row \i \e{Ctrl+End} \i Move the cursor to the end of the text 369 \row \i \e{Ctrl+End} \i Move the cursor to the end of the text
370 \row \i \e{Shift+Wheel} \i Scroll the page horizontally 370 \row \i \e{Shift+Wheel} \i Scroll the page horizontally
371 (the Wheel is the mouse wheel) 371 (the Wheel is the mouse wheel)
372 \row \i \e{Ctrl+Wheel} \i Zoom the text 372 \row \i \e{Ctrl+Wheel} \i Zoom the text
373 \endtable 373 \endtable
374 374
@@ -651,7 +651,7 @@ QTextEdit::QTextEdit( QWidget *parent, const char *name )
651*/ 651*/
652 652
653QTextEdit::QTextEdit( const QString& text, const QString& context, 653QTextEdit::QTextEdit( const QString& text, const QString& context,
654 QWidget *parent, const char *name) 654 QWidget *parent, const char *name)
655 : QScrollView( parent, name, WStaticContents | WRepaintNoErase | WResizeNoErase ), 655 : QScrollView( parent, name, WStaticContents | WRepaintNoErase | WResizeNoErase ),
656 doc( new QTextDocument( 0 ) ), undoRedoInfo( doc ) 656 doc( new QTextDocument( 0 ) ), undoRedoInfo( doc )
657{ 657{
@@ -673,12 +673,13 @@ QTextEdit::~QTextEdit()
673void QTextEdit::init() 673void QTextEdit::init()
674{ 674{
675 setFrameStyle( Sunken ); 675 setFrameStyle( Sunken );
676 setVScrollBarMode( AlwaysOn );
676 undoEnabled = TRUE; 677 undoEnabled = TRUE;
677 readonly = TRUE; 678 readonly = TRUE;
678 setReadOnly( FALSE ); 679 setReadOnly( FALSE );
679 d = new QTextEditPrivate; 680 d = new QTextEditPrivate;
680 connect( doc, SIGNAL( minimumWidthChanged(int) ), 681 connect( doc, SIGNAL( minimumWidthChanged(int) ),
681 this, SLOT( documentWidthChanged(int) ) ); 682 this, SLOT( documentWidthChanged(int) ) );
682 683
683 mousePressed = FALSE; 684 mousePressed = FALSE;
684 inDoubleClick = FALSE; 685 inDoubleClick = FALSE;
@@ -699,7 +700,7 @@ void QTextEdit::init()
699 viewport()->setBackgroundMode( PaletteBase ); 700 viewport()->setBackgroundMode( PaletteBase );
700 viewport()->setAcceptDrops( TRUE ); 701 viewport()->setAcceptDrops( TRUE );
701 resizeContents( 0, doc->lastParagraph() ? 702 resizeContents( 0, doc->lastParagraph() ?
702 ( doc->lastParagraph()->paragId() + 1 ) * doc->formatCollection()->defaultFormat()->height() : 0 ); 703 ( doc->lastParagraph()->paragId() + 1 ) * doc->formatCollection()->defaultFormat()->height() : 0 );
703 704
704 setKeyCompression( TRUE ); 705 setKeyCompression( TRUE );
705 viewport()->setMouseTracking( TRUE ); 706 viewport()->setMouseTracking( TRUE );
@@ -710,27 +711,27 @@ void QTextEdit::init()
710 711
711 formatTimer = new QTimer( this ); 712 formatTimer = new QTimer( this );
712 connect( formatTimer, SIGNAL( timeout() ), 713 connect( formatTimer, SIGNAL( timeout() ),
713 this, SLOT( formatMore() ) ); 714 this, SLOT( formatMore() ) );
714 lastFormatted = doc->firstParagraph(); 715 lastFormatted = doc->firstParagraph();
715 716
716 scrollTimer = new QTimer( this ); 717 scrollTimer = new QTimer( this );
717 connect( scrollTimer, SIGNAL( timeout() ), 718 connect( scrollTimer, SIGNAL( timeout() ),
718 this, SLOT( autoScrollTimerDone() ) ); 719 this, SLOT( autoScrollTimerDone() ) );
719 720
720 interval = 0; 721 interval = 0;
721 changeIntervalTimer = new QTimer( this ); 722 changeIntervalTimer = new QTimer( this );
722 connect( changeIntervalTimer, SIGNAL( timeout() ), 723 connect( changeIntervalTimer, SIGNAL( timeout() ),
723 this, SLOT( doChangeInterval() ) ); 724 this, SLOT( doChangeInterval() ) );
724 725
725 cursorVisible = TRUE; 726 cursorVisible = TRUE;
726 blinkTimer = new QTimer( this ); 727 blinkTimer = new QTimer( this );
727 connect( blinkTimer, SIGNAL( timeout() ), 728 connect( blinkTimer, SIGNAL( timeout() ),
728 this, SLOT( blinkCursor() ) ); 729 this, SLOT( blinkCursor() ) );
729 730
730#ifndef QT_NO_DRAGANDDROP 731#ifndef QT_NO_DRAGANDDROP
731 dragStartTimer = new QTimer( this ); 732 dragStartTimer = new QTimer( this );
732 connect( dragStartTimer, SIGNAL( timeout() ), 733 connect( dragStartTimer, SIGNAL( timeout() ),
733 this, SLOT( startDrag() ) ); 734 this, SLOT( startDrag() ) );
734#endif 735#endif
735 736
736 737
@@ -748,18 +749,18 @@ void QTextEdit::paintDocument( bool drawAll, QPainter *p, int cx, int cy, int cw
748{ 749{
749 bool drawCur = hasFocus() || viewport()->hasFocus(); 750 bool drawCur = hasFocus() || viewport()->hasFocus();
750 if ( hasSelectedText() || isReadOnly() || !cursorVisible ) 751 if ( hasSelectedText() || isReadOnly() || !cursorVisible )
751 drawCur = FALSE; 752 drawCur = FALSE;
752 QColorGroup g = colorGroup(); 753 QColorGroup g = colorGroup();
753 if ( doc->paper() ) 754 if ( doc->paper() )
754 g.setBrush( QColorGroup::Base, *doc->paper() ); 755 g.setBrush( QColorGroup::Base, *doc->paper() );
755 756
756 if ( contentsY() < doc->y() ) { 757 if ( contentsY() < doc->y() ) {
757 p->fillRect( contentsX(), contentsY(), visibleWidth(), doc->y(), 758 p->fillRect( contentsX(), contentsY(), visibleWidth(), doc->y(),
758 g.brush( QColorGroup::Base ) ); 759 g.brush( QColorGroup::Base ) );
759 } 760 }
760 if ( drawAll && doc->width() - contentsX() < cx + cw ) { 761 if ( drawAll && doc->width() - contentsX() < cx + cw ) {
761 p->fillRect( doc->width() - contentsX(), cy, cx + cw - doc->width() + contentsX(), ch, 762 p->fillRect( doc->width() - contentsX(), cy, cx + cw - doc->width() + contentsX(), ch,
762 g.brush( QColorGroup::Base ) ); 763 g.brush( QColorGroup::Base ) );
763 } 764 }
764 765
765 p->setBrushOrigin( -contentsX(), -contentsY() ); 766 p->setBrushOrigin( -contentsX(), -contentsY() );
@@ -767,11 +768,11 @@ void QTextEdit::paintDocument( bool drawAll, QPainter *p, int cx, int cy, int cw
767 lastFormatted = doc->draw( p, cx, cy, cw, ch, g, !drawAll, drawCur, cursor ); 768 lastFormatted = doc->draw( p, cx, cy, cw, ch, g, !drawAll, drawCur, cursor );
768 769
769 if ( lastFormatted == doc->lastParagraph() ) 770 if ( lastFormatted == doc->lastParagraph() )
770 resizeContents( contentsWidth(), doc->height() ); 771 resizeContents( contentsWidth(), doc->height() );
771 772
772 if ( contentsHeight() < visibleHeight() && ( !doc->lastParagraph() || doc->lastParagraph()->isValid() ) && drawAll ) 773 if ( contentsHeight() < visibleHeight() && ( !doc->lastParagraph() || doc->lastParagraph()->isValid() ) && drawAll )
773 p->fillRect( 0, contentsHeight(), visibleWidth(), 774 p->fillRect( 0, contentsHeight(), visibleWidth(),
774 visibleHeight() - contentsHeight(), g.brush( QColorGroup::Base ) ); 775 visibleHeight() - contentsHeight(), g.brush( QColorGroup::Base ) );
775} 776}
776 777
777/*! \reimp */ 778/*! \reimp */
@@ -782,11 +783,11 @@ void QTextEdit::drawContents( QPainter *p, int cx, int cy, int cw, int ch )
782 int v; 783 int v;
783 p->setPen( foregroundColor() ); 784 p->setPen( foregroundColor() );
784 if ( document()->isPageBreakEnabled() && ( v = document()->flow()->pageSize() ) > 0 ) { 785 if ( document()->isPageBreakEnabled() && ( v = document()->flow()->pageSize() ) > 0 ) {
785 int l = int(cy / v) * v; 786 int l = int(cy / v) * v;
786 while ( l < cy + ch ) { 787 while ( l < cy + ch ) {
787 p->drawLine( cx, l, cx + cw - 1, l ); 788 p->drawLine( cx, l, cx + cw - 1, l );
788 l += v; 789 l += v;
789 } 790 }
790 } 791 }
791 792
792} 793}
@@ -802,80 +803,80 @@ void QTextEdit::drawContents( QPainter * )
802bool QTextEdit::event( QEvent *e ) 803bool QTextEdit::event( QEvent *e )
803{ 804{
804 if ( e->type() == QEvent::AccelOverride && !isReadOnly() ) { 805 if ( e->type() == QEvent::AccelOverride && !isReadOnly() ) {
805 QKeyEvent* ke = (QKeyEvent*) e; 806 QKeyEvent* ke = (QKeyEvent*) e;
806 if ( ke->state() == NoButton || ke->state() == Keypad ) { 807 if ( ke->state() == NoButton || ke->state() == Keypad ) {
807 if ( ke->key() < Key_Escape ) { 808 if ( ke->key() < Key_Escape ) {
808 ke->accept(); 809 ke->accept();
809 } else { 810 } else {
810 switch ( ke->key() ) { 811 switch ( ke->key() ) {
811 case Key_Return: 812 case Key_Return:
812 case Key_Enter: 813 case Key_Enter:
813 case Key_Delete: 814 case Key_Delete:
814 case Key_Home: 815 case Key_Home:
815 case Key_End: 816 case Key_End:
816 case Key_Backspace: 817 case Key_Backspace:
817 ke->accept(); 818 ke->accept();
818 default: 819 default:
819 break; 820 break;
820 } 821 }
821 } 822 }
822 } else if ( ke->state() & ControlButton ) { 823 } else if ( ke->state() & ControlButton ) {
823 switch ( ke->key() ) { 824 switch ( ke->key() ) {
824// Those are too frequently used for application functionality 825// Those are too frequently used for application functionality
825 /* case Key_A: 826/* case Key_A:
826 case Key_B: 827 case Key_B:
827 case Key_D: 828 case Key_D:
828 case Key_E: 829 case Key_E:
829 case Key_F: 830 case Key_F:
830 case Key_H: 831 case Key_H:
831 case Key_I: 832 case Key_I:
832 case Key_K: 833 case Key_K:
833 case Key_N: 834 case Key_N:
834 case Key_P: 835 case Key_P:
835 case Key_T: 836 case Key_T:
836*/ 837*/
837 case Key_C: 838 case Key_C:
838 case Key_V: 839 case Key_V:
839 case Key_X: 840 case Key_X:
840 case Key_Y: 841 case Key_Y:
841 case Key_Z: 842 case Key_Z:
842 case Key_Left: 843 case Key_Left:
843 case Key_Right: 844 case Key_Right:
844 case Key_Up: 845 case Key_Up:
845 case Key_Down: 846 case Key_Down:
846 case Key_Home: 847 case Key_Home:
847 case Key_End: 848 case Key_End:
848 case Key_Tab: 849 case Key_Tab:
849#if defined (Q_WS_WIN) 850#if defined (Q_WS_WIN)
850 case Key_Insert: 851 case Key_Insert:
851 case Key_Delete: 852 case Key_Delete:
852#endif 853#endif
853 ke->accept(); 854 ke->accept();
854 default: 855 default:
855 break; 856 break;
856 } 857 }
857 } else { 858 } else {
858 switch ( ke->key() ) { 859 switch ( ke->key() ) {
859#if defined (Q_WS_WIN) 860#if defined (Q_WS_WIN)
860 case Key_Insert: 861 case Key_Insert:
861 ke->accept(); 862 ke->accept();
862#endif 863#endif
863 default: 864 default:
864 break; 865 break;
865 } 866 }
866 } 867 }
867 } 868 }
868 869
869 if ( e->type() == QEvent::Show ) { 870 if ( e->type() == QEvent::Show ) {
870 if ( d->ensureCursorVisibleInShowEvent ) { 871 if ( d->ensureCursorVisibleInShowEvent ) {
871 sync(); 872 sync();
872 ensureCursorVisible(); 873 ensureCursorVisible();
873 d->ensureCursorVisibleInShowEvent = FALSE; 874 d->ensureCursorVisibleInShowEvent = FALSE;
874 } 875 }
875 if ( !d->scrollToAnchor.isEmpty() ) { 876 if ( !d->scrollToAnchor.isEmpty() ) {
876 scrollToAnchor( d->scrollToAnchor ); 877 scrollToAnchor( d->scrollToAnchor );
877 d->scrollToAnchor = QString::null; 878 d->scrollToAnchor = QString::null;
878 } 879 }
879 } 880 }
880 return QWidget::event( e ); 881 return QWidget::event( e );
881} 882}
@@ -892,20 +893,20 @@ void QTextEdit::keyPressEvent( QKeyEvent *e )
892 interval = 10; 893 interval = 10;
893 bool unknown = FALSE; 894 bool unknown = FALSE;
894 if ( isReadOnly() ) { 895 if ( isReadOnly() ) {
895 if ( !handleReadOnlyKeyEvent( e ) ) 896 if ( !handleReadOnlyKeyEvent( e ) )
896 QScrollView::keyPressEvent( e ); 897 QScrollView::keyPressEvent( e );
897 changeIntervalTimer->start( 100, TRUE ); 898 changeIntervalTimer->start( 100, TRUE );
898 return; 899 return;
899 } 900 }
900 901
901 902
902 bool selChanged = FALSE; 903 bool selChanged = FALSE;
903 for ( int i = 1; i < doc->numSelections(); ++i ) // start with 1 as we don't want to remove the Standard-Selection 904 for ( int i = 1; i < doc->numSelections(); ++i ) // start with 1 as we don't want to remove the Standard-Selection
904 selChanged = doc->removeSelection( i ) || selChanged; 905 selChanged = doc->removeSelection( i ) || selChanged;
905 906
906 if ( selChanged ) { 907 if ( selChanged ) {
907 cursor->paragraph()->document()->nextDoubleBuffered = TRUE; 908 cursor->paragraph()->document()->nextDoubleBuffered = TRUE;
908 repaintChanged(); 909 repaintChanged();
909 } 910 }
910 911
911 bool clearUndoRedoInfo = TRUE; 912 bool clearUndoRedoInfo = TRUE;
@@ -914,237 +915,237 @@ void QTextEdit::keyPressEvent( QKeyEvent *e )
914 switch ( e->key() ) { 915 switch ( e->key() ) {
915 case Key_Left: 916 case Key_Left:
916 case Key_Right: { 917 case Key_Right: {
917 // a bit hacky, but can't change this without introducing new enum values for move and keeping the 918 // a bit hacky, but can't change this without introducing new enum values for move and keeping the
918 // correct semantics and movement for BiDi and non BiDi text. 919 // correct semantics and movement for BiDi and non BiDi text.
919 CursorAction a; 920 CursorAction a;
920 if ( cursor->paragraph()->string()->isRightToLeft() == (e->key() == Key_Right) ) 921 if ( cursor->paragraph()->string()->isRightToLeft() == (e->key() == Key_Right) )
921 a = e->state() & ControlButton ? MoveWordBackward : MoveBackward; 922 a = e->state() & ControlButton ? MoveWordBackward : MoveBackward;
922 else 923 else
923 a = e->state() & ControlButton ? MoveWordForward : MoveForward; 924 a = e->state() & ControlButton ? MoveWordForward : MoveForward;
924 moveCursor( a, e->state() & ShiftButton ); 925 moveCursor( a, e->state() & ShiftButton );
925 break; 926 break;
926 } 927 }
927 case Key_Up: 928 case Key_Up:
928 moveCursor( e->state() & ControlButton ? MovePgUp : MoveUp, e->state() & ShiftButton ); 929 moveCursor( e->state() & ControlButton ? MovePgUp : MoveUp, e->state() & ShiftButton );
929 break; 930 break;
930 case Key_Down: 931 case Key_Down:
931 moveCursor( e->state() & ControlButton ? MovePgDown : MoveDown, e->state() & ShiftButton ); 932 moveCursor( e->state() & ControlButton ? MovePgDown : MoveDown, e->state() & ShiftButton );
932 break; 933 break;
933 case Key_Home: 934 case Key_Home:
934 moveCursor( e->state() & ControlButton ? MoveHome : MoveLineStart, e->state() & ShiftButton ); 935 moveCursor( e->state() & ControlButton ? MoveHome : MoveLineStart, e->state() & ShiftButton );
935 break; 936 break;
936 case Key_End: 937 case Key_End:
937 moveCursor( e->state() & ControlButton ? MoveEnd : MoveLineEnd, e->state() & ShiftButton ); 938 moveCursor( e->state() & ControlButton ? MoveEnd : MoveLineEnd, e->state() & ShiftButton );
938 break; 939 break;
939 case Key_Prior: 940 case Key_Prior:
940 moveCursor( MovePgUp, e->state() & ShiftButton ); 941 moveCursor( MovePgUp, e->state() & ShiftButton );
941 break; 942 break;
942 case Key_Next: 943 case Key_Next:
943 moveCursor( MovePgDown, e->state() & ShiftButton ); 944 moveCursor( MovePgDown, e->state() & ShiftButton );
944 break; 945 break;
945 case Key_Return: case Key_Enter: 946 case Key_Return: case Key_Enter:
946 if ( doc->hasSelection( QTextDocument::Standard, FALSE ) ) 947 if ( doc->hasSelection( QTextDocument::Standard, FALSE ) )
947 removeSelectedText(); 948 removeSelectedText();
948 if ( textFormat() == Qt::RichText && ( e->state() & ControlButton ) ) { 949 if ( textFormat() == Qt::RichText && ( e->state() & ControlButton ) ) {
949 // Ctrl-Enter inserts a line break in rich text mode 950 // Ctrl-Enter inserts a line break in rich text mode
950 insert( QString( QChar( 0x2028) ), TRUE, FALSE, TRUE ); 951 insert( QString( QChar( 0x2028) ), TRUE, FALSE, TRUE );
951 } else { 952 } else {
952#ifndef QT_NO_CURSOR 953#ifndef QT_NO_CURSOR
953 viewport()->setCursor( isReadOnly() ? arrowCursor : ibeamCursor ); 954 viewport()->setCursor( isReadOnly() ? arrowCursor : ibeamCursor );
954#endif 955#endif
955 clearUndoRedoInfo = FALSE; 956 clearUndoRedoInfo = FALSE;
956 doKeyboardAction( ActionReturn ); 957 doKeyboardAction( ActionReturn );
957 emit returnPressed(); 958 emit returnPressed();
958 } 959 }
959 break; 960 break;
960 case Key_Delete: 961 case Key_Delete:
961#if defined (Q_WS_WIN) 962#if defined (Q_WS_WIN)
962 if ( e->state() & ShiftButton ) { 963 if ( e->state() & ShiftButton ) {
963 cut(); 964 cut();
964 break; 965 break;
965 } else 966 } else
966#endif 967#endif
967 if ( doc->hasSelection( QTextDocument::Standard, TRUE ) ) { 968 if ( doc->hasSelection( QTextDocument::Standard, TRUE ) ) {
968 removeSelectedText(); 969 removeSelectedText();
969 break; 970 break;
970 } 971 }
971 doKeyboardAction( ActionDelete ); 972 doKeyboardAction( ActionDelete );
972 clearUndoRedoInfo = FALSE; 973 clearUndoRedoInfo = FALSE;
973 974
974 break; 975 break;
975 case Key_Insert: 976 case Key_Insert:
976 if ( e->state() & ShiftButton ) 977 if ( e->state() & ShiftButton )
977 paste(); 978 paste();
978#if defined (Q_WS_WIN) 979#if defined (Q_WS_WIN)
979 else if ( e->state() & ControlButton ) 980 else if ( e->state() & ControlButton )
980 copy(); 981 copy();
981#endif 982#endif
982 break; 983 break;
983 case Key_Backspace: 984 case Key_Backspace:
984 if ( doc->hasSelection( QTextDocument::Standard, TRUE ) ) { 985 if ( doc->hasSelection( QTextDocument::Standard, TRUE ) ) {
985 removeSelectedText(); 986 removeSelectedText();
986 break; 987 break;
987 } 988 }
988 989
989 doKeyboardAction( ActionBackspace ); 990 doKeyboardAction( ActionBackspace );
990 clearUndoRedoInfo = FALSE; 991 clearUndoRedoInfo = FALSE;
991 992
992 break; 993 break;
993 case Key_F16: // Copy key on Sun keyboards 994 case Key_F16: // Copy key on Sun keyboards
994 copy(); 995 copy();
995 break; 996 break;
996 case Key_F18: // Paste key on Sun keyboards 997 case Key_F18: // Paste key on Sun keyboards
997 paste(); 998 paste();
998 break; 999 break;
999 case Key_F20: // Cut key on Sun keyboards 1000 case Key_F20: // Cut key on Sun keyboards
1000 cut(); 1001 cut();
1001 break; 1002 break;
1002 default: { 1003 default: {
1003 if ( e->text().length() && 1004 if ( e->text().length() &&
1004 ( !( e->state() & ControlButton ) && 1005 ( !( e->state() & ControlButton ) &&
1005 !( e->state() & AltButton ) || 1006 !( e->state() & AltButton ) ||
1006 ( ( e->state() & ControlButton | AltButton ) == (ControlButton|AltButton) ) ) && 1007 ( ( e->state() & ControlButton | AltButton ) == (ControlButton|AltButton) ) ) &&
1007 ( !e->ascii() || e->ascii() >= 32 || e->text() == "\t" ) ) { 1008 ( !e->ascii() || e->ascii() >= 32 || e->text() == "\t" ) ) {
1008 clearUndoRedoInfo = FALSE; 1009 clearUndoRedoInfo = FALSE;
1009 if ( e->key() == Key_Tab ) { 1010 if ( e->key() == Key_Tab ) {
1010 if ( textFormat() == Qt::RichText && cursor->paragraph()->isListItem() ) { 1011 if ( textFormat() == Qt::RichText && cursor->paragraph()->isListItem() ) {
1011 clearUndoRedo(); 1012 clearUndoRedo();
1012 undoRedoInfo.type = UndoRedoInfo::Style; 1013 undoRedoInfo.type = UndoRedoInfo::Style;
1013 undoRedoInfo.id = cursor->paragraph()->paragId(); 1014 undoRedoInfo.id = cursor->paragraph()->paragId();
1014 undoRedoInfo.eid = undoRedoInfo.id; 1015 undoRedoInfo.eid = undoRedoInfo.id;
1015 undoRedoInfo.styleInformation = QTextStyleCommand::readStyleInformation( doc, undoRedoInfo.id, undoRedoInfo.eid ); 1016 undoRedoInfo.styleInformation = QTextStyleCommand::readStyleInformation( doc, undoRedoInfo.id, undoRedoInfo.eid );
1016 cursor->paragraph()->setListDepth( cursor->paragraph()->listDepth() +1 ); 1017 cursor->paragraph()->setListDepth( cursor->paragraph()->listDepth() +1 );
1017 clearUndoRedo(); 1018 clearUndoRedo();
1018 drawCursor( FALSE ); 1019 drawCursor( FALSE );
1019 repaintChanged(); 1020 repaintChanged();
1020 drawCursor( TRUE ); 1021 drawCursor( TRUE );
1021 break; 1022 break;
1022 } 1023 }
1023 } 1024 }
1024 1025
1025 if ( textFormat() == Qt::RichText && !cursor->paragraph()->isListItem() ) { 1026 if ( textFormat() == Qt::RichText && !cursor->paragraph()->isListItem() ) {
1026 if ( cursor->index() == 0 && ( e->text()[0] == '-' || e->text()[0] == '*' ) ) { 1027 if ( cursor->index() == 0 && ( e->text()[0] == '-' || e->text()[0] == '*' ) ) {
1027 clearUndoRedo(); 1028 clearUndoRedo();
1028 undoRedoInfo.type = UndoRedoInfo::Style; 1029 undoRedoInfo.type = UndoRedoInfo::Style;
1029 undoRedoInfo.id = cursor->paragraph()->paragId(); 1030 undoRedoInfo.id = cursor->paragraph()->paragId();
1030 undoRedoInfo.eid = undoRedoInfo.id; 1031 undoRedoInfo.eid = undoRedoInfo.id;
1031 undoRedoInfo.styleInformation = QTextStyleCommand::readStyleInformation( doc, undoRedoInfo.id, undoRedoInfo.eid ); 1032 undoRedoInfo.styleInformation = QTextStyleCommand::readStyleInformation( doc, undoRedoInfo.id, undoRedoInfo.eid );
1032 setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListDisc ); 1033 setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListDisc );
1033 clearUndoRedo(); 1034 clearUndoRedo();
1034 drawCursor( FALSE ); 1035 drawCursor( FALSE );
1035 repaintChanged(); 1036 repaintChanged();
1036 drawCursor( TRUE ); 1037 drawCursor( TRUE );
1037 break; 1038 break;
1038 } 1039 }
1039 } 1040 }
1040 if ( overWrite && !cursor->atParagEnd() ) 1041 if ( overWrite && !cursor->atParagEnd() )
1041 cursor->remove(); 1042 cursor->remove();
1042 QString t = e->text(); 1043 QString t = e->text();
1043 QTextParagraph *p = cursor->paragraph(); 1044 QTextParagraph *p = cursor->paragraph();
1044 if ( p && p->string() && p->string()->isRightToLeft() ) { 1045 if ( p && p->string() && p->string()->isRightToLeft() ) {
1045 QChar *c = (QChar *)t.unicode(); 1046 QChar *c = (QChar *)t.unicode();
1046 int l = t.length(); 1047 int l = t.length();
1047 while( l-- ) { 1048 while( l-- ) {
1048 if ( c->mirrored() ) 1049 if ( c->mirrored() )
1049 *c = c->mirroredChar(); 1050 *c = c->mirroredChar();
1050 c++; 1051 c++;
1051 } 1052 }
1052 } 1053 }
1053 insert( t, TRUE, FALSE, TRUE ); 1054 insert( t, TRUE, FALSE, TRUE );
1054 break; 1055 break;
1055 } else if ( e->state() & ControlButton ) { 1056 } else if ( e->state() & ControlButton ) {
1056 switch ( e->key() ) { 1057 switch ( e->key() ) {
1057 case Key_C: case Key_F16: // Copy key on Sun keyboards 1058 case Key_C: case Key_F16: // Copy key on Sun keyboards
1058 copy(); 1059 copy();
1059 break; 1060 break;
1060 case Key_V: 1061 case Key_V:
1061 paste(); 1062 paste();
1062 break; 1063 break;
1063 case Key_X: 1064 case Key_X:
1064 cut(); 1065 cut();
1065 break; 1066 break;
1066 case Key_I: case Key_T: case Key_Tab: 1067 case Key_I: case Key_T: case Key_Tab:
1067 indent(); 1068 indent();
1068 break; 1069 break;
1069 case Key_A: 1070 case Key_A:
1070#if defined(Q_WS_X11) 1071#if defined(Q_WS_X11)
1071 moveCursor( MoveLineStart, e->state() & ShiftButton ); 1072 moveCursor( MoveLineStart, e->state() & ShiftButton );
1072#else 1073#else
1073 selectAll( TRUE ); 1074 selectAll( TRUE );
1074#endif 1075#endif
1075 break; 1076 break;
1076 case Key_B: 1077 case Key_B:
1077 moveCursor( MoveBackward, e->state() & ShiftButton ); 1078 moveCursor( MoveBackward, e->state() & ShiftButton );
1078 break; 1079 break;
1079 case Key_F: 1080 case Key_F:
1080 moveCursor( MoveForward, e->state() & ShiftButton ); 1081 moveCursor( MoveForward, e->state() & ShiftButton );
1081 break; 1082 break;
1082 case Key_D: 1083 case Key_D:
1083 if ( doc->hasSelection( QTextDocument::Standard ) ) { 1084 if ( doc->hasSelection( QTextDocument::Standard ) ) {
1084 removeSelectedText(); 1085 removeSelectedText();
1085 break; 1086 break;
1086 } 1087 }
1087 doKeyboardAction( ActionDelete ); 1088 doKeyboardAction( ActionDelete );
1088 clearUndoRedoInfo = FALSE; 1089 clearUndoRedoInfo = FALSE;
1089 break; 1090 break;
1090 case Key_H: 1091 case Key_H:
1091 if ( doc->hasSelection( QTextDocument::Standard ) ) { 1092 if ( doc->hasSelection( QTextDocument::Standard ) ) {
1092 removeSelectedText(); 1093 removeSelectedText();
1093 break; 1094 break;
1094 } 1095 }
1095 if ( !cursor->paragraph()->prev() && 1096 if ( !cursor->paragraph()->prev() &&
1096 cursor->atParagStart() ) 1097 cursor->atParagStart() )
1097 break; 1098 break;
1098 1099
1099 doKeyboardAction( ActionBackspace ); 1100 doKeyboardAction( ActionBackspace );
1100 clearUndoRedoInfo = FALSE; 1101 clearUndoRedoInfo = FALSE;
1101 break; 1102 break;
1102 case Key_E: 1103 case Key_E:
1103 moveCursor( MoveLineEnd, e->state() & ShiftButton ); 1104 moveCursor( MoveLineEnd, e->state() & ShiftButton );
1104 break; 1105 break;
1105 case Key_N: 1106 case Key_N:
1106 moveCursor( MoveDown, e->state() & ShiftButton ); 1107 moveCursor( MoveDown, e->state() & ShiftButton );
1107 break; 1108 break;
1108 case Key_P: 1109 case Key_P:
1109 moveCursor( MoveUp, e->state() & ShiftButton ); 1110 moveCursor( MoveUp, e->state() & ShiftButton );
1110 break; 1111 break;
1111 case Key_Z: 1112 case Key_Z:
1112 if(e->state() & ShiftButton) 1113 if(e->state() & ShiftButton)
1113 redo(); 1114 redo();
1114 else 1115 else
1115 undo(); 1116 undo();
1116 break; 1117 break;
1117 case Key_Y: 1118 case Key_Y:
1118 redo(); 1119 redo();
1119 break; 1120 break;
1120 case Key_K: 1121 case Key_K:
1121 doKeyboardAction( ActionKill ); 1122 doKeyboardAction( ActionKill );
1122 break; 1123 break;
1123#if defined(Q_WS_WIN) 1124#if defined(Q_WS_WIN)
1124 case Key_Insert: 1125 case Key_Insert:
1125 copy(); 1126 copy();
1126 break; 1127 break;
1127 case Key_Delete: 1128 case Key_Delete:
1128 del(); 1129 del();
1129 break; 1130 break;
1130#endif 1131#endif
1131 default: 1132 default:
1132 unknown = FALSE; 1133 unknown = FALSE;
1133 break; 1134 break;
1134 } 1135 }
1135 } else { 1136 } else {
1136 unknown = TRUE; 1137 unknown = TRUE;
1137 } 1138 }
1138 } 1139 }
1139 } 1140 }
1140 1141
1141 emit cursorPositionChanged( cursor ); 1142 emit cursorPositionChanged( cursor );
1142 emit cursorPositionChanged( cursor->paragraph()->paragId(), cursor->index() ); 1143 emit cursorPositionChanged( cursor->paragraph()->paragId(), cursor->index() );
1143 if ( clearUndoRedoInfo ) 1144 if ( clearUndoRedoInfo )
1144 clearUndoRedo(); 1145 clearUndoRedo();
1145 changeIntervalTimer->start( 100, TRUE ); 1146 changeIntervalTimer->start( 100, TRUE );
1146 if ( unknown ) 1147 if ( unknown )
1147 e->ignore(); 1148 e->ignore();
1148} 1149}
1149 1150
1150/*! 1151/*!
@@ -1155,10 +1156,10 @@ void QTextEdit::keyPressEvent( QKeyEvent *e )
1155void QTextEdit::doKeyboardAction( KeyboardAction action ) 1156void QTextEdit::doKeyboardAction( KeyboardAction action )
1156{ 1157{
1157 if ( isReadOnly() ) 1158 if ( isReadOnly() )
1158 return; 1159 return;
1159 1160
1160 if ( cursor->nestedDepth() != 0 ) // #### for 3.0, disable editing of tables as this is not advanced enough 1161 if ( cursor->nestedDepth() != 0 ) // #### for 3.0, disable editing of tables as this is not advanced enough
1161 return; 1162 return;
1162 1163
1163 lastFormatted = cursor->paragraph(); 1164 lastFormatted = cursor->paragraph();
1164 drawCursor( FALSE ); 1165 drawCursor( FALSE );
@@ -1166,86 +1167,86 @@ void QTextEdit::doKeyboardAction( KeyboardAction action )
1166 1167
1167 switch ( action ) { 1168 switch ( action ) {
1168 case ActionDelete: 1169 case ActionDelete:
1169 if ( !cursor->atParagEnd() ) { 1170 if ( !cursor->atParagEnd() ) {
1170 checkUndoRedoInfo( UndoRedoInfo::Delete ); 1171 checkUndoRedoInfo( UndoRedoInfo::Delete );
1171 if ( !undoRedoInfo.valid() ) { 1172 if ( !undoRedoInfo.valid() ) {
1172 undoRedoInfo.id = cursor->paragraph()->paragId(); 1173 undoRedoInfo.id = cursor->paragraph()->paragId();
1173 undoRedoInfo.index = cursor->index(); 1174 undoRedoInfo.index = cursor->index();
1174 undoRedoInfo.d->text = QString::null; 1175 undoRedoInfo.d->text = QString::null;
1175 } 1176 }
1176 undoRedoInfo.d->text.insert( undoRedoInfo.d->text.length(), cursor->paragraph()->at( cursor->index() ), TRUE ); 1177 undoRedoInfo.d->text.insert( undoRedoInfo.d->text.length(), cursor->paragraph()->at( cursor->index() ), TRUE );
1177 cursor->remove(); 1178 cursor->remove();
1178 } else { 1179 } else {
1179 clearUndoRedo(); 1180 clearUndoRedo();
1180 doc->setSelectionStart( QTextDocument::Temp, *cursor ); 1181 doc->setSelectionStart( QTextDocument::Temp, *cursor );
1181 cursor->gotoNextLetter(); 1182 cursor->gotoNextLetter();
1182 doc->setSelectionEnd( QTextDocument::Temp, *cursor ); 1183 doc->setSelectionEnd( QTextDocument::Temp, *cursor );
1183 removeSelectedText( QTextDocument::Temp ); 1184 removeSelectedText( QTextDocument::Temp );
1184 } 1185 }
1185 break; 1186 break;
1186 case ActionBackspace: 1187 case ActionBackspace:
1187 if ( textFormat() == Qt::RichText && cursor->paragraph()->isListItem() && cursor->index() == 0 ) { 1188 if ( textFormat() == Qt::RichText && cursor->paragraph()->isListItem() && cursor->index() == 0 ) {
1188 clearUndoRedo(); 1189 clearUndoRedo();
1189 undoRedoInfo.type = UndoRedoInfo::Style; 1190 undoRedoInfo.type = UndoRedoInfo::Style;
1190 undoRedoInfo.id = cursor->paragraph()->paragId(); 1191 undoRedoInfo.id = cursor->paragraph()->paragId();
1191 undoRedoInfo.eid = undoRedoInfo.id; 1192 undoRedoInfo.eid = undoRedoInfo.id;
1192 undoRedoInfo.styleInformation = QTextStyleCommand::readStyleInformation( doc, undoRedoInfo.id, undoRedoInfo.eid ); 1193 undoRedoInfo.styleInformation = QTextStyleCommand::readStyleInformation( doc, undoRedoInfo.id, undoRedoInfo.eid );
1193 int ldepth = cursor->paragraph()->listDepth(); 1194 int ldepth = cursor->paragraph()->listDepth();
1194 ldepth = QMAX( ldepth-1, 0 ); 1195 ldepth = QMAX( ldepth-1, 0 );
1195 cursor->paragraph()->setListDepth( ldepth ); 1196 cursor->paragraph()->setListDepth( ldepth );
1196 if ( ldepth == 0 ) 1197 if ( ldepth == 0 )
1197 cursor->paragraph()->setListItem( FALSE ); 1198 cursor->paragraph()->setListItem( FALSE );
1198 clearUndoRedo(); 1199 clearUndoRedo();
1199 lastFormatted = cursor->paragraph(); 1200 lastFormatted = cursor->paragraph();
1200 repaintChanged(); 1201 repaintChanged();
1201 drawCursor( TRUE ); 1202 drawCursor( TRUE );
1202 return; 1203 return;
1203 } 1204 }
1204 if ( !cursor->atParagStart() ) { 1205 if ( !cursor->atParagStart() ) {
1205 checkUndoRedoInfo( UndoRedoInfo::Delete ); 1206 checkUndoRedoInfo( UndoRedoInfo::Delete );
1206 if ( !undoRedoInfo.valid() ) { 1207 if ( !undoRedoInfo.valid() ) {
1207 undoRedoInfo.id = cursor->paragraph()->paragId(); 1208 undoRedoInfo.id = cursor->paragraph()->paragId();
1208 undoRedoInfo.index = cursor->index(); 1209 undoRedoInfo.index = cursor->index();
1209 undoRedoInfo.d->text = QString::null; 1210 undoRedoInfo.d->text = QString::null;
1210 } 1211 }
1211 cursor->gotoPreviousLetter(); 1212 cursor->gotoPreviousLetter();
1212 undoRedoInfo.d->text.insert( 0, cursor->paragraph()->at( cursor->index() ), TRUE ); 1213 undoRedoInfo.d->text.insert( 0, cursor->paragraph()->at( cursor->index() ), TRUE );
1213 undoRedoInfo.index = cursor->index(); 1214 undoRedoInfo.index = cursor->index();
1214 cursor->remove(); 1215 cursor->remove();
1215 lastFormatted = cursor->paragraph(); 1216 lastFormatted = cursor->paragraph();
1216 } else if ( cursor->paragraph()->prev() ){ 1217 } else if ( cursor->paragraph()->prev() ){
1217 clearUndoRedo(); 1218 clearUndoRedo();
1218 doc->setSelectionStart( QTextDocument::Temp, *cursor ); 1219 doc->setSelectionStart( QTextDocument::Temp, *cursor );
1219 cursor->gotoPreviousLetter(); 1220 cursor->gotoPreviousLetter();
1220 doc->setSelectionEnd( QTextDocument::Temp, *cursor ); 1221 doc->setSelectionEnd( QTextDocument::Temp, *cursor );
1221 removeSelectedText( QTextDocument::Temp ); 1222 removeSelectedText( QTextDocument::Temp );
1222 } 1223 }
1223 break; 1224 break;
1224 case ActionReturn: 1225 case ActionReturn:
1225 checkUndoRedoInfo( UndoRedoInfo::Return ); 1226 checkUndoRedoInfo( UndoRedoInfo::Return );
1226 if ( !undoRedoInfo.valid() ) { 1227 if ( !undoRedoInfo.valid() ) {
1227 undoRedoInfo.id = cursor->paragraph()->paragId(); 1228 undoRedoInfo.id = cursor->paragraph()->paragId();
1228 undoRedoInfo.index = cursor->index(); 1229 undoRedoInfo.index = cursor->index();
1229 undoRedoInfo.d->text = QString::null; 1230 undoRedoInfo.d->text = QString::null;
1230 } 1231 }
1231 undoRedoInfo.d->text += "\n"; 1232 undoRedoInfo.d->text += "\n";
1232 cursor->splitAndInsertEmptyParagraph(); 1233 cursor->splitAndInsertEmptyParagraph();
1233 if ( cursor->paragraph()->prev() ) { 1234 if ( cursor->paragraph()->prev() ) {
1234 lastFormatted = cursor->paragraph()->prev(); 1235 lastFormatted = cursor->paragraph()->prev();
1235 lastFormatted->invalidate( 0 ); 1236 lastFormatted->invalidate( 0 );
1236 } 1237 }
1237 doUpdateCurrentFormat = FALSE; 1238 doUpdateCurrentFormat = FALSE;
1238 break; 1239 break;
1239 case ActionKill: 1240 case ActionKill:
1240 clearUndoRedo(); 1241 clearUndoRedo();
1241 doc->setSelectionStart( QTextDocument::Temp, *cursor ); 1242 doc->setSelectionStart( QTextDocument::Temp, *cursor );
1242 if ( cursor->atParagEnd() ) 1243 if ( cursor->atParagEnd() )
1243 cursor->gotoNextLetter(); 1244 cursor->gotoNextLetter();
1244 else 1245 else
1245 cursor->setIndex( cursor->paragraph()->length() - 1 ); 1246 cursor->setIndex( cursor->paragraph()->length() - 1 );
1246 doc->setSelectionEnd( QTextDocument::Temp, *cursor ); 1247 doc->setSelectionEnd( QTextDocument::Temp, *cursor );
1247 removeSelectedText( QTextDocument::Temp ); 1248 removeSelectedText( QTextDocument::Temp );
1248 break; 1249 break;
1249 } 1250 }
1250 1251
1251 formatMore(); 1252 formatMore();
@@ -1254,7 +1255,7 @@ void QTextEdit::doKeyboardAction( KeyboardAction action )
1254 drawCursor( TRUE ); 1255 drawCursor( TRUE );
1255 updateMicroFocusHint(); 1256 updateMicroFocusHint();
1256 if ( doUpdateCurrentFormat ) 1257 if ( doUpdateCurrentFormat )
1257 updateCurrentFormat(); 1258 updateCurrentFormat();
1258 setModified(); 1259 setModified();
1259 emit textChanged(); 1260 emit textChanged();
1260} 1261}
@@ -1266,32 +1267,32 @@ void QTextEdit::readFormats( QTextCursor &c1, QTextCursor &c2, QTextString &text
1266 c1.restoreState(); 1267 c1.restoreState();
1267 int lastIndex = text.length(); 1268 int lastIndex = text.length();
1268 if ( c1.paragraph() == c2.paragraph() ) { 1269 if ( c1.paragraph() == c2.paragraph() ) {
1269 for ( int i = c1.index(); i < c2.index(); ++i ) 1270 for ( int i = c1.index(); i < c2.index(); ++i )
1270 text.insert( lastIndex + i - c1.index(), c1.paragraph()->at( i ), TRUE ); 1271 text.insert( lastIndex + i - c1.index(), c1.paragraph()->at( i ), TRUE );
1271 if ( fillStyles ) { 1272 if ( fillStyles ) {
1272 styleStream << (int) 1; 1273 styleStream << (int) 1;
1273 c1.paragraph()->writeStyleInformation( styleStream ); 1274 c1.paragraph()->writeStyleInformation( styleStream );
1274 } 1275 }
1275 } else { 1276 } else {
1276 int i; 1277 int i;
1277 for ( i = c1.index(); i < c1.paragraph()->length()-1; ++i ) 1278 for ( i = c1.index(); i < c1.paragraph()->length()-1; ++i )
1278 text.insert( lastIndex++, c1.paragraph()->at( i ), TRUE ); 1279 text.insert( lastIndex++, c1.paragraph()->at( i ), TRUE );
1279 int num = 2; // start and end, being different 1280 int num = 2; // start and end, being different
1280 text += "\n"; lastIndex++; 1281 text += "\n"; lastIndex++;
1281 QTextParagraph *p = c1.paragraph()->next(); 1282 QTextParagraph *p = c1.paragraph()->next();
1282 while ( p && p != c2.paragraph() ) { 1283 while ( p && p != c2.paragraph() ) {
1283 for ( i = 0; i < p->length()-1; ++i ) 1284 for ( i = 0; i < p->length()-1; ++i )
1284 text.insert( lastIndex++ , p->at( i ), TRUE ); 1285 text.insert( lastIndex++ , p->at( i ), TRUE );
1285 text += "\n"; num++; lastIndex++; 1286 text += "\n"; num++; lastIndex++;
1286 p = p->next(); 1287 p = p->next();
1287 } 1288 }
1288 for ( i = 0; i < c2.index(); ++i ) 1289 for ( i = 0; i < c2.index(); ++i )
1289 text.insert( i + lastIndex, c2.paragraph()->at( i ), TRUE ); 1290 text.insert( i + lastIndex, c2.paragraph()->at( i ), TRUE );
1290 if ( fillStyles ) { 1291 if ( fillStyles ) {
1291 styleStream << num; 1292 styleStream << num;
1292 for ( QTextParagraph *p = c1.paragraph(); --num >= 0; p = p->next() ) 1293 for ( QTextParagraph *p = c1.paragraph(); --num >= 0; p = p->next() )
1293 p->writeStyleInformation( styleStream ); 1294 p->writeStyleInformation( styleStream );
1294 } 1295 }
1295 } 1296 }
1296} 1297}
1297 1298
@@ -1317,7 +1318,7 @@ void QTextEdit::removeSelection( int selNum )
1317void QTextEdit::removeSelectedText( int selNum ) 1318void QTextEdit::removeSelectedText( int selNum )
1318{ 1319{
1319 if ( isReadOnly() ) 1320 if ( isReadOnly() )
1320 return; 1321 return;
1321 1322
1322 QTextCursor c1 = doc->selectionStartCursor( selNum ); 1323 QTextCursor c1 = doc->selectionStartCursor( selNum );
1323 c1.restoreState(); 1324 c1.restoreState();
@@ -1326,47 +1327,47 @@ void QTextEdit::removeSelectedText( int selNum )
1326 1327
1327 // ### no support for editing tables yet, plus security for broken selections 1328 // ### no support for editing tables yet, plus security for broken selections
1328 if ( c1.nestedDepth() || c2.nestedDepth() ) 1329 if ( c1.nestedDepth() || c2.nestedDepth() )
1329 return; 1330 return;
1330 1331
1331 for ( int i = 0; i < (int)doc->numSelections(); ++i ) { 1332 for ( int i = 0; i < (int)doc->numSelections(); ++i ) {
1332 if ( i == selNum ) 1333 if ( i == selNum )
1333 continue; 1334 continue;
1334 doc->removeSelection( i ); 1335 doc->removeSelection( i );
1335 } 1336 }
1336 1337
1337 drawCursor( FALSE ); 1338 drawCursor( FALSE );
1338 checkUndoRedoInfo( UndoRedoInfo::RemoveSelected ); 1339 checkUndoRedoInfo( UndoRedoInfo::RemoveSelected );
1339 if ( !undoRedoInfo.valid() ) { 1340 if ( !undoRedoInfo.valid() ) {
1340 doc->selectionStart( selNum, undoRedoInfo.id, undoRedoInfo.index ); 1341 doc->selectionStart( selNum, undoRedoInfo.id, undoRedoInfo.index );
1341 undoRedoInfo.d->text = QString::null; 1342 undoRedoInfo.d->text = QString::null;
1342 } 1343 }
1343 readFormats( c1, c2, undoRedoInfo.d->text, TRUE ); 1344 readFormats( c1, c2, undoRedoInfo.d->text, TRUE );
1344 1345
1345 1346
1346 doc->removeSelectedText( selNum, cursor ); 1347 doc->removeSelectedText( selNum, cursor );
1347 if ( cursor->isValid() ) { 1348 if ( cursor->isValid() ) {
1348 ensureCursorVisible(); 1349 ensureCursorVisible();
1349 lastFormatted = cursor->paragraph(); 1350 lastFormatted = cursor->paragraph();
1350 formatMore(); 1351 formatMore();
1351 repaintChanged(); 1352 repaintChanged();
1352 ensureCursorVisible(); 1353 ensureCursorVisible();
1353 drawCursor( TRUE ); 1354 drawCursor( TRUE );
1354 clearUndoRedo(); 1355 clearUndoRedo();
1355#if defined(Q_WS_WIN) 1356#if defined(Q_WS_WIN)
1356 // there seems to be a problem with repainting or erasing the area 1357 // there seems to be a problem with repainting or erasing the area
1357 // of the scrollview which is not the contents on windows 1358 // of the scrollview which is not the contents on windows
1358 if ( contentsHeight() < visibleHeight() ) 1359 if ( contentsHeight() < visibleHeight() )
1359 viewport()->repaint( 0, contentsHeight(), visibleWidth(), visibleHeight() - contentsHeight(), TRUE ); 1360 viewport()->repaint( 0, contentsHeight(), visibleWidth(), visibleHeight() - contentsHeight(), TRUE );
1360#endif 1361#endif
1361#ifndef QT_NO_CURSOR 1362#ifndef QT_NO_CURSOR
1362 viewport()->setCursor( isReadOnly() ? arrowCursor : ibeamCursor ); 1363 viewport()->setCursor( isReadOnly() ? arrowCursor : ibeamCursor );
1363#endif 1364#endif
1364 updateMicroFocusHint(); 1365 updateMicroFocusHint();
1365 } else { 1366 } else {
1366 delete cursor; 1367 delete cursor;
1367 cursor = new QTextCursor( doc ); 1368 cursor = new QTextCursor( doc );
1368 drawCursor( TRUE ); 1369 drawCursor( TRUE );
1369 viewport()->repaint( TRUE ); 1370 viewport()->repaint( TRUE );
1370 } 1371 }
1371 setModified(); 1372 setModified();
1372 emit textChanged(); 1373 emit textChanged();
@@ -1383,37 +1384,37 @@ void QTextEdit::moveCursor( CursorAction action, bool select )
1383{ 1384{
1384 drawCursor( FALSE ); 1385 drawCursor( FALSE );
1385 if ( select ) { 1386 if ( select ) {
1386 if ( !doc->hasSelection( QTextDocument::Standard ) ) 1387 if ( !doc->hasSelection( QTextDocument::Standard ) )
1387 doc->setSelectionStart( QTextDocument::Standard, *cursor ); 1388 doc->setSelectionStart( QTextDocument::Standard, *cursor );
1388 moveCursor( action ); 1389 moveCursor( action );
1389 if ( doc->setSelectionEnd( QTextDocument::Standard, *cursor ) ) { 1390 if ( doc->setSelectionEnd( QTextDocument::Standard, *cursor ) ) {
1390 cursor->paragraph()->document()->nextDoubleBuffered = TRUE; 1391 cursor->paragraph()->document()->nextDoubleBuffered = TRUE;
1391 repaintChanged(); 1392 repaintChanged();
1392 } else {
1393 drawCursor( TRUE );
1394 }
1395 ensureCursorVisible();
1396 emit selectionChanged();
1397 emit copyAvailable( doc->hasSelection( QTextDocument::Standard ) );
1398 } else { 1393 } else {
1399 bool redraw = doc->removeSelection( QTextDocument::Standard ); 1394 drawCursor( TRUE );
1400 moveCursor( action ); 1395 }
1401 if ( !redraw ) { 1396 ensureCursorVisible();
1402 ensureCursorVisible(); 1397 emit selectionChanged();
1403 drawCursor( TRUE ); 1398 emit copyAvailable( doc->hasSelection( QTextDocument::Standard ) );
1404 } else { 1399 } else {
1405 cursor->paragraph()->document()->nextDoubleBuffered = TRUE; 1400 bool redraw = doc->removeSelection( QTextDocument::Standard );
1406 repaintChanged(); 1401 moveCursor( action );
1407 ensureCursorVisible(); 1402 if ( !redraw ) {
1408 drawCursor( TRUE ); 1403 ensureCursorVisible();
1404 drawCursor( TRUE );
1405 } else {
1406 cursor->paragraph()->document()->nextDoubleBuffered = TRUE;
1407 repaintChanged();
1408 ensureCursorVisible();
1409 drawCursor( TRUE );
1409#ifndef QT_NO_CURSOR 1410#ifndef QT_NO_CURSOR
1410 viewport()->setCursor( isReadOnly() ? arrowCursor : ibeamCursor ); 1411 viewport()->setCursor( isReadOnly() ? arrowCursor : ibeamCursor );
1411#endif 1412#endif
1412 } 1413 }
1413 if ( redraw ) { 1414 if ( redraw ) {
1414 emit copyAvailable( doc->hasSelection( QTextDocument::Standard ) ); 1415 emit copyAvailable( doc->hasSelection( QTextDocument::Standard ) );
1415 emit selectionChanged(); 1416 emit selectionChanged();
1416 } 1417 }
1417 } 1418 }
1418 1419
1419 drawCursor( TRUE ); 1420 drawCursor( TRUE );
@@ -1428,42 +1429,42 @@ void QTextEdit::moveCursor( CursorAction action )
1428{ 1429{
1429 switch ( action ) { 1430 switch ( action ) {
1430 case MoveBackward: 1431 case MoveBackward:
1431 cursor->gotoPreviousLetter(); 1432 cursor->gotoPreviousLetter();
1432 break; 1433 break;
1433 case MoveWordBackward: 1434 case MoveWordBackward:
1434 cursor->gotoPreviousWord(); 1435 cursor->gotoPreviousWord();
1435 break; 1436 break;
1436 case MoveForward: 1437 case MoveForward:
1437 cursor->gotoNextLetter(); 1438 cursor->gotoNextLetter();
1438 break; 1439 break;
1439 case MoveWordForward: 1440 case MoveWordForward:
1440 cursor->gotoNextWord(); 1441 cursor->gotoNextWord();
1441 break; 1442 break;
1442 case MoveUp: 1443 case MoveUp:
1443 cursor->gotoUp(); 1444 cursor->gotoUp();
1444 break; 1445 break;
1445 case MovePgUp: 1446 case MovePgUp:
1446 cursor->gotoPageUp( visibleHeight() ); 1447 cursor->gotoPageUp( visibleHeight() );
1447 break; 1448 break;
1448 case MoveDown: 1449 case MoveDown:
1449 cursor->gotoDown(); 1450 cursor->gotoDown();
1450 break; 1451 break;
1451 case MovePgDown: 1452 case MovePgDown:
1452 cursor->gotoPageDown( visibleHeight() ); 1453 cursor->gotoPageDown( visibleHeight() );
1453 break; 1454 break;
1454 case MoveLineStart: 1455 case MoveLineStart:
1455 cursor->gotoLineStart(); 1456 cursor->gotoLineStart();
1456 break; 1457 break;
1457 case MoveHome: 1458 case MoveHome:
1458 cursor->gotoHome(); 1459 cursor->gotoHome();
1459 break; 1460 break;
1460 case MoveLineEnd: 1461 case MoveLineEnd:
1461 cursor->gotoLineEnd(); 1462 cursor->gotoLineEnd();
1462 break; 1463 break;
1463 case MoveEnd: 1464 case MoveEnd:
1464 ensureFormatted( doc->lastParagraph() ); 1465 ensureFormatted( doc->lastParagraph() );
1465 cursor->gotoEnd(); 1466 cursor->gotoEnd();
1466 break; 1467 break;
1467 } 1468 }
1468 updateMicroFocusHint(); 1469 updateMicroFocusHint();
1469 updateCurrentFormat(); 1470 updateCurrentFormat();
@@ -1475,7 +1476,7 @@ void QTextEdit::resizeEvent( QResizeEvent *e )
1475{ 1476{
1476 QScrollView::resizeEvent( e ); 1477 QScrollView::resizeEvent( e );
1477 if ( doc->visibleWidth() == 0 ) 1478 if ( doc->visibleWidth() == 0 )
1478 doResize(); 1479 doResize();
1479} 1480}
1480 1481
1481/*! \reimp */ 1482/*! \reimp */
@@ -1484,11 +1485,11 @@ void QTextEdit::viewportResizeEvent( QResizeEvent *e )
1484{ 1485{
1485 QScrollView::viewportResizeEvent( e ); 1486 QScrollView::viewportResizeEvent( e );
1486 if ( e->oldSize().width() != e->size().width() ) { 1487 if ( e->oldSize().width() != e->size().width() ) {
1487 bool stayAtBottom = e->oldSize().height() != e->size().height() && 1488 bool stayAtBottom = e->oldSize().height() != e->size().height() &&
1488 contentsY() > 0 && contentsY() >= doc->height() - e->oldSize().height(); 1489 contentsY() > 0 && contentsY() >= doc->height() - e->oldSize().height();
1489 doResize(); 1490 doResize();
1490 if ( stayAtBottom ) 1491 if ( stayAtBottom )
1491 scrollToBottom(); 1492 scrollToBottom();
1492 } 1493 }
1493} 1494}
1494 1495
@@ -1502,8 +1503,8 @@ void QTextEdit::viewportResizeEvent( QResizeEvent *e )
1502void QTextEdit::ensureCursorVisible() 1503void QTextEdit::ensureCursorVisible()
1503{ 1504{
1504 if ( !isVisible() ) { 1505 if ( !isVisible() ) {
1505 d->ensureCursorVisibleInShowEvent = TRUE; 1506 d->ensureCursorVisibleInShowEvent = TRUE;
1506 return; 1507 return;
1507 } 1508 }
1508 lastFormatted = cursor->paragraph(); 1509 lastFormatted = cursor->paragraph();
1509 formatMore(); 1510 formatMore();
@@ -1523,13 +1524,13 @@ void QTextEdit::ensureCursorVisible()
1523void QTextEdit::drawCursor( bool visible ) 1524void QTextEdit::drawCursor( bool visible )
1524{ 1525{
1525 if ( !isUpdatesEnabled() || 1526 if ( !isUpdatesEnabled() ||
1526 !viewport()->isUpdatesEnabled() || 1527 !viewport()->isUpdatesEnabled() ||
1527 !cursor->paragraph() || 1528 !cursor->paragraph() ||
1528 !cursor->paragraph()->isValid() || 1529 !cursor->paragraph()->isValid() ||
1529 !selectedText().isEmpty() || 1530 !selectedText().isEmpty() ||
1530 ( visible && !hasFocus() && !viewport()->hasFocus() && !inDnD ) || 1531 ( visible && !hasFocus() && !viewport()->hasFocus() && !inDnD ) ||
1531 isReadOnly() ) 1532 isReadOnly() )
1532 return; 1533 return;
1533 1534
1534 QPainter p( viewport() ); 1535 QPainter p( viewport() );
1535 QRect r( cursor->topParagraph()->rect() ); 1536 QRect r( cursor->topParagraph()->rect() );
@@ -1538,26 +1539,26 @@ void QTextEdit::drawCursor( bool visible )
1538 QPixmap *pix = 0; 1539 QPixmap *pix = 0;
1539 QColorGroup cg( colorGroup() ); 1540 QColorGroup cg( colorGroup() );
1540 if ( cursor->paragraph()->background() ) 1541 if ( cursor->paragraph()->background() )
1541 cg.setBrush( QColorGroup::Base, *cursor->paragraph()->background() ); 1542 cg.setBrush( QColorGroup::Base, *cursor->paragraph()->background() );
1542 else if ( doc->paper() ) 1543 else if ( doc->paper() )
1543 cg.setBrush( QColorGroup::Base, *doc->paper() ); 1544 cg.setBrush( QColorGroup::Base, *doc->paper() );
1544 p.setBrushOrigin( -contentsX(), -contentsY() ); 1545 p.setBrushOrigin( -contentsX(), -contentsY() );
1545 cursor->paragraph()->document()->nextDoubleBuffered = TRUE; 1546 cursor->paragraph()->document()->nextDoubleBuffered = TRUE;
1546 if ( !cursor->nestedDepth() ) { 1547 if ( !cursor->nestedDepth() ) {
1547 int h = cursor->paragraph()->lineHeightOfChar( cursor->index() ); 1548 int h = cursor->paragraph()->lineHeightOfChar( cursor->index() );
1548 int dist = 5; 1549 int dist = 5;
1549 if ( ( cursor->paragraph()->alignment() & Qt3::AlignJustify ) == Qt3::AlignJustify ) 1550 if ( ( cursor->paragraph()->alignment() & Qt3::AlignJustify ) == Qt3::AlignJustify )
1550 dist = 50; 1551 dist = 50;
1551 int x = r.x() - cursor->totalOffsetX() + cursor->x() - dist; 1552 int x = r.x() - cursor->totalOffsetX() + cursor->x() - dist;
1552 x = QMAX( x, 0 ); 1553 x = QMAX( x, 0 );
1553 p.setClipRect( QRect( x - contentsX(), 1554 p.setClipRect( QRect( x - contentsX(),
1554 r.y() - cursor->totalOffsetY() + cursor->y() - contentsY(), 2 * dist, h ) ); 1555 r.y() - cursor->totalOffsetY() + cursor->y() - contentsY(), 2 * dist, h ) );
1555 doc->drawParagraph( &p, cursor->paragraph(), x, 1556 doc->drawParagraph( &p, cursor->paragraph(), x,
1556 r.y() - cursor->totalOffsetY() + cursor->y(), 2 * dist, h, pix, cg, visible, cursor ); 1557 r.y() - cursor->totalOffsetY() + cursor->y(), 2 * dist, h, pix, cg, visible, cursor );
1557 } else { 1558 } else {
1558 doc->drawParagraph( &p, cursor->paragraph(), r.x() - cursor->totalOffsetX(), 1559 doc->drawParagraph( &p, cursor->paragraph(), r.x() - cursor->totalOffsetX(),
1559 r.y() - cursor->totalOffsetY(), r.width(), r.height(), 1560 r.y() - cursor->totalOffsetY(), r.width(), r.height(),
1560 pix, cg, visible, cursor ); 1561 pix, cg, visible, cursor );
1561 } 1562 }
1562 cursorVisible = visible; 1563 cursorVisible = visible;
1563} 1564}
@@ -1577,13 +1578,13 @@ enum {
1577void QTextEdit::contentsWheelEvent( QWheelEvent *e ) 1578void QTextEdit::contentsWheelEvent( QWheelEvent *e )
1578{ 1579{
1579 if ( isReadOnly() ) { 1580 if ( isReadOnly() ) {
1580 if ( e->state() & ControlButton ) { 1581 if ( e->state() & ControlButton ) {
1581 if ( e->delta() > 0 ) 1582 if ( e->delta() > 0 )
1582 zoomOut(); 1583 zoomOut();
1583 else if ( e->delta() < 0 ) 1584 else if ( e->delta() < 0 )
1584 zoomIn(); 1585 zoomIn();
1585 return; 1586 return;
1586 } 1587 }
1587 } 1588 }
1588 QScrollView::contentsWheelEvent( e ); 1589 QScrollView::contentsWheelEvent( e );
1589} 1590}
@@ -1601,72 +1602,72 @@ void QTextEdit::contentsMousePressEvent( QMouseEvent *e )
1601 pressedLink = QString::null; 1602 pressedLink = QString::null;
1602 1603
1603 if ( e->button() == LeftButton ) { 1604 if ( e->button() == LeftButton ) {
1604 mousePressed = TRUE; 1605 mousePressed = TRUE;
1605 drawCursor( FALSE ); 1606 drawCursor( FALSE );
1606 placeCursor( e->pos() ); 1607 placeCursor( e->pos() );
1607 ensureCursorVisible(); 1608 ensureCursorVisible();
1608 1609
1609 if ( isReadOnly() && linksEnabled() ) { 1610 if ( isReadOnly() && linksEnabled() ) {
1610 QTextCursor c = *cursor; 1611 QTextCursor c = *cursor;
1611 placeCursor( e->pos(), &c, TRUE ); 1612 placeCursor( e->pos(), &c, TRUE );
1612 if ( c.paragraph() && c.paragraph()->at( c.index() ) && 1613 if ( c.paragraph() && c.paragraph()->at( c.index() ) &&
1613 c.paragraph()->at( c.index() )->isAnchor() ) { 1614 c.paragraph()->at( c.index() )->isAnchor() ) {
1614 pressedLink = c.paragraph()->at( c.index() )->anchorHref(); 1615 pressedLink = c.paragraph()->at( c.index() )->anchorHref();
1615 } 1616 }
1616 } 1617 }
1617 1618
1618#ifndef QT_NO_DRAGANDDROP 1619#ifndef QT_NO_DRAGANDDROP
1619 if ( doc->inSelection( QTextDocument::Standard, e->pos() ) ) { 1620 if ( doc->inSelection( QTextDocument::Standard, e->pos() ) ) {
1620 mightStartDrag = TRUE; 1621 mightStartDrag = TRUE;
1621 drawCursor( TRUE ); 1622 drawCursor( TRUE );
1622 dragStartTimer->start( QApplication::startDragTime(), TRUE ); 1623 dragStartTimer->start( QApplication::startDragTime(), TRUE );
1623 dragStartPos = e->pos(); 1624 dragStartPos = e->pos();
1624 return; 1625 return;
1625 } 1626 }
1626#endif 1627#endif
1627 1628
1628 bool redraw = FALSE; 1629 bool redraw = FALSE;
1629 if ( doc->hasSelection( QTextDocument::Standard ) ) { 1630 if ( doc->hasSelection( QTextDocument::Standard ) ) {
1630 if ( !( e->state() & ShiftButton ) ) { 1631 if ( !( e->state() & ShiftButton ) ) {
1631 redraw = doc->removeSelection( QTextDocument::Standard ); 1632 redraw = doc->removeSelection( QTextDocument::Standard );
1632 doc->setSelectionStart( QTextDocument::Standard, *cursor ); 1633 doc->setSelectionStart( QTextDocument::Standard, *cursor );
1633 } else { 1634 } else {
1634 redraw = doc->setSelectionEnd( QTextDocument::Standard, *cursor ) || redraw; 1635 redraw = doc->setSelectionEnd( QTextDocument::Standard, *cursor ) || redraw;
1635 } 1636 }
1636 } else { 1637 } else {
1637 if ( isReadOnly() || !( e->state() & ShiftButton ) ) { 1638 if ( isReadOnly() || !( e->state() & ShiftButton ) ) {
1638 doc->setSelectionStart( QTextDocument::Standard, *cursor ); 1639 doc->setSelectionStart( QTextDocument::Standard, *cursor );
1639 } else { 1640 } else {
1640 doc->setSelectionStart( QTextDocument::Standard, c ); 1641 doc->setSelectionStart( QTextDocument::Standard, c );
1641 redraw = doc->setSelectionEnd( QTextDocument::Standard, *cursor ) || redraw; 1642 redraw = doc->setSelectionEnd( QTextDocument::Standard, *cursor ) || redraw;
1642 } 1643 }
1643 } 1644 }
1644 1645
1645 for ( int i = 1; i < doc->numSelections(); ++i ) // start with 1 as we don't want to remove the Standard-Selection 1646 for ( int i = 1; i < doc->numSelections(); ++i ) // start with 1 as we don't want to remove the Standard-Selection
1646 redraw = doc->removeSelection( i ) || redraw; 1647 redraw = doc->removeSelection( i ) || redraw;
1647 1648
1648 if ( !redraw ) { 1649 if ( !redraw ) {
1649 drawCursor( TRUE ); 1650 drawCursor( TRUE );
1650 } else { 1651 } else {
1651 repaintChanged(); 1652 repaintChanged();
1652#ifndef QT_NO_CURSOR 1653#ifndef QT_NO_CURSOR
1653 viewport()->setCursor( isReadOnly() ? arrowCursor : ibeamCursor ); 1654 viewport()->setCursor( isReadOnly() ? arrowCursor : ibeamCursor );
1654#endif 1655#endif
1655 } 1656 }
1656 } else if ( e->button() == MidButton ) { 1657 } else if ( e->button() == MidButton ) {
1657 bool redraw = doc->removeSelection( QTextDocument::Standard ); 1658 bool redraw = doc->removeSelection( QTextDocument::Standard );
1658 if ( !redraw ) { 1659 if ( !redraw ) {
1659 drawCursor( TRUE ); 1660 drawCursor( TRUE );
1660 } else { 1661 } else {
1661 repaintChanged(); 1662 repaintChanged();
1662#ifndef QT_NO_CURSOR 1663#ifndef QT_NO_CURSOR
1663 viewport()->setCursor( isReadOnly() ? arrowCursor : ibeamCursor ); 1664 viewport()->setCursor( isReadOnly() ? arrowCursor : ibeamCursor );
1664#endif 1665#endif
1665 } 1666 }
1666 } 1667 }
1667 1668
1668 if ( *cursor != oldCursor ) 1669 if ( *cursor != oldCursor )
1669 updateCurrentFormat(); 1670 updateCurrentFormat();
1670} 1671}
1671 1672
1672/*! \reimp */ 1673/*! \reimp */
@@ -1675,28 +1676,28 @@ void QTextEdit::contentsMouseMoveEvent( QMouseEvent *e )
1675{ 1676{
1676 if ( mousePressed ) { 1677 if ( mousePressed ) {
1677#ifndef QT_NO_DRAGANDDROP 1678#ifndef QT_NO_DRAGANDDROP
1678 if ( mightStartDrag ) { 1679 if ( mightStartDrag ) {
1679 dragStartTimer->stop(); 1680 dragStartTimer->stop();
1680 if ( ( e->pos() - dragStartPos ).manhattanLength() > QApplication::startDragDistance() ) 1681 if ( ( e->pos() - dragStartPos ).manhattanLength() > QApplication::startDragDistance() )
1681 startDrag(); 1682 startDrag();
1682#ifndef QT_NO_CURSOR 1683#ifndef QT_NO_CURSOR
1683 if ( !isReadOnly() ) 1684 if ( !isReadOnly() )
1684 viewport()->setCursor( ibeamCursor ); 1685 viewport()->setCursor( ibeamCursor );
1685#endif 1686#endif
1686 return; 1687 return;
1687 } 1688 }
1688#endif 1689#endif
1689 mousePos = e->pos(); 1690 mousePos = e->pos();
1690 handleMouseMove( mousePos ); 1691 handleMouseMove( mousePos );
1691 oldMousePos = mousePos; 1692 oldMousePos = mousePos;
1692 } 1693 }
1693 1694
1694#ifndef QT_NO_CURSOR 1695#ifndef QT_NO_CURSOR
1695 if ( !isReadOnly() && !mousePressed ) { 1696 if ( !isReadOnly() && !mousePressed ) {
1696 if ( doc->hasSelection( QTextDocument::Standard ) && doc->inSelection( QTextDocument::Standard, e->pos() ) ) 1697 if ( doc->hasSelection( QTextDocument::Standard ) && doc->inSelection( QTextDocument::Standard, e->pos() ) )
1697 viewport()->setCursor( arrowCursor ); 1698 viewport()->setCursor( arrowCursor );
1698 else 1699 else
1699 viewport()->setCursor( ibeamCursor ); 1700 viewport()->setCursor( ibeamCursor );
1700 } 1701 }
1701#endif 1702#endif
1702 updateCursor( e->pos() ); 1703 updateCursor( e->pos() );
@@ -1708,38 +1709,38 @@ void QTextEdit::contentsMouseReleaseEvent( QMouseEvent * e )
1708{ 1709{
1709 QTextCursor oldCursor = *cursor; 1710 QTextCursor oldCursor = *cursor;
1710 if ( scrollTimer->isActive() ) 1711 if ( scrollTimer->isActive() )
1711 scrollTimer->stop(); 1712 scrollTimer->stop();
1712#ifndef QT_NO_DRAGANDDROP 1713#ifndef QT_NO_DRAGANDDROP
1713 if ( dragStartTimer->isActive() ) 1714 if ( dragStartTimer->isActive() )
1714 dragStartTimer->stop(); 1715 dragStartTimer->stop();
1715 if ( mightStartDrag ) { 1716 if ( mightStartDrag ) {
1716 selectAll( FALSE ); 1717 selectAll( FALSE );
1717 mousePressed = FALSE; 1718 mousePressed = FALSE;
1718 } 1719 }
1719#endif 1720#endif
1720 if ( mousePressed ) { 1721 if ( mousePressed ) {
1721 mousePressed = FALSE; 1722 mousePressed = FALSE;
1722 } 1723 }
1723 emit cursorPositionChanged( cursor ); 1724 emit cursorPositionChanged( cursor );
1724 emit cursorPositionChanged( cursor->paragraph()->paragId(), cursor->index() ); 1725 emit cursorPositionChanged( cursor->paragraph()->paragId(), cursor->index() );
1725 if ( oldCursor != *cursor ) 1726 if ( oldCursor != *cursor )
1726 updateCurrentFormat(); 1727 updateCurrentFormat();
1727 inDoubleClick = FALSE; 1728 inDoubleClick = FALSE;
1728 1729
1729#ifndef QT_NO_NETWORKPROTOCOL 1730#ifndef QT_NO_NETWORKPROTOCOL
1730 if ( !onLink.isEmpty() && onLink == pressedLink && linksEnabled() ) { 1731 if ( !onLink.isEmpty() && onLink == pressedLink && linksEnabled() ) {
1731 QUrl u( doc->context(), onLink, TRUE ); 1732 QUrl u( doc->context(), onLink, TRUE );
1732 emitLinkClicked( u.toString( FALSE, FALSE ) ); 1733 emitLinkClicked( u.toString( FALSE, FALSE ) );
1733 1734
1734 // emitting linkClicked() may result in that the cursor winds 1735 // emitting linkClicked() may result in that the cursor winds
1735 // up hovering over a different valid link - check this and 1736 // up hovering over a different valid link - check this and
1736 // set the appropriate cursor shape 1737 // set the appropriate cursor shape
1737 updateCursor( e->pos() ); 1738 updateCursor( e->pos() );
1738 } 1739 }
1739#endif 1740#endif
1740 drawCursor( TRUE ); 1741 drawCursor( TRUE );
1741 if ( !doc->hasSelection( QTextDocument::Standard, TRUE ) ) 1742 if ( !doc->hasSelection( QTextDocument::Standard, TRUE ) )
1742 doc->removeSelection( QTextDocument::Standard ); 1743 doc->removeSelection( QTextDocument::Standard );
1743 1744
1744 emit copyAvailable( doc->hasSelection( QTextDocument::Standard ) ); 1745 emit copyAvailable( doc->hasSelection( QTextDocument::Standard ) );
1745 emit selectionChanged(); 1746 emit selectionChanged();
@@ -1752,9 +1753,9 @@ void QTextEdit::contentsMouseDoubleClickEvent( QMouseEvent * )
1752 QTextCursor c1 = *cursor; 1753 QTextCursor c1 = *cursor;
1753 QTextCursor c2 = *cursor; 1754 QTextCursor c2 = *cursor;
1754 if ( cursor->index() > 0 && !cursor->paragraph()->at( cursor->index()-1 )->c.isSpace() ) 1755 if ( cursor->index() > 0 && !cursor->paragraph()->at( cursor->index()-1 )->c.isSpace() )
1755 c1.gotoPreviousWord(); 1756 c1.gotoPreviousWord();
1756 if ( !cursor->paragraph()->at( cursor->index() )->c.isSpace() && !cursor->atParagEnd() ) 1757 if ( !cursor->paragraph()->at( cursor->index() )->c.isSpace() && !cursor->atParagEnd() )
1757 c2.gotoNextWord(); 1758 c2.gotoNextWord();
1758 1759
1759 doc->setSelectionStart( QTextDocument::Standard, c1 ); 1760 doc->setSelectionStart( QTextDocument::Standard, c1 );
1760 doc->setSelectionEnd( QTextDocument::Standard, c2 ); 1761 doc->setSelectionEnd( QTextDocument::Standard, c2 );
@@ -1774,8 +1775,8 @@ void QTextEdit::contentsMouseDoubleClickEvent( QMouseEvent * )
1774void QTextEdit::contentsDragEnterEvent( QDragEnterEvent *e ) 1775void QTextEdit::contentsDragEnterEvent( QDragEnterEvent *e )
1775{ 1776{
1776 if ( isReadOnly() || !QTextDrag::canDecode( e ) ) { 1777 if ( isReadOnly() || !QTextDrag::canDecode( e ) ) {
1777 e->ignore(); 1778 e->ignore();
1778 return; 1779 return;
1779 } 1780 }
1780 e->acceptAction(); 1781 e->acceptAction();
1781 inDnD = TRUE; 1782 inDnD = TRUE;
@@ -1786,8 +1787,8 @@ void QTextEdit::contentsDragEnterEvent( QDragEnterEvent *e )
1786void QTextEdit::contentsDragMoveEvent( QDragMoveEvent *e ) 1787void QTextEdit::contentsDragMoveEvent( QDragMoveEvent *e )
1787{ 1788{
1788 if ( isReadOnly() || !QTextDrag::canDecode( e ) ) { 1789 if ( isReadOnly() || !QTextDrag::canDecode( e ) ) {
1789 e->ignore(); 1790 e->ignore();
1790 return; 1791 return;
1791 } 1792 }
1792 drawCursor( FALSE ); 1793 drawCursor( FALSE );
1793 placeCursor( e->pos(), cursor ); 1794 placeCursor( e->pos(), cursor );
@@ -1807,67 +1808,67 @@ void QTextEdit::contentsDragLeaveEvent( QDragLeaveEvent * )
1807void QTextEdit::contentsDropEvent( QDropEvent *e ) 1808void QTextEdit::contentsDropEvent( QDropEvent *e )
1808{ 1809{
1809 if ( isReadOnly() ) 1810 if ( isReadOnly() )
1810 return; 1811 return;
1811 inDnD = FALSE; 1812 inDnD = FALSE;
1812 e->acceptAction(); 1813 e->acceptAction();
1813 QString text; 1814 QString text;
1814 bool intern = FALSE; 1815 bool intern = FALSE;
1815 if ( QTextDrag::decode( e, text ) ) { 1816 if ( QTextDrag::decode( e, text ) ) {
1816 bool hasSel = doc->hasSelection( QTextDocument::Standard ); 1817 bool hasSel = doc->hasSelection( QTextDocument::Standard );
1817 bool internalDrag = e->source() == this || e->source() == viewport(); 1818 bool internalDrag = e->source() == this || e->source() == viewport();
1818 int dropId, dropIndex; 1819 int dropId, dropIndex;
1819 QTextCursor insertCursor = *cursor; 1820 QTextCursor insertCursor = *cursor;
1820 dropId = cursor->paragraph()->paragId(); 1821 dropId = cursor->paragraph()->paragId();
1821 dropIndex = cursor->index(); 1822 dropIndex = cursor->index();
1822 if ( hasSel && internalDrag ) { 1823 if ( hasSel && internalDrag ) {
1823 QTextCursor c1, c2; 1824 QTextCursor c1, c2;
1824 int selStartId, selStartIndex; 1825 int selStartId, selStartIndex;
1825 int selEndId, selEndIndex; 1826 int selEndId, selEndIndex;
1826 c1 = doc->selectionStartCursor( QTextDocument::Standard ); 1827 c1 = doc->selectionStartCursor( QTextDocument::Standard );
1827 c1.restoreState(); 1828 c1.restoreState();
1828 c2 = doc->selectionEndCursor( QTextDocument::Standard ); 1829 c2 = doc->selectionEndCursor( QTextDocument::Standard );
1829 c2.restoreState(); 1830 c2.restoreState();
1830 selStartId = c1.paragraph()->paragId(); 1831 selStartId = c1.paragraph()->paragId();
1831 selStartIndex = c1.index(); 1832 selStartIndex = c1.index();
1832 selEndId = c2.paragraph()->paragId(); 1833 selEndId = c2.paragraph()->paragId();
1833 selEndIndex = c2.index(); 1834 selEndIndex = c2.index();
1834 if ( ( ( dropId > selStartId ) || 1835 if ( ( ( dropId > selStartId ) ||
1835 ( dropId == selStartId && dropIndex > selStartIndex ) ) && 1836 ( dropId == selStartId && dropIndex > selStartIndex ) ) &&
1836 ( ( dropId < selEndId ) || 1837 ( ( dropId < selEndId ) ||
1837 ( dropId == selEndId && dropIndex <= selEndIndex ) ) ) 1838 ( dropId == selEndId && dropIndex <= selEndIndex ) ) )
1838 insertCursor = c1; 1839 insertCursor = c1;
1839 if ( dropId == selEndId && dropIndex > selEndIndex ) { 1840 if ( dropId == selEndId && dropIndex > selEndIndex ) {
1840 insertCursor = c1; 1841 insertCursor = c1;
1841 if ( selStartId == selEndId ) { 1842 if ( selStartId == selEndId ) {
1842 insertCursor.setIndex( dropIndex - 1843 insertCursor.setIndex( dropIndex -
1843 ( selEndIndex - selStartIndex ) ); 1844 ( selEndIndex - selStartIndex ) );
1844 } else { 1845 } else {
1845 insertCursor.setIndex( dropIndex - selEndIndex + 1846 insertCursor.setIndex( dropIndex - selEndIndex +
1846 selStartIndex ); 1847 selStartIndex );
1847 } 1848 }
1848 } 1849 }
1849 } 1850 }
1850 1851
1851 if ( internalDrag && e->action() == QDropEvent::Move ) { 1852 if ( internalDrag && e->action() == QDropEvent::Move ) {
1852 removeSelectedText(); 1853 removeSelectedText();
1853 intern = TRUE; 1854 intern = TRUE;
1854 } else { 1855 } else {
1855 doc->removeSelection( QTextDocument::Standard ); 1856 doc->removeSelection( QTextDocument::Standard );
1856#ifndef QT_NO_CURSOR 1857#ifndef QT_NO_CURSOR
1857 viewport()->setCursor( isReadOnly() ? arrowCursor : ibeamCursor ); 1858 viewport()->setCursor( isReadOnly() ? arrowCursor : ibeamCursor );
1858#endif 1859#endif
1859 } 1860 }
1860 drawCursor( FALSE ); 1861 drawCursor( FALSE );
1861 cursor->setParagraph( insertCursor.paragraph() ); 1862 cursor->setParagraph( insertCursor.paragraph() );
1862 cursor->setIndex( insertCursor.index() ); 1863 cursor->setIndex( insertCursor.index() );
1863 drawCursor( TRUE ); 1864 drawCursor( TRUE );
1864 if ( !cursor->nestedDepth() ) { 1865 if ( !cursor->nestedDepth() ) {
1865 insert( text, FALSE, TRUE, FALSE ); 1866 insert( text, FALSE, TRUE, FALSE );
1866 } else { 1867 } else {
1867 if ( intern ) 1868 if ( intern )
1868 undo(); 1869 undo();
1869 e->ignore(); 1870 e->ignore();
1870 } 1871 }
1871 } 1872 }
1872} 1873}
1873 1874
@@ -1876,18 +1877,18 @@ void QTextEdit::contentsDropEvent( QDropEvent *e )
1876void QTextEdit::autoScrollTimerDone() 1877void QTextEdit::autoScrollTimerDone()
1877{ 1878{
1878 if ( mousePressed ) 1879 if ( mousePressed )
1879 handleMouseMove( viewportToContents( viewport()->mapFromGlobal( QCursor::pos() ) ) ); 1880 handleMouseMove( viewportToContents( viewport()->mapFromGlobal( QCursor::pos() ) ) );
1880} 1881}
1881 1882
1882void QTextEdit::handleMouseMove( const QPoint& pos ) 1883void QTextEdit::handleMouseMove( const QPoint& pos )
1883{ 1884{
1884 if ( !mousePressed ) 1885 if ( !mousePressed )
1885 return; 1886 return;
1886 1887
1887 if ( !scrollTimer->isActive() && pos.y() < contentsY() || pos.y() > contentsY() + visibleHeight() ) 1888 if ( !scrollTimer->isActive() && pos.y() < contentsY() || pos.y() > contentsY() + visibleHeight() )
1888 scrollTimer->start( 100, FALSE ); 1889 scrollTimer->start( 100, FALSE );
1889 else if ( scrollTimer->isActive() && pos.y() >= contentsY() && pos.y() <= contentsY() + visibleHeight() ) 1890 else if ( scrollTimer->isActive() && pos.y() >= contentsY() && pos.y() <= contentsY() + visibleHeight() )
1890 scrollTimer->stop(); 1891 scrollTimer->stop();
1891 1892
1892 drawCursor( FALSE ); 1893 drawCursor( FALSE );
1893 QTextCursor oldCursor = *cursor; 1894 QTextCursor oldCursor = *cursor;
@@ -1895,59 +1896,59 @@ void QTextEdit::handleMouseMove( const QPoint& pos )
1895 placeCursor( pos ); 1896 placeCursor( pos );
1896 1897
1897 if ( inDoubleClick ) { 1898 if ( inDoubleClick ) {
1898 QTextCursor cl = *cursor; 1899 QTextCursor cl = *cursor;
1899 cl.gotoPreviousWord(); 1900 cl.gotoPreviousWord();
1900 QTextCursor cr = *cursor; 1901 QTextCursor cr = *cursor;
1901 cr.gotoNextWord(); 1902 cr.gotoNextWord();
1902 1903
1903 int diff = QABS( oldCursor.paragraph()->at( oldCursor.index() )->x - mousePos.x() ); 1904 int diff = QABS( oldCursor.paragraph()->at( oldCursor.index() )->x - mousePos.x() );
1904 int ldiff = QABS( cl.paragraph()->at( cl.index() )->x - mousePos.x() ); 1905 int ldiff = QABS( cl.paragraph()->at( cl.index() )->x - mousePos.x() );
1905 int rdiff = QABS( cr.paragraph()->at( cr.index() )->x - mousePos.x() ); 1906 int rdiff = QABS( cr.paragraph()->at( cr.index() )->x - mousePos.x() );
1906 1907
1907 1908
1908 if ( cursor->paragraph()->lineStartOfChar( cursor->index() ) != 1909 if ( cursor->paragraph()->lineStartOfChar( cursor->index() ) !=
1909 oldCursor.paragraph()->lineStartOfChar( oldCursor.index() ) ) 1910 oldCursor.paragraph()->lineStartOfChar( oldCursor.index() ) )
1910 diff = 0xFFFFFF; 1911 diff = 0xFFFFFF;
1911 1912
1912 if ( rdiff < diff && rdiff < ldiff ) 1913 if ( rdiff < diff && rdiff < ldiff )
1913 *cursor = cr; 1914 *cursor = cr;
1914 else if ( ldiff < diff && ldiff < rdiff ) 1915 else if ( ldiff < diff && ldiff < rdiff )
1915 *cursor = cl; 1916 *cursor = cl;
1916 else 1917 else
1917 *cursor = oldCursor; 1918 *cursor = oldCursor;
1918 1919
1919 } 1920 }
1920 ensureCursorVisible(); 1921 ensureCursorVisible();
1921 1922
1922 bool redraw = FALSE; 1923 bool redraw = FALSE;
1923 if ( doc->hasSelection( QTextDocument::Standard ) ) { 1924 if ( doc->hasSelection( QTextDocument::Standard ) ) {
1924 redraw = doc->setSelectionEnd( QTextDocument::Standard, *cursor ) || redraw; 1925 redraw = doc->setSelectionEnd( QTextDocument::Standard, *cursor ) || redraw;
1925 } 1926 }
1926 1927
1927 if ( !redraw ) { 1928 if ( !redraw ) {
1928 drawCursor( TRUE ); 1929 drawCursor( TRUE );
1929 } else { 1930 } else {
1930 repaintChanged(); 1931 repaintChanged();
1931 drawCursor( TRUE ); 1932 drawCursor( TRUE );
1932 } 1933 }
1933 1934
1934 if ( currentFormat && currentFormat->key() != cursor->paragraph()->at( cursor->index() )->format()->key() ) { 1935 if ( currentFormat && currentFormat->key() != cursor->paragraph()->at( cursor->index() )->format()->key() ) {
1935 currentFormat->removeRef(); 1936 currentFormat->removeRef();
1936 currentFormat = doc->formatCollection()->format( cursor->paragraph()->at( cursor->index() )->format() ); 1937 currentFormat = doc->formatCollection()->format( cursor->paragraph()->at( cursor->index() )->format() );
1937 if ( currentFormat->isMisspelled() ) { 1938 if ( currentFormat->isMisspelled() ) {
1938 currentFormat->removeRef(); 1939 currentFormat->removeRef();
1939 currentFormat = doc->formatCollection()->format( currentFormat->font(), currentFormat->color() ); 1940 currentFormat = doc->formatCollection()->format( currentFormat->font(), currentFormat->color() );
1940 } 1941 }
1941 emit currentFontChanged( currentFormat->font() ); 1942 emit currentFontChanged( currentFormat->font() );
1942 emit currentColorChanged( currentFormat->color() ); 1943 emit currentColorChanged( currentFormat->color() );
1943 emit currentVerticalAlignmentChanged( (VerticalAlignment)currentFormat->vAlign() ); 1944 emit currentVerticalAlignmentChanged( (VerticalAlignment)currentFormat->vAlign() );
1944 } 1945 }
1945 1946
1946 if ( currentAlignment != cursor->paragraph()->alignment() ) { 1947 if ( currentAlignment != cursor->paragraph()->alignment() ) {
1947 currentAlignment = cursor->paragraph()->alignment(); 1948 currentAlignment = cursor->paragraph()->alignment();
1948 block_set_alignment = TRUE; 1949 block_set_alignment = TRUE;
1949 emit currentAlignmentChanged( currentAlignment ); 1950 emit currentAlignmentChanged( currentAlignment );
1950 block_set_alignment = FALSE; 1951 block_set_alignment = FALSE;
1951 } 1952 }
1952} 1953}
1953 1954
@@ -1963,7 +1964,7 @@ void QTextEdit::handleMouseMove( const QPoint& pos )
1963void QTextEdit::placeCursor( const QPoint &pos, QTextCursor *c, bool link ) 1964void QTextEdit::placeCursor( const QPoint &pos, QTextCursor *c, bool link )
1964{ 1965{
1965 if ( !c ) 1966 if ( !c )
1966 c = cursor; 1967 c = cursor;
1967 1968
1968 c->restoreState(); 1969 c->restoreState();
1969 QTextParagraph *s = doc->firstParagraph(); 1970 QTextParagraph *s = doc->firstParagraph();
@@ -1976,15 +1977,15 @@ void QTextEdit::updateMicroFocusHint()
1976{ 1977{
1977 QTextCursor c( *cursor ); 1978 QTextCursor c( *cursor );
1978 if ( d->preeditStart != -1 ) 1979 if ( d->preeditStart != -1 )
1979 c.setIndex( d->preeditStart ); 1980 c.setIndex( d->preeditStart );
1980 1981
1981 if ( hasFocus() || viewport()->hasFocus() ) { 1982 if ( hasFocus() || viewport()->hasFocus() ) {
1982 int h = c.paragraph()->lineHeightOfChar( cursor->index() ); 1983 int h = c.paragraph()->lineHeightOfChar( cursor->index() );
1983 if ( !readonly ) { 1984 if ( !readonly ) {
1984 QFont f = c.paragraph()->at( c.index() )->format()->font(); 1985 QFont f = c.paragraph()->at( c.index() )->format()->font();
1985 setMicroFocusHint( c.x() - contentsX() + frameWidth(), 1986 setMicroFocusHint( c.x() - contentsX() + frameWidth(),
1986 c.y() + cursor->paragraph()->rect().y() - contentsY() + frameWidth(), 0, h, TRUE ); 1987 c.y() + cursor->paragraph()->rect().y() - contentsY() + frameWidth(), 0, h, TRUE );
1987 } 1988 }
1988 } 1989 }
1989} 1990}
1990 1991
@@ -1993,7 +1994,7 @@ void QTextEdit::updateMicroFocusHint()
1993void QTextEdit::formatMore() 1994void QTextEdit::formatMore()
1994{ 1995{
1995 if ( !lastFormatted ) 1996 if ( !lastFormatted )
1996 return; 1997 return;
1997 1998
1998 int bottom = contentsHeight(); 1999 int bottom = contentsHeight();
1999 int lastBottom = -1; 2000 int lastBottom = -1;
@@ -2001,38 +2002,38 @@ void QTextEdit::formatMore()
2001 bool firstVisible = FALSE; 2002 bool firstVisible = FALSE;
2002 QRect cr( contentsX(), contentsY(), visibleWidth(), visibleHeight() ); 2003 QRect cr( contentsX(), contentsY(), visibleWidth(), visibleHeight() );
2003 for ( int i = 0; ( i < to || firstVisible ) && lastFormatted; ++i ) { 2004 for ( int i = 0; ( i < to || firstVisible ) && lastFormatted; ++i ) {
2004 lastFormatted->format(); 2005 lastFormatted->format();
2005 if ( i == 0 ) 2006 if ( i == 0 )
2006 firstVisible = lastFormatted->rect().intersects( cr ); 2007 firstVisible = lastFormatted->rect().intersects( cr );
2007 else if ( firstVisible ) 2008 else if ( firstVisible )
2008 firstVisible = lastFormatted->rect().intersects( cr ); 2009 firstVisible = lastFormatted->rect().intersects( cr );
2009 bottom = QMAX( bottom, lastFormatted->rect().top() + 2010 bottom = QMAX( bottom, lastFormatted->rect().top() +
2010 lastFormatted->rect().height() ); 2011 lastFormatted->rect().height() );
2011 lastBottom = lastFormatted->rect().top() + lastFormatted->rect().height(); 2012 lastBottom = lastFormatted->rect().top() + lastFormatted->rect().height();
2012 lastFormatted = lastFormatted->next(); 2013 lastFormatted = lastFormatted->next();
2013 if ( lastFormatted ) 2014 if ( lastFormatted )
2014 lastBottom = -1; 2015 lastBottom = -1;
2015 } 2016 }
2016 2017
2017 if ( bottom > contentsHeight() ) { 2018 if ( bottom > contentsHeight() ) {
2018 resizeContents( contentsWidth(), QMAX( doc->height(), bottom ) ); 2019 resizeContents( contentsWidth(), QMAX( doc->height(), bottom ) );
2019 } else if ( lastBottom != -1 && lastBottom < contentsHeight() ) { 2020 } else if ( lastBottom != -1 && lastBottom < contentsHeight() ) {
2020 resizeContents( contentsWidth(), QMAX( doc->height(), lastBottom ) ); 2021 resizeContents( contentsWidth(), QMAX( doc->height(), lastBottom ) );
2021 if ( contentsHeight() < visibleHeight() ) 2022 if ( contentsHeight() < visibleHeight() )
2022 updateContents( 0, contentsHeight(), visibleWidth(), 2023 updateContents( 0, contentsHeight(), visibleWidth(),
2023 visibleHeight() - contentsHeight() ); 2024 visibleHeight() - contentsHeight() );
2024 } 2025 }
2025 2026
2026 if ( lastFormatted ) 2027 if ( lastFormatted )
2027 formatTimer->start( interval, TRUE ); 2028 formatTimer->start( interval, TRUE );
2028 else 2029 else
2029 interval = QMAX( 0, interval ); 2030 interval = QMAX( 0, interval );
2030} 2031}
2031 2032
2032void QTextEdit::doResize() 2033void QTextEdit::doResize()
2033{ 2034{
2034 if ( wrapMode == FixedPixelWidth ) 2035 if ( wrapMode == FixedPixelWidth )
2035 return; 2036 return;
2036 doc->setMinimumWidth( -1 ); 2037 doc->setMinimumWidth( -1 );
2037 resizeContents( 0, 0 ); 2038 resizeContents( 0, 0 );
2038 doc->setWidth( visibleWidth() ); 2039 doc->setWidth( visibleWidth() );
@@ -2055,14 +2056,14 @@ void QTextEdit::doChangeInterval()
2055bool QTextEdit::eventFilter( QObject *o, QEvent *e ) 2056bool QTextEdit::eventFilter( QObject *o, QEvent *e )
2056{ 2057{
2057 if ( o == this || o == viewport() ) { 2058 if ( o == this || o == viewport() ) {
2058 if ( e->type() == QEvent::FocusIn ) { 2059 if ( e->type() == QEvent::FocusIn ) {
2059 blinkTimer->start( QApplication::cursorFlashTime() / 2 ); 2060 blinkTimer->start( QApplication::cursorFlashTime() / 2 );
2060 drawCursor( TRUE ); 2061 drawCursor( TRUE );
2061 updateMicroFocusHint(); 2062 updateMicroFocusHint();
2062 } else if ( e->type() == QEvent::FocusOut ) { 2063 } else if ( e->type() == QEvent::FocusOut ) {
2063 blinkTimer->stop(); 2064 blinkTimer->stop();
2064 drawCursor( FALSE ); 2065 drawCursor( FALSE );
2065 } 2066 }
2066 } 2067 }
2067 2068
2068 return QScrollView::eventFilter( o, e ); 2069 return QScrollView::eventFilter( o, e );
@@ -2083,59 +2084,59 @@ bool QTextEdit::eventFilter( QObject *o, QEvent *e )
2083void QTextEdit::insert( const QString &text, bool indent, bool checkNewLine, bool removeSelected ) 2084void QTextEdit::insert( const QString &text, bool indent, bool checkNewLine, bool removeSelected )
2084{ 2085{
2085 if ( cursor->nestedDepth() != 0 ) // #### for 3.0, disable editing of tables as this is not advanced enough 2086 if ( cursor->nestedDepth() != 0 ) // #### for 3.0, disable editing of tables as this is not advanced enough
2086 return; 2087 return;
2087 QString txt( text ); 2088 QString txt( text );
2088 drawCursor( FALSE ); 2089 drawCursor( FALSE );
2089 if ( !isReadOnly() && doc->hasSelection( QTextDocument::Standard ) && removeSelected ) 2090 if ( !isReadOnly() && doc->hasSelection( QTextDocument::Standard ) && removeSelected )
2090 removeSelectedText(); 2091 removeSelectedText();
2091 QTextCursor c2 = *cursor; 2092 QTextCursor c2 = *cursor;
2092 int oldLen = 0; 2093 int oldLen = 0;
2093 2094
2094 if ( undoEnabled && !isReadOnly() ) { 2095 if ( undoEnabled && !isReadOnly() ) {
2095 checkUndoRedoInfo( UndoRedoInfo::Insert ); 2096 checkUndoRedoInfo( UndoRedoInfo::Insert );
2096 if ( !undoRedoInfo.valid() ) { 2097 if ( !undoRedoInfo.valid() ) {
2097 undoRedoInfo.id = cursor->paragraph()->paragId(); 2098 undoRedoInfo.id = cursor->paragraph()->paragId();
2098 undoRedoInfo.index = cursor->index(); 2099 undoRedoInfo.index = cursor->index();
2099 undoRedoInfo.d->text = QString::null; 2100 undoRedoInfo.d->text = QString::null;
2100 } 2101 }
2101 oldLen = undoRedoInfo.d->text.length(); 2102 oldLen = undoRedoInfo.d->text.length();
2102 } 2103 }
2103 2104
2104 lastFormatted = checkNewLine && cursor->paragraph()->prev() ? 2105 lastFormatted = checkNewLine && cursor->paragraph()->prev() ?
2105 cursor->paragraph()->prev() : cursor->paragraph(); 2106 cursor->paragraph()->prev() : cursor->paragraph();
2106 QTextCursor oldCursor = *cursor; 2107 QTextCursor oldCursor = *cursor;
2107 cursor->insert( txt, checkNewLine ); 2108 cursor->insert( txt, checkNewLine );
2108 if ( doc->useFormatCollection() ) { 2109 if ( doc->useFormatCollection() ) {
2109 doc->setSelectionStart( QTextDocument::Temp, oldCursor ); 2110 doc->setSelectionStart( QTextDocument::Temp, oldCursor );
2110 doc->setSelectionEnd( QTextDocument::Temp, *cursor ); 2111 doc->setSelectionEnd( QTextDocument::Temp, *cursor );
2111 doc->setFormat( QTextDocument::Temp, currentFormat, QTextFormat::Format ); 2112 doc->setFormat( QTextDocument::Temp, currentFormat, QTextFormat::Format );
2112 doc->removeSelection( QTextDocument::Temp ); 2113 doc->removeSelection( QTextDocument::Temp );
2113 } 2114 }
2114 2115
2115 if ( indent && ( txt == "{" || txt == "}" || txt == ":" || txt == "#" ) ) 2116 if ( indent && ( txt == "{" || txt == "}" || txt == ":" || txt == "#" ) )
2116 cursor->indent(); 2117 cursor->indent();
2117 formatMore(); 2118 formatMore();
2118 repaintChanged(); 2119 repaintChanged();
2119 ensureCursorVisible(); 2120 ensureCursorVisible();
2120 drawCursor( TRUE ); 2121 drawCursor( TRUE );
2121 2122
2122 if ( undoEnabled && !isReadOnly() ) { 2123 if ( undoEnabled && !isReadOnly() ) {
2123 undoRedoInfo.d->text += txt; 2124 undoRedoInfo.d->text += txt;
2124 if ( !doc->preProcessor() ) { 2125 if ( !doc->preProcessor() ) {
2125 for ( int i = 0; i < (int)txt.length(); ++i ) { 2126 for ( int i = 0; i < (int)txt.length(); ++i ) {
2126 if ( txt[ i ] != '\n' && c2.paragraph()->at( c2.index() )->format() ) { 2127 if ( txt[ i ] != '\n' && c2.paragraph()->at( c2.index() )->format() ) {
2127 c2.paragraph()->at( c2.index() )->format()->addRef(); 2128 c2.paragraph()->at( c2.index() )->format()->addRef();
2128 undoRedoInfo.d->text.setFormat( oldLen + i, c2.paragraph()->at( c2.index() )->format(), TRUE ); 2129 undoRedoInfo.d->text.setFormat( oldLen + i, c2.paragraph()->at( c2.index() )->format(), TRUE );
2129 } 2130 }
2130 c2.gotoNextLetter(); 2131 c2.gotoNextLetter();
2131 } 2132 }
2132 } 2133 }
2133 } 2134 }
2134 2135
2135 if ( !removeSelected ) { 2136 if ( !removeSelected ) {
2136 doc->setSelectionStart( QTextDocument::Standard, oldCursor ); 2137 doc->setSelectionStart( QTextDocument::Standard, oldCursor );
2137 doc->setSelectionEnd( QTextDocument::Standard, *cursor ); 2138 doc->setSelectionEnd( QTextDocument::Standard, *cursor );
2138 repaintChanged(); 2139 repaintChanged();
2139 } 2140 }
2140 updateMicroFocusHint(); 2141 updateMicroFocusHint();
2141 setModified(); 2142 setModified();
@@ -2149,7 +2150,7 @@ void QTextEdit::insertAt( const QString &text, int para, int index )
2149 removeSelection( QTextDocument::Standard ); 2150 removeSelection( QTextDocument::Standard );
2150 QTextParagraph *p = doc->paragAt( para ); 2151 QTextParagraph *p = doc->paragAt( para );
2151 if ( !p ) 2152 if ( !p )
2152 return; 2153 return;
2153 QTextCursor tmp = *cursor; 2154 QTextCursor tmp = *cursor;
2154 cursor->setParagraph( p ); 2155 cursor->setParagraph( p );
2155 cursor->setIndex( index ); 2156 cursor->setIndex( index );
@@ -2166,14 +2167,14 @@ void QTextEdit::insertParagraph( const QString &text, int para )
2166{ 2167{
2167 QTextParagraph *p = doc->paragAt( para ); 2168 QTextParagraph *p = doc->paragAt( para );
2168 if ( p ) { 2169 if ( p ) {
2169 QTextCursor tmp( doc ); 2170 QTextCursor tmp( doc );
2170 tmp.setParagraph( p ); 2171 tmp.setParagraph( p );
2171 tmp.setIndex( 0 ); 2172 tmp.setIndex( 0 );
2172 tmp.insert( text, TRUE ); 2173 tmp.insert( text, TRUE );
2173 tmp.splitAndInsertEmptyParagraph(); 2174 tmp.splitAndInsertEmptyParagraph();
2174 repaintChanged(); 2175 repaintChanged();
2175 } else { 2176 } else {
2176 append( text ); 2177 append( text );
2177 } 2178 }
2178} 2179}
2179 2180
@@ -2183,41 +2184,41 @@ void QTextEdit::removeParagraph( int para )
2183{ 2184{
2184 QTextParagraph *p = doc->paragAt( para ); 2185 QTextParagraph *p = doc->paragAt( para );
2185 if ( !p ) 2186 if ( !p )
2186 return; 2187 return;
2187 for ( int i = 0; i < doc->numSelections(); ++i ) 2188 for ( int i = 0; i < doc->numSelections(); ++i )
2188 doc->removeSelection( i ); 2189 doc->removeSelection( i );
2189 2190
2190 if ( p == doc->firstParagraph() && p == doc->lastParagraph() ) { 2191 if ( p == doc->firstParagraph() && p == doc->lastParagraph() ) {
2191 p->remove( 0, p->length() - 1 ); 2192 p->remove( 0, p->length() - 1 );
2192 repaintChanged(); 2193 repaintChanged();
2193 return; 2194 return;
2194 } 2195 }
2195 drawCursor( FALSE ); 2196 drawCursor( FALSE );
2196 bool resetCursor = cursor->paragraph() == p; 2197 bool resetCursor = cursor->paragraph() == p;
2197 if ( p->prev() ) 2198 if ( p->prev() )
2198 p->prev()->setNext( p->next() ); 2199 p->prev()->setNext( p->next() );
2199 else 2200 else
2200 doc->setFirstParagraph( p->next() ); 2201 doc->setFirstParagraph( p->next() );
2201 if ( p->next() ) 2202 if ( p->next() )
2202 p->next()->setPrev( p->prev() ); 2203 p->next()->setPrev( p->prev() );
2203 else 2204 else
2204 doc->setLastParagraph( p->prev() ); 2205 doc->setLastParagraph( p->prev() );
2205 QTextParagraph *start = p->next(); 2206 QTextParagraph *start = p->next();
2206 int h = p->rect().height(); 2207 int h = p->rect().height();
2207 delete p; 2208 delete p;
2208 p = start; 2209 p = start;
2209 int dy = -h; 2210 int dy = -h;
2210 while ( p ) { 2211 while ( p ) {
2211 p->setParagId( p->prev() ? p->prev()->paragId() + 1 : 0 ); 2212 p->setParagId( p->prev() ? p->prev()->paragId() + 1 : 0 );
2212 p->move( dy ); 2213 p->move( dy );
2213 p->invalidate( 0 ); 2214 p->invalidate( 0 );
2214 p->setEndState( -1 ); 2215 p->setEndState( -1 );
2215 p = p->next(); 2216 p = p->next();
2216 } 2217 }
2217 2218
2218 if ( resetCursor ) { 2219 if ( resetCursor ) {
2219 cursor->setParagraph( doc->firstParagraph() ); 2220 cursor->setParagraph( doc->firstParagraph() );
2220 cursor->setIndex( 0 ); 2221 cursor->setIndex( 0 );
2221 } 2222 }
2222 repaintChanged(); 2223 repaintChanged();
2223 drawCursor( TRUE ); 2224 drawCursor( TRUE );
@@ -2239,10 +2240,10 @@ void QTextEdit::undo()
2239 // 100% certain this is the right call to do this. 2240 // 100% certain this is the right call to do this.
2240 clearUndoRedo(); 2241 clearUndoRedo();
2241 if ( isReadOnly() || !doc->commands()->isUndoAvailable() || !undoEnabled ) 2242 if ( isReadOnly() || !doc->commands()->isUndoAvailable() || !undoEnabled )
2242 return; 2243 return;
2243 2244
2244 for ( int i = 0; i < (int)doc->numSelections(); ++i ) 2245 for ( int i = 0; i < (int)doc->numSelections(); ++i )
2245 doc->removeSelection( i ); 2246 doc->removeSelection( i );
2246 2247
2247#ifndef QT_NO_CURSOR 2248#ifndef QT_NO_CURSOR
2248 viewport()->setCursor( isReadOnly() ? arrowCursor : ibeamCursor ); 2249 viewport()->setCursor( isReadOnly() ? arrowCursor : ibeamCursor );
@@ -2252,8 +2253,8 @@ void QTextEdit::undo()
2252 drawCursor( FALSE ); 2253 drawCursor( FALSE );
2253 QTextCursor *c = doc->undo( cursor ); 2254 QTextCursor *c = doc->undo( cursor );
2254 if ( !c ) { 2255 if ( !c ) {
2255 drawCursor( TRUE ); 2256 drawCursor( TRUE );
2256 return; 2257 return;
2257 } 2258 }
2258 lastFormatted = 0; 2259 lastFormatted = 0;
2259 ensureCursorVisible(); 2260 ensureCursorVisible();
@@ -2276,10 +2277,10 @@ void QTextEdit::undo()
2276void QTextEdit::redo() 2277void QTextEdit::redo()
2277{ 2278{
2278 if ( isReadOnly() || !doc->commands()->isRedoAvailable() || !undoEnabled ) 2279 if ( isReadOnly() || !doc->commands()->isRedoAvailable() || !undoEnabled )
2279 return; 2280 return;
2280 2281
2281 for ( int i = 0; i < (int)doc->numSelections(); ++i ) 2282 for ( int i = 0; i < (int)doc->numSelections(); ++i )
2282 doc->removeSelection( i ); 2283 doc->removeSelection( i );
2283 2284
2284#ifndef QT_NO_CURSOR 2285#ifndef QT_NO_CURSOR
2285 viewport()->setCursor( isReadOnly() ? arrowCursor : ibeamCursor ); 2286 viewport()->setCursor( isReadOnly() ? arrowCursor : ibeamCursor );
@@ -2289,8 +2290,8 @@ void QTextEdit::redo()
2289 drawCursor( FALSE ); 2290 drawCursor( FALSE );
2290 QTextCursor *c = doc->redo( cursor ); 2291 QTextCursor *c = doc->redo( cursor );
2291 if ( !c ) { 2292 if ( !c ) {
2292 drawCursor( TRUE ); 2293 drawCursor( TRUE );
2293 return; 2294 return;
2294 } 2295 }
2295 lastFormatted = 0; 2296 lastFormatted = 0;
2296 ensureCursorVisible(); 2297 ensureCursorVisible();
@@ -2315,7 +2316,7 @@ void QTextEdit::paste()
2315{ 2316{
2316#ifndef QT_NO_CLIPBOARD 2317#ifndef QT_NO_CLIPBOARD
2317 if ( isReadOnly() ) 2318 if ( isReadOnly() )
2318 return; 2319 return;
2319 pasteSubType( "plain" ); 2320 pasteSubType( "plain" );
2320 updateMicroFocusHint(); 2321 updateMicroFocusHint();
2321#endif 2322#endif
@@ -2324,7 +2325,7 @@ void QTextEdit::paste()
2324void QTextEdit::checkUndoRedoInfo( UndoRedoInfo::Type t ) 2325void QTextEdit::checkUndoRedoInfo( UndoRedoInfo::Type t )
2325{ 2326{
2326 if ( undoRedoInfo.valid() && t != undoRedoInfo.type ) { 2327 if ( undoRedoInfo.valid() && t != undoRedoInfo.type ) {
2327 clearUndoRedo(); 2328 clearUndoRedo();
2328 } 2329 }
2329 undoRedoInfo.type = t; 2330 undoRedoInfo.type = t;
2330} 2331}
@@ -2338,7 +2339,7 @@ void QTextEdit::checkUndoRedoInfo( UndoRedoInfo::Type t )
2338void QTextEdit::repaintChanged() 2339void QTextEdit::repaintChanged()
2339{ 2340{
2340 if ( !isUpdatesEnabled() || !viewport()->isUpdatesEnabled() ) 2341 if ( !isUpdatesEnabled() || !viewport()->isUpdatesEnabled() )
2341 return; 2342 return;
2342 QPainter p( viewport() ); 2343 QPainter p( viewport() );
2343 p.translate( -contentsX(), -contentsY() ); 2344 p.translate( -contentsX(), -contentsY() );
2344 paintDocument( FALSE, &p, contentsX(), contentsY(), visibleWidth(), visibleHeight() ); 2345 paintDocument( FALSE, &p, contentsX(), contentsY(), visibleWidth(), visibleHeight() );
@@ -2356,13 +2357,13 @@ void QTextEdit::repaintChanged()
2356void QTextEdit::cut() 2357void QTextEdit::cut()
2357{ 2358{
2358 if ( isReadOnly() ) 2359 if ( isReadOnly() )
2359 return; 2360 return;
2360 2361
2361 QString t; 2362 QString t;
2362 if ( doc->hasSelection( QTextDocument::Standard ) && 2363 if ( doc->hasSelection( QTextDocument::Standard ) &&
2363 !( t = doc->selectedText( QTextDocument::Standard, qt_enable_richtext_copy ) ).isEmpty() ) { 2364 !( t = doc->selectedText( QTextDocument::Standard, qt_enable_richtext_copy ) ).isEmpty() ) {
2364 QApplication::clipboard()->setText( t ); 2365 QApplication::clipboard()->setText( t );
2365 removeSelectedText(); 2366 removeSelectedText();
2366 } 2367 }
2367 updateMicroFocusHint(); 2368 updateMicroFocusHint();
2368} 2369}
@@ -2376,8 +2377,8 @@ void QTextEdit::copy()
2376{ 2377{
2377 QString t = doc->selectedText( QTextDocument::Standard, qt_enable_richtext_copy ); 2378 QString t = doc->selectedText( QTextDocument::Standard, qt_enable_richtext_copy );
2378 if ( doc->hasSelection( QTextDocument::Standard ) && 2379 if ( doc->hasSelection( QTextDocument::Standard ) &&
2379 !t.isEmpty() && t.simplifyWhiteSpace() != "<selstart/>" ) 2380 !t.isEmpty() && t.simplifyWhiteSpace() != "<selstart/>" )
2380 QApplication::clipboard()->setText( t ); 2381 QApplication::clipboard()->setText( t );
2381} 2382}
2382 2383
2383/*! 2384/*!
@@ -2387,13 +2388,13 @@ void QTextEdit::copy()
2387void QTextEdit::indent() 2388void QTextEdit::indent()
2388{ 2389{
2389 if ( isReadOnly() ) 2390 if ( isReadOnly() )
2390 return; 2391 return;
2391 2392
2392 drawCursor( FALSE ); 2393 drawCursor( FALSE );
2393 if ( !doc->hasSelection( QTextDocument::Standard ) ) 2394 if ( !doc->hasSelection( QTextDocument::Standard ) )
2394 cursor->indent(); 2395 cursor->indent();
2395 else 2396 else
2396 doc->indentSelection( QTextDocument::Standard ); 2397 doc->indentSelection( QTextDocument::Standard );
2397 repaintChanged(); 2398 repaintChanged();
2398 drawCursor( TRUE ); 2399 drawCursor( TRUE );
2399 setModified(); 2400 setModified();
@@ -2409,13 +2410,13 @@ void QTextEdit::indent()
2409bool QTextEdit::focusNextPrevChild( bool n ) 2410bool QTextEdit::focusNextPrevChild( bool n )
2410{ 2411{
2411 if ( !isReadOnly() || !linksEnabled() ) 2412 if ( !isReadOnly() || !linksEnabled() )
2412 return FALSE; 2413 return FALSE;
2413 bool b = doc->focusNextPrevChild( n ); 2414 bool b = doc->focusNextPrevChild( n );
2414 repaintChanged(); 2415 repaintChanged();
2415 if ( b ) 2416 if ( b )
2416 //##### this does not work with tables. The focusIndicator 2417 //##### this does not work with tables. The focusIndicator
2417 //should really be a QTextCursor. Fix 3.1 2418 //should really be a QTextCursor. Fix 3.1
2418 makeParagVisible( doc->focusIndicator.parag ); 2419 makeParagVisible( doc->focusIndicator.parag );
2419 return b; 2420 return b;
2420} 2421}
2421 2422
@@ -2429,47 +2430,47 @@ bool QTextEdit::focusNextPrevChild( bool n )
2429void QTextEdit::setFormat( QTextFormat *f, int flags ) 2430void QTextEdit::setFormat( QTextFormat *f, int flags )
2430{ 2431{
2431 if ( doc->hasSelection( QTextDocument::Standard ) ) { 2432 if ( doc->hasSelection( QTextDocument::Standard ) ) {
2432 drawCursor( FALSE ); 2433 drawCursor( FALSE );
2433 QTextCursor c1 = doc->selectionStartCursor( QTextDocument::Standard ); 2434 QTextCursor c1 = doc->selectionStartCursor( QTextDocument::Standard );
2434 c1.restoreState(); 2435 c1.restoreState();
2435 QTextCursor c2 = doc->selectionEndCursor( QTextDocument::Standard ); 2436 QTextCursor c2 = doc->selectionEndCursor( QTextDocument::Standard );
2436 c2.restoreState(); 2437 c2.restoreState();
2437 clearUndoRedo(); 2438 clearUndoRedo();
2438 undoRedoInfo.type = UndoRedoInfo::Format; 2439 undoRedoInfo.type = UndoRedoInfo::Format;
2439 undoRedoInfo.id = c1.paragraph()->paragId(); 2440 undoRedoInfo.id = c1.paragraph()->paragId();
2440 undoRedoInfo.index = c1.index(); 2441 undoRedoInfo.index = c1.index();
2441 undoRedoInfo.eid = c2.paragraph()->paragId(); 2442 undoRedoInfo.eid = c2.paragraph()->paragId();
2442 undoRedoInfo.eindex = c2.index(); 2443 undoRedoInfo.eindex = c2.index();
2443 readFormats( c1, c2, undoRedoInfo.d->text ); 2444 readFormats( c1, c2, undoRedoInfo.d->text );
2444 undoRedoInfo.format = f; 2445 undoRedoInfo.format = f;
2445 undoRedoInfo.flags = flags; 2446 undoRedoInfo.flags = flags;
2446 clearUndoRedo(); 2447 clearUndoRedo();
2447 doc->setFormat( QTextDocument::Standard, f, flags ); 2448 doc->setFormat( QTextDocument::Standard, f, flags );
2448 repaintChanged(); 2449 repaintChanged();
2449 formatMore(); 2450 formatMore();
2450 drawCursor( TRUE ); 2451 drawCursor( TRUE );
2451 setModified(); 2452 setModified();
2452 emit textChanged(); 2453 emit textChanged();
2453 } 2454 }
2454 if ( currentFormat && currentFormat->key() != f->key() ) { 2455 if ( currentFormat && currentFormat->key() != f->key() ) {
2455 currentFormat->removeRef(); 2456 currentFormat->removeRef();
2456 currentFormat = doc->formatCollection()->format( f ); 2457 currentFormat = doc->formatCollection()->format( f );
2457 if ( currentFormat->isMisspelled() ) { 2458 if ( currentFormat->isMisspelled() ) {
2458 currentFormat->removeRef(); 2459 currentFormat->removeRef();
2459 currentFormat = doc->formatCollection()->format( currentFormat->font(), currentFormat->color() ); 2460 currentFormat = doc->formatCollection()->format( currentFormat->font(), currentFormat->color() );
2460 } 2461 }
2461 emit currentFontChanged( currentFormat->font() ); 2462 emit currentFontChanged( currentFormat->font() );
2462 emit currentColorChanged( currentFormat->color() ); 2463 emit currentColorChanged( currentFormat->color() );
2463 emit currentVerticalAlignmentChanged( (VerticalAlignment)currentFormat->vAlign() ); 2464 emit currentVerticalAlignmentChanged( (VerticalAlignment)currentFormat->vAlign() );
2464 if ( cursor->index() == cursor->paragraph()->length() - 1 ) { 2465 if ( cursor->index() == cursor->paragraph()->length() - 1 ) {
2465 currentFormat->addRef(); 2466 currentFormat->addRef();
2466 cursor->paragraph()->string()->setFormat( cursor->index(), currentFormat, TRUE ); 2467 cursor->paragraph()->string()->setFormat( cursor->index(), currentFormat, TRUE );
2467 if ( cursor->paragraph()->length() == 1 ) { 2468 if ( cursor->paragraph()->length() == 1 ) {
2468 cursor->paragraph()->invalidate( 0 ); 2469 cursor->paragraph()->invalidate( 0 );
2469 cursor->paragraph()->format(); 2470 cursor->paragraph()->format();
2470 repaintChanged(); 2471 repaintChanged();
2471 } 2472 }
2472 } 2473 }
2473 } 2474 }
2474} 2475}
2475 2476
@@ -2479,9 +2480,9 @@ void QTextEdit::setPalette( const QPalette &p )
2479{ 2480{
2480 QScrollView::setPalette( p ); 2481 QScrollView::setPalette( p );
2481 if ( textFormat() == PlainText ) { 2482 if ( textFormat() == PlainText ) {
2482 QTextFormat *f = doc->formatCollection()->defaultFormat(); 2483 QTextFormat *f = doc->formatCollection()->defaultFormat();
2483 f->setColor( colorGroup().text() ); 2484 f->setColor( colorGroup().text() );
2484 updateContents( contentsX(), contentsY(), visibleWidth(), visibleHeight() ); 2485 updateContents( contentsX(), contentsY(), visibleWidth(), visibleHeight() );
2485 } 2486 }
2486} 2487}
2487 2488
@@ -2501,16 +2502,16 @@ void QTextEdit::setPalette( const QPalette &p )
2501void QTextEdit::setParagType( QStyleSheetItem::DisplayMode dm, QStyleSheetItem::ListStyle listStyle ) 2502void QTextEdit::setParagType( QStyleSheetItem::DisplayMode dm, QStyleSheetItem::ListStyle listStyle )
2502{ 2503{
2503 if ( isReadOnly() ) 2504 if ( isReadOnly() )
2504 return; 2505 return;
2505 2506
2506 drawCursor( FALSE ); 2507 drawCursor( FALSE );
2507 QTextParagraph *start = cursor->paragraph(); 2508 QTextParagraph *start = cursor->paragraph();
2508 QTextParagraph *end = start; 2509 QTextParagraph *end = start;
2509 if ( doc->hasSelection( QTextDocument::Standard ) ) { 2510 if ( doc->hasSelection( QTextDocument::Standard ) ) {
2510 start = doc->selectionStartCursor( QTextDocument::Standard ).topParagraph(); 2511 start = doc->selectionStartCursor( QTextDocument::Standard ).topParagraph();
2511 end = doc->selectionEndCursor( QTextDocument::Standard ).topParagraph(); 2512 end = doc->selectionEndCursor( QTextDocument::Standard ).topParagraph();
2512 if ( end->paragId() < start->paragId() ) 2513 if ( end->paragId() < start->paragId() )
2513 return; // do not trust our selections 2514 return; // do not trust our selections
2514 } 2515 }
2515 2516
2516 clearUndoRedo(); 2517 clearUndoRedo();
@@ -2520,16 +2521,16 @@ void QTextEdit::setParagType( QStyleSheetItem::DisplayMode dm, QStyleSheetItem::
2520 undoRedoInfo.styleInformation = QTextStyleCommand::readStyleInformation( doc, undoRedoInfo.id, undoRedoInfo.eid ); 2521 undoRedoInfo.styleInformation = QTextStyleCommand::readStyleInformation( doc, undoRedoInfo.id, undoRedoInfo.eid );
2521 2522
2522 while ( start != end->next() ) { 2523 while ( start != end->next() ) {
2523 start->setListStyle( listStyle ); 2524 start->setListStyle( listStyle );
2524 if ( dm == QStyleSheetItem::DisplayListItem ) { 2525 if ( dm == QStyleSheetItem::DisplayListItem ) {
2525 start->setListItem( TRUE ); 2526 start->setListItem( TRUE );
2526 if( start->listDepth() == 0 ) 2527 if( start->listDepth() == 0 )
2527 start->setListDepth( 1 ); 2528 start->setListDepth( 1 );
2528 } else if ( start->isListItem() ) { 2529 } else if ( start->isListItem() ) {
2529 start->setListItem( FALSE ); 2530 start->setListItem( FALSE );
2530 start->setListDepth( QMAX( start->listDepth()-1, 0 ) ); 2531 start->setListDepth( QMAX( start->listDepth()-1, 0 ) );
2531 } 2532 }
2532 start = start->next(); 2533 start = start->next();
2533 } 2534 }
2534 2535
2535 clearUndoRedo(); 2536 clearUndoRedo();
@@ -2550,16 +2551,16 @@ void QTextEdit::setParagType( QStyleSheetItem::DisplayMode dm, QStyleSheetItem::
2550void QTextEdit::setAlignment( int a ) 2551void QTextEdit::setAlignment( int a )
2551{ 2552{
2552 if ( isReadOnly() || block_set_alignment ) 2553 if ( isReadOnly() || block_set_alignment )
2553 return; 2554 return;
2554 2555
2555 drawCursor( FALSE ); 2556 drawCursor( FALSE );
2556 QTextParagraph *start = cursor->paragraph(); 2557 QTextParagraph *start = cursor->paragraph();
2557 QTextParagraph *end = start; 2558 QTextParagraph *end = start;
2558 if ( doc->hasSelection( QTextDocument::Standard ) ) { 2559 if ( doc->hasSelection( QTextDocument::Standard ) ) {
2559 start = doc->selectionStartCursor( QTextDocument::Standard ).topParagraph(); 2560 start = doc->selectionStartCursor( QTextDocument::Standard ).topParagraph();
2560 end = doc->selectionEndCursor( QTextDocument::Standard ).topParagraph(); 2561 end = doc->selectionEndCursor( QTextDocument::Standard ).topParagraph();
2561 if ( end->paragId() < start->paragId() ) 2562 if ( end->paragId() < start->paragId() )
2562 return; // do not trust our selections 2563 return; // do not trust our selections
2563 } 2564 }
2564 2565
2565 clearUndoRedo(); 2566 clearUndoRedo();
@@ -2569,8 +2570,8 @@ void QTextEdit::setAlignment( int a )
2569 undoRedoInfo.styleInformation = QTextStyleCommand::readStyleInformation( doc, undoRedoInfo.id, undoRedoInfo.eid ); 2570 undoRedoInfo.styleInformation = QTextStyleCommand::readStyleInformation( doc, undoRedoInfo.id, undoRedoInfo.eid );
2570 2571
2571 while ( start != end->next() ) { 2572 while ( start != end->next() ) {
2572 start->setAlignment( a ); 2573 start->setAlignment( a );
2573 start = start->next(); 2574 start = start->next();
2574 } 2575 }
2575 2576
2576 clearUndoRedo(); 2577 clearUndoRedo();
@@ -2578,8 +2579,8 @@ void QTextEdit::setAlignment( int a )
2578 formatMore(); 2579 formatMore();
2579 drawCursor( TRUE ); 2580 drawCursor( TRUE );
2580 if ( currentAlignment != a ) { 2581 if ( currentAlignment != a ) {
2581 currentAlignment = a; 2582 currentAlignment = a;
2582 emit currentAlignmentChanged( currentAlignment ); 2583 emit currentAlignmentChanged( currentAlignment );
2583 } 2584 }
2584 setModified(); 2585 setModified();
2585 emit textChanged(); 2586 emit textChanged();
@@ -2589,26 +2590,26 @@ void QTextEdit::updateCurrentFormat()
2589{ 2590{
2590 int i = cursor->index(); 2591 int i = cursor->index();
2591 if ( i > 0 ) 2592 if ( i > 0 )
2592 --i; 2593 --i;
2593 if ( doc->useFormatCollection() && 2594 if ( doc->useFormatCollection() &&
2594 ( !currentFormat || currentFormat->key() != cursor->paragraph()->at( i )->format()->key() ) ) { 2595 ( !currentFormat || currentFormat->key() != cursor->paragraph()->at( i )->format()->key() ) ) {
2595 if ( currentFormat ) 2596 if ( currentFormat )
2596 currentFormat->removeRef(); 2597 currentFormat->removeRef();
2597 currentFormat = doc->formatCollection()->format( cursor->paragraph()->at( i )->format() ); 2598 currentFormat = doc->formatCollection()->format( cursor->paragraph()->at( i )->format() );
2598 if ( currentFormat->isMisspelled() ) { 2599 if ( currentFormat->isMisspelled() ) {
2599 currentFormat->removeRef(); 2600 currentFormat->removeRef();
2600 currentFormat = doc->formatCollection()->format( currentFormat->font(), currentFormat->color() ); 2601 currentFormat = doc->formatCollection()->format( currentFormat->font(), currentFormat->color() );
2601 } 2602 }
2602 emit currentFontChanged( currentFormat->font() ); 2603 emit currentFontChanged( currentFormat->font() );
2603 emit currentColorChanged( currentFormat->color() ); 2604 emit currentColorChanged( currentFormat->color() );
2604 emit currentVerticalAlignmentChanged( (VerticalAlignment)currentFormat->vAlign() ); 2605 emit currentVerticalAlignmentChanged( (VerticalAlignment)currentFormat->vAlign() );
2605 } 2606 }
2606 2607
2607 if ( currentAlignment != cursor->paragraph()->alignment() ) { 2608 if ( currentAlignment != cursor->paragraph()->alignment() ) {
2608 currentAlignment = cursor->paragraph()->alignment(); 2609 currentAlignment = cursor->paragraph()->alignment();
2609 block_set_alignment = TRUE; 2610 block_set_alignment = TRUE;
2610 emit currentAlignmentChanged( currentAlignment ); 2611 emit currentAlignmentChanged( currentAlignment );
2611 block_set_alignment = FALSE; 2612 block_set_alignment = FALSE;
2612 } 2613 }
2613} 2614}
2614 2615
@@ -2728,7 +2729,7 @@ void QTextEdit::setFontInternal( const QFont &f_ )
2728QString QTextEdit::text() const 2729QString QTextEdit::text() const
2729{ 2730{
2730 if ( isReadOnly() ) 2731 if ( isReadOnly() )
2731 return doc->originalText(); 2732 return doc->originalText();
2732 return doc->text(); 2733 return doc->text();
2733} 2734}
2734 2735
@@ -2768,8 +2769,8 @@ QString QTextEdit::text( int para ) const
2768void QTextEdit::setText( const QString &text, const QString &context ) 2769void QTextEdit::setText( const QString &text, const QString &context )
2769{ 2770{
2770 if ( !isModified() && isReadOnly() && 2771 if ( !isModified() && isReadOnly() &&
2771 this->context() == context && this->text() == text ) 2772 this->context() == context && this->text() == text )
2772 return; 2773 return;
2773 2774
2774 emit undoAvailable( FALSE ); 2775 emit undoAvailable( FALSE );
2775 emit redoAvailable( FALSE ); 2776 emit redoAvailable( FALSE );
@@ -2781,12 +2782,12 @@ void QTextEdit::setText( const QString &text, const QString &context )
2781 doc->setText( text, context ); 2782 doc->setText( text, context );
2782 2783
2783 if ( wrapMode == FixedPixelWidth ) { 2784 if ( wrapMode == FixedPixelWidth ) {
2784 resizeContents( wrapWidth, 0 ); 2785 resizeContents( wrapWidth, 0 );
2785 doc->setWidth( wrapWidth ); 2786 doc->setWidth( wrapWidth );
2786 doc->setMinimumWidth( wrapWidth ); 2787 doc->setMinimumWidth( wrapWidth );
2787 } else { 2788 } else {
2788 doc->setMinimumWidth( -1 ); 2789 doc->setMinimumWidth( -1 );
2789 resizeContents( 0, 0 ); 2790 resizeContents( 0, 0 );
2790 } 2791 }
2791 2792
2792 lastFormatted = doc->firstParagraph(); 2793 lastFormatted = doc->firstParagraph();
@@ -2795,7 +2796,7 @@ void QTextEdit::setText( const QString &text, const QString &context )
2795 updateContents( contentsX(), contentsY(), visibleWidth(), visibleHeight() ); 2796 updateContents( contentsX(), contentsY(), visibleWidth(), visibleHeight() );
2796 2797
2797 if ( isModified() ) 2798 if ( isModified() )
2798 setModified( FALSE ); 2799 setModified( FALSE );
2799 emit textChanged(); 2800 emit textChanged();
2800 formatMore(); 2801 formatMore();
2801 updateCurrentFormat(); 2802 updateCurrentFormat();
@@ -2860,7 +2861,7 @@ void QTextEdit::setText( const QString &text, const QString &context )
2860*/ 2861*/
2861 2862
2862bool QTextEdit::find( const QString &expr, bool cs, bool wo, bool forward, 2863bool QTextEdit::find( const QString &expr, bool cs, bool wo, bool forward,
2863 int *para, int *index ) 2864 int *para, int *index )
2864{ 2865{
2865 drawCursor( FALSE ); 2866 drawCursor( FALSE );
2866#ifndef QT_NO_CURSOR 2867#ifndef QT_NO_CURSOR
@@ -2868,27 +2869,27 @@ bool QTextEdit::find( const QString &expr, bool cs, bool wo, bool forward,
2868#endif 2869#endif
2869 QTextCursor findcur = *cursor; 2870 QTextCursor findcur = *cursor;
2870 if ( para && index ) { 2871 if ( para && index ) {
2871 if ( doc->paragAt( *para ) ) 2872 if ( doc->paragAt( *para ) )
2872 findcur.gotoPosition( doc->paragAt(*para), *index ); 2873 findcur.gotoPosition( doc->paragAt(*para), *index );
2873 else 2874 else
2874 findcur.gotoEnd(); 2875 findcur.gotoEnd();
2875 } else if ( doc->hasSelection( QTextDocument::Standard ) ){ 2876 } else if ( doc->hasSelection( QTextDocument::Standard ) ){
2876 // maks sure we do not find the same selection again 2877 // maks sure we do not find the same selection again
2877 if ( forward ) 2878 if ( forward )
2878 findcur.gotoNextLetter(); 2879 findcur.gotoNextLetter();
2879 else 2880 else
2880 findcur.gotoPreviousLetter(); 2881 findcur.gotoPreviousLetter();
2881 } 2882 }
2882 removeSelection( QTextDocument::Standard ); 2883 removeSelection( QTextDocument::Standard );
2883 bool found = doc->find( findcur, expr, cs, wo, forward ); 2884 bool found = doc->find( findcur, expr, cs, wo, forward );
2884 if ( found ) { 2885 if ( found ) {
2885 if ( para ) 2886 if ( para )
2886 *para = findcur.paragraph()->paragId(); 2887 *para = findcur.paragraph()->paragId();
2887 if ( index ) 2888 if ( index )
2888 *index = findcur.index(); 2889 *index = findcur.index();
2889 *cursor = findcur; 2890 *cursor = findcur;
2890 repaintChanged(); 2891 repaintChanged();
2891 ensureCursorVisible(); 2892 ensureCursorVisible();
2892 } 2893 }
2893 drawCursor( TRUE ); 2894 drawCursor( TRUE );
2894 return found; 2895 return found;
@@ -2897,7 +2898,7 @@ bool QTextEdit::find( const QString &expr, bool cs, bool wo, bool forward,
2897void QTextEdit::blinkCursor() 2898void QTextEdit::blinkCursor()
2898{ 2899{
2899 if ( !cursorVisible ) 2900 if ( !cursorVisible )
2900 return; 2901 return;
2901 bool cv = cursorVisible; 2902 bool cv = cursorVisible;
2902 blinkCursorVisible = !blinkCursorVisible; 2903 blinkCursorVisible = !blinkCursorVisible;
2903 drawCursor( blinkCursorVisible ); 2904 drawCursor( blinkCursorVisible );
@@ -2914,10 +2915,10 @@ void QTextEdit::setCursorPosition( int para, int index )
2914{ 2915{
2915 QTextParagraph *p = doc->paragAt( para ); 2916 QTextParagraph *p = doc->paragAt( para );
2916 if ( !p ) 2917 if ( !p )
2917 return; 2918 return;
2918 2919
2919 if ( index > p->length() - 1 ) 2920 if ( index > p->length() - 1 )
2920 index = p->length() - 1; 2921 index = p->length() - 1;
2921 2922
2922 drawCursor( FALSE ); 2923 drawCursor( FALSE );
2923 cursor->setParagraph( p ); 2924 cursor->setParagraph( p );
@@ -2940,7 +2941,7 @@ void QTextEdit::setCursorPosition( int para, int index )
2940void QTextEdit::getCursorPosition( int *para, int *index ) const 2941void QTextEdit::getCursorPosition( int *para, int *index ) const
2941{ 2942{
2942 if ( !para || !index ) 2943 if ( !para || !index )
2943 return; 2944 return;
2944 *para = cursor->paragraph()->paragId(); 2945 *para = cursor->paragraph()->paragId();
2945 *index = cursor->index(); 2946 *index = cursor->index();
2946} 2947}
@@ -2961,25 +2962,25 @@ void QTextEdit::getCursorPosition( int *para, int *index ) const
2961*/ 2962*/
2962 2963
2963void QTextEdit::setSelection( int paraFrom, int indexFrom, 2964void QTextEdit::setSelection( int paraFrom, int indexFrom,
2964 int paraTo, int indexTo, int selNum ) 2965 int paraTo, int indexTo, int selNum )
2965{ 2966{
2966 if ( doc->hasSelection( selNum ) ) { 2967 if ( doc->hasSelection( selNum ) ) {
2967 doc->removeSelection( selNum ); 2968 doc->removeSelection( selNum );
2968 repaintChanged(); 2969 repaintChanged();
2969 } 2970 }
2970 if ( selNum > doc->numSelections() - 1 ) 2971 if ( selNum > doc->numSelections() - 1 )
2971 doc->addSelection( selNum ); 2972 doc->addSelection( selNum );
2972 QTextParagraph *p1 = doc->paragAt( paraFrom ); 2973 QTextParagraph *p1 = doc->paragAt( paraFrom );
2973 if ( !p1 ) 2974 if ( !p1 )
2974 return; 2975 return;
2975 QTextParagraph *p2 = doc->paragAt( paraTo ); 2976 QTextParagraph *p2 = doc->paragAt( paraTo );
2976 if ( !p2 ) 2977 if ( !p2 )
2977 return; 2978 return;
2978 2979
2979 if ( indexFrom > p1->length() - 1 ) 2980 if ( indexFrom > p1->length() - 1 )
2980 indexFrom = p1->length() - 1; 2981 indexFrom = p1->length() - 1;
2981 if ( indexTo > p2->length() - 1 ) 2982 if ( indexTo > p2->length() - 1 )
2982 indexTo = p2->length() - 1; 2983 indexTo = p2->length() - 1;
2983 2984
2984 drawCursor( FALSE ); 2985 drawCursor( FALSE );
2985 QTextCursor c = *cursor; 2986 QTextCursor c = *cursor;
@@ -2993,7 +2994,7 @@ void QTextEdit::setSelection( int paraFrom, int indexFrom,
2993 repaintChanged(); 2994 repaintChanged();
2994 ensureCursorVisible(); 2995 ensureCursorVisible();
2995 if ( selNum != QTextDocument::Standard ) 2996 if ( selNum != QTextDocument::Standard )
2996 *cursor = oldCursor; 2997 *cursor = oldCursor;
2997 drawCursor( TRUE ); 2998 drawCursor( TRUE );
2998} 2999}
2999 3000
@@ -3018,16 +3019,16 @@ void QTextEdit::setSelection( int paraFrom, int indexFrom,
3018*/ 3019*/
3019 3020
3020void QTextEdit::getSelection( int *paraFrom, int *indexFrom, 3021void QTextEdit::getSelection( int *paraFrom, int *indexFrom,
3021 int *paraTo, int *indexTo, int selNum ) const 3022 int *paraTo, int *indexTo, int selNum ) const
3022{ 3023{
3023 if ( !paraFrom || !paraTo || !indexFrom || !indexTo ) 3024 if ( !paraFrom || !paraTo || !indexFrom || !indexTo )
3024 return; 3025 return;
3025 if ( !doc->hasSelection( selNum ) ) { 3026 if ( !doc->hasSelection( selNum ) ) {
3026 *paraFrom = -1; 3027 *paraFrom = -1;
3027 *indexFrom = -1; 3028 *indexFrom = -1;
3028 *paraTo = -1; 3029 *paraTo = -1;
3029 *indexTo = -1; 3030 *indexTo = -1;
3030 return; 3031 return;
3031 } 3032 }
3032 3033
3033 doc->selectionStart( selNum, *paraFrom, *indexFrom ); 3034 doc->selectionStart( selNum, *paraFrom, *indexFrom );
@@ -3079,7 +3080,7 @@ int QTextEdit::linesOfParagraph( int para ) const
3079{ 3080{
3080 QTextParagraph *p = doc->paragAt( para ); 3081 QTextParagraph *p = doc->paragAt( para );
3081 if ( !p ) 3082 if ( !p )
3082 return -1; 3083 return -1;
3083 return p->lines(); 3084 return p->lines();
3084} 3085}
3085 3086
@@ -3092,7 +3093,7 @@ int QTextEdit::paragraphLength( int para ) const
3092{ 3093{
3093 QTextParagraph *p = doc->paragAt( para ); 3094 QTextParagraph *p = doc->paragAt( para );
3094 if ( !p ) 3095 if ( !p )
3095 return -1; 3096 return -1;
3096 return p->length() - 1; 3097 return p->length() - 1;
3097} 3098}
3098 3099
@@ -3109,8 +3110,8 @@ int QTextEdit::lines() const
3109 QTextParagraph *p = doc->firstParagraph(); 3110 QTextParagraph *p = doc->firstParagraph();
3110 int l = 0; 3111 int l = 0;
3111 while ( p ) { 3112 while ( p ) {
3112 l += p->lines(); 3113 l += p->lines();
3113 p = p->next(); 3114 p = p->next();
3114 } 3115 }
3115 3116
3116 return l; 3117 return l;
@@ -3128,12 +3129,12 @@ int QTextEdit::lineOfChar( int para, int index )
3128{ 3129{
3129 QTextParagraph *p = doc->paragAt( para ); 3130 QTextParagraph *p = doc->paragAt( para );
3130 if ( !p ) 3131 if ( !p )
3131 return -1; 3132 return -1;
3132 3133
3133 int idx, line; 3134 int idx, line;
3134 QTextStringChar *c = p->lineStartOfChar( index, &idx, &line ); 3135 QTextStringChar *c = p->lineStartOfChar( index, &idx, &line );
3135 if ( !c ) 3136 if ( !c )
3136 return -1; 3137 return -1;
3137 3138
3138 return line; 3139 return line;
3139} 3140}
@@ -3143,9 +3144,9 @@ void QTextEdit::setModified( bool m )
3143 bool oldModified = modified; 3144 bool oldModified = modified;
3144 modified = m; 3145 modified = m;
3145 if ( modified && doc->oTextValid ) 3146 if ( modified && doc->oTextValid )
3146 doc->invalidateOriginalText(); 3147 doc->invalidateOriginalText();
3147 if ( oldModified != modified ) 3148 if ( oldModified != modified )
3148 emit modificationChanged( modified ); 3149 emit modificationChanged( modified );
3149} 3150}
3150 3151
3151/*! \property QTextEdit::modified 3152/*! \property QTextEdit::modified
@@ -3160,7 +3161,7 @@ bool QTextEdit::isModified() const
3160void QTextEdit::setModified() 3161void QTextEdit::setModified()
3161{ 3162{
3162 if ( !isModified() ) 3163 if ( !isModified() )
3163 setModified( TRUE ); 3164 setModified( TRUE );
3164} 3165}
3165 3166
3166/*! 3167/*!
@@ -3261,10 +3262,10 @@ void QTextEdit::startDrag()
3261 inDoubleClick = FALSE; 3262 inDoubleClick = FALSE;
3262 QDragObject *drag = new QTextDrag( doc->selectedText( QTextDocument::Standard, qt_enable_richtext_copy ), viewport() ); 3263 QDragObject *drag = new QTextDrag( doc->selectedText( QTextDocument::Standard, qt_enable_richtext_copy ), viewport() );
3263 if ( isReadOnly() ) { 3264 if ( isReadOnly() ) {
3264 drag->dragCopy(); 3265 drag->dragCopy();
3265 } else { 3266 } else {
3266 if ( drag->drag() && QDragObject::target() != this && QDragObject::target() != viewport() ) 3267 if ( drag->drag() && QDragObject::target() != this && QDragObject::target() != viewport() )
3267 removeSelectedText(); 3268 removeSelectedText();
3268 } 3269 }
3269#endif 3270#endif
3270} 3271}
@@ -3281,9 +3282,9 @@ void QTextEdit::startDrag()
3281void QTextEdit::selectAll( bool select ) 3282void QTextEdit::selectAll( bool select )
3282{ 3283{
3283 if ( !select ) 3284 if ( !select )
3284 doc->removeSelection( QTextDocument::Standard ); 3285 doc->removeSelection( QTextDocument::Standard );
3285 else 3286 else
3286 doc->selectAll( QTextDocument::Standard ); 3287 doc->selectAll( QTextDocument::Standard );
3287 repaintChanged(); 3288 repaintChanged();
3288 emit copyAvailable( doc->hasSelection( QTextDocument::Standard ) ); 3289 emit copyAvailable( doc->hasSelection( QTextDocument::Standard ) );
3289 emit selectionChanged(); 3290 emit selectionChanged();
@@ -3295,15 +3296,15 @@ void QTextEdit::selectAll( bool select )
3295void QTextEdit::UndoRedoInfo::clear() 3296void QTextEdit::UndoRedoInfo::clear()
3296{ 3297{
3297 if ( valid() ) { 3298 if ( valid() ) {
3298 if ( type == Insert || type == Return ) 3299 if ( type == Insert || type == Return )
3299 doc->addCommand( new QTextInsertCommand( doc, id, index, d->text.rawData(), styleInformation ) ); 3300 doc->addCommand( new QTextInsertCommand( doc, id, index, d->text.rawData(), styleInformation ) );
3300 else if ( type == Format ) 3301 else if ( type == Format )
3301 doc->addCommand( new QTextFormatCommand( doc, id, index, eid, eindex, d->text.rawData(), format, flags ) ); 3302 doc->addCommand( new QTextFormatCommand( doc, id, index, eid, eindex, d->text.rawData(), format, flags ) );
3302 else if ( type == Style ) 3303 else if ( type == Style )
3303 doc->addCommand( new QTextStyleCommand( doc, id, eid, styleInformation ) ); 3304 doc->addCommand( new QTextStyleCommand( doc, id, eid, styleInformation ) );
3304 else if ( type != Invalid ) { 3305 else if ( type != Invalid ) {
3305 doc->addCommand( new QTextDeleteCommand( doc, id, index, d->text.rawData(), styleInformation ) ); 3306 doc->addCommand( new QTextDeleteCommand( doc, id, index, d->text.rawData(), styleInformation ) );
3306 } 3307 }
3307 } 3308 }
3308 type = Invalid; 3309 type = Invalid;
3309 d->text = QString::null; 3310 d->text = QString::null;
@@ -3325,8 +3326,8 @@ void QTextEdit::UndoRedoInfo::clear()
3325void QTextEdit::del() 3326void QTextEdit::del()
3326{ 3327{
3327 if ( doc->hasSelection( QTextDocument::Standard ) ) { 3328 if ( doc->hasSelection( QTextDocument::Standard ) ) {
3328 removeSelectedText(); 3329 removeSelectedText();
3329 return; 3330 return;
3330 } 3331 }
3331 3332
3332 doKeyboardAction( ActionDelete ); 3333 doKeyboardAction( ActionDelete );
@@ -3404,7 +3405,7 @@ void QTextEdit::setPaper( const QBrush& pap )
3404QBrush QTextEdit::paper() const 3405QBrush QTextEdit::paper() const
3405{ 3406{
3406 if ( doc->paper() ) 3407 if ( doc->paper() )
3407 return *doc->paper(); 3408 return *doc->paper();
3408 return QBrush(); 3409 return QBrush();
3409} 3410}
3410 3411
@@ -3477,10 +3478,10 @@ void QTextEdit::append( const QString &text )
3477 doc->removeSelection( QTextDocument::Standard ); 3478 doc->removeSelection( QTextDocument::Standard );
3478 TextFormat f = doc->textFormat(); 3479 TextFormat f = doc->textFormat();
3479 if ( f == AutoText ) { 3480 if ( f == AutoText ) {
3480 if ( QStyleSheet::mightBeRichText( text ) ) 3481 if ( QStyleSheet::mightBeRichText( text ) )
3481 f = RichText; 3482 f = RichText;
3482 else 3483 else
3483 f = PlainText; 3484 f = PlainText;
3484 } 3485 }
3485 3486
3486 drawCursor( FALSE ); 3487 drawCursor( FALSE );
@@ -3489,22 +3490,22 @@ void QTextEdit::append( const QString &text )
3489 bool atBottom = contentsY() >= contentsHeight() - visibleHeight(); 3490 bool atBottom = contentsY() >= contentsHeight() - visibleHeight();
3490 cursor->gotoEnd(); 3491 cursor->gotoEnd();
3491 if ( cursor->index() > 0 ) 3492 if ( cursor->index() > 0 )
3492 cursor->splitAndInsertEmptyParagraph(); 3493 cursor->splitAndInsertEmptyParagraph();
3493 QTextCursor oldCursor2 = *cursor; 3494 QTextCursor oldCursor2 = *cursor;
3494 3495
3495 if ( f == Qt::PlainText ) { 3496 if ( f == Qt::PlainText ) {
3496 cursor->insert( text, TRUE ); 3497 cursor->insert( text, TRUE );
3497 if ( doc->useFormatCollection() && 3498 if ( doc->useFormatCollection() &&
3498 currentFormat != cursor->paragraph()->at( cursor->index() )->format() ) { 3499 currentFormat != cursor->paragraph()->at( cursor->index() )->format() ) {
3499 doc->setSelectionStart( QTextDocument::Temp, oldCursor2 ); 3500 doc->setSelectionStart( QTextDocument::Temp, oldCursor2 );
3500 doc->setSelectionEnd( QTextDocument::Temp, *cursor ); 3501 doc->setSelectionEnd( QTextDocument::Temp, *cursor );
3501 doc->setFormat( QTextDocument::Temp, currentFormat, QTextFormat::Format ); 3502 doc->setFormat( QTextDocument::Temp, currentFormat, QTextFormat::Format );
3502 doc->removeSelection( QTextDocument::Temp ); 3503 doc->removeSelection( QTextDocument::Temp );
3503 } 3504 }
3504 } else { 3505 } else {
3505 if ( cursor->paragraph()->prev() ) 3506 if ( cursor->paragraph()->prev() )
3506 cursor->paragraph()->prev()->invalidate(0); // vertical margins might have to change 3507 cursor->paragraph()->prev()->invalidate(0); // vertical margins might have to change
3507 doc->setRichTextInternal( text ); 3508 doc->setRichTextInternal( text );
3508 } 3509 }
3509 formatMore(); 3510 formatMore();
3510 repaintChanged(); 3511 repaintChanged();
@@ -3512,7 +3513,7 @@ void QTextEdit::append( const QString &text )
3512 scrollToBottom(); 3513 scrollToBottom();
3513 *cursor = oldc; 3514 *cursor = oldc;
3514 if ( !isReadOnly() ) 3515 if ( !isReadOnly() )
3515 cursorVisible = TRUE; 3516 cursorVisible = TRUE;
3516 setModified(); 3517 setModified();
3517 emit textChanged(); 3518 emit textChanged();
3518} 3519}
@@ -3546,54 +3547,54 @@ bool QTextEdit::handleReadOnlyKeyEvent( QKeyEvent *e )
3546{ 3547{
3547 switch( e->key() ) { 3548 switch( e->key() ) {
3548 case Key_Down: 3549 case Key_Down:
3549 setContentsPos( contentsX(), contentsY() + 10 ); 3550 setContentsPos( contentsX(), contentsY() + 10 );
3550 break; 3551 break;
3551 case Key_Up: 3552 case Key_Up:
3552 setContentsPos( contentsX(), contentsY() - 10 ); 3553 setContentsPos( contentsX(), contentsY() - 10 );
3553 break; 3554 break;
3554 case Key_Left: 3555 case Key_Left:
3555 setContentsPos( contentsX() - 10, contentsY() ); 3556 setContentsPos( contentsX() - 10, contentsY() );
3556 break; 3557 break;
3557 case Key_Right: 3558 case Key_Right:
3558 setContentsPos( contentsX() + 10, contentsY() ); 3559 setContentsPos( contentsX() + 10, contentsY() );
3559 break; 3560 break;
3560 case Key_PageUp: 3561 case Key_PageUp:
3561 setContentsPos( contentsX(), contentsY() - visibleHeight() ); 3562 setContentsPos( contentsX(), contentsY() - visibleHeight() );
3562 break; 3563 break;
3563 case Key_PageDown: 3564 case Key_PageDown:
3564 setContentsPos( contentsX(), contentsY() + visibleHeight() ); 3565 setContentsPos( contentsX(), contentsY() + visibleHeight() );
3565 break; 3566 break;
3566 case Key_Home: 3567 case Key_Home:
3567 setContentsPos( contentsX(), 0 ); 3568 setContentsPos( contentsX(), 0 );
3568 break; 3569 break;
3569 case Key_End: 3570 case Key_End:
3570 setContentsPos( contentsX(), contentsHeight() - visibleHeight() ); 3571 setContentsPos( contentsX(), contentsHeight() - visibleHeight() );
3571 break; 3572 break;
3572 case Key_F16: // Copy key on Sun keyboards 3573 case Key_F16: // Copy key on Sun keyboards
3573 copy(); 3574 copy();
3574 break; 3575 break;
3575#ifndef QT_NO_NETWORKPROTOCOL 3576#ifndef QT_NO_NETWORKPROTOCOL
3576 case Key_Return: 3577 case Key_Return:
3577 case Key_Enter: 3578 case Key_Enter:
3578 case Key_Space: { 3579 case Key_Space: {
3579 if ( !doc->focusIndicator.href.isEmpty() ) { 3580 if ( !doc->focusIndicator.href.isEmpty() ) {
3580 QUrl u( doc->context(), doc->focusIndicator.href, TRUE ); 3581 QUrl u( doc->context(), doc->focusIndicator.href, TRUE );
3581 emitLinkClicked( u.toString( FALSE, FALSE ) ); 3582 emitLinkClicked( u.toString( FALSE, FALSE ) );
3582#ifndef QT_NO_CURSOR 3583#ifndef QT_NO_CURSOR
3583 viewport()->setCursor( isReadOnly() ? arrowCursor : ibeamCursor ); 3584 viewport()->setCursor( isReadOnly() ? arrowCursor : ibeamCursor );
3584#endif 3585#endif
3585 } 3586 }
3586 } break; 3587 } break;
3587#endif 3588#endif
3588 default: 3589 default:
3589 if ( e->state() & ControlButton ) { 3590 if ( e->state() & ControlButton ) {
3590 switch ( e->key() ) { 3591 switch ( e->key() ) {
3591 case Key_C: case Key_F16: // Copy key on Sun keyboards 3592 case Key_C: case Key_F16: // Copy key on Sun keyboards
3592 copy(); 3593 copy();
3593 break; 3594 break;
3594 } 3595 }
3595 } 3596 }
3596 return FALSE; 3597 return FALSE;
3597 } 3598 }
3598 return TRUE; 3599 return TRUE;
3599} 3600}
@@ -3638,27 +3639,27 @@ void QTextEdit::makeParagVisible( QTextParagraph *p )
3638void QTextEdit::scrollToAnchor( const QString& name ) 3639void QTextEdit::scrollToAnchor( const QString& name )
3639{ 3640{
3640 if ( !isVisible() ) { 3641 if ( !isVisible() ) {
3641 d->scrollToAnchor = name; 3642 d->scrollToAnchor = name;
3642 return; 3643 return;
3643 } 3644 }
3644 if ( name.isEmpty() ) 3645 if ( name.isEmpty() )
3645 return; 3646 return;
3646 sync(); 3647 sync();
3647 QTextCursor cursor( doc ); 3648 QTextCursor cursor( doc );
3648 QTextParagraph* last = doc->lastParagraph(); 3649 QTextParagraph* last = doc->lastParagraph();
3649 for (;;) { 3650 for (;;) {
3650 QTextStringChar* c = cursor.paragraph()->at( cursor.index() ); 3651 QTextStringChar* c = cursor.paragraph()->at( cursor.index() );
3651 if( c->isAnchor() ) { 3652 if( c->isAnchor() ) {
3652 QString a = c->anchorName(); 3653 QString a = c->anchorName();
3653 if ( a == name || 3654 if ( a == name ||
3654 (a.contains( '#' ) && QStringList::split( '#', a ).contains( name ) ) ) { 3655 (a.contains( '#' ) && QStringList::split( '#', a ).contains( name ) ) ) {
3655 setContentsPos( contentsX(), QMIN( cursor.paragraph()->rect().top() + cursor.totalOffsetY(), contentsHeight() - visibleHeight() ) ); 3656 setContentsPos( contentsX(), QMIN( cursor.paragraph()->rect().top() + cursor.totalOffsetY(), contentsHeight() - visibleHeight() ) );
3656 break; 3657 break;
3657 } 3658 }
3658 } 3659 }
3659 if ( cursor.paragraph() == last && cursor.atParagEnd() ) 3660 if ( cursor.paragraph() == last && cursor.atParagEnd() )
3660 break; 3661 break;
3661 cursor.gotoNextLetter(); 3662 cursor.gotoNextLetter();
3662 } 3663 }
3663} 3664}
3664 3665
@@ -3691,7 +3692,7 @@ void QTextEdit::updateStyles()
3691void QTextEdit::setDocument( QTextDocument *dc ) 3692void QTextEdit::setDocument( QTextDocument *dc )
3692{ 3693{
3693 if ( dc == doc ) 3694 if ( dc == doc )
3694 return; 3695 return;
3695 doc = dc; 3696 doc = dc;
3696 delete cursor; 3697 delete cursor;
3697 cursor = new QTextCursor( doc ); 3698 cursor = new QTextCursor( doc );
@@ -3717,70 +3718,70 @@ void QTextEdit::pasteSubType( const QCString& subtype )
3717 QCString st = subtype; 3718 QCString st = subtype;
3718 QString t = QApplication::clipboard()->text(st); 3719 QString t = QApplication::clipboard()->text(st);
3719 if ( doc->hasSelection( QTextDocument::Standard ) ) 3720 if ( doc->hasSelection( QTextDocument::Standard ) )
3720 removeSelectedText(); 3721 removeSelectedText();
3721 if ( !t.isEmpty() ) { 3722 if ( !t.isEmpty() ) {
3722 if ( t.startsWith( "<selstart/>" ) ) { 3723 if ( t.startsWith( "<selstart/>" ) ) {
3723 t.remove( 0, 11 ); 3724 t.remove( 0, 11 );
3724 QTextCursor oldC = *cursor; 3725 QTextCursor oldC = *cursor;
3725 lastFormatted = cursor->paragraph(); 3726 lastFormatted = cursor->paragraph();
3726 if ( lastFormatted->prev() ) 3727 if ( lastFormatted->prev() )
3727 lastFormatted = lastFormatted->prev(); 3728 lastFormatted = lastFormatted->prev();
3728 doc->setRichTextInternal( t, cursor ); 3729 doc->setRichTextInternal( t, cursor );
3729 3730
3730 if ( undoEnabled && !isReadOnly() ) { 3731 if ( undoEnabled && !isReadOnly() ) {
3731 doc->setSelectionStart( QTextDocument::Temp, oldC ); 3732 doc->setSelectionStart( QTextDocument::Temp, oldC );
3732 doc->setSelectionEnd( QTextDocument::Temp, *cursor ); 3733 doc->setSelectionEnd( QTextDocument::Temp, *cursor );
3733 3734
3734 checkUndoRedoInfo( UndoRedoInfo::Insert ); 3735 checkUndoRedoInfo( UndoRedoInfo::Insert );
3735 if ( !undoRedoInfo.valid() ) { 3736 if ( !undoRedoInfo.valid() ) {
3736 undoRedoInfo.id = oldC.paragraph()->paragId(); 3737 undoRedoInfo.id = oldC.paragraph()->paragId();
3737 undoRedoInfo.index = oldC.index(); 3738 undoRedoInfo.index = oldC.index();
3738 undoRedoInfo.d->text = QString::null; 3739 undoRedoInfo.d->text = QString::null;
3739 } 3740 }
3740 int oldLen = undoRedoInfo.d->text.length(); 3741 int oldLen = undoRedoInfo.d->text.length();
3741 if ( !doc->preProcessor() ) { 3742 if ( !doc->preProcessor() ) {
3742 QString txt = doc->selectedText( QTextDocument::Temp ); 3743 QString txt = doc->selectedText( QTextDocument::Temp );
3743 undoRedoInfo.d->text += txt; 3744 undoRedoInfo.d->text += txt;
3744 for ( int i = 0; i < (int)txt.length(); ++i ) { 3745 for ( int i = 0; i < (int)txt.length(); ++i ) {
3745 if ( txt[ i ] != '\n' && oldC.paragraph()->at( oldC.index() )->format() ) { 3746 if ( txt[ i ] != '\n' && oldC.paragraph()->at( oldC.index() )->format() ) {
3746 oldC.paragraph()->at( oldC.index() )->format()->addRef(); 3747 oldC.paragraph()->at( oldC.index() )->format()->addRef();
3747 undoRedoInfo.d->text. 3748 undoRedoInfo.d->text.
3748 setFormat( oldLen + i, oldC.paragraph()->at( oldC.index() )->format(), TRUE ); 3749 setFormat( oldLen + i, oldC.paragraph()->at( oldC.index() )->format(), TRUE );
3749 } 3750 }
3750 oldC.gotoNextLetter(); 3751 oldC.gotoNextLetter();
3751 } 3752 }
3752 } 3753 }
3753 undoRedoInfo.clear(); 3754 undoRedoInfo.clear();
3754 removeSelection( QTextDocument::Temp ); 3755 removeSelection( QTextDocument::Temp );
3755 } 3756 }
3756 3757
3757 formatMore(); 3758 formatMore();
3758 setModified(); 3759 setModified();
3759 emit textChanged(); 3760 emit textChanged();
3760 repaintChanged(); 3761 repaintChanged();
3761 ensureCursorVisible(); 3762 ensureCursorVisible();
3762 return; 3763 return;
3763 } 3764 }
3764 3765
3765#if defined(Q_OS_WIN32) 3766#if defined(Q_OS_WIN32)
3766 // Need to convert CRLF to LF 3767 // Need to convert CRLF to LF
3767 int index = t.find( QString::fromLatin1("\r\n"), 0 ); 3768 int index = t.find( QString::fromLatin1("\r\n"), 0 );
3768 while ( index != -1 ) { 3769 while ( index != -1 ) {
3769 t.replace( index, 2, QChar('\n') ); 3770 t.replace( index, 2, QChar('\n') );
3770 index = t.find( "\r\n", index ); 3771 index = t.find( "\r\n", index );
3771 } 3772 }
3772#elif defined(Q_OS_MAC) 3773#elif defined(Q_OS_MAC)
3773 //need to convert CR to LF 3774 //need to convert CR to LF
3774 for( unsigned int index = 0; index < t.length(); index++ ) 3775 for( unsigned int index = 0; index < t.length(); index++ )
3775 if(t[index] == '\r') 3776 if(t[index] == '\r')
3776 t[index] = '\n'; 3777 t[index] = '\n';
3777#endif 3778#endif
3778 for ( int i=0; (uint) i<t.length(); i++ ) { 3779 for ( int i=0; (uint) i<t.length(); i++ ) {
3779 if ( t[ i ] < ' ' && t[ i ] != '\n' && t[ i ] != '\t' ) 3780 if ( t[ i ] < ' ' && t[ i ] != '\n' && t[ i ] != '\t' )
3780 t[ i ] = ' '; 3781 t[ i ] = ' ';
3781 } 3782 }
3782 if ( !t.isEmpty() ) 3783 if ( !t.isEmpty() )
3783 insert( t, FALSE, TRUE, TRUE ); 3784 insert( t, FALSE, TRUE, TRUE );
3784 } 3785 }
3785} 3786}
3786 3787
@@ -3795,7 +3796,7 @@ void QTextEdit::pasteSpecial( const QPoint& pt )
3795{ 3796{
3796 QCString st = pickSpecial( QApplication::clipboard()->data(), TRUE, pt ); 3797 QCString st = pickSpecial( QApplication::clipboard()->data(), TRUE, pt );
3797 if ( !st.isEmpty() ) 3798 if ( !st.isEmpty() )
3798 pasteSubType( st ); 3799 pasteSubType( st );
3799} 3800}
3800#endif 3801#endif
3801#ifndef QT_NO_MIME 3802#ifndef QT_NO_MIME
@@ -3803,39 +3804,39 @@ QCString QTextEdit::pickSpecial( QMimeSource* ms, bool always_ask, const QPoint&
3803{ 3804{
3804 if ( ms ) { 3805 if ( ms ) {
3805#ifndef QT_NO_POPUPMENU 3806#ifndef QT_NO_POPUPMENU
3806 QPopupMenu popup( this, "qt_pickspecial_menu" ); 3807 QPopupMenu popup( this, "qt_pickspecial_menu" );
3807 QString fmt; 3808 QString fmt;
3808 int n = 0; 3809 int n = 0;
3809 QDict<void> done; 3810 QDict<void> done;
3810 for (int i = 0; !( fmt = ms->format( i ) ).isNull(); i++) { 3811 for (int i = 0; !( fmt = ms->format( i ) ).isNull(); i++) {
3811 int semi = fmt.find( ";" ); 3812 int semi = fmt.find( ";" );
3812 if ( semi >= 0 ) 3813 if ( semi >= 0 )
3813 fmt = fmt.left( semi ); 3814 fmt = fmt.left( semi );
3814 if ( fmt.left( 5 ) == "text/" ) { 3815 if ( fmt.left( 5 ) == "text/" ) {
3815 fmt = fmt.mid( 5 ); 3816 fmt = fmt.mid( 5 );
3816 if ( !done.find( fmt ) ) { 3817 if ( !done.find( fmt ) ) {
3817 done.insert( fmt,(void*)1 ); 3818 done.insert( fmt,(void*)1 );
3818 popup.insertItem( fmt, i ); 3819 popup.insertItem( fmt, i );
3819 n++; 3820 n++;
3820 } 3821 }
3821 } 3822 }
3822 } 3823 }
3823 if ( n ) { 3824 if ( n ) {
3824 int i = n ==1 && !always_ask ? popup.idAt( 0 ) : popup.exec( pt ); 3825 int i = n ==1 && !always_ask ? popup.idAt( 0 ) : popup.exec( pt );
3825 if ( i >= 0 ) 3826 if ( i >= 0 )
3826 return popup.text(i).latin1(); 3827 return popup.text(i).latin1();
3827 } 3828 }
3828#else 3829#else
3829 QString fmt; 3830 QString fmt;
3830 for (int i = 0; !( fmt = ms->format( i ) ).isNull(); i++) { 3831 for (int i = 0; !( fmt = ms->format( i ) ).isNull(); i++) {
3831 int semi = fmt.find( ";" ); 3832 int semi = fmt.find( ";" );
3832 if ( semi >= 0 ) 3833 if ( semi >= 0 )
3833 fmt = fmt.left( semi ); 3834 fmt = fmt.left( semi );
3834 if ( fmt.left( 5 ) == "text/" ) { 3835 if ( fmt.left( 5 ) == "text/" ) {
3835 fmt = fmt.mid( 5 ); 3836 fmt = fmt.mid( 5 );
3836 return fmt.latin1(); 3837 return fmt.latin1();
3837 } 3838 }
3838 } 3839 }
3839#endif 3840#endif
3840 } 3841 }
3841 return QCString(); 3842 return QCString();
@@ -3848,7 +3849,7 @@ QCString QTextEdit::pickSpecial( QMimeSource* ms, bool always_ask, const QPoint&
3848 This enum defines the QTextEdit's word wrap modes. The following 3849 This enum defines the QTextEdit's word wrap modes. The following
3849 values are valid: 3850 values are valid:
3850 3851
3851 \value NoWrap Do not wrap the text. 3852 \value NoWrap Do not wrap the text.
3852 3853
3853 \value WidgetWidth Wrap the text at the current width of the 3854 \value WidgetWidth Wrap the text at the current width of the
3854 widget (this is the default). Wrapping is at whitespace by default; 3855 widget (this is the default). Wrapping is at whitespace by default;
@@ -3886,39 +3887,39 @@ QCString QTextEdit::pickSpecial( QMimeSource* ms, bool always_ask, const QPoint&
3886void QTextEdit::setWordWrap( WordWrap mode ) 3887void QTextEdit::setWordWrap( WordWrap mode )
3887{ 3888{
3888 if ( wrapMode == mode ) 3889 if ( wrapMode == mode )
3889 return; 3890 return;
3890 wrapMode = mode; 3891 wrapMode = mode;
3891 switch ( mode ) { 3892 switch ( mode ) {
3892 case NoWrap: 3893 case NoWrap:
3893 document()->formatter()->setWrapEnabled( FALSE ); 3894 document()->formatter()->setWrapEnabled( FALSE );
3894 document()->formatter()->setWrapAtColumn( -1 ); 3895 document()->formatter()->setWrapAtColumn( -1 );
3895 doc->setWidth( visibleWidth() ); 3896 doc->setWidth( visibleWidth() );
3896 doc->setMinimumWidth( -1 ); 3897 doc->setMinimumWidth( -1 );
3897 doc->invalidate(); 3898 doc->invalidate();
3898 updateContents( contentsX(), contentsY(), visibleWidth(), visibleHeight() ); 3899 updateContents( contentsX(), contentsY(), visibleWidth(), visibleHeight() );
3899 lastFormatted = doc->firstParagraph(); 3900 lastFormatted = doc->firstParagraph();
3900 interval = 0; 3901 interval = 0;
3901 formatMore(); 3902 formatMore();
3902 break; 3903 break;
3903 case WidgetWidth: 3904 case WidgetWidth:
3904 document()->formatter()->setWrapEnabled( TRUE ); 3905 document()->formatter()->setWrapEnabled( TRUE );
3905 document()->formatter()->setWrapAtColumn( -1 ); 3906 document()->formatter()->setWrapAtColumn( -1 );
3906 doResize(); 3907 doResize();
3907 break; 3908 break;
3908 case FixedPixelWidth: 3909 case FixedPixelWidth:
3909 document()->formatter()->setWrapEnabled( TRUE ); 3910 document()->formatter()->setWrapEnabled( TRUE );
3910 document()->formatter()->setWrapAtColumn( -1 ); 3911 document()->formatter()->setWrapAtColumn( -1 );
3911 if ( wrapWidth < 0 ) 3912 if ( wrapWidth < 0 )
3912 wrapWidth = 200; 3913 wrapWidth = 200;
3913 setWrapColumnOrWidth( wrapWidth ); 3914 setWrapColumnOrWidth( wrapWidth );
3914 break; 3915 break;
3915 case FixedColumnWidth: 3916 case FixedColumnWidth:
3916 if ( wrapWidth < 0 ) 3917 if ( wrapWidth < 0 )
3917 wrapWidth = 80; 3918 wrapWidth = 80;
3918 document()->formatter()->setWrapEnabled( TRUE ); 3919 document()->formatter()->setWrapEnabled( TRUE );
3919 document()->formatter()->setWrapAtColumn( wrapWidth ); 3920 document()->formatter()->setWrapAtColumn( wrapWidth );
3920 setWrapColumnOrWidth( wrapWidth ); 3921 setWrapColumnOrWidth( wrapWidth );
3921 break; 3922 break;
3922 } 3923 }
3923} 3924}
3924 3925
@@ -3943,17 +3944,17 @@ void QTextEdit::setWrapColumnOrWidth( int value )
3943{ 3944{
3944 wrapWidth = value; 3945 wrapWidth = value;
3945 if ( wrapMode == FixedColumnWidth ) { 3946 if ( wrapMode == FixedColumnWidth ) {
3946 document()->formatter()->setWrapAtColumn( wrapWidth ); 3947 document()->formatter()->setWrapAtColumn( wrapWidth );
3947 resizeContents( 0, 0 ); 3948 resizeContents( 0, 0 );
3948 doc->setWidth( visibleWidth() ); 3949 doc->setWidth( visibleWidth() );
3949 doc->setMinimumWidth( -1 ); 3950 doc->setMinimumWidth( -1 );
3950 } else if (wrapMode == FixedPixelWidth ) { 3951 } else if (wrapMode == FixedPixelWidth ) {
3951 document()->formatter()->setWrapAtColumn( -1 ); 3952 document()->formatter()->setWrapAtColumn( -1 );
3952 resizeContents( wrapWidth, 0 ); 3953 resizeContents( wrapWidth, 0 );
3953 doc->setWidth( wrapWidth ); 3954 doc->setWidth( wrapWidth );
3954 doc->setMinimumWidth( wrapWidth ); 3955 doc->setMinimumWidth( wrapWidth );
3955 } else { 3956 } else {
3956 return; 3957 return;
3957 } 3958 }
3958 doc->invalidate(); 3959 doc->invalidate();
3959 updateContents( contentsX(), contentsY(), visibleWidth(), visibleHeight() ); 3960 updateContents( contentsX(), contentsY(), visibleWidth(), visibleHeight() );
@@ -3965,7 +3966,7 @@ void QTextEdit::setWrapColumnOrWidth( int value )
3965int QTextEdit::wrapColumnOrWidth() const 3966int QTextEdit::wrapColumnOrWidth() const
3966{ 3967{
3967 if ( wrapMode == WidgetWidth ) 3968 if ( wrapMode == WidgetWidth )
3968 return visibleWidth(); 3969 return visibleWidth();
3969 return wrapWidth; 3970 return wrapWidth;
3970} 3971}
3971 3972
@@ -3998,13 +3999,13 @@ int QTextEdit::wrapColumnOrWidth() const
3998void QTextEdit::setWrapPolicy( WrapPolicy policy ) 3999void QTextEdit::setWrapPolicy( WrapPolicy policy )
3999{ 4000{
4000 if ( wPolicy == policy ) 4001 if ( wPolicy == policy )
4001 return; 4002 return;
4002 wPolicy = policy; 4003 wPolicy = policy;
4003 QTextFormatter *formatter; 4004 QTextFormatter *formatter;
4004 if ( policy == AtWhiteSpace ) 4005 if ( policy == AtWhiteSpace )
4005 formatter = new QTextFormatterBreakWords; 4006 formatter = new QTextFormatterBreakWords;
4006 else 4007 else
4007 formatter = new QTextFormatterBreakInWords; 4008 formatter = new QTextFormatterBreakInWords;
4008 formatter->setWrapAtColumn( document()->formatter()->wrapAtColumn() ); 4009 formatter->setWrapAtColumn( document()->formatter()->wrapAtColumn() );
4009 formatter->setWrapEnabled( document()->formatter()->isWrapEnabled( 0 ) ); 4010 formatter->setWrapEnabled( document()->formatter()->isWrapEnabled( 0 ) );
4010 document()->setFormatter( formatter ); 4011 document()->setFormatter( formatter );
@@ -4035,7 +4036,7 @@ void QTextEdit::clear()
4035 4036
4036 setContentsPos( 0, 0 ); 4037 setContentsPos( 0, 0 );
4037 if ( cursor->isValid() ) 4038 if ( cursor->isValid() )
4038 cursor->restoreState(); 4039 cursor->restoreState();
4039 doc->clear( TRUE ); 4040 doc->clear( TRUE );
4040 delete cursor; 4041 delete cursor;
4041 cursor = new QTextCursor( doc ); 4042 cursor = new QTextCursor( doc );
@@ -4121,12 +4122,12 @@ void QTextEdit::clearUndoRedo()
4121bool QTextEdit::getFormat( int para, int index, QFont *font, QColor *color, VerticalAlignment *verticalAlignment ) 4122bool QTextEdit::getFormat( int para, int index, QFont *font, QColor *color, VerticalAlignment *verticalAlignment )
4122{ 4123{
4123 if ( !font || !color ) 4124 if ( !font || !color )
4124 return FALSE; 4125 return FALSE;
4125 QTextParagraph *p = doc->paragAt( para ); 4126 QTextParagraph *p = doc->paragAt( para );
4126 if ( !p ) 4127 if ( !p )
4127 return FALSE; 4128 return FALSE;
4128 if ( index < 0 || index >= p->length() ) 4129 if ( index < 0 || index >= p->length() )
4129 return FALSE; 4130 return FALSE;
4130 *font = p->at( index )->format()->font(); 4131 *font = p->at( index )->format()->font();
4131 *color = p->at( index )->format()->color(); 4132 *color = p->at( index )->format()->color();
4132 *verticalAlignment = (VerticalAlignment)p->at( index )->format()->vAlign(); 4133 *verticalAlignment = (VerticalAlignment)p->at( index )->format()->vAlign();
@@ -4152,16 +4153,16 @@ bool QTextEdit::getFormat( int para, int index, QFont *font, QColor *color, Vert
4152*/ 4153*/
4153 4154
4154bool QTextEdit::getParagraphFormat( int para, QFont *font, QColor *color, 4155bool QTextEdit::getParagraphFormat( int para, QFont *font, QColor *color,
4155 VerticalAlignment *verticalAlignment, int *alignment, 4156 VerticalAlignment *verticalAlignment, int *alignment,
4156 QStyleSheetItem::DisplayMode *displayMode, 4157 QStyleSheetItem::DisplayMode *displayMode,
4157 QStyleSheetItem::ListStyle *listStyle, 4158 QStyleSheetItem::ListStyle *listStyle,
4158 int *listDepth ) 4159 int *listDepth )
4159{ 4160{
4160 if ( !font || !color || !alignment || !displayMode || !listStyle ) 4161 if ( !font || !color || !alignment || !displayMode || !listStyle )
4161 return FALSE; 4162 return FALSE;
4162 QTextParagraph *p = doc->paragAt( para ); 4163 QTextParagraph *p = doc->paragAt( para );
4163 if ( !p ) 4164 if ( !p )
4164 return FALSE; 4165 return FALSE;
4165 *font = p->at(0)->format()->font(); 4166 *font = p->at(0)->format()->font();
4166 *color = p->at(0)->format()->color(); 4167 *color = p->at(0)->format()->color();
4167 *verticalAlignment = (VerticalAlignment)p->at(0)->format()->vAlign(); 4168 *verticalAlignment = (VerticalAlignment)p->at(0)->format()->vAlign();
@@ -4188,20 +4189,20 @@ QPopupMenu *QTextEdit::createPopupMenu( const QPoint& pos )
4188#ifndef QT_NO_POPUPMENU 4189#ifndef QT_NO_POPUPMENU
4189 QPopupMenu *popup = new QPopupMenu( this, "qt_edit_menu" ); 4190 QPopupMenu *popup = new QPopupMenu( this, "qt_edit_menu" );
4190 if ( !isReadOnly() ) { 4191 if ( !isReadOnly() ) {
4191 d->id[ IdUndo ] = popup->insertItem( tr( "&Undo" ) + ACCEL_KEY( Z ) ); 4192 d->id[ IdUndo ] = popup->insertItem( tr( "&Undo" ) + ACCEL_KEY( Z ) );
4192 d->id[ IdRedo ] = popup->insertItem( tr( "&Redo" ) + ACCEL_KEY( Y ) ); 4193 d->id[ IdRedo ] = popup->insertItem( tr( "&Redo" ) + ACCEL_KEY( Y ) );
4193 popup->insertSeparator(); 4194 popup->insertSeparator();
4194 } 4195 }
4195#ifndef QT_NO_CLIPBOARD 4196#ifndef QT_NO_CLIPBOARD
4196 if ( !isReadOnly() ) 4197 if ( !isReadOnly() )
4197 d->id[ IdCut ] = popup->insertItem( tr( "Cu&t" ) + ACCEL_KEY( X ) ); 4198 d->id[ IdCut ] = popup->insertItem( tr( "Cu&t" ) + ACCEL_KEY( X ) );
4198 d->id[ IdCopy ] = popup->insertItem( tr( "&Copy" ) + ACCEL_KEY( C ) ); 4199 d->id[ IdCopy ] = popup->insertItem( tr( "&Copy" ) + ACCEL_KEY( C ) );
4199 if ( !isReadOnly() ) 4200 if ( !isReadOnly() )
4200 d->id[ IdPaste ] = popup->insertItem( tr( "&Paste" ) + ACCEL_KEY( V ) ); 4201 d->id[ IdPaste ] = popup->insertItem( tr( "&Paste" ) + ACCEL_KEY( V ) );
4201#endif 4202#endif
4202 if ( !isReadOnly() ) { 4203 if ( !isReadOnly() ) {
4203 d->id[ IdClear ] = popup->insertItem( tr( "Clear" ) ); 4204 d->id[ IdClear ] = popup->insertItem( tr( "Clear" ) );
4204 popup->insertSeparator(); 4205 popup->insertSeparator();
4205 } 4206 }
4206#if defined(Q_WS_X11) 4207#if defined(Q_WS_X11)
4207 d->id[ IdSelectAll ] = popup->insertItem( tr( "Select All" ) ); 4208 d->id[ IdSelectAll ] = popup->insertItem( tr( "Select All" ) );
@@ -4334,8 +4335,8 @@ void QTextEdit::zoomTo( int size )
4334void QTextEdit::sync() 4335void QTextEdit::sync()
4335{ 4336{
4336 while ( lastFormatted ) { 4337 while ( lastFormatted ) {
4337 lastFormatted->format(); 4338 lastFormatted->format();
4338 lastFormatted = lastFormatted->next(); 4339 lastFormatted = lastFormatted->next();
4339 } 4340 }
4340 resizeContents( contentsWidth(), doc->height() ); 4341 resizeContents( contentsWidth(), doc->height() );
4341} 4342}
@@ -4346,17 +4347,17 @@ void QTextEdit::setEnabled( bool b )
4346{ 4347{
4347 QScrollView::setEnabled( b ); 4348 QScrollView::setEnabled( b );
4348 if ( !b ) { 4349 if ( !b ) {
4349 blinkTimer->stop(); 4350 blinkTimer->stop();
4350 drawCursor( FALSE ); 4351 drawCursor( FALSE );
4351 } 4352 }
4352 if ( textFormat() == PlainText ) { 4353 if ( textFormat() == PlainText ) {
4353 QTextFormat *f = doc->formatCollection()->defaultFormat(); 4354 QTextFormat *f = doc->formatCollection()->defaultFormat();
4354 f->setColor( colorGroup().text() ); 4355 f->setColor( colorGroup().text() );
4355 updateContents( contentsX(), contentsY(), visibleWidth(), visibleHeight() ); 4356 updateContents( contentsX(), contentsY(), visibleWidth(), visibleHeight() );
4356 } 4357 }
4357 if ( b ) { 4358 if ( b ) {
4358 blinkTimer->start( QApplication::cursorFlashTime() / 2 ); 4359 blinkTimer->start( QApplication::cursorFlashTime() / 2 );
4359 drawCursor( TRUE ); 4360 drawCursor( TRUE );
4360 } 4361 }
4361} 4362}
4362 4363
@@ -4372,9 +4373,9 @@ void QTextEdit::setEnabled( bool b )
4372void QTextEdit::setSelectionAttributes( int selNum, const QColor &back, bool invertText ) 4373void QTextEdit::setSelectionAttributes( int selNum, const QColor &back, bool invertText )
4373{ 4374{
4374 if ( selNum < 1 ) 4375 if ( selNum < 1 )
4375 return; 4376 return;
4376 if ( selNum > doc->numSelections() ) 4377 if ( selNum > doc->numSelections() )
4377 doc->addSelection( selNum ); 4378 doc->addSelection( selNum );
4378 doc->setSelectionColor( selNum, back ); 4379 doc->setSelectionColor( selNum, back );
4379 doc->setInvertSelectionText( selNum, invertText ); 4380 doc->setInvertSelectionText( selNum, invertText );
4380} 4381}
@@ -4383,22 +4384,22 @@ void QTextEdit::setSelectionAttributes( int selNum, const QColor &back, bool inv
4383void QTextEdit::windowActivationChange( bool ) 4384void QTextEdit::windowActivationChange( bool )
4384{ 4385{
4385 if ( !isVisible() ) 4386 if ( !isVisible() )
4386 return; 4387 return;
4387 4388
4388 if ( palette().active() != palette().inactive() ) 4389 if ( palette().active() != palette().inactive() )
4389 updateContents( contentsX(), contentsY(), visibleWidth(), visibleHeight() ); 4390 updateContents( contentsX(), contentsY(), visibleWidth(), visibleHeight() );
4390} 4391}
4391 4392
4392void QTextEdit::setReadOnly( bool b ) 4393void QTextEdit::setReadOnly( bool b )
4393{ 4394{
4394 if ( readonly == b ) 4395 if ( readonly == b )
4395 return; 4396 return;
4396 readonly = b; 4397 readonly = b;
4397#ifndef QT_NO_CURSOR 4398#ifndef QT_NO_CURSOR
4398 if ( readonly ) 4399 if ( readonly )
4399 viewport()->setCursor( arrowCursor ); 4400 viewport()->setCursor( arrowCursor );
4400 else 4401 else
4401 viewport()->setCursor( ibeamCursor ); 4402 viewport()->setCursor( ibeamCursor );
4402#endif 4403#endif
4403} 4404}
4404 4405
@@ -4421,7 +4422,7 @@ QRect QTextEdit::paragraphRect( int para ) const
4421 that->sync(); 4422 that->sync();
4422 QTextParagraph *p = doc->paragAt( para ); 4423 QTextParagraph *p = doc->paragAt( para );
4423 if ( !p ) 4424 if ( !p )
4424 return QRect( -1, -1, -1, -1 ); 4425 return QRect( -1, -1, -1, -1 );
4425 return p->rect(); 4426 return p->rect();
4426} 4427}
4427 4428
@@ -4435,7 +4436,7 @@ int QTextEdit::paragraphAt( const QPoint &pos ) const
4435 QTextCursor c( doc ); 4436 QTextCursor c( doc );
4436 c.place( pos, doc->firstParagraph() ); 4437 c.place( pos, doc->firstParagraph() );
4437 if ( c.paragraph() ) 4438 if ( c.paragraph() )
4438 return c.paragraph()->paragId(); 4439 return c.paragraph()->paragId();
4439 return -1; 4440 return -1;
4440} 4441}
4441 4442
@@ -4451,9 +4452,9 @@ int QTextEdit::charAt( const QPoint &pos, int *para ) const
4451 QTextCursor c( doc ); 4452 QTextCursor c( doc );
4452 c.place( pos, doc->firstParagraph() ); 4453 c.place( pos, doc->firstParagraph() );
4453 if ( c.paragraph() ) { 4454 if ( c.paragraph() ) {
4454 if ( para ) 4455 if ( para )
4455 *para = c.paragraph()->paragId(); 4456 *para = c.paragraph()->paragId();
4456 return c.index(); 4457 return c.index();
4457 } 4458 }
4458 return -1; 4459 return -1;
4459} 4460}
@@ -4464,7 +4465,7 @@ void QTextEdit::setParagraphBackgroundColor( int para, const QColor &bg )
4464{ 4465{
4465 QTextParagraph *p = doc->paragAt( para ); 4466 QTextParagraph *p = doc->paragAt( para );
4466 if ( !p ) 4467 if ( !p )
4467 return; 4468 return;
4468 p->setBackgroundColor( bg ); 4469 p->setBackgroundColor( bg );
4469 repaintChanged(); 4470 repaintChanged();
4470} 4471}
@@ -4477,7 +4478,7 @@ void QTextEdit::clearParagraphBackground( int para )
4477{ 4478{
4478 QTextParagraph *p = doc->paragAt( para ); 4479 QTextParagraph *p = doc->paragAt( para );
4479 if ( !p ) 4480 if ( !p )
4480 return; 4481 return;
4481 p->clearBackgroundColor(); 4482 p->clearBackgroundColor();
4482 repaintChanged(); 4483 repaintChanged();
4483} 4484}
@@ -4491,10 +4492,10 @@ QColor QTextEdit::paragraphBackgroundColor( int para ) const
4491{ 4492{
4492 QTextParagraph *p = doc->paragAt( para ); 4493 QTextParagraph *p = doc->paragAt( para );
4493 if ( !p ) 4494 if ( !p )
4494 return QColor(); 4495 return QColor();
4495 QColor *c = p->backgroundColor(); 4496 QColor *c = p->backgroundColor();
4496 if ( c ) 4497 if ( c )
4497 return *c; 4498 return *c;
4498 return QColor(); 4499 return QColor();
4499} 4500}
4500 4501
@@ -4531,9 +4532,9 @@ bool QTextEdit::isRedoAvailable() const
4531void QTextEdit::ensureFormatted( QTextParagraph *p ) 4532void QTextEdit::ensureFormatted( QTextParagraph *p )
4532{ 4533{
4533 while ( !p->isValid() ) { 4534 while ( !p->isValid() ) {
4534 if ( !lastFormatted ) 4535 if ( !lastFormatted )
4535 return; 4536 return;
4536 formatMore(); 4537 formatMore();
4537 } 4538 }
4538} 4539}
4539 4540
@@ -4541,30 +4542,30 @@ void QTextEdit::ensureFormatted( QTextParagraph *p )
4541void QTextEdit::updateCursor( const QPoint & pos ) 4542void QTextEdit::updateCursor( const QPoint & pos )
4542{ 4543{
4543 if ( isReadOnly() && linksEnabled() ) { 4544 if ( isReadOnly() && linksEnabled() ) {
4544 QTextCursor c = *cursor; 4545 QTextCursor c = *cursor;
4545 placeCursor( pos, &c, TRUE ); 4546 placeCursor( pos, &c, TRUE );
4546 4547
4547#ifndef QT_NO_NETWORKPROTOCOL 4548#ifndef QT_NO_NETWORKPROTOCOL
4548 if ( c.paragraph() && c.paragraph()->at( c.index() ) && 4549 if ( c.paragraph() && c.paragraph()->at( c.index() ) &&
4549 c.paragraph()->at( c.index() )->isAnchor() && 4550 c.paragraph()->at( c.index() )->isAnchor() &&
4550 !c.paragraph()->at( c.index() )->anchorHref().isEmpty() ) { 4551 !c.paragraph()->at( c.index() )->anchorHref().isEmpty() ) {
4551 if ( c.index() < c.paragraph()->length() - 1 ) 4552 if ( c.index() < c.paragraph()->length() - 1 )
4552 onLink = c.paragraph()->at( c.index() )->anchorHref(); 4553 onLink = c.paragraph()->at( c.index() )->anchorHref();
4553 else 4554 else
4554 onLink = QString::null; 4555 onLink = QString::null;
4555 4556
4556#ifndef QT_NO_CURSOR 4557#ifndef QT_NO_CURSOR
4557 viewport()->setCursor( onLink.isEmpty() ? arrowCursor : pointingHandCursor ); 4558 viewport()->setCursor( onLink.isEmpty() ? arrowCursor : pointingHandCursor );
4558#endif 4559#endif
4559 QUrl u( doc->context(), onLink, TRUE ); 4560 QUrl u( doc->context(), onLink, TRUE );
4560 emitHighlighted( u.toString( FALSE, FALSE ) ); 4561 emitHighlighted( u.toString( FALSE, FALSE ) );
4561 } else { 4562 } else {
4562#ifndef QT_NO_CURSOR 4563#ifndef QT_NO_CURSOR
4563 viewport()->setCursor( isReadOnly() ? arrowCursor : ibeamCursor ); 4564 viewport()->setCursor( isReadOnly() ? arrowCursor : ibeamCursor );
4564#endif 4565#endif
4565 onLink = QString::null; 4566 onLink = QString::null;
4566 emitHighlighted( QString::null ); 4567 emitHighlighted( QString::null );
4567 } 4568 }
4568#endif 4569#endif
4569 } 4570 }
4570} 4571}