Changeset 846 for trunk/src/gui/widgets/qlineedit.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/widgets/qlineedit.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 140 140 The length of the text can be constrained to maxLength(). The text 141 141 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 143 146 144 147 A related class is QTextEdit which allows multi-line, rich text … … 384 387 } 385 388 386 // ### Qt 4.7: remove this #if guard387 #if (QT_VERSION >= 0x407000) || defined(Q_WS_MAEMO_5)388 389 /*! 389 390 \since 4.7 … … 415 416 } 416 417 } 417 #endif418 418 419 419 /*! … … 543 543 return; 544 544 Qt::InputMethodHints imHints = inputMethodHints(); 545 if (mode == Password ) {545 if (mode == Password || mode == NoEcho) { 546 546 imHints |= Qt::ImhHiddenText; 547 547 } else { 548 548 imHints &= ~Qt::ImhHiddenText; 549 } 550 if (mode != Normal) { 551 imHints |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText); 552 } else { 553 imHints &= ~(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText); 549 554 } 550 555 setInputMethodHints(imHints); … … 1644 1649 if (!event->text().isEmpty() && event->text().at(0).isPrint() 1645 1650 && !isReadOnly()) 1646 {1647 1651 setEditFocus(true); 1648 #ifndef Q_OS_SYMBIAN 1649 clear(); 1650 #endif 1651 } else { 1652 else { 1652 1653 event->ignore(); 1653 1654 return; … … 1666 1667 #endif 1667 1668 d->control->processKeyEvent(event); 1668 if (event->isAccepted()) 1669 if (event->isAccepted()) { 1670 if (layoutDirection() != d->control->layoutDirection()) 1671 setLayoutDirection(d->control->layoutDirection()); 1669 1672 d->control->setCursorBlinkPeriod(0); 1673 } 1670 1674 } 1671 1675 … … 1705 1709 if (QApplication::keypadNavigationEnabled() 1706 1710 && hasFocus() && !hasEditFocus() 1707 && !e->preeditString().isEmpty()) {1711 && !e->preeditString().isEmpty()) 1708 1712 setEditFocus(true); 1709 #ifndef Q_OS_SYMBIAN1710 selectAll(); // so text is replaced rather than appended to1711 #endif1712 }1713 1713 #endif 1714 1714 … … 1867 1867 1868 1868 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)); 1870 1870 switch (va & Qt::AlignVertical_Mask) { 1871 1871 case Qt::AlignBottom: … … 1882 1882 QRect lineRect(r.x() + d->horizontalMargin, d->vscroll, r.width() - 2*d->horizontalMargin, fm.height()); 1883 1883 1884 int minLB = qMax(0, -fm.minLeftBearing()); 1885 int minRB = qMax(0, -fm.minRightBearing()); 1886 1884 1887 if (d->control->text().isEmpty()) { 1885 1888 if (!hasFocus() && !d->placeholderText.isEmpty()) { … … 1888 1891 QPen oldpen = p.pen(); 1889 1892 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); 1891 1896 p.setPen(oldpen); 1892 1897 return; … … 1902 1907 // minLB, minRB), the line edit rect (lineRect) and the cursor position 1903 1908 // (cix). 1904 int minLB = qMax(0, -fm.minLeftBearing());1905 int minRB = qMax(0, -fm.minRightBearing());1906 1909 int widthUsed = qRound(d->control->naturalTextWidth()) + 1 + minRB; 1907 1910 if ((minLB + widthUsed) <= lineRect.width()) { … … 1930 1933 // right 1931 1934 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 1933 1940 // the y offset is there to keep the baseline constant in case we have script changes in the text. 1934 1941 QPoint topLeft = lineRect.topLeft() - QPoint(d->hscroll, d->control->ascent() - fm.ascent()); … … 1950 1957 flags |= QLineControl::DrawSelections; 1951 1958 // 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()) 1953 1961 d->control->setPalette(pal); 1954 1962 } … … 2053 2061 void QLineEdit::contextMenuEvent(QContextMenuEvent *event) 2054 2062 { 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) 2061 2070 extern bool qt_use_rtl_extensions; 2062 2071 #endif … … 2130 2139 #endif 2131 2140 2132 #if defined(Q_WS_WIN) 2141 #if defined(Q_WS_WIN) || defined(Q_WS_X11) 2133 2142 if (!d->control->isReadOnly() && qt_use_rtl_extensions) { 2134 2143 #else … … 2163 2172 } 2164 2173 update(); 2165 break;2166 case QEvent::LayoutDirectionChange:2167 d->control->setLayoutDirection(layoutDirection());2168 2174 break; 2169 2175 default:
Note:
See TracChangeset
for help on using the changeset viewer.