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
|
2019-01-16 00:24:11 +08:00
|
|
|
**
|
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.
|
2019-01-16 00:24:11 +08:00
|
|
|
**
|
2017-06-10 04:04:02 +08:00
|
|
|
** 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.
|
2019-01-16 00:24:11 +08:00
|
|
|
**
|
2017-06-10 04:04:02 +08:00
|
|
|
** 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 DockAreaWidget.cpp
|
|
|
|
/// \author Uwe Kindler
|
|
|
|
/// \date 24.02.2017
|
|
|
|
/// \brief Implementation of CDockAreaWidget class
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// INCLUDES
|
|
|
|
//============================================================================
|
|
|
|
#include "DockAreaWidget.h"
|
|
|
|
|
|
|
|
#include <QStackedLayout>
|
|
|
|
#include <QScrollBar>
|
|
|
|
#include <QScrollArea>
|
|
|
|
#include <QWheelEvent>
|
|
|
|
#include <QStyle>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QSplitter>
|
2017-12-30 01:18:16 +08:00
|
|
|
#include <QXmlStreamWriter>
|
2018-09-07 17:10:14 +08:00
|
|
|
#include <QVector>
|
2018-10-10 21:15:59 +08:00
|
|
|
#include <QList>
|
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
|
|
|
|
#include "DockContainerWidget.h"
|
|
|
|
#include "DockWidget.h"
|
|
|
|
#include "FloatingDockContainer.h"
|
|
|
|
#include "DockManager.h"
|
|
|
|
#include "DockOverlay.h"
|
2018-08-24 19:41:58 +08:00
|
|
|
#include "DockAreaTabBar.h"
|
2018-09-14 14:46:10 +08:00
|
|
|
#include "DockSplitter.h"
|
2018-10-12 20:51:57 +08:00
|
|
|
#include "DockAreaTitleBar.h"
|
2020-02-11 15:32:49 +08:00
|
|
|
#include "DockComponentsFactory.h"
|
|
|
|
#include "DockWidgetTab.h"
|
2018-11-08 19:22:15 +08:00
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
|
|
|
|
namespace ads
|
|
|
|
{
|
|
|
|
static const char* const INDEX_PROPERTY = "index";
|
|
|
|
static const char* const ACTION_PROPERTY = "action";
|
|
|
|
|
2018-10-10 21:15:59 +08:00
|
|
|
/**
|
2019-08-26 13:58:56 +08:00
|
|
|
* Internal dock area layout mimics stack layout but only inserts the current
|
|
|
|
* widget into the internal QLayout object.
|
|
|
|
* \warning Only the current widget has a parent. All other widgets
|
|
|
|
* do not have a parent. That means, a widget that is in this layout may
|
|
|
|
* return nullptr for its parent() function if it is not the current widget.
|
2018-10-10 21:15:59 +08:00
|
|
|
*/
|
|
|
|
class CDockAreaLayout
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
QBoxLayout* m_ParentLayout;
|
|
|
|
QList<QWidget*> m_Widgets;
|
|
|
|
int m_CurrentIndex = -1;
|
|
|
|
QWidget* m_CurrentWidget = nullptr;
|
|
|
|
|
|
|
|
public:
|
2018-11-05 16:07:18 +08:00
|
|
|
/**
|
|
|
|
* Creates an instance with the given parent layout
|
|
|
|
*/
|
2018-10-10 21:15:59 +08:00
|
|
|
CDockAreaLayout(QBoxLayout* ParentLayout)
|
|
|
|
: m_ParentLayout(ParentLayout)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-08-20 18:56:37 +08:00
|
|
|
/**
|
|
|
|
* Delete widgets without parents in this layout
|
|
|
|
*/
|
|
|
|
~CDockAreaLayout()
|
|
|
|
{
|
|
|
|
for(auto Widget : m_Widgets)
|
|
|
|
{
|
|
|
|
if(!Widget->parent())
|
|
|
|
delete Widget;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-05 16:07:18 +08:00
|
|
|
/**
|
|
|
|
* Returns the number of widgets in this layout
|
|
|
|
*/
|
2018-10-10 21:15:59 +08:00
|
|
|
int count() const
|
|
|
|
{
|
|
|
|
return m_Widgets.count();
|
|
|
|
}
|
|
|
|
|
2018-11-05 16:07:18 +08:00
|
|
|
/**
|
|
|
|
* Inserts the widget at the given index position into the internal widget
|
|
|
|
* list
|
|
|
|
*/
|
2018-10-10 21:15:59 +08:00
|
|
|
void insertWidget(int index, QWidget* Widget)
|
|
|
|
{
|
2019-01-26 00:28:36 +08:00
|
|
|
Widget->setParent(nullptr);
|
2018-10-10 21:15:59 +08:00
|
|
|
if (index < 0)
|
|
|
|
{
|
|
|
|
index = m_Widgets.count();
|
|
|
|
}
|
|
|
|
m_Widgets.insert(index, Widget);
|
|
|
|
if (m_CurrentIndex < 0)
|
|
|
|
{
|
|
|
|
setCurrentIndex(index);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (index <= m_CurrentIndex )
|
|
|
|
{
|
|
|
|
++m_CurrentIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-05 16:07:18 +08:00
|
|
|
/**
|
2019-08-26 13:58:56 +08:00
|
|
|
* Removes the given widget from the layout
|
2018-11-05 16:07:18 +08:00
|
|
|
*/
|
2018-10-10 21:15:59 +08:00
|
|
|
void removeWidget(QWidget* Widget)
|
|
|
|
{
|
|
|
|
if (currentWidget() == Widget)
|
|
|
|
{
|
|
|
|
auto LayoutItem = m_ParentLayout->takeAt(1);
|
|
|
|
if (LayoutItem)
|
|
|
|
{
|
2019-01-26 00:28:36 +08:00
|
|
|
LayoutItem->widget()->setParent(nullptr);
|
2018-10-10 21:15:59 +08:00
|
|
|
}
|
2018-10-12 17:51:35 +08:00
|
|
|
m_CurrentWidget = nullptr;
|
|
|
|
m_CurrentIndex = -1;
|
2018-10-10 21:15:59 +08:00
|
|
|
}
|
2020-06-14 22:12:56 +08:00
|
|
|
else if (indexOf(Widget) < m_CurrentIndex)
|
|
|
|
{
|
|
|
|
--m_CurrentIndex;
|
|
|
|
}
|
2018-10-10 21:15:59 +08:00
|
|
|
m_Widgets.removeOne(Widget);
|
|
|
|
}
|
|
|
|
|
2018-11-05 16:07:18 +08:00
|
|
|
/**
|
|
|
|
* Returns the current selected widget
|
|
|
|
*/
|
2018-10-10 21:15:59 +08:00
|
|
|
QWidget* currentWidget() const
|
|
|
|
{
|
|
|
|
return m_CurrentWidget;
|
|
|
|
}
|
|
|
|
|
2018-11-05 16:07:18 +08:00
|
|
|
/**
|
|
|
|
* Activates the widget with the give index.
|
|
|
|
*/
|
2018-10-10 21:15:59 +08:00
|
|
|
void setCurrentIndex(int index)
|
|
|
|
{
|
|
|
|
QWidget *prev = currentWidget();
|
|
|
|
QWidget *next = widget(index);
|
|
|
|
if (!next || (next == prev && !m_CurrentWidget))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool reenableUpdates = false;
|
|
|
|
QWidget *parent = m_ParentLayout->parentWidget();
|
|
|
|
|
|
|
|
if (parent && parent->updatesEnabled())
|
|
|
|
{
|
|
|
|
reenableUpdates = true;
|
|
|
|
parent->setUpdatesEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto LayoutItem = m_ParentLayout->takeAt(1);
|
|
|
|
if (LayoutItem)
|
|
|
|
{
|
2019-01-26 00:28:36 +08:00
|
|
|
LayoutItem->widget()->setParent(nullptr);
|
2018-10-10 21:15:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
m_ParentLayout->addWidget(next);
|
|
|
|
if (prev)
|
|
|
|
{
|
|
|
|
prev->hide();
|
|
|
|
}
|
|
|
|
m_CurrentIndex = index;
|
|
|
|
m_CurrentWidget = next;
|
|
|
|
|
|
|
|
|
|
|
|
if (reenableUpdates)
|
|
|
|
{
|
|
|
|
parent->setUpdatesEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-05 16:07:18 +08:00
|
|
|
/**
|
|
|
|
* Returns the index of the current active widget
|
|
|
|
*/
|
2018-10-10 21:15:59 +08:00
|
|
|
int currentIndex() const
|
|
|
|
{
|
|
|
|
return m_CurrentIndex;
|
|
|
|
}
|
|
|
|
|
2018-11-05 16:07:18 +08:00
|
|
|
/**
|
|
|
|
* Returns true if there are no widgets in the layout
|
|
|
|
*/
|
2018-10-10 21:15:59 +08:00
|
|
|
bool isEmpty() const
|
|
|
|
{
|
|
|
|
return m_Widgets.empty();
|
|
|
|
}
|
|
|
|
|
2018-11-05 16:07:18 +08:00
|
|
|
/**
|
|
|
|
* Returns the index of the given widget
|
|
|
|
*/
|
2018-10-10 21:15:59 +08:00
|
|
|
int indexOf(QWidget* w) const
|
|
|
|
{
|
|
|
|
return m_Widgets.indexOf(w);
|
|
|
|
}
|
|
|
|
|
2018-11-05 16:07:18 +08:00
|
|
|
/**
|
|
|
|
* Returns the widget for the given index
|
|
|
|
*/
|
2018-10-10 21:15:59 +08:00
|
|
|
QWidget* widget(int index) const
|
|
|
|
{
|
|
|
|
return (index < m_Widgets.size()) ? m_Widgets.at(index) : nullptr;
|
|
|
|
}
|
|
|
|
|
2018-11-05 16:07:18 +08:00
|
|
|
/**
|
|
|
|
* Returns the geometry of the current active widget
|
|
|
|
*/
|
2018-10-10 21:15:59 +08:00
|
|
|
QRect geometry() const
|
|
|
|
{
|
|
|
|
return m_Widgets.empty() ? QRect() : currentWidget()->geometry();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using DockAreaLayout = CDockAreaLayout;
|
2020-08-18 05:50:37 +08:00
|
|
|
static constexpr DockWidgetAreas DefaultAllowedAreas = AllDockAreas;
|
2018-10-10 21:15:59 +08:00
|
|
|
|
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
/**
|
|
|
|
* Private data class of CDockAreaWidget class (pimpl)
|
|
|
|
*/
|
|
|
|
struct DockAreaWidgetPrivate
|
|
|
|
{
|
2019-01-23 14:43:07 +08:00
|
|
|
CDockAreaWidget* _this = nullptr;
|
|
|
|
QBoxLayout* Layout = nullptr;
|
|
|
|
DockAreaLayout* ContentsLayout = nullptr;
|
|
|
|
CDockAreaTitleBar* TitleBar = nullptr;
|
|
|
|
CDockManager* DockManager = nullptr;
|
2019-07-11 21:12:39 +08:00
|
|
|
bool UpdateTitleBarButtons = false;
|
2020-08-18 05:50:37 +08:00
|
|
|
DockWidgetAreas AllowedAreas = DefaultAllowedAreas;
|
2020-03-29 02:32:07 +08:00
|
|
|
QSize MinSizeHint;
|
2020-08-18 16:48:35 +08:00
|
|
|
CDockAreaWidget::DockAreaFlags Flags{CDockAreaWidget::DefaultFlags};
|
2017-03-23 17:23:53 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Private data constructor
|
|
|
|
*/
|
|
|
|
DockAreaWidgetPrivate(CDockAreaWidget* _public);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the layout for top area with tabs and close button
|
|
|
|
*/
|
2018-10-12 20:51:57 +08:00
|
|
|
void createTitleBar();
|
2017-03-23 17:23:53 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the dock widget with the given index
|
|
|
|
*/
|
|
|
|
CDockWidget* dockWidgetAt(int index)
|
|
|
|
{
|
2020-02-14 01:56:04 +08:00
|
|
|
return qobject_cast<CDockWidget*>(ContentsLayout->widget(index));
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience function to ease title widget access by index
|
|
|
|
*/
|
2018-09-07 18:56:20 +08:00
|
|
|
CDockWidgetTab* tabWidgetAt(int index)
|
2017-03-23 17:23:53 +08:00
|
|
|
{
|
2018-09-07 17:10:14 +08:00
|
|
|
return dockWidgetAt(index)->tabWidget();
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the tab action of the given dock widget
|
|
|
|
*/
|
|
|
|
QAction* dockWidgetTabAction(CDockWidget* DockWidget) const
|
|
|
|
{
|
|
|
|
return qvariant_cast<QAction*>(DockWidget->property(ACTION_PROPERTY));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the index of the given dock widget
|
|
|
|
*/
|
|
|
|
int dockWidgetIndex(CDockWidget* DockWidget) const
|
|
|
|
{
|
|
|
|
return DockWidget->property(INDEX_PROPERTY).toInt();
|
|
|
|
}
|
|
|
|
|
2018-10-12 20:51:57 +08:00
|
|
|
/**
|
|
|
|
* Convenience function for tabbar access
|
|
|
|
*/
|
|
|
|
CDockAreaTabBar* tabBar() const
|
|
|
|
{
|
|
|
|
return TitleBar->tabBar();
|
|
|
|
}
|
2018-11-08 19:22:15 +08:00
|
|
|
|
|
|
|
/**
|
2019-07-11 21:12:39 +08:00
|
|
|
* Udpates the enable state of the close and detach button
|
2018-11-08 19:22:15 +08:00
|
|
|
*/
|
2019-07-11 21:12:39 +08:00
|
|
|
void updateTitleBarButtonStates();
|
2020-03-29 02:32:07 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Scans all contained dock widgets for the max. minimum size hint
|
|
|
|
*/
|
|
|
|
void updateMinimumSizeHint()
|
|
|
|
{
|
|
|
|
MinSizeHint = QSize();
|
|
|
|
for (int i = 0; i < ContentsLayout->count(); ++i)
|
|
|
|
{
|
|
|
|
auto Widget = ContentsLayout->widget(i);
|
|
|
|
MinSizeHint.setHeight(qMax(MinSizeHint.height(), Widget->minimumSizeHint().height()));
|
|
|
|
MinSizeHint.setWidth(qMax(MinSizeHint.width(), Widget->minimumSizeHint().width()));
|
|
|
|
}
|
|
|
|
}
|
2017-03-23 17:23:53 +08:00
|
|
|
};
|
|
|
|
// struct DockAreaWidgetPrivate
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
DockAreaWidgetPrivate::DockAreaWidgetPrivate(CDockAreaWidget* _public) :
|
|
|
|
_this(_public)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
2018-10-12 20:51:57 +08:00
|
|
|
void DockAreaWidgetPrivate::createTitleBar()
|
2017-03-23 17:23:53 +08:00
|
|
|
{
|
2020-02-11 15:32:49 +08:00
|
|
|
TitleBar = componentsFactory()->createDockAreaTitleBar(_this);
|
2017-03-23 17:23:53 +08:00
|
|
|
Layout->addWidget(TitleBar);
|
2019-01-26 00:28:36 +08:00
|
|
|
QObject::connect(tabBar(), &CDockAreaTabBar::tabCloseRequested, _this, &CDockAreaWidget::onTabCloseRequested);
|
|
|
|
QObject::connect(TitleBar, &CDockAreaTitleBar::tabBarClicked, _this, &CDockAreaWidget::setCurrentIndex);
|
|
|
|
QObject::connect(tabBar(), &CDockAreaTabBar::tabMoved, _this, &CDockAreaWidget::reorderDockWidget);
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-08 19:22:15 +08:00
|
|
|
//============================================================================
|
2019-07-11 21:12:39 +08:00
|
|
|
void DockAreaWidgetPrivate::updateTitleBarButtonStates()
|
2018-11-08 19:22:15 +08:00
|
|
|
{
|
|
|
|
if (_this->isHidden())
|
|
|
|
{
|
2019-07-11 21:12:39 +08:00
|
|
|
UpdateTitleBarButtons = true;
|
2018-11-08 19:22:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TitleBar->button(TitleBarButtonClose)->setEnabled(
|
|
|
|
_this->features().testFlag(CDockWidget::DockWidgetClosable));
|
2019-07-11 21:12:39 +08:00
|
|
|
TitleBar->button(TitleBarButtonUndock)->setEnabled(
|
|
|
|
_this->features().testFlag(CDockWidget::DockWidgetFloatable));
|
2020-02-06 16:15:13 +08:00
|
|
|
TitleBar->updateDockWidgetActionsButtons();
|
2019-07-11 21:12:39 +08:00
|
|
|
UpdateTitleBarButtons = false;
|
2018-11-08 19:22:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
//============================================================================
|
|
|
|
CDockAreaWidget::CDockAreaWidget(CDockManager* DockManager, CDockContainerWidget* parent) :
|
|
|
|
QFrame(parent),
|
|
|
|
d(new DockAreaWidgetPrivate(this))
|
|
|
|
{
|
|
|
|
d->DockManager = DockManager;
|
|
|
|
d->Layout = new QBoxLayout(QBoxLayout::TopToBottom);
|
|
|
|
d->Layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
d->Layout->setSpacing(0);
|
|
|
|
setLayout(d->Layout);
|
|
|
|
|
2018-10-12 20:51:57 +08:00
|
|
|
d->createTitleBar();
|
2018-10-10 21:15:59 +08:00
|
|
|
d->ContentsLayout = new DockAreaLayout(d->Layout);
|
2019-11-23 04:53:17 +08:00
|
|
|
if (d->DockManager)
|
|
|
|
{
|
|
|
|
emit d->DockManager->dockAreaCreated(this);
|
|
|
|
}
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockAreaWidget::~CDockAreaWidget()
|
|
|
|
{
|
2019-07-21 15:53:24 +08:00
|
|
|
ADS_PRINT("~CDockAreaWidget()");
|
2018-10-10 21:15:59 +08:00
|
|
|
delete d->ContentsLayout;
|
2017-03-23 17:23:53 +08:00
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockManager* CDockAreaWidget::dockManager() const
|
|
|
|
{
|
|
|
|
return d->DockManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockContainerWidget* CDockAreaWidget::dockContainer() const
|
|
|
|
{
|
2018-10-10 21:15:59 +08:00
|
|
|
return internal::findParent<CDockContainerWidget*>(this);
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockAreaWidget::addDockWidget(CDockWidget* DockWidget)
|
|
|
|
{
|
|
|
|
insertDockWidget(d->ContentsLayout->count(), DockWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget,
|
|
|
|
bool Activate)
|
|
|
|
{
|
|
|
|
d->ContentsLayout->insertWidget(index, DockWidget);
|
2020-05-14 15:06:04 +08:00
|
|
|
DockWidget->setDockArea(this);
|
2020-02-15 05:56:48 +08:00
|
|
|
DockWidget->tabWidget()->setDockAreaWidget(this);
|
2018-09-07 17:10:14 +08:00
|
|
|
auto TabWidget = DockWidget->tabWidget();
|
2018-11-04 03:51:02 +08:00
|
|
|
// Inserting the tab will change the current index which in turn will
|
|
|
|
// make the tab widget visible in the slot
|
|
|
|
d->tabBar()->blockSignals(true);
|
2018-10-12 20:51:57 +08:00
|
|
|
d->tabBar()->insertTab(index, TabWidget);
|
2018-11-04 03:51:02 +08:00
|
|
|
d->tabBar()->blockSignals(false);
|
2018-09-07 18:38:11 +08:00
|
|
|
TabWidget->setVisible(!DockWidget->isClosed());
|
2017-03-23 17:23:53 +08:00
|
|
|
DockWidget->setProperty(INDEX_PROPERTY, index);
|
2020-03-29 02:32:07 +08:00
|
|
|
d->MinSizeHint.setHeight(qMax(d->MinSizeHint.height(), DockWidget->minimumSizeHint().height()));
|
|
|
|
d->MinSizeHint.setWidth(qMax(d->MinSizeHint.width(), DockWidget->minimumSizeHint().width()));
|
2017-03-23 17:23:53 +08:00
|
|
|
if (Activate)
|
|
|
|
{
|
|
|
|
setCurrentIndex(index);
|
|
|
|
}
|
2020-05-20 02:26:57 +08:00
|
|
|
// If this dock area is hidden, then we need to make it visible again
|
|
|
|
// by calling DockWidget->toggleViewInternal(true);
|
|
|
|
if (!this->isVisible() && d->ContentsLayout->count() > 1 && !dockManager()->isRestoringState())
|
|
|
|
{
|
|
|
|
DockWidget->toggleViewInternal(true);
|
|
|
|
}
|
2019-07-11 21:12:39 +08:00
|
|
|
d->updateTitleBarButtonStates();
|
2020-08-20 22:36:02 +08:00
|
|
|
updateTitleBarVisibility();
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
|
|
|
|
{
|
2019-07-21 15:53:24 +08:00
|
|
|
ADS_PRINT("CDockAreaWidget::removeDockWidget");
|
2020-07-07 20:38:03 +08:00
|
|
|
auto CurrentDockWidget = currentDockWidget();
|
|
|
|
auto NextOpenDockWidget = (DockWidget == CurrentDockWidget) ? nextOpenDockWidget(DockWidget) : nullptr;
|
2018-09-07 17:10:14 +08:00
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
d->ContentsLayout->removeWidget(DockWidget);
|
2018-09-14 19:21:29 +08:00
|
|
|
auto TabWidget = DockWidget->tabWidget();
|
|
|
|
TabWidget->hide();
|
2018-10-12 20:51:57 +08:00
|
|
|
d->tabBar()->removeTab(TabWidget);
|
2020-06-30 22:34:59 +08:00
|
|
|
TabWidget->setParent(DockWidget);
|
2020-06-30 04:11:37 +08:00
|
|
|
DockWidget->setDockArea(nullptr);
|
2019-05-15 20:47:58 +08:00
|
|
|
CDockContainerWidget* DockContainer = dockContainer();
|
2018-09-14 19:21:29 +08:00
|
|
|
if (NextOpenDockWidget)
|
2018-09-07 17:10:14 +08:00
|
|
|
{
|
2018-09-14 19:21:29 +08:00
|
|
|
setCurrentDockWidget(NextOpenDockWidget);
|
2018-09-07 17:10:14 +08:00
|
|
|
}
|
2020-05-20 02:26:57 +08:00
|
|
|
else if (d->ContentsLayout->isEmpty() && DockContainer->dockAreaCount() >= 1)
|
2017-03-23 17:23:53 +08:00
|
|
|
{
|
2019-07-21 15:53:24 +08:00
|
|
|
ADS_PRINT("Dock Area empty");
|
2019-05-15 20:47:58 +08:00
|
|
|
DockContainer->removeDockArea(this);
|
2018-09-14 19:21:29 +08:00
|
|
|
this->deleteLater();
|
2020-08-20 18:58:15 +08:00
|
|
|
if(DockContainer->dockAreaCount() == 0)
|
|
|
|
{
|
|
|
|
if(CFloatingDockContainer* FloatingDockContainer = DockContainer->floatingWidget())
|
|
|
|
{
|
|
|
|
FloatingDockContainer->hide();
|
|
|
|
FloatingDockContainer->deleteLater();
|
|
|
|
}
|
|
|
|
}
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
2020-07-07 20:38:03 +08:00
|
|
|
else if (DockWidget == CurrentDockWidget)
|
2018-09-14 14:46:10 +08:00
|
|
|
{
|
|
|
|
// if contents layout is not empty but there are no more open dock
|
|
|
|
// widgets, then we need to hide the dock area because it does not
|
|
|
|
// contain any visible content
|
|
|
|
hideAreaWithNoVisibleContent();
|
|
|
|
}
|
2017-03-23 17:23:53 +08:00
|
|
|
|
2019-07-11 21:12:39 +08:00
|
|
|
d->updateTitleBarButtonStates();
|
2018-11-05 16:07:18 +08:00
|
|
|
updateTitleBarVisibility();
|
2020-03-29 02:32:07 +08:00
|
|
|
d->updateMinimumSizeHint();
|
2019-05-15 20:47:58 +08:00
|
|
|
auto TopLevelDockWidget = DockContainer->topLevelDockWidget();
|
2018-11-02 16:19:53 +08:00
|
|
|
if (TopLevelDockWidget)
|
|
|
|
{
|
|
|
|
TopLevelDockWidget->emitTopLevelChanged(true);
|
|
|
|
}
|
2018-09-14 19:21:29 +08:00
|
|
|
|
|
|
|
#if (ADS_DEBUG_LEVEL > 0)
|
2017-03-28 14:48:44 +08:00
|
|
|
DockContainer->dumpLayout();
|
2018-09-14 19:21:29 +08:00
|
|
|
#endif
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-14 14:46:10 +08:00
|
|
|
//============================================================================
|
|
|
|
void CDockAreaWidget::hideAreaWithNoVisibleContent()
|
|
|
|
{
|
2018-11-01 14:53:54 +08:00
|
|
|
this->toggleView(false);
|
2018-09-14 14:46:10 +08:00
|
|
|
|
2018-12-03 19:52:57 +08:00
|
|
|
// Hide empty parent splitters
|
2018-09-14 14:46:10 +08:00
|
|
|
auto Splitter = internal::findParent<CDockSplitter*>(this);
|
2018-12-03 19:52:57 +08:00
|
|
|
internal::hideEmptyParentSplitters(Splitter);
|
2018-09-14 14:46:10 +08:00
|
|
|
|
|
|
|
//Hide empty floating widget
|
|
|
|
CDockContainerWidget* Container = this->dockContainer();
|
2020-04-12 07:05:20 +08:00
|
|
|
if (!Container->isFloating() && !CDockManager::testConfigFlag(CDockManager::HideSingleCentralWidgetTitleBar))
|
2018-11-04 03:51:02 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-05 16:07:18 +08:00
|
|
|
updateTitleBarVisibility();
|
2018-11-04 03:51:02 +08:00
|
|
|
auto TopLevelWidget = Container->topLevelDockWidget();
|
|
|
|
auto FloatingWidget = Container->floatingWidget();
|
|
|
|
if (TopLevelWidget)
|
|
|
|
{
|
2020-04-12 07:05:20 +08:00
|
|
|
if (FloatingWidget)
|
|
|
|
{
|
|
|
|
FloatingWidget->updateWindowTitle();
|
|
|
|
}
|
2018-11-04 03:51:02 +08:00
|
|
|
CDockWidget::emitTopLevelEventForWidget(TopLevelWidget, true);
|
|
|
|
}
|
2020-04-12 07:05:20 +08:00
|
|
|
else if (Container->openedDockAreas().isEmpty() && FloatingWidget)
|
2018-09-14 14:46:10 +08:00
|
|
|
{
|
|
|
|
FloatingWidget->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
//============================================================================
|
2018-10-12 20:51:57 +08:00
|
|
|
void CDockAreaWidget::onTabCloseRequested(int Index)
|
2017-03-23 17:23:53 +08:00
|
|
|
{
|
2019-07-21 15:53:24 +08:00
|
|
|
ADS_PRINT("CDockAreaWidget::onTabCloseRequested " << Index);
|
2019-12-10 21:44:44 +08:00
|
|
|
auto* DockWidget = dockWidget(Index);
|
|
|
|
if (DockWidget->features().testFlag(CDockWidget::DockWidgetDeleteOnClose))
|
|
|
|
{
|
2020-01-06 18:42:36 +08:00
|
|
|
DockWidget->closeDockWidgetInternal();
|
2019-12-10 21:44:44 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DockWidget->toggleView(false);
|
|
|
|
}
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockWidget* CDockAreaWidget::currentDockWidget() const
|
|
|
|
{
|
2018-11-04 03:51:02 +08:00
|
|
|
int CurrentIndex = currentIndex();
|
|
|
|
if (CurrentIndex < 0)
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dockWidget(CurrentIndex);
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockAreaWidget::setCurrentDockWidget(CDockWidget* DockWidget)
|
|
|
|
{
|
2018-11-01 15:52:14 +08:00
|
|
|
if (dockManager()->isRestoringState())
|
2017-03-23 17:23:53 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2018-10-11 19:07:27 +08:00
|
|
|
|
2018-11-01 15:52:14 +08:00
|
|
|
internalSetCurrentDockWidget(DockWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockAreaWidget::internalSetCurrentDockWidget(CDockWidget* DockWidget)
|
|
|
|
{
|
|
|
|
int Index = index(DockWidget);
|
|
|
|
if (Index < 0)
|
2018-10-11 19:07:27 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
setCurrentIndex(Index);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockAreaWidget::setCurrentIndex(int index)
|
|
|
|
{
|
2018-10-12 20:51:57 +08:00
|
|
|
auto TabBar = d->tabBar();
|
|
|
|
if (index < 0 || index > (TabBar->count() - 1))
|
2017-03-23 17:23:53 +08:00
|
|
|
{
|
|
|
|
qWarning() << Q_FUNC_INFO << "Invalid index" << index;
|
|
|
|
return;
|
2018-08-10 19:48:20 +08:00
|
|
|
}
|
|
|
|
|
2020-01-15 14:49:22 +08:00
|
|
|
auto cw = d->ContentsLayout->currentWidget();
|
|
|
|
auto nw = d->ContentsLayout->widget(index);
|
|
|
|
if (cw == nw && !nw->isHidden())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-10 19:48:20 +08:00
|
|
|
emit currentChanging(index);
|
2018-10-12 20:51:57 +08:00
|
|
|
TabBar->setCurrentIndex(index);
|
2018-10-11 19:07:27 +08:00
|
|
|
d->ContentsLayout->setCurrentIndex(index);
|
|
|
|
d->ContentsLayout->currentWidget()->show();
|
2017-03-23 17:23:53 +08:00
|
|
|
emit currentChanged(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
int CDockAreaWidget::currentIndex() const
|
|
|
|
{
|
|
|
|
return d->ContentsLayout->currentIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
2018-10-12 20:51:57 +08:00
|
|
|
QRect CDockAreaWidget::titleBarGeometry() const
|
2017-03-23 17:23:53 +08:00
|
|
|
{
|
2018-10-12 20:51:57 +08:00
|
|
|
return d->TitleBar->geometry();
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
QRect CDockAreaWidget::contentAreaGeometry() const
|
|
|
|
{
|
|
|
|
return d->ContentsLayout->geometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
2018-09-07 18:38:11 +08:00
|
|
|
int CDockAreaWidget::index(CDockWidget* DockWidget)
|
2017-03-23 17:23:53 +08:00
|
|
|
{
|
|
|
|
return d->ContentsLayout->indexOf(DockWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
QList<CDockWidget*> CDockAreaWidget::dockWidgets() const
|
|
|
|
{
|
|
|
|
QList<CDockWidget*> DockWidgetList;
|
|
|
|
for (int i = 0; i < d->ContentsLayout->count(); ++i)
|
|
|
|
{
|
|
|
|
DockWidgetList.append(dockWidget(i));
|
|
|
|
}
|
|
|
|
return DockWidgetList;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-14 14:46:10 +08:00
|
|
|
//============================================================================
|
|
|
|
int CDockAreaWidget::openDockWidgetsCount() const
|
|
|
|
{
|
|
|
|
int Count = 0;
|
|
|
|
for (int i = 0; i < d->ContentsLayout->count(); ++i)
|
|
|
|
{
|
|
|
|
if (!dockWidget(i)->isClosed())
|
|
|
|
{
|
|
|
|
++Count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
//============================================================================
|
|
|
|
QList<CDockWidget*> CDockAreaWidget::openedDockWidgets() const
|
|
|
|
{
|
|
|
|
QList<CDockWidget*> DockWidgetList;
|
|
|
|
for (int i = 0; i < d->ContentsLayout->count(); ++i)
|
|
|
|
{
|
|
|
|
CDockWidget* DockWidget = dockWidget(i);
|
|
|
|
if (!DockWidget->isClosed())
|
|
|
|
{
|
|
|
|
DockWidgetList.append(dockWidget(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return DockWidgetList;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-07 20:50:43 +08:00
|
|
|
//============================================================================
|
|
|
|
int CDockAreaWidget::indexOfFirstOpenDockWidget() const
|
|
|
|
{
|
|
|
|
for (int i = 0; i < d->ContentsLayout->count(); ++i)
|
|
|
|
{
|
|
|
|
if (!dockWidget(i)->isClosed())
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
//============================================================================
|
2018-09-14 14:46:10 +08:00
|
|
|
int CDockAreaWidget::dockWidgetsCount() const
|
2017-03-23 17:23:53 +08:00
|
|
|
{
|
|
|
|
return d->ContentsLayout->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockWidget* CDockAreaWidget::dockWidget(int Index) const
|
|
|
|
{
|
2018-11-04 03:51:02 +08:00
|
|
|
return qobject_cast<CDockWidget*>(d->ContentsLayout->widget(Index));
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockAreaWidget::reorderDockWidget(int fromIndex, int toIndex)
|
|
|
|
{
|
2019-07-21 15:53:24 +08:00
|
|
|
ADS_PRINT("CDockAreaWidget::reorderDockWidget");
|
2017-03-23 17:23:53 +08:00
|
|
|
if (fromIndex >= d->ContentsLayout->count() || fromIndex < 0
|
|
|
|
|| toIndex >= d->ContentsLayout->count() || toIndex < 0 || fromIndex == toIndex)
|
|
|
|
{
|
2019-07-21 15:53:24 +08:00
|
|
|
ADS_PRINT("Invalid index for tab movement" << fromIndex << toIndex);
|
2017-03-23 17:23:53 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-10 21:15:59 +08:00
|
|
|
auto Widget = d->ContentsLayout->widget(fromIndex);
|
|
|
|
d->ContentsLayout->removeWidget(Widget);
|
|
|
|
d->ContentsLayout->insertWidget(toIndex, Widget);
|
2018-10-12 16:41:19 +08:00
|
|
|
setCurrentIndex(toIndex);
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-07 17:10:14 +08:00
|
|
|
//============================================================================
|
|
|
|
void CDockAreaWidget::toggleDockWidgetView(CDockWidget* DockWidget, bool Open)
|
|
|
|
{
|
|
|
|
Q_UNUSED(DockWidget);
|
|
|
|
Q_UNUSED(Open);
|
2018-11-05 16:07:18 +08:00
|
|
|
updateTitleBarVisibility();
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
2018-11-05 16:07:18 +08:00
|
|
|
void CDockAreaWidget::updateTitleBarVisibility()
|
2017-03-23 17:23:53 +08:00
|
|
|
{
|
2018-11-05 16:07:18 +08:00
|
|
|
CDockContainerWidget* Container = dockContainer();
|
|
|
|
if (!Container)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-11 14:06:37 +08:00
|
|
|
if (CDockManager::testConfigFlag(CDockManager::AlwaysShowTabs))
|
2020-01-31 21:27:01 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-23 14:43:07 +08:00
|
|
|
if (d->TitleBar)
|
|
|
|
{
|
2020-04-12 07:05:20 +08:00
|
|
|
bool Hidden = Container->hasTopLevelDockWidget() && (Container->isFloating()
|
2020-06-11 14:06:37 +08:00
|
|
|
|| CDockManager::testConfigFlag(CDockManager::HideSingleCentralWidgetTitleBar));
|
2020-08-18 16:48:35 +08:00
|
|
|
Hidden |= (d->Flags.testFlag(HideSingleWidgetTitleBar) && openDockWidgetsCount() == 1);
|
2020-04-12 07:05:20 +08:00
|
|
|
d->TitleBar->setVisible(!Hidden);
|
2019-01-23 14:43:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockAreaWidget::markTitleBarMenuOutdated()
|
|
|
|
{
|
|
|
|
if (d->TitleBar)
|
|
|
|
{
|
|
|
|
d->TitleBar->markTabsMenuOutdated();
|
|
|
|
}
|
2017-03-23 17:23:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-23 14:43:07 +08:00
|
|
|
|
2017-03-23 22:57:15 +08:00
|
|
|
//============================================================================
|
2017-12-30 01:18:16 +08:00
|
|
|
void CDockAreaWidget::saveState(QXmlStreamWriter& s) const
|
2017-03-23 22:57:15 +08:00
|
|
|
{
|
2018-12-11 22:19:59 +08:00
|
|
|
s.writeStartElement("Area");
|
2017-12-30 01:18:16 +08:00
|
|
|
s.writeAttribute("Tabs", QString::number(d->ContentsLayout->count()));
|
2018-11-04 03:51:02 +08:00
|
|
|
auto CurrentDockWidget = currentDockWidget();
|
|
|
|
QString Name = CurrentDockWidget ? CurrentDockWidget->objectName() : "";
|
2018-12-11 22:19:59 +08:00
|
|
|
s.writeAttribute("Current", Name);
|
2020-08-18 16:48:35 +08:00
|
|
|
// To keep the saved XML data small, we only save the allowed areas and the
|
|
|
|
// dock area flags if the values are different from the default values
|
|
|
|
if (d->AllowedAreas != DefaultAllowedAreas)
|
2020-08-18 05:50:37 +08:00
|
|
|
{
|
2020-08-18 16:48:35 +08:00
|
|
|
s.writeAttribute("AllowedAreas", QString::number(d->AllowedAreas, 16));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->Flags != DefaultFlags)
|
|
|
|
{
|
|
|
|
s.writeAttribute("Flags", QString::number(d->Flags, 16));
|
2020-08-18 05:50:37 +08:00
|
|
|
}
|
2019-07-21 15:53:24 +08:00
|
|
|
ADS_PRINT("CDockAreaWidget::saveState TabCount: " << d->ContentsLayout->count()
|
|
|
|
<< " Current: " << Name);
|
2017-03-23 22:57:15 +08:00
|
|
|
for (int i = 0; i < d->ContentsLayout->count(); ++i)
|
|
|
|
{
|
2017-12-30 01:18:16 +08:00
|
|
|
dockWidget(i)->saveState(s);
|
2017-03-23 22:57:15 +08:00
|
|
|
}
|
2017-12-30 01:18:16 +08:00
|
|
|
s.writeEndElement();
|
2017-03-23 22:57:15 +08:00
|
|
|
}
|
|
|
|
|
2018-09-07 17:10:14 +08:00
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockWidget* CDockAreaWidget::nextOpenDockWidget(CDockWidget* DockWidget) const
|
|
|
|
{
|
|
|
|
auto OpenDockWidgets = openedDockWidgets();
|
2018-09-26 15:57:36 +08:00
|
|
|
if (OpenDockWidgets.count() > 1 || (OpenDockWidgets.count() == 1 && OpenDockWidgets[0] != DockWidget))
|
2018-09-07 17:10:14 +08:00
|
|
|
{
|
|
|
|
CDockWidget* NextDockWidget;
|
|
|
|
if (OpenDockWidgets.last() == DockWidget)
|
|
|
|
{
|
|
|
|
NextDockWidget = OpenDockWidgets[OpenDockWidgets.count() - 2];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int NextIndex = OpenDockWidgets.indexOf(DockWidget) + 1;
|
|
|
|
NextDockWidget = OpenDockWidgets[NextIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NextDockWidget;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-12 21:18:05 +08:00
|
|
|
|
|
|
|
//============================================================================
|
2020-01-06 18:42:36 +08:00
|
|
|
CDockWidget::DockWidgetFeatures CDockAreaWidget::features(eBitwiseOperator Mode) const
|
2018-10-12 21:18:05 +08:00
|
|
|
{
|
2020-01-06 18:42:36 +08:00
|
|
|
if (BitwiseAnd == Mode)
|
2018-10-12 21:18:05 +08:00
|
|
|
{
|
2020-01-06 18:42:36 +08:00
|
|
|
CDockWidget::DockWidgetFeatures Features(CDockWidget::AllDockWidgetFeatures);
|
|
|
|
for (const auto DockWidget : dockWidgets())
|
|
|
|
{
|
|
|
|
Features &= DockWidget->features();
|
|
|
|
}
|
|
|
|
return Features;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CDockWidget::DockWidgetFeatures Features(CDockWidget::NoDockWidgetFeatures);
|
|
|
|
for (const auto DockWidget : dockWidgets())
|
|
|
|
{
|
|
|
|
Features |= DockWidget->features();
|
|
|
|
}
|
|
|
|
return Features;
|
2018-10-12 21:18:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-15 14:29:30 +08:00
|
|
|
|
|
|
|
//============================================================================
|
2018-11-01 14:53:54 +08:00
|
|
|
void CDockAreaWidget::toggleView(bool Open)
|
2018-10-15 14:29:30 +08:00
|
|
|
{
|
2018-11-01 14:53:54 +08:00
|
|
|
setVisible(Open);
|
2018-11-08 19:22:15 +08:00
|
|
|
|
2018-11-01 14:53:54 +08:00
|
|
|
emit viewToggled(Open);
|
2018-10-15 14:29:30 +08:00
|
|
|
}
|
2018-11-04 03:51:02 +08:00
|
|
|
|
|
|
|
|
2018-11-08 19:22:15 +08:00
|
|
|
//============================================================================
|
|
|
|
void CDockAreaWidget::setVisible(bool Visible)
|
|
|
|
{
|
|
|
|
Super::setVisible(Visible);
|
2019-07-11 21:12:39 +08:00
|
|
|
if (d->UpdateTitleBarButtons)
|
2018-11-09 17:07:56 +08:00
|
|
|
{
|
2019-07-11 21:12:39 +08:00
|
|
|
d->updateTitleBarButtonStates();
|
2018-11-09 17:07:56 +08:00
|
|
|
}
|
2018-11-08 19:22:15 +08:00
|
|
|
}
|
|
|
|
|
2020-07-19 04:15:10 +08:00
|
|
|
|
|
|
|
//============================================================================
|
2020-02-02 22:56:31 +08:00
|
|
|
void CDockAreaWidget::setAllowedAreas(DockWidgetAreas areas)
|
|
|
|
{
|
|
|
|
d->AllowedAreas = areas;
|
|
|
|
}
|
|
|
|
|
2020-07-19 04:15:10 +08:00
|
|
|
|
|
|
|
//============================================================================
|
2020-02-02 22:56:31 +08:00
|
|
|
DockWidgetAreas CDockAreaWidget::allowedAreas() const
|
|
|
|
{
|
|
|
|
return d->AllowedAreas;
|
|
|
|
}
|
2018-11-08 19:22:15 +08:00
|
|
|
|
2020-08-18 16:48:35 +08:00
|
|
|
|
2020-07-19 04:15:10 +08:00
|
|
|
//============================================================================
|
2020-08-18 16:48:35 +08:00
|
|
|
CDockAreaWidget::DockAreaFlags CDockAreaWidget::dockAreaFlags() const
|
2020-07-19 04:15:10 +08:00
|
|
|
{
|
2020-08-18 16:48:35 +08:00
|
|
|
return d->Flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockAreaWidget::setDockAreaFlags(DockAreaFlags Flags)
|
|
|
|
{
|
|
|
|
auto ChangedFlags = d->Flags ^ Flags;
|
|
|
|
d->Flags = Flags;
|
|
|
|
if (ChangedFlags.testFlag(HideSingleWidgetTitleBar))
|
|
|
|
{
|
|
|
|
updateTitleBarVisibility();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockAreaWidget::setDockAreaFlag(eDockAreaFlag Flag, bool On)
|
|
|
|
{
|
|
|
|
auto flags = dockAreaFlags();
|
|
|
|
internal::setFlag(flags, Flag, On);
|
|
|
|
setDockAreaFlags(flags);
|
2020-07-19 04:15:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-04 03:51:02 +08:00
|
|
|
//============================================================================
|
|
|
|
QAbstractButton* CDockAreaWidget::titleBarButton(TitleBarButton which) const
|
|
|
|
{
|
|
|
|
return d->TitleBar->button(which);
|
|
|
|
}
|
2018-11-08 17:04:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockAreaWidget::closeArea()
|
|
|
|
{
|
2019-12-11 23:06:07 +08:00
|
|
|
// If there is only one single dock widget and this widget has the
|
|
|
|
// DeleteOnClose feature, then we delete the dock widget now
|
|
|
|
auto OpenDockWidgets = openedDockWidgets();
|
|
|
|
if (OpenDockWidgets.count() == 1 && OpenDockWidgets[0]->features().testFlag(CDockWidget::DockWidgetDeleteOnClose))
|
|
|
|
{
|
2020-01-06 18:42:36 +08:00
|
|
|
OpenDockWidgets[0]->closeDockWidgetInternal();
|
2019-12-11 23:06:07 +08:00
|
|
|
}
|
|
|
|
else
|
2018-11-08 17:04:29 +08:00
|
|
|
{
|
2019-12-11 23:06:07 +08:00
|
|
|
for (auto DockWidget : openedDockWidgets())
|
|
|
|
{
|
|
|
|
DockWidget->toggleView(false);
|
|
|
|
}
|
2018-11-08 17:04:29 +08:00
|
|
|
}
|
|
|
|
}
|
2018-12-20 22:29:38 +08:00
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockAreaWidget::closeOtherAreas()
|
|
|
|
{
|
|
|
|
dockContainer()->closeOtherAreas(this);
|
|
|
|
}
|
2020-02-07 21:29:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockAreaTitleBar* CDockAreaWidget::titleBar() const
|
|
|
|
{
|
|
|
|
return d->TitleBar;
|
|
|
|
}
|
2020-03-29 02:32:07 +08:00
|
|
|
|
|
|
|
|
2020-08-20 22:36:02 +08:00
|
|
|
//============================================================================
|
|
|
|
bool CDockAreaWidget::isCentralWidgetArea()
|
|
|
|
{
|
|
|
|
if(dockWidgetsCount()!=1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return dockManager()->centralWidget()==dockWidgets()[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-29 02:32:07 +08:00
|
|
|
//============================================================================
|
|
|
|
QSize CDockAreaWidget::minimumSizeHint() const
|
|
|
|
{
|
|
|
|
return d->MinSizeHint.isValid() ? d->MinSizeHint : Super::minimumSizeHint();
|
|
|
|
}
|
2020-08-21 14:09:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockAreaWidget::onDockWidgetFeaturesChanged()
|
|
|
|
{
|
|
|
|
if (d->TitleBar)
|
|
|
|
d->updateTitleBarButtonStates();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-23 17:23:53 +08:00
|
|
|
} // namespace ads
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// EOF DockAreaWidget.cpp
|