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 {
, _signalMapper(0)
{
_signalMapper = new QSignalMapper(this);
connect(_signalMapper, SIGNAL(mapped(QObject*)), SLOT(toggleSubWindowVisibility(QObject*)));
this->setTabsClosable(true);
this->setTabsMovable(true);
this->setDocumentMode(true);
......@@ -80,7 +82,6 @@ namespace campvis {
connect(visibilityAction, SIGNAL(triggered()), _signalMapper, SLOT(map()));
_signalMapper->setMapping(visibilityAction, visibilityAction);
connect(_signalMapper, SIGNAL(mapped(QObject*)), SLOT(toggleSubWindowVisibility(QObject*)));
return dockedWindow;
}
......@@ -95,6 +96,7 @@ namespace campvis {
connect(dockedWindow, SIGNAL(s_positionChanged(MdiDockedWindow*, const QPoint&)),
SLOT(trackMdiSubWindowsPosition(MdiDockedWindow*, const QPoint&)));
connect(dockedWindow, SIGNAL(s_closed(MdiDockedWindow*)), SLOT(handleDockedWindowClosing(MdiDockedWindow*)));
}
void MdiDockArea::toggleSubWindowVisibility(QObject* actionObject) {
......@@ -108,8 +110,12 @@ namespace campvis {
if (MdiDockedWindow* dockedWindow = dynamic_cast<MdiDockedWindow*>(windowWidget)) {
if (visibilityAction->isChecked())
this->addDockedWindow(dockedWindow);
else
else {
if (this->activeSubWindow() == dockedWindow)
this->activateNextSubWindow();
this->removeSubWindow(dockedWindow);
}
// Calling tileSubWindows() in TabbedView mode breaks the tabbed display
if (this->viewMode() == QMdiArea::SubWindowView)
......@@ -124,6 +130,13 @@ namespace campvis {
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() {
this->setViewMode(QMdiArea::SubWindowView);
this->tileSubWindows();
......
......@@ -69,6 +69,12 @@ namespace campvis {
*/
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();
private slots:
......@@ -103,6 +109,13 @@ namespace campvis {
*/
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:
/**
* Add the given MdiDockedWindow to the MDI area.
......
......@@ -45,6 +45,7 @@ namespace campvis {
_dragActive = true;
_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));
int x = mousePos.x() - this->frameSize().width() / 2;
int y = mousePos.y() - this->style()->pixelMetric(QStyle::PM_TitleBarHeight) / 2;
......@@ -106,4 +107,8 @@ namespace campvis {
QMdiSubWindow::mouseReleaseEvent(event);
}
void MdiDockedWindow::closeEvent(QCloseEvent* /*event*/) {
emit s_closed(this);
}
}
......@@ -79,6 +79,11 @@ namespace campvis {
*/
void s_positionChanged(MdiDockedWindow* mdiSubWindow, const QPoint& newPos);
/**
* Emitted when the window gets closed.
*/
void s_closed(MdiDockedWindow* mdiSubWindow);
protected:
/**
* Event handler that receives mouse move events for the window.
......@@ -90,6 +95,11 @@ namespace campvis {
*/
virtual void mouseReleaseEvent(QMouseEvent * event);
/**
* Event handler called when Qt receives a window close request for the window.
*/
virtual void closeEvent(QCloseEvent* event);
private:
bool _dragActive; ///< Is the window currently being dragged?
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