Focus the newly dropped dock widget

When we drag a dock widget into a another widget, we should focus it

Fixes issue #77
This commit is contained in:
Sergio Martins
2020-09-26 17:44:30 +01:00
parent e33151d482
commit c210a523e3
4 changed files with 33 additions and 4 deletions

View File

@@ -225,6 +225,9 @@ bool DropArea::drop(FloatingWindow *droppedWindow, QPoint globalPos)
}
bool result = true;
const bool needToFocusNewlyDroppedWidgets = Config::self().flags() & Config::Flag_TitleBarIsFocusable;
const DockWidgetBase::List droppedDockWidgets = needToFocusNewlyDroppedWidgets ? droppedWindow->multiSplitter()->dockWidgets()
: DockWidgetBase::List(); // just so save some memory allocations for the case where this variable isn't used
auto droploc = m_dropIndicatorOverlay->currentDropLocation();
switch (droploc) {
@@ -253,9 +256,23 @@ bool DropArea::drop(FloatingWindow *droppedWindow, QPoint globalPos)
break;
}
if (result)
if (result) {
// Window receiving the drop gets raised:
raiseAndActivate();
if (needToFocusNewlyDroppedWidgets) {
// Let's also focus the newly dropped dock widget
if (droppedDockWidgets.size() > 0) {
// If more than 1 was dropped, we only focus the first one
Frame *frame = droppedDockWidgets.first()->frame();
frame->FocusScope::focus(Qt::MouseFocusReason);
} else {
// Doesn't happen.
qWarning() << Q_FUNC_INFO << "Nothing was dropped?";
}
}
}
return result;
}