Changeset 561 for trunk/src/gui/text/qtextcontrol.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/text/qtextcontrol.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 56 56 #include <qtimer.h> 57 57 #include "private/qtextdocumentlayout_p.h" 58 #include "private/qabstracttextdocumentlayout_p.h" 58 59 #include "private/qtextedit_p.h" 59 60 #include "qtextdocument.h" … … 83 84 #include "private/qshortcutmap_p.h" 84 85 #include <qkeysequence.h> 85 #define ACCEL_KEY(k) (!qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? QLatin1 String("\t") + QString(QKeySequence(k)) : QString())86 #define ACCEL_KEY(k) (!qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? QLatin1Char('\t') + QString(QKeySequence(k)) : QString()) 86 87 #else 87 88 #define ACCEL_KEY(k) QString() … … 127 128 isEnabled(true), 128 129 hadSelectionOnMousePress(false), 130 ignoreUnusedNavigationEvents(false), 129 131 openExternalLinks(false) 130 132 {} … … 265 267 q->ensureCursorVisible(); 266 268 269 bool ignoreNavigationEvents = ignoreUnusedNavigationEvents; 270 bool isNavigationEvent = e->key() == Qt::Key_Up || e->key() == Qt::Key_Down; 271 272 #ifdef QT_KEYPAD_NAVIGATION 273 ignoreNavigationEvents = ignoreNavigationEvents || QApplication::keypadNavigationEnabled(); 274 isNavigationEvent = isNavigationEvent || 275 (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional 276 && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right)); 277 #else 278 isNavigationEvent = isNavigationEvent || e->key() == Qt::Key_Left || e->key() == Qt::Key_Right; 279 #endif 280 267 281 if (moved) { 268 282 if (cursor.position() != oldCursorPos) 269 283 emit q->cursorPositionChanged(); 270 284 emit q->microFocusChanged(); 271 } 272 #ifdef QT_KEYPAD_NAVIGATION 273 else if (QApplication::keypadNavigationEnabled() 274 && (e->key() == Qt::Key_Up || e->key() == Qt::Key_Down)) { 285 } else if (ignoreNavigationEvents && isNavigationEvent) { 275 286 return false; 276 287 } 277 #endif278 288 279 289 selectionChanged(/*forceEmitSelectionChanged =*/(mode == QTextCursor::KeepAnchor)); … … 395 405 setContent(format, text, document); 396 406 397 QWidget *parentWidget = qobject_cast<QWidget*>( q->parent());407 QWidget *parentWidget = qobject_cast<QWidget*>(parent); 398 408 if (parentWidget) { 399 409 QTextOption opt = doc->defaultTextOption(); … … 504 514 505 515 Qt::DropActions actions = Qt::CopyAction; 506 if (interactionFlags & Qt::TextEditable) 516 Qt::DropAction action; 517 if (interactionFlags & Qt::TextEditable) { 507 518 actions |= Qt::MoveAction; 508 Qt::DropAction action = drag->exec(actions, Qt::MoveAction); 519 action = drag->exec(actions, Qt::MoveAction); 520 } else { 521 action = drag->exec(actions, Qt::CopyAction); 522 } 509 523 510 524 if (action == Qt::MoveAction && drag->target() != contextWidget) … … 906 920 case QEvent::MouseButtonPress: { 907 921 QMouseEvent *ev = static_cast<QMouseEvent *>(e); 908 d->mousePressEvent(ev ->button(), matrix.map(ev->pos()), ev->modifiers(),922 d->mousePressEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(), 909 923 ev->buttons(), ev->globalPos()); 910 924 break; } … … 974 988 case QEvent::GraphicsSceneMousePress: { 975 989 QGraphicsSceneMouseEvent *ev = static_cast<QGraphicsSceneMouseEvent *>(e); 976 d->mousePressEvent(ev ->button(), matrix.map(ev->pos()), ev->modifiers(), ev->buttons(),990 d->mousePressEvent(ev, ev->button(), matrix.map(ev->pos()), ev->modifiers(), ev->buttons(), 977 991 ev->screenPos()); 978 992 break; } … … 1222 1236 } 1223 1237 else if (e == QKeySequence::DeleteEndOfWord) { 1224 cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor); 1238 if (!cursor.hasSelection()) 1239 cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor); 1225 1240 cursor.removeSelectedText(); 1226 1241 } 1227 1242 else if (e == QKeySequence::DeleteStartOfWord) { 1228 cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor); 1243 if (!cursor.hasSelection()) 1244 cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor); 1229 1245 cursor.removeSelectedText(); 1230 1246 } … … 1289 1305 { 1290 1306 Q_Q(QTextControl); 1291 emit q->updateRequest(q->blockBoundingRect(block)); 1307 QRectF br = q->blockBoundingRect(block); 1308 br.setRight(qreal(INT_MAX)); // the block might have shrunk 1309 emit q->updateRequest(br); 1292 1310 } 1293 1311 … … 1458 1476 } 1459 1477 1460 void QTextControlPrivate::mousePressEvent(Q t::MouseButton button, const QPointF &pos, Qt::KeyboardModifiers modifiers,1478 void QTextControlPrivate::mousePressEvent(QEvent *e, Qt::MouseButton button, const QPointF &pos, Qt::KeyboardModifiers modifiers, 1461 1479 Qt::MouseButtons buttons, const QPoint &globalPos) 1462 1480 { … … 1472 1490 } 1473 1491 } 1474 if (!(button & Qt::LeftButton) )1475 return;1476 1477 if (!((interactionFlags & Qt::TextSelectableByMouse) || (interactionFlags & Qt::TextEditable)))1478 return;1492 if (!(button & Qt::LeftButton) || 1493 !((interactionFlags & Qt::TextSelectableByMouse) || (interactionFlags & Qt::TextEditable))) { 1494 e->ignore(); 1495 return; 1496 } 1479 1497 1480 1498 cursorIsFocusIndicator = false; … … 1500 1518 } else { 1501 1519 int cursorPos = q->hitTest(pos, Qt::FuzzyHit); 1502 if (cursorPos == -1) 1520 if (cursorPos == -1) { 1521 e->ignore(); 1503 1522 return; 1523 } 1504 1524 1505 1525 #if !defined(QT_NO_IM) … … 1512 1532 ctx->mouseHandler(cursorPos - cursor.position(), &ev); 1513 1533 } 1514 if (!layout->preeditAreaText().isEmpty()) 1534 if (!layout->preeditAreaText().isEmpty()) { 1535 e->ignore(); 1515 1536 return; 1537 } 1516 1538 } 1517 1539 #endif … … 1612 1634 emit q->cursorPositionChanged(); 1613 1635 _q_updateCurrentCharFormatAndSelection(); 1636 #ifndef QT_NO_IM 1637 if (QInputContext *ic = inputContext()) { 1638 ic->update(); 1639 } 1640 #endif //QT_NO_IM 1614 1641 } else { 1615 1642 //emit q->visibilityRequest(QRectF(mousePos, QSizeF(1, 1))); … … 1713 1740 1714 1741 trippleClickPoint = pos; 1715 trippleClickTimer.start( qApp->doubleClickInterval(), q);1742 trippleClickTimer.start(QApplication::doubleClickInterval(), q); 1716 1743 if (doEmit) { 1717 1744 selectionChanged(); … … 1814 1841 void QTextControlPrivate::inputMethodEvent(QInputMethodEvent *e) 1815 1842 { 1843 Q_Q(QTextControl); 1816 1844 if (!(interactionFlags & Qt::TextEditable) || cursor.isNull()) { 1817 1845 e->ignore(); 1818 1846 return; 1819 1847 } 1848 bool isGettingInput = !e->commitString().isEmpty() 1849 || e->preeditString() != cursor.block().layout()->preeditAreaText() 1850 || e->replacementLength() > 0; 1851 1820 1852 cursor.beginEditBlock(); 1821 1822 cursor.removeSelectedText(); 1853 if (isGettingInput) { 1854 cursor.removeSelectedText(); 1855 } 1823 1856 1824 1857 // insert commit string … … 1830 1863 } 1831 1864 1865 for (int i = 0; i < e->attributes().size(); ++i) { 1866 const QInputMethodEvent::Attribute &a = e->attributes().at(i); 1867 if (a.type == QInputMethodEvent::Selection) { 1868 QTextCursor oldCursor = cursor; 1869 int blockStart = a.start + cursor.block().position(); 1870 cursor.setPosition(blockStart, QTextCursor::MoveAnchor); 1871 cursor.setPosition(blockStart + a.length, QTextCursor::KeepAnchor); 1872 q->ensureCursorVisible(); 1873 repaintOldAndNewSelection(oldCursor); 1874 } 1875 } 1876 1832 1877 QTextBlock block = cursor.block(); 1833 1878 QTextLayout *layout = block.layout(); 1834 layout->setPreeditArea(cursor.position() - block.position(), e->preeditString()); 1879 if (isGettingInput) 1880 layout->setPreeditArea(cursor.position() - block.position(), e->preeditString()); 1835 1881 QList<QTextLayout::FormatRange> overrides; 1836 1882 preeditCursor = e->preeditString().length(); … … 1866 1912 return QVariant(d->cursor.charFormat().font()); 1867 1913 case Qt::ImCursorPosition: 1868 return QVariant(d->cursor. selectionEnd() - block.position());1914 return QVariant(d->cursor.position() - block.position()); 1869 1915 case Qt::ImSurroundingText: 1870 1916 return QVariant(block.text()); 1871 1917 case Qt::ImCurrentSelection: 1872 1918 return QVariant(d->cursor.selectedText()); 1919 case Qt::ImMaximumTextLength: 1920 return QVariant(); // No limit. 1921 case Qt::ImAnchorPosition: 1922 return QVariant(qBound(0, d->cursor.anchor() - block.position(), block.length())); 1873 1923 default: 1874 1924 return QVariant(); … … 1889 1939 if (e->gotFocus()) { 1890 1940 #ifdef QT_KEYPAD_NAVIGATION 1891 if (!QApplication::keypadNavigationEnabled() || (hasEditFocus && e->reason() == Qt::PopupFocusReason)) { 1941 if (!QApplication::keypadNavigationEnabled() || (hasEditFocus && (e->reason() == Qt::PopupFocusReason 1942 #ifdef Q_OS_SYMBIAN 1943 || e->reason() == Qt::ActiveWindowFocusReason 1944 #endif 1945 ))) { 1892 1946 #endif 1893 1947 cursorOn = (interactionFlags & Qt::TextSelectableByKeyboard); … … 2221 2275 } 2222 2276 2277 bool QTextControl::ignoreUnusedNavigationEvents() const 2278 { 2279 Q_D(const QTextControl); 2280 return d->ignoreUnusedNavigationEvents; 2281 } 2282 2283 void QTextControl::setIgnoreUnusedNavigationEvents(bool ignore) 2284 { 2285 Q_D(QTextControl); 2286 d->ignoreUnusedNavigationEvents = ignore; 2287 } 2288 2223 2289 void QTextControl::moveCursor(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode) 2224 2290 { … … 2263 2329 #ifndef QT_NO_PRINTER 2264 2330 Q_D(const QTextControl); 2265 if ( printer &&!printer->isValid())2331 if (!printer || !printer->isValid()) 2266 2332 return; 2267 2333 QTextDocument *tempDoc = 0; … … 2277 2343 QTextCursor(tempDoc).insertFragment(d->cursor.selection()); 2278 2344 doc = tempDoc; 2345 2346 // copy the custom object handlers 2347 doc->documentLayout()->d_func()->handlers = d->doc->documentLayout()->d_func()->handlers; 2279 2348 } 2280 2349 doc->print(printer);
Note:
See TracChangeset
for help on using the changeset viewer.