25#include "core/Platform_p.h"
26#include "core/Logging_p.h"
34class FocusScope::Private
39 , m_thisView(thisView)
42 m_connection =
plat->
d->focusedViewChanged.connect(&Private::onFocusedViewChanged,
this);
51 bool lastFocusedIsTabWidget()
const
53 return m_lastFocusedInScope && !m_lastFocusedInScope->isNull()
59 void setIsFocused(
bool);
60 void onFocusedViewChanged(std::shared_ptr<View> view);
61 bool isInFocusScope(std::shared_ptr<View> view)
const;
65 bool m_isFocused =
false;
67 std::shared_ptr<View> m_lastFocusedInScope;
71FocusScope::Private::~Private()
77 : d(new Private(this, thisView))
88 return d->m_isFocused;
95 if (d->m_lastFocusedInScope && !d->m_lastFocusedInScope->isNull() && d->m_lastFocusedInScope->isVisible()
96 && !d->lastFocusedIsTabWidget()) {
100 d->m_lastFocusedInScope->setFocus(reason);
102 if (
auto group = d->m_thisView->asGroupController()) {
103 if (
auto dw = group->currentDockWidget()) {
105 if (
auto candidate = dwView->focusCandidate()) {
107 KDDW_DEBUG(
"FocusScope::focus: Setting focus on candidate!");
108 candidate->setFocus(reason);
110 KDDW_DEBUG(
"FocusScope::focus: Candidate has no focus policy");
113 KDDW_DEBUG(
"FocusScope::focus: Candidate not found");
116 KDDW_DEBUG(
"FocusScope::focus: Dw doesn't have view");
119 KDDW_DEBUG(
"FocusScope::focus: Group doesn't have current DW");
123 KDDW_DEBUG(
"FocusScope::focus: No group found");
124 d->m_thisView->setFocus(reason);
129void FocusScope::Private::setIsFocused(
bool is)
131 if (is != m_isFocused) {
135 q->isFocusedChangedCallback();
139void FocusScope::Private::onFocusedViewChanged(std::shared_ptr<View> view)
141 if (!view || view->isNull()) {
146 const bool is = isInFocusScope(view);
147 const bool focusViewChanged = !m_lastFocusedInScope || m_lastFocusedInScope->isNull()
148 || !m_lastFocusedInScope->equals(view);
150 m_lastFocusedInScope = view;
152 q->focusedWidgetChangedCallback();
158bool FocusScope::Private::isInFocusScope(std::shared_ptr<View> view)
const
160 if (m_thisView.isNull())
163 auto p = (view && !view->isNull()) ? view :
std::shared_ptr<
View>();
165 if (p->handle() == m_thisView->handle())
A ConnectionHandle represents the connection of a Signal to a slot (i.e. a function that is called wh...