Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquicktextutil_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QQUICKTEXTUTIL_P_H
6#define QQUICKTEXTUTIL_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtQml/qqmlincubator.h>
20#include <QtQuick/qquickitem.h>
21#include <QtQuick/qquickwindow.h>
22#include <QtCore/private/qglobal_p.h>
23#include <QtQml/qqmlcomponent.h>
24
26
27class QQuickTextUtil : public QObject // For the benefit of translations.
28{
29 Q_OBJECT
30public:
31 template <typename Private> static void setCursorDelegate(Private *d, QQmlComponent *delegate);
32 template <typename Private> static void createCursor(Private *d);
33
34 template <typename T> static typename T::RenderType textRenderType();
35
36 static qreal alignedX(qreal textWidth, qreal itemWidth, int alignment);
37 static qreal alignedY(qreal textHeight, qreal itemHeight, int alignment);
38
39private:
40 static QQuickItem *createCursor(
41 QQmlComponent *component,
42 QQuickItem *parent,
43 const QRectF &cursorRectangle,
44 const char *className);
45
46};
47
48template <typename Private>
49void QQuickTextUtil::setCursorDelegate(Private *d, QQmlComponent *delegate)
50{
51 if (d->cursorComponent == delegate)
52 return;
53
54 typename Private::Public *parent = d->q_func();
55
56 if (d->cursorComponent) {
57 disconnect(d->cursorComponent, SIGNAL(statusChanged(QQmlComponent::Status)),
58 parent, SLOT(createCursor()));
59 }
60
61 delete d->cursorItem;
62 d->cursorItem = 0;
63 d->cursorPending = true;
64
65 d->cursorComponent = delegate;
66
67 if (parent->isCursorVisible() && parent->isComponentComplete())
68 createCursor(d);
69
70 Q_EMIT parent->cursorDelegateChanged();
71}
72
73template <typename Private>
74void QQuickTextUtil::createCursor(Private *d)
75{
76 if (!d->cursorPending)
77 return;
78
79 d->cursorPending = false;
80
81 typename Private::Public *parent = d->q_func();
82 if (d->cursorComponent) {
83 d->cursorItem = createCursor(
84 d->cursorComponent,
85 parent,
86 parent->cursorRectangle(),
87 Private::Public::staticMetaObject.className());
88 }
89
90 d->setNativeCursorEnabled(!d->cursorItem);
91 d->updateType = Private::UpdatePaintNode;
92 parent->update();
93}
94
95template <typename T>
96typename T::RenderType QQuickTextUtil::textRenderType()
97{
98 switch (QQuickWindow::textRenderType()) {
99 case QQuickWindow::QtTextRendering:
100 return T::QtRendering;
101 case QQuickWindow::NativeTextRendering:
102 return T::NativeRendering;
103 case QQuickWindow::CurveTextRendering:
104 return T::CurveRendering;
105 }
106
107 Q_UNREACHABLE_RETURN(T::QtRendering);
108}
109
110QT_END_NAMESPACE
111
112#endif
The QSGTextNode class is a class for drawing text layouts and text documents in the Qt Quick scene gr...
Definition qsgtextnode.h:14
Q_STATIC_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core")
#define QQUICKTEXT_LARGETEXT_THRESHOLD
static void getLinks_helper(const QTextLayout *layout, QVector< QQuickTextPrivate::LinkDesc > *links)