aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates/qquickpopupanchors.cpp
blob: 963dd21aa41ea163a9b7301f1bb300c8c10cf309 (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
58
59
60
61
62
63
64
65
66
67
// Copyright (C) 2018 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 "qquickpopupanchors_p.h"
#include "qquickpopupanchors_p_p.h"
#include "qquickpopup_p_p.h"

QT_BEGIN_NAMESPACE

QQuickPopupAnchors::QQuickPopupAnchors(QQuickPopup *popup)
    : QObject(*(new QQuickPopupAnchorsPrivate), popup)
{
    Q_D(QQuickPopupAnchors);
    d->popup = popup;
}

QQuickPopupAnchors::~QQuickPopupAnchors()
{
    Q_D(const QQuickPopupAnchors);
    if (d->centerIn) {
        auto centerInPrivate = QQuickItemPrivate::get(d->centerIn);
        centerInPrivate->removeItemChangeListener(this, QQuickItemPrivate::Destroyed);
    }
}

QQuickItem *QQuickPopupAnchors::centerIn() const
{
    Q_D(const QQuickPopupAnchors);
    return d->centerIn;
}

void QQuickPopupAnchors::setCenterIn(QQuickItem *item)
{
    Q_D(QQuickPopupAnchors);
    if (item == d->centerIn)
        return;

    if (d->centerIn) {
        auto centerInPrivate = QQuickItemPrivate::get(d->centerIn);
        centerInPrivate->removeItemChangeListener(this, QQuickItemPrivate::Destroyed);
    }

    d->centerIn = item;

    if (d->centerIn) {
        auto centerInPrivate = QQuickItemPrivate::get(d->centerIn);
        centerInPrivate->addItemChangeListener(this, QQuickItemPrivate::Destroyed);
    }

    QQuickPopupPrivate::get(d->popup)->reposition();

    emit centerInChanged();
}

void QQuickPopupAnchors::resetCenterIn()
{
    setCenterIn(nullptr);
}

void QQuickPopupAnchors::itemDestroyed(QQuickItem *)
{
    resetCenterIn();
}

QT_END_NAMESPACE

#include "moc_qquickpopupanchors_p.cpp"