Added dock manager function addDockWidgetFloating to add initial floating dock widgets

This commit is contained in:
Uwe Kindler 2019-11-25 15:28:15 +01:00
parent 316d9a00b5
commit aee9fb1c95
4 changed files with 68 additions and 3 deletions

View File

@ -57,6 +57,7 @@
#include "DockManager.h" #include "DockManager.h"
#include "DockWidget.h" #include "DockWidget.h"
#include "DockAreaWidget.h" #include "DockAreaWidget.h"
#include "FloatingDockContainer.h"
//============================================================================ //============================================================================
@ -226,8 +227,11 @@ void MainWindowPrivate::createContent()
auto BottomDockArea = DockManager->addDockWidget(ads::BottomDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea); auto BottomDockArea = DockManager->addDockWidget(ads::BottomDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea); DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea); DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea);
//DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea);
//DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea); // Test creation of floating dock widgets
auto FloatingWidget = DockManager->addDockWidgetFloating(createFileSystemTreeDockWidget(ViewMenu));
FloatingWidget->move(QPoint(0,0));
DockManager->addDockWidgetFloating(createLongTextLabelDockWidget(ViewMenu));
for (auto DockWidget : DockManager->dockWidgetsMap()) for (auto DockWidget : DockManager->dockWidgetsMap())
{ {
@ -309,6 +313,10 @@ CMainWindow::CMainWindow(QWidget *parent) :
// uncomment the following line if the tab close button should be // uncomment the following line if the tab close button should be
// a QToolButton instead of a QPushButton // a QToolButton instead of a QPushButton
// CDockManager::setConfigFlags(CDockManager::configFlags() | CDockManager::TabCloseButtonIsToolButton); // CDockManager::setConfigFlags(CDockManager::configFlags() | CDockManager::TabCloseButtonIsToolButton);
auto Flags = CDockManager::configFlags();
Flags.setFlag(CDockManager::XmlAutoFormattingEnabled, true);
Flags.setFlag(CDockManager::XmlCompressionEnabled, false);
CDockManager::setConfigFlags(Flags);
// uncomment the following line if you wand a fixed tab width that does // uncomment the following line if you wand a fixed tab width that does
// not change if the visibility of the close button changes // not change if the visibility of the close button changes
@ -328,7 +336,7 @@ CMainWindow::CMainWindow(QWidget *parent) :
// Default window geometry // Default window geometry
resize(1280, 720); resize(1280, 720);
d->restoreState(); //d->restoreState();
d->restorePerspectives(); d->restorePerspectives();
} }

View File

@ -63,6 +63,7 @@ private:
friend struct DockWidgetPrivate; friend struct DockWidgetPrivate;
friend class CDockWidget; friend class CDockWidget;
friend struct DockManagerPrivate; friend struct DockManagerPrivate;
friend class CDockManager;
private slots: private slots:
void onTabCloseRequested(int Index); void onTabCloseRequested(int Index);

View File

@ -76,6 +76,7 @@ struct DockManagerPrivate
QMenu* ViewMenu; QMenu* ViewMenu;
CDockManager::eViewMenuInsertionOrder MenuInsertionOrder = CDockManager::MenuAlphabeticallySorted; CDockManager::eViewMenuInsertionOrder MenuInsertionOrder = CDockManager::MenuAlphabeticallySorted;
bool RestoringState = false; bool RestoringState = false;
QVector<CFloatingDockContainer*> UninitializedFloatingWidgets;
/** /**
* Private data constructor * Private data constructor
@ -560,6 +561,48 @@ bool CDockManager::restoreState(const QByteArray &state, int version)
} }
//============================================================================
CFloatingDockContainer* CDockManager::addDockWidgetFloating(CDockWidget* Dockwidget)
{
d->DockWidgetsMap.insert(Dockwidget->objectName(), Dockwidget);
CDockAreaWidget* OldDockArea = Dockwidget->dockAreaWidget();
if (OldDockArea)
{
OldDockArea->removeDockWidget(Dockwidget);
}
Dockwidget->setDockManager(this);
CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(Dockwidget);
FloatingWidget->resize(Dockwidget->size());
if (isVisible())
{
FloatingWidget->show();
}
else
{
d->UninitializedFloatingWidgets.append(FloatingWidget);
}
return FloatingWidget;
}
//============================================================================
void CDockManager::showEvent(QShowEvent *event)
{
Super::showEvent(event);
if (d->UninitializedFloatingWidgets.empty())
{
return;
}
for (auto FloatingWidget : d->UninitializedFloatingWidgets)
{
FloatingWidget->show();
}
d->UninitializedFloatingWidgets.clear();
}
//============================================================================ //============================================================================
CDockAreaWidget* CDockManager::addDockWidget(DockWidgetArea area, CDockAreaWidget* CDockManager::addDockWidget(DockWidgetArea area,
CDockWidget* Dockwidget, CDockAreaWidget* DockAreaWidget) CDockWidget* Dockwidget, CDockAreaWidget* DockAreaWidget)

View File

@ -111,7 +111,14 @@ protected:
*/ */
CDockOverlay* dockAreaOverlay() const; CDockOverlay* dockAreaOverlay() const;
/**
* Show the floating widgets that has been created floating
*/
virtual void showEvent(QShowEvent *event) override;
public: public:
using Super = CDockContainerWidget;
enum eViewMenuInsertionOrder enum eViewMenuInsertionOrder
{ {
MenuSortedByInsertion, MenuSortedByInsertion,
@ -206,6 +213,12 @@ public:
CDockAreaWidget* addDockWidgetTabToArea(CDockWidget* Dockwidget, CDockAreaWidget* addDockWidgetTabToArea(CDockWidget* Dockwidget,
CDockAreaWidget* DockAreaWidget); CDockAreaWidget* DockAreaWidget);
/**
* Adds the given DockWidget floating and returns the created
* CFloatingDockContainer instance.
*/
CFloatingDockContainer* addDockWidgetFloating(CDockWidget* Dockwidget);
/** /**
* Searches for a registered doc widget with the given ObjectName * Searches for a registered doc widget with the given ObjectName
* \return Return the found dock widget or nullptr if a dock widget with the * \return Return the found dock widget or nullptr if a dock widget with the