Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquicktextutil.cpp
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
4#include "qquicktextutil_p.h"
5
6#include <QtQml/qqmlinfo.h>
7
8#include <private/qqmlglobal_p.h>
9#include <private/qquickitem_p.h>
10
12
14 QQmlComponent *component, QQuickItem *parent, const QRectF &rectangle, const char *className)
15{
16 QQuickItem *item = nullptr;
17 if (component->isReady()) {
18 QQmlContext *creationContext = component->creationContext();
19
20 if (QObject *object = component->beginCreate(creationContext
21 ? creationContext
22 : qmlContext(parent))) {
23 if ((item = qobject_cast<QQuickItem *>(object))) {
26 item->setPosition(rectangle.topLeft());
27 item->setHeight(rectangle.height());
28 } else {
29 qmlWarning(parent) << tr("%1 does not support loading non-visual cursor delegates.")
31 }
32 component->completeCreate();
33 if (parent->clip())
35 return item;
36 }
37 } else if (component->isLoading()) {
40 return item;
41 }
42 qmlWarning(parent, component->errors()) << tr("Could not load cursor delegate");
43 return item;
44}
45
46qreal QQuickTextUtil::alignedX(const qreal textWidth, const qreal itemWidth, int alignment)
47{
48 qreal x = 0;
49 switch (alignment) {
50 case Qt::AlignLeft:
52 break;
53 case Qt::AlignRight:
54 x = itemWidth - textWidth;
55 break;
57 x = (itemWidth - textWidth) / 2;
58 break;
59 }
60 return x;
61}
62
63qreal QQuickTextUtil::alignedY(const qreal textHeight, const qreal itemHeight, int alignment)
64{
65 qreal y = 0;
66 switch (alignment) {
67 case Qt::AlignTop:
68 break;
69 case Qt::AlignBottom:
70 y = itemHeight - textHeight;
71 break;
73 y = (itemHeight - textHeight) / 2;
74 break;
75 }
76 return y;
77}
78
80
81#include "moc_qquicktextutil_p.cpp"
void setParentItem(QGraphicsItem *parent)
Sets this item's parent item to newParent.
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
The QQmlComponent class encapsulates a QML component definition.
Status
\qmltype Component \instantiates QQmlComponent\inqmlmodule QtQml
The QQmlContext class defines a context within a QML engine.
Definition qqmlcontext.h:25
static QQuickItemPrivate * get(QQuickItem *item)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
static qreal alignedX(qreal textWidth, qreal itemWidth, int alignment)
static void createCursor(Private *d)
static qreal alignedY(qreal textHeight, qreal itemHeight, int alignment)
\inmodule QtCore\reentrant
Definition qrect.h:484
constexpr qreal height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:732
constexpr QPointF topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:511
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:6018
void statusChanged(QQmlComponent::Status status)
[1]
Definition qlogging.cpp:11
uint alignment
Combined button and popup list for selecting options.
@ AlignRight
Definition qnamespace.h:146
@ AlignJustify
Definition qnamespace.h:149
@ AlignBottom
Definition qnamespace.h:154
@ AlignVCenter
Definition qnamespace.h:155
@ AlignTop
Definition qnamespace.h:153
@ AlignHCenter
Definition qnamespace.h:148
@ AlignLeft
Definition qnamespace.h:144
@ UniqueConnection
#define SLOT(a)
Definition qobjectdefs.h:52
#define SIGNAL(a)
Definition qobjectdefs.h:53
GLint GLint GLint GLint GLint x
[0]
GLint y
static qreal component(const QPointF &point, unsigned int i)
QQmlContext * qmlContext(const QObject *obj)
Definition qqml.cpp:75
void QQml_setParent_noEvent(QObject *object, QObject *parent)
Makes the object a child of parent.
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
#define tr(X)
double qreal
Definition qtypes.h:187
const char className[16]
[1]
Definition qwizard.cpp:100
QGraphicsItem * item