Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/widgets/qlineedit.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    140140    The length of the text can be constrained to maxLength(). The text
    141141    can be arbitrarily constrained using a validator() or an
    142     inputMask(), or both.
     142    inputMask(), or both. When switching between a validator and an input mask
     143    on the same line edit, it is best to clear the validator or input mask to
     144    prevent undefined behavior.
     145
    143146
    144147    A related class is QTextEdit which allows multi-line, rich text
     
    384387}
    385388
    386 // ### Qt 4.7: remove this #if guard
    387 #if (QT_VERSION >= 0x407000) || defined(Q_WS_MAEMO_5)
    388389/*!
    389390    \since 4.7
     
    415416    }
    416417}
    417 #endif
    418418
    419419/*!
     
    543543        return;
    544544    Qt::InputMethodHints imHints = inputMethodHints();
    545     if (mode == Password) {
     545    if (mode == Password || mode == NoEcho) {
    546546        imHints |= Qt::ImhHiddenText;
    547547    } else {
    548548        imHints &= ~Qt::ImhHiddenText;
     549    }
     550    if (mode != Normal) {
     551        imHints |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
     552    } else {
     553        imHints &= ~(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
    549554    }
    550555    setInputMethodHints(imHints);
     
    16441649                    if (!event->text().isEmpty() && event->text().at(0).isPrint()
    16451650                        && !isReadOnly())
    1646                     {
    16471651                        setEditFocus(true);
    1648 #ifndef Q_OS_SYMBIAN
    1649                         clear();
    1650 #endif
    1651                     } else {
     1652                    else {
    16521653                        event->ignore();
    16531654                        return;
     
    16661667#endif
    16671668    d->control->processKeyEvent(event);
    1668     if (event->isAccepted())
     1669    if (event->isAccepted()) {
     1670        if (layoutDirection() != d->control->layoutDirection())
     1671            setLayoutDirection(d->control->layoutDirection());
    16691672        d->control->setCursorBlinkPeriod(0);
     1673    }
    16701674}
    16711675
     
    17051709    if (QApplication::keypadNavigationEnabled()
    17061710        && hasFocus() && !hasEditFocus()
    1707         && !e->preeditString().isEmpty()) {
     1711        && !e->preeditString().isEmpty())
    17081712        setEditFocus(true);
    1709 #ifndef Q_OS_SYMBIAN
    1710         selectAll();        // so text is replaced rather than appended to
    1711 #endif
    1712     }
    17131713#endif
    17141714
     
    18671867
    18681868    QFontMetrics fm = fontMetrics();
    1869     Qt::Alignment va = QStyle::visualAlignment(layoutDirection(), QFlag(d->alignment));
     1869    Qt::Alignment va = QStyle::visualAlignment(d->control->layoutDirection(), QFlag(d->alignment));
    18701870    switch (va & Qt::AlignVertical_Mask) {
    18711871     case Qt::AlignBottom:
     
    18821882    QRect lineRect(r.x() + d->horizontalMargin, d->vscroll, r.width() - 2*d->horizontalMargin, fm.height());
    18831883
     1884    int minLB = qMax(0, -fm.minLeftBearing());
     1885    int minRB = qMax(0, -fm.minRightBearing());
     1886
    18841887    if (d->control->text().isEmpty()) {
    18851888        if (!hasFocus() && !d->placeholderText.isEmpty()) {
     
    18881891            QPen oldpen = p.pen();
    18891892            p.setPen(col);
    1890             p.drawText(lineRect, va, d->placeholderText);
     1893            lineRect.adjust(minLB, 0, 0, 0);
     1894            QString elidedText = fm.elidedText(d->placeholderText, Qt::ElideRight, lineRect.width());
     1895            p.drawText(lineRect, va, elidedText);
    18911896            p.setPen(oldpen);
    18921897            return;
     
    19021907    // minLB, minRB), the line edit rect (lineRect) and the cursor position
    19031908    // (cix).
    1904     int minLB = qMax(0, -fm.minLeftBearing());
    1905     int minRB = qMax(0, -fm.minRightBearing());
    19061909    int widthUsed = qRound(d->control->naturalTextWidth()) + 1 + minRB;
    19071910    if ((minLB + widthUsed) <=  lineRect.width()) {
     
    19301933        // right
    19311934        d->hscroll = widthUsed - lineRect.width() + 1;
    1932     }
     1935    } else {
     1936        //in case the text is bigger than the lineedit, the hscroll can never be negative
     1937        d->hscroll = qMax(0, d->hscroll);
     1938    }
     1939
    19331940    // the y offset is there to keep the baseline constant in case we have script changes in the text.
    19341941    QPoint topLeft = lineRect.topLeft() - QPoint(d->hscroll, d->control->ascent() - fm.ascent());
     
    19501957        flags |= QLineControl::DrawSelections;
    19511958        // Palette only used for selections/mask and may not be in sync
    1952         if(d->control->palette() != pal)
     1959        if (d->control->palette() != pal
     1960           || d->control->palette().currentColorGroup() != pal.currentColorGroup())
    19531961            d->control->setPalette(pal);
    19541962    }
     
    20532061void QLineEdit::contextMenuEvent(QContextMenuEvent *event)
    20542062{
    2055     QPointer<QMenu> menu = createStandardContextMenu();
    2056     menu->exec(event->globalPos());
    2057     delete menu;
    2058 }
    2059 
    2060 #if defined(Q_WS_WIN)
     2063    if (QMenu *menu = createStandardContextMenu()) {
     2064        menu->setAttribute(Qt::WA_DeleteOnClose);
     2065        menu->popup(event->globalPos());
     2066    }
     2067}
     2068
     2069#if defined(Q_WS_WIN) || defined(Q_WS_X11)
    20612070    extern bool qt_use_rtl_extensions;
    20622071#endif
     
    21302139#endif
    21312140
    2132 #if defined(Q_WS_WIN)
     2141#if defined(Q_WS_WIN) || defined(Q_WS_X11)
    21332142    if (!d->control->isReadOnly() && qt_use_rtl_extensions) {
    21342143#else
     
    21632172        }
    21642173        update();
    2165         break;
    2166     case QEvent::LayoutDirectionChange:
    2167         d->control->setLayoutDirection(layoutDirection());
    21682174        break;
    21692175    default:
Note: See TracChangeset for help on using the changeset viewer.