Add Platform::focusedView() and respective signal

Implemented as QGuiApplication::focusObjectChanged() for Qt,
other frontends will have their own impl.
This commit is contained in:
Sergio Martins
2022-04-05 21:53:52 +01:00
parent 43faf85eb4
commit 3ba4bc2d08
5 changed files with 49 additions and 0 deletions

View File

@@ -13,7 +13,9 @@
#include "KDDockWidgets.h"
// #include "QmlTypes.h" // TODOv2
#include "views/View_qtquick.h"
#include <QQuickWindow>
#include <QGuiApplication>
static KDDockWidgets::Platform_qtquick s_platformQtQuick;
@@ -25,6 +27,11 @@ Platform_qtquick::Platform_qtquick()
{
// KDDockWidgets::registerQmlTypes(); // TODOv2
QQuickWindow::setDefaultAlphaBuffer(true);
qApp->connect(qApp, &QGuiApplication::focusObjectChanged, qApp, [this](QObject *obj) {
ViewWrapper *wrapper = new Views::ViewWrapper_qtquick(obj);
focusedViewChanged.emit(std::shared_ptr<ViewWrapper>(wrapper));
});
}
Platform_qtquick::~Platform_qtquick()
@@ -35,3 +42,13 @@ const char *Platform_qtquick::name() const
{
return "qtquick";
}
std::shared_ptr<ViewWrapper> Platform_qtquick::focusedView() const
{
if (auto item = qobject_cast<QQuickItem *>(qApp->focusObject())) {
ViewWrapper *wrapper = new Views::ViewWrapper_qtquick(item);
return std::shared_ptr<ViewWrapper>(wrapper);
}
return {};
}