2017-02-27 21:15:20 +08:00
|
|
|
/*******************************************************************************
|
|
|
|
** QtAdcancedDockingSystem
|
|
|
|
** Copyright (C) 2017 Uwe Kindler
|
|
|
|
**
|
|
|
|
** This program is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** This program is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
******************************************************************************/
|
|
|
|
|
2017-02-27 01:13:56 +08:00
|
|
|
|
2017-02-25 05:44:02 +08:00
|
|
|
//============================================================================
|
|
|
|
/// \file DockWidget.cpp
|
|
|
|
/// \author Uwe Kindler
|
2017-02-27 01:13:56 +08:00
|
|
|
/// \date 26.02.2017
|
|
|
|
/// \brief Implementation of CDockWidget class
|
2017-02-25 05:44:02 +08:00
|
|
|
//============================================================================
|
|
|
|
|
2017-02-27 21:15:20 +08:00
|
|
|
|
2017-02-25 05:44:02 +08:00
|
|
|
//============================================================================
|
|
|
|
// INCLUDES
|
|
|
|
//============================================================================
|
|
|
|
#include "DockWidget.h"
|
|
|
|
|
2017-02-27 01:13:56 +08:00
|
|
|
#include <QBoxLayout>
|
2017-03-12 04:38:31 +08:00
|
|
|
#include <QAction>
|
|
|
|
#include <QSplitter>
|
|
|
|
#include <QStack>
|
|
|
|
#include <QTextStream>
|
2017-03-13 22:34:40 +08:00
|
|
|
#include <QPointer>
|
2017-03-12 04:38:31 +08:00
|
|
|
|
|
|
|
#include <iostream>
|
2017-02-27 01:13:56 +08:00
|
|
|
|
2017-02-27 21:15:20 +08:00
|
|
|
#include "DockWidgetTitleBar.h"
|
2017-03-01 21:09:56 +08:00
|
|
|
#include "DockContainerWidget.h"
|
|
|
|
#include "DockAreaWidget.h"
|
2017-03-12 04:38:31 +08:00
|
|
|
#include "DockManager.h"
|
|
|
|
#include "FloatingDockContainer.h"
|
|
|
|
|
2017-03-01 21:09:56 +08:00
|
|
|
#include "ads_globals.h"
|
2017-02-27 21:15:20 +08:00
|
|
|
|
2017-02-25 05:44:02 +08:00
|
|
|
namespace ads
|
|
|
|
{
|
2017-02-27 01:13:56 +08:00
|
|
|
/**
|
|
|
|
* Private data class of CDockWidget class (pimpl)
|
|
|
|
*/
|
|
|
|
struct DockWidgetPrivate
|
|
|
|
{
|
|
|
|
CDockWidget* _this;
|
|
|
|
QBoxLayout* Layout;
|
|
|
|
QWidget* Widget = nullptr;
|
2017-02-27 21:15:20 +08:00
|
|
|
CDockWidgetTitleBar* TitleWidget;
|
|
|
|
CDockWidget::DockWidgetFeatures Features = CDockWidget::AllDockWidgetFeatures;
|
2017-03-01 21:09:56 +08:00
|
|
|
CDockManager* DockManager = nullptr;
|
2017-03-12 04:38:31 +08:00
|
|
|
CDockAreaWidget* DockArea = nullptr;
|
|
|
|
QAction* ToggleViewAction;
|
2017-03-22 23:08:44 +08:00
|
|
|
bool Closed = false;
|
2017-03-13 22:34:40 +08:00
|
|
|
struct CapturedState
|
|
|
|
{
|
|
|
|
QString DockTreePosition;
|
|
|
|
QRect GlobalGeometry;
|
|
|
|
QPointer<CDockContainerWidget> DockContainer;
|
|
|
|
} CapturedState;
|
2017-02-27 01:13:56 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Private data constructor
|
|
|
|
*/
|
|
|
|
DockWidgetPrivate(CDockWidget* _public);
|
2017-03-12 04:38:31 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves the current state into CapturedState variable
|
|
|
|
*/
|
|
|
|
void capturedState();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show dock widget
|
|
|
|
*/
|
|
|
|
void showDockWidget();
|
2017-03-22 23:08:44 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides a parent splitter if all dock widgets in the splitter are closed
|
|
|
|
*/
|
|
|
|
void hideEmptyParentSplitter();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides a dock area if all dock widgets in the area are closed
|
|
|
|
*/
|
|
|
|
void hideEmptyParentDockArea();
|
2017-02-27 01:13:56 +08:00
|
|
|
};
|
|
|
|
// struct DockWidgetPrivate
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
DockWidgetPrivate::DockWidgetPrivate(CDockWidget* _public) :
|
|
|
|
_this(_public)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-03-12 04:38:31 +08:00
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void DockWidgetPrivate::capturedState()
|
|
|
|
{
|
2017-03-13 22:34:40 +08:00
|
|
|
QString DockTreePosition;
|
|
|
|
QTextStream stream(&DockTreePosition);
|
|
|
|
|
|
|
|
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)
|
2017-03-12 04:38:31 +08:00
|
|
|
{
|
2017-03-13 22:34:40 +08:00
|
|
|
SplitterData.push(QString("%1%2")
|
|
|
|
.arg((splitter->orientation() == Qt::Horizontal) ? "H" : "V")
|
|
|
|
.arg(splitter->indexOf(Widget)));
|
|
|
|
Widget = splitter;
|
|
|
|
splitter = internal::findParent<QSplitter*>(Widget);
|
2017-03-12 04:38:31 +08:00
|
|
|
}
|
2017-03-13 22:34:40 +08:00
|
|
|
|
|
|
|
QString Separator;
|
|
|
|
while (!SplitterData.isEmpty())
|
2017-03-12 04:38:31 +08:00
|
|
|
{
|
2017-03-13 22:34:40 +08:00
|
|
|
stream << Separator << SplitterData.pop();
|
|
|
|
Separator = " ";
|
2017-03-12 04:38:31 +08:00
|
|
|
}
|
2017-03-13 22:34:40 +08:00
|
|
|
this->CapturedState.DockTreePosition = DockTreePosition;
|
|
|
|
std::cout << "SerializedPosition: " << DockTreePosition.toStdString() << std::endl;
|
2017-03-12 04:38:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void DockWidgetPrivate::showDockWidget()
|
|
|
|
{
|
2017-03-22 23:08:44 +08:00
|
|
|
DockArea->show();
|
|
|
|
DockArea->setCurrentIndex(DockArea->tabIndex(_this));
|
|
|
|
QSplitter* Splitter = internal::findParent<QSplitter*>(_this);
|
|
|
|
if (Splitter)
|
2017-03-13 22:34:40 +08:00
|
|
|
{
|
2017-03-22 23:08:44 +08:00
|
|
|
Splitter->show();
|
2017-03-13 22:34:40 +08:00
|
|
|
}
|
2017-03-22 23:08:44 +08:00
|
|
|
}
|
2017-03-13 22:34:40 +08:00
|
|
|
|
|
|
|
|
2017-03-22 23:08:44 +08:00
|
|
|
//============================================================================
|
|
|
|
void DockWidgetPrivate::hideEmptyParentSplitter()
|
|
|
|
{
|
|
|
|
QSplitter* Splitter = internal::findParent<QSplitter*>(_this);
|
|
|
|
if (!Splitter)
|
2017-03-12 04:38:31 +08:00
|
|
|
{
|
2017-03-22 23:08:44 +08:00
|
|
|
return;
|
2017-03-13 22:34:40 +08:00
|
|
|
}
|
|
|
|
|
2017-03-22 23:08:44 +08:00
|
|
|
for (int i = 0; i < Splitter->count(); ++i)
|
2017-03-13 22:34:40 +08:00
|
|
|
{
|
2017-03-22 23:08:44 +08:00
|
|
|
if (Splitter->widget(i)->isVisible())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-03-13 22:34:40 +08:00
|
|
|
|
2017-03-22 23:08:44 +08:00
|
|
|
Splitter->hide();
|
|
|
|
}
|
2017-03-21 18:27:26 +08:00
|
|
|
|
|
|
|
|
2017-03-22 23:08:44 +08:00
|
|
|
//============================================================================
|
|
|
|
void DockWidgetPrivate::hideEmptyParentDockArea()
|
|
|
|
{
|
|
|
|
auto OpenDockWidgets = DockArea->openDockWidgets();
|
|
|
|
if (OpenDockWidgets.count() > 1)
|
2017-03-21 18:27:26 +08:00
|
|
|
{
|
2017-03-22 23:08:44 +08:00
|
|
|
CDockWidget* NextDockWidget;
|
|
|
|
if (OpenDockWidgets.last() == _this)
|
|
|
|
{
|
|
|
|
NextDockWidget = OpenDockWidgets[OpenDockWidgets.count() - 2];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int NextIndex = OpenDockWidgets.indexOf(_this) + 1;
|
|
|
|
NextDockWidget = OpenDockWidgets[NextIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
DockArea->setCurrentDockWidget(NextDockWidget);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DockArea->hide();
|
2017-03-12 04:38:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-27 01:13:56 +08:00
|
|
|
//============================================================================
|
|
|
|
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);
|
2017-02-27 21:15:20 +08:00
|
|
|
setWindowTitle(title);
|
|
|
|
|
|
|
|
d->TitleWidget = new CDockWidgetTitleBar(this);
|
2017-03-12 04:38:31 +08:00
|
|
|
d->ToggleViewAction = new QAction(title);
|
|
|
|
d->ToggleViewAction->setCheckable(true);
|
|
|
|
connect(d->ToggleViewAction, SIGNAL(triggered(bool)), this,
|
|
|
|
SLOT(toggleView(bool)));
|
2017-02-27 01:13:56 +08:00
|
|
|
}
|
2017-02-25 05:44:02 +08:00
|
|
|
|
2017-02-27 01:13:56 +08:00
|
|
|
//============================================================================
|
|
|
|
CDockWidget::~CDockWidget()
|
|
|
|
{
|
2017-03-12 04:38:31 +08:00
|
|
|
std::cout << "~CDockWidget()" << std::endl;
|
2017-02-27 01:13:56 +08:00
|
|
|
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;
|
|
|
|
}
|
2017-02-27 21:15:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockWidgetTitleBar* CDockWidget::titleBar() const
|
|
|
|
{
|
|
|
|
return d->TitleWidget;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockWidget::setFeatures(DockWidgetFeatures features)
|
|
|
|
{
|
|
|
|
d->Features = features;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockWidget::DockWidgetFeatures CDockWidget::features() const
|
|
|
|
{
|
|
|
|
return d->Features;
|
|
|
|
}
|
2017-02-28 22:23:02 +08:00
|
|
|
|
2017-03-01 21:09:56 +08:00
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockManager* CDockWidget::dockManager() const
|
|
|
|
{
|
|
|
|
return d->DockManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockWidget::setDockManager(CDockManager* DockManager)
|
|
|
|
{
|
|
|
|
d->DockManager = DockManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockContainerWidget* CDockWidget::dockContainer() const
|
|
|
|
{
|
|
|
|
return internal::findParent<CDockContainerWidget*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockAreaWidget* CDockWidget::dockAreaWidget() const
|
|
|
|
{
|
|
|
|
return internal::findParent<CDockAreaWidget*>(this);
|
|
|
|
}
|
|
|
|
|
2017-03-12 04:38:31 +08:00
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
bool CDockWidget::isFloating() const
|
|
|
|
{
|
|
|
|
return dockContainer() ? dockContainer()->isFloating() : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-22 23:08:44 +08:00
|
|
|
//============================================================================
|
|
|
|
bool CDockWidget::isClosed() const
|
|
|
|
{
|
|
|
|
return d->Closed;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-12 04:38:31 +08:00
|
|
|
//============================================================================
|
|
|
|
QAction* CDockWidget::toggleViewAction() const
|
|
|
|
{
|
|
|
|
return d->ToggleViewAction;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockWidget::toggleView(bool Open)
|
|
|
|
{
|
2017-03-21 18:27:26 +08:00
|
|
|
if (Open)
|
2017-03-12 04:38:31 +08:00
|
|
|
{
|
|
|
|
d->showDockWidget();
|
|
|
|
}
|
2017-03-21 18:27:26 +08:00
|
|
|
else
|
|
|
|
{
|
2017-03-22 23:08:44 +08:00
|
|
|
hideDockWidget();
|
2017-03-21 18:27:26 +08:00
|
|
|
}
|
2017-03-22 23:08:44 +08:00
|
|
|
d->Closed = !Open;
|
2017-03-12 04:38:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockWidget::setDockArea(CDockAreaWidget* DockArea)
|
|
|
|
{
|
|
|
|
d->DockArea = DockArea;
|
|
|
|
d->ToggleViewAction->setChecked(DockArea != nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
2017-03-22 23:08:44 +08:00
|
|
|
void CDockWidget::hideDockWidget()
|
2017-03-12 04:38:31 +08:00
|
|
|
{
|
2017-03-22 23:08:44 +08:00
|
|
|
CDockAreaWidget* DockArea = d->DockArea;
|
2017-03-21 18:27:26 +08:00
|
|
|
d->ToggleViewAction->setChecked(false);
|
|
|
|
d->TitleWidget->hide();
|
2017-03-22 23:08:44 +08:00
|
|
|
d->hideEmptyParentDockArea();
|
|
|
|
d->hideEmptyParentSplitter();
|
2017-03-12 04:38:31 +08:00
|
|
|
}
|
|
|
|
|
2017-02-25 05:44:02 +08:00
|
|
|
} // namespace ads
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// EOF DockWidget.cpp
|