7#include "overlayzstackingattached.h"
9#include "loggingcategory.h"
13OverlayZStackingAttached::OverlayZStackingAttached(
QObject *parent)
15 , m_layer(defaultLayerForPopupType(parent))
16 , m_parentPopup(nullptr)
20 if (!isPopup(parent)) {
21 qCWarning(KirigamiLog) <<
"OverlayZStacking must be attached to a Popup";
25 connect(parent, SIGNAL(parentChanged()),
this, SLOT(updateParentPopup()));
26 connect(parent, SIGNAL(closed()),
this, SLOT(dispatchPendingSignal()));
31OverlayZStackingAttached::~OverlayZStackingAttached()
38 const_cast<OverlayZStackingAttached *
>(
this)->updateParentPopupSilent();
41 qreal layerZ = defaultZForLayer(m_layer);
42 qreal parentZ = parentPopupZ() + 1;
44 return std::max(layerZ, parentZ);
52void OverlayZStackingAttached::setLayer(Layer layer)
54 if (m_layer ==
layer) {
65 return new OverlayZStackingAttached(
object);
68void OverlayZStackingAttached::enqueueSignal()
77void OverlayZStackingAttached::dispatchPendingSignal()
85void OverlayZStackingAttached::updateParentPopup()
87 const qreal oldZ = parentPopupZ();
89 updateParentPopupSilent();
91 if (oldZ != parentPopupZ()) {
96void OverlayZStackingAttached::updateParentPopupSilent()
98 auto popup = findParentPopup(
parent());
99 setParentPopup(popup);
102void OverlayZStackingAttached::setParentPopup(
QObject *parentPopup)
104 if (m_parentPopup == parentPopup) {
109 disconnect(m_parentPopup.data(), SIGNAL(zChanged()),
this, SLOT(enqueueSignal()));
113 m_parentPopup = parentPopup;
116 connect(m_parentPopup.data(), SIGNAL(zChanged()),
this, SLOT(enqueueSignal()));
120qreal OverlayZStackingAttached::parentPopupZ()
const
123 return m_parentPopup->property(
"z").toReal();
128bool OverlayZStackingAttached::isVisible(
const QObject *popup)
130 if (!isPopup(popup)) {
137bool OverlayZStackingAttached::isPopup(
const QObject *
object)
139 return object &&
object->inherits(
"QQuickPopup");
142QObject *OverlayZStackingAttached::findParentPopup(
const QObject *popup)
144 auto item = findParentPopupItem(popup);
148 auto parentPopup = item->
parent();
149 if (!isPopup(popup)) {
157 if (!isPopup(popup)) {
161 QQuickItem *parentItem = popup->
property(
"parent").
value<QQuickItem *>();
166 QQuickItem *item = parentItem;
168 if (item && item->
inherits(
"QQuickPopupItem")) {
177OverlayZStackingAttached::Layer OverlayZStackingAttached::defaultLayerForPopupType(
const QObject *popup)
180 if (popup->
inherits(
"QQuickDialog")) {
181 return Layer::Dialog;
182 }
else if (popup->
inherits(
"QQuickDrawer")) {
183 return Layer::Drawer;
184 }
else if (popup->
inherits(
"QQuickMenu")) {
186 }
else if (popup->
inherits(
"QQuickToolTip")) {
187 return Layer::ToolTip;
190 return DefaultLowest;
193qreal OverlayZStackingAttached::defaultZForLayer(Layer layer)
214#include "moc_overlayzstackingattached.cpp"
This attached property manages z-index for stacking overlays relative to each other.
QML_ELEMENTqreal z
An optimal z-index that attachee popup should bind to.
Layer layer
The logical stacking layer of attachee popup, akin to window manager's layers.
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
bool inherits(const char *className) const const
QObject * parent() const const
QVariant property(const char *name) const const
QQuickItem * parentItem() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
bool toBool() const const