summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-write/qtextedit.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-write/qtextedit.cpp') (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
@@ -61,6 +61,6 @@ public:
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 }
@@ -97,17 +97,17 @@ static bool block_set_alignment = FALSE;
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
@@ -209,4 +209,4 @@ static bool block_set_alignment = FALSE;
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 }
@@ -216,5 +216,5 @@ static bool block_set_alignment = FALSE;
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 }
@@ -341,3 +341,3 @@ static bool block_set_alignment = FALSE;
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
@@ -350,5 +350,5 @@ static bool block_set_alignment = FALSE;
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
@@ -370,3 +370,3 @@ static bool block_set_alignment = FALSE;
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
@@ -653,3 +653,3 @@ QTextEdit::QTextEdit( QWidget *parent, const char *name )
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 ),
@@ -675,2 +675,3 @@ void QTextEdit::init()
675 setFrameStyle( Sunken ); 675 setFrameStyle( Sunken );
676 setVScrollBarMode( AlwaysOn );
676 undoEnabled = TRUE; 677 undoEnabled = TRUE;
@@ -680,3 +681,3 @@ void QTextEdit::init()
680 connect( doc, SIGNAL( minimumWidthChanged(int) ), 681 connect( doc, SIGNAL( minimumWidthChanged(int) ),
681 this, SLOT( documentWidthChanged(int) ) ); 682 this, SLOT( documentWidthChanged(int) ) );
682 683
@@ -701,3 +702,3 @@ void QTextEdit::init()
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
@@ -712,3 +713,3 @@ void QTextEdit::init()
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();
@@ -717,3 +718,3 @@ void QTextEdit::init()
717 connect( scrollTimer, SIGNAL( timeout() ), 718 connect( scrollTimer, SIGNAL( timeout() ),
718 this, SLOT( autoScrollTimerDone() ) ); 719 this, SLOT( autoScrollTimerDone() ) );
719 720
@@ -722,3 +723,3 @@ void QTextEdit::init()
722 connect( changeIntervalTimer, SIGNAL( timeout() ), 723 connect( changeIntervalTimer, SIGNAL( timeout() ),
723 this, SLOT( doChangeInterval() ) ); 724 this, SLOT( doChangeInterval() ) );
724 725
@@ -727,3 +728,3 @@ void QTextEdit::init()
727 connect( blinkTimer, SIGNAL( timeout() ), 728 connect( blinkTimer, SIGNAL( timeout() ),
728 this, SLOT( blinkCursor() ) ); 729 this, SLOT( blinkCursor() ) );
729 730
@@ -732,3 +733,3 @@ void QTextEdit::init()
732 connect( dragStartTimer, SIGNAL( timeout() ), 733 connect( dragStartTimer, SIGNAL( timeout() ),
733 this, SLOT( startDrag() ) ); 734 this, SLOT( startDrag() ) );
734#endif 735#endif
@@ -750,14 +751,14 @@ void QTextEdit::paintDocument( bool drawAll, QPainter *p, int cx, int cy, int cw
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 }
@@ -769,7 +770,7 @@ void QTextEdit::paintDocument( bool drawAll, QPainter *p, int cx, int cy, int cw
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}
@@ -784,7 +785,7 @@ void QTextEdit::drawContents( QPainter *p, int cx, int cy, int cw, int ch )
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 }
@@ -804,64 +805,64 @@ bool QTextEdit::event( QEvent *e )
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 }
@@ -869,11 +870,11 @@ bool QTextEdit::event( QEvent *e )
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 }
@@ -894,6 +895,6 @@ void QTextEdit::keyPressEvent( QKeyEvent *e )
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 }
@@ -903,7 +904,7 @@ void QTextEdit::keyPressEvent( QKeyEvent *e )
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 }
@@ -916,223 +917,223 @@ void QTextEdit::keyPressEvent( QKeyEvent *e )
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 }
@@ -1143,6 +1144,6 @@ void QTextEdit::keyPressEvent( QKeyEvent *e )
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}
@@ -1157,6 +1158,6 @@ void QTextEdit::doKeyboardAction( KeyboardAction action )
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
@@ -1168,82 +1169,82 @@ void QTextEdit::doKeyboardAction( KeyboardAction 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 }
@@ -1256,3 +1257,3 @@ void QTextEdit::doKeyboardAction( KeyboardAction action )
1256 if ( doUpdateCurrentFormat ) 1257 if ( doUpdateCurrentFormat )
1257 updateCurrentFormat(); 1258 updateCurrentFormat();
1258 setModified(); 1259 setModified();
@@ -1268,28 +1269,28 @@ void QTextEdit::readFormats( QTextCursor &c1, QTextCursor &c2, QTextString &text
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 }
@@ -1319,3 +1320,3 @@ void QTextEdit::removeSelectedText( int selNum )
1319 if ( isReadOnly() ) 1320 if ( isReadOnly() )
1320 return; 1321 return;
1321 1322
@@ -1328,8 +1329,8 @@ void QTextEdit::removeSelectedText( int selNum )
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 }
@@ -1339,4 +1340,4 @@ void QTextEdit::removeSelectedText( int selNum )
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 }
@@ -1347,24 +1348,24 @@ void QTextEdit::removeSelectedText( int selNum )
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 }
@@ -1385,33 +1386,33 @@ void QTextEdit::moveCursor( CursorAction action, bool select )
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 }
@@ -1430,38 +1431,38 @@ void QTextEdit::moveCursor( CursorAction 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 }
@@ -1477,3 +1478,3 @@ void QTextEdit::resizeEvent( QResizeEvent *e )
1477 if ( doc->visibleWidth() == 0 ) 1478 if ( doc->visibleWidth() == 0 )
1478 doResize(); 1479 doResize();
1479} 1480}
@@ -1486,7 +1487,7 @@ void QTextEdit::viewportResizeEvent( QResizeEvent *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 }
@@ -1504,4 +1505,4 @@ void QTextEdit::ensureCursorVisible()
1504 if ( !isVisible() ) { 1505 if ( !isVisible() ) {
1505 d->ensureCursorVisibleInShowEvent = TRUE; 1506 d->ensureCursorVisibleInShowEvent = TRUE;
1506 return; 1507 return;
1507 } 1508 }
@@ -1525,9 +1526,9 @@ void QTextEdit::drawCursor( bool visible )
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
@@ -1540,5 +1541,5 @@ void QTextEdit::drawCursor( bool visible )
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() );
@@ -1546,16 +1547,16 @@ void QTextEdit::drawCursor( bool visible )
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 }
@@ -1579,9 +1580,9 @@ void QTextEdit::contentsWheelEvent( QWheelEvent *e )
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 }
@@ -1603,64 +1604,64 @@ void QTextEdit::contentsMousePressEvent( QMouseEvent *e )
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 }
@@ -1668,3 +1669,3 @@ void QTextEdit::contentsMousePressEvent( QMouseEvent *e )
1668 if ( *cursor != oldCursor ) 1669 if ( *cursor != oldCursor )
1669 updateCurrentFormat(); 1670 updateCurrentFormat();
1670} 1671}
@@ -1677,16 +1678,16 @@ void QTextEdit::contentsMouseMoveEvent( QMouseEvent *e )
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 }
@@ -1695,6 +1696,6 @@ void QTextEdit::contentsMouseMoveEvent( QMouseEvent *e )
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 }
@@ -1710,9 +1711,9 @@ void QTextEdit::contentsMouseReleaseEvent( QMouseEvent * e )
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 }
@@ -1720,3 +1721,3 @@ void QTextEdit::contentsMouseReleaseEvent( QMouseEvent * e )
1720 if ( mousePressed ) { 1721 if ( mousePressed ) {
1721 mousePressed = FALSE; 1722 mousePressed = FALSE;
1722 } 1723 }
@@ -1725,3 +1726,3 @@ void QTextEdit::contentsMouseReleaseEvent( QMouseEvent * e )
1725 if ( oldCursor != *cursor ) 1726 if ( oldCursor != *cursor )
1726 updateCurrentFormat(); 1727 updateCurrentFormat();
1727 inDoubleClick = FALSE; 1728 inDoubleClick = FALSE;
@@ -1730,9 +1731,9 @@ void QTextEdit::contentsMouseReleaseEvent( QMouseEvent * e )
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 }
@@ -1741,3 +1742,3 @@ void QTextEdit::contentsMouseReleaseEvent( QMouseEvent * e )
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
@@ -1754,5 +1755,5 @@ void QTextEdit::contentsMouseDoubleClickEvent( QMouseEvent * )
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
@@ -1776,4 +1777,4 @@ void QTextEdit::contentsDragEnterEvent( QDragEnterEvent *e )
1776 if ( isReadOnly() || !QTextDrag::canDecode( e ) ) { 1777 if ( isReadOnly() || !QTextDrag::canDecode( e ) ) {
1777 e->ignore(); 1778 e->ignore();
1778 return; 1779 return;
1779 } 1780 }
@@ -1788,4 +1789,4 @@ void QTextEdit::contentsDragMoveEvent( QDragMoveEvent *e )
1788 if ( isReadOnly() || !QTextDrag::canDecode( e ) ) { 1789 if ( isReadOnly() || !QTextDrag::canDecode( e ) ) {
1789 e->ignore(); 1790 e->ignore();
1790 return; 1791 return;
1791 } 1792 }
@@ -1809,3 +1810,3 @@ void QTextEdit::contentsDropEvent( QDropEvent *e )
1809 if ( isReadOnly() ) 1810 if ( isReadOnly() )
1810 return; 1811 return;
1811 inDnD = FALSE; 1812 inDnD = FALSE;
@@ -1815,57 +1816,57 @@ void QTextEdit::contentsDropEvent( QDropEvent *e )
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 }
@@ -1878,3 +1879,3 @@ void QTextEdit::autoScrollTimerDone()
1878 if ( mousePressed ) 1879 if ( mousePressed )
1879 handleMouseMove( viewportToContents( viewport()->mapFromGlobal( QCursor::pos() ) ) ); 1880 handleMouseMove( viewportToContents( viewport()->mapFromGlobal( QCursor::pos() ) ) );
1880} 1881}
@@ -1884,8 +1885,8 @@ void QTextEdit::handleMouseMove( const QPoint& pos )
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
@@ -1897,22 +1898,22 @@ void QTextEdit::handleMouseMove( const QPoint& pos )
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
@@ -1923,3 +1924,3 @@ void QTextEdit::handleMouseMove( const QPoint& pos )
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 }
@@ -1927,6 +1928,6 @@ void QTextEdit::handleMouseMove( const QPoint& pos )
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 }
@@ -1934,11 +1935,11 @@ void QTextEdit::handleMouseMove( const QPoint& pos )
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 }
@@ -1946,6 +1947,6 @@ void QTextEdit::handleMouseMove( const QPoint& pos )
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 }
@@ -1965,3 +1966,3 @@ void QTextEdit::placeCursor( const QPoint &pos, QTextCursor *c, bool link )
1965 if ( !c ) 1966 if ( !c )
1966 c = cursor; 1967 c = cursor;
1967 1968
@@ -1978,11 +1979,11 @@ void QTextEdit::updateMicroFocusHint()
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 }
@@ -1995,3 +1996,3 @@ void QTextEdit::formatMore()
1995 if ( !lastFormatted ) 1996 if ( !lastFormatted )
1996 return; 1997 return;
1997 1998
@@ -2003,13 +2004,13 @@ void QTextEdit::formatMore()
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 }
@@ -2017,8 +2018,8 @@ void QTextEdit::formatMore()
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 }
@@ -2026,5 +2027,5 @@ void QTextEdit::formatMore()
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}
@@ -2034,3 +2035,3 @@ void QTextEdit::doResize()
2034 if ( wrapMode == FixedPixelWidth ) 2035 if ( wrapMode == FixedPixelWidth )
2035 return; 2036 return;
2036 doc->setMinimumWidth( -1 ); 2037 doc->setMinimumWidth( -1 );
@@ -2057,10 +2058,10 @@ bool QTextEdit::eventFilter( QObject *o, QEvent *e )
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 }
@@ -2085,3 +2086,3 @@ void QTextEdit::insert( const QString &text, bool indent, bool checkNewLine, boo
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 );
@@ -2089,3 +2090,3 @@ void QTextEdit::insert( const QString &text, bool indent, bool checkNewLine, boo
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;
@@ -2094,9 +2095,9 @@ void QTextEdit::insert( const QString &text, bool indent, bool checkNewLine, boo
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 }
@@ -2104,3 +2105,3 @@ void QTextEdit::insert( const QString &text, bool indent, bool checkNewLine, boo
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;
@@ -2108,6 +2109,6 @@ void QTextEdit::insert( const QString &text, bool indent, bool checkNewLine, boo
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 }
@@ -2115,3 +2116,3 @@ void QTextEdit::insert( const QString &text, bool indent, bool checkNewLine, boo
2115 if ( indent && ( txt == "{" || txt == "}" || txt == ":" || txt == "#" ) ) 2116 if ( indent && ( txt == "{" || txt == "}" || txt == ":" || txt == "#" ) )
2116 cursor->indent(); 2117 cursor->indent();
2117 formatMore(); 2118 formatMore();
@@ -2122,12 +2123,12 @@ void QTextEdit::insert( const QString &text, bool indent, bool checkNewLine, boo
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 }
@@ -2135,5 +2136,5 @@ void QTextEdit::insert( const QString &text, bool indent, bool checkNewLine, boo
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 }
@@ -2151,3 +2152,3 @@ void QTextEdit::insertAt( const QString &text, int para, int index )
2151 if ( !p ) 2152 if ( !p )
2152 return; 2153 return;
2153 QTextCursor tmp = *cursor; 2154 QTextCursor tmp = *cursor;
@@ -2168,10 +2169,10 @@ void QTextEdit::insertParagraph( const QString &text, int 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 }
@@ -2185,10 +2186,10 @@ void QTextEdit::removeParagraph( int 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 }
@@ -2197,9 +2198,9 @@ void QTextEdit::removeParagraph( int para )
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();
@@ -2210,7 +2211,7 @@ void QTextEdit::removeParagraph( int para )
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 }
@@ -2218,4 +2219,4 @@ void QTextEdit::removeParagraph( int para )
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 }
@@ -2241,6 +2242,6 @@ void QTextEdit::undo()
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
@@ -2254,4 +2255,4 @@ void QTextEdit::undo()
2254 if ( !c ) { 2255 if ( !c ) {
2255 drawCursor( TRUE ); 2256 drawCursor( TRUE );
2256 return; 2257 return;
2257 } 2258 }
@@ -2278,6 +2279,6 @@ void QTextEdit::redo()
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
@@ -2291,4 +2292,4 @@ void QTextEdit::redo()
2291 if ( !c ) { 2292 if ( !c ) {
2292 drawCursor( TRUE ); 2293 drawCursor( TRUE );
2293 return; 2294 return;
2294 } 2295 }
@@ -2317,3 +2318,3 @@ void QTextEdit::paste()
2317 if ( isReadOnly() ) 2318 if ( isReadOnly() )
2318 return; 2319 return;
2319 pasteSubType( "plain" ); 2320 pasteSubType( "plain" );
@@ -2326,3 +2327,3 @@ void QTextEdit::checkUndoRedoInfo( UndoRedoInfo::Type t )
2326 if ( undoRedoInfo.valid() && t != undoRedoInfo.type ) { 2327 if ( undoRedoInfo.valid() && t != undoRedoInfo.type ) {
2327 clearUndoRedo(); 2328 clearUndoRedo();
2328 } 2329 }
@@ -2340,3 +2341,3 @@ void QTextEdit::repaintChanged()
2340 if ( !isUpdatesEnabled() || !viewport()->isUpdatesEnabled() ) 2341 if ( !isUpdatesEnabled() || !viewport()->isUpdatesEnabled() )
2341 return; 2342 return;
2342 QPainter p( viewport() ); 2343 QPainter p( viewport() );
@@ -2358,3 +2359,3 @@ void QTextEdit::cut()
2358 if ( isReadOnly() ) 2359 if ( isReadOnly() )
2359 return; 2360 return;
2360 2361
@@ -2362,5 +2363,5 @@ void QTextEdit::cut()
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 }
@@ -2378,4 +2379,4 @@ void QTextEdit::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}
@@ -2389,3 +2390,3 @@ void QTextEdit::indent()
2389 if ( isReadOnly() ) 2390 if ( isReadOnly() )
2390 return; 2391 return;
2391 2392
@@ -2393,5 +2394,5 @@ void QTextEdit::indent()
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();
@@ -2411,3 +2412,3 @@ bool QTextEdit::focusNextPrevChild( bool n )
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 );
@@ -2415,5 +2416,5 @@ bool QTextEdit::focusNextPrevChild( bool n )
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;
@@ -2431,43 +2432,43 @@ void QTextEdit::setFormat( QTextFormat *f, int flags )
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 }
@@ -2481,5 +2482,5 @@ void QTextEdit::setPalette( const QPalette &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 }
@@ -2503,3 +2504,3 @@ void QTextEdit::setParagType( QStyleSheetItem::DisplayMode dm, QStyleSheetItem::
2503 if ( isReadOnly() ) 2504 if ( isReadOnly() )
2504 return; 2505 return;
2505 2506
@@ -2509,6 +2510,6 @@ void QTextEdit::setParagType( QStyleSheetItem::DisplayMode dm, QStyleSheetItem::
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 }
@@ -2522,12 +2523,12 @@ void QTextEdit::setParagType( QStyleSheetItem::DisplayMode dm, QStyleSheetItem::
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 }
@@ -2552,3 +2553,3 @@ void QTextEdit::setAlignment( int a )
2552 if ( isReadOnly() || block_set_alignment ) 2553 if ( isReadOnly() || block_set_alignment )
2553 return; 2554 return;
2554 2555
@@ -2558,6 +2559,6 @@ void QTextEdit::setAlignment( int a )
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 }
@@ -2571,4 +2572,4 @@ void QTextEdit::setAlignment( int a )
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 }
@@ -2580,4 +2581,4 @@ void QTextEdit::setAlignment( int a )
2580 if ( currentAlignment != a ) { 2581 if ( currentAlignment != a ) {
2581 currentAlignment = a; 2582 currentAlignment = a;
2582 emit currentAlignmentChanged( currentAlignment ); 2583 emit currentAlignmentChanged( currentAlignment );
2583 } 2584 }
@@ -2591,15 +2592,15 @@ void QTextEdit::updateCurrentFormat()
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 }
@@ -2607,6 +2608,6 @@ void QTextEdit::updateCurrentFormat()
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 }
@@ -2730,3 +2731,3 @@ QString QTextEdit::text() const
2730 if ( isReadOnly() ) 2731 if ( isReadOnly() )
2731 return doc->originalText(); 2732 return doc->originalText();
2732 return doc->text(); 2733 return doc->text();
@@ -2770,4 +2771,4 @@ void QTextEdit::setText( const QString &text, const QString &context )
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
@@ -2783,8 +2784,8 @@ void QTextEdit::setText( const QString &text, const QString &context )
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 }
@@ -2797,3 +2798,3 @@ void QTextEdit::setText( const QString &text, const QString &context )
2797 if ( isModified() ) 2798 if ( isModified() )
2798 setModified( FALSE ); 2799 setModified( FALSE );
2799 emit textChanged(); 2800 emit textChanged();
@@ -2862,3 +2863,3 @@ void QTextEdit::setText( const QString &text, const QString &context )
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{
@@ -2870,12 +2871,12 @@ bool QTextEdit::find( const QString &expr, bool cs, bool wo, bool forward,
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 }
@@ -2884,9 +2885,9 @@ bool QTextEdit::find( const QString &expr, bool cs, bool wo, bool 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 }
@@ -2899,3 +2900,3 @@ void QTextEdit::blinkCursor()
2899 if ( !cursorVisible ) 2900 if ( !cursorVisible )
2900 return; 2901 return;
2901 bool cv = cursorVisible; 2902 bool cv = cursorVisible;
@@ -2916,6 +2917,6 @@ void QTextEdit::setCursorPosition( int para, int index )
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
@@ -2942,3 +2943,3 @@ void QTextEdit::getCursorPosition( int *para, int *index ) const
2942 if ( !para || !index ) 2943 if ( !para || !index )
2943 return; 2944 return;
2944 *para = cursor->paragraph()->paragId(); 2945 *para = cursor->paragraph()->paragId();
@@ -2963,21 +2964,21 @@ void QTextEdit::getCursorPosition( int *para, int *index ) const
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
@@ -2995,3 +2996,3 @@ void QTextEdit::setSelection( int paraFrom, int indexFrom,
2995 if ( selNum != QTextDocument::Standard ) 2996 if ( selNum != QTextDocument::Standard )
2996 *cursor = oldCursor; 2997 *cursor = oldCursor;
2997 drawCursor( TRUE ); 2998 drawCursor( TRUE );
@@ -3020,12 +3021,12 @@ void QTextEdit::setSelection( int paraFrom, int indexFrom,
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 }
@@ -3081,3 +3082,3 @@ int QTextEdit::linesOfParagraph( int para ) const
3081 if ( !p ) 3082 if ( !p )
3082 return -1; 3083 return -1;
3083 return p->lines(); 3084 return p->lines();
@@ -3094,3 +3095,3 @@ int QTextEdit::paragraphLength( int para ) const
3094 if ( !p ) 3095 if ( !p )
3095 return -1; 3096 return -1;
3096 return p->length() - 1; 3097 return p->length() - 1;
@@ -3111,4 +3112,4 @@ int QTextEdit::lines() const
3111 while ( p ) { 3112 while ( p ) {
3112 l += p->lines(); 3113 l += p->lines();
3113 p = p->next(); 3114 p = p->next();
3114 } 3115 }
@@ -3130,3 +3131,3 @@ int QTextEdit::lineOfChar( int para, int index )
3130 if ( !p ) 3131 if ( !p )
3131 return -1; 3132 return -1;
3132 3133
@@ -3135,3 +3136,3 @@ int QTextEdit::lineOfChar( int para, int index )
3135 if ( !c ) 3136 if ( !c )
3136 return -1; 3137 return -1;
3137 3138
@@ -3145,5 +3146,5 @@ void QTextEdit::setModified( bool 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}
@@ -3162,3 +3163,3 @@ void QTextEdit::setModified()
3162 if ( !isModified() ) 3163 if ( !isModified() )
3163 setModified( TRUE ); 3164 setModified( TRUE );
3164} 3165}
@@ -3263,6 +3264,6 @@ void QTextEdit::startDrag()
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 }
@@ -3283,5 +3284,5 @@ void QTextEdit::selectAll( bool select )
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();
@@ -3297,11 +3298,11 @@ void QTextEdit::UndoRedoInfo::clear()
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 }
@@ -3327,4 +3328,4 @@ void QTextEdit::del()
3327 if ( doc->hasSelection( QTextDocument::Standard ) ) { 3328 if ( doc->hasSelection( QTextDocument::Standard ) ) {
3328 removeSelectedText(); 3329 removeSelectedText();
3329 return; 3330 return;
3330 } 3331 }
@@ -3406,3 +3407,3 @@ QBrush QTextEdit::paper() const
3406 if ( doc->paper() ) 3407 if ( doc->paper() )
3407 return *doc->paper(); 3408 return *doc->paper();
3408 return QBrush(); 3409 return QBrush();
@@ -3479,6 +3480,6 @@ void QTextEdit::append( const QString &text )
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 }
@@ -3491,3 +3492,3 @@ void QTextEdit::append( const QString &text )
3491 if ( cursor->index() > 0 ) 3492 if ( cursor->index() > 0 )
3492 cursor->splitAndInsertEmptyParagraph(); 3493 cursor->splitAndInsertEmptyParagraph();
3493 QTextCursor oldCursor2 = *cursor; 3494 QTextCursor oldCursor2 = *cursor;
@@ -3495,14 +3496,14 @@ void QTextEdit::append( const QString &text )
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 }
@@ -3514,3 +3515,3 @@ void QTextEdit::append( const QString &text )
3514 if ( !isReadOnly() ) 3515 if ( !isReadOnly() )
3515 cursorVisible = TRUE; 3516 cursorVisible = TRUE;
3516 setModified(); 3517 setModified();
@@ -3548,28 +3549,28 @@ bool QTextEdit::handleReadOnlyKeyEvent( QKeyEvent *e )
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
@@ -3578,9 +3579,9 @@ bool QTextEdit::handleReadOnlyKeyEvent( QKeyEvent *e )
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;
@@ -3588,10 +3589,10 @@ bool QTextEdit::handleReadOnlyKeyEvent( QKeyEvent *e )
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 }
@@ -3640,7 +3641,7 @@ void QTextEdit::scrollToAnchor( const QString& name )
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();
@@ -3649,14 +3650,14 @@ void QTextEdit::scrollToAnchor( const QString& name )
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 }
@@ -3693,3 +3694,3 @@ void QTextEdit::setDocument( QTextDocument *dc )
3693 if ( dc == doc ) 3694 if ( dc == doc )
3694 return; 3695 return;
3695 doc = dc; 3696 doc = dc;
@@ -3719,66 +3720,66 @@ void QTextEdit::pasteSubType( const QCString& subtype )
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 }
@@ -3797,3 +3798,3 @@ void QTextEdit::pasteSpecial( const QPoint& pt )
3797 if ( !st.isEmpty() ) 3798 if ( !st.isEmpty() )
3798 pasteSubType( st ); 3799 pasteSubType( st );
3799} 3800}
@@ -3805,35 +3806,35 @@ QCString QTextEdit::pickSpecial( QMimeSource* ms, bool always_ask, const QPoint&
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
@@ -3850,3 +3851,3 @@ QCString QTextEdit::pickSpecial( QMimeSource* ms, bool always_ask, const QPoint&
3850 3851
3851 \value NoWrap Do not wrap the text. 3852 \value NoWrap Do not wrap the text.
3852 3853
@@ -3888,3 +3889,3 @@ void QTextEdit::setWordWrap( WordWrap mode )
3888 if ( wrapMode == mode ) 3889 if ( wrapMode == mode )
3889 return; 3890 return;
3890 wrapMode = mode; 3891 wrapMode = mode;
@@ -3892,31 +3893,31 @@ void QTextEdit::setWordWrap( WordWrap 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 }
@@ -3945,13 +3946,13 @@ void QTextEdit::setWrapColumnOrWidth( int 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 }
@@ -3967,3 +3968,3 @@ int QTextEdit::wrapColumnOrWidth() const
3967 if ( wrapMode == WidgetWidth ) 3968 if ( wrapMode == WidgetWidth )
3968 return visibleWidth(); 3969 return visibleWidth();
3969 return wrapWidth; 3970 return wrapWidth;
@@ -4000,3 +4001,3 @@ void QTextEdit::setWrapPolicy( WrapPolicy policy )
4000 if ( wPolicy == policy ) 4001 if ( wPolicy == policy )
4001 return; 4002 return;
4002 wPolicy = policy; 4003 wPolicy = policy;
@@ -4004,5 +4005,5 @@ void QTextEdit::setWrapPolicy( WrapPolicy policy )
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() );
@@ -4037,3 +4038,3 @@ void QTextEdit::clear()
4037 if ( cursor->isValid() ) 4038 if ( cursor->isValid() )
4038 cursor->restoreState(); 4039 cursor->restoreState();
4039 doc->clear( TRUE ); 4040 doc->clear( TRUE );
@@ -4123,8 +4124,8 @@ bool QTextEdit::getFormat( int para, int index, QFont *font, QColor *color, Vert
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();
@@ -4154,12 +4155,12 @@ bool QTextEdit::getFormat( int para, int index, QFont *font, QColor *color, Vert
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();
@@ -4190,5 +4191,5 @@ QPopupMenu *QTextEdit::createPopupMenu( const QPoint& pos )
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 }
@@ -4196,10 +4197,10 @@ QPopupMenu *QTextEdit::createPopupMenu( const QPoint& pos )
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 }
@@ -4336,4 +4337,4 @@ void QTextEdit::sync()
4336 while ( lastFormatted ) { 4337 while ( lastFormatted ) {
4337 lastFormatted->format(); 4338 lastFormatted->format();
4338 lastFormatted = lastFormatted->next(); 4339 lastFormatted = lastFormatted->next();
4339 } 4340 }
@@ -4348,13 +4349,13 @@ void QTextEdit::setEnabled( bool 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 }
@@ -4374,5 +4375,5 @@ void QTextEdit::setSelectionAttributes( int selNum, const QColor &back, bool inv
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 );
@@ -4385,6 +4386,6 @@ void QTextEdit::windowActivationChange( bool )
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}
@@ -4394,3 +4395,3 @@ void QTextEdit::setReadOnly( bool b )
4394 if ( readonly == b ) 4395 if ( readonly == b )
4395 return; 4396 return;
4396 readonly = b; 4397 readonly = b;
@@ -4398,5 +4399,5 @@ void QTextEdit::setReadOnly( bool b )
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
@@ -4423,3 +4424,3 @@ QRect QTextEdit::paragraphRect( int para ) const
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();
@@ -4437,3 +4438,3 @@ int QTextEdit::paragraphAt( const QPoint &pos ) const
4437 if ( c.paragraph() ) 4438 if ( c.paragraph() )
4438 return c.paragraph()->paragId(); 4439 return c.paragraph()->paragId();
4439 return -1; 4440 return -1;
@@ -4453,5 +4454,5 @@ int QTextEdit::charAt( const QPoint &pos, int *para ) const
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 }
@@ -4466,3 +4467,3 @@ void QTextEdit::setParagraphBackgroundColor( int para, const QColor &bg )
4466 if ( !p ) 4467 if ( !p )
4467 return; 4468 return;
4468 p->setBackgroundColor( bg ); 4469 p->setBackgroundColor( bg );
@@ -4479,3 +4480,3 @@ void QTextEdit::clearParagraphBackground( int para )
4479 if ( !p ) 4480 if ( !p )
4480 return; 4481 return;
4481 p->clearBackgroundColor(); 4482 p->clearBackgroundColor();
@@ -4493,6 +4494,6 @@ QColor QTextEdit::paragraphBackgroundColor( int para ) const
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();
@@ -4533,5 +4534,5 @@ void QTextEdit::ensureFormatted( QTextParagraph *p )
4533 while ( !p->isValid() ) { 4534 while ( !p->isValid() ) {
4534 if ( !lastFormatted ) 4535 if ( !lastFormatted )
4535 return; 4536 return;
4536 formatMore(); 4537 formatMore();
4537 } 4538 }
@@ -4543,26 +4544,26 @@ void QTextEdit::updateCursor( const QPoint & pos )
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