diff options
Diffstat (limited to 'src/quick/items/qquicktextinput.cpp')
-rw-r--r-- | src/quick/items/qquicktextinput.cpp | 91 |
1 files changed, 72 insertions, 19 deletions
diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index ffc94dfd46..2b1141bea8 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -1,31 +1,37 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtQuick module of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL21$ +** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. ** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** @@ -118,6 +124,8 @@ void QQuickTextInput::componentComplete() \qmlproperty string QtQuick::TextInput::text The text in the TextInput. + + \sa clear() */ QString QQuickTextInput::text() const { @@ -671,8 +679,7 @@ void QQuickTextInput::setReadOnly(bool ro) setFlag(QQuickItem::ItemAcceptsInputMethod, !ro); #endif d->m_readOnly = ro; - if (!ro) - d->setCursorPosition(d->end()); + d->setCursorPosition(d->end()); #ifndef QT_NO_IM updateInputMethod(Qt::ImEnabled); #endif @@ -1940,6 +1947,7 @@ void QQuickTextInput::undo() { Q_D(QQuickTextInput); if (!d->m_readOnly) { + d->resetInputMethod(); d->internalUndo(); d->finishChange(-1, true); } @@ -1955,6 +1963,7 @@ void QQuickTextInput::redo() { Q_D(QQuickTextInput); if (!d->m_readOnly) { + d->resetInputMethod(); d->internalRedo(); d->finishChange(); } @@ -2192,6 +2201,7 @@ void QQuickTextInput::resetPasswordMaskDelay() partial text input from an input method. \readonly + \sa preeditText */ QString QQuickTextInput::displayText() const { @@ -2200,6 +2210,21 @@ QString QQuickTextInput::displayText() const } /*! + \qmlproperty string QtQuick::TextInput::preeditText + \readonly + \since 5.7 + + This property contains partial text input from an input method. + + \sa displayText +*/ +QString QQuickTextInput::preeditText() const +{ + Q_D(const QQuickTextInput); + return d->m_textLayout.preeditAreaText(); +} + +/*! \qmlproperty bool QtQuick::TextInput::selectByMouse Defaults to false. @@ -2561,6 +2586,13 @@ void QQuickTextInputPrivate::init() } } +void QQuickTextInputPrivate::resetInputMethod() +{ + Q_Q(QQuickTextInput); + if (!m_readOnly && q->hasActiveFocus() && qGuiApp) + QGuiApplication::inputMethod()->reset(); +} + void QQuickTextInput::updateCursorRectangle(bool scroll) { Q_D(QQuickTextInput); @@ -3271,7 +3303,10 @@ void QQuickTextInputPrivate::processInputMethodEvent(QInputMethodEvent *event) cursorPositionChanged = true; } } + QString oldPreeditString = m_textLayout.preeditAreaText(); m_textLayout.setPreeditArea(m_cursor, event->preeditString()); + if (oldPreeditString != m_textLayout.preeditAreaText()) + emit q->preeditTextChanged(); const int oldPreeditCursor = m_preeditCursor; m_preeditCursor = event->preeditString().length(); hasImState = !event->preeditString().isEmpty(); @@ -3542,7 +3577,7 @@ void QQuickTextInputPrivate::internalInsert(const QString &s) int remaining = m_maxLength - m_text.length(); if (remaining != 0) { m_text.insert(m_cursor, s.left(remaining)); - for (int i = 0; i < (int) s.left(remaining).length(); ++i) + for (int i = 0; i < (int) s.leftRef(remaining).length(); ++i) addCommand(Command(Insert, m_cursor++, s.at(i), -1, -1)); m_textDirty = true; } @@ -3895,14 +3930,14 @@ QString QQuickTextInputPrivate::maskString(uint pos, const QString &str, bool cl int n = findInMask(i, true, true, str[(int)strIndex]); if (n != -1) { if (str.length() != 1 || i == 0 || (i > 0 && (!m_maskData[i-1].separator || m_maskData[i-1].maskChar != str[(int)strIndex]))) { - s += fill.mid(i, n-i+1); + s += fill.midRef(i, n-i+1); i = n + 1; // update i to find + 1 } } else { // search for valid m_blank if not n = findInMask(i, true, false, str[(int)strIndex]); if (n != -1) { - s += fill.mid(i, n-i); + s += fill.midRef(i, n-i); switch (m_maskData[n].caseMode) { case MaskInputData::Upper: s += str[(int)strIndex].toUpper(); @@ -4460,6 +4495,24 @@ void QQuickTextInput::ensureVisible(int position) } /*! + \qmlmethod QtQuick::TextInput::clear() + \since 5.7 + + Clears the contents of the text input + and resets partial text input from an input method. + + Use this method instead of setting the \l text property to an empty string. + + \sa QInputMethod::reset() +*/ +void QQuickTextInput::clear() +{ + Q_D(QQuickTextInput); + d->resetInputMethod(); + d->clear(); +} + +/*! \since 5.6 \qmlproperty real QtQuick::TextInput::padding \qmlproperty real QtQuick::TextInput::topPadding |