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-10-15 14:29:30 +08:00
|
|
|
#include <QStyleOptionButton>
|
2018-11-02 16:19:53 +08:00
|
|
|
#include <QPainter>
|
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"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
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;
|
|
|
|
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-02 16:19:53 +08:00
|
|
|
|
|
|
|
QPixmap createTransparentPixmap(const QPixmap& Source);
|
2018-10-12 19:37:37 +08:00
|
|
|
};// struct DockAreaTitleBarPrivate
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
DockAreaTitleBarPrivate::DockAreaTitleBarPrivate(CDockAreaTitleBar* _public) :
|
|
|
|
_this(_public)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-02 16:19:53 +08:00
|
|
|
//============================================================================
|
|
|
|
QPixmap DockAreaTitleBarPrivate::createTransparentPixmap(const QPixmap& Source)
|
|
|
|
{
|
|
|
|
QPixmap disabledPixmap(Source.size());
|
|
|
|
disabledPixmap.fill(Qt::transparent);
|
|
|
|
QPainter p(&disabledPixmap);
|
|
|
|
p.setOpacity(0.25);
|
|
|
|
p.drawPixmap(0, 0, Source);
|
|
|
|
return disabledPixmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-12 19:37:37 +08:00
|
|
|
//============================================================================
|
|
|
|
void DockAreaTitleBarPrivate::createButtons()
|
|
|
|
{
|
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);
|
2018-10-12 19:37:37 +08:00
|
|
|
TabsMenuButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarUnshadeButton));
|
|
|
|
TabsMenuButton->setMaximumWidth(TabsMenuButton->iconSize().width());
|
|
|
|
|
|
|
|
QMenu* TabsMenu = new QMenu(TabsMenuButton);
|
|
|
|
_this->connect(TabsMenu, SIGNAL(aboutToShow()), SLOT(onTabsMenuAboutToShow()));
|
|
|
|
TabsMenuButton->setMenu(TabsMenu);
|
|
|
|
TopLayout->addWidget(TabsMenuButton, 0);
|
2018-10-15 21:09:59 +08:00
|
|
|
TabsMenuButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
2018-10-12 19:37:37 +08:00
|
|
|
_this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)),
|
|
|
|
SLOT(onTabsMenuActionTriggered(QAction*)));
|
|
|
|
|
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);
|
2018-11-02 16:19:53 +08:00
|
|
|
|
|
|
|
// The standard icons do does not look good on high DPI screens
|
|
|
|
QIcon CloseIcon = _this->style()->standardIcon(QStyle::SP_TitleBarCloseButton);
|
|
|
|
QPixmap normalPixmap = _this->style()->standardPixmap(QStyle::SP_TitleBarCloseButton, 0, CloseButton);
|
|
|
|
QPixmap disabledPixmap = createTransparentPixmap(normalPixmap);
|
|
|
|
CloseIcon.addPixmap(disabledPixmap, QIcon::Disabled);
|
|
|
|
|
2018-10-31 06:45:59 +08:00
|
|
|
CloseButton->setIcon(CloseIcon);
|
2018-10-12 19:37:37 +08:00
|
|
|
CloseButton->setToolTip(QObject::tr("Close"));
|
2018-10-15 21:09:59 +08:00
|
|
|
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
2018-10-12 19:37:37 +08:00
|
|
|
TopLayout->addWidget(CloseButton, 0);
|
|
|
|
_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-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());
|
|
|
|
Action->setData(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
d->MenuOutdated = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
void CDockAreaTitleBar::onCloseButtonClicked()
|
|
|
|
{
|
|
|
|
qDebug() << "CDockAreaTitleBar::onCloseButtonClicked";
|
|
|
|
d->TabBar->closeTab(d->TabBar->currentIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
CDockWidget* DockWidget = d->TabBar->tab(Index)->dockWidget();
|
2018-10-31 06:45:59 +08:00
|
|
|
d->CloseButton->setEnabled(DockWidget->features().testFlag(CDockWidget::DockWidgetClosable));
|
2018-10-12 20:51:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-12 19:37:37 +08:00
|
|
|
} // namespace ads
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// EOF DockAreaTitleBar.cpp
|