22 #include "private/TitleBar_p.h"
23 #include "private/Frame_p.h"
24 #include "private/DockRegistry_p.h"
27 #include <QGuiApplication>
33 class FocusScope::Private :
public QObject
36 Private(
FocusScope *qq, QWidgetAdapter *thisWidget)
38 , m_thisWidget(thisWidget)
41 this, &Private::onFocusObjectChanged);
43 onFocusObjectChanged(qApp->focusObject());
48 bool lastFocusedIsTabWidget()
const
50 if (!m_lastFocusedInScope)
53 if (
auto metaObj = m_lastFocusedInScope->metaObject()) {
56 return className ==
QLatin1String(
"KDDockWidgets::TabBarWidget")
65 void setIsFocused(
bool);
66 void onFocusObjectChanged(
QObject *);
70 QWidgetAdapter *
const m_thisWidget;
71 bool m_isFocused =
false;
76 FocusScope::Private::~Private()
81 : d(new Private(this, thisWidget))
92 return d->m_isFocused;
97 return d->m_lastFocusedInScope;
102 if (d->m_lastFocusedInScope && !d->lastFocusedIsTabWidget()) {
106 d->m_lastFocusedInScope->setFocus(reason);
108 if (
auto frame = qobject_cast<Frame *>(d->m_thisWidget)) {
110 if (
auto guest = dw->widget()) {
112 guest->setFocus(reason);
117 d->m_thisWidget->setFocus(reason);
122 void FocusScope::Private::setIsFocused(
bool is)
124 if (is != m_isFocused) {
128 q->isFocusedChangedCallback();
132 void FocusScope::Private::onFocusObjectChanged(
QObject *obj)
134 auto widget = qobject_cast<WidgetType *>(obj);
140 const bool is = isInFocusScope(widget);
141 if (is && m_lastFocusedInScope != widget && !qobject_cast<TitleBar *>(obj)) {
142 m_lastFocusedInScope = widget;
144 q->focusedWidgetChangedCallback();
150 bool FocusScope::Private::isInFocusScope(
WidgetType *widget)
const
154 if (p == m_thisWidget)
157 p = KDDockWidgets::Private::parentWidget(p);