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);
178 item->customContextMenuRequestedGlobalSlot(pointGlobal);
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
213 QRect r = item->geometry();
214 QPoint retval(pos.x() - r.left(), pos.y() - r.top());
218 ViewItem* ViewContainer::findViewItem(
const QPoint &pos)
223 QRect r = item->geometry();
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);
255 item->mouseWheelSlot(p.x(), p.y(),
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);