2011-04-27 12:13:26 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-19 09:38:36 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 12:13:26 +00:00
|
|
|
**
|
2013-09-30 05:28:31 +00:00
|
|
|
** This file is part of the QtQuick module of the Qt Toolkit.
|
2011-04-27 12:13:26 +00:00
|
|
|
**
|
2016-01-19 09:38:36 +00:00
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
2012-09-20 05:21:40 +00:00
|
|
|
** 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
|
2015-01-28 11:55:39 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-19 09:38:36 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-20 05:21:40 +00:00
|
|
|
**
|
2011-04-27 12:13:26 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-09-20 05:21:40 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2016-01-19 09:38:36 +00:00
|
|
|
** 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.
|
2011-04-27 12:13:26 +00:00
|
|
|
**
|
2016-01-19 09:38:36 +00:00
|
|
|
** 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.
|
2011-04-27 12:13:26 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
#ifndef QQUICKTEXTINPUT_P_H
|
|
|
|
#define QQUICKTEXTINPUT_P_H
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2015-10-05 08:45:54 +00:00
|
|
|
//
|
|
|
|
// W A R N I N G
|
|
|
|
// -------------
|
|
|
|
//
|
|
|
|
// This file is not part of the Qt API. It exists purely as an
|
|
|
|
// implementation detail. This header file may change from version to
|
|
|
|
// version without notice, or even be removed.
|
|
|
|
//
|
|
|
|
// We mean it.
|
|
|
|
//
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
#include "qquickimplicitsizeitem_p.h"
|
Invalidate text when application fonts are added or removed
We had multiple related issues due to application fonts being added
or removed during the application lifetime.
1. If a text had font family "foo" set, and this font did not
exist at the time, then loading "foo" at a later stage would not
update the text to use the correct font, since the result of
the previous request had been cached.
2. A variation of #1 was if the font "foo" was loaded by a FontLoader
in the scene and referred to by name in the text component. In this
case, there was a race condition, where the font lookup would sometimes
yield different results on the main thread and on the render thread,
and text would be garbled.
3. When a font was removed from the font database, then references to
it would remain in the caches (glyph cache + font cache) in the render
thread. With certain backends (DirectWrite, CoreText) this caused errors
or even crashes, as the cached font engines would be referring to data
that had been removed.
The work-around for #1 and #2 was merely to avoid hardcoding names for
fonts, but instead getting them from the FontLoader. This way, you can
avoid requesting the font family before it is available (and thus avoid
caching the wrong result). However, for #3 there is no known work-around.
This patch fixes all three (together with a smaller patch for qtbase) by
invalidating all text and related caches in Qt Quick when fonts are
either added or removed from the font database. This does add some
overhead if font loading happens during runtime, but the alternative is
broken behavior and dangling pointers.
This is done during the synchronization step. Before synchronization,
the font cache is flushed and all text components are marked for update,
so that fonts are re-requested against the new font database.
After synchronization, we delete all distance field glyph caches which
are not currently in use, to avoid having references to stale application
font data in the list.
[ChangeLog][Text] Fix multiple issues with usage of application fonts when
they are added or removed during the lifetime of the application.
Task-number: QTBUG-100697
Task-number: QDS-1142
Change-Id: Ib309e54e0ee97b6be6d2a7211964043fd51c9ec5
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2022-03-18 11:57:01 +00:00
|
|
|
#include "qquicktextinterface_p.h"
|
2011-12-15 01:36:54 +00:00
|
|
|
#include <QtGui/qtextoption.h>
|
2011-04-27 12:13:26 +00:00
|
|
|
#include <QtGui/qvalidator.h>
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
class QQuickTextInputPrivate;
|
2011-04-27 12:13:26 +00:00
|
|
|
class QValidator;
|
Invalidate text when application fonts are added or removed
We had multiple related issues due to application fonts being added
or removed during the application lifetime.
1. If a text had font family "foo" set, and this font did not
exist at the time, then loading "foo" at a later stage would not
update the text to use the correct font, since the result of
the previous request had been cached.
2. A variation of #1 was if the font "foo" was loaded by a FontLoader
in the scene and referred to by name in the text component. In this
case, there was a race condition, where the font lookup would sometimes
yield different results on the main thread and on the render thread,
and text would be garbled.
3. When a font was removed from the font database, then references to
it would remain in the caches (glyph cache + font cache) in the render
thread. With certain backends (DirectWrite, CoreText) this caused errors
or even crashes, as the cached font engines would be referring to data
that had been removed.
The work-around for #1 and #2 was merely to avoid hardcoding names for
fonts, but instead getting them from the FontLoader. This way, you can
avoid requesting the font family before it is available (and thus avoid
caching the wrong result). However, for #3 there is no known work-around.
This patch fixes all three (together with a smaller patch for qtbase) by
invalidating all text and related caches in Qt Quick when fonts are
either added or removed from the font database. This does add some
overhead if font loading happens during runtime, but the alternative is
broken behavior and dangling pointers.
This is done during the synchronization step. Before synchronization,
the font cache is flushed and all text components are marked for update,
so that fonts are re-requested against the new font database.
After synchronization, we delete all distance field glyph caches which
are not currently in use, to avoid having references to stale application
font data in the list.
[ChangeLog][Text] Fix multiple issues with usage of application fonts when
they are added or removed during the lifetime of the application.
Task-number: QTBUG-100697
Task-number: QDS-1142
Change-Id: Ib309e54e0ee97b6be6d2a7211964043fd51c9ec5
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2022-03-18 11:57:01 +00:00
|
|
|
class Q_QUICK_PRIVATE_EXPORT QQuickTextInput : public QQuickImplicitSizeItem, public QQuickTextInterface
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
Invalidate text when application fonts are added or removed
We had multiple related issues due to application fonts being added
or removed during the application lifetime.
1. If a text had font family "foo" set, and this font did not
exist at the time, then loading "foo" at a later stage would not
update the text to use the correct font, since the result of
the previous request had been cached.
2. A variation of #1 was if the font "foo" was loaded by a FontLoader
in the scene and referred to by name in the text component. In this
case, there was a race condition, where the font lookup would sometimes
yield different results on the main thread and on the render thread,
and text would be garbled.
3. When a font was removed from the font database, then references to
it would remain in the caches (glyph cache + font cache) in the render
thread. With certain backends (DirectWrite, CoreText) this caused errors
or even crashes, as the cached font engines would be referring to data
that had been removed.
The work-around for #1 and #2 was merely to avoid hardcoding names for
fonts, but instead getting them from the FontLoader. This way, you can
avoid requesting the font family before it is available (and thus avoid
caching the wrong result). However, for #3 there is no known work-around.
This patch fixes all three (together with a smaller patch for qtbase) by
invalidating all text and related caches in Qt Quick when fonts are
either added or removed from the font database. This does add some
overhead if font loading happens during runtime, but the alternative is
broken behavior and dangling pointers.
This is done during the synchronization step. Before synchronization,
the font cache is flushed and all text components are marked for update,
so that fonts are re-requested against the new font database.
After synchronization, we delete all distance field glyph caches which
are not currently in use, to avoid having references to stale application
font data in the list.
[ChangeLog][Text] Fix multiple issues with usage of application fonts when
they are added or removed during the lifetime of the application.
Task-number: QTBUG-100697
Task-number: QDS-1142
Change-Id: Ib309e54e0ee97b6be6d2a7211964043fd51c9ec5
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2022-03-18 11:57:01 +00:00
|
|
|
Q_INTERFACES(QQuickTextInterface)
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
|
2012-01-04 00:53:26 +00:00
|
|
|
Q_PROPERTY(int length READ length NOTIFY textChanged)
|
2011-04-27 12:13:26 +00:00
|
|
|
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
|
|
|
|
Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged)
|
|
|
|
Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor NOTIFY selectedTextColorChanged)
|
|
|
|
Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
|
|
|
|
Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign RESET resetHAlign NOTIFY horizontalAlignmentChanged)
|
|
|
|
Q_PROPERTY(HAlignment effectiveHorizontalAlignment READ effectiveHAlign NOTIFY effectiveHorizontalAlignmentChanged)
|
2011-12-15 01:36:54 +00:00
|
|
|
Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged)
|
|
|
|
Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged)
|
|
|
|
Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged)
|
|
|
|
Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
|
2012-02-23 04:11:48 +00:00
|
|
|
Q_PROPERTY(QRectF cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged)
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_PROPERTY(QQmlComponent *cursorDelegate READ cursorDelegate WRITE setCursorDelegate NOTIFY cursorDelegateChanged)
|
2015-08-28 15:11:57 +00:00
|
|
|
Q_PROPERTY(bool overwriteMode READ overwriteMode WRITE setOverwriteMode NOTIFY overwriteModeChanged)
|
2011-04-27 12:13:26 +00:00
|
|
|
Q_PROPERTY(int selectionStart READ selectionStart NOTIFY selectionStartChanged)
|
|
|
|
Q_PROPERTY(int selectionEnd READ selectionEnd NOTIFY selectionEndChanged)
|
|
|
|
Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectedTextChanged)
|
|
|
|
|
|
|
|
Q_PROPERTY(int maximumLength READ maxLength WRITE setMaxLength NOTIFY maximumLengthChanged)
|
|
|
|
Q_PROPERTY(QValidator* validator READ validator WRITE setValidator NOTIFY validatorChanged)
|
|
|
|
Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask NOTIFY inputMaskChanged)
|
2012-02-15 12:30:44 +00:00
|
|
|
Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints NOTIFY inputMethodHintsChanged)
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged)
|
|
|
|
Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode NOTIFY echoModeChanged)
|
|
|
|
Q_PROPERTY(bool activeFocusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY activeFocusOnPressChanged)
|
|
|
|
Q_PROPERTY(QString passwordCharacter READ passwordCharacter WRITE setPasswordCharacter NOTIFY passwordCharacterChanged)
|
2020-01-16 12:42:11 +00:00
|
|
|
Q_PROPERTY(int passwordMaskDelay READ passwordMaskDelay WRITE setPasswordMaskDelay RESET resetPasswordMaskDelay NOTIFY passwordMaskDelayChanged REVISION(2, 4))
|
2011-04-27 12:13:26 +00:00
|
|
|
Q_PROPERTY(QString displayText READ displayText NOTIFY displayTextChanged)
|
2020-01-16 12:42:11 +00:00
|
|
|
Q_PROPERTY(QString preeditText READ preeditText NOTIFY preeditTextChanged REVISION(2, 7))
|
2011-04-27 12:13:26 +00:00
|
|
|
Q_PROPERTY(bool autoScroll READ autoScroll WRITE setAutoScroll NOTIFY autoScrollChanged)
|
|
|
|
Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged)
|
|
|
|
Q_PROPERTY(SelectionMode mouseSelectionMode READ mouseSelectionMode WRITE setMouseSelectionMode NOTIFY mouseSelectionModeChanged)
|
2012-01-20 06:10:23 +00:00
|
|
|
Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection NOTIFY persistentSelectionChanged)
|
2011-04-27 12:13:26 +00:00
|
|
|
Q_PROPERTY(bool canPaste READ canPaste NOTIFY canPasteChanged)
|
2012-01-10 01:52:43 +00:00
|
|
|
Q_PROPERTY(bool canUndo READ canUndo NOTIFY canUndoChanged)
|
|
|
|
Q_PROPERTY(bool canRedo READ canRedo NOTIFY canRedoChanged)
|
2011-04-27 12:13:26 +00:00
|
|
|
Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged)
|
2012-02-07 01:57:42 +00:00
|
|
|
Q_PROPERTY(qreal contentWidth READ contentWidth NOTIFY contentSizeChanged)
|
|
|
|
Q_PROPERTY(qreal contentHeight READ contentHeight NOTIFY contentSizeChanged)
|
2012-07-04 12:56:38 +00:00
|
|
|
Q_PROPERTY(RenderType renderType READ renderType WRITE setRenderType NOTIFY renderTypeChanged)
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2020-01-16 12:42:11 +00:00
|
|
|
Q_PROPERTY(qreal padding READ padding WRITE setPadding RESET resetPadding NOTIFY paddingChanged REVISION(2, 6))
|
|
|
|
Q_PROPERTY(qreal topPadding READ topPadding WRITE setTopPadding RESET resetTopPadding NOTIFY topPaddingChanged REVISION(2, 6))
|
|
|
|
Q_PROPERTY(qreal leftPadding READ leftPadding WRITE setLeftPadding RESET resetLeftPadding NOTIFY leftPaddingChanged REVISION(2, 6))
|
|
|
|
Q_PROPERTY(qreal rightPadding READ rightPadding WRITE setRightPadding RESET resetRightPadding NOTIFY rightPaddingChanged REVISION(2, 6))
|
|
|
|
Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding RESET resetBottomPadding NOTIFY bottomPaddingChanged REVISION(2, 6))
|
2019-08-21 16:34:21 +00:00
|
|
|
QML_NAMED_ELEMENT(TextInput)
|
2020-01-16 12:42:11 +00:00
|
|
|
QML_ADDED_IN_VERSION(2, 0)
|
2015-02-02 16:51:16 +00:00
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
public:
|
2018-02-21 09:41:54 +00:00
|
|
|
QQuickTextInput(QQuickItem * parent=nullptr);
|
2011-10-14 08:51:42 +00:00
|
|
|
~QQuickTextInput();
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2017-09-20 18:57:39 +00:00
|
|
|
void componentComplete() override;
|
2011-12-15 01:36:54 +00:00
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
enum EchoMode {//To match QLineEdit::EchoMode
|
|
|
|
Normal,
|
|
|
|
NoEcho,
|
|
|
|
Password,
|
|
|
|
PasswordEchoOnEdit
|
|
|
|
};
|
2015-05-13 07:59:40 +00:00
|
|
|
Q_ENUM(EchoMode)
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
enum HAlignment {
|
|
|
|
AlignLeft = Qt::AlignLeft,
|
|
|
|
AlignRight = Qt::AlignRight,
|
|
|
|
AlignHCenter = Qt::AlignHCenter
|
|
|
|
};
|
2015-05-13 07:59:40 +00:00
|
|
|
Q_ENUM(HAlignment)
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-12-15 01:36:54 +00:00
|
|
|
enum VAlignment {
|
|
|
|
AlignTop = Qt::AlignTop,
|
|
|
|
AlignBottom = Qt::AlignBottom,
|
|
|
|
AlignVCenter = Qt::AlignVCenter
|
|
|
|
};
|
2015-05-13 07:59:40 +00:00
|
|
|
Q_ENUM(VAlignment)
|
2011-12-15 01:36:54 +00:00
|
|
|
|
|
|
|
enum WrapMode {
|
|
|
|
NoWrap = QTextOption::NoWrap,
|
|
|
|
WordWrap = QTextOption::WordWrap,
|
|
|
|
WrapAnywhere = QTextOption::WrapAnywhere,
|
|
|
|
WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
|
|
|
|
Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
|
|
|
|
};
|
2015-05-13 07:59:40 +00:00
|
|
|
Q_ENUM(WrapMode)
|
2011-12-15 01:36:54 +00:00
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
enum SelectionMode {
|
|
|
|
SelectCharacters,
|
|
|
|
SelectWords
|
|
|
|
};
|
2015-05-13 07:59:40 +00:00
|
|
|
Q_ENUM(SelectionMode)
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
enum CursorPosition {
|
|
|
|
CursorBetweenCharacters,
|
|
|
|
CursorOnCharacter
|
|
|
|
};
|
2015-05-13 07:59:40 +00:00
|
|
|
Q_ENUM(CursorPosition)
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-07-04 12:56:38 +00:00
|
|
|
enum RenderType { QtRendering,
|
|
|
|
NativeRendering
|
|
|
|
};
|
2015-05-13 07:59:40 +00:00
|
|
|
Q_ENUM(RenderType)
|
2011-12-15 01:36:54 +00:00
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
//Auxilliary functions needed to control the TextInput from QML
|
2013-05-08 14:22:39 +00:00
|
|
|
Q_INVOKABLE void positionAt(QQmlV4Function *args) const;
|
2011-04-27 12:13:26 +00:00
|
|
|
Q_INVOKABLE QRectF positionToRectangle(int pos) const;
|
|
|
|
Q_INVOKABLE void moveCursorSelection(int pos);
|
|
|
|
Q_INVOKABLE void moveCursorSelection(int pos, SelectionMode mode);
|
|
|
|
|
2012-07-04 12:56:38 +00:00
|
|
|
RenderType renderType() const;
|
|
|
|
void setRenderType(RenderType renderType);
|
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
QString text() const;
|
|
|
|
void setText(const QString &);
|
|
|
|
|
2012-01-04 00:53:26 +00:00
|
|
|
int length() const;
|
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
QFont font() const;
|
|
|
|
void setFont(const QFont &font);
|
|
|
|
|
|
|
|
QColor color() const;
|
|
|
|
void setColor(const QColor &c);
|
|
|
|
|
|
|
|
QColor selectionColor() const;
|
|
|
|
void setSelectionColor(const QColor &c);
|
|
|
|
|
|
|
|
QColor selectedTextColor() const;
|
|
|
|
void setSelectedTextColor(const QColor &c);
|
|
|
|
|
|
|
|
HAlignment hAlign() const;
|
|
|
|
void setHAlign(HAlignment align);
|
|
|
|
void resetHAlign();
|
|
|
|
HAlignment effectiveHAlign() const;
|
|
|
|
|
2011-12-15 01:36:54 +00:00
|
|
|
VAlignment vAlign() const;
|
|
|
|
void setVAlign(VAlignment align);
|
|
|
|
|
|
|
|
WrapMode wrapMode() const;
|
|
|
|
void setWrapMode(WrapMode w);
|
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
bool isReadOnly() const;
|
|
|
|
void setReadOnly(bool);
|
|
|
|
|
|
|
|
bool isCursorVisible() const;
|
|
|
|
void setCursorVisible(bool on);
|
|
|
|
|
|
|
|
int cursorPosition() const;
|
|
|
|
void setCursorPosition(int cp);
|
|
|
|
|
2012-02-23 04:11:48 +00:00
|
|
|
QRectF cursorRectangle() const;
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
int selectionStart() const;
|
|
|
|
int selectionEnd() const;
|
|
|
|
|
|
|
|
QString selectedText() const;
|
|
|
|
|
|
|
|
int maxLength() const;
|
|
|
|
void setMaxLength(int ml);
|
|
|
|
|
|
|
|
QValidator * validator() const;
|
|
|
|
void setValidator(QValidator* v);
|
2014-09-09 15:35:33 +00:00
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
QString inputMask() const;
|
|
|
|
void setInputMask(const QString &im);
|
|
|
|
|
|
|
|
EchoMode echoMode() const;
|
|
|
|
void setEchoMode(EchoMode echo);
|
|
|
|
|
|
|
|
QString passwordCharacter() const;
|
|
|
|
void setPasswordCharacter(const QString &str);
|
|
|
|
|
2014-03-11 10:04:52 +00:00
|
|
|
int passwordMaskDelay() const;
|
|
|
|
void setPasswordMaskDelay(int delay);
|
|
|
|
void resetPasswordMaskDelay();
|
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
QString displayText() const;
|
2020-01-16 12:42:11 +00:00
|
|
|
Q_REVISION(2, 7) QString preeditText() const;
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlComponent* cursorDelegate() const;
|
|
|
|
void setCursorDelegate(QQmlComponent*);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2015-08-28 15:11:57 +00:00
|
|
|
bool overwriteMode() const;
|
|
|
|
void setOverwriteMode(bool overwrite);
|
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
bool focusOnPress() const;
|
|
|
|
void setFocusOnPress(bool);
|
|
|
|
|
|
|
|
bool autoScroll() const;
|
|
|
|
void setAutoScroll(bool);
|
|
|
|
|
|
|
|
bool selectByMouse() const;
|
|
|
|
void setSelectByMouse(bool);
|
|
|
|
|
|
|
|
SelectionMode mouseSelectionMode() const;
|
|
|
|
void setMouseSelectionMode(SelectionMode mode);
|
|
|
|
|
2012-01-20 06:10:23 +00:00
|
|
|
bool persistentSelection() const;
|
|
|
|
void setPersistentSelection(bool persist);
|
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
bool hasAcceptableInput() const;
|
|
|
|
|
2016-11-16 13:22:36 +00:00
|
|
|
#if QT_CONFIG(im)
|
2017-09-20 18:57:39 +00:00
|
|
|
QVariant inputMethodQuery(Qt::InputMethodQuery property) const override;
|
2020-01-16 12:42:11 +00:00
|
|
|
Q_REVISION(2, 4) Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery query, const QVariant &argument) const;
|
2012-11-22 17:47:45 +00:00
|
|
|
#endif
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2017-09-20 18:57:39 +00:00
|
|
|
QRectF boundingRect() const override;
|
|
|
|
QRectF clipRect() const override;
|
2012-04-19 01:08:28 +00:00
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
bool canPaste() const;
|
|
|
|
|
2012-01-10 01:52:43 +00:00
|
|
|
bool canUndo() const;
|
|
|
|
bool canRedo() const;
|
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
bool isInputMethodComposing() const;
|
|
|
|
|
2012-02-15 12:30:44 +00:00
|
|
|
Qt::InputMethodHints inputMethodHints() const;
|
|
|
|
void setInputMethodHints(Qt::InputMethodHints hints);
|
2011-05-04 07:53:51 +00:00
|
|
|
|
2012-01-04 00:53:26 +00:00
|
|
|
Q_INVOKABLE QString getText(int start, int end) const;
|
|
|
|
|
2012-02-07 01:57:42 +00:00
|
|
|
qreal contentWidth() const;
|
|
|
|
qreal contentHeight() const;
|
|
|
|
|
2015-02-02 16:51:16 +00:00
|
|
|
qreal padding() const;
|
|
|
|
void setPadding(qreal padding);
|
|
|
|
void resetPadding();
|
|
|
|
|
|
|
|
qreal topPadding() const;
|
|
|
|
void setTopPadding(qreal padding);
|
|
|
|
void resetTopPadding();
|
|
|
|
|
|
|
|
qreal leftPadding() const;
|
|
|
|
void setLeftPadding(qreal padding);
|
|
|
|
void resetLeftPadding();
|
|
|
|
|
|
|
|
qreal rightPadding() const;
|
|
|
|
void setRightPadding(qreal padding);
|
|
|
|
void resetRightPadding();
|
|
|
|
|
|
|
|
qreal bottomPadding() const;
|
|
|
|
void setBottomPadding(qreal padding);
|
|
|
|
void resetBottomPadding();
|
|
|
|
|
Invalidate text when application fonts are added or removed
We had multiple related issues due to application fonts being added
or removed during the application lifetime.
1. If a text had font family "foo" set, and this font did not
exist at the time, then loading "foo" at a later stage would not
update the text to use the correct font, since the result of
the previous request had been cached.
2. A variation of #1 was if the font "foo" was loaded by a FontLoader
in the scene and referred to by name in the text component. In this
case, there was a race condition, where the font lookup would sometimes
yield different results on the main thread and on the render thread,
and text would be garbled.
3. When a font was removed from the font database, then references to
it would remain in the caches (glyph cache + font cache) in the render
thread. With certain backends (DirectWrite, CoreText) this caused errors
or even crashes, as the cached font engines would be referring to data
that had been removed.
The work-around for #1 and #2 was merely to avoid hardcoding names for
fonts, but instead getting them from the FontLoader. This way, you can
avoid requesting the font family before it is available (and thus avoid
caching the wrong result). However, for #3 there is no known work-around.
This patch fixes all three (together with a smaller patch for qtbase) by
invalidating all text and related caches in Qt Quick when fonts are
either added or removed from the font database. This does add some
overhead if font loading happens during runtime, but the alternative is
broken behavior and dangling pointers.
This is done during the synchronization step. Before synchronization,
the font cache is flushed and all text components are marked for update,
so that fonts are re-requested against the new font database.
After synchronization, we delete all distance field glyph caches which
are not currently in use, to avoid having references to stale application
font data in the list.
[ChangeLog][Text] Fix multiple issues with usage of application fonts when
they are added or removed during the lifetime of the application.
Task-number: QTBUG-100697
Task-number: QDS-1142
Change-Id: Ib309e54e0ee97b6be6d2a7211964043fd51c9ec5
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2022-03-18 11:57:01 +00:00
|
|
|
void invalidate() override;
|
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
Q_SIGNALS:
|
|
|
|
void textChanged();
|
|
|
|
void cursorPositionChanged();
|
2011-07-25 02:55:57 +00:00
|
|
|
void cursorRectangleChanged();
|
2011-04-27 12:13:26 +00:00
|
|
|
void selectionStartChanged();
|
|
|
|
void selectionEndChanged();
|
|
|
|
void selectedTextChanged();
|
|
|
|
void accepted();
|
|
|
|
void acceptableInputChanged();
|
2020-01-16 12:42:11 +00:00
|
|
|
Q_REVISION(2, 2) void editingFinished();
|
|
|
|
Q_REVISION(2, 9) void textEdited();
|
2012-02-20 07:18:20 +00:00
|
|
|
void colorChanged();
|
|
|
|
void selectionColorChanged();
|
|
|
|
void selectedTextColorChanged();
|
2011-04-27 12:13:26 +00:00
|
|
|
void fontChanged(const QFont &font);
|
2016-04-07 09:22:33 +00:00
|
|
|
void horizontalAlignmentChanged(QQuickTextInput::HAlignment alignment);
|
|
|
|
void verticalAlignmentChanged(QQuickTextInput::VAlignment alignment);
|
2011-12-15 01:36:54 +00:00
|
|
|
void wrapModeChanged();
|
2011-04-27 12:13:26 +00:00
|
|
|
void readOnlyChanged(bool isReadOnly);
|
|
|
|
void cursorVisibleChanged(bool isCursorVisible);
|
|
|
|
void cursorDelegateChanged();
|
2015-08-28 15:11:57 +00:00
|
|
|
void overwriteModeChanged(bool overwriteMode);
|
2011-04-27 12:13:26 +00:00
|
|
|
void maximumLengthChanged(int maximumLength);
|
|
|
|
void validatorChanged();
|
|
|
|
void inputMaskChanged(const QString &inputMask);
|
2016-04-07 09:22:33 +00:00
|
|
|
void echoModeChanged(QQuickTextInput::EchoMode echoMode);
|
2011-04-27 12:13:26 +00:00
|
|
|
void passwordCharacterChanged();
|
2020-01-16 12:42:11 +00:00
|
|
|
Q_REVISION(2, 4) void passwordMaskDelayChanged(int delay);
|
2011-04-27 12:13:26 +00:00
|
|
|
void displayTextChanged();
|
2020-01-16 12:42:11 +00:00
|
|
|
Q_REVISION(2, 7) void preeditTextChanged();
|
2011-04-27 12:13:26 +00:00
|
|
|
void activeFocusOnPressChanged(bool activeFocusOnPress);
|
|
|
|
void autoScrollChanged(bool autoScroll);
|
|
|
|
void selectByMouseChanged(bool selectByMouse);
|
2016-04-07 09:22:33 +00:00
|
|
|
void mouseSelectionModeChanged(QQuickTextInput::SelectionMode mode);
|
2012-01-20 06:10:23 +00:00
|
|
|
void persistentSelectionChanged();
|
2011-04-27 12:13:26 +00:00
|
|
|
void canPasteChanged();
|
2012-01-10 01:52:43 +00:00
|
|
|
void canUndoChanged();
|
|
|
|
void canRedoChanged();
|
2011-04-27 12:13:26 +00:00
|
|
|
void inputMethodComposingChanged();
|
|
|
|
void effectiveHorizontalAlignmentChanged();
|
2012-02-07 01:57:42 +00:00
|
|
|
void contentSizeChanged();
|
2012-02-15 12:30:44 +00:00
|
|
|
void inputMethodHintsChanged();
|
2012-07-04 12:56:38 +00:00
|
|
|
void renderTypeChanged();
|
2020-01-16 12:42:11 +00:00
|
|
|
Q_REVISION(2, 6) void paddingChanged();
|
|
|
|
Q_REVISION(2, 6) void topPaddingChanged();
|
|
|
|
Q_REVISION(2, 6) void leftPaddingChanged();
|
|
|
|
Q_REVISION(2, 6) void rightPaddingChanged();
|
|
|
|
Q_REVISION(2, 6) void bottomPaddingChanged();
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2014-10-16 14:57:08 +00:00
|
|
|
private:
|
|
|
|
void invalidateFontCaches();
|
2021-07-22 07:56:04 +00:00
|
|
|
void ensureActiveFocus(Qt::FocusReason reason);
|
2014-10-16 14:57:08 +00:00
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
protected:
|
2018-02-21 09:41:54 +00:00
|
|
|
QQuickTextInput(QQuickTextInputPrivate &dd, QQuickItem *parent = nullptr);
|
2015-06-18 19:38:57 +00:00
|
|
|
|
2020-03-23 15:07:09 +00:00
|
|
|
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
|
2014-08-09 14:18:01 +00:00
|
|
|
|
2017-09-20 18:57:39 +00:00
|
|
|
void mousePressEvent(QMouseEvent *event) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *event) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
|
|
|
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
|
|
|
void keyPressEvent(QKeyEvent* ev) override;
|
2016-11-16 13:22:36 +00:00
|
|
|
#if QT_CONFIG(im)
|
2017-09-20 18:57:39 +00:00
|
|
|
void inputMethodEvent(QInputMethodEvent *) override;
|
2012-11-22 17:47:45 +00:00
|
|
|
#endif
|
2017-09-20 18:57:39 +00:00
|
|
|
void mouseUngrabEvent() override;
|
|
|
|
bool event(QEvent *e) override;
|
|
|
|
void focusOutEvent(QFocusEvent *event) override;
|
|
|
|
void focusInEvent(QFocusEvent *event) override;
|
|
|
|
void timerEvent(QTimerEvent *event) override;
|
|
|
|
QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) override;
|
|
|
|
void updatePolish() override;
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
void selectAll();
|
|
|
|
void selectWord();
|
|
|
|
void select(int start, int end);
|
|
|
|
void deselect();
|
|
|
|
bool isRightToLeft(int start, int end);
|
2016-11-16 13:22:36 +00:00
|
|
|
#if QT_CONFIG(clipboard)
|
2011-04-27 12:13:26 +00:00
|
|
|
void cut();
|
|
|
|
void copy();
|
|
|
|
void paste();
|
|
|
|
#endif
|
2012-01-10 01:52:43 +00:00
|
|
|
void undo();
|
|
|
|
void redo();
|
2012-01-04 00:53:26 +00:00
|
|
|
void insert(int position, const QString &text);
|
|
|
|
void remove(int start, int end);
|
2020-01-16 12:42:11 +00:00
|
|
|
Q_REVISION(2, 4) void ensureVisible(int position);
|
|
|
|
Q_REVISION(2, 7) void clear();
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void selectionChanged();
|
|
|
|
void createCursor();
|
2014-05-16 12:35:23 +00:00
|
|
|
void updateCursorRectangle(bool scroll = true);
|
2011-04-27 12:13:26 +00:00
|
|
|
void q_canPasteChanged();
|
2012-01-09 11:41:36 +00:00
|
|
|
void q_updateAlignment();
|
2011-11-24 12:48:19 +00:00
|
|
|
void triggerPreprocess();
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2016-11-16 13:22:36 +00:00
|
|
|
#if QT_CONFIG(validator)
|
2012-06-21 06:44:30 +00:00
|
|
|
void q_validatorChanged();
|
|
|
|
#endif
|
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
private:
|
2012-05-04 06:07:32 +00:00
|
|
|
friend class QQuickTextUtil;
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
Q_DECLARE_PRIVATE(QQuickTextInput)
|
2011-04-27 12:13:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QML_DECLARE_TYPE(QQuickTextInput)
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
#endif // QQUICKTEXTINPUT_P_H
|