mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-11-15 13:15:43 +08:00
Added global config flags to support different dock manager behaviour
This commit is contained in:
parent
b9265fccec
commit
854f542164
@ -266,11 +266,17 @@ CMainWindow::CMainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
d(new MainWindowPrivate(this))
|
||||
{
|
||||
using namespace ads;
|
||||
d->ui.setupUi(this);
|
||||
d->createActions();
|
||||
|
||||
// Now create the dock manager and its content
|
||||
d->DockManager = new ads::CDockManager(this);
|
||||
d->DockManager = new CDockManager(this);
|
||||
|
||||
// Uncomment the following line to have the old style where the dock
|
||||
// area close button closes the active tab
|
||||
//d->DockManager->setConfigFlags({
|
||||
// CDockManager::DockAreaHasCloseButton | CDockManager::DockAreaCloseButtonClosesTab});
|
||||
connect(d->PerspectiveComboBox, SIGNAL(activated(const QString&)),
|
||||
d->DockManager, SLOT(openPerspective(const QString&)));
|
||||
|
||||
@ -280,8 +286,6 @@ CMainWindow::CMainWindow(QWidget *parent) :
|
||||
|
||||
d->restoreState();
|
||||
d->restorePerspectives();
|
||||
/*CAnimatedLabel* AnimatedLabel = new CAnimatedLabel();
|
||||
AnimatedLabel->show();*/
|
||||
}
|
||||
|
||||
|
||||
|
@ -80,6 +80,22 @@ struct DockAreaTitleBarPrivate
|
||||
* Creates the internal TabBar
|
||||
*/
|
||||
void createTabBar();
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
return DockArea->dockManager()->configFlags().testFlag(Flag);
|
||||
}
|
||||
};// struct DockAreaTitleBarPrivate
|
||||
|
||||
|
||||
@ -133,6 +149,9 @@ void DockAreaTitleBarPrivate::createButtons()
|
||||
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||
TopLayout->addWidget(CloseButton, 0);
|
||||
_this->connect(CloseButton, SIGNAL(clicked()), SLOT(onCloseButtonClicked()));
|
||||
|
||||
CloseButton->setEnabled(testConfigFlag(CDockManager::DockAreaHasCloseButton));
|
||||
CloseButton->setVisible(CloseButton->isEnabled());
|
||||
}
|
||||
|
||||
|
||||
@ -221,8 +240,14 @@ void CDockAreaTitleBar::onTabsMenuAboutToShow()
|
||||
void CDockAreaTitleBar::onCloseButtonClicked()
|
||||
{
|
||||
qDebug() << "CDockAreaTitleBar::onCloseButtonClicked";
|
||||
//d->TabBar->closeTab(d->TabBar->currentIndex());
|
||||
d->DockArea->closeArea();
|
||||
if (d->testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
|
||||
{
|
||||
d->TabBar->closeTab(d->TabBar->currentIndex());
|
||||
}
|
||||
else
|
||||
{
|
||||
d->DockArea->closeArea();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -249,8 +274,12 @@ void CDockAreaTitleBar::onCurrentTabChanged(int Index)
|
||||
{
|
||||
return;
|
||||
}
|
||||
/*CDockWidget* DockWidget = d->TabBar->tab(Index)->dockWidget();
|
||||
d->CloseButton->setEnabled(DockWidget->features().testFlag(CDockWidget::DockWidgetClosable));*/
|
||||
|
||||
if (d->testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
|
||||
{
|
||||
CDockWidget* DockWidget = d->TabBar->tab(Index)->dockWidget();
|
||||
d->CloseButton->setEnabled(DockWidget->features().testFlag(CDockWidget::DockWidgetClosable));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -74,6 +74,7 @@ struct DockManagerPrivate
|
||||
QMenu* ViewMenu;
|
||||
CDockManager::eViewMenuInsertionOrder MenuInsertionOrder = CDockManager::MenuAlphabeticallySorted;
|
||||
bool RestoringState = false;
|
||||
CDockManager::ConfigFlags ConfigFlags{CDockManager::DefaultConfig};
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
@ -718,6 +719,20 @@ int CDockManager::startDragDistance()
|
||||
return QApplication::startDragDistance() * 1.5;
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
CDockManager::ConfigFlags CDockManager::configFlags() const
|
||||
{
|
||||
return d->ConfigFlags;
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
void CDockManager::setConfigFlags(const ConfigFlags Flags)
|
||||
{
|
||||
d->ConfigFlags = Flags;
|
||||
}
|
||||
|
||||
} // namespace ads
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -114,10 +114,25 @@ public:
|
||||
XmlAutoFormattingEnabled
|
||||
};
|
||||
|
||||
/**
|
||||
* These global configuration flags configure some global dock manager
|
||||
* settings.
|
||||
*/
|
||||
enum eConfigFlag
|
||||
{
|
||||
ActiveTabHasCloseButton = 0x01, //!< If this flag is set, the active tab in a tab area has a close button
|
||||
DockAreaHasCloseButton = 0x02, //!< If the flag is set each dock area has a close button
|
||||
DockAreaCloseButtonClosesTab = 0x04,//!< If the flag is set, the dock area close button closes the active tab, if not set, it closes the complete cock area
|
||||
DefaultConfig = ActiveTabHasCloseButton | DockAreaHasCloseButton, ///< the default configuration
|
||||
};
|
||||
Q_DECLARE_FLAGS(ConfigFlags, eConfigFlag)
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
* If the given parent is a QMainWindow, the dock manager sets itself as the
|
||||
* central widget
|
||||
* central widget.
|
||||
* Before you create any dock widgets, you should properly setup the
|
||||
* configuration flags via setConfigFlags()
|
||||
*/
|
||||
CDockManager(QWidget* parent = 0);
|
||||
|
||||
@ -126,6 +141,17 @@ public:
|
||||
*/
|
||||
virtual ~CDockManager();
|
||||
|
||||
/**
|
||||
* This function returns the global configuration flags
|
||||
*/
|
||||
ConfigFlags configFlags() const;
|
||||
|
||||
/**
|
||||
* Sets the global configuration flags for the whole docking system.
|
||||
* Call this function before you create your first dock widget.
|
||||
*/
|
||||
void setConfigFlags(const ConfigFlags Flags);
|
||||
|
||||
/**
|
||||
* Adds dockwidget into the given area.
|
||||
* If DockAreaWidget is not null, then the area parameter indicates the area
|
||||
|
@ -123,6 +123,14 @@ struct DockWidgetTabPrivate
|
||||
* is not possible for any reason
|
||||
*/
|
||||
bool startFloating();
|
||||
|
||||
/**
|
||||
* Returns true if the given config flag is set
|
||||
*/
|
||||
bool testConfigFlag(CDockManager::eConfigFlag Flag) const
|
||||
{
|
||||
return DockArea->dockManager()->configFlags().testFlag(Flag);
|
||||
}
|
||||
};
|
||||
// struct DockWidgetTabPrivate
|
||||
|
||||
@ -347,7 +355,9 @@ bool CDockWidgetTab::isActiveTab() const
|
||||
//============================================================================
|
||||
void CDockWidgetTab::setActiveTab(bool active)
|
||||
{
|
||||
d->CloseButton->setVisible(active && d->DockWidget->features().testFlag(CDockWidget::DockWidgetClosable));
|
||||
bool DockWidgetClosable = d->DockWidget->features().testFlag(CDockWidget::DockWidgetClosable);
|
||||
bool TabHasCloseButton = d->testConfigFlag(CDockManager::ActiveTabHasCloseButton);
|
||||
d->CloseButton->setVisible(active && DockWidgetClosable && TabHasCloseButton);
|
||||
if (d->IsActiveTab == active)
|
||||
{
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user