Skip to content

Commit 6617cf6

Browse files
author
Uwe Kindler
committed
Implemented proper updating of floating widget title
1 parent 81523b0 commit 6617cf6

11 files changed

+67
-31
lines changed

demo/MainWindow.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,13 @@ void MainWindowPrivate::createContent()
177177
DockWidget->setFeature(ads::CDockWidget::DockWidgetClosable, false);
178178
DockManager->addDockWidget(ads::LeftDockWidgetArea, DockWidget);
179179
DockManager->addDockWidget(ads::LeftDockWidgetArea, createLongTextLabelDockWidget(ViewMenu));
180-
auto FileSystemWidget = createFileSystemTreeDockWidget(ViewMenu);
180+
/*auto FileSystemWidget = createFileSystemTreeDockWidget(ViewMenu);
181181
auto ToolBar = FileSystemWidget->toolBar();
182182
ToolBar->addAction(ui.actionSaveState);
183183
ToolBar->addAction(ui.actionRestoreState);
184-
DockManager->addDockWidget(ads::BottomDockWidgetArea, FileSystemWidget);
184+
DockManager->addDockWidget(ads::BottomDockWidgetArea, FileSystemWidget);*/
185185

186-
FileSystemWidget = createFileSystemTreeDockWidget(ViewMenu);
186+
/*FileSystemWidget = createFileSystemTreeDockWidget(ViewMenu);
187187
ToolBar = FileSystemWidget->toolBar();
188188
ToolBar->addAction(ui.actionSaveState);
189189
ToolBar->addAction(ui.actionRestoreState);
@@ -198,7 +198,7 @@ void MainWindowPrivate::createContent()
198198
DockManager->addDockWidget(ads::TopDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
199199
auto BottomDockArea = DockManager->addDockWidget(ads::BottomDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
200200
DockManager->addDockWidget(ads::RightDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), RighDockArea);
201-
DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea);
201+
DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(ViewMenu), BottomDockArea);*/
202202
}
203203

204204

@@ -321,7 +321,6 @@ void CMainWindow::on_actionRestoreState_triggered(bool)
321321
//============================================================================
322322
void CMainWindow::savePerspective()
323323
{
324-
std::cout << "savePerspective" << std::endl;
325324
QString PerspectiveName = QInputDialog::getText(this, "Save Perspective", "Enter unique name:");
326325
if (PerspectiveName.isEmpty())
327326
{

demo/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ int main(int argc, char *argv[])
3838
std::shared_ptr<int> b;
3939
QApplication a(argc, argv);
4040
a.setQuitOnLastWindowClosed(true);
41-
qInstallMessageHandler(myMessageOutput);
41+
//qInstallMessageHandler(myMessageOutput);
4242
qDebug() << "Message handler test";
4343

4444
CMainWindow mw;

src/DockAreaTabBar.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ void CDockAreaTabBar::wheelEvent(QWheelEvent* Event)
136136
//============================================================================
137137
void CDockAreaTabBar::mousePressEvent(QMouseEvent* ev)
138138
{
139-
std::cout << "CDockAreaTabBar::mousePressEvent" << std::endl;
140139
if (ev->button() == Qt::LeftButton)
141140
{
142141
ev->accept();
@@ -232,7 +231,6 @@ void CDockAreaTabBar::startFloating(const QPoint& Pos)
232231
//============================================================================
233232
void CDockAreaTabBar::setCurrentIndex(int index)
234233
{
235-
std::cout << "CDockAreaTabBar::setCurrentIndex " << index << std::endl;
236234
if (index == d->CurrentIndex)
237235
{
238236
return;

src/DockAreaTitleBar.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "DockAreaTitleBar.h"
1212

1313
#include <QPushButton>
14+
#include <QToolButton>
1415
#include <QBoxLayout>
1516
#include <QStyle>
1617
#include <QMenu>
@@ -31,14 +32,15 @@
3132

3233
namespace ads
3334
{
35+
using tTileBarButton = QPushButton;
3436
/**
3537
* Private data class of CDockAreaTitleBar class (pimpl)
3638
*/
3739
struct DockAreaTitleBarPrivate
3840
{
3941
CDockAreaTitleBar* _this;
40-
QPushButton* TabsMenuButton;
41-
QPushButton* CloseButton;
42+
tTileBarButton* TabsMenuButton;
43+
tTileBarButton* CloseButton;
4244
QBoxLayout* TopLayout;
4345
CDockAreaWidget* DockArea;
4446
CDockAreaTabBar* TabBar;
@@ -74,7 +76,7 @@ DockAreaTitleBarPrivate::DockAreaTitleBarPrivate(CDockAreaTitleBar* _public) :
7476
//============================================================================
7577
void DockAreaTitleBarPrivate::createButtons()
7678
{
77-
TabsMenuButton = new QPushButton();
79+
TabsMenuButton = new tTileBarButton();
7880
TabsMenuButton->setObjectName("tabsMenuButton");
7981
TabsMenuButton->setFlat(true);
8082
TabsMenuButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarUnshadeButton));
@@ -88,10 +90,18 @@ void DockAreaTitleBarPrivate::createButtons()
8890
_this->connect(TabsMenuButton->menu(), SIGNAL(triggered(QAction*)),
8991
SLOT(onTabsMenuActionTriggered(QAction*)));
9092

91-
CloseButton = new QPushButton();
93+
CloseButton = new tTileBarButton();
9294
CloseButton->setObjectName("closeButton");
9395
CloseButton->setFlat(true);
94-
CloseButton->setIcon(_this->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
96+
QPixmap ClosePixmap = _this->style()->standardPixmap(QStyle::SP_TitleBarCloseButton);
97+
QIcon CloseIcon;
98+
QStyleOptionButton option;
99+
option.initFrom(CloseButton);
100+
QPixmap ClosePixmapDisabled = _this->style()->generatedIconPixmap(QIcon::Disabled, ClosePixmap, &option);
101+
CloseIcon.addPixmap(ClosePixmap, QIcon::Active);
102+
CloseIcon.addPixmap(ClosePixmapDisabled, QIcon::Disabled);
103+
CloseButton->setIcon(CloseIcon);
104+
//CloseButton->setIcon(QIcon(":/ads/close.svg"));
95105
CloseButton->setToolTip(QObject::tr("Close"));
96106
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
97107
TopLayout->addWidget(CloseButton, 0);
@@ -201,7 +211,7 @@ void CDockAreaTitleBar::onTabsMenuActionTriggered(QAction* Action)
201211
void CDockAreaTitleBar::onCurrentTabChanged(int Index)
202212
{
203213
CDockWidget* DockWidget = d->TabBar->tab(Index)->dockWidget();
204-
d->CloseButton->setVisible(DockWidget->features().testFlag(CDockWidget::DockWidgetClosable));
214+
d->CloseButton->setEnabled(DockWidget->features().testFlag(CDockWidget::DockWidgetClosable));
205215
}
206216

207217

src/DockAreaWidget.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,10 @@ class CDockAreaLayout
132132

133133
void setCurrentIndex(int index)
134134
{
135-
std::cout << "CDockAreaLayout::setCurrentIndex " << index << std::endl;
136135
QWidget *prev = currentWidget();
137136
QWidget *next = widget(index);
138137
if (!next || (next == prev && !m_CurrentWidget))
139138
{
140-
std::cout << "return" << std::endl;
141139
return;
142140
}
143141

@@ -150,7 +148,6 @@ class CDockAreaLayout
150148
parent->setUpdatesEnabled(false);
151149
}
152150

153-
std::cout << "m_ParentLayout->addWidget(next)" << std::endl;
154151
auto LayoutItem = m_ParentLayout->takeAt(1);
155152
if (LayoutItem)
156153
{

src/DockContainerWidget.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ int CDockContainerWidget::visibleDockAreaCount() const
927927
int Result = 0;
928928
for (auto DockArea : d->DockAreas)
929929
{
930-
Result += DockArea->isVisibleTo(this) ? 1 : 0;
930+
Result += DockArea->isHidden() ? 0 : 1;
931931
}
932932

933933
return Result;
@@ -982,9 +982,6 @@ void CDockContainerWidget::dropFloatingWidget(CFloatingDockContainer* FloatingWi
982982
{
983983
TopLevelDockWidget->emitTopLevelChanged(false);
984984
}
985-
986-
std::cout << "CDockContainerWidget::dropFloatingWidget " <<
987-
Timer.restart() << std::endl;
988985
}
989986

990987

@@ -994,7 +991,7 @@ QList<CDockAreaWidget*> CDockContainerWidget::openedDockAreas() const
994991
QList<CDockAreaWidget*> Result;
995992
for (auto DockArea : d->DockAreas)
996993
{
997-
if (DockArea->isVisibleTo(this))
994+
if (!DockArea->isHidden())
998995
{
999996
Result.append(DockArea);
1000997
}

src/DockManager.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,10 @@ bool DockManagerPrivate::restoreState(const QByteArray &state, int version)
262262
// Now all dock areas are properly restored and we setup the index of
263263
// The dock areas because the previous toggleView() action has changed
264264
// the dock area index
265-
std::cout << "Restoring dock container indexes" << std::endl;
266265
int Count = 0;
267266
for (auto DockContainer : Containers)
268267
{
269268
Count++;
270-
std::cout << "Restoring container " << Count << " floating: "
271-
<< DockContainer->isFloating() << " DockAreaCount " << DockContainer->dockAreaCount() << std::endl;
272269
for (int i = 0; i < DockContainer->dockAreaCount(); ++i)
273270
{
274271
CDockAreaWidget* DockArea = DockContainer->dockArea(i);
@@ -481,8 +478,8 @@ bool CDockManager::restoreState(const QByteArray &state, int version)
481478
// dock manager. Because there will be no processing of application
482479
// events until this function is finished, the user will not see this
483480
// hiding
484-
bool IsVisible = this->isVisibleTo(parentWidget());
485-
if (IsVisible)
481+
bool IsHidden = this->isHidden();
482+
if (!IsHidden)
486483
{
487484
hide();
488485
}
@@ -491,12 +488,11 @@ bool CDockManager::restoreState(const QByteArray &state, int version)
491488
bool Result = d->restoreState(state, version);
492489
d->RestoringState = false;
493490
emit stateRestored();
494-
if (IsVisible)
491+
if (!IsHidden)
495492
{
496493
show();
497494
}
498495

499-
std::cout << "CDockManager::restoreState " << Timer.restart() << std::endl;
500496
return Result;
501497
}
502498

src/DockWidget.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,14 +435,16 @@ void CDockWidget::toggleViewInternal(bool Open)
435435
{
436436
CDockContainerWidget* DockContainer = dockContainer();
437437
CDockWidget* TopLevelDockWidget = nullptr;
438+
CDockWidget* TopLevelDockWidgetBefore = nullptr;
438439

439-
if (Open && DockContainer)
440+
if (DockContainer)
440441
{
441-
TopLevelDockWidget = DockContainer->topLevelDockWidget();
442+
TopLevelDockWidgetBefore = DockContainer->topLevelDockWidget();
442443
}
443444

444445
if (Open)
445446
{
447+
TopLevelDockWidget = TopLevelDockWidgetBefore;
446448
d->showDockWidget();
447449
}
448450
else
@@ -468,6 +470,22 @@ void CDockWidget::toggleViewInternal(bool Open)
468470
CDockWidget::emitTopLevelEventForWidget(TopLevelDockWidget, !Open);
469471
}
470472

473+
CDockWidget* TopLevelDockWidgetAfter = nullptr;
474+
if (DockContainer)
475+
{
476+
TopLevelDockWidgetAfter = DockContainer->topLevelDockWidget();
477+
}
478+
479+
if (TopLevelDockWidgetAfter != TopLevelDockWidgetBefore)
480+
{
481+
CFloatingDockContainer* FloatingContainer = qobject_cast<CFloatingDockContainer*>(DockContainer->parentWidget());
482+
if (FloatingContainer)
483+
{
484+
FloatingContainer->updateWindowTitle(TopLevelDockWidgetAfter ? TopLevelDockWidgetAfter->windowTitle() : "");
485+
}
486+
}
487+
488+
471489
if (!Open)
472490
{
473491
emit closed();

src/FloatingDockContainer.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,20 @@ void CFloatingDockContainer::onDockAreasAddedOrRemoved()
500500
}
501501

502502

503+
//============================================================================
504+
void CFloatingDockContainer::updateWindowTitle(const QString& Title)
505+
{
506+
if (Title.isEmpty())
507+
{
508+
this->setWindowTitle(qApp->applicationDisplayName());
509+
}
510+
else
511+
{
512+
this->setWindowTitle(Title);
513+
}
514+
}
515+
516+
503517
//============================================================================
504518
void CFloatingDockContainer::onDockAreaCurrentChanged(int Index)
505519
{

src/FloatingDockContainer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class ADS_EXPORT CFloatingDockContainer : public QWidget
6868
friend class CDockWidgetTab;
6969
friend class CDockAreaTitleBar;
7070
friend struct DockAreaTitleBarPrivate;
71+
friend class CDockWidget;
7172

7273
private slots:
7374
void onDockAreasAddedOrRemoved();
@@ -95,6 +96,11 @@ private slots:
9596
*/
9697
bool restoreState(QXmlStreamReader& Stream, bool Testing);
9798

99+
/**
100+
* Call this function to update the window title
101+
*/
102+
void updateWindowTitle(const QString& Title ="");
103+
98104

99105
protected: // reimplements QWidget
100106
virtual void changeEvent(QEvent *event) override;

0 commit comments

Comments
 (0)