Skip to content

Commit 72ec61a

Browse files
author
Uwe Kindler
committed
Added access functions for the titlebar buttons
1 parent 0ac19eb commit 72ec61a

12 files changed

+141
-46
lines changed

src/DockAreaTabBar.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,17 +214,25 @@ void CDockAreaTabBar::mouseDoubleClickEvent(QMouseEvent *event)
214214

215215

216216
//============================================================================
217-
void CDockAreaTabBar::startFloating(const QPoint& Pos)
217+
CFloatingDockContainer* CDockAreaTabBar::makeAreaFloating(const QPoint& Pos)
218218
{
219219
QSize Size = d->DockArea->size();
220220
CFloatingDockContainer* FloatingWidget = new CFloatingDockContainer(d->DockArea);
221221
FloatingWidget->startFloating(Pos, Size);
222-
d->FloatingWidget = FloatingWidget;
223-
auto TopLevelDockWidget = d->FloatingWidget->topLevelDockWidget();
222+
auto TopLevelDockWidget = FloatingWidget->topLevelDockWidget();
224223
if (TopLevelDockWidget)
225224
{
226225
TopLevelDockWidget->emitTopLevelChanged(true);
227226
}
227+
228+
return FloatingWidget;
229+
}
230+
231+
232+
//============================================================================
233+
void CDockAreaTabBar::startFloating(const QPoint& Pos)
234+
{
235+
d->FloatingWidget = makeAreaFloating(Pos);
228236
}
229237

230238

src/DockAreaTabBar.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ namespace ads
3636
class CDockAreaWidget;
3737
class CDockWidgetTab;
3838
struct DockAreaTabBarPrivate;
39+
class CDockAreaTitleBar;
40+
class CFloatingDockContainer;
3941

4042
/**
4143
* Custom tabbar implementation for tab area that is shown on top of a
@@ -48,6 +50,7 @@ class CDockAreaTabBar : public QScrollArea
4850
private:
4951
DockAreaTabBarPrivate* d; ///< private data (pimpl)
5052
friend class DockAreaTabBarPrivate;
53+
friend class CDockAreaTitleBar;
5154

5255
private slots:
5356
void onTabClicked();
@@ -81,6 +84,12 @@ private slots:
8184
*/
8285
void startFloating(const QPoint& Pos);
8386

87+
/**
88+
* Makes the dock area loating
89+
*/
90+
CFloatingDockContainer* makeAreaFloating(const QPoint& Pos);
91+
92+
8493
public:
8594
using Super = QScrollArea;
8695
/**

src/DockAreaTitleBar.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct DockAreaTitleBarPrivate
4141
{
4242
CDockAreaTitleBar* _this;
4343
tTileBarButton* TabsMenuButton;
44+
tTileBarButton* UndockButton;
4445
tTileBarButton* CloseButton;
4546
QBoxLayout* TopLayout;
4647
CDockAreaWidget* DockArea;
@@ -106,6 +107,15 @@ void DockAreaTitleBarPrivate::createButtons()
106107
_this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)),
107108
SLOT(onTabsMenuActionTriggered(QAction*)));
108109

110+
// Undock button
111+
UndockButton = new tTileBarButton();
112+
UndockButton->setObjectName("undockButton");
113+
UndockButton->setAutoRaise(true);
114+
UndockButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarNormalButton));
115+
UndockButton->setMaximumWidth(UndockButton->iconSize().width());
116+
TopLayout->addWidget(UndockButton, 0);
117+
_this->connect(UndockButton, SIGNAL(clicked()), SLOT(onUndockButtonClicked()));
118+
109119
CloseButton = new tTileBarButton();
110120
CloseButton->setObjectName("closeButton");
111121
CloseButton->setAutoRaise(true);
@@ -213,6 +223,14 @@ void CDockAreaTitleBar::onCloseButtonClicked()
213223
}
214224

215225

226+
//============================================================================
227+
void CDockAreaTitleBar::onUndockButtonClicked()
228+
{
229+
std::cout << "CDockAreaTitleBar::onUndockButtonClicked" << std::endl;
230+
d->TabBar->makeAreaFloating(mapFromGlobal(QCursor::pos()));
231+
}
232+
233+
216234
//============================================================================
217235
void CDockAreaTitleBar::onTabsMenuActionTriggered(QAction* Action)
218236
{
@@ -230,6 +248,27 @@ void CDockAreaTitleBar::onCurrentTabChanged(int Index)
230248
}
231249

232250

251+
//============================================================================
252+
QAbstractButton* CDockAreaTitleBar::button(TitleBarButton which) const
253+
{
254+
switch (which)
255+
{
256+
case TitleBarButtonTabsMenu: return d->TabsMenuButton;
257+
case TitleBarButtonUndock: return d->UndockButton;
258+
case TitleBarButtonClose: return d->CloseButton;
259+
default:
260+
return nullptr;
261+
}
262+
}
263+
264+
265+
//============================================================================
266+
void CDockAreaTitleBar::setVisible(bool Visible)
267+
{
268+
Super::setVisible(Visible);
269+
}
270+
271+
233272
} // namespace ads
234273

235274
//---------------------------------------------------------------------------

src/DockAreaTitleBar.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
//============================================================================
3333
#include <QFrame>
3434

35+
#include "ads_globals.h"
36+
37+
class QAbstractButton;
38+
3539
namespace ads
3640
{
3741
class CDockAreaTabBar;
@@ -52,6 +56,7 @@ private slots:
5256
void markTabsMenuOutdated();
5357
void onTabsMenuAboutToShow();
5458
void onCloseButtonClicked();
59+
void onUndockButtonClicked();
5560
void onTabsMenuActionTriggered(QAction* Action);
5661
void onCurrentTabChanged(int Index);
5762

@@ -72,6 +77,13 @@ private slots:
7277
*/
7378
CDockAreaTabBar* tabBar() const;
7479

80+
/**
81+
* Returns the button corresponding to the given title bar button identifier
82+
*/
83+
QAbstractButton* button(TitleBarButton which) const;
84+
85+
virtual void setVisible(bool Visible) override;
86+
7587
signals:
7688
/**
7789
* This signal is emitted if a tab in the tab bar is clicked by the user

src/DockAreaWidget.cpp

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ struct DockAreaWidgetPrivate
258258
* Updates the tab bar visibility depending on the number of dock widgets
259259
* in this area
260260
*/
261-
void updateTabBar();
261+
void updateTitleBarVisibility();
262262

263263
/**
264264
* Convenience function for tabbar access
@@ -294,7 +294,7 @@ void DockAreaWidgetPrivate::createTitleBar()
294294

295295

296296
//============================================================================
297-
void DockAreaWidgetPrivate::updateTabBar()
297+
void DockAreaWidgetPrivate::updateTitleBarVisibility()
298298
{
299299
CDockContainerWidget* Container = _this->dockContainer();
300300
if (!Container)
@@ -358,7 +358,11 @@ void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget,
358358
d->ContentsLayout->insertWidget(index, DockWidget);
359359
DockWidget->tabWidget()->setDockAreaWidget(this);
360360
auto TabWidget = DockWidget->tabWidget();
361+
// Inserting the tab will change the current index which in turn will
362+
// make the tab widget visible in the slot
363+
d->tabBar()->blockSignals(true);
361364
d->tabBar()->insertTab(index, TabWidget);
365+
d->tabBar()->blockSignals(false);
362366
TabWidget->setVisible(!DockWidget->isClosed());
363367
DockWidget->setProperty(INDEX_PROPERTY, index);
364368
if (Activate)
@@ -398,7 +402,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
398402
hideAreaWithNoVisibleContent();
399403
}
400404

401-
d->updateTabBar();
405+
d->updateTitleBarVisibility();
402406
auto TopLevelDockWidget = dockContainer()->topLevelDockWidget();
403407
if (TopLevelDockWidget)
404408
{
@@ -415,6 +419,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
415419
//============================================================================
416420
void CDockAreaWidget::hideAreaWithNoVisibleContent()
417421
{
422+
std::cout << "CDockAreaWidget::hideAreaWithNoVisibleContent()" << std::endl;
418423
this->toggleView(false);
419424

420425
// Hide empty parent splitter
@@ -430,9 +435,21 @@ void CDockAreaWidget::hideAreaWithNoVisibleContent()
430435

431436
//Hide empty floating widget
432437
CDockContainerWidget* Container = this->dockContainer();
433-
if (Container->isFloating() && Container->openedDockAreas().isEmpty())
438+
if (!Container->isFloating())
439+
{
440+
return;
441+
}
442+
443+
d->updateTitleBarVisibility();
444+
auto TopLevelWidget = Container->topLevelDockWidget();
445+
auto FloatingWidget = Container->floatingWidget();
446+
if (TopLevelWidget)
447+
{
448+
FloatingWidget->updateWindowTitle();
449+
CDockWidget::emitTopLevelEventForWidget(TopLevelWidget, true);
450+
}
451+
else if (Container->openedDockAreas().isEmpty())
434452
{
435-
CFloatingDockContainer* FloatingWidget = internal::findParent<CFloatingDockContainer*>(Container);
436453
FloatingWidget->hide();
437454
}
438455
}
@@ -449,7 +466,13 @@ void CDockAreaWidget::onTabCloseRequested(int Index)
449466
//============================================================================
450467
CDockWidget* CDockAreaWidget::currentDockWidget() const
451468
{
452-
return dockWidget(currentIndex());
469+
int CurrentIndex = currentIndex();
470+
if (CurrentIndex < 0)
471+
{
472+
return nullptr;
473+
}
474+
475+
return dockWidget(CurrentIndex);
453476
}
454477

455478

@@ -576,7 +599,7 @@ int CDockAreaWidget::dockWidgetsCount() const
576599
//============================================================================
577600
CDockWidget* CDockAreaWidget::dockWidget(int Index) const
578601
{
579-
return dynamic_cast<CDockWidget*>(d->ContentsLayout->widget(Index));
602+
return qobject_cast<CDockWidget*>(d->ContentsLayout->widget(Index));
580603
}
581604

582605

@@ -610,7 +633,7 @@ void CDockAreaWidget::toggleDockWidgetView(CDockWidget* DockWidget, bool Open)
610633
//============================================================================
611634
void CDockAreaWidget::updateTabBarVisibility()
612635
{
613-
d->updateTabBar();
636+
d->updateTitleBarVisibility();
614637
}
615638

616639

@@ -619,9 +642,11 @@ void CDockAreaWidget::saveState(QXmlStreamWriter& s) const
619642
{
620643
s.writeStartElement("DockAreaWidget");
621644
s.writeAttribute("Tabs", QString::number(d->ContentsLayout->count()));
622-
s.writeAttribute("CurrentDockWidget", currentDockWidget()->objectName());
645+
auto CurrentDockWidget = currentDockWidget();
646+
QString Name = CurrentDockWidget ? CurrentDockWidget->objectName() : "";
647+
s.writeAttribute("CurrentDockWidget", Name);
623648
qDebug() << "CDockAreaWidget::saveState TabCount: " << d->ContentsLayout->count()
624-
<< " CurrentDockWidge: " << currentDockWidget()->objectName();
649+
<< " CurrentDockWidge: " << Name;
625650
for (int i = 0; i < d->ContentsLayout->count(); ++i)
626651
{
627652
dockWidget(i)->saveState(s);
@@ -675,6 +700,13 @@ void CDockAreaWidget::toggleView(bool Open)
675700
setVisible(Open);
676701
emit viewToggled(Open);
677702
}
703+
704+
705+
//============================================================================
706+
QAbstractButton* CDockAreaWidget::titleBarButton(TitleBarButton which) const
707+
{
708+
return d->TitleBar->button(which);
709+
}
678710
} // namespace ads
679711

680712
//---------------------------------------------------------------------------

src/DockAreaWidget.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "DockWidget.h"
3737

3838
class QXmlStreamWriter;
39+
class QAbstractButton;
3940

4041
namespace ads
4142
{
@@ -190,12 +191,14 @@ private slots:
190191
CDockWidget* dockWidget(int Index) const;
191192

192193
/**
193-
* Returns the index of the current active dock widget
194+
* Returns the index of the current active dock widget or -1 if there
195+
* are is no active dock widget (ie.e if all dock widgets are closed)
194196
*/
195197
int currentIndex() const;
196198

197199
/**
198-
* Returns the current active dock widget
200+
* Returns the current active dock widget or a nullptr if there is no
201+
* active dock widget (i.e. if all dock widgets are closed)
199202
*/
200203
CDockWidget* currentDockWidget() const;
201204

@@ -218,6 +221,12 @@ private slots:
218221
*/
219222
CDockWidget::DockWidgetFeatures features() const;
220223

224+
/**
225+
* Returns the title bar button corresponding to the given title bar
226+
* button identifier
227+
*/
228+
QAbstractButton* titleBarButton(TitleBarButton which) const;
229+
221230
public slots:
222231
/**
223232
* This activates the tab for the given tab index.

src/DockContainerWidget.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,10 +528,6 @@ bool DockContainerWidgetPrivate::restoreDockArea(QXmlStreamReader& s,
528528

529529

530530
QString CurrentDockWidget = s.attributes().value("CurrentDockWidget").toString();
531-
if (CurrentDockWidget.isEmpty())
532-
{
533-
return false;
534-
}
535531
qDebug() << "Restore NodeDockArea Tabs: " << Tabs << " CurrentDockWidget: "
536532
<< CurrentDockWidget;
537533

src/DockManager.cpp

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@ bool DockManagerPrivate::restoreState(const QByteArray &state, int version)
264264
{
265265
CDockAreaWidget* DockArea = DockContainer->dockArea(i);
266266
QString DockWidgetName = DockArea->property("currentDockWidget").toString();
267+
if (DockWidgetName.isEmpty())
268+
{
269+
continue;
270+
}
271+
267272
CDockWidget* DockWidget = _this->findDockWidget(DockWidgetName);
268273
if (!DockWidget->isClosed())
269274
{
@@ -272,29 +277,6 @@ bool DockManagerPrivate::restoreState(const QByteArray &state, int version)
272277
}
273278
}
274279

275-
276-
// Finally we need to send the topLevelChanged() signals for all dock
277-
// widgets if top level changed
278-
/*for (auto DockContainer : Containers)
279-
{
280-
CDockWidget* TopLevelDockWidget = DockContainer->topLevelDockWidget();
281-
if (TopLevelDockWidget)
282-
{
283-
TopLevelDockWidget->emitTopLevelChanged(true);
284-
}
285-
else
286-
{
287-
for (int i = 0; i < DockContainer->dockAreaCount(); ++i)
288-
{
289-
auto DockArea = DockContainer->dockArea(i);
290-
for (auto DockWidget : DockArea->dockWidgets())
291-
{
292-
DockWidget->emitTopLevelChanged(false);
293-
}
294-
}
295-
}
296-
}*/
297-
298280
return true;
299281
}
300282

src/DockWidgetTab.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,7 @@ void CDockWidgetTab::mouseDoubleClickEvent(QMouseEvent *event)
400400
//============================================================================
401401
void CDockWidgetTab::setVisible(bool visible)
402402
{
403-
/*if (!visible)
404-
{
405-
qDebug() << "CDockWidgetTab::setVisible " << visible;
406-
}*/
403+
// Just here for debugging to insert debug output
407404
Super::setVisible(visible);
408405
}
409406

0 commit comments

Comments
 (0)