Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/text/qtextcontrol.cpp

    r2 r561  
    22**
    33** 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)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** 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.
    3838** $QT_END_LICENSE$
    3939**
     
    5656#include <qtimer.h>
    5757#include "private/qtextdocumentlayout_p.h"
     58#include "private/qabstracttextdocumentlayout_p.h"
    5859#include "private/qtextedit_p.h"
    5960#include "qtextdocument.h"
     
    8384#include "private/qshortcutmap_p.h"
    8485#include <qkeysequence.h>
    85 #define ACCEL_KEY(k) (!qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? QLatin1String("\t") + QString(QKeySequence(k)) : QString())
     86#define ACCEL_KEY(k) (!qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? QLatin1Char('\t') + QString(QKeySequence(k)) : QString())
    8687#else
    8788#define ACCEL_KEY(k) QString()
     
    127128      isEnabled(true),
    128129      hadSelectionOnMousePress(false),
     130      ignoreUnusedNavigationEvents(false),
    129131      openExternalLinks(false)
    130132{}
     
    265267    q->ensureCursorVisible();
    266268
     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
    267281    if (moved) {
    268282        if (cursor.position() != oldCursorPos)
    269283            emit q->cursorPositionChanged();
    270284        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) {
    275286        return false;
    276287    }
    277 #endif
    278288
    279289    selectionChanged(/*forceEmitSelectionChanged =*/(mode == QTextCursor::KeepAnchor));
     
    395405    setContent(format, text, document);
    396406
    397     QWidget *parentWidget = qobject_cast<QWidget*>(q->parent());
     407    QWidget *parentWidget = qobject_cast<QWidget*>(parent);
    398408    if (parentWidget) {
    399409        QTextOption opt = doc->defaultTextOption();
     
    504514
    505515    Qt::DropActions actions = Qt::CopyAction;
    506     if (interactionFlags & Qt::TextEditable)
     516    Qt::DropAction action;
     517    if (interactionFlags & Qt::TextEditable) {
    507518        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    }
    509523
    510524    if (action == Qt::MoveAction && drag->target() != contextWidget)
     
    906920        case QEvent::MouseButtonPress: {
    907921            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(),
    909923                               ev->buttons(), ev->globalPos());
    910924            break; }
     
    974988        case QEvent::GraphicsSceneMousePress: {
    975989            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(),
    977991                               ev->screenPos());
    978992            break; }
     
    12221236    }
    12231237    else if (e == QKeySequence::DeleteEndOfWord) {
    1224         cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor);
     1238        if (!cursor.hasSelection())
     1239            cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor);
    12251240        cursor.removeSelectedText();
    12261241    }
    12271242    else if (e == QKeySequence::DeleteStartOfWord) {
    1228         cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor);
     1243        if (!cursor.hasSelection())
     1244            cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor);
    12291245        cursor.removeSelectedText();
    12301246    }
     
    12891305{
    12901306    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);
    12921310}
    12931311
     
    14581476}
    14591477
    1460 void QTextControlPrivate::mousePressEvent(Qt::MouseButton button, const QPointF &pos, Qt::KeyboardModifiers modifiers,
     1478void QTextControlPrivate::mousePressEvent(QEvent *e, Qt::MouseButton button, const QPointF &pos, Qt::KeyboardModifiers modifiers,
    14611479                                          Qt::MouseButtons buttons, const QPoint &globalPos)
    14621480{
     
    14721490        }
    14731491    }
    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    }
    14791497
    14801498    cursorIsFocusIndicator = false;
     
    15001518    } else {
    15011519        int cursorPos = q->hitTest(pos, Qt::FuzzyHit);
    1502         if (cursorPos == -1)
     1520        if (cursorPos == -1) {
     1521            e->ignore();
    15031522            return;
     1523        }
    15041524
    15051525#if !defined(QT_NO_IM)
     
    15121532                ctx->mouseHandler(cursorPos - cursor.position(), &ev);
    15131533            }
    1514             if (!layout->preeditAreaText().isEmpty())
     1534            if (!layout->preeditAreaText().isEmpty()) {
     1535                e->ignore();
    15151536                return;
     1537            }
    15161538        }
    15171539#endif
     
    16121634            emit q->cursorPositionChanged();
    16131635        _q_updateCurrentCharFormatAndSelection();
     1636#ifndef QT_NO_IM
     1637        if (QInputContext *ic = inputContext()) {
     1638            ic->update();
     1639        }
     1640#endif //QT_NO_IM
    16141641    } else {
    16151642        //emit q->visibilityRequest(QRectF(mousePos, QSizeF(1, 1)));
     
    17131740
    17141741    trippleClickPoint = pos;
    1715     trippleClickTimer.start(qApp->doubleClickInterval(), q);
     1742    trippleClickTimer.start(QApplication::doubleClickInterval(), q);
    17161743    if (doEmit) {
    17171744        selectionChanged();
     
    18141841void QTextControlPrivate::inputMethodEvent(QInputMethodEvent *e)
    18151842{
     1843    Q_Q(QTextControl);
    18161844    if (!(interactionFlags & Qt::TextEditable) || cursor.isNull()) {
    18171845        e->ignore();
    18181846        return;
    18191847    }
     1848    bool isGettingInput = !e->commitString().isEmpty()
     1849            || e->preeditString() != cursor.block().layout()->preeditAreaText()
     1850            || e->replacementLength() > 0;
     1851
    18201852    cursor.beginEditBlock();
    1821 
    1822     cursor.removeSelectedText();
     1853    if (isGettingInput) {
     1854        cursor.removeSelectedText();
     1855    }
    18231856
    18241857    // insert commit string
     
    18301863    }
    18311864
     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
    18321877    QTextBlock block = cursor.block();
    18331878    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());
    18351881    QList<QTextLayout::FormatRange> overrides;
    18361882    preeditCursor = e->preeditString().length();
     
    18661912        return QVariant(d->cursor.charFormat().font());
    18671913    case Qt::ImCursorPosition:
    1868         return QVariant(d->cursor.selectionEnd() - block.position());
     1914        return QVariant(d->cursor.position() - block.position());
    18691915    case Qt::ImSurroundingText:
    18701916        return QVariant(block.text());
    18711917    case Qt::ImCurrentSelection:
    18721918        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()));
    18731923    default:
    18741924        return QVariant();
     
    18891939    if (e->gotFocus()) {
    18901940#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            ))) {
    18921946#endif
    18931947        cursorOn = (interactionFlags & Qt::TextSelectableByKeyboard);
     
    22212275}
    22222276
     2277bool QTextControl::ignoreUnusedNavigationEvents() const
     2278{
     2279    Q_D(const QTextControl);
     2280    return d->ignoreUnusedNavigationEvents;
     2281}
     2282
     2283void QTextControl::setIgnoreUnusedNavigationEvents(bool ignore)
     2284{
     2285    Q_D(QTextControl);
     2286    d->ignoreUnusedNavigationEvents = ignore;
     2287}
     2288
    22232289void QTextControl::moveCursor(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode)
    22242290{
     
    22632329#ifndef QT_NO_PRINTER
    22642330    Q_D(const QTextControl);
    2265     if (printer && !printer->isValid())
     2331    if (!printer || !printer->isValid())
    22662332        return;
    22672333    QTextDocument *tempDoc = 0;
     
    22772343        QTextCursor(tempDoc).insertFragment(d->cursor.selection());
    22782344        doc = tempDoc;
     2345
     2346        // copy the custom object handlers
     2347        doc->documentLayout()->d_func()->handlers = d->doc->documentLayout()->d_func()->handlers;
    22792348    }
    22802349    doc->print(printer);
Note: See TracChangeset for help on using the changeset viewer.