7#include <QtQml/qqmlinfo.h>
8#include <QtQml/qqmlcomponent.h>
10#include <private/qqmlglobal_p.h>
11#include <private/qquickitem_p.h>
15QQuickItem *QQuickTextUtil::createCursor(
16 QQmlComponent *component, QQuickItem *parent,
const QRectF &rectangle,
const char *className)
18 QQuickItem *item =
nullptr;
19 if (component->isReady()) {
20 QQmlContext *creationContext = component->creationContext();
22 if (QObject *object = component->beginCreate(creationContext
24 : qmlContext(parent))) {
25 if ((item = qobject_cast<QQuickItem *>(object))) {
26 QQml_setParent_noEvent(item, parent);
27 item->setParentItem(parent);
28 item->setPosition(rectangle.topLeft());
29 item->setHeight(rectangle.height());
31 qmlWarning(parent) << tr(
"%1 does not support loading non-visual cursor delegates.")
32 .arg(QString::fromUtf8(className));
34 component->completeCreate();
36 QQuickItemPrivate::get(parent)->dirty(QQuickItemPrivate::Size);
39 }
else if (component->isLoading()) {
40 QObject::connect(component, SIGNAL(statusChanged(QQmlComponent::Status)),
41 parent, SLOT(createCursor()), Qt::UniqueConnection);
44 qmlWarning(parent, component->errors()) << tr(
"Could not load cursor delegate");
48qreal QQuickTextUtil::alignedX(
const qreal textWidth,
const qreal itemWidth,
int alignment)
53 case Qt::AlignJustify:
56 x = itemWidth - textWidth;
58 case Qt::AlignHCenter:
59 x = (itemWidth - textWidth) / 2;
65qreal QQuickTextUtil::alignedY(
const qreal textHeight,
const qreal itemHeight,
int alignment)
72 y = itemHeight - textHeight;
74 case Qt::AlignVCenter:
75 y = (itemHeight - textHeight) / 2;
83#include "moc_qquicktextutil_p.cpp"