Skip to content

Commit

Permalink
Added visibilityChanged code
Browse files Browse the repository at this point in the history
  • Loading branch information
githubuser0xFFFF committed Jan 14, 2020
1 parent 407af06 commit 03bd4a4
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 12 deletions.
14 changes: 14 additions & 0 deletions demo/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}

Expand Down Expand Up @@ -501,6 +502,19 @@ void CMainWindow::onViewToggled(bool Open)
}


//============================================================================
void CMainWindow::onViewVisibilityChanged(bool Visible)
{
auto DockWidget = qobject_cast<ads::CDockWidget*>(sender());
if (!DockWidget)
{
return;
}

qDebug() << DockWidget->objectName() << " visibilityChanged(" << Visible << ")";
}


//============================================================================
void CMainWindow::createEditor()
{
Expand Down
1 change: 1 addition & 0 deletions demo/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions src/DockAreaWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
56 changes: 44 additions & 12 deletions src/DockWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
#include <QToolBar>
#include <QXmlStreamWriter>

#include <QGuiApplication>
#include <QScreen>
#include <QWindow>

#include "DockContainerWidget.h"
#include "DockAreaWidget.h"
#include "DockManager.h"
Expand Down Expand Up @@ -296,6 +300,7 @@ void CDockWidget::setFeatures(DockWidgetFeatures features)
return;
}
d->Features = features;
emit featuresChanged(d->Features);
d->TabWidget->onDockWidgetFeaturesChanged();
}

Expand Down Expand Up @@ -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)
{
d->TabWidget->setText(title);
}
if (d->ToggleViewAction)
case QEvent::Hide:
emit visibilityChanged(false);
break;

case QEvent::Show:
{
d->ToggleViewAction->setText(title);
}
if (d->DockArea)
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->DockArea->markTitleBarMenuOutdated();//update tabs menu
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);
}
emit titleChanged(title);
break;

default:
break;
}

return Super::event(e);
}

Expand Down
13 changes: 13 additions & 0 deletions src/DockWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,19 @@ public slots:
* 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
Expand Down

0 comments on commit 03bd4a4

Please sign in to comment.