Skip to content

Commit 1186d2b

Browse files
Fixed #509 - Implemented support for restoring maximized state of floating widgets on Windows
1 parent 44115d4 commit 1186d2b

File tree

4 files changed

+82
-25
lines changed

4 files changed

+82
-25
lines changed

src/DockManager.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include <QMenu>
4848
#include <QApplication>
4949
#include <QWindow>
50+
#include <QWindowStateChangeEvent>
5051

5152
#include "FloatingDockContainer.h"
5253
#include "DockOverlay.h"
@@ -116,6 +117,7 @@ struct DockManagerPrivate
116117
QVector<CFloatingDockContainer*> UninitializedFloatingWidgets;
117118
CDockFocusController* FocusController = nullptr;
118119
CDockWidget* CentralWidget = nullptr;
120+
bool IsLeavingMinimized = false;
119121

120122
/**
121123
* Private data constructor
@@ -510,9 +512,10 @@ CDockManager::CDockManager(QWidget *parent) :
510512
d->FocusController = new CDockFocusController(this);
511513
}
512514

513-
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
515+
514516
window()->installEventFilter(this);
515517

518+
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
516519
connect(qApp, &QApplication::focusWindowChanged, [](QWindow* focusWindow)
517520
{
518521
// bring modal dialogs to foreground to ensure that they are in front of any
@@ -629,8 +632,39 @@ bool CDockManager::eventFilter(QObject *obj, QEvent *e)
629632
}
630633
return Super::eventFilter(obj, e);
631634
}
635+
#else
636+
//============================================================================
637+
bool CDockManager::eventFilter(QObject *obj, QEvent *e)
638+
{
639+
if (e->type() == QEvent::WindowStateChange)
640+
{
641+
QWindowStateChangeEvent* ev = static_cast<QWindowStateChangeEvent*>(e);
642+
if (ev->oldState().testFlag(Qt::WindowMinimized))
643+
{
644+
d->IsLeavingMinimized = true;
645+
QMetaObject::invokeMethod(this, "endLeavingMinimizedState", Qt::QueuedConnection);
646+
}
647+
}
648+
return Super::eventFilter(obj, e);
649+
}
632650
#endif
633651

652+
653+
//============================================================================
654+
void CDockManager::endLeavingMinimizedState()
655+
{
656+
d->IsLeavingMinimized = false;
657+
this->activateWindow();
658+
}
659+
660+
661+
//============================================================================
662+
bool CDockManager::isLeavingMinimizedState() const
663+
{
664+
return d->IsLeavingMinimized;
665+
}
666+
667+
634668
//============================================================================
635669
void CDockManager::registerFloatingWidget(CFloatingDockContainer* FloatingWidget)
636670
{

src/DockManager.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ class ADS_EXPORT CDockManager : public CDockContainerWidget
8888
friend class CAutoHideDockContainer;
8989
friend CAutoHideSideBar;
9090

91+
public Q_SLOTS:
92+
/**
93+
* Ends the isRestoringFromMinimizedState
94+
*/
95+
void endLeavingMinimizedState();
96+
9197

9298
protected:
9399
/**
@@ -539,6 +545,15 @@ class ADS_EXPORT CDockManager : public CDockContainerWidget
539545
*/
540546
bool isRestoringState() const;
541547

548+
/**
549+
* This function returns true, if the DockManager window is restoring from
550+
* minimized state.
551+
* The DockManager is in this state starting from the QWindowStateChangeEvent
552+
* that signals the state change from minimized to normal until
553+
* endLeavingMinimizedState() function is called.
554+
*/
555+
bool isLeavingMinimizedState() const;
556+
542557
/**
543558
* The distance the user needs to move the mouse with the left button
544559
* hold down before a dock widget start floating
@@ -560,9 +575,7 @@ class ADS_EXPORT CDockManager : public CDockContainerWidget
560575
widget->setFocus(Qt::OtherFocusReason);
561576
}
562577

563-
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
564578
bool eventFilter(QObject *obj, QEvent *e) override;
565-
#endif
566579

567580
/**
568581
* Returns the dock widget that has focus style in the ui or a nullptr if

src/FloatingDockContainer.cpp

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -763,18 +763,43 @@ CDockContainerWidget* CFloatingDockContainer::dockContainer() const
763763
void CFloatingDockContainer::changeEvent(QEvent *event)
764764
{
765765
Super::changeEvent(event);
766-
if ((event->type() == QEvent::ActivationChange) && isActiveWindow())
766+
switch (event->type())
767767
{
768-
ADS_PRINT("FloatingWidget::changeEvent QEvent::ActivationChange ");
769-
d->zOrderIndex = ++zOrderCounter;
768+
case QEvent::ActivationChange:
769+
if (isActiveWindow())
770+
{
771+
ADS_PRINT("FloatingWidget::changeEvent QEvent::ActivationChange ");
772+
d->zOrderIndex = ++zOrderCounter;
770773

771774
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
772-
if (d->DraggingState == DraggingFloatingWidget)
775+
if (d->DraggingState == DraggingFloatingWidget)
776+
{
777+
d->titleMouseReleaseEvent();
778+
d->DraggingState = DraggingInactive;
779+
}
780+
#endif
781+
}
782+
break;
783+
784+
case QEvent::WindowStateChange:
785+
// If the DockManager window is restored from minimized on Windows
786+
// then the FloatingWidgets are not properly restored to maximized but
787+
// to normal state.
788+
// We simply check here, if the FloatingWidget was maximized before
789+
// and if the DockManager is just leaving the minimized state. In this
790+
// case, we restore the maximized state of this floating widget
791+
if (d->DockManager->isLeavingMinimizedState())
773792
{
774-
d->titleMouseReleaseEvent();
775-
d->DraggingState = DraggingInactive;
793+
QWindowStateChangeEvent* ev = static_cast<QWindowStateChangeEvent*>(event);
794+
if (ev->oldState().testFlag(Qt::WindowMaximized))
795+
{
796+
this->showMaximized();
797+
}
776798
}
777-
#endif
799+
break;
800+
801+
default:
802+
break; // do nothing
778803
}
779804
}
780805

@@ -1337,19 +1362,6 @@ bool CFloatingDockContainer::hasNativeTitleBar()
13371362
}
13381363
#endif
13391364

1340-
1341-
//============================================================================
1342-
bool CFloatingDockContainer::event(QEvent *e)
1343-
{
1344-
qDebug() << "CFloatingDockContainer::event: " << e;
1345-
if (e->type() == QEvent::WindowStateChange)
1346-
{
1347-
QWindowStateChangeEvent* ev = static_cast<QWindowStateChangeEvent*>(e);
1348-
qDebug() << "WindowStateChange " << ev->oldState() << " -> " << windowState();
1349-
qDebug() << "isActiveWindow " << isActiveWindow();
1350-
}
1351-
return Super::event(e);
1352-
}
13531365
} // namespace ads
13541366

13551367
//---------------------------------------------------------------------------

src/FloatingDockContainer.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,6 @@ private Q_SLOTS:
298298
*/
299299
bool hasNativeTitleBar();
300300
#endif
301-
302-
virtual bool event(QEvent *e) override;
303301
}; // class FloatingDockContainer
304302
}
305303
// namespace ads

0 commit comments

Comments
 (0)