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