Implemented support for adding dock widgets to DockContainerWidget

This commit is contained in:
Uwe Kindler
2017-02-26 18:13:56 +01:00
parent 94a6f5e2f1
commit 4a0c176327
24 changed files with 864 additions and 50 deletions

View File

@@ -124,31 +124,9 @@ void CContainerWidget::dropFloatingWidget(FloatingWidget* FloatingWidget,
}
void CContainerWidget::dropChildSections(QWidget* Parent)
{
auto Sections = Parent->findChildren<SectionWidget*>(QString(), Qt::FindDirectChildrenOnly);
auto Splitters = Parent->findChildren<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);
std::cout << "-----------------------" << std::endl;
std::cout << "Sections " << Sections.size() << std::endl;
std::cout << "Splitters " << Splitters.size() << std::endl;
for (auto Section : Sections)
{
// drop section
}
for (auto Splitter : Splitters)
{
dropChildSections(Splitter);
}
}
void CContainerWidget::dropIntoContainer(FloatingWidget* FloatingWidget, DropArea area)
{
dropChildSections(FloatingWidget->containerWidget());
CContainerWidget* FloatingContainer = FloatingWidget->containerWidget();
QSplitter* FloatingMainSplitter = FloatingContainer->findChild<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);

View File

@@ -116,9 +116,6 @@ protected:
unsigned int m_zOrderIndex = 0;
static unsigned int zOrderCounter;
private:
void dropChildSections(QWidget* Parent);
private slots:
void onActiveTabChanged();
};

View File

@@ -10,7 +10,10 @@
//============================================================================
#include "DockAreaWidget.h"
#include <QStackedLayout>
#include "DockContainerWidget.h"
#include "DockWidget.h"
namespace ads
{
@@ -20,6 +23,7 @@ namespace ads
struct DockAreaWidgetPrivate
{
CDockAreaWidget* _this;
QStackedLayout* StackedLayout;
/**
* Private data constructor
@@ -40,7 +44,11 @@ CDockAreaWidget::CDockAreaWidget(CDockManager* DockManager, CDockContainerWidget
QFrame(parent),
d(new DockAreaWidgetPrivate(this))
{
setStyleSheet("background: yellow;");
d->StackedLayout = new QStackedLayout();
d->StackedLayout->setContentsMargins(0, 0, 0, 0);
d->StackedLayout->setSpacing(0);
setLayout(d->StackedLayout);
}
//============================================================================
@@ -66,6 +74,13 @@ CDockContainerWidget* CDockAreaWidget::dockContainerWidget() const
return 0;
}
//============================================================================
void CDockAreaWidget::addDockWidget(CDockWidget* DockWidget)
{
d->StackedLayout->addWidget(DockWidget);
}
} // namespace ads
//---------------------------------------------------------------------------

View File

@@ -17,6 +17,7 @@ namespace ads
struct DockAreaWidgetPrivate;
class CDockManager;
class CDockContainerWidget;
class CDockWidget;
/**
* DockAreaWidget manages multiple instances of DckWidgets.
@@ -46,6 +47,12 @@ public:
* if there is no
*/
CDockContainerWidget* dockContainerWidget() const;
/**
* Add a new dock widget to dock area.
* All dockwidgets in the dock area tabified in a stacked layout with tabs
*/
void addDockWidget(CDockWidget* DockWidget);
}; // class DockAreaWidget
}
// namespace ads

View File

@@ -13,14 +13,31 @@
#include <QEvent>
#include <QList>
#include <QGridLayout>
#include <QSplitter>
#include "DockManager.h"
#include "DockAreaWidget.h"
#include "ads_globals.h"
namespace ads
{
static unsigned int zOrderCounter = 0;
/**
* Helper function to ease insertion of dock area into splitter
*/
static void inserDockAreaIntoSplitter(QSplitter* Splitter, QWidget* widget, bool Append)
{
if (Append)
{
Splitter->addWidget(widget);
}
else
{
Splitter->insertWidget(0, widget);
}
}
/**
* Private data class of CDockContainerWidget class (pimpl)
*/
@@ -40,12 +57,23 @@ struct DockContainerWidgetPrivate
/**
* Create a new dock area widget and adds it to the list of doc areas
*/
CDockAreaWidget* newDockAreaWidget()
CDockAreaWidget* newDockArea()
{
auto DockAreaWidget = new CDockAreaWidget(DockManager, _this);
DockAreas.append(DockAreaWidget);
return DockAreaWidget;
}
/**
* Adds dock widget to container
*/
void dockWidgetIntoContainer(DockWidgetArea area, CDockWidget* Dockwidget);
/**
* Adds dock widget to a existing DockWidgetArea
*/
void dockWidgetIntoDockArea(DockWidgetArea area, CDockWidget* Dockwidget,
CDockAreaWidget* DockAreaWidget);
}; // struct DockContainerWidgetPrivate
@@ -56,11 +84,72 @@ DockContainerWidgetPrivate::DockContainerWidgetPrivate(CDockContainerWidget* _pu
}
//============================================================================
void DockContainerWidgetPrivate::dockWidgetIntoContainer(DockWidgetArea area,
CDockWidget* Dockwidget)
{
CDockAreaWidget* NewDockArea = new CDockAreaWidget(DockManager, _this);
NewDockArea->addDockWidget(Dockwidget);
auto InsertParam = internal::dockAreaInsertParameters(area);
if (DockAreas.isEmpty())
{
Layout->addWidget(NewDockArea, 0, 0);
}
else if (DockAreas.count() == 1)
{
QSplitter* Splitter = internal::newSplitter(InsertParam.first);
auto DockArea = dynamic_cast<CDockAreaWidget*>(Layout->itemAtPosition(0, 0)->widget());
Layout->replaceWidget(DockArea, Splitter);
Splitter->addWidget(DockArea);
inserDockAreaIntoSplitter(Splitter, NewDockArea, InsertParam.second);
}
else
{
QSplitter* Splitter = _this->findChild<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);
if (Splitter->orientation() == InsertParam.first)
{
inserDockAreaIntoSplitter(Splitter, NewDockArea, InsertParam.second);
}
else
{
QSplitter* NewSplitter = internal::newSplitter(InsertParam.first);
if (InsertParam.second)
{
QLayoutItem* li = Layout->replaceWidget(Splitter, NewSplitter);
NewSplitter->addWidget(Splitter);
NewSplitter->addWidget(NewDockArea);
delete li;
}
else
{
NewSplitter->addWidget(NewDockArea);
QLayoutItem* li = Layout->replaceWidget(Splitter, NewSplitter);
NewSplitter->addWidget(Splitter);
delete li;
}
}
}
DockAreas.append(NewDockArea);
}
//============================================================================
void DockContainerWidgetPrivate::dockWidgetIntoDockArea(DockWidgetArea area,
CDockWidget* Dockwidget, CDockAreaWidget* DockAreaWidget)
{
}
//============================================================================
CDockContainerWidget::CDockContainerWidget(CDockManager* DockManager, QWidget *parent) :
QFrame(parent),
d(new DockContainerWidgetPrivate(this))
{
setStyleSheet("background: green;");
d->DockManager = DockManager;
d->Layout = new QGridLayout();
@@ -80,9 +169,13 @@ CDockContainerWidget::~CDockContainerWidget()
void CDockContainerWidget::addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget,
CDockAreaWidget* DockAreaWidget)
{
if (d->DockAreas.isEmpty())
if (DockAreaWidget)
{
d->dockWidgetIntoDockArea(area, Dockwidget, DockAreaWidget);
}
else
{
d->dockWidgetIntoContainer(area, Dockwidget);
}
}

View File

@@ -1,8 +1,9 @@
//============================================================================
/// \file DockManager.cpp
/// \author Uwe Kindler
/// \date 23.02.2017
/// \brief Implementation of CDockManager
/// \date 26.02.2017
/// \brief Implementation of CDockManager class
//============================================================================
//============================================================================
@@ -10,9 +11,49 @@
//============================================================================
#include "DockManager.h"
#include <QMainWindow>
namespace ads
{
/**
* Private data class of CDockManager class (pimpl)
*/
struct DockManagerPrivate
{
CDockManager* _this;
/**
* Private data constructor
*/
DockManagerPrivate(CDockManager* _public);
};
// struct DockManagerPrivate
//============================================================================
DockManagerPrivate::DockManagerPrivate(CDockManager* _public) :
_this(_public)
{
}
//============================================================================
CDockManager::CDockManager(QWidget *parent) :
CDockContainerWidget(this, parent),
d(new DockManagerPrivate(this))
{
QMainWindow* MainWindow = dynamic_cast<QMainWindow*>(parent);
if (MainWindow)
{
MainWindow->setCentralWidget(this);
}
}
//============================================================================
CDockManager::~CDockManager()
{
delete d;
}
} // namespace ads
//---------------------------------------------------------------------------

View File

@@ -3,8 +3,8 @@
//============================================================================
/// \file DockManager.h
/// \author Uwe Kindler
/// \date 23.02.2017
/// \brief Declaration of CDockManager
/// \date 26.02.2017
/// \brief Declaration of CDockManager class
//============================================================================
//============================================================================
@@ -14,15 +14,31 @@
namespace ads
{
struct DockManagerPrivate;
/**
* @brief
*/
* The central dock manager that maintains the complete docking system
**/
class CDockManager : public CDockContainerWidget
{
};
Q_OBJECT
private:
DockManagerPrivate* d; ///< private data (pimpl)
friend class DockManagerPrivate;
protected:
public:
/**
* Default Constructor.
* If the given parent is a QMainWindow, the dck manager sets itself as the
* central widget
*/
CDockManager(QWidget* parent = 0);
/**
* Virtual Destructor
*/
virtual ~CDockManager();
}; // class DockManager
} // namespace ads
//---------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#endif // DockManagerH

View File

@@ -1,8 +1,9 @@
//============================================================================
/// \file DockWidget.cpp
/// \author Uwe Kindler
/// \date 23.02.2017
/// \brief Implementation of CDockWidget
/// \date 26.02.2017
/// \brief Implementation of CDockWidget class
//============================================================================
//============================================================================
@@ -10,9 +11,72 @@
//============================================================================
#include "DockWidget.h"
#include <QBoxLayout>
namespace ads
{
/**
* Private data class of CDockWidget class (pimpl)
*/
struct DockWidgetPrivate
{
CDockWidget* _this;
QBoxLayout* Layout;
QWidget* Widget = nullptr;
/**
* Private data constructor
*/
DockWidgetPrivate(CDockWidget* _public);
};
// struct DockWidgetPrivate
//============================================================================
DockWidgetPrivate::DockWidgetPrivate(CDockWidget* _public) :
_this(_public)
{
}
//============================================================================
CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
QFrame(parent),
d(new DockWidgetPrivate(this))
{
d->Layout = new QBoxLayout(QBoxLayout::TopToBottom);
d->Layout->setContentsMargins(0, 0, 0, 0);
d->Layout->setSpacing(0);
setLayout(d->Layout);
}
//============================================================================
CDockWidget::~CDockWidget()
{
delete d;
}
//============================================================================
void CDockWidget::setWidget(QWidget* widget)
{
if (d->Widget)
{
d->Layout->replaceWidget(d->Widget, widget);
}
else
{
d->Layout->addWidget(widget);
}
d->Widget = widget;
}
//============================================================================
QWidget* CDockWidget::widget() const
{
return d->Widget;
}
} // namespace ads
//---------------------------------------------------------------------------

View File

@@ -3,8 +3,8 @@
//============================================================================
/// \file DockWidget.h
/// \author Uwe Kindler
/// \date 23.02.2017
/// \brief Declaration of CDockWidget
/// \date 26.02.2017
/// \brief Declaration of CDockWidget class
//============================================================================
//============================================================================
@@ -14,16 +14,42 @@
namespace ads
{
struct DockWidgetPrivate;
/**
* @brief
* The QDockWidget class provides a widget that can be docked inside a
* CDockManager or floated as a top-level window on the desktop.
*/
class CDockWidget : public QFrame
{
Q_OBJECT
};
private:
DockWidgetPrivate* d; ///< private data (pimpl)
friend class DockWidgetPrivate;
protected:
public:
/**
* Default Constructor
*/
CDockWidget(const QString &title, QWidget* parent = 0);
} // namespace ads
/**
* Virtual Destructor
*/
virtual ~CDockWidget();
//---------------------------------------------------------------------------
/**
* Sets the widget for the dock widget to widget.
*/
void setWidget(QWidget* widget);
/**
* Returns the widget for the dock widget. This function returns zero if
* the widget has not been set.
*/
QWidget* widget() const;
}; // class DockWidget
}
// namespace ads
//-----------------------------------------------------------------------------
#endif // DockWidgetH

View File

@@ -12,11 +12,14 @@
#include <QSplitter>
#include <QVariant>
#include "ads_globals.h"
namespace ads
{
namespace internal
{
//============================================================================
QSplitter* newSplitter(Qt::Orientation orientation, QWidget* parent)
{
QSplitter* s = new QSplitter(orientation, parent);
@@ -26,6 +29,22 @@ QSplitter* newSplitter(Qt::Orientation orientation, QWidget* parent)
return s;
}
//============================================================================
QPair<Qt::Orientation, bool> dockAreaInsertParameters(DockWidgetArea Area)
{
switch (Area)
{
case TopDockWidgetArea: return QPair<Qt::Orientation, bool>(Qt::Vertical, false);
case RightDockWidgetArea: return QPair<Qt::Orientation, bool>(Qt::Horizontal, true);
case CenterDockWidgetArea:
case BottomDockWidgetArea: return QPair<Qt::Orientation, bool>(Qt::Vertical, true);
case LeftDockWidgetArea: return QPair<Qt::Orientation, bool>(Qt::Horizontal, false);
default: QPair<Qt::Orientation, bool>(Qt::Vertical, false);
} // switch (Area)
return QPair<Qt::Orientation, bool>(Qt::Vertical, false);
}
} // namespace internal
} // namespace ads

View File

@@ -11,6 +11,8 @@
//============================================================================
// INCLUDES
//============================================================================
#include <QPair>
class QSplitter;
namespace ads
@@ -24,8 +26,8 @@ enum DockWidgetArea
BottomDockWidgetArea = 0x08,
CenterDockWidgetArea = 0x10,
OuterAreas = TopDockWidgetArea | LeftDockWidgetArea | RightDockWidgetArea | BottomDockWidgetArea,
AllAreas = OuterAreas | CenterDockWidgetArea
OuterDockAreas = TopDockWidgetArea | LeftDockWidgetArea | RightDockWidgetArea | BottomDockWidgetArea,
AllDockAreas = OuterDockAreas | CenterDockWidgetArea
};
Q_DECLARE_FLAGS(DockWidgetAreas, DockWidgetArea)
@@ -34,7 +36,12 @@ namespace internal
/**
* Helper function to create new splitter widgets
*/
QSplitter* newSplitter(Qt::Orientation orientation, QWidget* parent);
QSplitter* newSplitter(Qt::Orientation orientation, QWidget* parent = 0);
/**
* Returns the insertion parameters for the given dock area
*/
QPair<Qt::Orientation, bool> dockAreaInsertParameters(DockWidgetArea Area);
} // namespace internal
} // namespace ads

View File

@@ -0,0 +1,20 @@
DEPENDPATH *= $$PWD
HEADERS += \
$$PWD/ads_globals.h \
$$PWD/DockAreaWidget.h \
$$PWD/DockContainerWidget.h \
$$PWD/DockManager.h \
$$PWD/DockWidget.h \
$$PWD/DockWidgetTitleBar.h \
$$PWD/FloatingDockContainer.h
SOURCES += \
$$PWD/ads_globals.cpp \
$$PWD/DockAreaWidget.cpp \
$$PWD/DockContainerWidget.cpp \
$$PWD/DockManager.cpp \
$$PWD/DockWidget.cpp \
$$PWD/DockWidgetTitleBar.cpp \
$$PWD/FloatingDockContainer.cpp