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 /*! |
|
389 \since 4.7 |
|
390 |
|
391 \property QLineEdit::placeholderText |
|
392 \brief the line edit's placeholder text |
|
393 |
|
394 Setting this property makes the line edit display a grayed-out |
|
395 placeholder text as long as the text() is empty and the widget doesn't |
|
396 have focus. |
|
397 |
|
398 By default, this property contains an empty string. |
|
399 |
|
400 \sa text() |
|
401 */ |
|
402 QString QLineEdit::placeholderText() const |
|
403 { |
|
404 Q_D(const QLineEdit); |
|
405 return d->placeholderText; |
|
406 } |
|
407 |
|
408 void QLineEdit::setPlaceholderText(const QString& placeholderText) |
|
409 { |
|
410 Q_D(QLineEdit); |
|
411 if (d->placeholderText != placeholderText) { |
|
412 d->placeholderText = placeholderText; |
|
413 if (!hasFocus()) |
|
414 update(); |
|
415 } |
|
416 } |
|
417 #endif |
386 |
418 |
387 /*! |
419 /*! |
388 \property QLineEdit::displayText |
420 \property QLineEdit::displayText |
389 \brief the displayed text |
421 \brief the displayed text |
390 |
422 |
622 QSize QLineEdit::sizeHint() const |
654 QSize QLineEdit::sizeHint() const |
623 { |
655 { |
624 Q_D(const QLineEdit); |
656 Q_D(const QLineEdit); |
625 ensurePolished(); |
657 ensurePolished(); |
626 QFontMetrics fm(font()); |
658 QFontMetrics fm(font()); |
627 int h = qMax(fm.lineSpacing(), 14) + 2*d->verticalMargin |
659 int h = qMax(fm.height(), 14) + 2*d->verticalMargin |
628 + d->topTextMargin + d->bottomTextMargin |
660 + d->topTextMargin + d->bottomTextMargin |
629 + d->topmargin + d->bottommargin; |
661 + d->topmargin + d->bottommargin; |
630 int w = fm.width(QLatin1Char('x')) * 17 + 2*d->horizontalMargin |
662 int w = fm.width(QLatin1Char('x')) * 17 + 2*d->horizontalMargin |
631 + d->leftTextMargin + d->rightTextMargin |
663 + d->leftTextMargin + d->rightTextMargin |
632 + d->leftmargin + d->rightmargin; // "some" |
664 + d->leftmargin + d->rightmargin; // "some" |
1386 //d->separate(); |
1441 //d->separate(); |
1387 } else if (e->type() == QEvent::WindowActivate) { |
1442 } else if (e->type() == QEvent::WindowActivate) { |
1388 QTimer::singleShot(0, this, SLOT(_q_handleWindowActivate())); |
1443 QTimer::singleShot(0, this, SLOT(_q_handleWindowActivate())); |
1389 }else if(e->type() == QEvent::ShortcutOverride){ |
1444 }else if(e->type() == QEvent::ShortcutOverride){ |
1390 d->control->processEvent(e); |
1445 d->control->processEvent(e); |
|
1446 } else if (e->type() == QEvent::KeyRelease) { |
|
1447 d->control->setCursorBlinkPeriod(QApplication::cursorFlashTime()); |
|
1448 } else if (e->type() == QEvent::Show) { |
|
1449 //In order to get the cursor blinking if QComboBox::setEditable is called when the combobox has focus |
|
1450 if (hasFocus()) { |
|
1451 d->control->setCursorBlinkPeriod(QApplication::cursorFlashTime()); |
|
1452 QStyleOptionFrameV2 opt; |
|
1453 initStyleOption(&opt); |
|
1454 if ((!hasSelectedText() && d->control->preeditAreaText().isEmpty()) |
|
1455 || style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this)) |
|
1456 d->setCursorVisible(true); |
|
1457 } |
1391 } |
1458 } |
1392 |
1459 |
1393 #ifdef QT_KEYPAD_NAVIGATION |
1460 #ifdef QT_KEYPAD_NAVIGATION |
1394 if (QApplication::keypadNavigationEnabled()) { |
1461 if (QApplication::keypadNavigationEnabled()) { |
1395 if (e->type() == QEvent::EnterEditFocus) { |
1462 if (e->type() == QEvent::EnterEditFocus) { |
1685 selectAll(); |
1759 selectAll(); |
1686 } else if (e->reason() == Qt::MouseFocusReason) { |
1760 } else if (e->reason() == Qt::MouseFocusReason) { |
1687 d->clickCausedFocus = 1; |
1761 d->clickCausedFocus = 1; |
1688 } |
1762 } |
1689 #ifdef QT_KEYPAD_NAVIGATION |
1763 #ifdef QT_KEYPAD_NAVIGATION |
1690 if (!QApplication::keypadNavigationEnabled() || (hasEditFocus() && e->reason() == Qt::PopupFocusReason)){ |
1764 if (!QApplication::keypadNavigationEnabled() || (hasEditFocus() && ( e->reason() == Qt::PopupFocusReason |
|
1765 #ifdef Q_OS_SYMBIAN |
|
1766 || e->reason() == Qt::ActiveWindowFocusReason |
|
1767 #endif |
|
1768 ))) { |
1691 #endif |
1769 #endif |
1692 d->control->setCursorBlinkPeriod(QApplication::cursorFlashTime()); |
1770 d->control->setCursorBlinkPeriod(QApplication::cursorFlashTime()); |
1693 QStyleOptionFrameV2 opt; |
1771 QStyleOptionFrameV2 opt; |
1694 initStyleOption(&opt); |
1772 initStyleOption(&opt); |
1695 if((!hasSelectedText() && d->control->preeditAreaText().isEmpty()) |
1773 if((!hasSelectedText() && d->control->preeditAreaText().isEmpty()) |
1794 //center |
1872 //center |
1795 d->vscroll = r.y() + (r.height() - fm.height() + 1) / 2; |
1873 d->vscroll = r.y() + (r.height() - fm.height() + 1) / 2; |
1796 break; |
1874 break; |
1797 } |
1875 } |
1798 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 |
|
1878 if (d->control->text().isEmpty()) { |
|
1879 if (!hasFocus() && !d->placeholderText.isEmpty()) { |
|
1880 QColor col = pal.text().color(); |
|
1881 col.setAlpha(128); |
|
1882 QPen oldpen = p.pen(); |
|
1883 p.setPen(col); |
|
1884 p.drawText(lineRect, va, d->placeholderText); |
|
1885 p.setPen(oldpen); |
|
1886 return; |
|
1887 } |
|
1888 } |
1799 |
1889 |
1800 int cix = qRound(d->control->cursorToX()); |
1890 int cix = qRound(d->control->cursorToX()); |
1801 |
1891 |
1802 // horizontal scrolling. d->hscroll is the left indent from the beginning |
1892 // horizontal scrolling. d->hscroll is the left indent from the beginning |
1803 // of the text line to the left edge of lineRect. we update this value |
1893 // of the text line to the left edge of lineRect. we update this value |
1974 QMenu *QLineEdit::createStandardContextMenu() |
2064 QMenu *QLineEdit::createStandardContextMenu() |
1975 { |
2065 { |
1976 Q_D(QLineEdit); |
2066 Q_D(QLineEdit); |
1977 QMenu *popup = new QMenu(this); |
2067 QMenu *popup = new QMenu(this); |
1978 popup->setObjectName(QLatin1String("qt_edit_menu")); |
2068 popup->setObjectName(QLatin1String("qt_edit_menu")); |
1979 |
2069 QAction *action = 0; |
1980 QAction *action = popup->addAction(QLineEdit::tr("&Undo") + ACCEL_KEY(QKeySequence::Undo)); |
2070 |
1981 action->setEnabled(d->control->isUndoAvailable()); |
2071 if (!isReadOnly()) { |
1982 connect(action, SIGNAL(triggered()), SLOT(undo())); |
2072 action = popup->addAction(QLineEdit::tr("&Undo") + ACCEL_KEY(QKeySequence::Undo)); |
1983 |
2073 action->setEnabled(d->control->isUndoAvailable()); |
1984 action = popup->addAction(QLineEdit::tr("&Redo") + ACCEL_KEY(QKeySequence::Redo)); |
2074 connect(action, SIGNAL(triggered()), SLOT(undo())); |
1985 action->setEnabled(d->control->isRedoAvailable()); |
2075 |
1986 connect(action, SIGNAL(triggered()), SLOT(redo())); |
2076 action = popup->addAction(QLineEdit::tr("&Redo") + ACCEL_KEY(QKeySequence::Redo)); |
1987 |
2077 action->setEnabled(d->control->isRedoAvailable()); |
1988 popup->addSeparator(); |
2078 connect(action, SIGNAL(triggered()), SLOT(redo())); |
|
2079 |
|
2080 popup->addSeparator(); |
|
2081 } |
1989 |
2082 |
1990 #ifndef QT_NO_CLIPBOARD |
2083 #ifndef QT_NO_CLIPBOARD |
1991 action = popup->addAction(QLineEdit::tr("Cu&t") + ACCEL_KEY(QKeySequence::Cut)); |
2084 if (!isReadOnly()) { |
1992 action->setEnabled(!d->control->isReadOnly() && d->control->hasSelectedText() |
2085 action = popup->addAction(QLineEdit::tr("Cu&t") + ACCEL_KEY(QKeySequence::Cut)); |
1993 && d->control->echoMode() == QLineEdit::Normal); |
2086 action->setEnabled(!d->control->isReadOnly() && d->control->hasSelectedText() |
1994 connect(action, SIGNAL(triggered()), SLOT(cut())); |
2087 && d->control->echoMode() == QLineEdit::Normal); |
|
2088 connect(action, SIGNAL(triggered()), SLOT(cut())); |
|
2089 } |
1995 |
2090 |
1996 action = popup->addAction(QLineEdit::tr("&Copy") + ACCEL_KEY(QKeySequence::Copy)); |
2091 action = popup->addAction(QLineEdit::tr("&Copy") + ACCEL_KEY(QKeySequence::Copy)); |
1997 action->setEnabled(d->control->hasSelectedText() |
2092 action->setEnabled(d->control->hasSelectedText() |
1998 && d->control->echoMode() == QLineEdit::Normal); |
2093 && d->control->echoMode() == QLineEdit::Normal); |
1999 connect(action, SIGNAL(triggered()), SLOT(copy())); |
2094 connect(action, SIGNAL(triggered()), SLOT(copy())); |
2000 |
2095 |
2001 action = popup->addAction(QLineEdit::tr("&Paste") + ACCEL_KEY(QKeySequence::Paste)); |
2096 if (!isReadOnly()) { |
2002 action->setEnabled(!d->control->isReadOnly() && !QApplication::clipboard()->text().isEmpty()); |
2097 action = popup->addAction(QLineEdit::tr("&Paste") + ACCEL_KEY(QKeySequence::Paste)); |
2003 connect(action, SIGNAL(triggered()), SLOT(paste())); |
2098 action->setEnabled(!d->control->isReadOnly() && !QApplication::clipboard()->text().isEmpty()); |
2004 #endif |
2099 connect(action, SIGNAL(triggered()), SLOT(paste())); |
2005 |
2100 } |
2006 action = popup->addAction(QLineEdit::tr("Delete")); |
2101 #endif |
2007 action->setEnabled(!d->control->isReadOnly() && !d->control->text().isEmpty() && d->control->hasSelectedText()); |
2102 |
2008 connect(action, SIGNAL(triggered()), d->control, SLOT(_q_deleteSelected())); |
2103 if (!isReadOnly()) { |
2009 |
2104 action = popup->addAction(QLineEdit::tr("Delete")); |
2010 popup->addSeparator(); |
2105 action->setEnabled(!d->control->isReadOnly() && !d->control->text().isEmpty() && d->control->hasSelectedText()); |
|
2106 connect(action, SIGNAL(triggered()), d->control, SLOT(_q_deleteSelected())); |
|
2107 } |
|
2108 |
|
2109 if (!popup->isEmpty()) |
|
2110 popup->addSeparator(); |
2011 |
2111 |
2012 action = popup->addAction(QLineEdit::tr("Select All") + ACCEL_KEY(QKeySequence::SelectAll)); |
2112 action = popup->addAction(QLineEdit::tr("Select All") + ACCEL_KEY(QKeySequence::SelectAll)); |
2013 action->setEnabled(!d->control->text().isEmpty() && !d->control->allSelected()); |
2113 action->setEnabled(!d->control->text().isEmpty() && !d->control->allSelected()); |
2014 d->selectAllAction = action; |
2114 d->selectAllAction = action; |
2015 connect(action, SIGNAL(triggered()), SLOT(selectAll())); |
2115 connect(action, SIGNAL(triggered()), SLOT(selectAll())); |