Make MultiSplitter::rectForDrop() receive WindowBeingDragged

Instead of FloatingWindow, which won't exist on wayland while a
drag is in progress.
This commit is contained in:
Sergio Martins
2020-10-14 19:52:41 +01:00
parent 4eb5a0940e
commit 93b25b6a31
7 changed files with 41 additions and 10 deletions

View File

@@ -31,6 +31,7 @@
#include "FrameworkWidgetFactory.h"
#include "multisplitter/Widget_qwidget.h"
#include "DropArea_p.h"
#include "WindowBeingDragged_p.h"
#include <QScopedValueRollback>
@@ -436,10 +437,11 @@ Layouting::ItemContainer *MultiSplitter::rootItem() const
return m_rootItem;
}
QRect MultiSplitter::rectForDrop(const FloatingWindow *fw, Location location,
QRect MultiSplitter::rectForDrop(const WindowBeingDragged *wbd, Location location,
const Layouting::Item *relativeTo) const
{
Layouting::Item item(nullptr);
FloatingWindow *fw = wbd ? wbd->floatingWindow() : nullptr;
if (!fw)
return {};

View File

@@ -40,7 +40,7 @@ namespace KDDockWidgets {
class MainWindowBase;
class FloatingWindow;
class Frame;
class WindowBeingDragged;
/**
* MultiSplitter is simply a wrapper around Layouting::Item in which the hosted widgets are
@@ -131,7 +131,7 @@ public:
* Excludes the Separator thickness, result is actually smaller than what needed. In other words,
* the result will be exactly the same as the geometry the widget will get.
*/
QRect rectForDrop(const FloatingWindow *, KDDockWidgets::Location location,
QRect rectForDrop(const WindowBeingDragged *wbd, KDDockWidgets::Location location,
const Layouting::Item *relativeTo) const;
bool deserialize(const LayoutSaver::MultiSplitter &);

View File

@@ -18,6 +18,9 @@ using namespace KDDockWidgets;
static Draggable* bestDraggable(Draggable *draggable)
{
if (!draggable)
return nullptr;
// When de detach a title bar it will get hidden and we only the title bar of the FloatingWindow is visible
/// Apparently that causes problems with grabbing the mouse, so instead use a visible draggable.
// grabbing mouse on an hidden window works usually, it's some edge case on Windows with MFC.
@@ -54,6 +57,17 @@ WindowBeingDragged::WindowBeingDragged(FloatingWindow *fw, Draggable *draggable)
if (!qIsNaN(opacity) && !qFuzzyCompare(1.0, opacity))
fw->setWindowOpacity(opacity);
}
#if DOCKS_DEVELOPER_MODE
// Just used by tests
WindowBeingDragged::WindowBeingDragged(FloatingWindow *fw)
: m_floatingWindow(fw)
, m_draggable(nullptr)
, m_affinities(fw->affinities())
{
}
#endif
WindowBeingDragged::~WindowBeingDragged()
{

View File

@@ -26,6 +26,11 @@ struct DOCKS_EXPORT_FOR_UNIT_TESTS WindowBeingDragged
{
public:
explicit WindowBeingDragged(FloatingWindow *fw, Draggable *draggable);
#if DOCKS_DEVELOPER_MODE
// For tests.
explicit WindowBeingDragged(FloatingWindow *fw);
#endif
~WindowBeingDragged();
void init();

View File

@@ -181,7 +181,7 @@ void ClassicIndicators::setDropLocation(ClassicIndicators::DropLocation location
auto windowBeingDragged = DragController::instance()->windowBeingDragged();
QRect rect = m_dropArea->rectForDrop(windowBeingDragged->floatingWindow(), multisplitterLocation,
QRect rect = m_dropArea->rectForDrop(windowBeingDragged, multisplitterLocation,
m_dropArea->itemForFrame(relativeToFrame));
m_rubberBand->setGeometry(rect);

View File

@@ -20,6 +20,7 @@
#include "TitleBar_p.h"
#include "Position_p.h"
#include "DropAreaWithCentralFrame_p.h"
#include "WindowBeingDragged_p.h"
#include <QtTest/QtTest>
#include <QObject>
@@ -352,8 +353,11 @@ void TestCommon::tst_sizeAfterRedock()
DropArea *dropArea = fw1->dropArea();
MultiSplitter *ms1 = fw1->multiSplitter();
const QRect suggestedDropRect = ms1->rectForDrop(oldFw2, Location_OnBottom, nullptr);
QCOMPARE(suggestedDropRect.height(), height2);
{
WindowBeingDragged wbd2(oldFw2);
const QRect suggestedDropRect = ms1->rectForDrop(&wbd2, Location_OnBottom, nullptr);
QCOMPARE(suggestedDropRect.height(), height2);
}
dropArea->drop(dw2->floatingWindow(), Location_OnBottom, nullptr);

View File

@@ -2930,7 +2930,7 @@ void TestDocks::tst_negativeAnchorPosition6()
layout->checkSanity();
Item *centralItem = m->dropArea()->centralFrame();
layout->rectForDrop(d2->floatingWindow(), Location_OnTop, centralItem);
layout->rectForDrop(nullptr, Location_OnTop, centralItem);
layout->checkSanity();
delete m->window();
@@ -3443,7 +3443,10 @@ void TestDocks::tst_rectForDropCrash()
m->addDockWidget(d1, Location_OnTop);
Item *centralItem = m->dropArea()->centralFrame();
layout->rectForDrop(d2->floatingWindow(), Location_OnTop, centralItem);
{
WindowBeingDragged wbd2(d2->floatingWindow());
layout->rectForDrop(&wbd2, Location_OnTop, centralItem);
}
layout->checkSanity();
delete m->window();
@@ -5095,8 +5098,11 @@ void TestDocks::tst_maximumSizePolicy()
// Make the floating window big, and see if the suggested highlight is still small
dock1->window()->resize(QSize(dock1->width(), 800));
const QRect highlightRect = m1->multiSplitter()->rectForDrop(dock1->floatingWindow(), Location_OnBottom, nullptr);
QVERIFY(highlightRect.height() <= maxHeight + tollerance);
{
WindowBeingDragged wbd1(dock1->floatingWindow());
const QRect highlightRect = m1->multiSplitter()->rectForDrop(&wbd1, Location_OnBottom, nullptr);
QVERIFY(highlightRect.height() <= maxHeight + tollerance);
}
// Now drop it, and check too
m1->addDockWidget(dock1, Location_OnBottom);