1 | // Copyright (C) 2018 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 "qquickpopupanchors_p.h" |
5 | #include "qquickpopupanchors_p_p.h" |
6 | #include "qquickpopup_p_p.h" |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | QQuickPopupAnchors::QQuickPopupAnchors(QQuickPopup *popup) |
11 | : QObject(*(new QQuickPopupAnchorsPrivate), popup) |
12 | { |
13 | Q_D(QQuickPopupAnchors); |
14 | d->popup = popup; |
15 | } |
16 | |
17 | QQuickPopupAnchors::~QQuickPopupAnchors() |
18 | { |
19 | Q_D(const QQuickPopupAnchors); |
20 | if (d->centerIn) { |
21 | auto centerInPrivate = QQuickItemPrivate::get(item: d->centerIn); |
22 | centerInPrivate->removeItemChangeListener(this, types: QQuickItemPrivate::Destroyed); |
23 | } |
24 | } |
25 | |
26 | QQuickItem *QQuickPopupAnchors::centerIn() const |
27 | { |
28 | Q_D(const QQuickPopupAnchors); |
29 | return d->centerIn; |
30 | } |
31 | |
32 | void QQuickPopupAnchors::setCenterIn(QQuickItem *item) |
33 | { |
34 | Q_D(QQuickPopupAnchors); |
35 | if (item == d->centerIn) |
36 | return; |
37 | |
38 | if (d->centerIn) { |
39 | auto centerInPrivate = QQuickItemPrivate::get(item: d->centerIn); |
40 | centerInPrivate->removeItemChangeListener(this, types: QQuickItemPrivate::Destroyed); |
41 | } |
42 | |
43 | d->centerIn = item; |
44 | |
45 | if (d->centerIn) { |
46 | auto centerInPrivate = QQuickItemPrivate::get(item: d->centerIn); |
47 | centerInPrivate->addItemChangeListener(listener: this, types: QQuickItemPrivate::Destroyed); |
48 | } |
49 | |
50 | QQuickPopupPrivate::get(popup: d->popup)->reposition(); |
51 | |
52 | emit centerInChanged(); |
53 | } |
54 | |
55 | void QQuickPopupAnchors::resetCenterIn() |
56 | { |
57 | setCenterIn(nullptr); |
58 | } |
59 | |
60 | void QQuickPopupAnchors::itemDestroyed(QQuickItem *) |
61 | { |
62 | resetCenterIn(); |
63 | } |
64 | |
65 | QT_END_NAMESPACE |
66 | |
67 | #include "moc_qquickpopupanchors_p.cpp" |
68 |