mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 04:53:25 +02:00
Update ToolWindow to auto-hide itself when main window loses focus
This commit is contained in:
parent
ad3d7fbfb4
commit
2bfd3d213a
2 changed files with 40 additions and 2 deletions
|
@ -19,6 +19,8 @@ ToolWindow::ToolWindow(QWidget* parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
_hasShown(false),
|
_hasShown(false),
|
||||||
_lastGeometry() {
|
_lastGeometry() {
|
||||||
|
|
||||||
|
Application::getInstance()->installEventFilter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ToolWindow::event(QEvent* event) {
|
bool ToolWindow::event(QEvent* event) {
|
||||||
|
@ -47,8 +49,37 @@ bool ToolWindow::event(QEvent* event) {
|
||||||
return QMainWindow::event(event);
|
return QMainWindow::event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ToolWindow::eventFilter(QObject* sender, QEvent* event) {
|
||||||
|
switch (event->type()) {
|
||||||
|
case QEvent::WindowStateChange:
|
||||||
|
if (Application::getInstance()->getWindow()->isMinimized()) {
|
||||||
|
// If we are already visible, we are self-hiding
|
||||||
|
_selfHidden = isVisible();
|
||||||
|
setVisible(false);
|
||||||
|
} else {
|
||||||
|
if (_selfHidden) {
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case QEvent::ApplicationDeactivate:
|
||||||
|
_selfHidden = isVisible();
|
||||||
|
setVisible(false);
|
||||||
|
break;
|
||||||
|
case QEvent::ApplicationActivate:
|
||||||
|
if (_selfHidden) {
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void ToolWindow::onChildVisibilityUpdated(bool visible) {
|
void ToolWindow::onChildVisibilityUpdated(bool visible) {
|
||||||
if (visible) {
|
if (!_selfHidden && visible) {
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
} else {
|
} else {
|
||||||
bool hasVisible = false;
|
bool hasVisible = false;
|
||||||
|
@ -59,7 +90,10 @@ void ToolWindow::onChildVisibilityUpdated(bool visible) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setVisible(hasVisible);
|
// If a child was hidden and we don't have any children still visible, hide ourself.
|
||||||
|
if (!hasVisible) {
|
||||||
|
setVisible(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,11 +28,15 @@ public:
|
||||||
virtual void addDockWidget(Qt::DockWidgetArea area, QDockWidget* dockWidget, Qt::Orientation orientation);
|
virtual void addDockWidget(Qt::DockWidgetArea area, QDockWidget* dockWidget, Qt::Orientation orientation);
|
||||||
virtual void removeDockWidget(QDockWidget* dockWidget);
|
virtual void removeDockWidget(QDockWidget* dockWidget);
|
||||||
|
|
||||||
|
virtual bool eventFilter(QObject* sender, QEvent* event);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onChildVisibilityUpdated(bool visible);
|
void onChildVisibilityUpdated(bool visible);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Indicates whether this window was hidden by itself (because the main window lost focus).
|
||||||
|
bool _selfHidden;
|
||||||
bool _hasShown;
|
bool _hasShown;
|
||||||
QRect _lastGeometry;
|
QRect _lastGeometry;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue