aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates/qquickpopupanchors.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quicktemplates/qquickpopupanchors.cpp')
-rw-r--r--src/quicktemplates/qquickpopupanchors.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/quicktemplates/qquickpopupanchors.cpp b/src/quicktemplates/qquickpopupanchors.cpp
new file mode 100644
index 0000000000..963dd21aa4
--- /dev/null
+++ b/src/quicktemplates/qquickpopupanchors.cpp
@@ -0,0 +1,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"