diff options
Diffstat (limited to 'src/widgets/widgets/qlineedit.cpp')
-rw-r--r-- | src/widgets/widgets/qlineedit.cpp | 70 |
1 files changed, 48 insertions, 22 deletions
diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp index 13b204e825..e3b348f0ef 100644 --- a/src/widgets/widgets/qlineedit.cpp +++ b/src/widgets/widgets/qlineedit.cpp @@ -80,7 +80,10 @@ #include "private/qapplication_p.h" #include "private/qshortcutmap_p.h" #include "qkeysequence.h" -#define ACCEL_KEY(k) (!qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? \ +#define ACCEL_KEY(k) ((qApp->testAttribute(Qt::AA_DontShowIconsInMenus) \ + ? false \ + : qApp->styleHints()->showShortcutsInContextMenus()) \ + && !qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? \ QLatin1Char('\t') + QKeySequence(k).toString(QKeySequence::NativeText) : QString()) #else #define ACCEL_KEY(k) QString() @@ -93,10 +96,6 @@ QT_BEGIN_NAMESPACE -#if 0 // Used to be included in Qt4 for Q_WS_MAC -extern void qt_mac_secure_keyboard(bool); //qapplication_mac.cpp -#endif - /*! Initialize \a option with the values from this QLineEdit. This method is useful for subclasses when they need a QStyleOptionFrame, but don't want @@ -232,10 +231,10 @@ void QLineEdit::initStyleOption(QStyleOptionFrame *option) const */ /*! - \fn void QLineEdit::cursorPositionChanged(int old, int new) + \fn void QLineEdit::cursorPositionChanged(int oldPos, int newPos) This signal is emitted whenever the cursor moves. The previous - position is given by \a old, and the new position by \a new. + position is given by \a oldPos, and the new position by \a newPos. \sa setCursorPosition(), cursorPosition() */ @@ -578,10 +577,6 @@ void QLineEdit::setEchoMode(EchoMode mode) setInputMethodHints(imHints); d->control->setEchoMode(mode); update(); -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (hasFocus()) - qt_mac_secure_keyboard(mode == Password || mode == NoEcho); -#endif } @@ -687,7 +682,7 @@ QSize QLineEdit::sizeHint() const int h = qMax(fm.height(), 14) + 2*d->verticalMargin + d->topTextMargin + d->bottomTextMargin + d->topmargin + d->bottommargin; - int w = fm.width(QLatin1Char('x')) * 17 + 2*d->horizontalMargin + int w = fm.horizontalAdvance(QLatin1Char('x')) * 17 + 2*d->horizontalMargin + d->effectiveLeftTextMargin() + d->effectiveRightTextMargin() + d->leftmargin + d->rightmargin; // "some" QStyleOptionFrame opt; @@ -964,6 +959,8 @@ QString QLineEdit::selectedText() const line edit or -1 if no text is selected. \sa selectedText() + \sa selectionEnd() + \sa selectionLength() */ int QLineEdit::selectionStart() const @@ -972,8 +969,33 @@ int QLineEdit::selectionStart() const return d->control->selectionStart(); } +/*! + Returns the index of the character directly after the selection + in the line edit or -1 if no text is selected. + \since 5.10 + + \sa selectedText() + \sa selectionStart() + \sa selectionLength() +*/ +int QLineEdit::selectionEnd() const +{ + Q_D(const QLineEdit); + return d->control->selectionEnd(); +} +/*! + Returns the length of the selection. + \since 5.10 + \sa selectedText() + \sa selectionStart() + \sa selectionEnd() +*/ +int QLineEdit::selectionLength() const +{ + return selectionEnd() - selectionStart(); +} /*! Selects text from position \a start and for \a length characters. @@ -1444,6 +1466,8 @@ bool QLineEdit::event(QEvent * e) #endif } else if (e->type() == QEvent::Resize) { d->positionSideWidgets(); + } else if (e->type() == QEvent::StyleChange) { + d->initMouseYThreshold(); } #ifdef QT_KEYPAD_NAVIGATION if (QApplication::keypadNavigationEnabled()) { @@ -1524,7 +1548,17 @@ void QLineEdit::mouseMoveEvent(QMouseEvent * e) const bool select = (d->imHints & Qt::ImhNoPredictiveText); #endif #ifndef QT_NO_IM - if (d->control->composeMode() && select) { + if (d->mouseYThreshold > 0 && e->pos().y() > d->mousePressPos.y() + d->mouseYThreshold) { + if (layoutDirection() == Qt::RightToLeft) + d->control->home(select); + else + d->control->end(select); + } else if (d->mouseYThreshold > 0 && e->pos().y() + d->mouseYThreshold < d->mousePressPos.y()) { + if (layoutDirection() == Qt::RightToLeft) + d->control->end(select); + else + d->control->home(select); + } else if (d->control->composeMode() && select) { int startPos = d->xToPos(d->mousePressPos.x()); int currentPos = d->xToPos(e->pos().x()); if (startPos != currentPos) @@ -1563,7 +1597,7 @@ void QLineEdit::mouseReleaseEvent(QMouseEvent* e) d->control->copy(QClipboard::Selection); } else if (!d->control->isReadOnly() && e->button() == Qt::MidButton) { deselect(); - insert(QApplication::clipboard()->text(QClipboard::Selection)); + d->control->paste(QClipboard::Selection); } } #endif @@ -1818,10 +1852,6 @@ void QLineEdit::focusInEvent(QFocusEvent *e) if((!hasSelectedText() && d->control->preeditAreaText().isEmpty()) || style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this)) d->setCursorVisible(true); -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (d->control->echoMode() == Password || d->control->echoMode() == NoEcho) - qt_mac_secure_keyboard(true); -#endif #ifdef QT_KEYPAD_NAVIGATION d->control->setCancelText(d->control->text()); } @@ -1866,10 +1896,6 @@ void QLineEdit::focusOutEvent(QFocusEvent *e) if (hasAcceptableInput() || d->control->fixup()) emit editingFinished(); } -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (d->control->echoMode() == Password || d->control->echoMode() == NoEcho) - qt_mac_secure_keyboard(false); -#endif #ifdef QT_KEYPAD_NAVIGATION d->control->setCancelText(QString()); #endif |