Commit 8126df4d authored by Artur Grunau's avatar Artur Grunau
Browse files

Properly hide docked MDI subwindows that got closed

Closing a docked MDI subwindow caused it to disappear if the MDI area
was in SubWindowView mode, but its inactive tab could still be seen in
TabbedView mode.

If a docked MDI subwindow gets closed, hide it by removing it from the
MDI area.
parent dd068eea
...@@ -41,6 +41,8 @@ namespace campvis { ...@@ -41,6 +41,8 @@ namespace campvis {
, _signalMapper(0) , _signalMapper(0)
{ {
_signalMapper = new QSignalMapper(this); _signalMapper = new QSignalMapper(this);
connect(_signalMapper, SIGNAL(mapped(QObject*)), SLOT(toggleSubWindowVisibility(QObject*)));
this->setTabsClosable(true); this->setTabsClosable(true);
this->setTabsMovable(true); this->setTabsMovable(true);
this->setDocumentMode(true); this->setDocumentMode(true);
...@@ -80,7 +82,6 @@ namespace campvis { ...@@ -80,7 +82,6 @@ namespace campvis {
connect(visibilityAction, SIGNAL(triggered()), _signalMapper, SLOT(map())); connect(visibilityAction, SIGNAL(triggered()), _signalMapper, SLOT(map()));
_signalMapper->setMapping(visibilityAction, visibilityAction); _signalMapper->setMapping(visibilityAction, visibilityAction);
connect(_signalMapper, SIGNAL(mapped(QObject*)), SLOT(toggleSubWindowVisibility(QObject*)));
return dockedWindow; return dockedWindow;
} }
...@@ -95,6 +96,7 @@ namespace campvis { ...@@ -95,6 +96,7 @@ namespace campvis {
connect(dockedWindow, SIGNAL(s_positionChanged(MdiDockedWindow*, const QPoint&)), connect(dockedWindow, SIGNAL(s_positionChanged(MdiDockedWindow*, const QPoint&)),
SLOT(trackMdiSubWindowsPosition(MdiDockedWindow*, const QPoint&))); SLOT(trackMdiSubWindowsPosition(MdiDockedWindow*, const QPoint&)));
connect(dockedWindow, SIGNAL(s_closed(MdiDockedWindow*)), SLOT(handleDockedWindowClosing(MdiDockedWindow*)));
} }
void MdiDockArea::toggleSubWindowVisibility(QObject* actionObject) { void MdiDockArea::toggleSubWindowVisibility(QObject* actionObject) {
...@@ -108,8 +110,12 @@ namespace campvis { ...@@ -108,8 +110,12 @@ namespace campvis {
if (MdiDockedWindow* dockedWindow = dynamic_cast<MdiDockedWindow*>(windowWidget)) { if (MdiDockedWindow* dockedWindow = dynamic_cast<MdiDockedWindow*>(windowWidget)) {
if (visibilityAction->isChecked()) if (visibilityAction->isChecked())
this->addDockedWindow(dockedWindow); this->addDockedWindow(dockedWindow);
else else {
if (this->activeSubWindow() == dockedWindow)
this->activateNextSubWindow();
this->removeSubWindow(dockedWindow); this->removeSubWindow(dockedWindow);
}
// Calling tileSubWindows() in TabbedView mode breaks the tabbed display // Calling tileSubWindows() in TabbedView mode breaks the tabbed display
if (this->viewMode() == QMdiArea::SubWindowView) if (this->viewMode() == QMdiArea::SubWindowView)
...@@ -124,6 +130,13 @@ namespace campvis { ...@@ -124,6 +130,13 @@ namespace campvis {
tgtAssert(false, "Widget's parent is of unsupported type."); tgtAssert(false, "Widget's parent is of unsupported type.");
} }
void MdiDockArea::handleDockedWindowClosing(MdiDockedWindow* dockedWindow) {
if (this->activeSubWindow() == dockedWindow)
this->activateNextSubWindow();
this->removeSubWindow(dockedWindow);
}
void MdiDockArea::switchToTiledDisplay() { void MdiDockArea::switchToTiledDisplay() {
this->setViewMode(QMdiArea::SubWindowView); this->setViewMode(QMdiArea::SubWindowView);
this->tileSubWindows(); this->tileSubWindows();
......
...@@ -69,6 +69,12 @@ namespace campvis { ...@@ -69,6 +69,12 @@ namespace campvis {
*/ */
MdiDockedWindow* addSubWindow(QWidget* widget, Qt::WindowFlags windowFlags = 0); MdiDockedWindow* addSubWindow(QWidget* widget, Qt::WindowFlags windowFlags = 0);
/**
* Return a menu that lets the user control how the area's contents are displayed.
*
* The menu contains actions that make it possible to change the layout and visibility of
* the area's subwindows.
*/
QMenu* menu(); QMenu* menu();
private slots: private slots:
...@@ -103,6 +109,13 @@ namespace campvis { ...@@ -103,6 +109,13 @@ namespace campvis {
*/ */
void toggleSubWindowVisibility(QObject* actionObject); void toggleSubWindowVisibility(QObject* actionObject);
/**
* Remove the closed MdiDockedWindow from the area and update its visibility action.
*
* \param mdiSubWindow the MdiDockedWindow that has been closed
*/
void handleDockedWindowClosing(MdiDockedWindow* dockedWindow);
private: private:
/** /**
* Add the given MdiDockedWindow to the MDI area. * Add the given MdiDockedWindow to the MDI area.
......
...@@ -45,6 +45,7 @@ namespace campvis { ...@@ -45,6 +45,7 @@ namespace campvis {
_dragActive = true; _dragActive = true;
_lastMousePos = QCursor::pos(); _lastMousePos = QCursor::pos();
// Position the window so that the centre of its title bar is under the cursor
const QPoint& mousePos = this->mapToParent(this->mapFromGlobal(_lastMousePos)); const QPoint& mousePos = this->mapToParent(this->mapFromGlobal(_lastMousePos));
int x = mousePos.x() - this->frameSize().width() / 2; int x = mousePos.x() - this->frameSize().width() / 2;
int y = mousePos.y() - this->style()->pixelMetric(QStyle::PM_TitleBarHeight) / 2; int y = mousePos.y() - this->style()->pixelMetric(QStyle::PM_TitleBarHeight) / 2;
...@@ -106,4 +107,8 @@ namespace campvis { ...@@ -106,4 +107,8 @@ namespace campvis {
QMdiSubWindow::mouseReleaseEvent(event); QMdiSubWindow::mouseReleaseEvent(event);
} }
void MdiDockedWindow::closeEvent(QCloseEvent* /*event*/) {
emit s_closed(this);
}
} }
...@@ -79,6 +79,11 @@ namespace campvis { ...@@ -79,6 +79,11 @@ namespace campvis {
*/ */
void s_positionChanged(MdiDockedWindow* mdiSubWindow, const QPoint& newPos); void s_positionChanged(MdiDockedWindow* mdiSubWindow, const QPoint& newPos);
/**
* Emitted when the window gets closed.
*/
void s_closed(MdiDockedWindow* mdiSubWindow);
protected: protected:
/** /**
* Event handler that receives mouse move events for the window. * Event handler that receives mouse move events for the window.
...@@ -90,6 +95,11 @@ namespace campvis { ...@@ -90,6 +95,11 @@ namespace campvis {
*/ */
virtual void mouseReleaseEvent(QMouseEvent * event); virtual void mouseReleaseEvent(QMouseEvent * event);
/**
* Event handler called when Qt receives a window close request for the window.
*/
virtual void closeEvent(QCloseEvent* event);
private: private:
bool _dragActive; ///< Is the window currently being dragged? bool _dragActive; ///< Is the window currently being dragged?
QPoint _lastMousePos; ///< Last reported mouse position QPoint _lastMousePos; ///< Last reported mouse position
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment