Add Platform::focusedView() and respective signal
Implemented as QGuiApplication::focusObjectChanged() for Qt, other frontends will have their own impl.
This commit is contained in:
@@ -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 {};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user