core/window: add QsWindow attached object to contained Items

This commit is contained in:
outfoxxed 2024-07-17 20:54:29 -07:00
parent d1c33d48cd
commit e48af44607
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
4 changed files with 75 additions and 1 deletions

View file

@ -1 +1,29 @@
#include "windowinterface.hpp" // NOLINT
#include "windowinterface.hpp"
#include <qobject.h>
#include <qquickitem.h>
#include <qvariant.h>
#include "proxywindow.hpp"
QsWindowAttached* WindowInterface::qmlAttachedProperties(QObject* object) {
auto* item = qobject_cast<QQuickItem*>(object);
if (!item) return nullptr;
auto* window = item->window();
if (!window) return nullptr;
auto* proxy = window->property("__qs_proxywindow").value<ProxyWindowBase*>();
if (!proxy) return nullptr;
auto v = proxy->property("__qs_window_attached");
if (auto* attached = v.value<QsWindowAttached*>()) {
return attached;
}
auto* attached = new ProxyWindowAttached(proxy);
if (attached) {
proxy->setProperty("__qs_window_attached", QVariant::fromValue(attached));
}
return attached;
}