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

@@ -11,10 +11,14 @@
#include "Platform_qtwidgets.h"
#include "KDDockWidgets.h"
#include "qtwidgets/DebugWindow_p.h"
#include "qtwidgets/views/ViewWrapper_qtwidgets.h"
#include <QApplication>
#include <memory.h>
static KDDockWidgets::Platform_qtwidgets s_platformQtWidgets;
using namespace KDDockWidgets;
@@ -27,6 +31,11 @@ Platform_qtwidgets::Platform_qtwidgets()
dv->show();
}
#endif
qApp->connect(qApp, &QGuiApplication::focusObjectChanged, qApp, [this](QObject *obj) {
ViewWrapper *wrapper = new Views::ViewWrapper_qtwidgets(obj);
focusedViewChanged.emit(std::shared_ptr<ViewWrapper>(wrapper));
});
}
Platform_qtwidgets::~Platform_qtwidgets()
@@ -42,3 +51,13 @@ bool Platform_qtwidgets::hasActivePopup() const
{
return qApp->activePopupWidget() != nullptr;
}
std::shared_ptr<ViewWrapper> Platform_qtwidgets::focusedView() const
{
if (auto w = qobject_cast<QWidget *>(qApp->focusObject())) {
ViewWrapper *wrapper = new Views::ViewWrapper_qtwidgets(w);
return std::shared_ptr<ViewWrapper>(wrapper);
}
return {};
}