mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-25 23:51:33 +08:00
Added access functions for the titlebar buttons
This commit is contained in:
parent
0ac19ebdfb
commit
72ec61a043
@ -214,17 +214,25 @@ void CDockAreaTabBar::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaTabBar::startFloating(const QPoint& Pos)
|
||||
CFloatingDockContainer* CDockAreaTabBar::makeAreaFloating(const QPoint& Pos)
|
||||
{
|
||||
QSize Size = d->DockArea->size();
|
||||
CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(d->DockArea);
|
||||
FloatingWidget->startFloating(Pos, Size);
|
||||
d->FloatingWidget = FloatingWidget;
|
||||
auto TopLevelDockWidget = d->FloatingWidget->topLevelDockWidget();
|
||||
auto TopLevelDockWidget = FloatingWidget->topLevelDockWidget();
|
||||
if (TopLevelDockWidget)
|
||||
{
|
||||
TopLevelDockWidget->emitTopLevelChanged(true);
|
||||
}
|
||||
|
||||
return FloatingWidget;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaTabBar::startFloating(const QPoint& Pos)
|
||||
{
|
||||
d->FloatingWidget = makeAreaFloating(Pos);
|
||||
}
|
||||
|
||||
|
||||
|
@ -36,6 +36,8 @@ namespace ads
|
||||
class CDockAreaWidget;
|
||||
class CDockWidgetTab;
|
||||
struct DockAreaTabBarPrivate;
|
||||
class CDockAreaTitleBar;
|
||||
class CFloatingDockContainer;
|
||||
|
||||
/**
|
||||
* Custom tabbar implementation for tab area that is shown on top of a
|
||||
@ -48,6 +50,7 @@ class CDockAreaTabBar : public QScrollArea
|
||||
private:
|
||||
DockAreaTabBarPrivate* d; ///< private data (pimpl)
|
||||
friend class DockAreaTabBarPrivate;
|
||||
friend class CDockAreaTitleBar;
|
||||
|
||||
private slots:
|
||||
void onTabClicked();
|
||||
@ -81,6 +84,12 @@ protected:
|
||||
*/
|
||||
void startFloating(const QPoint& Pos);
|
||||
|
||||
/**
|
||||
* Makes the dock area loating
|
||||
*/
|
||||
CFloatingDockContainer* makeAreaFloating(const QPoint& Pos);
|
||||
|
||||
|
||||
public:
|
||||
using Super = QScrollArea;
|
||||
/**
|
||||
|
@ -41,6 +41,7 @@ struct DockAreaTitleBarPrivate
|
||||
{
|
||||
CDockAreaTitleBar* _this;
|
||||
tTileBarButton* TabsMenuButton;
|
||||
tTileBarButton* UndockButton;
|
||||
tTileBarButton* CloseButton;
|
||||
QBoxLayout* TopLayout;
|
||||
CDockAreaWidget* DockArea;
|
||||
@ -106,6 +107,15 @@ void DockAreaTitleBarPrivate::createButtons()
|
||||
_this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)),
|
||||
SLOT(onTabsMenuActionTriggered(QAction*)));
|
||||
|
||||
// Undock button
|
||||
UndockButton = new tTileBarButton();
|
||||
UndockButton->setObjectName("undockButton");
|
||||
UndockButton->setAutoRaise(true);
|
||||
UndockButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarNormalButton));
|
||||
UndockButton->setMaximumWidth(UndockButton->iconSize().width());
|
||||
TopLayout->addWidget(UndockButton, 0);
|
||||
_this->connect(UndockButton, SIGNAL(clicked()), SLOT(onUndockButtonClicked()));
|
||||
|
||||
CloseButton = new tTileBarButton();
|
||||
CloseButton->setObjectName("closeButton");
|
||||
CloseButton->setAutoRaise(true);
|
||||
@ -213,6 +223,14 @@ void CDockAreaTitleBar::onCloseButtonClicked()
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaTitleBar::onUndockButtonClicked()
|
||||
{
|
||||
std::cout << "CDockAreaTitleBar::onUndockButtonClicked" << std::endl;
|
||||
d->TabBar->makeAreaFloating(mapFromGlobal(QCursor::pos()));
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockAreaTitleBar::onTabsMenuActionTriggered(QAction* Action)
|
||||
{
|
||||
@ -230,6 +248,27 @@ void CDockAreaTitleBar::onCurrentTabChanged(int Index)
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
} // namespace ads
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -32,6 +32,10 @@
|
||||
//============================================================================
|
||||
#include <QFrame>
|
||||
|
||||
#include "ads_globals.h"
|
||||
|
||||
class QAbstractButton;
|
||||
|
||||
namespace ads
|
||||
{
|
||||
class CDockAreaTabBar;
|
||||
@ -52,6 +56,7 @@ private slots:
|
||||
void markTabsMenuOutdated();
|
||||
void onTabsMenuAboutToShow();
|
||||
void onCloseButtonClicked();
|
||||
void onUndockButtonClicked();
|
||||
void onTabsMenuActionTriggered(QAction* Action);
|
||||
void onCurrentTabChanged(int Index);
|
||||
|
||||
@ -72,6 +77,13 @@ public:
|
||||
*/
|
||||
CDockAreaTabBar* tabBar() const;
|
||||
|
||||
/**
|
||||
* Returns the button corresponding to the given title bar button identifier
|
||||
*/
|
||||
QAbstractButton* button(TitleBarButton which) const;
|
||||
|
||||
virtual void setVisible(bool Visible) override;
|
||||
|
||||
signals:
|
||||
/**
|
||||
* This signal is emitted if a tab in the tab bar is clicked by the user
|
||||
|
@ -258,7 +258,7 @@ struct DockAreaWidgetPrivate
|
||||
* Updates the tab bar visibility depending on the number of dock widgets
|
||||
* in this area
|
||||
*/
|
||||
void updateTabBar();
|
||||
void updateTitleBarVisibility();
|
||||
|
||||
/**
|
||||
* Convenience function for tabbar access
|
||||
@ -294,7 +294,7 @@ void DockAreaWidgetPrivate::createTitleBar()
|
||||
|
||||
|
||||
//============================================================================
|
||||
void DockAreaWidgetPrivate::updateTabBar()
|
||||
void DockAreaWidgetPrivate::updateTitleBarVisibility()
|
||||
{
|
||||
CDockContainerWidget* Container = _this->dockContainer();
|
||||
if (!Container)
|
||||
@ -358,7 +358,11 @@ void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget,
|
||||
d->ContentsLayout->insertWidget(index, DockWidget);
|
||||
DockWidget->tabWidget()->setDockAreaWidget(this);
|
||||
auto TabWidget = DockWidget->tabWidget();
|
||||
// Inserting the tab will change the current index which in turn will
|
||||
// make the tab widget visible in the slot
|
||||
d->tabBar()->blockSignals(true);
|
||||
d->tabBar()->insertTab(index, TabWidget);
|
||||
d->tabBar()->blockSignals(false);
|
||||
TabWidget->setVisible(!DockWidget->isClosed());
|
||||
DockWidget->setProperty(INDEX_PROPERTY, index);
|
||||
if (Activate)
|
||||
@ -398,7 +402,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
|
||||
hideAreaWithNoVisibleContent();
|
||||
}
|
||||
|
||||
d->updateTabBar();
|
||||
d->updateTitleBarVisibility();
|
||||
auto TopLevelDockWidget = dockContainer()->topLevelDockWidget();
|
||||
if (TopLevelDockWidget)
|
||||
{
|
||||
@ -415,6 +419,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
|
||||
//============================================================================
|
||||
void CDockAreaWidget::hideAreaWithNoVisibleContent()
|
||||
{
|
||||
std::cout << "CDockAreaWidget::hideAreaWithNoVisibleContent()" << std::endl;
|
||||
this->toggleView(false);
|
||||
|
||||
// Hide empty parent splitter
|
||||
@ -430,9 +435,21 @@ void CDockAreaWidget::hideAreaWithNoVisibleContent()
|
||||
|
||||
//Hide empty floating widget
|
||||
CDockContainerWidget* Container = this->dockContainer();
|
||||
if (Container->isFloating() && Container->openedDockAreas().isEmpty())
|
||||
if (!Container->isFloating())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
d->updateTitleBarVisibility();
|
||||
auto TopLevelWidget = Container->topLevelDockWidget();
|
||||
auto FloatingWidget = Container->floatingWidget();
|
||||
if (TopLevelWidget)
|
||||
{
|
||||
FloatingWidget->updateWindowTitle();
|
||||
CDockWidget::emitTopLevelEventForWidget(TopLevelWidget, true);
|
||||
}
|
||||
else if (Container->openedDockAreas().isEmpty())
|
||||
{
|
||||
CFloatingDockContainer* FloatingWidget = internal::findParent<CFloatingDockContainer*>(Container);
|
||||
FloatingWidget->hide();
|
||||
}
|
||||
}
|
||||
@ -449,7 +466,13 @@ void CDockAreaWidget::onTabCloseRequested(int Index)
|
||||
//============================================================================
|
||||
CDockWidget* CDockAreaWidget::currentDockWidget() const
|
||||
{
|
||||
return dockWidget(currentIndex());
|
||||
int CurrentIndex = currentIndex();
|
||||
if (CurrentIndex < 0)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return dockWidget(CurrentIndex);
|
||||
}
|
||||
|
||||
|
||||
@ -576,7 +599,7 @@ int CDockAreaWidget::dockWidgetsCount() const
|
||||
//============================================================================
|
||||
CDockWidget* CDockAreaWidget::dockWidget(int Index) const
|
||||
{
|
||||
return dynamic_cast<CDockWidget*>(d->ContentsLayout->widget(Index));
|
||||
return qobject_cast<CDockWidget*>(d->ContentsLayout->widget(Index));
|
||||
}
|
||||
|
||||
|
||||
@ -610,7 +633,7 @@ void CDockAreaWidget::toggleDockWidgetView(CDockWidget* DockWidget, bool Open)
|
||||
//============================================================================
|
||||
void CDockAreaWidget::updateTabBarVisibility()
|
||||
{
|
||||
d->updateTabBar();
|
||||
d->updateTitleBarVisibility();
|
||||
}
|
||||
|
||||
|
||||
@ -619,9 +642,11 @@ void CDockAreaWidget::saveState(QXmlStreamWriter& s) const
|
||||
{
|
||||
s.writeStartElement("DockAreaWidget");
|
||||
s.writeAttribute("Tabs", QString::number(d->ContentsLayout->count()));
|
||||
s.writeAttribute("CurrentDockWidget", currentDockWidget()->objectName());
|
||||
auto CurrentDockWidget = currentDockWidget();
|
||||
QString Name = CurrentDockWidget ? CurrentDockWidget->objectName() : "";
|
||||
s.writeAttribute("CurrentDockWidget", Name);
|
||||
qDebug() << "CDockAreaWidget::saveState TabCount: " << d->ContentsLayout->count()
|
||||
<< " CurrentDockWidge: " << currentDockWidget()->objectName();
|
||||
<< " CurrentDockWidge: " << Name;
|
||||
for (int i = 0; i < d->ContentsLayout->count(); ++i)
|
||||
{
|
||||
dockWidget(i)->saveState(s);
|
||||
@ -675,6 +700,13 @@ void CDockAreaWidget::toggleView(bool Open)
|
||||
setVisible(Open);
|
||||
emit viewToggled(Open);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QAbstractButton* CDockAreaWidget::titleBarButton(TitleBarButton which) const
|
||||
{
|
||||
return d->TitleBar->button(which);
|
||||
}
|
||||
} // namespace ads
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "DockWidget.h"
|
||||
|
||||
class QXmlStreamWriter;
|
||||
class QAbstractButton;
|
||||
|
||||
namespace ads
|
||||
{
|
||||
@ -190,12 +191,14 @@ public:
|
||||
CDockWidget* dockWidget(int Index) const;
|
||||
|
||||
/**
|
||||
* Returns the index of the current active dock widget
|
||||
* Returns the index of the current active dock widget or -1 if there
|
||||
* are is no active dock widget (ie.e if all dock widgets are closed)
|
||||
*/
|
||||
int currentIndex() const;
|
||||
|
||||
/**
|
||||
* Returns the current active dock widget
|
||||
* Returns the current active dock widget or a nullptr if there is no
|
||||
* active dock widget (i.e. if all dock widgets are closed)
|
||||
*/
|
||||
CDockWidget* currentDockWidget() const;
|
||||
|
||||
@ -218,6 +221,12 @@ public:
|
||||
*/
|
||||
CDockWidget::DockWidgetFeatures features() const;
|
||||
|
||||
/**
|
||||
* Returns the title bar button corresponding to the given title bar
|
||||
* button identifier
|
||||
*/
|
||||
QAbstractButton* titleBarButton(TitleBarButton which) const;
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* This activates the tab for the given tab index.
|
||||
|
@ -528,10 +528,6 @@ bool DockContainerWidgetPrivate::restoreDockArea(QXmlStreamReader& s,
|
||||
|
||||
|
||||
QString CurrentDockWidget = s.attributes().value("CurrentDockWidget").toString();
|
||||
if (CurrentDockWidget.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
qDebug() << "Restore NodeDockArea Tabs: " << Tabs << " CurrentDockWidget: "
|
||||
<< CurrentDockWidget;
|
||||
|
||||
|
@ -264,6 +264,11 @@ bool DockManagerPrivate::restoreState(const QByteArray &state, int version)
|
||||
{
|
||||
CDockAreaWidget* DockArea = DockContainer->dockArea(i);
|
||||
QString DockWidgetName = DockArea->property("currentDockWidget").toString();
|
||||
if (DockWidgetName.isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
CDockWidget* DockWidget = _this->findDockWidget(DockWidgetName);
|
||||
if (!DockWidget->isClosed())
|
||||
{
|
||||
@ -272,29 +277,6 @@ bool DockManagerPrivate::restoreState(const QByteArray &state, int version)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Finally we need to send the topLevelChanged() signals for all dock
|
||||
// widgets if top level changed
|
||||
/*for (auto DockContainer : Containers)
|
||||
{
|
||||
CDockWidget* TopLevelDockWidget = DockContainer->topLevelDockWidget();
|
||||
if (TopLevelDockWidget)
|
||||
{
|
||||
TopLevelDockWidget->emitTopLevelChanged(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < DockContainer->dockAreaCount(); ++i)
|
||||
{
|
||||
auto DockArea = DockContainer->dockArea(i);
|
||||
for (auto DockWidget : DockArea->dockWidgets())
|
||||
{
|
||||
DockWidget->emitTopLevelChanged(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -400,10 +400,7 @@ void CDockWidgetTab::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
//============================================================================
|
||||
void CDockWidgetTab::setVisible(bool visible)
|
||||
{
|
||||
/*if (!visible)
|
||||
{
|
||||
qDebug() << "CDockWidgetTab::setVisible " << visible;
|
||||
}*/
|
||||
// Just here for debugging to insert debug output
|
||||
Super::setVisible(visible);
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include <QPointer>
|
||||
#include <QAction>
|
||||
#include <QDebug>
|
||||
#include <QAbstractButton>
|
||||
|
||||
#include "DockContainerWidget.h"
|
||||
#include "DockAreaWidget.h"
|
||||
@ -471,6 +472,7 @@ void CFloatingDockContainer::onDockAreasAddedOrRemoved()
|
||||
if (TopLevelDockArea)
|
||||
{
|
||||
d->SingleDockArea = TopLevelDockArea;
|
||||
d->SingleDockArea->titleBarButton(TitleBarButtonUndock)->setVisible(false);
|
||||
this->setWindowTitle(d->SingleDockArea->currentDockWidget()->windowTitle());
|
||||
connect(d->SingleDockArea, SIGNAL(currentChanged(int)), this,
|
||||
SLOT(onDockAreaCurrentChanged(int)));
|
||||
@ -479,6 +481,7 @@ void CFloatingDockContainer::onDockAreasAddedOrRemoved()
|
||||
{
|
||||
if (d->SingleDockArea)
|
||||
{
|
||||
d->SingleDockArea->titleBarButton(TitleBarButtonUndock)->setVisible(true);
|
||||
disconnect(d->SingleDockArea, SIGNAL(currentChanged(int)), this,
|
||||
SLOT(onDockAreaCurrentChanged(int)));
|
||||
d->SingleDockArea = nullptr;
|
||||
|
@ -69,6 +69,7 @@ private:
|
||||
friend class CDockAreaTitleBar;
|
||||
friend struct DockAreaTitleBarPrivate;
|
||||
friend class CDockWidget;
|
||||
friend class CDockAreaWidget;
|
||||
|
||||
private slots:
|
||||
void onDockAreasAddedOrRemoved();
|
||||
|
@ -61,6 +61,13 @@ enum DockWidgetArea
|
||||
Q_DECLARE_FLAGS(DockWidgetAreas, DockWidgetArea)
|
||||
|
||||
|
||||
enum TitleBarButton
|
||||
{
|
||||
TitleBarButtonTabsMenu,
|
||||
TitleBarButtonUndock,
|
||||
TitleBarButtonClose
|
||||
};
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user