14 #include <QResizeEvent> 15 #include "vtkRenderWindow.h" 16 #include "vtkRenderer.h" 17 #include <QGridLayout> 30 mRenderWindowFactory(factory),
31 QVTKWidget(parent, f),
32 mMouseEventTarget(NULL),
35 mOffScreenRendering =
false;
36 this->setContextMenuPolicy(Qt::CustomContextMenu);
37 connect(
this, SIGNAL(customContextMenuRequested(
const QPoint &)),
this, SLOT(customContextMenuRequestedSlot(
const QPoint &)));
40 this->setLayout(
new QGridLayout);
41 disableGLHiDPI(this->winId());
69 return dynamic_cast<QGridLayout*
>(layout());
72 void ViewContainer::paintEvent(QPaintEvent* event)
74 inherited_widget::paintEvent(event);
101 this->initializeRenderWindow();
117 mOffScreenRendering = on;
122 return mOffScreenRendering;
125 void ViewContainer::initializeRenderWindow()
130 QString uid = QString(
"rw_oscr=%1").arg(mOffScreenRendering);
132 bool renderWindowExists = mRenderWindowFactory->renderWindowExists(uid);
134 mRenderWindow = mRenderWindowFactory->getRenderWindow(uid, mOffScreenRendering);
135 if(!renderWindowExists)
163 rw->AddRenderer(renderer);
164 renderer->SetViewport(0,0,1,1);
165 QColor background = palette().color(QPalette::Background);
166 renderer->SetBackground(background.redF(), background.greenF(), background.blueF());
169 void ViewContainer::customContextMenuRequestedSlot(
const QPoint& point)
171 ViewItem* item = this->findViewItem(point);
175 QWidget* sender =
dynamic_cast<QWidget*
>(this->sender());
176 QPoint pointGlobal = sender->mapToGlobal(point);
181 void ViewContainer::mouseMoveEvent(QMouseEvent* event)
183 inherited_widget::mouseMoveEvent(event);
192 void ViewContainer::mousePressEvent(QMouseEvent* event)
198 if ((this->contextMenuPolicy() == Qt::CustomContextMenu) && event->buttons().testFlag(Qt::RightButton))
201 inherited_widget::mousePressEvent(event);
211 QPoint ViewContainer::convertToItemSpace(
const QPoint &pos,
ViewItem* item)
const 214 QPoint retval(pos.x() - r.left(), pos.y() - r.top());
218 ViewItem* ViewContainer::findViewItem(
const QPoint &pos)
230 void ViewContainer::mouseReleaseEvent(QMouseEvent* event)
232 inherited_widget::mouseReleaseEvent(event);
242 void ViewContainer::focusInEvent(QFocusEvent* event)
244 inherited_widget::focusInEvent(event);
247 void ViewContainer::wheelEvent(QWheelEvent* event)
249 inherited_widget::wheelEvent(event);
251 ViewItem *item = this->findViewItem(event->pos());
254 QPoint p = this->convertToItemSpace(event->pos(), item);
256 event->delta(),
event->orientation(),
event->buttons());
260 void ViewContainer::showEvent(QShowEvent* event)
262 inherited_widget::showEvent(event);
272 hash += item->
getView()->computeTotalMTime();
280 QString msg(
"During rendering of ViewContainer");
292 void ViewContainer::resizeEvent( QResizeEvent *event)
294 inherited_widget::resizeEvent(event);
void mouseWheelSlot(int x, int y, int delta, int orientation, Qt::MouseButtons buttons)
vtkSmartPointer< class vtkRenderWindow > vtkRenderWindowPtr
cstring_cast_Placeholder cstring_cast(const T &val)
ViewContainer(RenderWindowFactoryPtr factory, QWidget *parent=NULL, Qt::WindowFlags f=0)
LayoutPosition span
size of region
void mouseReleaseSlot(int x, int y, Qt::MouseButtons buttons)
#define report_gl_error_text(text)
ViewItem * addView(QString uid, LayoutRegion region, QString name="")
void mousePressSlot(int x, int y, Qt::MouseButtons buttons)
vtkSmartPointer< class vtkRenderer > vtkRendererPtr
ViewItem * getViewItem(int index)
vtkRenderWindowPtr getRenderWindow()
unsigned long mMTimeHash
sum of all MTimes in objects rendered
void mouseMoveSlot(int x, int y, Qt::MouseButtons buttons)
void setStretchFactors(QGridLayout *layout, LayoutRegion region, int stretchFactor)
virtual void setModified()
void renderAll()
Use this function to render all views at once. Do not call render on each view.
static const int MaxGridSize
LayoutPosition pos
start position of region
virtual void setOffScreenRenderingAndClear(bool on)
boost::shared_ptr< class RenderWindowFactory > RenderWindowFactoryPtr
virtual QGridLayout * getGridLayout()
void customContextMenuRequestedGlobalSlot(const QPoint &point)
ViewRepCollectionPtr getView()
virtual QRect geometry() const
virtual bool getOffScreenRendering() const
vtkRenderWindowPtr mRenderWindow
Namespace for all CustusX production code.
ViewItem * mMouseEventTarget