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>
|
2022-11-05 17:11:09 +08:00
|
|
|
#include <QApplication>
|
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"
|
2020-02-11 15:32:49 +08:00
|
|
|
#include "DockComponentsFactory.h"
|
2021-07-26 00:12:27 +08:00
|
|
|
#include "DockFocusController.h"
|
2022-09-08 14:43:18 +08:00
|
|
|
#include "ElidingLabel.h"
|
2022-11-02 19:45:45 +08:00
|
|
|
#include "AutoHideDockContainer.h"
|
2022-11-03 22:28:01 +08:00
|
|
|
#include "IconProvider.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
|
|
|
|
{
|
2022-11-03 22:28:01 +08:00
|
|
|
static const char* const LocationProperty = "Location";
|
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;
|
2023-07-11 14:25:34 +08:00
|
|
|
QPointer<CTitleBarButton> TabsMenuButton;
|
|
|
|
QPointer<CTitleBarButton> AutoHideButton;
|
|
|
|
QPointer<CTitleBarButton> UndockButton;
|
|
|
|
QPointer<CTitleBarButton> CloseButton;
|
2020-02-07 20:42:11 +08:00
|
|
|
QBoxLayout* Layout;
|
2018-10-12 19:37:37 +08:00
|
|
|
CDockAreaWidget* DockArea;
|
|
|
|
CDockAreaTabBar* TabBar;
|
2022-10-13 14:26:54 +08:00
|
|
|
CElidingLabel* AutoHideTitleLabel;
|
2018-10-12 19:37:37 +08:00
|
|
|
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();
|
|
|
|
|
2022-09-08 14:43:18 +08:00
|
|
|
|
2018-10-12 19:37:37 +08:00
|
|
|
/**
|
2022-10-13 14:26:54 +08:00
|
|
|
* Creates the auto hide title label, only displayed when the dock area is overlayed
|
2022-09-08 14:43:18 +08:00
|
|
|
*/
|
2022-10-13 14:26:54 +08:00
|
|
|
void createAutoHideTitleLabel();
|
2022-09-08 14:43:18 +08:00
|
|
|
|
|
|
|
/**
|
2018-10-12 19:37:37 +08:00
|
|
|
* 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
|
|
|
|
2022-09-12 15:55:45 +08:00
|
|
|
/**
|
|
|
|
* Returns true if the given config flag is set
|
|
|
|
* Convenience function to ease config flag testing
|
|
|
|
*/
|
2022-11-01 21:36:09 +08:00
|
|
|
static bool testAutoHideConfigFlag(CDockManager::eAutoHideFlag Flag)
|
2022-09-12 15:55:45 +08:00
|
|
|
{
|
2022-11-01 21:36:09 +08:00
|
|
|
return CDockManager::testAutoHideConfigFlag(Flag);
|
2022-09-12 15:55:45 +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);
|
2022-11-03 22:28:01 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to create and initialize the menu entries for
|
|
|
|
* the "Auto Hide Group To..." menu
|
|
|
|
*/
|
|
|
|
QAction* createAutoHideToAction(const QString& Title, SideBarLocation Location,
|
|
|
|
QMenu* Menu)
|
|
|
|
{
|
|
|
|
auto Action = Menu->addAction(Title);
|
|
|
|
Action->setProperty("Location", Location);
|
|
|
|
QObject::connect(Action, &QAction::triggered, _this, &CDockAreaTitleBar::onAutoHideToActionClicked);
|
|
|
|
return Action;
|
|
|
|
}
|
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
|
|
|
|
2022-09-07 11:54:32 +08:00
|
|
|
// Undock button
|
|
|
|
UndockButton = new CTitleBarButton(testConfigFlag(CDockManager::DockAreaHasUndockButton));
|
|
|
|
UndockButton->setObjectName("detachGroupButton");
|
|
|
|
UndockButton->setAutoRaise(true);
|
|
|
|
internal::setToolTip(UndockButton, QObject::tr("Detach Group"));
|
|
|
|
internal::setButtonIcon(UndockButton, QStyle::SP_TitleBarNormalButton, ads::DockAreaUndockIcon);
|
|
|
|
UndockButton->setSizePolicy(ButtonSizePolicy);
|
|
|
|
Layout->addWidget(UndockButton, 0);
|
|
|
|
_this->connect(UndockButton, SIGNAL(clicked()), SLOT(onUndockButtonClicked()));
|
|
|
|
|
2022-09-05 17:29:42 +08:00
|
|
|
// AutoHide Button
|
2022-11-01 21:36:09 +08:00
|
|
|
const auto autoHideEnabled = testAutoHideConfigFlag(CDockManager::AutoHideFeatureEnabled);
|
|
|
|
AutoHideButton = new CTitleBarButton(testAutoHideConfigFlag(CDockManager::DockAreaHasAutoHideButton) && autoHideEnabled);
|
2022-09-07 11:54:03 +08:00
|
|
|
AutoHideButton->setObjectName("dockAreaAutoHideButton");
|
2022-09-05 17:29:42 +08:00
|
|
|
AutoHideButton->setAutoRaise(true);
|
2022-11-05 17:11:09 +08:00
|
|
|
internal::setToolTip(AutoHideButton, _this->titleBarButtonToolTip(TitleBarButtonAutoHide));
|
2022-09-07 11:54:03 +08:00
|
|
|
internal::setButtonIcon(AutoHideButton, QStyle::SP_DialogOkButton, ads::AutoHideIcon);
|
2022-09-05 17:29:42 +08:00
|
|
|
AutoHideButton->setSizePolicy(ButtonSizePolicy);
|
2022-11-01 21:36:09 +08:00
|
|
|
AutoHideButton->setCheckable(testAutoHideConfigFlag(CDockManager::AutoHideButtonCheckable));
|
2022-10-18 17:21:10 +08:00
|
|
|
AutoHideButton->setChecked(false);
|
2022-09-05 17:29:42 +08:00
|
|
|
Layout->addWidget(AutoHideButton, 0);
|
2022-10-17 20:22:12 +08:00
|
|
|
_this->connect(AutoHideButton, SIGNAL(clicked()), SLOT(onAutoHideButtonClicked()));
|
2022-09-05 17:29:42 +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);
|
2022-11-05 17:11:09 +08:00
|
|
|
internal::setToolTip(CloseButton, _this->titleBarButtonToolTip(TitleBarButtonClose));
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-08 14:43:18 +08:00
|
|
|
//============================================================================
|
2022-10-13 14:26:54 +08:00
|
|
|
void DockAreaTitleBarPrivate::createAutoHideTitleLabel()
|
2022-09-08 14:43:18 +08:00
|
|
|
{
|
2022-10-13 14:26:54 +08:00
|
|
|
AutoHideTitleLabel = new CElidingLabel("");
|
|
|
|
AutoHideTitleLabel->setObjectName("autoHideTitleLabel");
|
|
|
|
Layout->addWidget(AutoHideTitleLabel);
|
2022-09-08 14:43:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2023-01-20 18:50:34 +08:00
|
|
|
bool CreateFloatingDockContainer = (DraggingFloatingWidget != DragState);
|
2020-02-07 19:16:26 +08:00
|
|
|
CFloatingDockContainer* FloatingDockContainer = nullptr;
|
|
|
|
IFloatingWidget* FloatingWidget;
|
2023-01-20 16:44:18 +08:00
|
|
|
if (CreateFloatingDockContainer)
|
2020-02-07 19:16:26 +08:00
|
|
|
{
|
2023-01-20 16:44:18 +08:00
|
|
|
if (DockArea->autoHideDockContainer())
|
|
|
|
{
|
|
|
|
DockArea->autoHideDockContainer()->cleanupAndDelete();
|
|
|
|
}
|
2020-02-07 19:16:26 +08:00
|
|
|
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)
|
|
|
|
{
|
2023-01-20 16:44:18 +08:00
|
|
|
if (DockArea->autoHideDockContainer())
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
2022-10-13 14:26:54 +08:00
|
|
|
DockArea->autoHideDockContainer()->hide();
|
2022-09-05 17:29:42 +08:00
|
|
|
}
|
2020-02-07 19:16:26 +08:00
|
|
|
FloatingWidget = makeAreaFloating(Offset, DraggingFloatingWidget);
|
2022-11-22 18:11:49 +08:00
|
|
|
qApp->postEvent(DockArea, new QEvent((QEvent::Type)internal::DockedWidgetDragStartEvent));
|
2020-02-07 19:16:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
2022-10-13 14:26:54 +08:00
|
|
|
d->createAutoHideTitleLabel();
|
|
|
|
d->AutoHideTitleLabel->setVisible(false); // Default hidden
|
2020-02-08 05:49:10 +08:00
|
|
|
d->Layout->addWidget(new CSpacerWidget(this));
|
2018-10-12 19:37:37 +08:00
|
|
|
d->createButtons();
|
2020-07-13 14:41:30 +08:00
|
|
|
|
|
|
|
setFocusPolicy(Qt::NoFocus);
|
2018-10-12 19:37:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
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");
|
2023-04-28 15:27:22 +08:00
|
|
|
if (CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideCloseButtonCollapsesDock) &&
|
|
|
|
d->DockArea->autoHideDockContainer())
|
|
|
|
{
|
|
|
|
d->DockArea->autoHideDockContainer()->collapseView(true);
|
|
|
|
}
|
|
|
|
else if (d->testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
|
2018-11-08 19:57:25 +08:00
|
|
|
{
|
|
|
|
d->TabBar->closeTab(d->TabBar->currentIndex());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d->DockArea->closeArea();
|
|
|
|
}
|
2018-10-12 19:37:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-19 15:10:26 +08:00
|
|
|
//============================================================================
|
|
|
|
void CDockAreaTitleBar::onAutoHideCloseActionTriggered()
|
|
|
|
{
|
|
|
|
d->DockArea->closeArea();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockAreaTitleBar::onAutoHideMinimizeActionTriggered()
|
|
|
|
{
|
|
|
|
auto AutoHideContainer = d->DockArea->autoHideDockContainer();
|
|
|
|
if (AutoHideContainer)
|
|
|
|
{
|
|
|
|
AutoHideContainer->collapseView(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
2021-01-22 13:18:34 +08:00
|
|
|
Q_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
|
|
|
{
|
2022-11-19 04:12:17 +08:00
|
|
|
auto Tab = d->TabBar->currentTab();
|
|
|
|
if (!Tab)
|
2022-09-09 13:33:42 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-19 04:12:17 +08:00
|
|
|
CDockWidget* DockWidget = Tab->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();
|
|
|
|
}
|
|
|
|
|
2022-09-06 13:49:11 +08:00
|
|
|
|
|
|
|
//============================================================================
|
2022-10-17 20:22:12 +08:00
|
|
|
void CDockAreaTitleBar::onAutoHideButtonClicked()
|
2022-09-05 17:29:42 +08:00
|
|
|
{
|
2022-11-05 17:11:09 +08:00
|
|
|
if (CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideButtonTogglesArea)
|
|
|
|
|| qApp->keyboardModifiers().testFlag(Qt::ControlModifier))
|
2022-11-02 19:45:45 +08:00
|
|
|
{
|
|
|
|
d->DockArea->toggleAutoHide();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d->DockArea->currentDockWidget()->toggleAutoHide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
2022-11-02 21:29:23 +08:00
|
|
|
void CDockAreaTitleBar::onAutoHideDockAreaActionClicked()
|
2022-11-02 19:45:45 +08:00
|
|
|
{
|
|
|
|
d->DockArea->toggleAutoHide();
|
2022-09-05 17:29:42 +08:00
|
|
|
}
|
|
|
|
|
2020-02-06 16:15:13 +08:00
|
|
|
|
2022-11-03 22:28:01 +08:00
|
|
|
//============================================================================
|
|
|
|
void CDockAreaTitleBar::onAutoHideToActionClicked()
|
|
|
|
{
|
|
|
|
int Location = sender()->property(LocationProperty).toInt();
|
|
|
|
d->DockArea->toggleAutoHide((SideBarLocation)Location);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-04 03:51:02 +08:00
|
|
|
//============================================================================
|
2023-07-11 14:25:34 +08:00
|
|
|
CTitleBarButton* CDockAreaTitleBar::button(TitleBarButton which) const
|
2018-11-04 03:51:02 +08:00
|
|
|
{
|
|
|
|
switch (which)
|
|
|
|
{
|
|
|
|
case TitleBarButtonTabsMenu: return d->TabsMenuButton;
|
|
|
|
case TitleBarButtonUndock: return d->UndockButton;
|
|
|
|
case TitleBarButtonClose: return d->CloseButton;
|
2022-09-05 17:29:42 +08:00
|
|
|
case TitleBarButtonAutoHide: return d->AutoHideButton;
|
2018-11-04 03:51:02 +08:00
|
|
|
default:
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-08 14:43:18 +08:00
|
|
|
|
|
|
|
//============================================================================
|
2022-10-13 14:26:54 +08:00
|
|
|
CElidingLabel* CDockAreaTitleBar::autoHideTitleLabel() const
|
2022-09-08 14:43:18 +08:00
|
|
|
{
|
2022-10-13 14:26:54 +08:00
|
|
|
return d->AutoHideTitleLabel;
|
2022-09-08 14:43:18 +08:00
|
|
|
}
|
|
|
|
|
2018-11-04 03:51:02 +08:00
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
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
|
|
|
{
|
2021-07-26 00:12:27 +08:00
|
|
|
d->dockManager()->dockFocusController()->setDockWidgetTabFocused(d->TabBar->currentTab());
|
2020-06-06 20:59:03 +08:00
|
|
|
}
|
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()
|
2022-09-05 17:29:42 +08:00
|
|
|
&& d->DockArea->dockContainer()->visibleDockAreaCount() == 1
|
2022-10-13 14:26:54 +08:00
|
|
|
&& !d->DockArea->isAutoHide())
|
2020-02-07 19:16:26 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If one single dock widget in this area is not floatable then the whole
|
|
|
|
// area is not floatable
|
2023-01-20 18:50:34 +08:00
|
|
|
// We can create the floating drag preview if the dock widget is movable
|
2020-02-16 21:37:14 +08:00
|
|
|
auto Features = d->DockArea->features();
|
2023-01-20 18:50:34 +08:00
|
|
|
if (!Features.testFlag(CDockWidget::DockWidgetFloatable) && !(Features.testFlag(CDockWidget::DockWidgetMovable)))
|
2020-02-07 19:16:26 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DragDistance = (d->DragStartMousePos - ev->pos()).manhattanLength();
|
|
|
|
if (DragDistance >= CDockManager::startDragDistance())
|
|
|
|
{
|
2022-10-13 14:26:54 +08:00
|
|
|
ADS_PRINT("CDockAreaTitleBar::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;
|
|
|
|
}
|
2022-10-13 14:37:39 +08:00
|
|
|
|
2020-02-07 19:16:26 +08:00
|
|
|
d->makeAreaFloating(event->pos(), DraggingInactive);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-07 17:21:54 +08:00
|
|
|
//============================================================================
|
|
|
|
void CDockAreaTitleBar::setAreaFloating()
|
|
|
|
{
|
|
|
|
// 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
|
2023-07-10 16:10:37 +08:00
|
|
|
// empty.
|
|
|
|
auto DockContainer = d->DockArea->dockContainer();
|
|
|
|
if (DockContainer->isFloating() && DockContainer->dockAreaCount() == 1
|
|
|
|
&& !d->DockArea->isAutoHide())
|
2023-07-07 17:21:54 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->makeAreaFloating(mapFromGlobal(QCursor::pos()), DraggingInactive);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-07 19:23:26 +08:00
|
|
|
//============================================================================
|
|
|
|
void CDockAreaTitleBar::contextMenuEvent(QContextMenuEvent* ev)
|
|
|
|
{
|
|
|
|
ev->accept();
|
|
|
|
if (d->isDraggingState(DraggingFloatingWidget))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-03 23:44:40 +08:00
|
|
|
const bool isAutoHide = d->DockArea->isAutoHide();
|
|
|
|
const bool isTopLevelArea = d->DockArea->isTopLevelArea();
|
2022-11-02 20:06:42 +08:00
|
|
|
QAction* Action;
|
2020-02-07 19:23:26 +08:00
|
|
|
QMenu Menu(this);
|
2022-11-03 23:44:40 +08:00
|
|
|
if (!isTopLevelArea)
|
2022-11-02 20:06:42 +08:00
|
|
|
{
|
2022-11-03 23:44:40 +08:00
|
|
|
Action = Menu.addAction(isAutoHide ? tr("Detach") : tr("Detach Group"),
|
2022-11-02 20:06:42 +08:00
|
|
|
this, SLOT(onUndockButtonClicked()));
|
|
|
|
Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable));
|
|
|
|
if (CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideFeatureEnabled))
|
|
|
|
{
|
2022-11-05 17:11:09 +08:00
|
|
|
Action = Menu.addAction(isAutoHide ? tr("Unpin (Dock)") : tr("Pin Group"), this, SLOT(onAutoHideDockAreaActionClicked()));
|
2022-11-03 22:28:01 +08:00
|
|
|
auto AreaIsPinnable = d->DockArea->features().testFlag(CDockWidget::DockWidgetPinnable);
|
|
|
|
Action->setEnabled(AreaIsPinnable);
|
|
|
|
|
2022-11-03 23:44:40 +08:00
|
|
|
if (!isAutoHide)
|
2022-11-03 22:28:01 +08:00
|
|
|
{
|
2022-11-05 17:11:09 +08:00
|
|
|
auto menu = Menu.addMenu(tr("Pin Group To..."));
|
2022-11-03 22:28:01 +08:00
|
|
|
menu->setEnabled(AreaIsPinnable);
|
|
|
|
d->createAutoHideToAction(tr("Top"), SideBarTop, menu);
|
|
|
|
d->createAutoHideToAction(tr("Left"), SideBarLeft, menu);
|
|
|
|
d->createAutoHideToAction(tr("Right"), SideBarRight, menu);
|
|
|
|
d->createAutoHideToAction(tr("Bottom"), SideBarBottom, menu);
|
|
|
|
}
|
2022-11-02 20:06:42 +08:00
|
|
|
}
|
|
|
|
Menu.addSeparator();
|
|
|
|
}
|
2023-10-19 15:10:26 +08:00
|
|
|
|
|
|
|
if (isAutoHide)
|
|
|
|
{
|
|
|
|
Action = Menu.addAction(tr("Minimize"), this, SLOT(onAutoHideMinimizeActionTriggered()));
|
|
|
|
Action = Menu.addAction(tr("Close"), this, SLOT(onAutoHideCloseActionTriggered()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Action = Menu.addAction(isAutoHide ? tr("Close") : tr("Close Group"), this, SLOT(onCloseButtonClicked()));
|
|
|
|
}
|
|
|
|
|
2020-02-07 19:23:26 +08:00
|
|
|
Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetClosable));
|
2022-11-03 23:44:40 +08:00
|
|
|
if (!isAutoHide && !isTopLevelArea)
|
2022-11-02 19:45:45 +08:00
|
|
|
{
|
2022-11-02 20:06:42 +08:00
|
|
|
Action = Menu.addAction(tr("Close Other Groups"), d->DockArea, SLOT(closeOtherAreas()));
|
2022-11-02 19:45:45 +08:00
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
2022-09-09 14:43:59 +08:00
|
|
|
//============================================================================
|
2022-11-05 17:11:09 +08:00
|
|
|
QString CDockAreaTitleBar::titleBarButtonToolTip(TitleBarButton Button) const
|
2022-09-09 14:43:59 +08:00
|
|
|
{
|
2022-11-05 17:11:09 +08:00
|
|
|
switch (Button)
|
2022-09-09 14:43:59 +08:00
|
|
|
{
|
2022-11-05 17:11:09 +08:00
|
|
|
case TitleBarButtonAutoHide:
|
|
|
|
if (d->DockArea->isAutoHide())
|
|
|
|
{
|
|
|
|
return tr("Unpin (Dock)");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideButtonTogglesArea))
|
|
|
|
{
|
|
|
|
return tr("Pin Group");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return tr("Pin Active Tab (Press Ctrl to Pin Group)");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TitleBarButtonClose:
|
|
|
|
if (d->DockArea->isAutoHide())
|
|
|
|
{
|
2023-10-19 15:10:26 +08:00
|
|
|
bool Minimize = CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideCloseButtonCollapsesDock);
|
|
|
|
return Minimize ? tr("Minimize") : tr("Close");
|
2022-11-05 17:11:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (CDockManager::testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
|
|
|
|
{
|
|
|
|
return tr("Close Active Tab");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return tr("Close Group");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2022-09-09 14:43:59 +08:00
|
|
|
}
|
|
|
|
|
2022-11-05 17:11:09 +08:00
|
|
|
return QString();
|
2022-09-09 14:43:59 +08:00
|
|
|
}
|
|
|
|
|
2020-05-13 14:04:50 +08:00
|
|
|
//============================================================================
|
2023-07-11 14:25:34 +08:00
|
|
|
CTitleBarButton::CTitleBarButton(bool showInTitleBar, QWidget* parent)
|
2020-06-11 14:06:37 +08:00
|
|
|
: tTitleBarButton(parent),
|
2023-07-11 14:25:34 +08:00
|
|
|
ShowInTitleBar(showInTitleBar),
|
2020-06-11 14:06:37 +08:00
|
|
|
HideWhenDisabled(CDockManager::testConfigFlag(CDockManager::DockAreaHideDisabledButtons))
|
2020-05-13 14:04:50 +08:00
|
|
|
{
|
2020-07-13 14:41:30 +08:00
|
|
|
setFocusPolicy(Qt::NoFocus);
|
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)
|
|
|
|
{
|
2023-08-09 01:46:12 +08:00
|
|
|
// 'visible' can stay 'true' if and only if this button is configured to generally visible:
|
2023-07-11 14:25:34 +08:00
|
|
|
visible = visible && this->ShowInTitleBar;
|
2020-05-13 14:04:50 +08:00
|
|
|
|
|
|
|
// '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);
|
|
|
|
}
|
|
|
|
|
2023-07-11 14:25:34 +08:00
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CTitleBarButton::setShowInTitleBar(bool Show)
|
|
|
|
{
|
|
|
|
this->ShowInTitleBar = Show;
|
|
|
|
if (!Show)
|
|
|
|
{
|
|
|
|
setVisible(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-13 14:04:50 +08:00
|
|
|
//============================================================================
|
|
|
|
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
|