qtdeclarative/src/quick/items/qquicktextinput_p.h

421 lines
15 KiB
C
Raw Normal View History

// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QQUICKTEXTINPUT_P_H
#define QQUICKTEXTINPUT_P_H
//
// 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.
//
#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"
#include <QtGui/qtextoption.h>
Fix build with -no-feature-validator By removing property, getter, setter and notify signal for validator. .../qmetatype.h: In instantiation of ‘constexpr bool QtPrivate::checkTypeIsSuitableForMetaType() [with X = QValidator*]’: .../qmetatype.h:2589:9: required from ‘constexpr const QtPrivate::QMetaTypeInterface* QtPrivate::qTryMetaTypeInterfaceForType() [with Unique = void; TypeCompletePair = QtPrivate::TypeAndForceComplete<QValidator*, std::integral_constant<bool, true> >]’ .../qmetatype.h:2639:102: required from ‘constexpr const QtPrivate::QMetaTypeInterface* const qt_metaTypeArray [72]<int, QVariant, QQmlInstanceModel*, bool, int, int, QString, QString, QString, QQmlComponent*, QQuickItem*, QQuickPopup*, bool, bool, bool, QString, QValidator*, QFlags<Qt::InputMethodHint>, bool, bool, double, double, QVariant, QString, bool, QQuickComboBox::ImplicitContentWidthPolicy, QQuickComboBox, void, int, void, int, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, QString, int, int, const QString&, QFlags<Qt::MatchFlag>, int, const QString&, QVariant, int, int, const QVariant&>’ .../moc_qquickcombobox_p.cpp:588:5: required from here .../qmetatype.h:1181:55: error: static assertion failed: Pointer Meta Types must either point to fully-defined types or be declared with Q_DECLARE_OPAQUE_POINTER(T *) Pick-to: 6.5 Change-Id: I0ee5ae9c84bc977571f39788299f1d84a7e582c5 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-01-16 05:21:43 +00:00
#if QT_CONFIG(validator)
#include <QtGui/qvalidator.h>
Fix build with -no-feature-validator By removing property, getter, setter and notify signal for validator. .../qmetatype.h: In instantiation of ‘constexpr bool QtPrivate::checkTypeIsSuitableForMetaType() [with X = QValidator*]’: .../qmetatype.h:2589:9: required from ‘constexpr const QtPrivate::QMetaTypeInterface* QtPrivate::qTryMetaTypeInterfaceForType() [with Unique = void; TypeCompletePair = QtPrivate::TypeAndForceComplete<QValidator*, std::integral_constant<bool, true> >]’ .../qmetatype.h:2639:102: required from ‘constexpr const QtPrivate::QMetaTypeInterface* const qt_metaTypeArray [72]<int, QVariant, QQmlInstanceModel*, bool, int, int, QString, QString, QString, QQmlComponent*, QQuickItem*, QQuickPopup*, bool, bool, bool, QString, QValidator*, QFlags<Qt::InputMethodHint>, bool, bool, double, double, QVariant, QString, bool, QQuickComboBox::ImplicitContentWidthPolicy, QQuickComboBox, void, int, void, int, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, QString, int, int, const QString&, QFlags<Qt::MatchFlag>, int, const QString&, QVariant, int, int, const QVariant&>’ .../moc_qquickcombobox_p.cpp:588:5: required from here .../qmetatype.h:1181:55: error: static assertion failed: Pointer Meta Types must either point to fully-defined types or be declared with Q_DECLARE_OPAQUE_POINTER(T *) Pick-to: 6.5 Change-Id: I0ee5ae9c84bc977571f39788299f1d84a7e582c5 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-01-16 05:21:43 +00:00
#endif
QT_BEGIN_NAMESPACE
class QQuickTextInputPrivate;
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
{
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)
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged FINAL)
Q_PROPERTY(int length READ length NOTIFY textChanged FINAL)
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL)
Q_PROPERTY(QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged FINAL)
Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor NOTIFY selectedTextColorChanged FINAL)
Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign RESET resetHAlign NOTIFY horizontalAlignmentChanged FINAL)
Q_PROPERTY(HAlignment effectiveHorizontalAlignment READ effectiveHAlign NOTIFY effectiveHorizontalAlignmentChanged FINAL)
Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged FINAL)
Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged FINAL)
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged FINAL)
Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged FINAL)
Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged FINAL)
Q_PROPERTY(QRectF cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged FINAL)
Q_PROPERTY(QQmlComponent *cursorDelegate READ cursorDelegate WRITE setCursorDelegate NOTIFY cursorDelegateChanged FINAL)
Q_PROPERTY(bool overwriteMode READ overwriteMode WRITE setOverwriteMode NOTIFY overwriteModeChanged FINAL)
Q_PROPERTY(int selectionStart READ selectionStart NOTIFY selectionStartChanged FINAL)
Q_PROPERTY(int selectionEnd READ selectionEnd NOTIFY selectionEndChanged FINAL)
Q_PROPERTY(QString selectedText READ selectedText NOTIFY selectedTextChanged FINAL)
Q_PROPERTY(int maximumLength READ maxLength WRITE setMaxLength NOTIFY maximumLengthChanged FINAL)
Fix build with -no-feature-validator By removing property, getter, setter and notify signal for validator. .../qmetatype.h: In instantiation of ‘constexpr bool QtPrivate::checkTypeIsSuitableForMetaType() [with X = QValidator*]’: .../qmetatype.h:2589:9: required from ‘constexpr const QtPrivate::QMetaTypeInterface* QtPrivate::qTryMetaTypeInterfaceForType() [with Unique = void; TypeCompletePair = QtPrivate::TypeAndForceComplete<QValidator*, std::integral_constant<bool, true> >]’ .../qmetatype.h:2639:102: required from ‘constexpr const QtPrivate::QMetaTypeInterface* const qt_metaTypeArray [72]<int, QVariant, QQmlInstanceModel*, bool, int, int, QString, QString, QString, QQmlComponent*, QQuickItem*, QQuickPopup*, bool, bool, bool, QString, QValidator*, QFlags<Qt::InputMethodHint>, bool, bool, double, double, QVariant, QString, bool, QQuickComboBox::ImplicitContentWidthPolicy, QQuickComboBox, void, int, void, int, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, QString, int, int, const QString&, QFlags<Qt::MatchFlag>, int, const QString&, QVariant, int, int, const QVariant&>’ .../moc_qquickcombobox_p.cpp:588:5: required from here .../qmetatype.h:1181:55: error: static assertion failed: Pointer Meta Types must either point to fully-defined types or be declared with Q_DECLARE_OPAQUE_POINTER(T *) Pick-to: 6.5 Change-Id: I0ee5ae9c84bc977571f39788299f1d84a7e582c5 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-01-16 05:21:43 +00:00
#if QT_CONFIG(validator)
Q_PROPERTY(QValidator* validator READ validator WRITE setValidator NOTIFY validatorChanged FINAL)
Fix build with -no-feature-validator By removing property, getter, setter and notify signal for validator. .../qmetatype.h: In instantiation of ‘constexpr bool QtPrivate::checkTypeIsSuitableForMetaType() [with X = QValidator*]’: .../qmetatype.h:2589:9: required from ‘constexpr const QtPrivate::QMetaTypeInterface* QtPrivate::qTryMetaTypeInterfaceForType() [with Unique = void; TypeCompletePair = QtPrivate::TypeAndForceComplete<QValidator*, std::integral_constant<bool, true> >]’ .../qmetatype.h:2639:102: required from ‘constexpr const QtPrivate::QMetaTypeInterface* const qt_metaTypeArray [72]<int, QVariant, QQmlInstanceModel*, bool, int, int, QString, QString, QString, QQmlComponent*, QQuickItem*, QQuickPopup*, bool, bool, bool, QString, QValidator*, QFlags<Qt::InputMethodHint>, bool, bool, double, double, QVariant, QString, bool, QQuickComboBox::ImplicitContentWidthPolicy, QQuickComboBox, void, int, void, int, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, QString, int, int, const QString&, QFlags<Qt::MatchFlag>, int, const QString&, QVariant, int, int, const QVariant&>’ .../moc_qquickcombobox_p.cpp:588:5: required from here .../qmetatype.h:1181:55: error: static assertion failed: Pointer Meta Types must either point to fully-defined types or be declared with Q_DECLARE_OPAQUE_POINTER(T *) Pick-to: 6.5 Change-Id: I0ee5ae9c84bc977571f39788299f1d84a7e582c5 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-01-16 05:21:43 +00:00
#endif
Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask NOTIFY inputMaskChanged FINAL)
Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints NOTIFY inputMethodHintsChanged FINAL)
Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged FINAL)
Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode NOTIFY echoModeChanged FINAL)
Q_PROPERTY(bool activeFocusOnPress READ focusOnPress WRITE setFocusOnPress NOTIFY activeFocusOnPressChanged FINAL)
Q_PROPERTY(QString passwordCharacter READ passwordCharacter WRITE setPasswordCharacter NOTIFY passwordCharacterChanged FINAL)
Q_PROPERTY(int passwordMaskDelay READ passwordMaskDelay WRITE setPasswordMaskDelay RESET resetPasswordMaskDelay NOTIFY passwordMaskDelayChanged REVISION(2, 4) FINAL)
Q_PROPERTY(QString displayText READ displayText NOTIFY displayTextChanged FINAL)
Q_PROPERTY(QString preeditText READ preeditText NOTIFY preeditTextChanged REVISION(2, 7) FINAL)
Q_PROPERTY(bool autoScroll READ autoScroll WRITE setAutoScroll NOTIFY autoScrollChanged FINAL)
Q_PROPERTY(bool selectByMouse READ selectByMouse WRITE setSelectByMouse NOTIFY selectByMouseChanged FINAL)
Q_PROPERTY(SelectionMode mouseSelectionMode READ mouseSelectionMode WRITE setMouseSelectionMode NOTIFY mouseSelectionModeChanged FINAL)
Q_PROPERTY(bool persistentSelection READ persistentSelection WRITE setPersistentSelection NOTIFY persistentSelectionChanged FINAL)
Q_PROPERTY(bool canPaste READ canPaste NOTIFY canPasteChanged FINAL)
Q_PROPERTY(bool canUndo READ canUndo NOTIFY canUndoChanged FINAL)
Q_PROPERTY(bool canRedo READ canRedo NOTIFY canRedoChanged FINAL)
Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged FINAL)
Q_PROPERTY(qreal contentWidth READ contentWidth NOTIFY contentSizeChanged FINAL)
Q_PROPERTY(qreal contentHeight READ contentHeight NOTIFY contentSizeChanged FINAL)
Q_PROPERTY(RenderType renderType READ renderType WRITE setRenderType NOTIFY renderTypeChanged FINAL)
Q_PROPERTY(qreal padding READ padding WRITE setPadding RESET resetPadding NOTIFY paddingChanged REVISION(2, 6) FINAL)
Q_PROPERTY(qreal topPadding READ topPadding WRITE setTopPadding RESET resetTopPadding NOTIFY topPaddingChanged REVISION(2, 6) FINAL)
Q_PROPERTY(qreal leftPadding READ leftPadding WRITE setLeftPadding RESET resetLeftPadding NOTIFY leftPaddingChanged REVISION(2, 6) FINAL)
Q_PROPERTY(qreal rightPadding READ rightPadding WRITE setRightPadding RESET resetRightPadding NOTIFY rightPaddingChanged REVISION(2, 6) FINAL)
Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding RESET resetBottomPadding NOTIFY bottomPaddingChanged REVISION(2, 6) FINAL)
QML_NAMED_ELEMENT(TextInput)
QML_ADDED_IN_VERSION(2, 0)
TextInput/Field: selectByMouse default=true, but not on touchscreens When you drag a finger across a TextInput or TextField, it should not select text. - your finger probably covers several characters, so you can't see where you're selecting until afterwards - if the item is in a Flickable, flicking by touch should be prioritized - if flicking happens, the text cursor should not move; but to avoid losing too much functionality, we allow it to move on release, if the TextInput or TextField gets the release (i.e. if it still has the exclusive grab) - TextField's pressed, pressAndHold and released signals continue to behave the same with touch as with mouse So now we distinguish mouse events that are synthesized from non-mouse devices and avoid mouse-like behaviors as described above, but there is no behavior change if the event comes from an actual mouse or touchpad. Since most users want selecting text by mouse to "just work", and an actual mouse is precise enough to do so, and dragging a Flickable with the mouse is unintuitive (since most UIs don't allow it and most mice have wheels), selectByMouse now defaults to true, and has the stricter meaning that its name implies. To select text on a touchscreen, the end-user needs to rely on text-selection handles, which are provided on touch-centric mobile platforms, and could also be implemented from scratch if someone builds a custom text field using TextInput. [ChangeLog][QtQuick][TextInput] The selectByMouse property is now enabled by default, but no longer enables selecting by dragging your finger across text on a touchscreen. Platforms that are optimized for touchscreens normally use special text-selection handles, which interact with Qt via QInputMethod. You can opt out of the behavior change by using an import version < 6.4. [ChangeLog][Controls][TextField] The selectByMouse property is now enabled by default, but no longer enables selecting by dragging your finger across text on a touchscreen. Platforms that are optimized for touchscreens normally use special text-selection handles, which interact with Qt via QInputMethod. You can opt out of the behavior change by using an import version < 6.4. Pick-to: 6.4 Task-number: QTBUG-10684 Task-number: QTBUG-38934 Task-number: QTBUG-101205 Change-Id: I6d3158dd48896a0bed37cbc0b2da01d313a499f8 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2022-02-24 08:00:48 +00:00
#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
QML_ADDED_IN_VERSION(6, 4)
#endif
public:
QQuickTextInput(QQuickItem * parent=nullptr);
~QQuickTextInput();
void componentComplete() override;
enum EchoMode {//To match QLineEdit::EchoMode
Normal,
NoEcho,
Password,
PasswordEchoOnEdit
};
Q_ENUM(EchoMode)
enum HAlignment {
AlignLeft = Qt::AlignLeft,
AlignRight = Qt::AlignRight,
AlignHCenter = Qt::AlignHCenter
};
Q_ENUM(HAlignment)
enum VAlignment {
AlignTop = Qt::AlignTop,
AlignBottom = Qt::AlignBottom,
AlignVCenter = Qt::AlignVCenter
};
Q_ENUM(VAlignment)
enum WrapMode {
NoWrap = QTextOption::NoWrap,
WordWrap = QTextOption::WordWrap,
WrapAnywhere = QTextOption::WrapAnywhere,
WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere, // COMPAT
Wrap = QTextOption::WrapAtWordBoundaryOrAnywhere
};
Q_ENUM(WrapMode)
enum SelectionMode {
SelectCharacters,
SelectWords
};
Q_ENUM(SelectionMode)
enum CursorPosition {
CursorBetweenCharacters,
CursorOnCharacter
};
Q_ENUM(CursorPosition)
enum RenderType { QtRendering,
NativeRendering
};
Q_ENUM(RenderType)
//Auxilliary functions needed to control the TextInput from QML
Q_INVOKABLE void positionAt(QQmlV4Function *args) const;
Q_INVOKABLE QRectF positionToRectangle(int pos) const;
Q_INVOKABLE void moveCursorSelection(int pos);
Q_INVOKABLE void moveCursorSelection(int pos, SelectionMode mode);
RenderType renderType() const;
void setRenderType(RenderType renderType);
QString text() const;
void setText(const QString &);
int length() const;
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;
VAlignment vAlign() const;
void setVAlign(VAlignment align);
WrapMode wrapMode() const;
void setWrapMode(WrapMode w);
bool isReadOnly() const;
void setReadOnly(bool);
bool isCursorVisible() const;
void setCursorVisible(bool on);
int cursorPosition() const;
void setCursorPosition(int cp);
QRectF cursorRectangle() const;
int selectionStart() const;
int selectionEnd() const;
QString selectedText() const;
int maxLength() const;
void setMaxLength(int ml);
Fix build with -no-feature-validator By removing property, getter, setter and notify signal for validator. .../qmetatype.h: In instantiation of ‘constexpr bool QtPrivate::checkTypeIsSuitableForMetaType() [with X = QValidator*]’: .../qmetatype.h:2589:9: required from ‘constexpr const QtPrivate::QMetaTypeInterface* QtPrivate::qTryMetaTypeInterfaceForType() [with Unique = void; TypeCompletePair = QtPrivate::TypeAndForceComplete<QValidator*, std::integral_constant<bool, true> >]’ .../qmetatype.h:2639:102: required from ‘constexpr const QtPrivate::QMetaTypeInterface* const qt_metaTypeArray [72]<int, QVariant, QQmlInstanceModel*, bool, int, int, QString, QString, QString, QQmlComponent*, QQuickItem*, QQuickPopup*, bool, bool, bool, QString, QValidator*, QFlags<Qt::InputMethodHint>, bool, bool, double, double, QVariant, QString, bool, QQuickComboBox::ImplicitContentWidthPolicy, QQuickComboBox, void, int, void, int, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, QString, int, int, const QString&, QFlags<Qt::MatchFlag>, int, const QString&, QVariant, int, int, const QVariant&>’ .../moc_qquickcombobox_p.cpp:588:5: required from here .../qmetatype.h:1181:55: error: static assertion failed: Pointer Meta Types must either point to fully-defined types or be declared with Q_DECLARE_OPAQUE_POINTER(T *) Pick-to: 6.5 Change-Id: I0ee5ae9c84bc977571f39788299f1d84a7e582c5 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-01-16 05:21:43 +00:00
#if QT_CONFIG(validator)
QValidator * validator() const;
void setValidator(QValidator* v);
Fix build with -no-feature-validator By removing property, getter, setter and notify signal for validator. .../qmetatype.h: In instantiation of ‘constexpr bool QtPrivate::checkTypeIsSuitableForMetaType() [with X = QValidator*]’: .../qmetatype.h:2589:9: required from ‘constexpr const QtPrivate::QMetaTypeInterface* QtPrivate::qTryMetaTypeInterfaceForType() [with Unique = void; TypeCompletePair = QtPrivate::TypeAndForceComplete<QValidator*, std::integral_constant<bool, true> >]’ .../qmetatype.h:2639:102: required from ‘constexpr const QtPrivate::QMetaTypeInterface* const qt_metaTypeArray [72]<int, QVariant, QQmlInstanceModel*, bool, int, int, QString, QString, QString, QQmlComponent*, QQuickItem*, QQuickPopup*, bool, bool, bool, QString, QValidator*, QFlags<Qt::InputMethodHint>, bool, bool, double, double, QVariant, QString, bool, QQuickComboBox::ImplicitContentWidthPolicy, QQuickComboBox, void, int, void, int, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, QString, int, int, const QString&, QFlags<Qt::MatchFlag>, int, const QString&, QVariant, int, int, const QVariant&>’ .../moc_qquickcombobox_p.cpp:588:5: required from here .../qmetatype.h:1181:55: error: static assertion failed: Pointer Meta Types must either point to fully-defined types or be declared with Q_DECLARE_OPAQUE_POINTER(T *) Pick-to: 6.5 Change-Id: I0ee5ae9c84bc977571f39788299f1d84a7e582c5 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-01-16 05:21:43 +00:00
#endif
QString inputMask() const;
void setInputMask(const QString &im);
EchoMode echoMode() const;
void setEchoMode(EchoMode echo);
QString passwordCharacter() const;
void setPasswordCharacter(const QString &str);
int passwordMaskDelay() const;
void setPasswordMaskDelay(int delay);
void resetPasswordMaskDelay();
QString displayText() const;
Q_REVISION(2, 7) QString preeditText() const;
QQmlComponent* cursorDelegate() const;
void setCursorDelegate(QQmlComponent*);
bool overwriteMode() const;
void setOverwriteMode(bool overwrite);
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);
bool persistentSelection() const;
void setPersistentSelection(bool persist);
bool hasAcceptableInput() const;
#if QT_CONFIG(im)
QVariant inputMethodQuery(Qt::InputMethodQuery property) const override;
Q_REVISION(2, 4) Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery query, const QVariant &argument) const;
#endif
QRectF boundingRect() const override;
QRectF clipRect() const override;
bool canPaste() const;
bool canUndo() const;
bool canRedo() const;
bool isInputMethodComposing() const;
Qt::InputMethodHints inputMethodHints() const;
void setInputMethodHints(Qt::InputMethodHints hints);
2011-05-04 07:53:51 +00:00
Q_INVOKABLE QString getText(int start, int end) const;
qreal contentWidth() const;
qreal contentHeight() const;
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;
Q_SIGNALS:
void textChanged();
void cursorPositionChanged();
void cursorRectangleChanged();
void selectionStartChanged();
void selectionEndChanged();
void selectedTextChanged();
void accepted();
void acceptableInputChanged();
Q_REVISION(2, 2) void editingFinished();
Q_REVISION(2, 9) void textEdited();
void colorChanged();
void selectionColorChanged();
void selectedTextColorChanged();
void fontChanged(const QFont &font);
void horizontalAlignmentChanged(QQuickTextInput::HAlignment alignment);
void verticalAlignmentChanged(QQuickTextInput::VAlignment alignment);
void wrapModeChanged();
void readOnlyChanged(bool isReadOnly);
void cursorVisibleChanged(bool isCursorVisible);
void cursorDelegateChanged();
void overwriteModeChanged(bool overwriteMode);
void maximumLengthChanged(int maximumLength);
Fix build with -no-feature-validator By removing property, getter, setter and notify signal for validator. .../qmetatype.h: In instantiation of ‘constexpr bool QtPrivate::checkTypeIsSuitableForMetaType() [with X = QValidator*]’: .../qmetatype.h:2589:9: required from ‘constexpr const QtPrivate::QMetaTypeInterface* QtPrivate::qTryMetaTypeInterfaceForType() [with Unique = void; TypeCompletePair = QtPrivate::TypeAndForceComplete<QValidator*, std::integral_constant<bool, true> >]’ .../qmetatype.h:2639:102: required from ‘constexpr const QtPrivate::QMetaTypeInterface* const qt_metaTypeArray [72]<int, QVariant, QQmlInstanceModel*, bool, int, int, QString, QString, QString, QQmlComponent*, QQuickItem*, QQuickPopup*, bool, bool, bool, QString, QValidator*, QFlags<Qt::InputMethodHint>, bool, bool, double, double, QVariant, QString, bool, QQuickComboBox::ImplicitContentWidthPolicy, QQuickComboBox, void, int, void, int, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, QString, int, int, const QString&, QFlags<Qt::MatchFlag>, int, const QString&, QVariant, int, int, const QVariant&>’ .../moc_qquickcombobox_p.cpp:588:5: required from here .../qmetatype.h:1181:55: error: static assertion failed: Pointer Meta Types must either point to fully-defined types or be declared with Q_DECLARE_OPAQUE_POINTER(T *) Pick-to: 6.5 Change-Id: I0ee5ae9c84bc977571f39788299f1d84a7e582c5 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-01-16 05:21:43 +00:00
#if QT_CONFIG(validator)
void validatorChanged();
Fix build with -no-feature-validator By removing property, getter, setter and notify signal for validator. .../qmetatype.h: In instantiation of ‘constexpr bool QtPrivate::checkTypeIsSuitableForMetaType() [with X = QValidator*]’: .../qmetatype.h:2589:9: required from ‘constexpr const QtPrivate::QMetaTypeInterface* QtPrivate::qTryMetaTypeInterfaceForType() [with Unique = void; TypeCompletePair = QtPrivate::TypeAndForceComplete<QValidator*, std::integral_constant<bool, true> >]’ .../qmetatype.h:2639:102: required from ‘constexpr const QtPrivate::QMetaTypeInterface* const qt_metaTypeArray [72]<int, QVariant, QQmlInstanceModel*, bool, int, int, QString, QString, QString, QQmlComponent*, QQuickItem*, QQuickPopup*, bool, bool, bool, QString, QValidator*, QFlags<Qt::InputMethodHint>, bool, bool, double, double, QVariant, QString, bool, QQuickComboBox::ImplicitContentWidthPolicy, QQuickComboBox, void, int, void, int, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, QString, int, int, const QString&, QFlags<Qt::MatchFlag>, int, const QString&, QVariant, int, int, const QVariant&>’ .../moc_qquickcombobox_p.cpp:588:5: required from here .../qmetatype.h:1181:55: error: static assertion failed: Pointer Meta Types must either point to fully-defined types or be declared with Q_DECLARE_OPAQUE_POINTER(T *) Pick-to: 6.5 Change-Id: I0ee5ae9c84bc977571f39788299f1d84a7e582c5 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-01-16 05:21:43 +00:00
#endif
void inputMaskChanged(const QString &inputMask);
void echoModeChanged(QQuickTextInput::EchoMode echoMode);
void passwordCharacterChanged();
Q_REVISION(2, 4) void passwordMaskDelayChanged(int delay);
void displayTextChanged();
Q_REVISION(2, 7) void preeditTextChanged();
void activeFocusOnPressChanged(bool activeFocusOnPress);
void autoScrollChanged(bool autoScroll);
void selectByMouseChanged(bool selectByMouse);
void mouseSelectionModeChanged(QQuickTextInput::SelectionMode mode);
void persistentSelectionChanged();
void canPasteChanged();
void canUndoChanged();
void canRedoChanged();
void inputMethodComposingChanged();
void effectiveHorizontalAlignmentChanged();
void contentSizeChanged();
void inputMethodHintsChanged();
void renderTypeChanged();
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();
private:
void invalidateFontCaches();
void ensureActiveFocus(Qt::FocusReason reason);
protected:
QQuickTextInput(QQuickTextInputPrivate &dd, QQuickItem *parent = nullptr);
TextInput/Field: selectByMouse default=true, but not on touchscreens When you drag a finger across a TextInput or TextField, it should not select text. - your finger probably covers several characters, so you can't see where you're selecting until afterwards - if the item is in a Flickable, flicking by touch should be prioritized - if flicking happens, the text cursor should not move; but to avoid losing too much functionality, we allow it to move on release, if the TextInput or TextField gets the release (i.e. if it still has the exclusive grab) - TextField's pressed, pressAndHold and released signals continue to behave the same with touch as with mouse So now we distinguish mouse events that are synthesized from non-mouse devices and avoid mouse-like behaviors as described above, but there is no behavior change if the event comes from an actual mouse or touchpad. Since most users want selecting text by mouse to "just work", and an actual mouse is precise enough to do so, and dragging a Flickable with the mouse is unintuitive (since most UIs don't allow it and most mice have wheels), selectByMouse now defaults to true, and has the stricter meaning that its name implies. To select text on a touchscreen, the end-user needs to rely on text-selection handles, which are provided on touch-centric mobile platforms, and could also be implemented from scratch if someone builds a custom text field using TextInput. [ChangeLog][QtQuick][TextInput] The selectByMouse property is now enabled by default, but no longer enables selecting by dragging your finger across text on a touchscreen. Platforms that are optimized for touchscreens normally use special text-selection handles, which interact with Qt via QInputMethod. You can opt out of the behavior change by using an import version < 6.4. [ChangeLog][Controls][TextField] The selectByMouse property is now enabled by default, but no longer enables selecting by dragging your finger across text on a touchscreen. Platforms that are optimized for touchscreens normally use special text-selection handles, which interact with Qt via QInputMethod. You can opt out of the behavior change by using an import version < 6.4. Pick-to: 6.4 Task-number: QTBUG-10684 Task-number: QTBUG-38934 Task-number: QTBUG-101205 Change-Id: I6d3158dd48896a0bed37cbc0b2da01d313a499f8 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2022-02-24 08:00:48 +00:00
#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
void setOldSelectionDefault();
#endif
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
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;
#if QT_CONFIG(im)
void inputMethodEvent(QInputMethodEvent *) override;
#endif
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;
public Q_SLOTS:
void selectAll();
void selectWord();
void select(int start, int end);
void deselect();
bool isRightToLeft(int start, int end);
#if QT_CONFIG(clipboard)
void cut();
void copy();
void paste();
#endif
void undo();
void redo();
void insert(int position, const QString &text);
void remove(int start, int end);
Q_REVISION(2, 4) void ensureVisible(int position);
Q_REVISION(2, 7) void clear();
private Q_SLOTS:
void selectionChanged();
void createCursor();
void updateCursorRectangle(bool scroll = true);
void q_canPasteChanged();
void q_updateAlignment();
void triggerPreprocess();
#if QT_CONFIG(validator)
void q_validatorChanged();
#endif
private:
friend class QQuickTextUtil;
Q_DECLARE_PRIVATE(QQuickTextInput)
};
TextInput/Field: selectByMouse default=true, but not on touchscreens When you drag a finger across a TextInput or TextField, it should not select text. - your finger probably covers several characters, so you can't see where you're selecting until afterwards - if the item is in a Flickable, flicking by touch should be prioritized - if flicking happens, the text cursor should not move; but to avoid losing too much functionality, we allow it to move on release, if the TextInput or TextField gets the release (i.e. if it still has the exclusive grab) - TextField's pressed, pressAndHold and released signals continue to behave the same with touch as with mouse So now we distinguish mouse events that are synthesized from non-mouse devices and avoid mouse-like behaviors as described above, but there is no behavior change if the event comes from an actual mouse or touchpad. Since most users want selecting text by mouse to "just work", and an actual mouse is precise enough to do so, and dragging a Flickable with the mouse is unintuitive (since most UIs don't allow it and most mice have wheels), selectByMouse now defaults to true, and has the stricter meaning that its name implies. To select text on a touchscreen, the end-user needs to rely on text-selection handles, which are provided on touch-centric mobile platforms, and could also be implemented from scratch if someone builds a custom text field using TextInput. [ChangeLog][QtQuick][TextInput] The selectByMouse property is now enabled by default, but no longer enables selecting by dragging your finger across text on a touchscreen. Platforms that are optimized for touchscreens normally use special text-selection handles, which interact with Qt via QInputMethod. You can opt out of the behavior change by using an import version < 6.4. [ChangeLog][Controls][TextField] The selectByMouse property is now enabled by default, but no longer enables selecting by dragging your finger across text on a touchscreen. Platforms that are optimized for touchscreens normally use special text-selection handles, which interact with Qt via QInputMethod. You can opt out of the behavior change by using an import version < 6.4. Pick-to: 6.4 Task-number: QTBUG-10684 Task-number: QTBUG-38934 Task-number: QTBUG-101205 Change-Id: I6d3158dd48896a0bed37cbc0b2da01d313a499f8 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2022-02-24 08:00:48 +00:00
#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
class QQuickPre64TextInput : public QQuickTextInput {
Q_OBJECT
QML_NAMED_ELEMENT(TextInput)
QML_ADDED_IN_VERSION(2, 0)
QML_REMOVED_IN_VERSION(6, 4)
public:
QQuickPre64TextInput(QQuickItem *parent = nullptr);
};
#endif
QT_END_NAMESPACE
QML_DECLARE_TYPE(QQuickTextInput)
#endif // QQUICKTEXTINPUT_P_H