From 03bd4a45053cf4e68e9fd6d2a4134fa6760266c0 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Tue, 14 Jan 2020 15:58:45 +0100 Subject: [PATCH] Added visibilityChanged code --- demo/MainWindow.cpp | 14 +++++++++++ demo/MainWindow.h | 1 + src/DockAreaWidget.cpp | 5 ++++ src/DockWidget.cpp | 56 +++++++++++++++++++++++++++++++++--------- src/DockWidget.h | 13 ++++++++++ 5 files changed, 77 insertions(+), 12 deletions(-) diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index 95e34be..2ee49bb 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -317,6 +317,7 @@ void MainWindowPrivate::createContent() for (auto DockWidget : DockManager->dockWidgetsMap()) { _this->connect(DockWidget, SIGNAL(viewToggled(bool)), SLOT(onViewToggled(bool))); + _this->connect(DockWidget, SIGNAL(visibilityChanged(bool)), SLOT(onViewVisibilityChanged(bool))); } } @@ -501,6 +502,19 @@ void CMainWindow::onViewToggled(bool Open) } +//============================================================================ +void CMainWindow::onViewVisibilityChanged(bool Visible) +{ + auto DockWidget = qobject_cast(sender()); + if (!DockWidget) + { + return; + } + + qDebug() << DockWidget->objectName() << " visibilityChanged(" << Visible << ")"; +} + + //============================================================================ void CMainWindow::createEditor() { diff --git a/demo/MainWindow.h b/demo/MainWindow.h index c7575eb..f2fe937 100644 --- a/demo/MainWindow.h +++ b/demo/MainWindow.h @@ -59,6 +59,7 @@ private slots: void on_actionRestoreState_triggered(bool); void savePerspective(); void onViewToggled(bool Open); + void onViewVisibilityChanged(bool Visible); void createEditor(); void createTable(); void onEditorCloseRequested(); diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index ca2f964..13c8aca 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -546,6 +546,11 @@ void CDockAreaWidget::internalSetCurrentDockWidget(CDockWidget* DockWidget) void CDockAreaWidget::setCurrentIndex(int index) { auto TabBar = d->tabBar(); + /*if (TabBar->currentIndex() == index) + { + return; + }*/ + if (index < 0 || index > (TabBar->count() - 1)) { qWarning() << Q_FUNC_INFO << "Invalid index" << index; diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp index 398f727..5c07248 100644 --- a/src/DockWidget.cpp +++ b/src/DockWidget.cpp @@ -45,6 +45,10 @@ #include #include +#include +#include +#include + #include "DockContainerWidget.h" #include "DockAreaWidget.h" #include "DockManager.h" @@ -296,6 +300,7 @@ void CDockWidget::setFeatures(DockWidgetFeatures features) return; } d->Features = features; + emit featuresChanged(d->Features); d->TabWidget->onDockWidgetFeaturesChanged(); } @@ -517,23 +522,50 @@ void CDockWidget::flagAsUnassigned() //============================================================================ bool CDockWidget::event(QEvent *e) { - if (e->type() == QEvent::WindowTitleChange) + switch (e->type()) { - const auto title = windowTitle(); - if (d->TabWidget) + case QEvent::Hide: + emit visibilityChanged(false); + break; + + case QEvent::Show: { - d->TabWidget->setText(title); - } - if (d->ToggleViewAction) + QPoint parentTopLeft(0, 0); + if (isWindow()) + { + if (const QWindow *window = windowHandle()) + parentTopLeft = window->screen()->availableVirtualGeometry().topLeft(); + else + parentTopLeft = QGuiApplication::primaryScreen()->availableVirtualGeometry().topLeft(); + std::cout << "QEvent::Show isWindow()" << std::endl; + } + emit visibilityChanged(geometry().right() >= parentTopLeft.x() && geometry().bottom() >= parentTopLeft.y()); + } + break; + + case QEvent::WindowTitleChange : { - d->ToggleViewAction->setText(title); + const auto title = windowTitle(); + if (d->TabWidget) + { + d->TabWidget->setText(title); + } + if (d->ToggleViewAction) + { + d->ToggleViewAction->setText(title); + } + if (d->DockArea) + { + d->DockArea->markTitleBarMenuOutdated();//update tabs menu + } + emit titleChanged(title); } - if (d->DockArea) - { - d->DockArea->markTitleBarMenuOutdated();//update tabs menu - } - emit titleChanged(title); + break; + + default: + break; } + return Super::event(e); } diff --git a/src/DockWidget.h b/src/DockWidget.h index 0f96430..b5e2681 100644 --- a/src/DockWidget.h +++ b/src/DockWidget.h @@ -468,6 +468,19 @@ signals: * This signal is emitted, if close is requested */ void closeRequested(); + + /** + * This signal is emitted when the dock widget becomes visible (or invisible). + * This happens when the widget is hidden or shown, as well as when it is + * docked in a tabbed dock area and its tab becomes selected or unselected. + */ + void visibilityChanged(bool visible); + + /** + * This signal is emitted when the features property changes. + * The features parameter gives the new value of the property. + */ + void featuresChanged(DockWidgetFeatures features); }; // class DockWidget } // namespace ads