2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit e3289b08 authored by Artur Grunau's avatar Artur Grunau
Browse files

Refactor PipelineMdiSubWindow and rename it MdiDockedWindow

PipelineMdiSubWindow has been renamed MdiDockedWindow, and
refactored to make it easier to use it with arbitrary widgets.
parent 06a76302
......@@ -38,8 +38,8 @@ SET(CampvisApplicationToBeMocced
gui/logviewerwidget.h
gui/loghighlighter.h
gui/mdi/mdidockarea.h
gui/mdi/mdidockedwindow.h
gui/mdi/mdifloatingwindow.h
gui/mdi/pipelinemdisubwindow.h
gui/adjusterwidgets/doubleadjusterwidget.h
gui/adjusterwidgets/intadjusterwidget.h
gui/properties/abstractpropertywidget.h
......
......@@ -31,18 +31,18 @@
namespace campvis {
PipelineMdiSubWindow* MdiDockArea::addSubWindow(QWidget* widget, Qt::WindowFlags windowFlags /*= 0*/) {
PipelineMdiSubWindow* mdiSubWindow = new PipelineMdiSubWindow;
MdiDockedWindow* MdiDockArea::addSubWindow(QWidget* widget, Qt::WindowFlags windowFlags /*= 0*/) {
MdiDockedWindow* dockedWindow = new MdiDockedWindow();
mdiSubWindow->setWidget(widget);
QMdiArea::addSubWindow(mdiSubWindow, windowFlags);
dockedWindow->setWidget(widget);
QMdiArea::addSubWindow(dockedWindow, windowFlags);
widget->show();
this->tileSubWindows();
connect(mdiSubWindow, SIGNAL(s_positionChanged(PipelineMdiSubWindow*, const QPoint&)),
this, SLOT(trackMdiSubWindowsPosition(PipelineMdiSubWindow*, const QPoint&)));
connect(dockedWindow, SIGNAL(s_positionChanged(MdiDockedWindow*, const QPoint&)),
this, SLOT(trackMdiSubWindowsPosition(MdiDockedWindow*, const QPoint&)));
return mdiSubWindow;
return dockedWindow;
}
void MdiDockArea::trackFloatingWindowsPosition(MdiFloatingWindow* floatingWindow, const QPoint& newPos) {
......@@ -58,33 +58,33 @@ namespace campvis {
floatingWindow->stopWindowDrag();
QWidget* widget = floatingWindow->widget();
PipelineMdiSubWindow* mdiSubWindow = this->addSubWindow(widget);
mdiSubWindow->setWindowTitle(floatingWindow->windowTitle());
MdiDockedWindow* dockedWindow = this->addSubWindow(widget);
dockedWindow->setWindowTitle(floatingWindow->windowTitle());
widget->show();
floatingWindow->deleteLater();
mdiSubWindow->move(this->mapFromGlobal(newPos));
mdiSubWindow->grabMouse();
dockedWindow->move(this->mapFromGlobal(newPos));
dockedWindow->grabMouse();
}
}
void MdiDockArea::trackMdiSubWindowsPosition(PipelineMdiSubWindow *mdiSubWindow, const QPoint& newPos) {
const QRect& subWindowGeometry = mdiSubWindow->frameGeometry();
void MdiDockArea::trackMdiSubWindowsPosition(MdiDockedWindow *dockedWindow, const QPoint& newPos) {
const QRect& subWindowGeometry = dockedWindow->frameGeometry();
const QRect& mdiAreaGeometry = contentsRect();
const QRect& intersection = subWindowGeometry & mdiAreaGeometry;
// Detach the subwindow if at least 60% of it has left the MDI area
// Detach the docked window's widget if at least 60% of it has left the MDI area
if (subWindowGeometry.width() * subWindowGeometry.height() * 2 >
intersection.width() * intersection.height() * 5) {
QWidget* widget = mdiSubWindow->widget();
mdiSubWindow->stopWindowDrag();
mdiSubWindow->setWidget(0);
removeSubWindow(mdiSubWindow);
mdiSubWindow->deleteLater();
QWidget* widget = dockedWindow->widget();
dockedWindow->stopWindowDrag();
dockedWindow->setWidget(0);
removeSubWindow(dockedWindow);
dockedWindow->deleteLater();
tileSubWindows();
MdiFloatingWindow* floatingWindow = new MdiFloatingWindow(widget);
floatingWindow->setWindowTitle(mdiSubWindow->windowTitle());
floatingWindow->setWindowTitle(dockedWindow->windowTitle());
floatingWindow->move(this->mapToGlobal(newPos));
floatingWindow->show();
floatingWindow->forceWindowDrag();
......
......@@ -30,8 +30,8 @@
#ifndef MDIDOCKAREA_H__
#define MDIDOCKAREA_H__
#include "mdidockedwindow.h"
#include "mdifloatingwindow.h"
#include "pipelinemdisubwindow.h"
#include <QMdiArea>
......@@ -40,9 +40,9 @@ namespace campvis {
/**
* MDI area whose subwindows can be docked and undocked.
*
* MdiDockArea takes care of creating all necessary representations (floating window, MDI
* subwindow) of the widgets passed to \ref addSubWindow and seamlessly switching between them
* in response to the user's actions (window dragging, key presses, etc).
* MdiDockArea takes care of creating all necessary representations (docked and floating window)
* of the widgets passed to \ref addSubWindow and seamlessly switching between them in response
* to the user's actions (window dragging, key presses, etc).
*/
class MdiDockArea : public QMdiArea {
......@@ -50,16 +50,15 @@ namespace campvis {
public:
/**
* Wrap \p widget in an MDI subwindow and dock it in the MDI area.
* Wrap \p widget in an MDI window and dock it in the MDI area.
*
* This method creates a PipelineMdiSubWindow wrapping the widget it's passed, and adds it
* to the MDI area.
* This method creates a MdiDockedWindow wrapping the widget, and adds it to the MDI area.
*
* \param widget the widget to add to the MDI area
* \param windowFlags flags used to customize the frame of the created subwindow
* \return the PipelineMdiSubWindow instance that was added to the MDI area
*/
PipelineMdiSubWindow* addSubWindow(QWidget* widget, Qt::WindowFlags windowFlags = 0);
MdiDockedWindow* addSubWindow(QWidget* widget, Qt::WindowFlags windowFlags = 0);
private slots:
/**
......@@ -70,11 +69,11 @@ namespace campvis {
void trackFloatingWindowsPosition(MdiFloatingWindow* floatingWindow, const QPoint& newPos);
/**
* Track the position of an MDI subwindow and detach it if necessary.
* Track the position of a docked MDI window and detach it if necessary.
*
* This slot is invoked when the position of an MDI subwindow changes.
*/
void trackMdiSubWindowsPosition(PipelineMdiSubWindow* mdiSubWindow, const QPoint& newPos);
void trackMdiSubWindowsPosition(MdiDockedWindow* mdiSubWindow, const QPoint& newPos);
};
}
......
......@@ -27,27 +27,27 @@
//
// ================================================================================================
#include "pipelinemdisubwindow.h"
#include "mdidockedwindow.h"
#include <QMdiArea>
#include <QMoveEvent>
namespace campvis {
PipelineMdiSubWindow::PipelineMdiSubWindow(QWidget* parent /*= 0*/, Qt::WindowFlags flags /*= 0*/)
MdiDockedWindow::MdiDockedWindow(QWidget* parent /*= 0*/, Qt::WindowFlags flags /*= 0*/)
: QMdiSubWindow(parent, flags)
, _dragActive(false)
, _lastMousePos()
{}
void PipelineMdiSubWindow::stopWindowDrag() {
void MdiDockedWindow::stopWindowDrag() {
if (_dragActive) {
_dragActive = false;
releaseMouse();
}
}
void PipelineMdiSubWindow::mouseMoveEvent(QMouseEvent* event) {
void MdiDockedWindow::mouseMoveEvent(QMouseEvent* event) {
if (event->buttons().testFlag(Qt::LeftButton)) {
const QPoint& mousePos = event->globalPos();
......@@ -81,7 +81,7 @@ namespace campvis {
}
}
void PipelineMdiSubWindow::mouseReleaseEvent(QMouseEvent* event) {
void MdiDockedWindow::mouseReleaseEvent(QMouseEvent* event) {
if (event->button() == Qt::LeftButton) {
stopWindowDrag();
mdiArea()->tileSubWindows();
......
......@@ -27,34 +27,34 @@
//
// ================================================================================================
#ifndef PIPELINEMDISUBWINDOW_H__
#define PIPELINEMDISUBWINDOW_H__
#ifndef MDIDOCKEDWINDOW_H__
#define MDIDOCKEDWINDOW_H__
#include <QMdiSubWindow>
namespace campvis {
/**
* QMdiSubWindow subclass for visualization pipeline widgets.
* QMdiSubWindow subclass representing a window docked in an MdiDockArea.
*
* PipelineMdiSubWindow reports changes in its position via the s_positionChanged signal.
* Higher-level components listen to this signal to decide when to detach the subwindow from
* its MDI area. PipelineMdiSubWindow also implements additional methods (stopWindowDrag) that
* should be used to coordinate this detaching with respect to grabbing/releasing the mouse
* input.
* MdiDockedWindow reports changes in its position via the s_positionChanged signal. Its
* MdiDockArea listens to this signal to decide when to detach the window.
*
* MdiDockedWindow implements additional methods (stopWindowDrag) that should be used to
* coordinate its detaching with respect to grabbing/releasing the mouse input.
*/
class PipelineMdiSubWindow : public QMdiSubWindow {
class MdiDockedWindow : public QMdiSubWindow {
Q_OBJECT
public:
/**
* Construct an MDI subwindow for a visualization pipeline.
* Construct a new docked MDI window.
*
* \param parent the window's parent
* \param flags options customizing the frame of the subwindow
*/
explicit PipelineMdiSubWindow(QWidget* parent = 0, Qt::WindowFlags flags = 0);
explicit MdiDockedWindow(QWidget* parent = 0, Qt::WindowFlags flags = 0);
/**
* Cancel the dragging of the window.
......@@ -66,20 +66,20 @@ namespace campvis {
signals:
/**
* Emitted when the subwindow's position changes.
* Emitted when the window's position changes.
*
* \param newPos the subwindow's new position
* \param newPos the window's new position
*/
void s_positionChanged(PipelineMdiSubWindow* mdiSubWindow, const QPoint& newPos);
void s_positionChanged(MdiDockedWindow* mdiSubWindow, const QPoint& newPos);
protected:
/**
* Event handler that receives mouse move events for the widget.
* Event handler that receives mouse move events for the window.
*/
virtual void mouseMoveEvent(QMouseEvent* event);
/**
* Event handler that receives mouse release events for the widget.
* Event handler that receives mouse release events for the window.
*/
virtual void mouseReleaseEvent(QMouseEvent * event);
......@@ -90,4 +90,4 @@ namespace campvis {
};
}
#endif // PIPELINEMDISUBWINDOW_H__
#endif // MDIDOCKEDWINDOW_H__
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