mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2025-01-24 05:22:06 +08:00
Added signals for dock area added and removed
This commit is contained in:
parent
97571e4be8
commit
239bd4781b
@ -81,16 +81,6 @@ struct DockContainerWidgetPrivate
|
||||
*/
|
||||
DockContainerWidgetPrivate(CDockContainerWidget* _public);
|
||||
|
||||
/**
|
||||
* Create a new dock area widget and adds it to the list of doc areas
|
||||
*/
|
||||
CDockAreaWidget* newDockArea()
|
||||
{
|
||||
auto DockAreaWidget = new CDockAreaWidget(DockManager, _this);
|
||||
DockAreas.append(DockAreaWidget);
|
||||
return DockAreaWidget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds dock widget to container and returns the dock area that contains
|
||||
* the inserted dock widget
|
||||
@ -289,6 +279,8 @@ void DockContainerWidgetPrivate::addDockAreasToList(const QList<CDockAreaWidget*
|
||||
{
|
||||
DockAreas.last()->updateDockArea();
|
||||
}
|
||||
|
||||
emit _this->dockAreasAdded();
|
||||
}
|
||||
|
||||
|
||||
@ -348,6 +340,7 @@ void DockContainerWidgetPrivate::addDockArea(CDockAreaWidget* NewDockArea, DockW
|
||||
|
||||
DockAreas.append(NewDockArea);
|
||||
NewDockArea->updateDockArea();
|
||||
emit _this->dockAreasAdded();
|
||||
}
|
||||
|
||||
|
||||
@ -392,6 +385,7 @@ CDockAreaWidget* DockContainerWidgetPrivate::dockWidgetIntoDockArea(DockWidgetAr
|
||||
}
|
||||
|
||||
DockAreas.append(NewDockArea);
|
||||
emit _this->dockAreasAdded();
|
||||
return NewDockArea;
|
||||
}
|
||||
|
||||
@ -521,6 +515,7 @@ void CDockContainerWidget::removeDockArea(CDockAreaWidget* area)
|
||||
d->Layout->replaceWidget(Splitter, widget);
|
||||
}
|
||||
delete Splitter;
|
||||
emit dockAreasRemoved();
|
||||
}
|
||||
|
||||
|
||||
|
@ -126,6 +126,19 @@ public:
|
||||
* This function returns true, if this container is in a floating widget
|
||||
*/
|
||||
bool isFloating() const;
|
||||
|
||||
signals:
|
||||
/**
|
||||
* This signal is emitted if one or multiple dock areas has been added to
|
||||
* the internal list of dock areas.
|
||||
* If multiple dock areas are inserted, this signal is emitted only once
|
||||
*/
|
||||
void dockAreasAdded();
|
||||
|
||||
/**
|
||||
* This signal is emitted if one or multiple dock areas has been removed
|
||||
*/
|
||||
void dockAreasRemoved();
|
||||
}; // class DockContainerWidget
|
||||
} // namespace ads
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include <QSplitter>
|
||||
#include <QStack>
|
||||
#include <QTextStream>
|
||||
#include <QPointer>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@ -61,7 +62,12 @@ struct DockWidgetPrivate
|
||||
CDockManager* DockManager = nullptr;
|
||||
CDockAreaWidget* DockArea = nullptr;
|
||||
QAction* ToggleViewAction;
|
||||
QString CapturedState;
|
||||
struct CapturedState
|
||||
{
|
||||
QString DockTreePosition;
|
||||
QRect GlobalGeometry;
|
||||
QPointer<CDockContainerWidget> DockContainer;
|
||||
} CapturedState;
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
@ -91,67 +97,60 @@ DockWidgetPrivate::DockWidgetPrivate(CDockWidget* _public) :
|
||||
//============================================================================
|
||||
void DockWidgetPrivate::capturedState()
|
||||
{
|
||||
QString CapturedState;
|
||||
QTextStream stream(&CapturedState);
|
||||
stream << (_this->isFloating() ? "F " : "D ");
|
||||
if (_this->isFloating())
|
||||
{
|
||||
CFloatingDockContainer* FloatingWidget = internal::findParent<CFloatingDockContainer*>(_this);
|
||||
QRect Rect = FloatingWidget->geometry();
|
||||
stream << Rect.left() << " " << Rect.top() << " " << Rect.width()
|
||||
<< " " << Rect.height();
|
||||
}
|
||||
else
|
||||
{
|
||||
QWidget* Widget = DockArea;
|
||||
QSplitter* splitter = internal::findParent<QSplitter*>(Widget);
|
||||
QStack<QString> SplitterData;
|
||||
while (splitter)
|
||||
{
|
||||
SplitterData.push(QString("%1%2")
|
||||
.arg((splitter->orientation() == Qt::Horizontal) ? "H" : "V")
|
||||
.arg(splitter->indexOf(Widget)));
|
||||
Widget = splitter;
|
||||
splitter = internal::findParent<QSplitter*>(Widget);
|
||||
}
|
||||
QString DockTreePosition;
|
||||
QTextStream stream(&DockTreePosition);
|
||||
|
||||
QString Separator;
|
||||
while (!SplitterData.isEmpty())
|
||||
{
|
||||
stream << Separator << SplitterData.pop();
|
||||
Separator = " ";
|
||||
}
|
||||
QPoint GlobalTopLeft = _this->mapToGlobal(_this->geometry().topLeft());
|
||||
QRect Rect(GlobalTopLeft, _this->geometry().size());
|
||||
CapturedState.GlobalGeometry = Rect;
|
||||
CapturedState.DockContainer = _this->dockContainer();
|
||||
|
||||
QWidget* Widget = DockArea;
|
||||
QSplitter* splitter = internal::findParent<QSplitter*>(Widget);
|
||||
QStack<QString> SplitterData;
|
||||
while (splitter)
|
||||
{
|
||||
SplitterData.push(QString("%1%2")
|
||||
.arg((splitter->orientation() == Qt::Horizontal) ? "H" : "V")
|
||||
.arg(splitter->indexOf(Widget)));
|
||||
Widget = splitter;
|
||||
splitter = internal::findParent<QSplitter*>(Widget);
|
||||
}
|
||||
this->CapturedState = CapturedState;
|
||||
std::cout << "SerializedPosition: " << CapturedState.toStdString() << std::endl;
|
||||
|
||||
QString Separator;
|
||||
while (!SplitterData.isEmpty())
|
||||
{
|
||||
stream << Separator << SplitterData.pop();
|
||||
Separator = " ";
|
||||
}
|
||||
this->CapturedState.DockTreePosition = DockTreePosition;
|
||||
std::cout << "SerializedPosition: " << DockTreePosition.toStdString() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockWidgetPrivate::showDockWidget()
|
||||
{
|
||||
QTextStream stream(&CapturedState);
|
||||
QString DockedState;
|
||||
stream >> DockedState;
|
||||
if (DockedState == "F")
|
||||
if (!CapturedState.DockContainer)
|
||||
{
|
||||
auto FloatingWidget = new CFloatingDockContainer(_this);
|
||||
FloatingWidget->setGeometry(CapturedState.GlobalGeometry);
|
||||
FloatingWidget->show();
|
||||
return;
|
||||
}
|
||||
|
||||
CDockContainerWidget* DockContainer = CapturedState.DockContainer.data();
|
||||
QStringList DockTree = this->CapturedState.DockTreePosition.split(' ');
|
||||
QSplitter* splitter = DockContainer->findChild<QSplitter*>(QString(), Qt::FindDirectChildrenOnly);
|
||||
|
||||
while (splitter)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
for (const auto& TreeItem : DockTree)
|
||||
{
|
||||
std::cout << "Restoring Floating Dock Widget" << std::endl;
|
||||
QVector<int> v;
|
||||
while (!stream.atEnd())
|
||||
{
|
||||
int Value;
|
||||
stream >> Value;
|
||||
v.append(Value);
|
||||
}
|
||||
|
||||
if (v.count() == 4)
|
||||
{
|
||||
std::cout << "Rectangle Loaded" << std::endl;
|
||||
QRect Rect(v[0], v[1], v[2], v[3]);
|
||||
auto FloatingWidget = new CFloatingDockContainer(_this);
|
||||
FloatingWidget->setGeometry(Rect);
|
||||
FloatingWidget->show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,6 +60,7 @@ struct FloatingDockContainerPrivate
|
||||
bool DraggingActive = false;
|
||||
QPoint DragStartMousePosition;
|
||||
CDockContainerWidget* DropContainer = nullptr;
|
||||
CDockAreaWidget* SingleDockArea = nullptr;
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
@ -179,6 +180,8 @@ CFloatingDockContainer::CFloatingDockContainer(CDockManager* DockManager) :
|
||||
setLayout(l);
|
||||
|
||||
d->DockContainer = new CDockContainerWidget(DockManager, this);
|
||||
connect(d->DockContainer, SIGNAL(dockAreasAdded()), this, SLOT(onDockAreasAddedOrRemoved()));
|
||||
connect(d->DockContainer, SIGNAL(dockAreasRemoved()), this, SLOT(onDockAreasAddedOrRemoved()));
|
||||
l->addWidget(d->DockContainer);
|
||||
DockManager->registerFloatingWidget(this);
|
||||
|
||||
@ -339,6 +342,38 @@ void CFloatingDockContainer::moveFloating()
|
||||
const QPoint moveToPos = QCursor::pos() - d->DragStartMousePosition - QPoint(BorderSize, 0);
|
||||
move(moveToPos);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CFloatingDockContainer::onDockAreasAddedOrRemoved()
|
||||
{
|
||||
if (d->DockContainer->dockAreaCount() == 1)
|
||||
{
|
||||
d->SingleDockArea = d->DockContainer->dockArea(0);
|
||||
this->setWindowTitle(d->SingleDockArea->currentDockWidget()->windowTitle());
|
||||
connect(d->SingleDockArea, SIGNAL(currentChanged(int)), this,
|
||||
SLOT(onDockAreaCurrentChanged(int)));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (d->SingleDockArea)
|
||||
{
|
||||
disconnect(d->SingleDockArea, SIGNAL(currentChanged(int)), this,
|
||||
SLOT(onDockAreaCurrentChanged(int)));
|
||||
d->SingleDockArea = nullptr;
|
||||
}
|
||||
this->setWindowTitle(qApp->applicationDisplayName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CFloatingDockContainer::onDockAreaCurrentChanged(int Index)
|
||||
{
|
||||
this->setWindowTitle(d->SingleDockArea->currentDockWidget()->windowTitle());
|
||||
}
|
||||
|
||||
|
||||
} // namespace ads
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -50,6 +50,11 @@ class CFloatingDockContainer : public QWidget
|
||||
private:
|
||||
FloatingDockContainerPrivate* d; ///< private data (pimpl)
|
||||
friend class FloatingDockContainerPrivate;
|
||||
|
||||
private slots:
|
||||
void onDockAreasAddedOrRemoved();
|
||||
void onDockAreaCurrentChanged(int Index);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Private constructor that is called from public constructors
|
||||
|
Loading…
Reference in New Issue
Block a user