Skip to content

Commit 03bd4a4

Browse files
Added visibilityChanged code
1 parent 407af06 commit 03bd4a4

File tree

5 files changed

+77
-12
lines changed

5 files changed

+77
-12
lines changed

demo/MainWindow.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ void MainWindowPrivate::createContent()
317317
for (auto DockWidget : DockManager->dockWidgetsMap())
318318
{
319319
_this->connect(DockWidget, SIGNAL(viewToggled(bool)), SLOT(onViewToggled(bool)));
320+
_this->connect(DockWidget, SIGNAL(visibilityChanged(bool)), SLOT(onViewVisibilityChanged(bool)));
320321
}
321322
}
322323

@@ -501,6 +502,19 @@ void CMainWindow::onViewToggled(bool Open)
501502
}
502503

503504

505+
//============================================================================
506+
void CMainWindow::onViewVisibilityChanged(bool Visible)
507+
{
508+
auto DockWidget = qobject_cast<ads::CDockWidget*>(sender());
509+
if (!DockWidget)
510+
{
511+
return;
512+
}
513+
514+
qDebug() << DockWidget->objectName() << " visibilityChanged(" << Visible << ")";
515+
}
516+
517+
504518
//============================================================================
505519
void CMainWindow::createEditor()
506520
{

demo/MainWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ private slots:
5959
void on_actionRestoreState_triggered(bool);
6060
void savePerspective();
6161
void onViewToggled(bool Open);
62+
void onViewVisibilityChanged(bool Visible);
6263
void createEditor();
6364
void createTable();
6465
void onEditorCloseRequested();

src/DockAreaWidget.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,11 @@ void CDockAreaWidget::internalSetCurrentDockWidget(CDockWidget* DockWidget)
546546
void CDockAreaWidget::setCurrentIndex(int index)
547547
{
548548
auto TabBar = d->tabBar();
549+
/*if (TabBar->currentIndex() == index)
550+
{
551+
return;
552+
}*/
553+
549554
if (index < 0 || index > (TabBar->count() - 1))
550555
{
551556
qWarning() << Q_FUNC_INFO << "Invalid index" << index;

src/DockWidget.cpp

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
#include <QToolBar>
4646
#include <QXmlStreamWriter>
4747

48+
#include <QGuiApplication>
49+
#include <QScreen>
50+
#include <QWindow>
51+
4852
#include "DockContainerWidget.h"
4953
#include "DockAreaWidget.h"
5054
#include "DockManager.h"
@@ -296,6 +300,7 @@ void CDockWidget::setFeatures(DockWidgetFeatures features)
296300
return;
297301
}
298302
d->Features = features;
303+
emit featuresChanged(d->Features);
299304
d->TabWidget->onDockWidgetFeaturesChanged();
300305
}
301306

@@ -517,23 +522,50 @@ void CDockWidget::flagAsUnassigned()
517522
//============================================================================
518523
bool CDockWidget::event(QEvent *e)
519524
{
520-
if (e->type() == QEvent::WindowTitleChange)
525+
switch (e->type())
521526
{
522-
const auto title = windowTitle();
523-
if (d->TabWidget)
524-
{
525-
d->TabWidget->setText(title);
526-
}
527-
if (d->ToggleViewAction)
527+
case QEvent::Hide:
528+
emit visibilityChanged(false);
529+
break;
530+
531+
case QEvent::Show:
528532
{
529-
d->ToggleViewAction->setText(title);
530-
}
531-
if (d->DockArea)
533+
QPoint parentTopLeft(0, 0);
534+
if (isWindow())
535+
{
536+
if (const QWindow *window = windowHandle())
537+
parentTopLeft = window->screen()->availableVirtualGeometry().topLeft();
538+
else
539+
parentTopLeft = QGuiApplication::primaryScreen()->availableVirtualGeometry().topLeft();
540+
std::cout << "QEvent::Show isWindow()" << std::endl;
541+
}
542+
emit visibilityChanged(geometry().right() >= parentTopLeft.x() && geometry().bottom() >= parentTopLeft.y());
543+
}
544+
break;
545+
546+
case QEvent::WindowTitleChange :
532547
{
533-
d->DockArea->markTitleBarMenuOutdated();//update tabs menu
548+
const auto title = windowTitle();
549+
if (d->TabWidget)
550+
{
551+
d->TabWidget->setText(title);
552+
}
553+
if (d->ToggleViewAction)
554+
{
555+
d->ToggleViewAction->setText(title);
556+
}
557+
if (d->DockArea)
558+
{
559+
d->DockArea->markTitleBarMenuOutdated();//update tabs menu
560+
}
561+
emit titleChanged(title);
534562
}
535-
emit titleChanged(title);
563+
break;
564+
565+
default:
566+
break;
536567
}
568+
537569
return Super::event(e);
538570
}
539571

src/DockWidget.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,19 @@ public slots:
468468
* This signal is emitted, if close is requested
469469
*/
470470
void closeRequested();
471+
472+
/**
473+
* This signal is emitted when the dock widget becomes visible (or invisible).
474+
* This happens when the widget is hidden or shown, as well as when it is
475+
* docked in a tabbed dock area and its tab becomes selected or unselected.
476+
*/
477+
void visibilityChanged(bool visible);
478+
479+
/**
480+
* This signal is emitted when the features property changes.
481+
* The features parameter gives the new value of the property.
482+
*/
483+
void featuresChanged(DockWidgetFeatures features);
471484
}; // class DockWidget
472485
}
473486
// namespace ads

0 commit comments

Comments
 (0)