blob: 4a1fb0db00e29861d25d08e3a71f01ee079d1115 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
// Copyright (C) 2017 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
#include "qquickplaceholdertext_p.h"
#include <QtQuick/private/qquicktext_p_p.h>
#include <QtQuick/private/qquicktextinput_p_p.h>
#include <QtQuick/private/qquicktextedit_p_p.h>
QT_BEGIN_NAMESPACE
QQuickPlaceholderText::QQuickPlaceholderText(QQuickItem *parent) : QQuickText(parent)
{
}
void QQuickPlaceholderText::componentComplete()
{
QQuickText::componentComplete();
auto control = textControl();
if (control)
connect(control, SIGNAL(effectiveHorizontalAlignmentChanged()), this, SLOT(updateAlignment()));
updateAlignment();
}
/*!
\internal
The control that we're representing. This exists because
parentItem() is not always the control - it may be a Flickable
in the case of TextArea.
*/
QQuickItem *QQuickPlaceholderText::textControl() const
{
return qobject_cast<QQuickItem *>(parent());
}
void QQuickPlaceholderText::updateAlignment()
{
if (QQuickTextInput *input = qobject_cast<QQuickTextInput *>(parentItem())) {
if (QQuickTextInputPrivate::get(input)->hAlignImplicit)
resetHAlign();
else
setHAlign(static_cast<HAlignment>(input->hAlign()));
} else if (QQuickTextEdit *edit = qobject_cast<QQuickTextEdit *>(parentItem())) {
if (QQuickTextEditPrivate::get(edit)->hAlignImplicit)
resetHAlign();
else
setHAlign(static_cast<HAlignment>(edit->hAlign()));
} else {
resetHAlign();
}
}
QT_END_NAMESPACE
#include "moc_qquickplaceholdertext_p.cpp"
|