diff options
Diffstat (limited to 'src/widgets/widgets/qlineedit.cpp')
-rw-r--r-- | src/widgets/widgets/qlineedit.cpp | 101 |
1 files changed, 51 insertions, 50 deletions
diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp index 68e3de05bc..7f482a6a4e 100644 --- a/src/widgets/widgets/qlineedit.cpp +++ b/src/widgets/widgets/qlineedit.cpp @@ -293,7 +293,7 @@ QLineEdit::~QLineEdit() /*! \property QLineEdit::text - \brief the line edit's text + \brief the line edit's text. Setting this property clears the selection, clears the undo/redo history, moves the cursor to the end of the line and resets the @@ -322,7 +322,7 @@ void QLineEdit::setText(const QString& text) \since 4.7 \property QLineEdit::placeholderText - \brief the line edit's placeholder text + \brief the line edit's placeholder text. Setting this property makes the line edit display a grayed-out placeholder text as long as the line edit is empty. @@ -354,7 +354,7 @@ void QLineEdit::setPlaceholderText(const QString& placeholderText) /*! \property QLineEdit::displayText - \brief the displayed text + \brief the displayed text. If \l echoMode is \l Normal this returns the same as text(); if \l EchoMode is \l Password or \l PasswordEchoOnEdit it returns a string of @@ -375,7 +375,7 @@ QString QLineEdit::displayText() const /*! \property QLineEdit::maxLength - \brief the maximum permitted length of the text + \brief the maximum permitted length of the text. If the text is too long, it is truncated at the limit. @@ -405,7 +405,7 @@ void QLineEdit::setMaxLength(int maxLength) /*! \property QLineEdit::frame - \brief whether the line edit draws itself with a frame + \brief whether the line edit draws itself with a frame. If enabled (the default) the line edit draws itself inside a frame, otherwise the line edit draws itself without any frame. @@ -544,7 +544,7 @@ void QLineEdit::setFrame(bool enable) /*! \property QLineEdit::echoMode - \brief the line edit's echo mode + \brief the line edit's echo mode. The echo mode determines how the text entered in the line edit is displayed (or echoed) to the user. @@ -684,11 +684,12 @@ QSize QLineEdit::sizeHint() const ensurePolished(); QFontMetrics fm(font()); const int iconSize = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this); - int h = qMax(fm.height(), iconSize - 2) + 2 * QLineEditPrivate::verticalMargin - + d->topTextMargin + d->bottomTextMargin + const QMargins tm = d->effectiveTextMargins(); + int h = qMax(fm.height(), qMax(14, iconSize - 2)) + 2 * QLineEditPrivate::verticalMargin + + tm.top() + tm.bottom() + d->topmargin + d->bottommargin; int w = fm.horizontalAdvance(QLatin1Char('x')) * 17 + 2 * QLineEditPrivate::horizontalMargin - + d->effectiveLeftTextMargin() + d->effectiveRightTextMargin() + + tm.left() + tm.right() + d->leftmargin + d->rightmargin; // "some" QStyleOptionFrame opt; initStyleOption(&opt); @@ -708,11 +709,12 @@ QSize QLineEdit::minimumSizeHint() const Q_D(const QLineEdit); ensurePolished(); QFontMetrics fm = fontMetrics(); + const QMargins tm = d->effectiveTextMargins(); int h = fm.height() + qMax(2 * QLineEditPrivate::verticalMargin, fm.leading()) - + d->topTextMargin + d->bottomTextMargin + + tm.top() + tm.bottom() + d->topmargin + d->bottommargin; int w = fm.maxWidth() - + d->effectiveLeftTextMargin() + d->effectiveRightTextMargin() + + tm.left() + tm.right() + d->leftmargin + d->rightmargin; QStyleOptionFrame opt; initStyleOption(&opt); @@ -723,7 +725,7 @@ QSize QLineEdit::minimumSizeHint() const /*! \property QLineEdit::cursorPosition - \brief the current cursor position for this line edit + \brief the current cursor position for this line edit. Setting the cursor position causes a repaint when appropriate. @@ -756,7 +758,7 @@ int QLineEdit::cursorPositionAt(const QPoint &pos) /*! \property QLineEdit::alignment - \brief the alignment of the line edit + \brief the alignment of the line edit. Both horizontal and vertical alignment is allowed here, Qt::AlignJustify will map to Qt::AlignLeft. @@ -894,7 +896,7 @@ void QLineEdit::end(bool mark) /*! \property QLineEdit::modified - \brief whether the line edit's contents has been modified by the user + \brief whether the line edit's contents has been modified by the user. The modified flag is never read by QLineEdit; it has a default value of false and is changed to true whenever the user changes the line @@ -924,7 +926,7 @@ void QLineEdit::setModified(bool modified) /*! \property QLineEdit::hasSelectedText - \brief whether there is any text selected + \brief whether there is any text selected. hasSelectedText() returns \c true if some or all of the text has been selected by the user; otherwise returns \c false. @@ -943,7 +945,7 @@ bool QLineEdit::hasSelectedText() const /*! \property QLineEdit::selectedText - \brief the selected text + \brief the selected text. If there is no selected text this property's value is an empty string. @@ -1030,7 +1032,7 @@ void QLineEdit::setSelection(int start, int length) /*! \property QLineEdit::undoAvailable - \brief whether undo is available + \brief whether undo is available. Undo becomes available once the user has modified the text in the line edit. @@ -1045,7 +1047,7 @@ bool QLineEdit::isUndoAvailable() const /*! \property QLineEdit::redoAvailable - \brief whether redo is available + \brief whether redo is available. Redo becomes available once the user has performed one or more undo operations on text in the line edit. @@ -1062,7 +1064,7 @@ bool QLineEdit::isRedoAvailable() const /*! \property QLineEdit::dragEnabled \brief whether the lineedit starts a drag if the user presses and - moves the mouse on some selected text + moves the mouse on some selected text. Dragging is disabled by default. */ @@ -1081,7 +1083,7 @@ void QLineEdit::setDragEnabled(bool b) /*! \property QLineEdit::cursorMoveStyle - \brief the movement style of cursor in this line edit + \brief the movement style of cursor in this line edit. \since 4.8 When this property is set to Qt::VisualMoveStyle, the line edit will use visual @@ -1127,17 +1129,11 @@ bool QLineEdit::hasAcceptableInput() const sizes \a left, \a top, \a right, and \a bottom. \since 4.5 - See also getTextMargins(). + See also textMargins(). */ void QLineEdit::setTextMargins(int left, int top, int right, int bottom) { - Q_D(QLineEdit); - d->leftTextMargin = left; - d->topTextMargin = top; - d->rightTextMargin = right; - d->bottomTextMargin = bottom; - updateGeometry(); - update(); + setTextMargins({left, top, right, bottom}); } /*! @@ -1148,10 +1144,17 @@ void QLineEdit::setTextMargins(int left, int top, int right, int bottom) */ void QLineEdit::setTextMargins(const QMargins &margins) { - setTextMargins(margins.left(), margins.top(), margins.right(), margins.bottom()); + Q_D(QLineEdit); + d->textMargins = margins; + updateGeometry(); + update(); } +#if QT_DEPRECATED_SINCE(5, 14) /*! + \obsolete + Use textMargins() + Returns the widget's text margins for \a left, \a top, \a right, and \a bottom. \since 4.5 @@ -1159,16 +1162,17 @@ void QLineEdit::setTextMargins(const QMargins &margins) */ void QLineEdit::getTextMargins(int *left, int *top, int *right, int *bottom) const { - Q_D(const QLineEdit); + QMargins m = textMargins(); if (left) - *left = d->leftTextMargin; + *left = m.left(); if (top) - *top = d->topTextMargin; + *top = m.top(); if (right) - *right = d->rightTextMargin; + *right = m.right(); if (bottom) - *bottom = d->bottomTextMargin; + *bottom = m.bottom(); } +#endif /*! \since 4.6 @@ -1179,12 +1183,12 @@ void QLineEdit::getTextMargins(int *left, int *top, int *right, int *bottom) con QMargins QLineEdit::textMargins() const { Q_D(const QLineEdit); - return QMargins(d->leftTextMargin, d->topTextMargin, d->rightTextMargin, d->bottomTextMargin); + return d->textMargins; } /*! \property QLineEdit::inputMask - \brief The validation input mask + \brief The validation input mask. If no mask is set, inputMask() returns an empty string. @@ -1481,7 +1485,7 @@ bool QLineEdit::event(QEvent * e) d->initMouseYThreshold(); } #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { if (e->type() == QEvent::EnterEditFocus) { end(false); d->setCursorVisible(true); @@ -1513,7 +1517,7 @@ void QLineEdit::mousePressEvent(QMouseEvent* e) if (e->button() == Qt::RightButton) return; #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { + if (QApplication::QApplicationPrivate() && !hasEditFocus()) { setEditFocus(true); // Get the completion list to pop up. if (d->control->completer()) @@ -1722,7 +1726,7 @@ void QLineEdit::keyPressEvent(QKeyEvent *event) bool select = false; switch (event->key()) { case Qt::Key_Select: - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { if (hasEditFocus()) { setEditFocus(false); if (d->control->completer() && d->control->completer()->popup()->isVisible()) @@ -1733,13 +1737,13 @@ void QLineEdit::keyPressEvent(QKeyEvent *event) break; case Qt::Key_Back: case Qt::Key_No: - if (!QApplication::keypadNavigationEnabled() || !hasEditFocus()) { + if (!QApplicationPrivate::keypadNavigationEnabled() || !hasEditFocus()) { event->ignore(); return; } break; default: - if (QApplication::keypadNavigationEnabled()) { + if (QApplicationPrivate::keypadNavigationEnabled()) { if (!hasEditFocus() && !(event->modifiers() & Qt::ControlModifier)) { if (!event->text().isEmpty() && event->text().at(0).isPrint() && !isReadOnly()) @@ -1754,7 +1758,7 @@ void QLineEdit::keyPressEvent(QKeyEvent *event) - if (QApplication::keypadNavigationEnabled() && !select && !hasEditFocus()) { + if (QApplicationPrivate::keypadNavigationEnabled() && !select && !hasEditFocus()) { setEditFocus(true); if (event->key() == Qt::Key_Select) return; // Just start. No action. @@ -1801,7 +1805,7 @@ void QLineEdit::inputMethodEvent(QInputMethodEvent *e) // Focus in if currently in navigation focus on the widget // Only focus in on preedits, to allow input methods to // commit text as they focus out without interfering with focus - if (QApplication::keypadNavigationEnabled() + if (QApplicationPrivate::keypadNavigationEnabled() && hasFocus() && !hasEditFocus() && !e->preeditString().isEmpty()) setEditFocus(true); @@ -1874,7 +1878,7 @@ void QLineEdit::focusInEvent(QFocusEvent *e) d->clickCausedFocus = 1; } #ifdef QT_KEYPAD_NAVIGATION - if (!QApplication::keypadNavigationEnabled() || (hasEditFocus() && ( e->reason() == Qt::PopupFocusReason))) { + if (!QApplicationPrivate::keypadNavigationEnabled() || (hasEditFocus() && ( e->reason() == Qt::PopupFocusReason))) { #endif d->control->setBlinkingCursorEnabled(true); QStyleOptionFrame opt; @@ -1918,7 +1922,7 @@ void QLineEdit::focusOutEvent(QFocusEvent *e) d->control->setBlinkingCursorEnabled(false); #ifdef QT_KEYPAD_NAVIGATION // editingFinished() is already emitted on LeaveEditFocus - if (!QApplication::keypadNavigationEnabled()) + if (!QApplicationPrivate::keypadNavigationEnabled()) #endif if (reason != Qt::PopupFocusReason || !(QApplication::activePopupWidget() && QApplication::activePopupWidget()->parentWidget() == this)) { @@ -1950,10 +1954,7 @@ void QLineEdit::paintEvent(QPaintEvent *) initStyleOption(&panel); style()->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, &p, this); QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); - r.setX(r.x() + d->effectiveLeftTextMargin()); - r.setY(r.y() + d->topTextMargin); - r.setRight(r.right() - d->effectiveRightTextMargin()); - r.setBottom(r.bottom() - d->bottomTextMargin); + r = r.marginsRemoved(d->effectiveTextMargins()); p.setClipRect(r); QFontMetrics fm = fontMetrics(); @@ -2041,7 +2042,7 @@ void QLineEdit::paintEvent(QPaintEvent *) int flags = QWidgetLineControl::DrawText; #ifdef QT_KEYPAD_NAVIGATION - if (!QApplication::keypadNavigationEnabled() || hasEditFocus()) + if (!QApplicationPrivate::keypadNavigationEnabled() || hasEditFocus()) #endif if (d->control->hasSelectedText() || (d->cursorVisible && !d->control->inputMask().isEmpty() && !d->control->isReadOnly())){ flags |= QWidgetLineControl::DrawSelections; |