Skip to content

Commit 1d90e8e

Browse files
Merge branch 'fix_issue_380' of https://github.com/jporcher/Qt-Advanced-Docking-System into jporcher-fix_issue_380
2 parents e35bd65 + 6b30274 commit 1d90e8e

File tree

10 files changed

+313
-0
lines changed

10 files changed

+313
-0
lines changed

examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
cmake_minimum_required(VERSION 3.5)
22
project(QtADSExamples LANGUAGES CXX VERSION ${VERSION_SHORT})
33
add_subdirectory(simple)
4+
add_subdirectory(hideshow)
45
add_subdirectory(sidebar)
56
add_subdirectory(deleteonclose)
67
add_subdirectory(centralwidget)

examples/examples.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ TEMPLATE = subdirs
33
SUBDIRS = \
44
centralwidget \
55
simple \
6+
hideshow \
67
sidebar \
78
deleteonclose \
89
emptydockarea \

examples/hideshow/CMakeLists.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
project(ads_example_hideshow VERSION ${VERSION_SHORT})
3+
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
4+
find_package(Qt${QT_VERSION_MAJOR} 5.5 COMPONENTS Core Gui Widgets REQUIRED)
5+
set(CMAKE_INCLUDE_CURRENT_DIR ON)
6+
add_executable(HideShowExample WIN32
7+
main.cpp
8+
MainWindow.cpp
9+
MainWindow.ui
10+
)
11+
target_include_directories(HideShowExample PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../../src")
12+
target_link_libraries(HideShowExample PRIVATE qtadvanceddocking)
13+
target_link_libraries(HideShowExample PUBLIC Qt${QT_VERSION_MAJOR}::Core
14+
Qt${QT_VERSION_MAJOR}::Gui
15+
Qt${QT_VERSION_MAJOR}::Widgets)
16+
set_target_properties(HideShowExample PROPERTIES
17+
AUTOMOC ON
18+
AUTORCC ON
19+
AUTOUIC ON
20+
CXX_STANDARD 14
21+
CXX_STANDARD_REQUIRED ON
22+
CXX_EXTENSIONS OFF
23+
VERSION ${VERSION_SHORT}
24+
EXPORT_NAME "Qt Advanced Docking System Hide,Show Example"
25+
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${ads_PlatformDir}/lib"
26+
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${ads_PlatformDir}/lib"
27+
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${ads_PlatformDir}/bin"
28+
)

examples/hideshow/MainWindow.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include "../../examples/hideshow/MainWindow.h"
2+
3+
#include "ui_MainWindow.h"
4+
5+
#include <QLabel>
6+
#include <QPushButton>
7+
8+
MainWindow::MainWindow(QWidget *parent) :
9+
QMainWindow(parent),
10+
ui(new Ui::MainWindow)
11+
{
12+
ui->setupUi(this);
13+
14+
ui->centralWidget->setLayout( m_layout = new QStackedLayout() );
15+
16+
m_welcomeWidget = new QWidget(this);
17+
auto welcomeLayout = new QVBoxLayout(m_welcomeWidget);
18+
welcomeLayout->addStretch();
19+
QPushButton* openButton = new QPushButton("Open project");
20+
welcomeLayout->addWidget( openButton );
21+
welcomeLayout->addStretch();
22+
23+
connect( openButton, SIGNAL(clicked()), this, SLOT(openProject()) );
24+
25+
m_DockManager = new ads::CDockManager(ui->centralWidget);
26+
27+
// Create example content label - this can be any application specific
28+
// widget
29+
QLabel* l = new QLabel();
30+
l->setWordWrap(true);
31+
l->setAlignment(Qt::AlignTop | Qt::AlignLeft);
32+
l->setText("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. ");
33+
34+
// Create a dock widget with the title Label 1 and set the created label
35+
// as the dock widget content
36+
ads::CDockWidget* DockWidget = new ads::CDockWidget("Label 1");
37+
DockWidget->setWidget(l);
38+
39+
// Add the toggleViewAction of the dock widget to the menu to give
40+
// the user the possibility to show the dock widget if it has been closed
41+
ui->menuView->addAction(DockWidget->toggleViewAction());
42+
43+
connect( ui->actionOpen, SIGNAL(triggered()), this, SLOT(openProject()) );
44+
connect( ui->actionClose, SIGNAL(triggered()), this, SLOT(closeProject()) );
45+
46+
// Add the dock widget to the top dock widget area
47+
m_DockManager->addDockWidget(ads::TopDockWidgetArea, DockWidget);
48+
49+
ui->centralWidget->layout()->addWidget( m_welcomeWidget );
50+
ui->centralWidget->layout()->addWidget( m_DockManager );
51+
52+
closeProject();
53+
}
54+
55+
MainWindow::~MainWindow()
56+
{
57+
delete ui;
58+
}
59+
60+
void MainWindow::openProject()
61+
{
62+
ui->actionOpen->setEnabled(false);
63+
ui->actionClose->setEnabled(true);
64+
ui->menuView->setEnabled(true);
65+
66+
m_layout->setCurrentWidget( m_DockManager );
67+
}
68+
69+
void MainWindow::closeProject()
70+
{
71+
ui->actionOpen->setEnabled(true);
72+
ui->actionClose->setEnabled(false);
73+
ui->menuView->setEnabled(false);
74+
75+
m_DockManager->hideManagerAndFloatingWidgets();
76+
m_layout->setCurrentWidget( m_welcomeWidget );
77+
}
78+

examples/hideshow/MainWindow.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef MAINWINDOW_H
2+
#define MAINWINDOW_H
3+
4+
#include <QMainWindow>
5+
#include <QStackedLayout>
6+
#include "DockManager.h"
7+
8+
QT_BEGIN_NAMESPACE
9+
namespace Ui {
10+
class MainWindow;
11+
}
12+
QT_END_NAMESPACE
13+
14+
class MainWindow : public QMainWindow
15+
{
16+
Q_OBJECT
17+
18+
public:
19+
explicit MainWindow(QWidget *parent = 0);
20+
~MainWindow();
21+
22+
private slots:
23+
void openProject();
24+
void closeProject();
25+
26+
private:
27+
Ui::MainWindow *ui;
28+
QWidget* m_welcomeWidget;
29+
ads::CDockManager* m_DockManager;
30+
QStackedLayout* m_layout;
31+
};
32+
33+
#endif // MAINWINDOW_H

examples/hideshow/MainWindow.ui

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>MainWindow</class>
4+
<widget class="QMainWindow" name="MainWindow">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>400</width>
10+
<height>300</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>MainWindow</string>
15+
</property>
16+
<widget class="QWidget" name="centralWidget"/>
17+
<widget class="QMenuBar" name="menuBar">
18+
<property name="geometry">
19+
<rect>
20+
<x>0</x>
21+
<y>0</y>
22+
<width>400</width>
23+
<height>26</height>
24+
</rect>
25+
</property>
26+
<widget class="QMenu" name="menuView">
27+
<property name="title">
28+
<string>View</string>
29+
</property>
30+
</widget>
31+
<widget class="QMenu" name="menuFile">
32+
<property name="title">
33+
<string>File</string>
34+
</property>
35+
<addaction name="actionOpen"/>
36+
<addaction name="actionClose"/>
37+
</widget>
38+
<addaction name="menuFile"/>
39+
<addaction name="menuView"/>
40+
</widget>
41+
<widget class="QStatusBar" name="statusBar"/>
42+
<action name="actionOpen">
43+
<property name="text">
44+
<string>Open project</string>
45+
</property>
46+
</action>
47+
<action name="actionClose">
48+
<property name="text">
49+
<string>Close project</string>
50+
</property>
51+
</action>
52+
</widget>
53+
<layoutdefault spacing="6" margin="11"/>
54+
<resources/>
55+
<connections/>
56+
</ui>

examples/hideshow/hideshow.pro

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
ADS_OUT_ROOT = $${OUT_PWD}/../..
2+
3+
QT += core gui widgets
4+
5+
TARGET = HideShowExample
6+
DESTDIR = $${ADS_OUT_ROOT}/lib
7+
TEMPLATE = app
8+
CONFIG += c++14
9+
CONFIG += debug_and_release
10+
adsBuildStatic {
11+
DEFINES += ADS_STATIC
12+
}
13+
14+
DEFINES += QT_DEPRECATED_WARNINGS
15+
16+
SOURCES += \
17+
main.cpp \
18+
MainWindow.cpp
19+
20+
HEADERS += \
21+
MainWindow.h
22+
23+
FORMS += \
24+
MainWindow.ui
25+
26+
27+
LIBS += -L$${ADS_OUT_ROOT}/lib
28+
include(../../ads.pri)
29+
INCLUDEPATH += ../../src
30+
DEPENDPATH += ../../src
31+

examples/hideshow/main.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <QApplication>
2+
#include "../../examples/hideshow/MainWindow.h"
3+
4+
int main(int argc, char *argv[])
5+
{
6+
QApplication a(argc, argv);
7+
MainWindow w;
8+
w.show();
9+
10+
return a.exec();
11+
}

src/DockManager.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ struct DockManagerPrivate
9898
{
9999
CDockManager* _this;
100100
QList<CFloatingDockContainer*> FloatingWidgets;
101+
QList<CFloatingDockContainer*> HiddenFloatingWidgets;
101102
QList<CDockContainerWidget*> Containers;
102103
CDockOverlay* ContainerOverlay;
103104
CDockOverlay* DockAreaOverlay;
@@ -755,6 +756,10 @@ CFloatingDockContainer* CDockManager::addDockWidgetFloating(CDockWidget* Dockwid
755756
void CDockManager::showEvent(QShowEvent *event)
756757
{
757758
Super::showEvent(event);
759+
760+
// Fix Issue #380
761+
restoreHiddenFloatingWidgets();
762+
758763
if (d->UninitializedFloatingWidgets.empty())
759764
{
760765
return;
@@ -772,6 +777,32 @@ void CDockManager::showEvent(QShowEvent *event)
772777
d->UninitializedFloatingWidgets.clear();
773778
}
774779

780+
void CDockManager::restoreHiddenFloatingWidgets()
781+
{
782+
// Restore floating widgets that were hidden upon hideManagerAndFloatingWidgets
783+
for (auto FloatingWidget : d->HiddenFloatingWidgets)
784+
{
785+
bool hasDockWidgetVisible = false;
786+
787+
// Needed to prevent CFloatingDockContainer being shown empty
788+
// Could make sense to move this to CFloatingDockContainer::showEvent(QShowEvent *event)
789+
// if experiencing CFloatingDockContainer being shown empty in other situations, but let's keep
790+
// it here for now to make sure changes to fix Issue #380 does not impact existing behaviours
791+
for ( auto dockWidget : FloatingWidget->dockWidgets() )
792+
{
793+
if ( dockWidget->toggleViewAction()->isChecked() )
794+
{
795+
dockWidget->toggleView(true);
796+
hasDockWidgetVisible = true;
797+
}
798+
}
799+
800+
if ( hasDockWidgetVisible )
801+
FloatingWidget->show();
802+
}
803+
804+
d->HiddenFloatingWidgets.clear();
805+
}
775806

776807
//============================================================================
777808
CDockAreaWidget* CDockManager::addDockWidget(DockWidgetArea area,
@@ -1102,6 +1133,38 @@ void CDockManager::setDockWidgetFocused(CDockWidget* DockWidget)
11021133
}
11031134
}
11041135

1136+
//===========================================================================
1137+
void CDockManager::hideManagerAndFloatingWidgets()
1138+
{
1139+
hide();
1140+
1141+
d->HiddenFloatingWidgets.clear();
1142+
// Hide updates of floating widgets from user
1143+
for (auto FloatingWidget : d->FloatingWidgets)
1144+
{
1145+
if ( FloatingWidget->isVisible() )
1146+
{
1147+
QList<CDockWidget*> VisibleWidgets;
1148+
for ( auto dockWidget : FloatingWidget->dockWidgets() )
1149+
{
1150+
if ( dockWidget->toggleViewAction()->isChecked() )
1151+
VisibleWidgets.push_back( dockWidget );
1152+
}
1153+
1154+
// save as floating widget to be shown when CDockManager will be shown back
1155+
d->HiddenFloatingWidgets.push_back( FloatingWidget );
1156+
FloatingWidget->hide();
1157+
1158+
// hidding floating widget automatically marked contained CDockWidgets as hidden
1159+
// but they must remain marked as visible as we want them to be restored visible
1160+
// when CDockManager will be shown back
1161+
for ( auto dockWidget : VisibleWidgets )
1162+
{
1163+
dockWidget->toggleViewAction()->setChecked(true);
1164+
}
1165+
}
1166+
}
1167+
}
11051168

11061169
//===========================================================================
11071170
CDockWidget* CDockManager::focusedDockWidget() const

src/DockManager.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ class ADS_EXPORT CDockManager : public CDockContainerWidget
147147
*/
148148
CDockFocusController* dockFocusController() const;
149149

150+
/**
151+
* Restore floating widgets hidden by an earlier call to hideManagerAndFloatingWidgets.
152+
*/
153+
void restoreHiddenFloatingWidgets();
154+
150155
public:
151156
using Super = CDockContainerWidget;
152157

@@ -527,6 +532,12 @@ public Q_SLOTS:
527532
*/
528533
void setDockWidgetFocused(CDockWidget* DockWidget);
529534

535+
/**
536+
* hide CDockManager and all floating widgets (See Issue #380). Calling regular QWidget::hide()
537+
* hides the CDockManager but not the floating widgets;
538+
*/
539+
void hideManagerAndFloatingWidgets();
540+
530541
Q_SIGNALS:
531542
/**
532543
* This signal is emitted if the list of perspectives changed.

0 commit comments

Comments
 (0)