Skip to content

Commit 854f542

Browse files
author
Uwe Kindler
committed
Added global config flags to support different dock manager behaviour
1 parent b9265fc commit 854f542

File tree

5 files changed

+93
-9
lines changed

5 files changed

+93
-9
lines changed

demo/MainWindow.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,17 @@ CMainWindow::CMainWindow(QWidget *parent) :
266266
QMainWindow(parent),
267267
d(new MainWindowPrivate(this))
268268
{
269+
using namespace ads;
269270
d->ui.setupUi(this);
270271
d->createActions();
271272

272273
// Now create the dock manager and its content
273-
d->DockManager = new ads::CDockManager(this);
274+
d->DockManager = new CDockManager(this);
275+
276+
// Uncomment the following line to have the old style where the dock
277+
// area close button closes the active tab
278+
//d->DockManager->setConfigFlags({
279+
// CDockManager::DockAreaHasCloseButton | CDockManager::DockAreaCloseButtonClosesTab});
274280
connect(d->PerspectiveComboBox, SIGNAL(activated(const QString&)),
275281
d->DockManager, SLOT(openPerspective(const QString&)));
276282

@@ -280,8 +286,6 @@ CMainWindow::CMainWindow(QWidget *parent) :
280286

281287
d->restoreState();
282288
d->restorePerspectives();
283-
/*CAnimatedLabel* AnimatedLabel = new CAnimatedLabel();
284-
AnimatedLabel->show();*/
285289
}
286290

287291

src/DockAreaTitleBar.cpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,22 @@ struct DockAreaTitleBarPrivate
8080
* Creates the internal TabBar
8181
*/
8282
void createTabBar();
83+
84+
/**
85+
* Convenience function for DockManager access
86+
*/
87+
CDockManager* dockManager() const
88+
{
89+
return DockArea->dockManager();
90+
}
91+
92+
/**
93+
* Returns true if the given config flag is set
94+
*/
95+
bool testConfigFlag(CDockManager::eConfigFlag Flag) const
96+
{
97+
return DockArea->dockManager()->configFlags().testFlag(Flag);
98+
}
8399
};// struct DockAreaTitleBarPrivate
84100

85101

@@ -133,6 +149,9 @@ void DockAreaTitleBarPrivate::createButtons()
133149
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
134150
TopLayout->addWidget(CloseButton, 0);
135151
_this->connect(CloseButton, SIGNAL(clicked()), SLOT(onCloseButtonClicked()));
152+
153+
CloseButton->setEnabled(testConfigFlag(CDockManager::DockAreaHasCloseButton));
154+
CloseButton->setVisible(CloseButton->isEnabled());
136155
}
137156

138157

@@ -221,8 +240,14 @@ void CDockAreaTitleBar::onTabsMenuAboutToShow()
221240
void CDockAreaTitleBar::onCloseButtonClicked()
222241
{
223242
qDebug() << "CDockAreaTitleBar::onCloseButtonClicked";
224-
//d->TabBar->closeTab(d->TabBar->currentIndex());
225-
d->DockArea->closeArea();
243+
if (d->testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
244+
{
245+
d->TabBar->closeTab(d->TabBar->currentIndex());
246+
}
247+
else
248+
{
249+
d->DockArea->closeArea();
250+
}
226251
}
227252

228253

@@ -249,8 +274,12 @@ void CDockAreaTitleBar::onCurrentTabChanged(int Index)
249274
{
250275
return;
251276
}
252-
/*CDockWidget* DockWidget = d->TabBar->tab(Index)->dockWidget();
253-
d->CloseButton->setEnabled(DockWidget->features().testFlag(CDockWidget::DockWidgetClosable));*/
277+
278+
if (d->testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab))
279+
{
280+
CDockWidget* DockWidget = d->TabBar->tab(Index)->dockWidget();
281+
d->CloseButton->setEnabled(DockWidget->features().testFlag(CDockWidget::DockWidgetClosable));
282+
}
254283
}
255284

256285

src/DockManager.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct DockManagerPrivate
7474
QMenu* ViewMenu;
7575
CDockManager::eViewMenuInsertionOrder MenuInsertionOrder = CDockManager::MenuAlphabeticallySorted;
7676
bool RestoringState = false;
77+
CDockManager::ConfigFlags ConfigFlags{CDockManager::DefaultConfig};
7778

7879
/**
7980
* Private data constructor
@@ -718,6 +719,20 @@ int CDockManager::startDragDistance()
718719
return QApplication::startDragDistance() * 1.5;
719720
}
720721

722+
723+
//===========================================================================
724+
CDockManager::ConfigFlags CDockManager::configFlags() const
725+
{
726+
return d->ConfigFlags;
727+
}
728+
729+
730+
//===========================================================================
731+
void CDockManager::setConfigFlags(const ConfigFlags Flags)
732+
{
733+
d->ConfigFlags = Flags;
734+
}
735+
721736
} // namespace ads
722737

723738
//---------------------------------------------------------------------------

src/DockManager.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,25 @@ class ADS_EXPORT CDockManager : public CDockContainerWidget
114114
XmlAutoFormattingEnabled
115115
};
116116

117+
/**
118+
* These global configuration flags configure some global dock manager
119+
* settings.
120+
*/
121+
enum eConfigFlag
122+
{
123+
ActiveTabHasCloseButton = 0x01, //!< If this flag is set, the active tab in a tab area has a close button
124+
DockAreaHasCloseButton = 0x02, //!< If the flag is set each dock area has a close button
125+
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
126+
DefaultConfig = ActiveTabHasCloseButton | DockAreaHasCloseButton, ///< the default configuration
127+
};
128+
Q_DECLARE_FLAGS(ConfigFlags, eConfigFlag)
129+
117130
/**
118131
* Default Constructor.
119132
* If the given parent is a QMainWindow, the dock manager sets itself as the
120-
* central widget
133+
* central widget.
134+
* Before you create any dock widgets, you should properly setup the
135+
* configuration flags via setConfigFlags()
121136
*/
122137
CDockManager(QWidget* parent = 0);
123138

@@ -126,6 +141,17 @@ class ADS_EXPORT CDockManager : public CDockContainerWidget
126141
*/
127142
virtual ~CDockManager();
128143

144+
/**
145+
* This function returns the global configuration flags
146+
*/
147+
ConfigFlags configFlags() const;
148+
149+
/**
150+
* Sets the global configuration flags for the whole docking system.
151+
* Call this function before you create your first dock widget.
152+
*/
153+
void setConfigFlags(const ConfigFlags Flags);
154+
129155
/**
130156
* Adds dockwidget into the given area.
131157
* If DockAreaWidget is not null, then the area parameter indicates the area

src/DockWidgetTab.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ struct DockWidgetTabPrivate
123123
* is not possible for any reason
124124
*/
125125
bool startFloating();
126+
127+
/**
128+
* Returns true if the given config flag is set
129+
*/
130+
bool testConfigFlag(CDockManager::eConfigFlag Flag) const
131+
{
132+
return DockArea->dockManager()->configFlags().testFlag(Flag);
133+
}
126134
};
127135
// struct DockWidgetTabPrivate
128136

@@ -347,7 +355,9 @@ bool CDockWidgetTab::isActiveTab() const
347355
//============================================================================
348356
void CDockWidgetTab::setActiveTab(bool active)
349357
{
350-
d->CloseButton->setVisible(active && d->DockWidget->features().testFlag(CDockWidget::DockWidgetClosable));
358+
bool DockWidgetClosable = d->DockWidget->features().testFlag(CDockWidget::DockWidgetClosable);
359+
bool TabHasCloseButton = d->testConfigFlag(CDockManager::ActiveTabHasCloseButton);
360+
d->CloseButton->setVisible(active && DockWidgetClosable && TabHasCloseButton);
351361
if (d->IsActiveTab == active)
352362
{
353363
return;

0 commit comments

Comments
 (0)