Commit 62373ebf authored by Artur Grunau's avatar Artur Grunau
Browse files

Handle dragging VP widgets out of the MDI area

The way visualization pipelines are displayed has been considerably
reworked. A new class, VisualizationPipelineWrapper, is now responsible
for creating all necessary representations (VisualizationPipelineWidget,
PipelineMdiSubwindow) of a visualization pipeline and seamlessly
switching between them in response to the user's actions (window
dragging, key presses, etc). As a result, it's now possible to drag
visualization pipeline widgets out of the MDI area and turn them into
top-level floating windows.
parent 02d432e8
......@@ -34,6 +34,9 @@ SET(CampvisApplicationToBeMocced
gui/qtdatahandle.h
gui/logviewerwidget.h
gui/loghighlighter.h
gui/pipelinemdisubwindow.h
gui/visualizationpipelinewidget.h
gui/visualizationpipelinewrapper.h
gui/properties/abstractpropertywidget.h
gui/properties/abstracttransferfunctioneditor.h
gui/properties/boolpropertywidget.h
......
......@@ -34,6 +34,7 @@
#include "application/gui/datacontainerinspectorwidget.h"
#include "application/gui/datacontainerinspectorcanvas.h"
#include "application/gui/qtdatahandle.h"
#include "application/gui/visualizationpipelinewrapper.h"
#include "core/pipeline/abstractpipeline.h"
#include "core/pipeline/abstractprocessor.h"
......@@ -198,9 +199,8 @@ namespace campvis {
_logViewer->deinit();
}
void MainWindow::addVisualizationPipelineWidget(const std::string& name, QWidget* widget) {
QMdiSubWindow* subWindow = _mdiArea->addSubWindow(widget);
subWindow->setWindowTitle(QString::fromStdString(name));
void MainWindow::addVisualizationPipelineWidget(const std::string& name, QWidget* canvas) {
VisualizationPipelineWrapper* widget = new VisualizationPipelineWrapper(name, canvas, _mdiArea, this);
}
QDockWidget* MainWindow::dockPrimaryWidget(const std::string& name, QWidget* widget) {
......
......@@ -92,10 +92,10 @@ namespace campvis {
/**
* Adds a widget of a visualization pipeline to the main window.
* \param name the name of the visualization pipeline.
* \param widget the pipeline's widget to add to the main window.
* \param name the name of the visualization pipeline
* \param canvas the pipeline's canvas
*/
void addVisualizationPipelineWidget(const std::string& name, QWidget* widget);
void addVisualizationPipelineWidget(const std::string& name, QWidget* canvas);
signals:
/// Qt signal for updating the PipelineWidget.
......
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universität München
// Boltzmannstr. 3, 85748 Garching b. München, Germany
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
//
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ================================================================================================
#include "pipelinemdisubwindow.h"
#include <QMdiArea>
#include <QMoveEvent>
#include <QApplication>
namespace campvis {
void PipelineMdiSubWindow::moveEvent(QMoveEvent* event) {
// Special move logic only applies if the event was generated by the user dragging the
// window. If it was caused by Qt laying out widgets before displaying them, ignore it.
if (QApplication::mouseButtons() != Qt::LeftButton) {
return;
}
const QPoint& pos = event->pos();
QMdiArea* mdiArea = this->mdiArea();
int halfWidth = frameGeometry().width() / 2;
int halfHeight = frameGeometry().height() / 2;
// Eject the subwindow if more than half of it has left the MDI area
if (pos.x() < -halfWidth || pos.y() < -halfHeight ||
pos.x() > mdiArea->width() - halfWidth ||
pos.y() > mdiArea->height() - halfHeight)
{
QWidget *widget = this->widget();
const QPoint& absolutePos = mdiArea->mapToGlobal(pos);
this->setWidget(0);
mdiArea->removeSubWindow(this);
if (widget != 0) {
widget->move(absolutePos);
widget->show();
}
emit s_leftMdiArea();
}
}
}
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universität München
// Boltzmannstr. 3, 85748 Garching b. München, Germany
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
//
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ================================================================================================
#ifndef PIPELINEMDISUBWINDOW_H__
#define PIPELINEMDISUBWINDOW_H__
#include <QMdiSubWindow>
namespace campvis {
/**
* QMdiSubWindow subclass for visualization pipeline widgets.
*
* PipelineMdiSubWindow implements special move semantics: once it's been mostly dragged out of
* its MDI area, it disappears and releases its widget, making it a top-level floating window.
*/
class PipelineMdiSubWindow : public QMdiSubWindow {
Q_OBJECT;
signals:
/**
* Emitted when the subwindow is ejected from the MDI area (by dragging).
*/
void s_leftMdiArea();
protected:
/**
* Event handler that receives move events for the window.
*/
virtual void moveEvent(QMoveEvent* event);
};
}
#endif // PIPELINEMDISUBWINDOW_H__
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitt Mnchen
// Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
//
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ================================================================================================
#include "visualizationpipelinewidget.h"
#include <QMdiArea>
#include <QMoveEvent>
#include <QHBoxLayout>
namespace campvis {
VisualizationPipelineWidget::VisualizationPipelineWidget(QWidget* canvas, QWidget* parent /*= 0*/)
: QWidget(parent)
, _dragActive(false)
{
QLayout* layout = new QHBoxLayout();
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(canvas);
setLayout(layout);
}
void VisualizationPipelineWidget::forceWindowDrag() {
if (!_dragActive) {
_dragActive = true;
_lastMousePos = QCursor::pos();
grabMouse();
}
}
void VisualizationPipelineWidget::mouseMoveEvent(QMouseEvent* event) {
const QPoint& mousePos = event->globalPos();
move(pos() + (mousePos - _lastMousePos));
_lastMousePos = mousePos;
}
void VisualizationPipelineWidget::mouseReleaseEvent(QMouseEvent* event) {
if (event->button() == Qt::LeftButton) {
_dragActive = false;
releaseMouse();
}
}
}
\ No newline at end of file
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universität München
// Boltzmannstr. 3, 85748 Garching b. München, Germany
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
//
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ================================================================================================
#ifndef VISUALIZATIONPIPELINEWIDGET_H__
#define VISUALIZATIONPIPELINEWIDGET_H__
#include <QWidget>
namespace campvis {
/**
* Specialised widget for visualization pipelines.
*
* VisualizationPipelineWidget can be seamlessly used with MDI subwindows, as well as
* a top-level floating window.
*/
class VisualizationPipelineWidget : public QWidget {
Q_OBJECT;
public:
/**
* Construct a floating widget for a visualization pipeline.
*
* \param canvas the pipeline's canvas
* \param parent the widget's parent
*/
VisualizationPipelineWidget(QWidget* canvas, QWidget* parent = 0);
public slots:
/**
* Enter the widget into forced drag mode.
*
* This slot is invoked after the the widget has been detached from an MDI area and become
* a floating window. It lets the user drag the window as if it was still the same widget
* (MdiSubWindow) that has just been "pulled out" of the MDI area.
*/
void forceWindowDrag();
protected:
/**
* Event handler that receives mouse move events for the widget.
*/
virtual void mouseMoveEvent(QMouseEvent* event);
/**
* Event handler that receives mouse release events for the widget.
*/
virtual void mouseReleaseEvent(QMouseEvent * event);
private:
bool _dragActive; ///< Is the widget currently being dragged?
QPoint _lastMousePos; ///< Last reported mouse position
};
}
#endif // VISUALIZATIONPIPELINEWIDGET_H__
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitt Mnchen
// Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
//
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ================================================================================================
#include "visualizationpipelinewrapper.h"
namespace campvis {
VisualizationPipelineWrapper::VisualizationPipelineWrapper(const std::string& name, QWidget* canvas,
QMdiArea* mdiArea, QObject* parent /*= 0*/)
: QObject(parent)
, _mdiArea(mdiArea)
{
_pipelineWidget = new VisualizationPipelineWidget(canvas);
_mdiSubWindow = new PipelineMdiSubWindow();
_mdiSubWindow->setWidget(_pipelineWidget);
mdiArea->addSubWindow(_mdiSubWindow);
_mdiSubWindow->setWindowTitle(QString::fromStdString(name));
connect(_mdiSubWindow, SIGNAL(s_leftMdiArea()), _pipelineWidget, SLOT(forceWindowDrag()));
connect(_mdiSubWindow, SIGNAL(s_leftMdiArea()), this, SLOT(retileMdiSubWindows()));
}
void VisualizationPipelineWrapper::retileMdiSubWindows() {
_mdiArea->tileSubWindows();
}
}
\ No newline at end of file
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universität München
// Boltzmannstr. 3, 85748 Garching b. München, Germany
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
//
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ================================================================================================
#ifndef VISUALIZATIONPIPELINEWRAPPER_H__
#define VISUALIZATIONPIPELINEWRAPPER_H__
#include "pipelinemdisubwindow.h"
#include "visualizationpipelinewidget.h"
#include <QMdiArea>
namespace campvis {
/**
* Display wrapper for visualization pipelines.
*
* VisualizationPipelineWrapper takes care of creating all necessary representations (widget,
* MDI subwindow) of a visualization pipeline and seamlessly switching between them in
* response to the user's actions (window dragging, key presses, etc).
*/
class VisualizationPipelineWrapper : public QObject {
Q_OBJECT;
public:
/**
* Construct a wrapper for a visualization pipeline.
*
* This constructor creates a widget for the visualization pipeline it's passed. It then
* adds it to an MDI subwindow, and places it in the specified MDI area.
*
* \param name the name of the visualization pipeline
* \param canvas the pipeline's canvas
* \param mdiArea the MDI are to which the widget should be added
* \param parent the widget's parent
*/
VisualizationPipelineWrapper(const std::string& name, QWidget* canvas,
QMdiArea* mdiArea, QObject* parent = 0);
private slots:
/**
* Re-tile subwindows in the MDI area.
*
* This slot is invoked whenever the pipeline's MDI subwindow is detached or reattached.
*/
void retileMdiSubWindows();
private:
QMdiArea* _mdiArea; ///< The MDI area associated with the widget
PipelineMdiSubWindow* _mdiSubWindow; ///< An MDI subwindow for the pipeline
VisualizationPipelineWidget* _pipelineWidget; ///< A widget for the pipeline
};
}
#endif // VISUALIZATIONPIPELINEWRAPPER_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