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

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

Refactor VisualizationPipelineWidget and rename it MdiFloatingWindow

VisualizationPipelineWidget has been renamed MdiFloatingWindow, and
refactored to make it easier to use it with arbitrary widgets.
parent 7e5e44b1
......@@ -38,7 +38,7 @@ SET(CampvisApplicationToBeMocced
gui/loghighlighter.h
gui/mdidockarea.h
gui/pipelinemdisubwindow.h
gui/visualizationpipelinewidget.h
gui/mdifloatingwindow.h
gui/adjusterwidgets/doubleadjusterwidget.h
gui/adjusterwidgets/intadjusterwidget.h
gui/properties/abstractpropertywidget.h
......
......@@ -45,23 +45,23 @@ namespace campvis {
return mdiSubWindow;
}
void MdiDockArea::trackFloatingWindowsPosition(VisualizationPipelineWidget* pipelineWidget, const QPoint& newPos) {
const QRect& widgetGeometry = pipelineWidget->frameGeometry();
void MdiDockArea::trackFloatingWindowsPosition(MdiFloatingWindow* floatingWindow, const QPoint& newPos) {
const QRect& widgetGeometry = floatingWindow->frameGeometry();
const QRect& mdiAreaRect = this->contentsRect();
const QRect mdiAreaGeometry(this->mapToGlobal(mdiAreaRect.topLeft()),
this->mapToGlobal(mdiAreaRect.bottomRight()));
const QRect& intersection = widgetGeometry & mdiAreaGeometry;
// Dock the widget if at least 60% of it is over the MDI area
// Dock the floating window's widget if at least 60% of it is over the MDI area
if (widgetGeometry.width() * widgetGeometry.height() * 3 <
intersection.width() * intersection.height() * 5) {
pipelineWidget->stopWindowDrag();
floatingWindow->stopWindowDrag();
QWidget* widget = pipelineWidget->canvas();
QWidget* widget = floatingWindow->widget();
PipelineMdiSubWindow* mdiSubWindow = this->addSubWindow(widget);
mdiSubWindow->setWindowTitle(pipelineWidget->windowTitle());
mdiSubWindow->setWindowTitle(floatingWindow->windowTitle());
widget->show();
pipelineWidget->deleteLater();
floatingWindow->deleteLater();
mdiSubWindow->move(this->mapFromGlobal(newPos));
mdiSubWindow->grabMouse();
......@@ -83,14 +83,14 @@ namespace campvis {
mdiSubWindow->deleteLater();
tileSubWindows();
VisualizationPipelineWidget* pipelineWidget = new VisualizationPipelineWidget(widget);
pipelineWidget->setWindowTitle(mdiSubWindow->windowTitle());
pipelineWidget->move(this->mapToGlobal(newPos));
pipelineWidget->show();
pipelineWidget->forceWindowDrag();
MdiFloatingWindow* floatingWindow = new MdiFloatingWindow(widget);
floatingWindow->setWindowTitle(mdiSubWindow->windowTitle());
floatingWindow->move(this->mapToGlobal(newPos));
floatingWindow->show();
floatingWindow->forceWindowDrag();
connect(pipelineWidget, SIGNAL(s_positionChanged(VisualizationPipelineWidget*, const QPoint&)),
this, SLOT(trackFloatingWindowsPosition(VisualizationPipelineWidget*, const QPoint&)));
connect(floatingWindow, SIGNAL(s_positionChanged(MdiFloatingWindow*, const QPoint&)),
this, SLOT(trackFloatingWindowsPosition(MdiFloatingWindow*, const QPoint&)));
}
}
......
......@@ -30,8 +30,8 @@
#ifndef MDIDOCKAREA_H__
#define MDIDOCKAREA_H__
#include "mdifloatingwindow.h"
#include "pipelinemdisubwindow.h"
#include "visualizationpipelinewidget.h"
#include <QMdiArea>
......@@ -63,16 +63,16 @@ namespace campvis {
private slots:
/**
* Track the position of the pipeline's widget and dock it if necessary.
* Track the position of a floating MDI window and dock it if necessary.
*
* This slot is invoked when the pipeline's widget is floating and its position changes.
* This slot is invoked when the position of a floating MDI window changes.
*/
void trackFloatingWindowsPosition(VisualizationPipelineWidget* pipelineWidget, const QPoint& newPos);
void trackFloatingWindowsPosition(MdiFloatingWindow* floatingWindow, const QPoint& newPos);
/**
* Track the position of the pipeline's MDI subwindow and detach it if necessary.
* Track the position of an MDI subwindow and detach it if necessary.
*
* This slot is invoked when the position of the pipeline's MDI subwindow changes.
* This slot is invoked when the position of an MDI subwindow changes.
*/
void trackMdiSubWindowsPosition(PipelineMdiSubWindow* mdiSubWindow, const QPoint& newPos);
......
......@@ -27,7 +27,7 @@
//
// ================================================================================================
#include "visualizationpipelinewidget.h"
#include "mdifloatingwindow.h"
#include <QMdiArea>
#include <QMoveEvent>
......@@ -35,20 +35,20 @@
namespace campvis {
VisualizationPipelineWidget::VisualizationPipelineWidget(QWidget* canvas, QWidget* parent /*= 0*/)
MdiFloatingWindow::MdiFloatingWindow(QWidget* widget, QWidget* parent /*= 0*/)
: QWidget(parent)
, _canvas(canvas)
, _widget(widget)
, _dragActive(false)
, _lastMousePos()
{
QLayout* layout = new QHBoxLayout();
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(canvas);
layout->addWidget(widget);
setLayout(layout);
}
void VisualizationPipelineWidget::forceWindowDrag() {
void MdiFloatingWindow::forceWindowDrag() {
if (!_dragActive && parent() == 0) {
_dragActive = true;
_lastMousePos = QCursor::pos();
......@@ -56,18 +56,18 @@ namespace campvis {
}
}
void VisualizationPipelineWidget::stopWindowDrag() {
void MdiFloatingWindow::stopWindowDrag() {
if (_dragActive) {
_dragActive = false;
releaseMouse();
}
}
QWidget* VisualizationPipelineWidget::canvas() {
return _canvas;
QWidget* MdiFloatingWindow::widget() {
return _widget;
}
void VisualizationPipelineWidget::mouseMoveEvent(QMouseEvent* event) {
void MdiFloatingWindow::mouseMoveEvent(QMouseEvent* event) {
const QPoint& mousePos = event->globalPos();
const QPoint& newPos = pos() + (mousePos - _lastMousePos);
......@@ -75,13 +75,13 @@ namespace campvis {
_lastMousePos = mousePos;
}
void VisualizationPipelineWidget::mouseReleaseEvent(QMouseEvent* event) {
void MdiFloatingWindow::mouseReleaseEvent(QMouseEvent* event) {
if (event->button() == Qt::LeftButton) {
stopWindowDrag();
}
}
void VisualizationPipelineWidget::moveEvent(QMoveEvent* /*event*/) {
void MdiFloatingWindow::moveEvent(QMoveEvent* /*event*/) {
emit s_positionChanged(this, frameGeometry().topLeft());
}
......
......@@ -27,75 +27,73 @@
//
// ================================================================================================
#ifndef VISUALIZATIONPIPELINEWIDGET_H__
#define VISUALIZATIONPIPELINEWIDGET_H__
#ifndef MDIFLOATINGWINDOW_H__
#define MDIFLOATINGWINDOW_H__
#include <QWidget>
namespace campvis {
/**
* Specialised widget for visualization pipelines.
* Specialised widget for detached MDI subwindows.
*
* VisualizationPipelineWidget can be seamlessly used with MDI subwindows and as a top-level
* floating window. When detached, it reports changes in its position via the s_positionChanged
* signal. Higher-level components listen to this signal to decide when to dock the widget in
* an MDI area. VisualizationPipelineWidget also implements additional methods (forceWindowDrag,
* stopWindowDrag) that should be used to coordinate the docking with respect to
* grabbing/releasing the mouse input.
* MdiFloatingWindow is a top-level floating window representing an undocked MDI subwindow.
* It reports changes in its position via the s_positionChanged signal. The MDI area that
* created it listens to this signal to decide when to scrap the floating window and dock back
* the widget that it wraps.
*
* MdiFloatingWindow also implements additional methods (forceWindowDrag, stopWindowDrag)
* that should be used to coordinate its creation/disposal with respect to grabbing/releasing
* the mouse input.
*/
class VisualizationPipelineWidget : public QWidget {
class MdiFloatingWindow : public QWidget {
Q_OBJECT
public:
/**
* Construct a widget for a visualization pipeline.
* Construct a new MdiFloatingWindow.
*
* \param canvas the pipeline's canvas
* \param parent the widget's parent
* \param canvas the widget this window is to wrap
* \param parent the windows's parent
*/
explicit VisualizationPipelineWidget(QWidget* canvas, QWidget* parent = 0);
explicit MdiFloatingWindow(QWidget* widget, QWidget* parent = 0);
/**
* Enter the widget into forced drag mode.
* Enter the window into forced drag mode.
*
* This method is to be invoked after the the widget has been detached from an MDI area and
* become a floating window. It causes the widget to grab the mouse input and follow the
* cursor. As a result, the user can seamlessly continue dragging the widget after it has
* been "pulled out" of the MDI area.
* This method causes the window to grab the mouse input and follow the cursor.
*/
void forceWindowDrag();
/**
* Cancel the dragging of the widget.
* Cancel the dragging of the window.
*
* This method causes the widget to release the mouse grab and stop following the cursor.
* It's supposed to be called when the widget is re-docked in an MDI area.
* This method causes the window to release the mouse grab and stop following the cursor.
*/
void stopWindowDrag();
/**
* Return the canvas this widget wraps.
* Return the widget this window wraps.
*/
QWidget* canvas();
QWidget* widget();
signals:
/**
* Emitted when the widget's position changes.
* Emitted when the window's position changes.
*
* \param newPos the widget's new position
* \param newPos the window's new position
*/
void s_positionChanged(VisualizationPipelineWidget *pipelineWidget, const QPoint& newPos);
void s_positionChanged(MdiFloatingWindow *pipelineWidget, 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);
......@@ -105,11 +103,11 @@ namespace campvis {
virtual void moveEvent(QMoveEvent* event);
private:
QWidget* _canvas; ///< The canvas this widget wraps
bool _dragActive; ///< Is the widget currently being dragged?
QWidget* _widget; ///< The widget this window wraps
bool _dragActive; ///< Is the window currently being dragged?
QPoint _lastMousePos; ///< Last reported mouse position
};
}
#endif // VISUALIZATIONPIPELINEWIDGET_H__
#endif // MDIFLOATINGWINDOW_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