equal
deleted
inserted
replaced
381 { |
381 { |
382 Q_D(QLineEdit); |
382 Q_D(QLineEdit); |
383 d->control->setText(text); |
383 d->control->setText(text); |
384 } |
384 } |
385 |
385 |
386 // ### Qt 4.7: remove this #if guard |
|
387 #if (QT_VERSION >= 0x407000) || defined(Q_WS_MAEMO_5) |
|
388 /*! |
386 /*! |
389 \since 4.7 |
387 \since 4.7 |
390 |
388 |
391 \property QLineEdit::placeholderText |
389 \property QLineEdit::placeholderText |
392 \brief the line edit's placeholder text |
390 \brief the line edit's placeholder text |
412 d->placeholderText = placeholderText; |
410 d->placeholderText = placeholderText; |
413 if (!hasFocus()) |
411 if (!hasFocus()) |
414 update(); |
412 update(); |
415 } |
413 } |
416 } |
414 } |
417 #endif |
|
418 |
415 |
419 /*! |
416 /*! |
420 \property QLineEdit::displayText |
417 \property QLineEdit::displayText |
421 \brief the displayed text |
418 \brief the displayed text |
422 |
419 |
540 { |
537 { |
541 Q_D(QLineEdit); |
538 Q_D(QLineEdit); |
542 if (mode == (EchoMode)d->control->echoMode()) |
539 if (mode == (EchoMode)d->control->echoMode()) |
543 return; |
540 return; |
544 Qt::InputMethodHints imHints = inputMethodHints(); |
541 Qt::InputMethodHints imHints = inputMethodHints(); |
545 if (mode == Password) { |
542 if (mode == Password || mode == NoEcho) { |
546 imHints |= Qt::ImhHiddenText; |
543 imHints |= Qt::ImhHiddenText; |
547 } else { |
544 } else { |
548 imHints &= ~Qt::ImhHiddenText; |
545 imHints &= ~Qt::ImhHiddenText; |
|
546 } |
|
547 if (mode != Normal) { |
|
548 imHints |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText); |
|
549 } else { |
|
550 imHints &= ~(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText); |
549 } |
551 } |
550 setInputMethodHints(imHints); |
552 setInputMethodHints(imHints); |
551 d->control->setEchoMode(mode); |
553 d->control->setEchoMode(mode); |
552 update(); |
554 update(); |
553 #ifdef Q_WS_MAC |
555 #ifdef Q_WS_MAC |
736 setText(newText); |
738 setText(newText); |
737 if(!hasAcceptableInput()){ |
739 if(!hasAcceptableInput()){ |
738 setText(oldText); |
740 setText(oldText); |
739 return false; |
741 return false; |
740 } |
742 } |
741 setCursorPosition(newPos); |
743 int selstart = qMin(newMarkAnchor, newMarkDrag); |
742 setSelection(qMin(newMarkAnchor, newMarkDrag), qAbs(newMarkAnchor - newMarkDrag)); |
744 int sellength = qAbs(newMarkAnchor - newMarkDrag); |
|
745 if (selstart == newPos) { |
|
746 selstart = qMax(newMarkAnchor, newMarkDrag); |
|
747 sellength = -sellength; |
|
748 } |
|
749 //setSelection also set the position |
|
750 setSelection(selstart, sellength); |
743 return true; |
751 return true; |
744 } |
752 } |
745 #endif //QT3_SUPPORT |
753 #endif //QT3_SUPPORT |
746 |
754 |
747 /*! |
755 /*! |
1635 default: |
1643 default: |
1636 if (QApplication::keypadNavigationEnabled()) { |
1644 if (QApplication::keypadNavigationEnabled()) { |
1637 if (!hasEditFocus() && !(event->modifiers() & Qt::ControlModifier)) { |
1645 if (!hasEditFocus() && !(event->modifiers() & Qt::ControlModifier)) { |
1638 if (!event->text().isEmpty() && event->text().at(0).isPrint() |
1646 if (!event->text().isEmpty() && event->text().at(0).isPrint() |
1639 && !isReadOnly()) |
1647 && !isReadOnly()) |
1640 { |
|
1641 setEditFocus(true); |
1648 setEditFocus(true); |
1642 #ifndef Q_OS_SYMBIAN |
1649 else { |
1643 clear(); |
|
1644 #endif |
|
1645 } else { |
|
1646 event->ignore(); |
1650 event->ignore(); |
1647 return; |
1651 return; |
1648 } |
1652 } |
1649 } |
1653 } |
1650 } |
1654 } |
1696 // Focus in if currently in navigation focus on the widget |
1700 // Focus in if currently in navigation focus on the widget |
1697 // Only focus in on preedits, to allow input methods to |
1701 // Only focus in on preedits, to allow input methods to |
1698 // commit text as they focus out without interfering with focus |
1702 // commit text as they focus out without interfering with focus |
1699 if (QApplication::keypadNavigationEnabled() |
1703 if (QApplication::keypadNavigationEnabled() |
1700 && hasFocus() && !hasEditFocus() |
1704 && hasFocus() && !hasEditFocus() |
1701 && !e->preeditString().isEmpty()) { |
1705 && !e->preeditString().isEmpty()) |
1702 setEditFocus(true); |
1706 setEditFocus(true); |
1703 #ifndef Q_OS_SYMBIAN |
|
1704 selectAll(); // so text is replaced rather than appended to |
|
1705 #endif |
|
1706 } |
|
1707 #endif |
1707 #endif |
1708 |
1708 |
1709 d->control->processInputMethodEvent(e); |
1709 d->control->processInputMethodEvent(e); |
1710 |
1710 |
1711 #ifndef QT_NO_COMPLETER |
1711 #ifndef QT_NO_COMPLETER |
1873 d->vscroll = r.y() + (r.height() - fm.height() + 1) / 2; |
1873 d->vscroll = r.y() + (r.height() - fm.height() + 1) / 2; |
1874 break; |
1874 break; |
1875 } |
1875 } |
1876 QRect lineRect(r.x() + d->horizontalMargin, d->vscroll, r.width() - 2*d->horizontalMargin, fm.height()); |
1876 QRect lineRect(r.x() + d->horizontalMargin, d->vscroll, r.width() - 2*d->horizontalMargin, fm.height()); |
1877 |
1877 |
|
1878 int minLB = qMax(0, -fm.minLeftBearing()); |
|
1879 int minRB = qMax(0, -fm.minRightBearing()); |
|
1880 |
1878 if (d->control->text().isEmpty()) { |
1881 if (d->control->text().isEmpty()) { |
1879 if (!hasFocus() && !d->placeholderText.isEmpty()) { |
1882 if (!hasFocus() && !d->placeholderText.isEmpty()) { |
1880 QColor col = pal.text().color(); |
1883 QColor col = pal.text().color(); |
1881 col.setAlpha(128); |
1884 col.setAlpha(128); |
1882 QPen oldpen = p.pen(); |
1885 QPen oldpen = p.pen(); |
1883 p.setPen(col); |
1886 p.setPen(col); |
1884 p.drawText(lineRect, va, d->placeholderText); |
1887 lineRect.adjust(minLB, 0, 0, 0); |
|
1888 QString elidedText = fm.elidedText(d->placeholderText, Qt::ElideRight, lineRect.width()); |
|
1889 p.drawText(lineRect, va, elidedText); |
1885 p.setPen(oldpen); |
1890 p.setPen(oldpen); |
1886 return; |
1891 return; |
1887 } |
1892 } |
1888 } |
1893 } |
1889 |
1894 |
1893 // of the text line to the left edge of lineRect. we update this value |
1898 // of the text line to the left edge of lineRect. we update this value |
1894 // depending on the delta from the last paint event; in effect this means |
1899 // depending on the delta from the last paint event; in effect this means |
1895 // the below code handles all scrolling based on the textline (widthUsed, |
1900 // the below code handles all scrolling based on the textline (widthUsed, |
1896 // minLB, minRB), the line edit rect (lineRect) and the cursor position |
1901 // minLB, minRB), the line edit rect (lineRect) and the cursor position |
1897 // (cix). |
1902 // (cix). |
1898 int minLB = qMax(0, -fm.minLeftBearing()); |
|
1899 int minRB = qMax(0, -fm.minRightBearing()); |
|
1900 int widthUsed = qRound(d->control->naturalTextWidth()) + 1 + minRB; |
1903 int widthUsed = qRound(d->control->naturalTextWidth()) + 1 + minRB; |
1901 if ((minLB + widthUsed) <= lineRect.width()) { |
1904 if ((minLB + widthUsed) <= lineRect.width()) { |
1902 // text fits in lineRect; use hscroll for alignment |
1905 // text fits in lineRect; use hscroll for alignment |
1903 switch (va & ~(Qt::AlignAbsolute|Qt::AlignVertical_Mask)) { |
1906 switch (va & ~(Qt::AlignAbsolute|Qt::AlignVertical_Mask)) { |
1904 case Qt::AlignRight: |
1907 case Qt::AlignRight: |
2044 |
2047 |
2045 \sa setContextMenuPolicy() |
2048 \sa setContextMenuPolicy() |
2046 */ |
2049 */ |
2047 void QLineEdit::contextMenuEvent(QContextMenuEvent *event) |
2050 void QLineEdit::contextMenuEvent(QContextMenuEvent *event) |
2048 { |
2051 { |
2049 QPointer<QMenu> menu = createStandardContextMenu(); |
2052 if (QMenu *menu = createStandardContextMenu()) { |
2050 menu->exec(event->globalPos()); |
2053 menu->setAttribute(Qt::WA_DeleteOnClose); |
2051 delete menu; |
2054 menu->popup(event->globalPos()); |
2052 } |
2055 } |
2053 |
2056 } |
2054 #if defined(Q_WS_WIN) |
2057 |
|
2058 #if defined(Q_WS_WIN) || defined(Q_WS_X11) |
2055 extern bool qt_use_rtl_extensions; |
2059 extern bool qt_use_rtl_extensions; |
2056 #endif |
2060 #endif |
2057 |
2061 |
2058 /*! This function creates the standard context menu which is shown |
2062 /*! This function creates the standard context menu which is shown |
2059 when the user clicks on the line edit with the right mouse |
2063 when the user clicks on the line edit with the right mouse |
2121 for (int i = 0; i < imActions.size(); ++i) |
2125 for (int i = 0; i < imActions.size(); ++i) |
2122 popup->addAction(imActions.at(i)); |
2126 popup->addAction(imActions.at(i)); |
2123 } |
2127 } |
2124 #endif |
2128 #endif |
2125 |
2129 |
2126 #if defined(Q_WS_WIN) |
2130 #if defined(Q_WS_WIN) || defined(Q_WS_X11) |
2127 if (!d->control->isReadOnly() && qt_use_rtl_extensions) { |
2131 if (!d->control->isReadOnly() && qt_use_rtl_extensions) { |
2128 #else |
2132 #else |
2129 if (!d->control->isReadOnly()) { |
2133 if (!d->control->isReadOnly()) { |
2130 #endif |
2134 #endif |
2131 popup->addSeparator(); |
2135 popup->addSeparator(); |