2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2020 Uwe Kindler
|
2023-01-04 08:19:47 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-2.1-or-later OR GPL-3.0-or-later
|
2020-01-24 17:13:32 +01:00
|
|
|
|
|
|
|
|
#include "dockwidget.h"
|
|
|
|
|
|
|
|
|
|
#include "ads_globals.h"
|
2023-02-22 14:29:18 +01:00
|
|
|
#include "ads_globals_p.h"
|
2020-01-24 17:13:32 +01:00
|
|
|
#include "dockareawidget.h"
|
|
|
|
|
#include "dockcomponentsfactory.h"
|
|
|
|
|
#include "dockcontainerwidget.h"
|
|
|
|
|
#include "dockmanager.h"
|
|
|
|
|
#include "docksplitter.h"
|
|
|
|
|
#include "dockwidgettab.h"
|
|
|
|
|
#include "floatingdockcontainer.h"
|
|
|
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
|
#include <QBoxLayout>
|
|
|
|
|
#include <QEvent>
|
|
|
|
|
#include <QLoggingCategory>
|
|
|
|
|
#include <QPointer>
|
|
|
|
|
#include <QScrollArea>
|
|
|
|
|
#include <QSplitter>
|
|
|
|
|
#include <QStack>
|
|
|
|
|
#include <QTextStream>
|
|
|
|
|
#include <QToolBar>
|
|
|
|
|
#include <QXmlStreamWriter>
|
2020-06-22 16:46:25 +02:00
|
|
|
#include <QWindow>
|
2020-01-24 17:13:32 +01:00
|
|
|
|
|
|
|
|
namespace ADS
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Private data class of DockWidget class (pimpl)
|
|
|
|
|
*/
|
2020-03-02 10:21:25 +01:00
|
|
|
class DockWidgetPrivate
|
2020-01-24 17:13:32 +01:00
|
|
|
{
|
2020-03-02 10:21:25 +01:00
|
|
|
public:
|
2020-01-24 17:13:32 +01:00
|
|
|
DockWidget *q = nullptr;
|
|
|
|
|
QBoxLayout *m_layout = nullptr;
|
|
|
|
|
QWidget *m_widget = nullptr;
|
|
|
|
|
DockWidgetTab *m_tabWidget = nullptr;
|
|
|
|
|
DockWidget::DockWidgetFeatures m_features = DockWidget::DefaultDockWidgetFeatures;
|
|
|
|
|
DockManager *m_dockManager = nullptr;
|
|
|
|
|
DockAreaWidget *m_dockArea = nullptr;
|
|
|
|
|
QAction *m_toggleViewAction = nullptr;
|
|
|
|
|
bool m_closed = false;
|
|
|
|
|
QScrollArea *m_scrollArea = nullptr;
|
|
|
|
|
QToolBar *m_toolBar = nullptr;
|
|
|
|
|
Qt::ToolButtonStyle m_toolBarStyleDocked = Qt::ToolButtonIconOnly;
|
|
|
|
|
Qt::ToolButtonStyle m_toolBarStyleFloating = Qt::ToolButtonTextUnderIcon;
|
|
|
|
|
QSize m_toolBarIconSizeDocked = QSize(16, 16);
|
|
|
|
|
QSize m_toolBarIconSizeFloating = QSize(24, 24);
|
|
|
|
|
bool m_isFloatingTopLevel = false;
|
|
|
|
|
QList<QAction *> m_titleBarActions;
|
2020-04-06 14:25:11 +02:00
|
|
|
DockWidget::eMinimumSizeHintMode m_minimumSizeHintMode = DockWidget::MinimumSizeHintFromDockWidget;
|
2020-01-24 17:13:32 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Private data constructor
|
|
|
|
|
*/
|
|
|
|
|
DockWidgetPrivate(DockWidget *parent);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show dock widget
|
|
|
|
|
*/
|
|
|
|
|
void showDockWidget();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Hide dock widget.
|
|
|
|
|
*/
|
|
|
|
|
void hideDockWidget();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
|
|
|
|
void updateParentDockArea();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Setup the top tool bar
|
|
|
|
|
*/
|
|
|
|
|
void setupToolBar();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Setup the main scroll area
|
|
|
|
|
*/
|
|
|
|
|
void setupScrollArea();
|
2020-03-02 10:21:25 +01:00
|
|
|
}; // class DockWidgetPrivate
|
2020-01-24 17:13:32 +01:00
|
|
|
|
|
|
|
|
DockWidgetPrivate::DockWidgetPrivate(DockWidget *parent)
|
|
|
|
|
: q(parent)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
void DockWidgetPrivate::showDockWidget()
|
|
|
|
|
{
|
|
|
|
|
if (!m_dockArea) {
|
|
|
|
|
FloatingDockContainer *floatingWidget = new FloatingDockContainer(q);
|
|
|
|
|
floatingWidget->resize(q->size());
|
2020-06-22 16:46:25 +02:00
|
|
|
m_tabWidget->show();
|
2020-01-24 17:13:32 +01:00
|
|
|
floatingWidget->show();
|
|
|
|
|
} else {
|
|
|
|
|
m_dockArea->setCurrentDockWidget(q);
|
|
|
|
|
m_dockArea->toggleView(true);
|
|
|
|
|
m_tabWidget->show();
|
|
|
|
|
QSplitter *splitter = internal::findParent<QSplitter *>(m_dockArea);
|
|
|
|
|
while (splitter && !splitter->isVisible()) {
|
|
|
|
|
splitter->show();
|
|
|
|
|
splitter = internal::findParent<QSplitter *>(splitter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DockContainerWidget *container = m_dockArea->dockContainer();
|
|
|
|
|
if (container->isFloating()) {
|
|
|
|
|
FloatingDockContainer *floatingWidget
|
|
|
|
|
= internal::findParent<FloatingDockContainer *>(container);
|
|
|
|
|
floatingWidget->show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockWidgetPrivate::hideDockWidget()
|
|
|
|
|
{
|
|
|
|
|
m_tabWidget->hide();
|
|
|
|
|
updateParentDockArea();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockWidgetPrivate::updateParentDockArea()
|
|
|
|
|
{
|
2020-02-25 11:22:36 +01:00
|
|
|
if (!m_dockArea)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// we don't need to change the current tab if the current DockWidget is not the one being closed
|
|
|
|
|
if (m_dockArea->currentDockWidget() != q)
|
2020-01-24 17:13:32 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
auto nextDockWidget = m_dockArea->nextOpenDockWidget(q);
|
2020-02-25 11:22:36 +01:00
|
|
|
if (nextDockWidget)
|
2020-01-24 17:13:32 +01:00
|
|
|
m_dockArea->setCurrentDockWidget(nextDockWidget);
|
2020-02-25 11:22:36 +01:00
|
|
|
else
|
2020-01-24 17:13:32 +01:00
|
|
|
m_dockArea->hideAreaWithNoVisibleContent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockWidgetPrivate::setupToolBar()
|
|
|
|
|
{
|
|
|
|
|
m_toolBar = new QToolBar(q);
|
|
|
|
|
m_toolBar->setObjectName("dockWidgetToolBar");
|
|
|
|
|
m_layout->insertWidget(0, m_toolBar);
|
|
|
|
|
m_toolBar->setIconSize(QSize(16, 16));
|
|
|
|
|
m_toolBar->toggleViewAction()->setEnabled(false);
|
|
|
|
|
m_toolBar->toggleViewAction()->setVisible(false);
|
|
|
|
|
QObject::connect(q, &DockWidget::topLevelChanged, q, &DockWidget::setToolbarFloatingStyle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockWidgetPrivate::setupScrollArea()
|
|
|
|
|
{
|
|
|
|
|
m_scrollArea = new QScrollArea(q);
|
|
|
|
|
m_scrollArea->setObjectName("dockWidgetScrollArea");
|
|
|
|
|
m_scrollArea->setWidgetResizable(true);
|
|
|
|
|
m_layout->addWidget(m_scrollArea);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DockWidget::DockWidget(const QString &uniqueId, QWidget *parent)
|
|
|
|
|
: QFrame(parent)
|
|
|
|
|
, d(new DockWidgetPrivate(this))
|
|
|
|
|
{
|
|
|
|
|
d->m_layout = new QBoxLayout(QBoxLayout::TopToBottom);
|
|
|
|
|
d->m_layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
d->m_layout->setSpacing(0);
|
|
|
|
|
setLayout(d->m_layout);
|
|
|
|
|
setWindowTitle(uniqueId); // temporarily use unique id as title
|
|
|
|
|
setObjectName(uniqueId);
|
|
|
|
|
|
|
|
|
|
d->m_tabWidget = componentsFactory()->createDockWidgetTab(this);
|
|
|
|
|
d->m_toggleViewAction = new QAction(uniqueId, this);
|
|
|
|
|
d->m_toggleViewAction->setCheckable(true);
|
2022-07-21 16:47:30 +02:00
|
|
|
connect(d->m_toggleViewAction, &QAction::triggered, this, [this](bool open) {
|
|
|
|
|
// If the toggle view action mode is ActionModeShow (== m_toggleViewAction isn't
|
|
|
|
|
// checkable, see setToggleViewActionMode()), then open is always true
|
|
|
|
|
toggleView(open || !d->m_toggleViewAction->isCheckable());
|
|
|
|
|
});
|
2020-01-24 17:13:32 +01:00
|
|
|
setToolbarFloatingStyle(false);
|
2020-06-22 16:46:25 +02:00
|
|
|
|
|
|
|
|
if (DockManager::testConfigFlag(DockManager::FocusHighlighting))
|
|
|
|
|
setFocusPolicy(Qt::ClickFocus);
|
2020-01-24 17:13:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DockWidget::~DockWidget()
|
|
|
|
|
{
|
|
|
|
|
qCInfo(adsLog) << Q_FUNC_INFO;
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockWidget::setToggleViewActionChecked(bool checked)
|
|
|
|
|
{
|
2022-07-21 16:47:30 +02:00
|
|
|
d->m_toggleViewAction->setChecked(checked);
|
2020-01-24 17:13:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockWidget::setWidget(QWidget *widget, eInsertMode insertMode)
|
|
|
|
|
{
|
2020-06-22 16:46:25 +02:00
|
|
|
if (d->m_widget)
|
|
|
|
|
takeWidget();
|
|
|
|
|
|
|
|
|
|
auto scrollAreaWidget = qobject_cast<QAbstractScrollArea *>(widget);
|
2020-01-24 17:13:32 +01:00
|
|
|
if (scrollAreaWidget || ForceNoScrollArea == insertMode) {
|
|
|
|
|
d->m_layout->addWidget(widget);
|
2020-02-25 11:22:36 +01:00
|
|
|
if (scrollAreaWidget && scrollAreaWidget->viewport())
|
2020-01-24 17:13:32 +01:00
|
|
|
scrollAreaWidget->viewport()->setProperty("dockWidgetContent", true);
|
|
|
|
|
} else {
|
|
|
|
|
d->setupScrollArea();
|
|
|
|
|
d->m_scrollArea->setWidget(widget);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d->m_widget = widget;
|
|
|
|
|
d->m_widget->setProperty("dockWidgetContent", true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *DockWidget::takeWidget()
|
|
|
|
|
{
|
2020-06-22 16:46:25 +02:00
|
|
|
QWidget *w = nullptr;
|
|
|
|
|
if (d->m_scrollArea) {
|
|
|
|
|
d->m_layout->removeWidget(d->m_scrollArea);
|
|
|
|
|
w = d->m_scrollArea->takeWidget();
|
|
|
|
|
delete d->m_scrollArea;
|
|
|
|
|
d->m_scrollArea = nullptr;
|
|
|
|
|
d->m_widget = nullptr;
|
|
|
|
|
} else if (d->m_widget) {
|
|
|
|
|
d->m_layout->removeWidget(d->m_widget);
|
|
|
|
|
w = d->m_widget;
|
|
|
|
|
d->m_widget = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (w)
|
|
|
|
|
w->setParent(nullptr);
|
|
|
|
|
|
|
|
|
|
return w;
|
2020-01-24 17:13:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *DockWidget::widget() const { return d->m_widget; }
|
|
|
|
|
|
|
|
|
|
DockWidgetTab *DockWidget::tabWidget() const { return d->m_tabWidget; }
|
|
|
|
|
|
|
|
|
|
void DockWidget::setFeatures(DockWidgetFeatures features)
|
|
|
|
|
{
|
2020-06-22 16:46:25 +02:00
|
|
|
if (d->m_features == features)
|
2020-01-24 17:13:32 +01:00
|
|
|
return;
|
2020-06-22 16:46:25 +02:00
|
|
|
|
2020-01-24 17:13:32 +01:00
|
|
|
d->m_features = features;
|
|
|
|
|
emit featuresChanged(d->m_features);
|
|
|
|
|
d->m_tabWidget->onDockWidgetFeaturesChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockWidget::setFeature(DockWidgetFeature flag, bool on)
|
|
|
|
|
{
|
|
|
|
|
auto currentFeatures = features();
|
|
|
|
|
internal::setFlag(currentFeatures, flag, on);
|
|
|
|
|
setFeatures(currentFeatures);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DockWidget::DockWidgetFeatures DockWidget::features() const { return d->m_features; }
|
|
|
|
|
|
|
|
|
|
DockManager *DockWidget::dockManager() const { return d->m_dockManager; }
|
|
|
|
|
|
|
|
|
|
void DockWidget::setDockManager(DockManager *dockManager) { d->m_dockManager = dockManager; }
|
|
|
|
|
|
|
|
|
|
DockContainerWidget *DockWidget::dockContainer() const
|
|
|
|
|
{
|
2020-06-22 16:46:25 +02:00
|
|
|
if (d->m_dockArea)
|
2020-01-24 17:13:32 +01:00
|
|
|
return d->m_dockArea->dockContainer();
|
2020-06-22 16:46:25 +02:00
|
|
|
else
|
2020-01-24 17:13:32 +01:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DockAreaWidget *DockWidget::dockAreaWidget() const { return d->m_dockArea; }
|
|
|
|
|
|
|
|
|
|
bool DockWidget::isFloating() const
|
|
|
|
|
{
|
2020-02-25 11:22:36 +01:00
|
|
|
if (!isInFloatingContainer())
|
2020-01-24 17:13:32 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return dockContainer()->topLevelDockWidget() == this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DockWidget::isInFloatingContainer() const
|
|
|
|
|
{
|
|
|
|
|
auto container = dockContainer();
|
2020-02-25 11:22:36 +01:00
|
|
|
if (!container)
|
2020-01-24 17:13:32 +01:00
|
|
|
return false;
|
|
|
|
|
|
2020-02-25 11:22:36 +01:00
|
|
|
if (!container->isFloating())
|
2020-01-24 17:13:32 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DockWidget::isClosed() const { return d->m_closed; }
|
|
|
|
|
|
|
|
|
|
QAction *DockWidget::toggleViewAction() const { return d->m_toggleViewAction; }
|
|
|
|
|
|
|
|
|
|
void DockWidget::setToggleViewActionMode(eToggleViewActionMode mode)
|
|
|
|
|
{
|
|
|
|
|
if (ActionModeToggle == mode) {
|
|
|
|
|
d->m_toggleViewAction->setCheckable(true);
|
|
|
|
|
d->m_toggleViewAction->setIcon(QIcon());
|
|
|
|
|
} else {
|
|
|
|
|
d->m_toggleViewAction->setCheckable(false);
|
|
|
|
|
d->m_toggleViewAction->setIcon(d->m_tabWidget->icon());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-06 14:25:11 +02:00
|
|
|
void DockWidget::setMinimumSizeHintMode(eMinimumSizeHintMode mode)
|
|
|
|
|
{
|
|
|
|
|
d->m_minimumSizeHintMode = mode;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-24 17:13:32 +01:00
|
|
|
void DockWidget::toggleView(bool open)
|
|
|
|
|
{
|
|
|
|
|
// 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
|
2020-02-25 11:22:36 +01:00
|
|
|
if (d->m_closed != !open)
|
2020-01-24 17:13:32 +01:00
|
|
|
toggleViewInternal(open);
|
2020-02-25 11:22:36 +01:00
|
|
|
else if (open && d->m_dockArea)
|
2020-01-24 17:13:32 +01:00
|
|
|
d->m_dockArea->setCurrentDockWidget(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockWidget::toggleViewInternal(bool open)
|
|
|
|
|
{
|
2020-03-02 10:26:56 +01:00
|
|
|
const DockContainerWidget *const beforeDockContainerWidget = dockContainer();
|
|
|
|
|
DockWidget *topLevelDockWidgetBefore = beforeDockContainerWidget
|
|
|
|
|
? beforeDockContainerWidget->topLevelDockWidget()
|
2020-01-24 17:13:32 +01:00
|
|
|
: nullptr;
|
|
|
|
|
|
2020-06-22 16:46:25 +02:00
|
|
|
if (open)
|
2020-01-24 17:13:32 +01:00
|
|
|
d->showDockWidget();
|
2020-06-22 16:46:25 +02:00
|
|
|
else
|
2020-01-24 17:13:32 +01:00
|
|
|
d->hideDockWidget();
|
2020-06-22 16:46:25 +02:00
|
|
|
|
2020-01-24 17:13:32 +01:00
|
|
|
d->m_closed = !open;
|
|
|
|
|
//d->m_toggleViewAction->blockSignals(true);
|
|
|
|
|
d->m_toggleViewAction->setChecked(open);
|
|
|
|
|
//d->m_toggleViewAction->blockSignals(false);
|
2020-02-25 11:22:36 +01:00
|
|
|
if (d->m_dockArea)
|
2020-01-24 17:13:32 +01:00
|
|
|
d->m_dockArea->toggleDockWidgetView(this, open);
|
|
|
|
|
|
2020-02-25 11:22:36 +01:00
|
|
|
if (open && topLevelDockWidgetBefore)
|
2020-01-24 17:13:32 +01:00
|
|
|
DockWidget::emitTopLevelEventForWidget(topLevelDockWidgetBefore, false);
|
|
|
|
|
|
|
|
|
|
// Here we need to call the dockContainer() function again, because if
|
|
|
|
|
// this dock widget was unassigned before the call to showDockWidget() then
|
|
|
|
|
// it has a dock container now
|
2020-03-02 10:26:56 +01:00
|
|
|
const DockContainerWidget *const dockContainerWidget = dockContainer();
|
2020-01-24 17:13:32 +01:00
|
|
|
DockWidget *topLevelDockWidgetAfter = dockContainerWidget
|
|
|
|
|
? dockContainerWidget->topLevelDockWidget()
|
|
|
|
|
: nullptr;
|
|
|
|
|
DockWidget::emitTopLevelEventForWidget(topLevelDockWidgetAfter, true);
|
2020-03-02 10:25:30 +01:00
|
|
|
FloatingDockContainer *floatingContainer = dockContainerWidget
|
|
|
|
|
? dockContainerWidget->floatingWidget()
|
|
|
|
|
: nullptr;
|
2020-02-25 11:22:36 +01:00
|
|
|
if (floatingContainer)
|
2020-01-24 17:13:32 +01:00
|
|
|
floatingContainer->updateWindowTitle();
|
|
|
|
|
|
2020-02-25 11:22:36 +01:00
|
|
|
if (!open)
|
2020-01-24 17:13:32 +01:00
|
|
|
emit closed();
|
2020-02-25 11:22:36 +01:00
|
|
|
|
2020-01-24 17:13:32 +01:00
|
|
|
emit viewToggled(open);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockWidget::setDockArea(DockAreaWidget *dockArea)
|
|
|
|
|
{
|
|
|
|
|
d->m_dockArea = dockArea;
|
|
|
|
|
d->m_toggleViewAction->setChecked(dockArea != nullptr && !this->isClosed());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockWidget::saveState(QXmlStreamWriter &stream) const
|
|
|
|
|
{
|
|
|
|
|
stream.writeStartElement("widget");
|
|
|
|
|
stream.writeAttribute("name", objectName());
|
|
|
|
|
stream.writeAttribute("closed", QVariant::fromValue(d->m_closed).toString());
|
|
|
|
|
stream.writeEndElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockWidget::flagAsUnassigned()
|
|
|
|
|
{
|
|
|
|
|
d->m_closed = true;
|
|
|
|
|
setParent(d->m_dockManager);
|
|
|
|
|
setVisible(false);
|
|
|
|
|
setDockArea(nullptr);
|
|
|
|
|
tabWidget()->setParent(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DockWidget::event(QEvent *event)
|
|
|
|
|
{
|
|
|
|
|
switch (event->type()) {
|
|
|
|
|
case QEvent::Hide:
|
|
|
|
|
emit visibilityChanged(false);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case QEvent::Show:
|
|
|
|
|
emit visibilityChanged(geometry().right() >= 0 && geometry().bottom() >= 0);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case QEvent::WindowTitleChange :
|
|
|
|
|
{
|
|
|
|
|
const auto title = windowTitle();
|
|
|
|
|
if (d->m_tabWidget) {
|
|
|
|
|
d->m_tabWidget->setText(title);
|
|
|
|
|
}
|
|
|
|
|
if (d->m_toggleViewAction) {
|
|
|
|
|
d->m_toggleViewAction->setText(title);
|
|
|
|
|
}
|
|
|
|
|
if (d->m_dockArea) {
|
|
|
|
|
d->m_dockArea->markTitleBarMenuOutdated(); // update tabs menu
|
|
|
|
|
}
|
|
|
|
|
emit titleChanged(title);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Super::event(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifndef QT_NO_TOOLTIP
|
|
|
|
|
void DockWidget::setTabToolTip(const QString &text)
|
|
|
|
|
{
|
2020-02-25 11:22:36 +01:00
|
|
|
if (d->m_tabWidget)
|
2020-01-24 17:13:32 +01:00
|
|
|
d->m_tabWidget->setToolTip(text);
|
2020-02-25 11:22:36 +01:00
|
|
|
|
|
|
|
|
if (d->m_toggleViewAction)
|
2020-01-24 17:13:32 +01:00
|
|
|
d->m_toggleViewAction->setToolTip(text);
|
2020-02-25 11:22:36 +01:00
|
|
|
|
|
|
|
|
if (d->m_dockArea)
|
2020-06-22 16:46:25 +02:00
|
|
|
d->m_dockArea->markTitleBarMenuOutdated(); // update tabs menu
|
2020-01-24 17:13:32 +01:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void DockWidget::setIcon(const QIcon &icon)
|
|
|
|
|
{
|
|
|
|
|
d->m_tabWidget->setIcon(icon);
|
2020-02-25 11:22:36 +01:00
|
|
|
if (!d->m_toggleViewAction->isCheckable())
|
2020-01-24 17:13:32 +01:00
|
|
|
d->m_toggleViewAction->setIcon(icon);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QIcon DockWidget::icon() const { return d->m_tabWidget->icon(); }
|
|
|
|
|
|
|
|
|
|
QToolBar *DockWidget::toolBar() const { return d->m_toolBar; }
|
|
|
|
|
|
|
|
|
|
QToolBar *DockWidget::createDefaultToolBar()
|
|
|
|
|
{
|
2020-02-25 11:22:36 +01:00
|
|
|
if (!d->m_toolBar)
|
2020-01-24 17:13:32 +01:00
|
|
|
d->setupToolBar();
|
|
|
|
|
|
|
|
|
|
return d->m_toolBar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockWidget::setToolBar(QToolBar *toolBar)
|
|
|
|
|
{
|
2020-02-25 11:22:36 +01:00
|
|
|
if (d->m_toolBar)
|
2020-01-24 17:13:32 +01:00
|
|
|
delete d->m_toolBar;
|
|
|
|
|
|
|
|
|
|
d->m_toolBar = toolBar;
|
|
|
|
|
d->m_layout->insertWidget(0, d->m_toolBar);
|
|
|
|
|
connect(this, &DockWidget::topLevelChanged, this, &DockWidget::setToolbarFloatingStyle);
|
|
|
|
|
setToolbarFloatingStyle(isFloating());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockWidget::setToolBarStyle(Qt::ToolButtonStyle style, eState state)
|
|
|
|
|
{
|
2020-02-25 11:22:36 +01:00
|
|
|
if (StateFloating == state)
|
2020-01-24 17:13:32 +01:00
|
|
|
d->m_toolBarStyleFloating = style;
|
2020-02-25 11:22:36 +01:00
|
|
|
else
|
2020-01-24 17:13:32 +01:00
|
|
|
d->m_toolBarStyleDocked = style;
|
|
|
|
|
|
|
|
|
|
setToolbarFloatingStyle(isFloating());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt::ToolButtonStyle DockWidget::toolBarStyle(eState state) const
|
|
|
|
|
{
|
2020-02-25 11:22:36 +01:00
|
|
|
if (StateFloating == state)
|
2020-01-24 17:13:32 +01:00
|
|
|
return d->m_toolBarStyleFloating;
|
2020-02-25 11:22:36 +01:00
|
|
|
else
|
2020-01-24 17:13:32 +01:00
|
|
|
return d->m_toolBarStyleDocked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockWidget::setToolBarIconSize(const QSize &iconSize, eState state)
|
|
|
|
|
{
|
2020-02-25 11:22:36 +01:00
|
|
|
if (StateFloating == state)
|
2020-01-24 17:13:32 +01:00
|
|
|
d->m_toolBarIconSizeFloating = iconSize;
|
2020-02-25 11:22:36 +01:00
|
|
|
else
|
2020-01-24 17:13:32 +01:00
|
|
|
d->m_toolBarIconSizeDocked = iconSize;
|
|
|
|
|
|
|
|
|
|
setToolbarFloatingStyle(isFloating());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSize DockWidget::toolBarIconSize(eState state) const
|
|
|
|
|
{
|
2020-02-25 11:22:36 +01:00
|
|
|
if (StateFloating == state)
|
2020-01-24 17:13:32 +01:00
|
|
|
return d->m_toolBarIconSizeFloating;
|
2020-02-25 11:22:36 +01:00
|
|
|
else
|
2020-01-24 17:13:32 +01:00
|
|
|
return d->m_toolBarIconSizeDocked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockWidget::setToolbarFloatingStyle(bool floating)
|
|
|
|
|
{
|
2020-02-25 11:22:36 +01:00
|
|
|
if (!d->m_toolBar)
|
2020-01-24 17:13:32 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
auto iconSize = floating ? d->m_toolBarIconSizeFloating : d->m_toolBarIconSizeDocked;
|
2020-02-25 11:22:36 +01:00
|
|
|
if (iconSize != d->m_toolBar->iconSize())
|
2020-01-24 17:13:32 +01:00
|
|
|
d->m_toolBar->setIconSize(iconSize);
|
|
|
|
|
|
|
|
|
|
auto buttonStyle = floating ? d->m_toolBarStyleFloating : d->m_toolBarStyleDocked;
|
2020-02-25 11:22:36 +01:00
|
|
|
if (buttonStyle != d->m_toolBar->toolButtonStyle())
|
2020-01-24 17:13:32 +01:00
|
|
|
d->m_toolBar->setToolButtonStyle(buttonStyle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockWidget::emitTopLevelEventForWidget(DockWidget *topLevelDockWidget, bool floating)
|
|
|
|
|
{
|
|
|
|
|
if (topLevelDockWidget) {
|
|
|
|
|
topLevelDockWidget->dockAreaWidget()->updateTitleBarVisibility();
|
|
|
|
|
topLevelDockWidget->emitTopLevelChanged(floating);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockWidget::emitTopLevelChanged(bool floating)
|
|
|
|
|
{
|
|
|
|
|
if (floating != d->m_isFloatingTopLevel) {
|
|
|
|
|
d->m_isFloatingTopLevel = floating;
|
|
|
|
|
emit topLevelChanged(d->m_isFloatingTopLevel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockWidget::setClosedState(bool closed) { d->m_closed = closed; }
|
|
|
|
|
|
2020-04-06 14:25:11 +02:00
|
|
|
QSize DockWidget::minimumSizeHint() const
|
|
|
|
|
{
|
2023-05-05 10:48:23 +03:00
|
|
|
if (!d->m_widget)
|
|
|
|
|
return QSize(60, 40);
|
|
|
|
|
|
|
|
|
|
DockContainerWidget *container = this->dockContainer();
|
|
|
|
|
if (!container || container->isFloating()) {
|
|
|
|
|
const QSize sh = d->m_widget->minimumSizeHint();
|
|
|
|
|
const QSize s = d->m_widget->minimumSize();
|
|
|
|
|
return {std::max(s.width(), sh.width()), std::max(s.height(), sh.height())};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (d->m_minimumSizeHintMode == DockWidget::MinimumSizeHintFromDockWidget)
|
2020-04-06 14:25:11 +02:00
|
|
|
return QSize(60, 40);
|
|
|
|
|
else
|
|
|
|
|
return d->m_widget->minimumSizeHint();
|
|
|
|
|
}
|
2020-01-24 17:13:32 +01:00
|
|
|
|
|
|
|
|
void DockWidget::setFloating()
|
|
|
|
|
{
|
2020-02-25 11:22:36 +01:00
|
|
|
if (isClosed())
|
2020-01-24 17:13:32 +01:00
|
|
|
return;
|
2020-02-25 11:22:36 +01:00
|
|
|
|
2020-01-24 17:13:32 +01:00
|
|
|
d->m_tabWidget->detachDockWidget();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockWidget::deleteDockWidget()
|
|
|
|
|
{
|
|
|
|
|
dockManager()->removeDockWidget(this);
|
|
|
|
|
deleteLater();
|
|
|
|
|
d->m_closed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockWidget::closeDockWidget()
|
|
|
|
|
{
|
|
|
|
|
closeDockWidgetInternal(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DockWidget::closeDockWidgetInternal(bool forceClose)
|
|
|
|
|
{
|
2020-02-25 11:22:36 +01:00
|
|
|
if (!forceClose)
|
2020-01-24 17:13:32 +01:00
|
|
|
emit closeRequested();
|
|
|
|
|
|
2020-02-25 11:22:36 +01:00
|
|
|
if (!forceClose && features().testFlag(DockWidget::CustomCloseHandling))
|
2020-01-24 17:13:32 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (features().testFlag(DockWidget::DockWidgetDeleteOnClose)) {
|
|
|
|
|
// If the dock widget is floating, then we check if we also need to
|
|
|
|
|
// delete the floating widget
|
|
|
|
|
if (isFloating()) {
|
|
|
|
|
FloatingDockContainer* floatingWidget = internal::findParent<
|
|
|
|
|
FloatingDockContainer *>(this);
|
2020-02-25 11:22:36 +01:00
|
|
|
if (floatingWidget->dockWidgets().count() == 1)
|
2020-01-24 17:13:32 +01:00
|
|
|
floatingWidget->deleteLater();
|
2020-02-25 11:22:36 +01:00
|
|
|
else
|
2020-01-24 17:13:32 +01:00
|
|
|
floatingWidget->hide();
|
|
|
|
|
}
|
|
|
|
|
deleteDockWidget();
|
2020-04-06 14:25:11 +02:00
|
|
|
emit closed();
|
2020-01-24 17:13:32 +01:00
|
|
|
} else {
|
|
|
|
|
toggleView(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockWidget::setTitleBarActions(QList<QAction *> actions)
|
|
|
|
|
{
|
|
|
|
|
d->m_titleBarActions = actions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<QAction *> DockWidget::titleBarActions() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_titleBarActions;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-22 16:46:25 +02:00
|
|
|
void DockWidget::showFullScreen()
|
|
|
|
|
{
|
|
|
|
|
if (isFloating())
|
|
|
|
|
dockContainer()->floatingWidget()->showFullScreen();
|
|
|
|
|
else
|
|
|
|
|
Super::showFullScreen();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockWidget::showNormal()
|
|
|
|
|
{
|
|
|
|
|
if (isFloating())
|
|
|
|
|
dockContainer()->floatingWidget()->showNormal();
|
|
|
|
|
else
|
|
|
|
|
Super::showNormal();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DockWidget::isFullScreen() const
|
|
|
|
|
{
|
|
|
|
|
if (isFloating())
|
|
|
|
|
return dockContainer()->floatingWidget()->isFullScreen();
|
|
|
|
|
else
|
|
|
|
|
return Super::isFullScreen();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockWidget::setAsCurrentTab()
|
|
|
|
|
{
|
|
|
|
|
if (d->m_dockArea && !isClosed())
|
|
|
|
|
d->m_dockArea->setCurrentDockWidget(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DockWidget::isTabbed() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_dockArea && (d->m_dockArea->openDockWidgetsCount() > 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DockWidget::isCurrentTab() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_dockArea && (d->m_dockArea->currentDockWidget() == this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DockWidget::raise()
|
|
|
|
|
{
|
|
|
|
|
if (isClosed())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
setAsCurrentTab();
|
|
|
|
|
if (isInFloatingContainer())
|
|
|
|
|
{
|
|
|
|
|
auto floatingWindow = window();
|
|
|
|
|
floatingWindow->raise();
|
|
|
|
|
floatingWindow->activateWindow();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-24 17:13:32 +01:00
|
|
|
} // namespace ADS
|