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>
|
|
|
|
|
2018-11-08 17:04:29 +08:00
|
|
|
#include "ads_globals.h"
|
2018-10-12 19:37:37 +08:00
|
|
|
#include "FloatingDockContainer.h"
|
|
|
|
#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"
|
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
|
|
|
|
{
|
2018-11-01 16:07:10 +08:00
|
|
|
using tTileBarButton = QToolButton;
|
2018-10-12 19:37:37 +08:00
|
|
|
/**
|
|
|
|
* Private data class of CDockAreaTitleBar class (pimpl)
|
|
|
|
*/
|
|
|
|
struct DockAreaTitleBarPrivate
|
|
|
|
{
|
|
|
|
CDockAreaTitleBar* _this;
|
2018-10-31 06:45:59 +08:00
|
|
|
tTileBarButton* TabsMenuButton;
|
2018-11-04 03:51:02 +08:00
|
|
|
tTileBarButton* UndockButton;
|
2018-10-31 06:45:59 +08:00
|
|
|
tTileBarButton* CloseButton;
|
2018-10-12 19:37:37 +08:00
|
|
|
QBoxLayout* TopLayout;
|
|
|
|
CDockAreaWidget* DockArea;
|
|
|
|
CDockAreaTabBar* TabBar;
|
|
|
|
bool MenuOutdated = true;
|
|
|
|
QMenu* TabsMenu;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
bool testConfigFlag(CDockManager::eConfigFlag Flag) const
|
|
|
|
{
|
2019-09-13 03:15:35 +08:00
|
|
|
return CDockManager::configFlags().testFlag(Flag);
|
2018-11-08 19:57:25 +08:00
|
|
|
}
|
2019-05-14 21:32:50 +08:00
|
|
|
|
|
|
|
/**
|
2019-08-26 13:58:56 +08:00
|
|
|
* Helper function to set title bar button icons depending on operating
|
|
|
|
* system and to avoid duplicated code. On windows the standard icons
|
2019-10-18 14:31:26 +08:00
|
|
|
* are blurry since Qt 5.11 so we need to do some additional steps.
|
|
|
|
* If the global IconPovider of the dockmanager provides a custom
|
|
|
|
* Icon for the given CustomIconId, the this icon will be used.
|
2019-05-14 21:32:50 +08:00
|
|
|
*/
|
2019-10-18 14:31:26 +08:00
|
|
|
void setTitleBarButtonIcon(tTileBarButton* Button, QStyle::StandardPixmap StandarPixmap,
|
|
|
|
ads::eIcon CustomIconId)
|
2019-05-14 21:32:50 +08:00
|
|
|
{
|
2019-10-18 14:31:26 +08:00
|
|
|
// First we try to use custom icons if available
|
|
|
|
QIcon Icon = CDockManager::iconProvider().customIcon(CustomIconId);
|
|
|
|
if (!Icon.isNull())
|
|
|
|
{
|
|
|
|
Button->setIcon(Icon);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-14 21:32:50 +08:00
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
Button->setIcon(_this->style()->standardIcon(StandarPixmap));
|
|
|
|
#else
|
|
|
|
QPixmap normalPixmap = _this->style()->standardPixmap(StandarPixmap, 0, Button);
|
|
|
|
Icon.addPixmap(internal::createTransparentPixmap(normalPixmap, 0.25), QIcon::Disabled);
|
|
|
|
Icon.addPixmap(normalPixmap, QIcon::Normal);
|
|
|
|
Button->setIcon(Icon);
|
|
|
|
#endif
|
|
|
|
}
|
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);
|
2019-05-14 21:32:50 +08:00
|
|
|
// Tabs menu button
|
2018-10-31 06:45:59 +08:00
|
|
|
TabsMenuButton = new tTileBarButton();
|
2018-10-12 19:37:37 +08:00
|
|
|
TabsMenuButton->setObjectName("tabsMenuButton");
|
2018-11-01 16:07:10 +08:00
|
|
|
TabsMenuButton->setAutoRaise(true);
|
|
|
|
TabsMenuButton->setPopupMode(QToolButton::InstantPopup);
|
2019-10-18 14:31:26 +08:00
|
|
|
setTitleBarButtonIcon(TabsMenuButton, QStyle::SP_TitleBarUnshadeButton, ads::DockAreaMenuIcon);
|
2018-10-12 19:37:37 +08:00
|
|
|
QMenu* TabsMenu = new QMenu(TabsMenuButton);
|
2019-08-26 13:58:56 +08:00
|
|
|
#ifndef QT_NO_TOOLTIP
|
2019-01-23 14:43:07 +08:00
|
|
|
TabsMenu->setToolTipsVisible(true);
|
2019-08-26 13:58:56 +08:00
|
|
|
#endif
|
2018-10-12 19:37:37 +08:00
|
|
|
_this->connect(TabsMenu, SIGNAL(aboutToShow()), SLOT(onTabsMenuAboutToShow()));
|
|
|
|
TabsMenuButton->setMenu(TabsMenu);
|
2019-08-26 13:58:56 +08:00
|
|
|
#ifndef QT_NO_TOOLTIP
|
2018-11-09 17:07:56 +08:00
|
|
|
TabsMenuButton->setToolTip(QObject::tr("List all tabs"));
|
2019-08-26 13:58:56 +08:00
|
|
|
#endif
|
2019-09-13 16:25:33 +08:00
|
|
|
TabsMenuButton->setSizePolicy(ButtonSizePolicy);
|
2018-11-07 20:50:43 +08:00
|
|
|
TopLayout->addWidget(TabsMenuButton, 0);
|
2018-10-12 19:37:37 +08:00
|
|
|
_this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)),
|
|
|
|
SLOT(onTabsMenuActionTriggered(QAction*)));
|
|
|
|
|
2019-05-14 21:32:50 +08:00
|
|
|
|
2018-11-04 03:51:02 +08:00
|
|
|
// Undock button
|
|
|
|
UndockButton = new tTileBarButton();
|
|
|
|
UndockButton->setObjectName("undockButton");
|
|
|
|
UndockButton->setAutoRaise(true);
|
2019-08-26 13:58:56 +08:00
|
|
|
#ifndef QT_NO_TOOLTIP
|
2018-11-09 17:07:56 +08:00
|
|
|
UndockButton->setToolTip(QObject::tr("Detach Group"));
|
2019-08-26 13:58:56 +08:00
|
|
|
#endif
|
2019-10-18 14:31:26 +08:00
|
|
|
setTitleBarButtonIcon(UndockButton, QStyle::SP_TitleBarNormalButton, ads::DockAreaUndockIcon);
|
2019-09-13 16:25:33 +08:00
|
|
|
UndockButton->setSizePolicy(ButtonSizePolicy);
|
2018-11-04 03:51:02 +08:00
|
|
|
TopLayout->addWidget(UndockButton, 0);
|
|
|
|
_this->connect(UndockButton, SIGNAL(clicked()), SLOT(onUndockButtonClicked()));
|
|
|
|
|
2019-05-14 21:32:50 +08:00
|
|
|
|
|
|
|
// Close button
|
2018-10-31 06:45:59 +08:00
|
|
|
CloseButton = new tTileBarButton();
|
2018-10-12 19:37:37 +08:00
|
|
|
CloseButton->setObjectName("closeButton");
|
2018-11-01 16:07:10 +08:00
|
|
|
CloseButton->setAutoRaise(true);
|
2019-10-18 14:31:26 +08:00
|
|
|
setTitleBarButtonIcon(CloseButton, QStyle::SP_TitleBarCloseButton, ads::DockAreaCloseIcon);
|
2019-08-26 13:58:56 +08:00
|
|
|
#ifndef QT_NO_TOOLTIP
|
2018-11-09 17:07:56 +08:00
|
|
|
if (testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
|
|
|
|
{
|
|
|
|
CloseButton->setToolTip(QObject::tr("Close Active Tab"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CloseButton->setToolTip(QObject::tr("Close Group"));
|
|
|
|
}
|
2019-08-26 13:58:56 +08:00
|
|
|
#endif
|
2019-09-13 16:25:33 +08:00
|
|
|
CloseButton->setSizePolicy(ButtonSizePolicy);
|
2019-05-10 17:33:26 +08:00
|
|
|
CloseButton->setIconSize(QSize(16, 16));
|
2019-09-13 03:24:48 +08:00
|
|
|
if (testConfigFlag(CDockManager::DockAreaHasCloseButton))
|
|
|
|
{
|
|
|
|
TopLayout->addWidget(CloseButton, 0);
|
|
|
|
}
|
2018-10-12 19:37:37 +08:00
|
|
|
_this->connect(CloseButton, SIGNAL(clicked()), SLOT(onCloseButtonClicked()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void DockAreaTitleBarPrivate::createTabBar()
|
|
|
|
{
|
|
|
|
TabBar = new CDockAreaTabBar(DockArea);
|
|
|
|
TopLayout->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)));
|
2018-12-20 22:29:38 +08:00
|
|
|
|
|
|
|
TabBar->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
_this->connect(TabBar, SIGNAL(customContextMenuRequested(const QPoint&)),
|
|
|
|
SLOT(showContextMenu(const QPoint&)));
|
2018-10-12 19:37:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockAreaTitleBar::CDockAreaTitleBar(CDockAreaWidget* parent) :
|
|
|
|
QFrame(parent),
|
|
|
|
d(new DockAreaTitleBarPrivate(this))
|
|
|
|
{
|
|
|
|
d->DockArea = parent;
|
|
|
|
|
|
|
|
setObjectName("dockAreaTitleBar");
|
|
|
|
d->TopLayout = new QBoxLayout(QBoxLayout::LeftToRight);
|
|
|
|
d->TopLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
d->TopLayout->setSpacing(0);
|
|
|
|
setLayout(d->TopLayout);
|
|
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
|
|
|
|
d->createTabBar();
|
|
|
|
d->createButtons();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockAreaTitleBar::~CDockAreaTitleBar()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
CDockAreaTabBar* CDockAreaTitleBar::tabBar() const
|
|
|
|
{
|
|
|
|
return d->TabBar;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockAreaTitleBar::markTabsMenuOutdated()
|
|
|
|
{
|
|
|
|
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());
|
2019-01-23 14:43:07 +08:00
|
|
|
#ifndef QT_NO_TOOLTIP
|
|
|
|
Action->setToolTip(Tab->toolTip());
|
|
|
|
#endif
|
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))
|
|
|
|
{
|
|
|
|
d->TabBar->makeAreaFloating(mapFromGlobal(QCursor::pos()), DraggingInactive);
|
|
|
|
}
|
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
|
|
|
//============================================================================
|
|
|
|
void CDockAreaTitleBar::onCurrentTabChanged(int Index)
|
|
|
|
{
|
2018-11-04 04:48:35 +08:00
|
|
|
if (Index < 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2018-11-08 19:57:25 +08:00
|
|
|
|
|
|
|
if (d->testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
|
|
|
|
{
|
|
|
|
CDockWidget* DockWidget = d->TabBar->tab(Index)->dockWidget();
|
|
|
|
d->CloseButton->setEnabled(DockWidget->features().testFlag(CDockWidget::DockWidgetClosable));
|
|
|
|
}
|
2018-10-12 20:51:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-20 22:29:38 +08:00
|
|
|
//============================================================================
|
|
|
|
void CDockAreaTitleBar::showContextMenu(const QPoint& pos)
|
|
|
|
{
|
2019-12-16 20:56:20 +08:00
|
|
|
if (d->TabBar->dragState() == DraggingFloatingWidget)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-20 22:29:38 +08:00
|
|
|
QMenu Menu(this);
|
2019-07-11 21:12:39 +08:00
|
|
|
auto Action = Menu.addAction(tr("Detach Area"), this, SLOT(onUndockButtonClicked()));
|
|
|
|
Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable));
|
2018-12-20 22:29:38 +08:00
|
|
|
Menu.addSeparator();
|
2019-07-11 21:12:39 +08:00
|
|
|
Action = Menu.addAction(tr("Close Area"), this, SLOT(onCloseButtonClicked()));
|
2018-12-20 22:29:38 +08:00
|
|
|
Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetClosable));
|
|
|
|
Menu.addAction(tr("Close Other Areas"), d->DockArea, SLOT(closeOtherAreas()));
|
|
|
|
Menu.exec(mapToGlobal(pos));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-12 19:37:37 +08:00
|
|
|
} // namespace ads
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// EOF DockAreaTitleBar.cpp
|