2017-02-27 21:15:20 +08:00
|
|
|
/*******************************************************************************
|
2017-06-10 04:04:02 +08:00
|
|
|
** Qt Advanced Docking System
|
2017-02-27 21:15:20 +08:00
|
|
|
** Copyright (C) 2017 Uwe Kindler
|
2017-06-10 04:04:02 +08:00
|
|
|
**
|
|
|
|
** This library is free software; you can redistribute it and/or
|
|
|
|
** modify it under the terms of the GNU Lesser General Public
|
|
|
|
** License as published by the Free Software Foundation; either
|
|
|
|
** version 2.1 of the License, or (at your option) any later version.
|
|
|
|
**
|
|
|
|
** This library is distributed in the hope that it will be useful,
|
2017-02-27 21:15:20 +08:00
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2017-06-10 04:04:02 +08:00
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
** Lesser General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU Lesser General Public
|
|
|
|
** License along with this library; If not, see <http://www.gnu.org/licenses/>.
|
2017-02-27 21:15:20 +08:00
|
|
|
******************************************************************************/
|
|
|
|
|
2017-02-27 01:13:56 +08:00
|
|
|
|
2017-02-25 05:44:02 +08:00
|
|
|
//============================================================================
|
|
|
|
/// \file DockManager.cpp
|
|
|
|
/// \author Uwe Kindler
|
2017-02-27 01:13:56 +08:00
|
|
|
/// \date 26.02.2017
|
|
|
|
/// \brief Implementation of CDockManager 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
|
|
|
|
//============================================================================
|
2018-08-24 19:41:58 +08:00
|
|
|
#include <DockWidgetTab.h>
|
2017-02-25 05:44:02 +08:00
|
|
|
#include "DockManager.h"
|
|
|
|
|
2018-09-14 04:19:13 +08:00
|
|
|
#include <algorithm>
|
|
|
|
|
2017-02-27 01:13:56 +08:00
|
|
|
#include <QMainWindow>
|
2017-03-01 21:09:56 +08:00
|
|
|
#include <QList>
|
2017-03-27 16:41:27 +08:00
|
|
|
#include <QMap>
|
2017-03-28 16:57:03 +08:00
|
|
|
#include <QVariant>
|
2017-03-28 18:01:27 +08:00
|
|
|
#include <QDebug>
|
2017-03-28 19:05:18 +08:00
|
|
|
#include <QFile>
|
2017-03-29 04:38:47 +08:00
|
|
|
#include <QAction>
|
2017-12-30 01:18:16 +08:00
|
|
|
#include <QXmlStreamWriter>
|
|
|
|
#include <QXmlStreamReader>
|
2018-02-13 19:00:58 +08:00
|
|
|
#include <QSettings>
|
2018-09-14 04:19:13 +08:00
|
|
|
#include <QMenu>
|
2017-03-01 21:09:56 +08:00
|
|
|
|
|
|
|
#include "FloatingDockContainer.h"
|
2017-03-01 23:13:37 +08:00
|
|
|
#include "DockOverlay.h"
|
2017-03-27 16:41:27 +08:00
|
|
|
#include "DockWidget.h"
|
|
|
|
#include "ads_globals.h"
|
|
|
|
#include "DockStateSerialization.h"
|
2017-03-29 04:38:47 +08:00
|
|
|
#include "DockAreaWidget.h"
|
2017-02-27 01:13:56 +08:00
|
|
|
|
2018-10-10 21:15:59 +08:00
|
|
|
#include <QElapsedTimer>
|
|
|
|
#include <iostream>
|
2018-09-14 04:19:13 +08:00
|
|
|
|
2017-02-25 05:44:02 +08:00
|
|
|
namespace ads
|
|
|
|
{
|
2017-02-27 01:13:56 +08:00
|
|
|
/**
|
|
|
|
* Private data class of CDockManager class (pimpl)
|
|
|
|
*/
|
|
|
|
struct DockManagerPrivate
|
|
|
|
{
|
|
|
|
CDockManager* _this;
|
2017-03-01 21:09:56 +08:00
|
|
|
QList<CFloatingDockContainer*> FloatingWidgets;
|
2017-03-01 23:13:37 +08:00
|
|
|
QList<CDockContainerWidget*> Containers;
|
|
|
|
CDockOverlay* ContainerOverlay;
|
|
|
|
CDockOverlay* DockAreaOverlay;
|
2017-03-27 16:41:27 +08:00
|
|
|
QMap<QString, CDockWidget*> DockWidgetsMap;
|
2018-02-13 19:00:58 +08:00
|
|
|
QMap<QString, QByteArray> Perspectives;
|
2018-09-14 04:19:13 +08:00
|
|
|
QMap<QString, QMenu*> ViewMenuGroups;
|
|
|
|
QMenu* ViewMenu;
|
|
|
|
CDockManager::eViewMenuInsertionOrder MenuInsertionOrder = CDockManager::MenuAlphabeticallySorted;
|
2018-09-27 22:21:14 +08:00
|
|
|
bool RestoringState = false;
|
2017-02-27 01:13:56 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Private data constructor
|
|
|
|
*/
|
|
|
|
DockManagerPrivate(CDockManager* _public);
|
2017-03-23 22:57:15 +08:00
|
|
|
|
2017-03-27 16:41:27 +08:00
|
|
|
/**
|
|
|
|
* Checks if the given data stream is a valid docking system state
|
|
|
|
* file.
|
|
|
|
*/
|
|
|
|
bool checkFormat(const QByteArray &state, int version);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restores the state
|
|
|
|
*/
|
2018-09-27 22:21:14 +08:00
|
|
|
bool restoreStateFromXml(const QByteArray &state, int version, bool Testing = internal::Restore);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restore state
|
|
|
|
*/
|
|
|
|
bool restoreState(const QByteArray &state, int version);
|
2017-03-28 16:57:03 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Restores the container with the given index
|
|
|
|
*/
|
2017-12-30 01:18:16 +08:00
|
|
|
bool restoreContainer(int Index, QXmlStreamReader& stream, bool Testing);
|
2017-03-28 19:05:18 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the stylesheet
|
|
|
|
*/
|
|
|
|
void loadStylesheet();
|
2018-09-14 04:19:13 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds action to menu - optionally in sorted order
|
|
|
|
*/
|
|
|
|
void addActionToMenu(QAction* Action, QMenu* Menu, bool InsertSorted);
|
2017-02-27 01:13:56 +08:00
|
|
|
};
|
|
|
|
// struct DockManagerPrivate
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
DockManagerPrivate::DockManagerPrivate(CDockManager* _public) :
|
|
|
|
_this(_public)
|
|
|
|
{
|
2017-02-25 05:44:02 +08:00
|
|
|
|
2017-02-27 01:13:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-28 19:05:18 +08:00
|
|
|
//============================================================================
|
|
|
|
void DockManagerPrivate::loadStylesheet()
|
|
|
|
{
|
|
|
|
QString Result;
|
|
|
|
QFile StyleSheetFile(":ads/stylesheets/default.css");
|
|
|
|
StyleSheetFile.open(QIODevice::ReadOnly);
|
|
|
|
QTextStream StyleSheetStream(&StyleSheetFile);
|
|
|
|
Result = StyleSheetStream.readAll();
|
|
|
|
StyleSheetFile.close();
|
|
|
|
_this->setStyleSheet(Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-27 16:41:27 +08:00
|
|
|
//============================================================================
|
2017-12-30 01:18:16 +08:00
|
|
|
bool DockManagerPrivate::restoreContainer(int Index, QXmlStreamReader& stream, bool Testing)
|
2017-03-27 16:41:27 +08:00
|
|
|
{
|
2017-12-30 01:18:16 +08:00
|
|
|
if (Testing)
|
|
|
|
{
|
|
|
|
Index = 0;
|
|
|
|
}
|
2017-03-27 16:41:27 +08:00
|
|
|
|
2017-03-28 16:57:03 +08:00
|
|
|
if (Index >= Containers.count())
|
|
|
|
{
|
|
|
|
CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(_this);
|
2017-03-29 18:18:49 +08:00
|
|
|
return FloatingWidget->restoreState(stream, Testing);
|
2017-03-28 16:57:03 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-28 18:01:27 +08:00
|
|
|
qDebug() << "d->Containers[i]->restoreState ";
|
2017-03-29 18:18:49 +08:00
|
|
|
return Containers[Index]->restoreState(stream, Testing);
|
2017-03-28 16:57:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-27 16:41:27 +08:00
|
|
|
//============================================================================
|
2017-12-30 01:18:16 +08:00
|
|
|
bool DockManagerPrivate::checkFormat(const QByteArray &state, int version)
|
|
|
|
{
|
2018-09-27 22:21:14 +08:00
|
|
|
return restoreStateFromXml(state, version, internal::RestoreTesting);
|
2017-12-30 01:18:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
2018-09-27 22:21:14 +08:00
|
|
|
bool DockManagerPrivate::restoreStateFromXml(const QByteArray &state, int version,
|
2017-12-30 01:18:16 +08:00
|
|
|
bool Testing)
|
2017-03-27 16:41:27 +08:00
|
|
|
{
|
|
|
|
if (state.isEmpty())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2017-12-30 01:18:16 +08:00
|
|
|
QXmlStreamReader s(state);
|
|
|
|
s.readNextStartElement();
|
|
|
|
if (s.name() != "QtAdvancedDockingSystem")
|
2017-03-27 16:41:27 +08:00
|
|
|
{
|
2017-12-30 01:18:16 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
qDebug() << s.attributes().value("Version");
|
|
|
|
bool ok;
|
|
|
|
int v = s.attributes().value("Version").toInt(&ok);
|
|
|
|
if (!ok || v != version)
|
|
|
|
{
|
|
|
|
return false;
|
2017-03-27 16:41:27 +08:00
|
|
|
}
|
|
|
|
|
2017-12-30 01:18:16 +08:00
|
|
|
bool Result = true;
|
|
|
|
int DockContainers = s.attributes().value("DockContainers").toInt();
|
|
|
|
qDebug() << DockContainers;
|
|
|
|
int DockContainerCount = 0;
|
|
|
|
while (s.readNextStartElement())
|
2017-03-27 16:41:27 +08:00
|
|
|
{
|
2017-12-30 01:18:16 +08:00
|
|
|
if (s.name() == "DockContainerWidget")
|
2017-03-27 16:41:27 +08:00
|
|
|
{
|
2017-12-30 01:18:16 +08:00
|
|
|
Result = restoreContainer(DockContainerCount, s, Testing);
|
|
|
|
if (!Result)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DockContainerCount++;
|
2017-03-27 16:41:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-30 01:18:16 +08:00
|
|
|
if (!Testing)
|
2017-03-27 16:41:27 +08:00
|
|
|
{
|
2017-12-30 01:18:16 +08:00
|
|
|
// Delete remaining empty floating widgets
|
|
|
|
int FloatingWidgetIndex = DockContainerCount - 1;
|
|
|
|
int DeleteCount = FloatingWidgets.count() - FloatingWidgetIndex;
|
|
|
|
for (int i = 0; i < DeleteCount; ++i)
|
|
|
|
{
|
|
|
|
FloatingWidgets[FloatingWidgetIndex + i]->deleteLater();
|
|
|
|
}
|
2017-03-27 16:41:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return Result;
|
2017-03-23 22:57:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-27 22:21:14 +08:00
|
|
|
//============================================================================
|
|
|
|
bool DockManagerPrivate::restoreState(const QByteArray &state, int version)
|
|
|
|
{
|
|
|
|
if (!checkFormat(state, version))
|
|
|
|
{
|
|
|
|
qDebug() << "checkFormat: Error checking format!!!!!!!";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto DockWidget : DockWidgetsMap)
|
|
|
|
{
|
|
|
|
DockWidget->setProperty("dirty", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!restoreStateFromXml(state, version))
|
|
|
|
{
|
|
|
|
qDebug() << "restoreState: Error restoring state!!!!!!!";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// All dock widgets, that have not been processed in the restore state
|
|
|
|
// function are invisible to the user now and have no assigned dock area
|
|
|
|
// They do not belong to any dock container, until the user toggles the
|
|
|
|
// toggle view action the next time
|
|
|
|
for (auto DockWidget : DockWidgetsMap)
|
|
|
|
{
|
|
|
|
if (DockWidget->property("dirty").toBool())
|
|
|
|
{
|
|
|
|
DockWidget->flagAsUnassigned();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DockWidget->toggleViewInternal(!DockWidget->property("closed").toBool());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now all dock areas are properly restored and we setup the index of
|
|
|
|
// The dock areas because the previous toggleView() action has changed
|
|
|
|
// the dock area index
|
|
|
|
for (auto DockContainer : Containers)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < DockContainer->dockAreaCount(); ++i)
|
|
|
|
{
|
|
|
|
CDockAreaWidget* DockArea = DockContainer->dockArea(i);
|
|
|
|
int CurrentIndex = DockArea->property("currentIndex").toInt();
|
|
|
|
int DockWidgetCount = DockArea->dockWidgetsCount();
|
|
|
|
if (CurrentIndex < DockWidgetCount && DockWidgetCount > 1 && CurrentIndex > -1)
|
|
|
|
{
|
|
|
|
auto DockWidget = DockArea->dockWidget(CurrentIndex);
|
|
|
|
if (!DockWidget->isClosed())
|
|
|
|
{
|
|
|
|
DockArea->setCurrentIndex(CurrentIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finally we need to send the topLevelChanged() signals for all dock
|
|
|
|
// widgets if top level changed
|
|
|
|
for (auto DockContainer : Containers)
|
|
|
|
{
|
|
|
|
CDockWidget* TopLevelDockWidget = DockContainer->topLevelDockWidget();
|
|
|
|
if (TopLevelDockWidget)
|
|
|
|
{
|
|
|
|
TopLevelDockWidget->emitTopLevelChanged(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i = 0; i < DockContainer->dockAreaCount(); ++i)
|
|
|
|
{
|
|
|
|
auto DockArea = DockContainer->dockArea(i);
|
|
|
|
for (auto DockWidget : DockArea->dockWidgets())
|
|
|
|
{
|
|
|
|
DockWidget->emitTopLevelChanged(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-14 04:19:13 +08:00
|
|
|
//============================================================================
|
|
|
|
void DockManagerPrivate::addActionToMenu(QAction* Action, QMenu* Menu, bool InsertSorted)
|
|
|
|
{
|
|
|
|
if (InsertSorted)
|
|
|
|
{
|
|
|
|
auto Actions = Menu->actions();
|
|
|
|
auto it = std::find_if(Actions.begin(), Actions.end(),
|
|
|
|
[&Action](const QAction* a)
|
|
|
|
{
|
|
|
|
return a->text().compare(Action->text(), Qt::CaseInsensitive) > 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (it == Actions.end())
|
|
|
|
{
|
|
|
|
Menu->addAction(Action);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Menu->insertAction(*it, Action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Menu->addAction(Action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-02-27 01:13:56 +08:00
|
|
|
//============================================================================
|
|
|
|
CDockManager::CDockManager(QWidget *parent) :
|
|
|
|
CDockContainerWidget(this, parent),
|
|
|
|
d(new DockManagerPrivate(this))
|
|
|
|
{
|
|
|
|
QMainWindow* MainWindow = dynamic_cast<QMainWindow*>(parent);
|
|
|
|
if (MainWindow)
|
|
|
|
{
|
|
|
|
MainWindow->setCentralWidget(this);
|
|
|
|
}
|
2017-03-01 23:13:37 +08:00
|
|
|
|
2018-09-14 04:19:13 +08:00
|
|
|
d->ViewMenu = new QMenu(tr("Show View"), this);
|
2017-03-02 18:43:48 +08:00
|
|
|
d->DockAreaOverlay = new CDockOverlay(this, CDockOverlay::ModeDockAreaOverlay);
|
|
|
|
d->ContainerOverlay = new CDockOverlay(this, CDockOverlay::ModeContainerOverlay);
|
2017-03-01 23:13:37 +08:00
|
|
|
d->Containers.append(this);
|
2017-03-28 19:05:18 +08:00
|
|
|
d->loadStylesheet();
|
2017-02-27 01:13:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockManager::~CDockManager()
|
|
|
|
{
|
2017-03-03 22:47:03 +08:00
|
|
|
auto FloatingWidgets = d->FloatingWidgets;
|
|
|
|
for (auto FloatingWidget : FloatingWidgets)
|
|
|
|
{
|
|
|
|
delete FloatingWidget;
|
|
|
|
}
|
2017-02-27 01:13:56 +08:00
|
|
|
delete d;
|
|
|
|
}
|
2017-03-01 21:09:56 +08:00
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockManager::registerFloatingWidget(CFloatingDockContainer* FloatingWidget)
|
|
|
|
{
|
|
|
|
d->FloatingWidgets.append(FloatingWidget);
|
2017-03-28 18:01:27 +08:00
|
|
|
qDebug() << "d->FloatingWidgets.count() " << d->FloatingWidgets.count();
|
2017-03-01 21:09:56 +08:00
|
|
|
}
|
2017-03-01 23:13:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockManager::removeFloatingWidget(CFloatingDockContainer* FloatingWidget)
|
|
|
|
{
|
|
|
|
d->FloatingWidgets.removeAll(FloatingWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockManager::registerDockContainer(CDockContainerWidget* DockContainer)
|
|
|
|
{
|
|
|
|
d->Containers.append(DockContainer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockManager::removeDockContainer(CDockContainerWidget* DockContainer)
|
|
|
|
{
|
|
|
|
if (this != DockContainer)
|
|
|
|
{
|
|
|
|
d->Containers.removeAll(DockContainer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockOverlay* CDockManager::containerOverlay() const
|
|
|
|
{
|
|
|
|
return d->ContainerOverlay;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockOverlay* CDockManager::dockAreaOverlay() const
|
|
|
|
{
|
|
|
|
return d->DockAreaOverlay;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
const QList<CDockContainerWidget*> CDockManager::dockContainers() const
|
|
|
|
{
|
|
|
|
return d->Containers;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
const QList<CFloatingDockContainer*> CDockManager::floatingWidgets() const
|
|
|
|
{
|
|
|
|
return d->FloatingWidgets;
|
|
|
|
}
|
2017-03-02 22:49:53 +08:00
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
unsigned int CDockManager::zOrderIndex() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-03-23 22:57:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
2018-09-14 04:19:13 +08:00
|
|
|
QByteArray CDockManager::saveState(eXmlMode XmlMode, int version) const
|
2017-03-23 22:57:15 +08:00
|
|
|
{
|
2017-12-30 01:18:16 +08:00
|
|
|
QByteArray xmldata;
|
|
|
|
QXmlStreamWriter s(&xmldata);
|
2018-09-14 04:19:13 +08:00
|
|
|
s.setAutoFormatting(XmlAutoFormattingEnabled == XmlMode);
|
2017-12-30 01:18:16 +08:00
|
|
|
s.writeStartDocument();
|
|
|
|
s.writeStartElement("QtAdvancedDockingSystem");
|
|
|
|
s.writeAttribute("Version", QString::number(version));
|
|
|
|
s.writeAttribute("DockContainers", QString::number(d->Containers.count()));
|
|
|
|
for (auto Container : d->Containers)
|
|
|
|
{
|
|
|
|
Container->saveState(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
s.writeEndElement();
|
|
|
|
s.writeEndDocument();
|
|
|
|
|
|
|
|
return xmldata;
|
2017-03-23 22:57:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
bool CDockManager::restoreState(const QByteArray &state, int version)
|
|
|
|
{
|
2018-10-10 21:15:59 +08:00
|
|
|
QElapsedTimer Timer;
|
|
|
|
Timer.start();
|
|
|
|
|
2018-09-27 22:21:14 +08:00
|
|
|
// Prevent multiple calls as long as state is not restore. This may
|
|
|
|
// happen, if QApplication::processEvents() is called somewhere
|
|
|
|
if (d->RestoringState)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-28 16:57:03 +08:00
|
|
|
|
2018-09-27 22:21:14 +08:00
|
|
|
// We hide the complete dock manager here. Restoring the state means
|
|
|
|
// that DockWidgets are removed from the DockArea internal stack layout
|
|
|
|
// which in turn means, that each time a widget is removed the stack
|
|
|
|
// will show and raise the next available widget which in turn
|
|
|
|
// triggers show events for the dock widgets. To avoid this we hide the
|
|
|
|
// dock manager. Because there will be no processing of application
|
|
|
|
// events until this function is finished, the user will not see this
|
|
|
|
// hiding
|
|
|
|
bool IsVisible = this->isVisibleTo(parentWidget());
|
|
|
|
if (IsVisible)
|
|
|
|
{
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
d->RestoringState = true;
|
|
|
|
emit restoringState();
|
|
|
|
bool Result = d->restoreState(state, version);
|
|
|
|
d->RestoringState = false;
|
|
|
|
emit stateRestored();
|
|
|
|
if (IsVisible)
|
|
|
|
{
|
|
|
|
show();
|
|
|
|
}
|
2018-09-26 15:57:36 +08:00
|
|
|
|
2018-10-10 21:15:59 +08:00
|
|
|
std::cout << "CDockManager::restoreState " << Timer.restart() << std::endl;
|
2018-09-27 22:21:14 +08:00
|
|
|
return Result;
|
2017-03-27 16:41:27 +08:00
|
|
|
}
|
2017-03-23 22:57:15 +08:00
|
|
|
|
|
|
|
|
2017-03-27 16:41:27 +08:00
|
|
|
//============================================================================
|
|
|
|
CDockAreaWidget* CDockManager::addDockWidget(DockWidgetArea area,
|
|
|
|
CDockWidget* Dockwidget, CDockAreaWidget* DockAreaWidget)
|
|
|
|
{
|
|
|
|
d->DockWidgetsMap.insert(Dockwidget->objectName(), Dockwidget);
|
|
|
|
return CDockContainerWidget::addDockWidget(area, Dockwidget, DockAreaWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-07 17:10:14 +08:00
|
|
|
//============================================================================
|
|
|
|
CDockAreaWidget* CDockManager::addDockWidgetTab(DockWidgetArea area,
|
|
|
|
CDockWidget* Dockwidget)
|
|
|
|
{
|
|
|
|
CDockAreaWidget* AreaWidget = lastAddedDockAreaWidget(area);
|
|
|
|
if (AreaWidget)
|
|
|
|
{
|
|
|
|
return addDockWidget(ads::CenterDockWidgetArea, Dockwidget, AreaWidget);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return addDockWidget(area, Dockwidget, AreaWidget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockAreaWidget* CDockManager::addDockWidgetTabToArea(CDockWidget* Dockwidget,
|
|
|
|
CDockAreaWidget* DockAreaWidget)
|
|
|
|
{
|
|
|
|
return addDockWidget(ads::CenterDockWidgetArea, Dockwidget, DockAreaWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-27 16:41:27 +08:00
|
|
|
//============================================================================
|
|
|
|
CDockWidget* CDockManager::findDockWidget(const QString& ObjectName)
|
|
|
|
{
|
|
|
|
return d->DockWidgetsMap.value(ObjectName, nullptr);
|
2017-03-23 22:57:15 +08:00
|
|
|
}
|
2018-02-13 19:00:58 +08:00
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockManager::addPerspective(const QString& UniquePrespectiveName)
|
|
|
|
{
|
|
|
|
d->Perspectives.insert(UniquePrespectiveName, saveState());
|
|
|
|
emit perspectiveListChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
QStringList CDockManager::perspectiveNames() const
|
|
|
|
{
|
|
|
|
return d->Perspectives.keys();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockManager::openPerspective(const QString& PerspectiveName)
|
|
|
|
{
|
|
|
|
const auto Iterator = d->Perspectives.find(PerspectiveName);
|
|
|
|
if (d->Perspectives.end() == Iterator)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-27 22:21:14 +08:00
|
|
|
emit openingPerspective(PerspectiveName);
|
2018-02-13 19:00:58 +08:00
|
|
|
restoreState(Iterator.value());
|
2018-09-27 22:21:14 +08:00
|
|
|
emit perspectiveOpened(PerspectiveName);
|
2018-02-13 19:00:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockManager::savePerspectives(QSettings& Settings) const
|
|
|
|
{
|
|
|
|
Settings.beginWriteArray("Perspectives", d->Perspectives.size());
|
|
|
|
int i = 0;
|
|
|
|
for (auto it = d->Perspectives.constBegin(); it != d->Perspectives.constEnd(); ++it)
|
|
|
|
{
|
|
|
|
Settings.setArrayIndex(i);
|
|
|
|
Settings.setValue("Name", it.key());
|
|
|
|
Settings.setValue("State", it.value());
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
Settings.endArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockManager::loadPerspectives(QSettings& Settings)
|
|
|
|
{
|
|
|
|
d->Perspectives.clear();
|
|
|
|
int Size = Settings.beginReadArray("Perspectives");
|
|
|
|
if (!Size)
|
|
|
|
{
|
|
|
|
Settings.endArray();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < Size; ++i)
|
|
|
|
{
|
|
|
|
Settings.setArrayIndex(i);
|
|
|
|
QString Name = Settings.value("Name").toString();
|
|
|
|
QByteArray Data = Settings.value("State").toByteArray();
|
|
|
|
if (Name.isEmpty() || Data.isEmpty())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->Perspectives.insert(Name, Data);
|
|
|
|
}
|
|
|
|
|
|
|
|
Settings.endArray();
|
|
|
|
}
|
2018-09-14 04:19:13 +08:00
|
|
|
|
|
|
|
//============================================================================
|
2018-09-26 15:57:36 +08:00
|
|
|
QAction* CDockManager::addToggleViewActionToMenu(QAction* ToggleViewAction,
|
2018-09-14 04:19:13 +08:00
|
|
|
const QString& Group, const QIcon& GroupIcon)
|
|
|
|
{
|
|
|
|
bool AlphabeticallySorted = (MenuAlphabeticallySorted == d->MenuInsertionOrder);
|
|
|
|
if (!Group.isEmpty())
|
|
|
|
{
|
|
|
|
QMenu* GroupMenu = d->ViewMenuGroups.value(Group, 0);
|
|
|
|
if (!GroupMenu)
|
|
|
|
{
|
|
|
|
GroupMenu = new QMenu(Group, this);
|
|
|
|
GroupMenu->setIcon(GroupIcon);
|
|
|
|
d->addActionToMenu(GroupMenu->menuAction(), d->ViewMenu, AlphabeticallySorted);
|
|
|
|
d->ViewMenuGroups.insert(Group, GroupMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
d->addActionToMenu(ToggleViewAction, GroupMenu, AlphabeticallySorted);
|
2018-09-26 15:57:36 +08:00
|
|
|
return GroupMenu->menuAction();
|
2018-09-14 04:19:13 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d->addActionToMenu(ToggleViewAction, d->ViewMenu, AlphabeticallySorted);
|
2018-09-26 15:57:36 +08:00
|
|
|
return ToggleViewAction;
|
2018-09-14 04:19:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
QMenu* CDockManager::viewMenu() const
|
|
|
|
{
|
|
|
|
return d->ViewMenu;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockManager::setViewMenuInsertionOrder(eViewMenuInsertionOrder Order)
|
|
|
|
{
|
|
|
|
d->MenuInsertionOrder = Order;
|
|
|
|
}
|
|
|
|
|
2018-10-10 21:15:59 +08:00
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
bool CDockManager::isRestoringState() const
|
|
|
|
{
|
|
|
|
return d->RestoringState;
|
|
|
|
}
|
|
|
|
|
2017-02-25 05:44:02 +08:00
|
|
|
} // namespace ads
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// EOF DockManager.cpp
|