2018-11-05 19:00:56 +08:00
|
|
|
/*******************************************************************************
|
|
|
|
** Qt Advanced Docking System
|
|
|
|
** Copyright (C) 2017 Uwe Kindler
|
|
|
|
**
|
|
|
|
** 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,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** 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/>.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
2018-10-12 19:37:37 +08:00
|
|
|
//============================================================================
|
|
|
|
/// \file DockAreaTitleBar.cpp
|
|
|
|
/// \author Uwe Kindler
|
|
|
|
/// \date 12.10.2018
|
|
|
|
/// \brief Implementation of CDockAreaTitleBar class
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// INCLUDES
|
|
|
|
//============================================================================
|
|
|
|
#include "DockAreaTitleBar.h"
|
|
|
|
|
|
|
|
#include <QPushButton>
|
2018-10-31 06:45:59 +08:00
|
|
|
#include <QToolButton>
|
2018-10-12 19:37:37 +08:00
|
|
|
#include <QBoxLayout>
|
|
|
|
#include <QStyle>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QScrollArea>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QDebug>
|
2020-02-02 18:16:38 +08:00
|
|
|
#include <QPointer>
|
2018-10-12 19:37:37 +08:00
|
|
|
|
2020-05-13 22:40:43 +08:00
|
|
|
#include "DockAreaTitleBar_p.h"
|
2018-11-08 17:04:29 +08:00
|
|
|
#include "ads_globals.h"
|
2018-10-12 19:37:37 +08:00
|
|
|
#include "FloatingDockContainer.h"
|
2020-02-07 19:16:26 +08:00
|
|
|
#include "FloatingDragPreview.h"
|
2018-10-12 19:37:37 +08:00
|
|
|
#include "DockAreaWidget.h"
|
|
|
|
#include "DockOverlay.h"
|
|
|
|
#include "DockManager.h"
|
|
|
|
#include "DockWidget.h"
|
|
|
|
#include "DockWidgetTab.h"
|
|
|
|
#include "DockAreaTabBar.h"
|
2019-10-18 14:31:26 +08:00
|
|
|
#include "IconProvider.h"
|
2020-02-11 15:32:49 +08:00
|
|
|
#include "DockComponentsFactory.h"
|
2018-10-12 19:37:37 +08:00
|
|
|
|
2018-12-20 22:29:38 +08:00
|
|
|
#include <iostream>
|
2018-10-12 19:37:37 +08:00
|
|
|
|
|
|
|
namespace ads
|
|
|
|
{
|
2020-02-02 18:16:38 +08:00
|
|
|
|
2018-10-12 19:37:37 +08:00
|
|
|
/**
|
|
|
|
* Private data class of CDockAreaTitleBar class (pimpl)
|
|
|
|
*/
|
|
|
|
struct DockAreaTitleBarPrivate
|
|
|
|
{
|
|
|
|
CDockAreaTitleBar* _this;
|
2020-02-02 18:16:38 +08:00
|
|
|
QPointer<tTitleBarButton> TabsMenuButton;
|
|
|
|
QPointer<tTitleBarButton> UndockButton;
|
|
|
|
QPointer<tTitleBarButton> CloseButton;
|
2020-02-07 20:42:11 +08:00
|
|
|
QBoxLayout* Layout;
|
2018-10-12 19:37:37 +08:00
|
|
|
CDockAreaWidget* DockArea;
|
|
|
|
CDockAreaTabBar* TabBar;
|
|
|
|
bool MenuOutdated = true;
|
|
|
|
QMenu* TabsMenu;
|
2020-02-06 07:31:57 +08:00
|
|
|
QList<tTitleBarButton*> DockWidgetActionsButtons;
|
2018-10-12 19:37:37 +08:00
|
|
|
|
2020-02-07 19:16:26 +08:00
|
|
|
QPoint DragStartMousePos;
|
|
|
|
eDragState DragState = DraggingInactive;
|
|
|
|
IFloatingWidget* FloatingWidget = nullptr;
|
|
|
|
|
|
|
|
|
2018-10-12 19:37:37 +08:00
|
|
|
/**
|
|
|
|
* Private data constructor
|
|
|
|
*/
|
|
|
|
DockAreaTitleBarPrivate(CDockAreaTitleBar* _public);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the title bar close and menu buttons
|
|
|
|
*/
|
|
|
|
void createButtons();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the internal TabBar
|
|
|
|
*/
|
|
|
|
void createTabBar();
|
2018-11-08 19:57:25 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience function for DockManager access
|
|
|
|
*/
|
|
|
|
CDockManager* dockManager() const
|
|
|
|
{
|
|
|
|
return DockArea->dockManager();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the given config flag is set
|
2020-06-11 14:06:37 +08:00
|
|
|
* Convenience function to ease config flag testing
|
2018-11-08 19:57:25 +08:00
|
|
|
*/
|
2020-02-05 15:04:27 +08:00
|
|
|
static bool testConfigFlag(CDockManager::eConfigFlag Flag)
|
2018-11-08 19:57:25 +08:00
|
|
|
{
|
2020-06-11 14:06:37 +08:00
|
|
|
return CDockManager::testConfigFlag(Flag);
|
2018-11-08 19:57:25 +08:00
|
|
|
}
|
2020-02-07 19:16:26 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test function for current drag state
|
|
|
|
*/
|
|
|
|
bool isDraggingState(eDragState dragState) const
|
|
|
|
{
|
|
|
|
return this->DragState == dragState;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts floating
|
|
|
|
*/
|
|
|
|
void startFloating(const QPoint& Offset);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes the dock area floating
|
|
|
|
*/
|
|
|
|
IFloatingWidget* makeAreaFloating(const QPoint& Offset, eDragState DragState);
|
2018-10-12 19:37:37 +08:00
|
|
|
};// struct DockAreaTitleBarPrivate
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
DockAreaTitleBarPrivate::DockAreaTitleBarPrivate(CDockAreaTitleBar* _public) :
|
|
|
|
_this(_public)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void DockAreaTitleBarPrivate::createButtons()
|
|
|
|
{
|
2019-09-13 16:25:33 +08:00
|
|
|
QSizePolicy ButtonSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
2020-02-02 23:22:05 +08:00
|
|
|
|
2020-02-05 15:04:27 +08:00
|
|
|
// Tabs menu button
|
|
|
|
TabsMenuButton = new CTitleBarButton(testConfigFlag(CDockManager::DockAreaHasTabsMenuButton));
|
|
|
|
TabsMenuButton->setObjectName("tabsMenuButton");
|
|
|
|
TabsMenuButton->setAutoRaise(true);
|
|
|
|
TabsMenuButton->setPopupMode(QToolButton::InstantPopup);
|
2020-02-05 15:57:57 +08:00
|
|
|
internal::setButtonIcon(TabsMenuButton, QStyle::SP_TitleBarUnshadeButton, ads::DockAreaMenuIcon);
|
2020-02-05 15:04:27 +08:00
|
|
|
QMenu* TabsMenu = new QMenu(TabsMenuButton);
|
2019-08-26 13:58:56 +08:00
|
|
|
#ifndef QT_NO_TOOLTIP
|
2020-02-05 15:04:27 +08:00
|
|
|
TabsMenu->setToolTipsVisible(true);
|
2019-08-26 13:58:56 +08:00
|
|
|
#endif
|
2020-02-05 15:04:27 +08:00
|
|
|
_this->connect(TabsMenu, SIGNAL(aboutToShow()), SLOT(onTabsMenuAboutToShow()));
|
|
|
|
TabsMenuButton->setMenu(TabsMenu);
|
2020-02-15 05:56:48 +08:00
|
|
|
internal::setToolTip(TabsMenuButton, QObject::tr("List All Tabs"));
|
2020-02-05 15:04:27 +08:00
|
|
|
TabsMenuButton->setSizePolicy(ButtonSizePolicy);
|
2020-02-07 20:42:11 +08:00
|
|
|
Layout->addWidget(TabsMenuButton, 0);
|
2020-02-05 15:04:27 +08:00
|
|
|
_this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)),
|
|
|
|
SLOT(onTabsMenuActionTriggered(QAction*)));
|
2018-10-12 19:37:37 +08:00
|
|
|
|
2020-02-05 15:04:27 +08:00
|
|
|
// Undock button
|
|
|
|
UndockButton = new CTitleBarButton(testConfigFlag(CDockManager::DockAreaHasUndockButton));
|
2020-06-14 22:25:18 +08:00
|
|
|
UndockButton->setObjectName("detachGroupButton");
|
2020-02-05 15:04:27 +08:00
|
|
|
UndockButton->setAutoRaise(true);
|
2020-02-05 15:33:40 +08:00
|
|
|
internal::setToolTip(UndockButton, QObject::tr("Detach Group"));
|
2020-02-05 15:57:57 +08:00
|
|
|
internal::setButtonIcon(UndockButton, QStyle::SP_TitleBarNormalButton, ads::DockAreaUndockIcon);
|
2020-02-05 15:04:27 +08:00
|
|
|
UndockButton->setSizePolicy(ButtonSizePolicy);
|
2020-02-07 20:42:11 +08:00
|
|
|
Layout->addWidget(UndockButton, 0);
|
2020-02-05 15:04:27 +08:00
|
|
|
_this->connect(UndockButton, SIGNAL(clicked()), SLOT(onUndockButtonClicked()));
|
2018-11-04 03:51:02 +08:00
|
|
|
|
2020-02-05 15:04:27 +08:00
|
|
|
// Close button
|
|
|
|
CloseButton = new CTitleBarButton(testConfigFlag(CDockManager::DockAreaHasCloseButton));
|
2020-06-14 22:25:18 +08:00
|
|
|
CloseButton->setObjectName("dockAreaCloseButton");
|
2020-02-05 15:04:27 +08:00
|
|
|
CloseButton->setAutoRaise(true);
|
2020-02-05 15:57:57 +08:00
|
|
|
internal::setButtonIcon(CloseButton, QStyle::SP_TitleBarCloseButton, ads::DockAreaCloseIcon);
|
2020-02-05 15:04:27 +08:00
|
|
|
if (testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
|
|
|
|
{
|
2020-02-05 15:33:40 +08:00
|
|
|
internal::setToolTip(CloseButton, QObject::tr("Close Active Tab"));
|
2018-11-09 17:07:56 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-02-05 15:33:40 +08:00
|
|
|
internal::setToolTip(CloseButton, QObject::tr("Close Group"));
|
2019-09-13 03:24:48 +08:00
|
|
|
}
|
2020-02-05 15:04:27 +08:00
|
|
|
CloseButton->setSizePolicy(ButtonSizePolicy);
|
|
|
|
CloseButton->setIconSize(QSize(16, 16));
|
2020-02-07 20:42:11 +08:00
|
|
|
Layout->addWidget(CloseButton, 0);
|
2020-02-05 15:04:27 +08:00
|
|
|
_this->connect(CloseButton, SIGNAL(clicked()), SLOT(onCloseButtonClicked()));
|
2018-10-12 19:37:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void DockAreaTitleBarPrivate::createTabBar()
|
|
|
|
{
|
2020-02-11 15:32:49 +08:00
|
|
|
TabBar = componentsFactory()->createDockAreaTabBar(DockArea);
|
2020-02-07 20:42:11 +08:00
|
|
|
TabBar->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
|
|
|
|
Layout->addWidget(TabBar);
|
2018-10-12 20:51:57 +08:00
|
|
|
_this->connect(TabBar, SIGNAL(tabClosed(int)), SLOT(markTabsMenuOutdated()));
|
|
|
|
_this->connect(TabBar, SIGNAL(tabOpened(int)), SLOT(markTabsMenuOutdated()));
|
|
|
|
_this->connect(TabBar, SIGNAL(tabInserted(int)), SLOT(markTabsMenuOutdated()));
|
|
|
|
_this->connect(TabBar, SIGNAL(removingTab(int)), SLOT(markTabsMenuOutdated()));
|
|
|
|
_this->connect(TabBar, SIGNAL(tabMoved(int, int)), SLOT(markTabsMenuOutdated()));
|
|
|
|
_this->connect(TabBar, SIGNAL(currentChanged(int)), SLOT(onCurrentTabChanged(int)));
|
2018-10-15 21:09:59 +08:00
|
|
|
_this->connect(TabBar, SIGNAL(tabBarClicked(int)), SIGNAL(tabBarClicked(int)));
|
2020-02-06 22:21:19 +08:00
|
|
|
_this->connect(TabBar, SIGNAL(elidedChanged(bool)), SLOT(markTabsMenuOutdated()));
|
2018-10-12 19:37:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-07 19:16:26 +08:00
|
|
|
//============================================================================
|
|
|
|
IFloatingWidget* DockAreaTitleBarPrivate::makeAreaFloating(const QPoint& Offset, eDragState DragState)
|
|
|
|
{
|
|
|
|
QSize Size = DockArea->size();
|
|
|
|
this->DragState = DragState;
|
2020-06-11 14:06:37 +08:00
|
|
|
bool OpaqueUndocking = CDockManager::testConfigFlag(CDockManager::OpaqueUndocking) ||
|
2020-02-07 19:16:26 +08:00
|
|
|
(DraggingFloatingWidget != DragState);
|
|
|
|
CFloatingDockContainer* FloatingDockContainer = nullptr;
|
|
|
|
IFloatingWidget* FloatingWidget;
|
|
|
|
if (OpaqueUndocking)
|
|
|
|
{
|
|
|
|
FloatingWidget = FloatingDockContainer = new CFloatingDockContainer(DockArea);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto w = new CFloatingDragPreview(DockArea);
|
|
|
|
QObject::connect(w, &CFloatingDragPreview::draggingCanceled, [=]()
|
|
|
|
{
|
|
|
|
this->DragState = DraggingInactive;
|
|
|
|
});
|
|
|
|
FloatingWidget = w;
|
|
|
|
}
|
|
|
|
|
|
|
|
FloatingWidget->startFloating(Offset, Size, DragState, nullptr);
|
|
|
|
if (FloatingDockContainer)
|
|
|
|
{
|
|
|
|
auto TopLevelDockWidget = FloatingDockContainer->topLevelDockWidget();
|
|
|
|
if (TopLevelDockWidget)
|
|
|
|
{
|
|
|
|
TopLevelDockWidget->emitTopLevelChanged(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FloatingWidget;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void DockAreaTitleBarPrivate::startFloating(const QPoint& Offset)
|
|
|
|
{
|
|
|
|
FloatingWidget = makeAreaFloating(Offset, DraggingFloatingWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-12 19:37:37 +08:00
|
|
|
//============================================================================
|
|
|
|
CDockAreaTitleBar::CDockAreaTitleBar(CDockAreaWidget* parent) :
|
|
|
|
QFrame(parent),
|
|
|
|
d(new DockAreaTitleBarPrivate(this))
|
|
|
|
{
|
|
|
|
d->DockArea = parent;
|
|
|
|
|
|
|
|
setObjectName("dockAreaTitleBar");
|
2020-02-07 20:42:11 +08:00
|
|
|
d->Layout = new QBoxLayout(QBoxLayout::LeftToRight);
|
|
|
|
d->Layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
d->Layout->setSpacing(0);
|
|
|
|
setLayout(d->Layout);
|
2020-02-07 18:49:45 +08:00
|
|
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
2018-10-12 19:37:37 +08:00
|
|
|
|
|
|
|
d->createTabBar();
|
2020-02-08 05:49:10 +08:00
|
|
|
d->Layout->addWidget(new CSpacerWidget(this));
|
2018-10-12 19:37:37 +08:00
|
|
|
d->createButtons();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockAreaTitleBar::~CDockAreaTitleBar()
|
|
|
|
{
|
2020-02-02 18:16:38 +08:00
|
|
|
if (!d->CloseButton.isNull())
|
|
|
|
{
|
|
|
|
delete d->CloseButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!d->TabsMenuButton.isNull())
|
|
|
|
{
|
|
|
|
delete d->TabsMenuButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!d->UndockButton.isNull())
|
|
|
|
{
|
|
|
|
delete d->UndockButton;
|
|
|
|
}
|
2018-10-12 19:37:37 +08:00
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockAreaTabBar* CDockAreaTitleBar::tabBar() const
|
|
|
|
{
|
|
|
|
return d->TabBar;
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockAreaTitleBar::markTabsMenuOutdated()
|
|
|
|
{
|
2020-02-06 22:21:19 +08:00
|
|
|
if(DockAreaTitleBarPrivate::testConfigFlag(CDockManager::DockAreaDynamicTabsMenuButtonVisibility))
|
|
|
|
{
|
|
|
|
bool hasElidedTabTitle = false;
|
|
|
|
for (int i = 0; i < d->TabBar->count(); ++i)
|
|
|
|
{
|
|
|
|
if (!d->TabBar->isTabOpen(i))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
CDockWidgetTab* Tab = d->TabBar->tab(i);
|
|
|
|
if(Tab->isTitleElided())
|
|
|
|
{
|
|
|
|
hasElidedTabTitle = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool visible = (hasElidedTabTitle && (d->TabBar->count() > 1));
|
|
|
|
QMetaObject::invokeMethod(d->TabsMenuButton, "setVisible", Qt::QueuedConnection, Q_ARG(bool, visible));
|
|
|
|
}
|
2018-10-12 19:37:37 +08:00
|
|
|
d->MenuOutdated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockAreaTitleBar::onTabsMenuAboutToShow()
|
|
|
|
{
|
|
|
|
if (!d->MenuOutdated)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QMenu* menu = d->TabsMenuButton->menu();
|
|
|
|
menu->clear();
|
|
|
|
for (int i = 0; i < d->TabBar->count(); ++i)
|
|
|
|
{
|
|
|
|
if (!d->TabBar->isTabOpen(i))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
auto Tab = d->TabBar->tab(i);
|
|
|
|
QAction* Action = menu->addAction(Tab->icon(), Tab->text());
|
2020-02-05 15:33:40 +08:00
|
|
|
internal::setToolTip(Action, Tab->toolTip());
|
2018-10-12 19:37:37 +08:00
|
|
|
Action->setData(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
d->MenuOutdated = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockAreaTitleBar::onCloseButtonClicked()
|
|
|
|
{
|
2019-07-21 15:53:24 +08:00
|
|
|
ADS_PRINT("CDockAreaTitleBar::onCloseButtonClicked");
|
2018-11-08 19:57:25 +08:00
|
|
|
if (d->testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
|
|
|
|
{
|
|
|
|
d->TabBar->closeTab(d->TabBar->currentIndex());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d->DockArea->closeArea();
|
|
|
|
}
|
2018-10-12 19:37:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-04 03:51:02 +08:00
|
|
|
//============================================================================
|
|
|
|
void CDockAreaTitleBar::onUndockButtonClicked()
|
|
|
|
{
|
2019-07-11 21:12:39 +08:00
|
|
|
if (d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable))
|
|
|
|
{
|
2020-02-07 19:16:26 +08:00
|
|
|
d->makeAreaFloating(mapFromGlobal(QCursor::pos()), DraggingInactive);
|
2019-07-11 21:12:39 +08:00
|
|
|
}
|
2018-11-04 03:51:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-12 19:37:37 +08:00
|
|
|
//============================================================================
|
|
|
|
void CDockAreaTitleBar::onTabsMenuActionTriggered(QAction* Action)
|
|
|
|
{
|
|
|
|
int Index = Action->data().toInt();
|
|
|
|
d->TabBar->setCurrentIndex(Index);
|
2018-10-15 21:09:59 +08:00
|
|
|
emit tabBarClicked(Index);
|
2018-10-12 19:37:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-12 20:51:57 +08:00
|
|
|
//============================================================================
|
2020-02-06 16:15:13 +08:00
|
|
|
void CDockAreaTitleBar::updateDockWidgetActionsButtons()
|
2018-10-12 20:51:57 +08:00
|
|
|
{
|
2020-02-06 16:15:13 +08:00
|
|
|
CDockWidget* DockWidget = d->TabBar->currentTab()->dockWidget();
|
2020-02-06 07:31:57 +08:00
|
|
|
if (!d->DockWidgetActionsButtons.isEmpty())
|
|
|
|
{
|
|
|
|
for (auto Button : d->DockWidgetActionsButtons)
|
|
|
|
{
|
2020-02-07 20:42:11 +08:00
|
|
|
d->Layout->removeWidget(Button);
|
2020-02-06 07:31:57 +08:00
|
|
|
delete Button;
|
|
|
|
}
|
|
|
|
d->DockWidgetActionsButtons.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Actions = DockWidget->titleBarActions();
|
|
|
|
if (Actions.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-07 21:29:02 +08:00
|
|
|
int InsertIndex = indexOf(d->TabsMenuButton);
|
2020-02-06 07:31:57 +08:00
|
|
|
for (auto Action : Actions)
|
|
|
|
{
|
|
|
|
auto Button = new CTitleBarButton(true, this);
|
|
|
|
Button->setDefaultAction(Action);
|
|
|
|
Button->setAutoRaise(true);
|
|
|
|
Button->setPopupMode(QToolButton::InstantPopup);
|
|
|
|
Button->setObjectName(Action->objectName());
|
2020-02-07 20:42:11 +08:00
|
|
|
d->Layout->insertWidget(InsertIndex++, Button, 0);
|
2020-02-06 07:31:57 +08:00
|
|
|
d->DockWidgetActionsButtons.append(Button);
|
|
|
|
}
|
2018-10-12 20:51:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-06 16:15:13 +08:00
|
|
|
//============================================================================
|
|
|
|
void CDockAreaTitleBar::onCurrentTabChanged(int Index)
|
|
|
|
{
|
|
|
|
if (Index < 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
|
|
|
|
{
|
|
|
|
CDockWidget* DockWidget = d->TabBar->tab(Index)->dockWidget();
|
|
|
|
d->CloseButton->setEnabled(DockWidget->features().testFlag(CDockWidget::DockWidgetClosable));
|
|
|
|
}
|
|
|
|
|
|
|
|
updateDockWidgetActionsButtons();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-04 03:51:02 +08:00
|
|
|
//============================================================================
|
|
|
|
QAbstractButton* CDockAreaTitleBar::button(TitleBarButton which) const
|
|
|
|
{
|
|
|
|
switch (which)
|
|
|
|
{
|
|
|
|
case TitleBarButtonTabsMenu: return d->TabsMenuButton;
|
|
|
|
case TitleBarButtonUndock: return d->UndockButton;
|
|
|
|
case TitleBarButtonClose: return d->CloseButton;
|
|
|
|
default:
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockAreaTitleBar::setVisible(bool Visible)
|
|
|
|
{
|
|
|
|
Super::setVisible(Visible);
|
2019-01-23 14:43:07 +08:00
|
|
|
markTabsMenuOutdated();
|
2018-11-04 03:51:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-07 19:16:26 +08:00
|
|
|
//============================================================================
|
|
|
|
void CDockAreaTitleBar::mousePressEvent(QMouseEvent* ev)
|
|
|
|
{
|
|
|
|
if (ev->button() == Qt::LeftButton)
|
|
|
|
{
|
|
|
|
ev->accept();
|
|
|
|
d->DragStartMousePos = ev->pos();
|
|
|
|
d->DragState = DraggingMousePressed;
|
2020-06-06 20:59:03 +08:00
|
|
|
|
2020-06-11 14:06:37 +08:00
|
|
|
if (CDockManager::testConfigFlag(CDockManager::FocusHighlighting))
|
2020-06-06 20:59:03 +08:00
|
|
|
{
|
|
|
|
d->TabBar->currentTab()->setFocus(Qt::OtherFocusReason);
|
|
|
|
}
|
2020-02-07 19:16:26 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
Super::mousePressEvent(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockAreaTitleBar::mouseReleaseEvent(QMouseEvent* ev)
|
|
|
|
{
|
|
|
|
if (ev->button() == Qt::LeftButton)
|
|
|
|
{
|
|
|
|
ADS_PRINT("CDockAreaTitleBar::mouseReleaseEvent");
|
|
|
|
ev->accept();
|
|
|
|
auto CurrentDragState = d->DragState;
|
|
|
|
d->DragStartMousePos = QPoint();
|
|
|
|
d->DragState = DraggingInactive;
|
|
|
|
if (DraggingFloatingWidget == CurrentDragState)
|
|
|
|
{
|
|
|
|
d->FloatingWidget->finishDragging();
|
|
|
|
}
|
2020-06-06 20:59:03 +08:00
|
|
|
|
2020-02-07 19:16:26 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
Super::mouseReleaseEvent(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockAreaTitleBar::mouseMoveEvent(QMouseEvent* ev)
|
|
|
|
{
|
|
|
|
Super::mouseMoveEvent(ev);
|
|
|
|
if (!(ev->buttons() & Qt::LeftButton) || d->isDraggingState(DraggingInactive))
|
|
|
|
{
|
|
|
|
d->DragState = DraggingInactive;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// move floating window
|
|
|
|
if (d->isDraggingState(DraggingFloatingWidget))
|
|
|
|
{
|
|
|
|
d->FloatingWidget->moveFloating();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-11 15:03:28 +08:00
|
|
|
// If this is the last dock area in a floating dock container it does not make
|
2020-02-07 19:16:26 +08:00
|
|
|
// sense to move it to a new floating widget and leave this one
|
|
|
|
// empty
|
|
|
|
if (d->DockArea->dockContainer()->isFloating()
|
|
|
|
&& d->DockArea->dockContainer()->visibleDockAreaCount() == 1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If one single dock widget in this area is not floatable then the whole
|
|
|
|
// area is not floatable
|
2020-02-16 21:37:14 +08:00
|
|
|
// If we do non opaque undocking, then we can create the floating drag
|
|
|
|
// preview if the dock widget is movable
|
|
|
|
auto Features = d->DockArea->features();
|
|
|
|
if (!Features.testFlag(CDockWidget::DockWidgetFloatable)
|
|
|
|
&& !(Features.testFlag(CDockWidget::DockWidgetMovable) && !CDockManager::testConfigFlag(CDockManager::OpaqueUndocking)))
|
2020-02-07 19:16:26 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DragDistance = (d->DragStartMousePos - ev->pos()).manhattanLength();
|
|
|
|
if (DragDistance >= CDockManager::startDragDistance())
|
|
|
|
{
|
2020-05-11 15:03:28 +08:00
|
|
|
ADS_PRINT("CDockAreaTitlBar::startFloating");
|
2020-02-07 19:16:26 +08:00
|
|
|
d->startFloating(d->DragStartMousePos);
|
|
|
|
auto Overlay = d->DockArea->dockManager()->containerOverlay();
|
|
|
|
Overlay->setAllowedAreas(OuterDockAreas);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockAreaTitleBar::mouseDoubleClickEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
// If this is the last dock area in a dock container it does not make
|
|
|
|
// sense to move it to a new floating widget and leave this one
|
|
|
|
// empty
|
|
|
|
if (d->DockArea->dockContainer()->isFloating() && d->DockArea->dockContainer()->dockAreaCount() == 1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
d->makeAreaFloating(event->pos(), DraggingInactive);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-07 19:23:26 +08:00
|
|
|
//============================================================================
|
|
|
|
void CDockAreaTitleBar::contextMenuEvent(QContextMenuEvent* ev)
|
|
|
|
{
|
|
|
|
ev->accept();
|
|
|
|
if (d->isDraggingState(DraggingFloatingWidget))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QMenu Menu(this);
|
2020-06-30 15:59:42 +08:00
|
|
|
auto Action = Menu.addAction(tr("Detach Group"), this, SLOT(onUndockButtonClicked()));
|
2020-02-07 19:23:26 +08:00
|
|
|
Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable));
|
|
|
|
Menu.addSeparator();
|
2020-06-30 15:59:42 +08:00
|
|
|
Action = Menu.addAction(tr("Close Group"), this, SLOT(onCloseButtonClicked()));
|
2020-02-07 19:23:26 +08:00
|
|
|
Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetClosable));
|
2020-06-30 15:59:42 +08:00
|
|
|
Menu.addAction(tr("Close Other Groups"), d->DockArea, SLOT(closeOtherAreas()));
|
2020-02-07 19:23:26 +08:00
|
|
|
Menu.exec(ev->globalPos());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-07 20:42:11 +08:00
|
|
|
//============================================================================
|
|
|
|
void CDockAreaTitleBar::insertWidget(int index, QWidget *widget)
|
|
|
|
{
|
|
|
|
d->Layout->insertWidget(index, widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
int CDockAreaTitleBar::indexOf(QWidget *widget) const
|
|
|
|
{
|
|
|
|
return d->Layout->indexOf(widget);
|
|
|
|
}
|
|
|
|
|
2020-05-13 14:04:50 +08:00
|
|
|
//============================================================================
|
2020-06-11 14:06:37 +08:00
|
|
|
CTitleBarButton::CTitleBarButton(bool visible, QWidget* parent)
|
|
|
|
: tTitleBarButton(parent),
|
|
|
|
Visible(visible),
|
|
|
|
HideWhenDisabled(CDockManager::testConfigFlag(CDockManager::DockAreaHideDisabledButtons))
|
2020-05-13 14:04:50 +08:00
|
|
|
{
|
2020-02-07 20:42:11 +08:00
|
|
|
|
2020-05-13 14:04:50 +08:00
|
|
|
}
|
2018-10-12 19:37:37 +08:00
|
|
|
|
2020-05-13 14:04:50 +08:00
|
|
|
//============================================================================
|
|
|
|
void CTitleBarButton::setVisible(bool visible)
|
|
|
|
{
|
|
|
|
// 'visible' can stay 'true' if and only if this button is configured to generaly visible:
|
|
|
|
visible = visible && this->Visible;
|
|
|
|
|
|
|
|
// 'visible' can stay 'true' unless: this button is configured to be invisible when it is disabled and it is currently disabled:
|
|
|
|
if (visible && HideWhenDisabled)
|
|
|
|
{
|
|
|
|
visible = isEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
Super::setVisible(visible);
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
bool CTitleBarButton::event(QEvent *ev)
|
|
|
|
{
|
|
|
|
if (QEvent::EnabledChange == ev->type() && HideWhenDisabled)
|
|
|
|
{
|
|
|
|
// force setVisible() call
|
|
|
|
// Calling setVisible() directly here doesn't work well when button is expected to be shown first time
|
|
|
|
QMetaObject::invokeMethod(this, "setVisible", Qt::QueuedConnection, Q_ARG(bool, isEnabled()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return Super::event(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CSpacerWidget::CSpacerWidget(QWidget* Parent /*= 0*/) : Super(Parent)
|
|
|
|
{
|
|
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
setStyleSheet("border: none; background: none;");
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace ads
|
2020-02-06 16:15:13 +08:00
|
|
|
|
2018-10-12 19:37:37 +08:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// EOF DockAreaTitleBar.cpp
|