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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -288,6 +288,16 @@ Layouting::Item *MultiSplitter::itemForFrame(const Frame *frame) const
|
||||
return m_rootItem->itemForWidget(frame);
|
||||
}
|
||||
|
||||
DockWidgetBase::List MultiSplitter::dockWidgets() const
|
||||
{
|
||||
DockWidgetBase::List dockWidgets;
|
||||
const Frame::List frames = this->frames();
|
||||
for (Frame *frame : frames)
|
||||
dockWidgets << frame->dockWidgets();
|
||||
|
||||
return dockWidgets;
|
||||
}
|
||||
|
||||
Frame::List MultiSplitter::framesFrom(QWidgetOrQuick *frameOrMultiSplitter) const
|
||||
{
|
||||
if (auto frame = qobject_cast<Frame*>(frameOrMultiSplitter))
|
||||
|
||||
@@ -188,10 +188,13 @@ public:
|
||||
Layouting::Item *itemForFrame(const Frame *frame) const;
|
||||
|
||||
/**
|
||||
* @brief Returns a list of Frame objects contained in this layout
|
||||
* @brief Returns this list of Frame objects contained in this layout
|
||||
*/
|
||||
QList<Frame*> frames() const;
|
||||
|
||||
/// @brief Returns the list of dock widgets contained in this layout
|
||||
QVector<DockWidgetBase*> dockWidgets() const;
|
||||
|
||||
/// @brief restores the dockwidget @p dw to its previous position
|
||||
void restorePlaceholder(DockWidgetBase *dw, Layouting::Item *, int tabIndex);
|
||||
|
||||
|
||||
@@ -6105,9 +6105,8 @@ void TestDocks::tst_dockWidgetGetsFocusWhenDocked()
|
||||
/// We dropped into floating window 1, it should still be active
|
||||
QVERIFY(fw1->isActiveWindow());
|
||||
|
||||
QEXPECT_FAIL("", "To be fixed", Continue);
|
||||
// DockWidget 2 was dropped, it should now be focused
|
||||
QVERIFY(!dw1->isFocused());
|
||||
QEXPECT_FAIL("", "To be fixed", Continue);
|
||||
QVERIFY(dw2->isFocused());
|
||||
|
||||
delete fw1;
|
||||
|
||||
Reference in New Issue
Block a user