2017-03-23 17:23:53 +08:00
|
|
|
/*******************************************************************************
|
2017-06-10 04:04:02 +08:00
|
|
|
** Qt Advanced Docking System
|
2017-03-23 17:23:53 +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-03-23 17:23:53 +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-03-23 17:23:53 +08:00
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
/// \file DockWidget.cpp
|
|
|
|
/// \author Uwe Kindler
|
|
|
|
/// \date 26.02.2017
|
|
|
|
/// \brief Implementation of CDockWidget class
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// INCLUDES
|
|
|
|
//============================================================================
|
2018-08-24 19:41:58 +08:00
|
|
|
#include <DockWidgetTab.h>
|
2017-03-23 17:23:53 +08:00
|
|
|
#include "DockWidget.h"
|
|
|
|
|
|
|
|
#include <QBoxLayout>
|
|
|
|
#include <QAction>
|
|
|
|
#include <QSplitter>
|
|
|
|
#include <QStack>
|
2018-09-12 19:52:10 +08:00
|
|
|
#include <QScrollArea>
|
2017-03-23 17:23:53 +08:00
|
|
|
#include <QTextStream>
|
|
|
|
#include <QPointer>
|
2017-03-28 16:57:03 +08:00
|
|
|
#include <QEvent>
|
2017-03-28 18:01:27 +08:00
|
|
|
#include <QDebug>
|
2018-09-12 19:52:10 +08:00
|
|
|
#include <QToolBar>
|
2017-12-30 01:18:16 +08:00
|
|
|
#include <QXmlStreamWriter>
|
2017-03-23 17:23:53 +08:00
|
|
|
|
|
|
|
#include "DockContainerWidget.h"
|
|
|
|
#include "DockAreaWidget.h"
|
|
|
|
#include "DockManager.h"
|
|
|
|
#include "FloatingDockContainer.h"
|
2017-03-27 16:41:27 +08:00
|
|
|
#include "DockStateSerialization.h"
|
2017-03-29 21:43:18 +08:00
|
|
|
#include "DockSplitter.h"
|
2017-03-23 17:23:53 +08:00
|
|
|
#include "ads_globals.h"
|
|
|
|
|
2018-09-07 18:38:11 +08:00
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
namespace ads
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Private data class of CDockWidget class (pimpl)
|
|
|
|
*/
|
|
|
|
struct DockWidgetPrivate
|
|
|
|
{
|
|
|
|
CDockWidget* _this;
|
|
|
|
QBoxLayout* Layout;
|
|
|
|
QWidget* Widget = nullptr;
|
2018-09-07 17:10:14 +08:00
|
|
|
CDockWidgetTab* TabWidget;
|
2017-03-23 17:23:53 +08:00
|
|
|
CDockWidget::DockWidgetFeatures Features = CDockWidget::AllDockWidgetFeatures;
|
|
|
|
CDockManager* DockManager = nullptr;
|
|
|
|
CDockAreaWidget* DockArea = nullptr;
|
|
|
|
QAction* ToggleViewAction;
|
|
|
|
bool Closed = false;
|
2018-09-12 19:52:10 +08:00
|
|
|
CDockWidget::LayoutFlags LayoutFlags;
|
|
|
|
QScrollArea* ScrollArea = nullptr;
|
|
|
|
QToolBar* ToolBar = nullptr;
|
|
|
|
Qt::ToolButtonStyle ToolBarStyleDocked = Qt::ToolButtonIconOnly;
|
|
|
|
Qt::ToolButtonStyle ToolBarStyleFloating = Qt::ToolButtonTextUnderIcon;
|
|
|
|
QSize ToolBarIconSizeDocked = QSize(16, 16);
|
|
|
|
QSize ToolBarIconSizeFloating = QSize(24, 24);
|
2018-09-26 15:57:36 +08:00
|
|
|
bool IsFloatingTopLevel = false;
|
2017-03-23 17:23:53 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Private data constructor
|
|
|
|
*/
|
|
|
|
DockWidgetPrivate(CDockWidget* _public);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show dock widget
|
|
|
|
*/
|
|
|
|
void showDockWidget();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide dock widget.
|
|
|
|
*/
|
|
|
|
void hideDockWidget();
|
|
|
|
|
|
|
|
/**
|
2018-09-07 17:10:14 +08:00
|
|
|
* Hides a dock area if all dock widgets in the area are closed.
|
|
|
|
* This function updates the current selected tab and hides the parent
|
|
|
|
* dock area if it is empty
|
2017-03-23 17:23:53 +08:00
|
|
|
*/
|
2018-09-07 17:10:14 +08:00
|
|
|
void updateParentDockArea();
|
2017-03-23 17:23:53 +08:00
|
|
|
|
2018-09-12 19:52:10 +08:00
|
|
|
/**
|
|
|
|
* Setup the top tool bar
|
|
|
|
*/
|
|
|
|
void setupToolBar();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup the main scroll area
|
|
|
|
*/
|
|
|
|
void setupScrollArea();
|
2017-03-23 17:23:53 +08:00
|
|
|
};
|
|
|
|
// struct DockWidgetPrivate
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
DockWidgetPrivate::DockWidgetPrivate(CDockWidget* _public) :
|
|
|
|
_this(_public)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void DockWidgetPrivate::showDockWidget()
|
|
|
|
{
|
2017-03-28 16:57:03 +08:00
|
|
|
if (!DockArea)
|
2017-03-23 17:23:53 +08:00
|
|
|
{
|
2017-03-28 16:57:03 +08:00
|
|
|
CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(_this);
|
|
|
|
FloatingWidget->resize(_this->size());
|
|
|
|
FloatingWidget->show();
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
2017-03-28 16:57:03 +08:00
|
|
|
else
|
2017-03-23 17:23:53 +08:00
|
|
|
{
|
2017-03-28 16:57:03 +08:00
|
|
|
DockArea->show();
|
2018-09-07 18:38:11 +08:00
|
|
|
DockArea->setCurrentDockWidget(_this);
|
2018-10-12 17:51:35 +08:00
|
|
|
TabWidget->show();
|
2017-03-28 16:57:03 +08:00
|
|
|
QSplitter* Splitter = internal::findParent<QSplitter*>(_this);
|
2017-03-29 21:43:18 +08:00
|
|
|
while (Splitter && !Splitter->isVisible())
|
2017-03-28 16:57:03 +08:00
|
|
|
{
|
|
|
|
Splitter->show();
|
2017-03-29 21:43:18 +08:00
|
|
|
Splitter = internal::findParent<QSplitter*>(Splitter);
|
2017-03-28 16:57:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CDockContainerWidget* Container = DockArea->dockContainer();
|
|
|
|
if (Container->isFloating())
|
|
|
|
{
|
|
|
|
CFloatingDockContainer* FloatingWidget = internal::findParent<
|
|
|
|
CFloatingDockContainer*>(Container);
|
|
|
|
FloatingWidget->show();
|
|
|
|
}
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void DockWidgetPrivate::hideDockWidget()
|
|
|
|
{
|
2018-09-07 17:10:14 +08:00
|
|
|
TabWidget->hide();
|
|
|
|
updateParentDockArea();
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
2018-09-07 17:10:14 +08:00
|
|
|
void DockWidgetPrivate::updateParentDockArea()
|
2017-03-23 17:23:53 +08:00
|
|
|
{
|
2018-09-26 15:57:36 +08:00
|
|
|
if (!DockArea)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-07 17:10:14 +08:00
|
|
|
auto NextDockWidget = DockArea->nextOpenDockWidget(_this);
|
|
|
|
if (NextDockWidget)
|
2017-03-23 17:23:53 +08:00
|
|
|
{
|
|
|
|
DockArea->setCurrentDockWidget(NextDockWidget);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-14 14:46:10 +08:00
|
|
|
DockArea->hideAreaWithNoVisibleContent();
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
2018-09-12 19:52:10 +08:00
|
|
|
void DockWidgetPrivate::setupToolBar()
|
|
|
|
{
|
|
|
|
if (!LayoutFlags.testFlag(CDockWidget::WithTopToolBar))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ToolBar = new QToolBar(_this);
|
|
|
|
ToolBar->setObjectName("dockWidgetToolBar");
|
|
|
|
Layout->addWidget(ToolBar);
|
|
|
|
ToolBar->setIconSize(QSize(16, 16));
|
|
|
|
ToolBar->toggleViewAction()->setEnabled(false);
|
|
|
|
ToolBar->toggleViewAction()->setVisible(false);
|
|
|
|
_this->connect(_this, SIGNAL(topLevelChanged(bool)), SLOT(setToolbarFloatingStyle(bool)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void DockWidgetPrivate::setupScrollArea()
|
|
|
|
{
|
|
|
|
if (!LayoutFlags.testFlag(CDockWidget::WithScrollArea))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScrollArea = new QScrollArea(_this);
|
|
|
|
ScrollArea->setObjectName("dockWidgetScrollArea");
|
|
|
|
ScrollArea->setWidgetResizable(true);
|
|
|
|
Layout->addWidget(ScrollArea);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockWidget::CDockWidget(const QString &title, QWidget *parent,
|
|
|
|
LayoutFlags layoutFlags) :
|
2017-03-23 17:23:53 +08:00
|
|
|
QFrame(parent),
|
|
|
|
d(new DockWidgetPrivate(this))
|
|
|
|
{
|
2018-09-12 19:52:10 +08:00
|
|
|
d->LayoutFlags = layoutFlags;
|
2017-03-23 17:23:53 +08:00
|
|
|
d->Layout = new QBoxLayout(QBoxLayout::TopToBottom);
|
|
|
|
d->Layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
d->Layout->setSpacing(0);
|
|
|
|
setLayout(d->Layout);
|
|
|
|
setWindowTitle(title);
|
2018-08-29 14:47:05 +08:00
|
|
|
setObjectName(title);
|
2018-09-12 19:52:10 +08:00
|
|
|
d->setupToolBar();
|
|
|
|
d->setupScrollArea();
|
2017-03-23 17:23:53 +08:00
|
|
|
|
2018-09-07 17:10:14 +08:00
|
|
|
d->TabWidget = new CDockWidgetTab(this);
|
2017-03-23 17:23:53 +08:00
|
|
|
d->ToggleViewAction = new QAction(title);
|
|
|
|
d->ToggleViewAction->setCheckable(true);
|
|
|
|
connect(d->ToggleViewAction, SIGNAL(triggered(bool)), this,
|
|
|
|
SLOT(toggleView(bool)));
|
2018-09-12 19:52:10 +08:00
|
|
|
setToolbarFloatingStyle(false);
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockWidget::~CDockWidget()
|
|
|
|
{
|
2017-03-28 18:01:27 +08:00
|
|
|
qDebug() << "~CDockWidget()";
|
2017-03-23 17:23:53 +08:00
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockWidget::setToggleViewActionChecked(bool Checked)
|
|
|
|
{
|
|
|
|
QAction* Action = d->ToggleViewAction;
|
|
|
|
Action->blockSignals(true);
|
|
|
|
Action->setChecked(Checked);
|
|
|
|
Action->blockSignals(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockWidget::setWidget(QWidget* widget)
|
|
|
|
{
|
2018-09-12 19:52:10 +08:00
|
|
|
if (d->LayoutFlags.testFlag(WithScrollArea))
|
|
|
|
{
|
|
|
|
d->ScrollArea->setWidget(widget);
|
|
|
|
}
|
|
|
|
else if (d->Widget)
|
2017-03-23 17:23:53 +08:00
|
|
|
{
|
|
|
|
d->Layout->replaceWidget(d->Widget, widget);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d->Layout->addWidget(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
d->Widget = widget;
|
2018-09-12 19:52:10 +08:00
|
|
|
d->Widget->setProperty("dockWidgetContent", true);
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
QWidget* CDockWidget::widget() const
|
|
|
|
{
|
|
|
|
return d->Widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
2018-09-07 17:10:14 +08:00
|
|
|
CDockWidgetTab* CDockWidget::tabWidget() const
|
2017-03-23 17:23:53 +08:00
|
|
|
{
|
2018-09-07 17:10:14 +08:00
|
|
|
return d->TabWidget;
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockWidget::setFeatures(DockWidgetFeatures features)
|
|
|
|
{
|
|
|
|
d->Features = features;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-24 19:41:58 +08:00
|
|
|
//============================================================================
|
|
|
|
void CDockWidget::setFeature(DockWidgetFeature flag, bool on)
|
|
|
|
{
|
|
|
|
d->Features.setFlag(flag, on);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
//============================================================================
|
|
|
|
CDockWidget::DockWidgetFeatures CDockWidget::features() const
|
|
|
|
{
|
|
|
|
return d->Features;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockManager* CDockWidget::dockManager() const
|
|
|
|
{
|
|
|
|
return d->DockManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockWidget::setDockManager(CDockManager* DockManager)
|
|
|
|
{
|
|
|
|
d->DockManager = DockManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockContainerWidget* CDockWidget::dockContainer() const
|
|
|
|
{
|
2018-10-11 20:15:27 +08:00
|
|
|
if (d->DockArea)
|
|
|
|
{
|
|
|
|
return d->DockArea->dockContainer();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockAreaWidget* CDockWidget::dockAreaWidget() const
|
|
|
|
{
|
2018-09-14 19:21:29 +08:00
|
|
|
return d->DockArea;
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
bool CDockWidget::isFloating() const
|
|
|
|
{
|
2018-09-07 17:10:14 +08:00
|
|
|
if (!isInFloatingContainer())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-26 15:57:36 +08:00
|
|
|
return dockContainer()->topLevelDockWidget() == this;
|
2018-09-07 17:10:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
bool CDockWidget::isInFloatingContainer() const
|
|
|
|
{
|
2018-09-14 19:21:29 +08:00
|
|
|
auto Container = dockContainer();
|
|
|
|
if (!Container)
|
2018-09-07 17:10:14 +08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-14 19:21:29 +08:00
|
|
|
if (!Container->isFloating())
|
2018-09-07 17:10:14 +08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
bool CDockWidget::isClosed() const
|
|
|
|
{
|
|
|
|
return d->Closed;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
QAction* CDockWidget::toggleViewAction() const
|
|
|
|
{
|
|
|
|
return d->ToggleViewAction;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-02 15:01:23 +08:00
|
|
|
//============================================================================
|
|
|
|
void CDockWidget::setToggleViewActionMode(eToggleViewActionMode Mode)
|
|
|
|
{
|
|
|
|
if (ActionModeToggle == Mode)
|
|
|
|
{
|
|
|
|
d->ToggleViewAction->setCheckable(true);
|
|
|
|
d->ToggleViewAction->setIcon(QIcon());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d->ToggleViewAction->setCheckable(false);
|
2018-09-07 17:10:14 +08:00
|
|
|
d->ToggleViewAction->setIcon(d->TabWidget->icon());
|
2018-01-02 15:01:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
//============================================================================
|
|
|
|
void CDockWidget::toggleView(bool Open)
|
|
|
|
{
|
2018-09-26 15:57:36 +08:00
|
|
|
// If the toggle view action mode is ActionModeShow, then Open is always
|
|
|
|
// true if the sender is the toggle view action
|
2018-01-02 15:01:23 +08:00
|
|
|
QAction* Sender = qobject_cast<QAction*>(sender());
|
2018-09-26 15:57:36 +08:00
|
|
|
if (Sender == d->ToggleViewAction && !d->ToggleViewAction->isCheckable())
|
|
|
|
{
|
|
|
|
Open = true;
|
|
|
|
}
|
|
|
|
// If the dock widget state is different, then we really need to toggle
|
|
|
|
// the state. If we are in the right state, then we simply make this
|
|
|
|
// dock widget the current dock widget
|
|
|
|
if (d->Closed != !Open)
|
2018-09-14 19:21:29 +08:00
|
|
|
{
|
2018-09-26 15:57:36 +08:00
|
|
|
toggleViewInternal(Open);
|
2018-09-14 19:21:29 +08:00
|
|
|
}
|
2018-09-26 15:57:36 +08:00
|
|
|
else if (Open && d->DockArea)
|
|
|
|
{
|
|
|
|
d->DockArea->setCurrentDockWidget(this);
|
|
|
|
}
|
|
|
|
}
|
2018-09-14 19:21:29 +08:00
|
|
|
|
2018-09-26 15:57:36 +08:00
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockWidget::toggleViewInternal(bool Open)
|
|
|
|
{
|
|
|
|
CDockContainerWidget* DockContainer = dockContainer();
|
2018-10-11 20:15:27 +08:00
|
|
|
CDockWidget* TopLevelDockWidget = nullptr;
|
2018-09-26 15:57:36 +08:00
|
|
|
|
2018-10-11 20:15:27 +08:00
|
|
|
if (Open && DockContainer)
|
2018-01-02 15:01:23 +08:00
|
|
|
{
|
2018-09-26 15:57:36 +08:00
|
|
|
TopLevelDockWidget = DockContainer->topLevelDockWidget();
|
2018-01-02 15:01:23 +08:00
|
|
|
}
|
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
if (Open)
|
|
|
|
{
|
|
|
|
d->showDockWidget();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d->hideDockWidget();
|
|
|
|
}
|
|
|
|
d->Closed = !Open;
|
2017-03-29 21:43:18 +08:00
|
|
|
d->ToggleViewAction->blockSignals(true);
|
|
|
|
d->ToggleViewAction->setChecked(Open);
|
|
|
|
d->ToggleViewAction->blockSignals(false);
|
2018-09-26 15:57:36 +08:00
|
|
|
if (d->DockArea)
|
|
|
|
{
|
|
|
|
d->DockArea->toggleDockWidgetView(this, Open);
|
|
|
|
}
|
2018-09-07 17:10:14 +08:00
|
|
|
|
2018-10-11 20:15:27 +08:00
|
|
|
if (!Open && DockContainer)
|
2018-09-14 19:21:29 +08:00
|
|
|
{
|
2018-09-26 15:57:36 +08:00
|
|
|
TopLevelDockWidget = DockContainer->topLevelDockWidget();
|
2018-09-14 19:21:29 +08:00
|
|
|
}
|
|
|
|
|
2018-09-26 15:57:36 +08:00
|
|
|
if (TopLevelDockWidget)
|
2018-09-14 19:21:29 +08:00
|
|
|
{
|
2018-09-26 15:57:36 +08:00
|
|
|
CDockWidget::emitTopLevelEventForWidget(TopLevelDockWidget, !Open);
|
2018-09-14 19:21:29 +08:00
|
|
|
}
|
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
if (!Open)
|
|
|
|
{
|
|
|
|
emit closed();
|
|
|
|
}
|
|
|
|
emit viewToggled(Open);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockWidget::setDockArea(CDockAreaWidget* DockArea)
|
|
|
|
{
|
|
|
|
d->DockArea = DockArea;
|
2018-09-07 18:38:11 +08:00
|
|
|
d->ToggleViewAction->setChecked(DockArea != nullptr && !this->isClosed());
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-23 22:57:15 +08:00
|
|
|
//============================================================================
|
2017-12-30 01:18:16 +08:00
|
|
|
void CDockWidget::saveState(QXmlStreamWriter& s) const
|
2017-03-23 22:57:15 +08:00
|
|
|
{
|
2017-12-30 01:18:16 +08:00
|
|
|
s.writeStartElement("DockWidget");
|
|
|
|
s.writeAttribute("ObjectName", objectName());
|
|
|
|
s.writeAttribute("Closed", QString::number(d->Closed ? 1 : 0));
|
|
|
|
s.writeEndElement();
|
2017-03-23 22:57:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-28 16:57:03 +08:00
|
|
|
//============================================================================
|
|
|
|
void CDockWidget::flagAsUnassigned()
|
|
|
|
{
|
2018-09-26 15:57:36 +08:00
|
|
|
d->Closed = true;
|
2017-03-28 16:57:03 +08:00
|
|
|
setParent(d->DockManager);
|
2018-10-11 20:15:27 +08:00
|
|
|
setVisible(false);
|
2017-03-28 16:57:03 +08:00
|
|
|
setDockArea(nullptr);
|
2018-09-07 17:10:14 +08:00
|
|
|
tabWidget()->setParent(this);
|
2017-03-28 16:57:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
bool CDockWidget::event(QEvent *e)
|
|
|
|
{
|
|
|
|
if (e->type() == QEvent::WindowTitleChange)
|
|
|
|
{
|
|
|
|
emit titleChanged(windowTitle());
|
|
|
|
}
|
|
|
|
return QFrame::event(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-02 15:01:23 +08:00
|
|
|
//============================================================================
|
|
|
|
void CDockWidget::setIcon(const QIcon& Icon)
|
|
|
|
{
|
2018-09-07 17:10:14 +08:00
|
|
|
d->TabWidget->setIcon(Icon);
|
2018-01-02 15:01:23 +08:00
|
|
|
if (!d->ToggleViewAction->isCheckable())
|
|
|
|
{
|
|
|
|
d->ToggleViewAction->setIcon(Icon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-27 21:40:01 +08:00
|
|
|
//============================================================================
|
|
|
|
QIcon CDockWidget::icon() const
|
|
|
|
{
|
2018-09-07 17:10:14 +08:00
|
|
|
return d->TabWidget->icon();
|
2018-08-27 21:40:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-12 19:52:10 +08:00
|
|
|
//============================================================================
|
|
|
|
QToolBar* CDockWidget::toolBar() const
|
|
|
|
{
|
|
|
|
return d->ToolBar;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockWidget::setToolBar(QToolBar* ToolBar)
|
|
|
|
{
|
|
|
|
if (d->ToolBar)
|
|
|
|
{
|
|
|
|
delete d->ToolBar;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->ToolBar = ToolBar;
|
|
|
|
d->Layout->insertWidget(0, d->ToolBar);
|
|
|
|
this->connect(this, SIGNAL(topLevelChanged(bool)), SLOT(setToolbarFloatingStyle(bool)));
|
|
|
|
setToolbarFloatingStyle(isFloating());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockWidget::setToolBarStyle(Qt::ToolButtonStyle Style, eState State)
|
|
|
|
{
|
|
|
|
if (StateFloating == State)
|
|
|
|
{
|
|
|
|
d->ToolBarStyleFloating = Style;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d->ToolBarStyleDocked = Style;
|
|
|
|
}
|
|
|
|
|
|
|
|
setToolbarFloatingStyle(isFloating());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
Qt::ToolButtonStyle CDockWidget::toolBarStyle(eState State) const
|
|
|
|
{
|
|
|
|
if (StateFloating == State)
|
|
|
|
{
|
|
|
|
return d->ToolBarStyleFloating;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return d->ToolBarStyleDocked;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockWidget::setToolBarIconSize(const QSize& IconSize, eState State)
|
|
|
|
{
|
|
|
|
if (StateFloating == State)
|
|
|
|
{
|
|
|
|
d->ToolBarIconSizeFloating = IconSize;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d->ToolBarIconSizeDocked = IconSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
setToolbarFloatingStyle(isFloating());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
QSize CDockWidget::toolBarIconSize(eState State) const
|
|
|
|
{
|
|
|
|
if (StateFloating == State)
|
|
|
|
{
|
|
|
|
return d->ToolBarIconSizeFloating;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return d->ToolBarIconSizeDocked;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockWidget::setToolbarFloatingStyle(bool Floating)
|
|
|
|
{
|
|
|
|
if (!d->ToolBar)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto IconSize = Floating ? d->ToolBarIconSizeFloating : d->ToolBarIconSizeDocked;
|
|
|
|
if (IconSize != d->ToolBar->iconSize())
|
|
|
|
{
|
|
|
|
d->ToolBar->setIconSize(IconSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto ButtonStyle = Floating ? d->ToolBarStyleFloating : d->ToolBarStyleDocked;
|
|
|
|
if (ButtonStyle != d->ToolBar->toolButtonStyle())
|
|
|
|
{
|
|
|
|
d->ToolBar->setToolButtonStyle(ButtonStyle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-28 16:57:03 +08:00
|
|
|
|
2018-09-26 15:57:36 +08:00
|
|
|
//============================================================================
|
|
|
|
void CDockWidget::emitTopLevelEventForWidget(CDockWidget* TopLevelDockWidget, bool Floating)
|
|
|
|
{
|
|
|
|
if (TopLevelDockWidget)
|
|
|
|
{
|
|
|
|
TopLevelDockWidget->dockAreaWidget()->updateTabBarVisibility();
|
|
|
|
TopLevelDockWidget->emitTopLevelChanged(Floating);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockWidget::emitTopLevelChanged(bool Floating)
|
|
|
|
{
|
|
|
|
if (Floating != d->IsFloatingTopLevel)
|
|
|
|
{
|
|
|
|
d->IsFloatingTopLevel = Floating;
|
|
|
|
emit topLevelChanged(d->IsFloatingTopLevel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockWidget::setClosedState(bool Closed)
|
|
|
|
{
|
|
|
|
d->Closed = Closed;
|
|
|
|
}
|
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
} // namespace ads
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// EOF DockWidget.cpp
|