439 QObject::connect(doc, SIGNAL(contentsChanged()), q, SLOT(_q_updateCurrentCharFormatAndSelection())); |
439 QObject::connect(doc, SIGNAL(contentsChanged()), q, SLOT(_q_updateCurrentCharFormatAndSelection())); |
440 QObject::connect(doc, SIGNAL(cursorPositionChanged(QTextCursor)), q, SLOT(_q_emitCursorPosChanged(QTextCursor))); |
440 QObject::connect(doc, SIGNAL(cursorPositionChanged(QTextCursor)), q, SLOT(_q_emitCursorPosChanged(QTextCursor))); |
441 QObject::connect(doc, SIGNAL(documentLayoutChanged()), q, SLOT(_q_documentLayoutChanged())); |
441 QObject::connect(doc, SIGNAL(documentLayoutChanged()), q, SLOT(_q_documentLayoutChanged())); |
442 |
442 |
443 // convenience signal forwards |
443 // convenience signal forwards |
444 QObject::connect(doc, SIGNAL(contentsChanged()), q, SIGNAL(textChanged())); |
|
445 QObject::connect(doc, SIGNAL(undoAvailable(bool)), q, SIGNAL(undoAvailable(bool))); |
444 QObject::connect(doc, SIGNAL(undoAvailable(bool)), q, SIGNAL(undoAvailable(bool))); |
446 QObject::connect(doc, SIGNAL(redoAvailable(bool)), q, SIGNAL(redoAvailable(bool))); |
445 QObject::connect(doc, SIGNAL(redoAvailable(bool)), q, SIGNAL(redoAvailable(bool))); |
447 QObject::connect(doc, SIGNAL(modificationChanged(bool)), q, SIGNAL(modificationChanged(bool))); |
446 QObject::connect(doc, SIGNAL(modificationChanged(bool)), q, SIGNAL(modificationChanged(bool))); |
448 QObject::connect(doc, SIGNAL(blockCountChanged(int)), q, SIGNAL(blockCountChanged(int))); |
447 QObject::connect(doc, SIGNAL(blockCountChanged(int)), q, SIGNAL(blockCountChanged(int))); |
449 } |
448 } |
450 |
449 |
451 bool previousUndoRedoState = doc->isUndoRedoEnabled(); |
450 bool previousUndoRedoState = doc->isUndoRedoEnabled(); |
452 if (!document) |
451 if (!document) |
453 doc->setUndoRedoEnabled(false); |
452 doc->setUndoRedoEnabled(false); |
454 |
453 |
|
454 //Saving the index save some time. |
|
455 static int contentsChangedIndex = QTextDocument::staticMetaObject.indexOfSignal("contentsChanged()"); |
|
456 static int textChangedIndex = QTextControl::staticMetaObject.indexOfSignal("textChanged()"); |
455 // avoid multiple textChanged() signals being emitted |
457 // avoid multiple textChanged() signals being emitted |
456 QObject::disconnect(doc, SIGNAL(contentsChanged()), q, SIGNAL(textChanged())); |
458 QMetaObject::disconnect(doc, contentsChangedIndex, q, textChangedIndex); |
457 |
459 |
458 if (!text.isEmpty()) { |
460 if (!text.isEmpty()) { |
459 // clear 'our' cursor for insertion to prevent |
461 // clear 'our' cursor for insertion to prevent |
460 // the emission of the cursorPositionChanged() signal. |
462 // the emission of the cursorPositionChanged() signal. |
461 // instead we emit it only once at the end instead of |
463 // instead we emit it only once at the end instead of |
486 } else if (clearDocument) { |
488 } else if (clearDocument) { |
487 doc->clear(); |
489 doc->clear(); |
488 } |
490 } |
489 cursor.setCharFormat(charFormatForInsertion); |
491 cursor.setCharFormat(charFormatForInsertion); |
490 |
492 |
491 QObject::connect(doc, SIGNAL(contentsChanged()), q, SIGNAL(textChanged())); |
493 QMetaObject::connect(doc, contentsChangedIndex, q, textChangedIndex); |
492 emit q->textChanged(); |
494 emit q->textChanged(); |
493 if (!document) |
495 if (!document) |
494 doc->setUndoRedoEnabled(previousUndoRedoState); |
496 doc->setUndoRedoEnabled(previousUndoRedoState); |
495 _q_updateCurrentCharFormatAndSelection(); |
497 _q_updateCurrentCharFormatAndSelection(); |
496 if (!document) |
498 if (!document) |
743 |
745 |
744 void QTextControl::undo() |
746 void QTextControl::undo() |
745 { |
747 { |
746 Q_D(QTextControl); |
748 Q_D(QTextControl); |
747 d->repaintSelection(); |
749 d->repaintSelection(); |
|
750 const int oldCursorPos = d->cursor.position(); |
748 d->doc->undo(&d->cursor); |
751 d->doc->undo(&d->cursor); |
|
752 if (d->cursor.position() != oldCursorPos) |
|
753 emit cursorPositionChanged(); |
|
754 emit microFocusChanged(); |
749 ensureCursorVisible(); |
755 ensureCursorVisible(); |
750 } |
756 } |
751 |
757 |
752 void QTextControl::redo() |
758 void QTextControl::redo() |
753 { |
759 { |
754 Q_D(QTextControl); |
760 Q_D(QTextControl); |
755 d->repaintSelection(); |
761 d->repaintSelection(); |
|
762 const int oldCursorPos = d->cursor.position(); |
756 d->doc->redo(&d->cursor); |
763 d->doc->redo(&d->cursor); |
|
764 if (d->cursor.position() != oldCursorPos) |
|
765 emit cursorPositionChanged(); |
|
766 emit microFocusChanged(); |
757 ensureCursorVisible(); |
767 ensureCursorVisible(); |
758 } |
768 } |
759 |
769 |
760 QTextControl::QTextControl(QObject *parent) |
770 QTextControl::QTextControl(QObject *parent) |
761 : QObject(*new QTextControlPrivate, parent) |
771 : QObject(*new QTextControlPrivate, parent) |
1227 #ifndef QT_NO_CLIPBOARD |
1239 #ifndef QT_NO_CLIPBOARD |
1228 else if (e == QKeySequence::Cut) { |
1240 else if (e == QKeySequence::Cut) { |
1229 q->cut(); |
1241 q->cut(); |
1230 } |
1242 } |
1231 else if (e == QKeySequence::Paste) { |
1243 else if (e == QKeySequence::Paste) { |
1232 q->paste(); |
1244 QClipboard::Mode mode = QClipboard::Clipboard; |
|
1245 #ifdef Q_WS_X11 |
|
1246 if (e->modifiers() == (Qt::CTRL | Qt::SHIFT) && e->key() == Qt::Key_Insert) |
|
1247 mode = QClipboard::Selection; |
|
1248 #endif |
|
1249 q->paste(mode); |
1233 } |
1250 } |
1234 #endif |
1251 #endif |
1235 else if (e == QKeySequence::Delete) { |
1252 else if (e == QKeySequence::Delete) { |
1236 QTextCursor localCursor = cursor; |
1253 QTextCursor localCursor = cursor; |
1237 localCursor.deleteChar(); |
1254 localCursor.deleteChar(); |