31 #pragma warning(disable:4127)
32 #pragma warning(disable:4512)
38 #include "QVTKInteractorAdapter.h"
39 #include "QVTKInteractor.h"
42 #include "qapplication.h"
44 #include "qsignalmapper.h"
46 #include "vtkRenderingOpenGLModule.h"
48 #include "qx11info_x11.h"
56 #include "vtkInteractorStyleTrackballCamera.h"
57 #include "vtkRenderWindow.h"
58 #include "vtkCommand.h"
59 #include "vtkOStrStreamWrapper.h"
60 #include "vtkObjectFactory.h"
61 #include "vtkCallbackCommand.h"
62 #include "vtkConfigure.h"
63 #include "vtkUnsignedCharArray.h"
64 #include "vtkImageData.h"
65 #include "vtkPointData.h"
66 #include "vtkRenderer.h"
67 #include "vtkRendererCollection.h"
69 #if defined(VTK_USE_TDX) && defined(Q_WS_X11)
70 # include "vtkTDxUnixDevice.h"
75 : QWidget(p, f | Qt::MSWindowsOwnDC), mRenWin(NULL)
84 this->setFocusPolicy(Qt::StrongFocus);
88 this->setMouseTracking(
true);
92 QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding )
115 #if defined(VTK_USE_TDX) && defined(Q_WS_X11)
116 QByteArray theSignal=
117 QMetaObject::normalizedSignature(
"CreateDevice(vtkTDxDevice *)");
118 if(QApplication::instance()->metaObject()->indexOfSignal(theSignal)!=-1)
120 QObject::connect(QApplication::instance(),
121 SIGNAL(CreateDevice(vtkTDxDevice *)),
123 SLOT(setDevice(vtkTDxDevice *)));
127 vtkGenericWarningMacro(
"Missing signal CreateDevice on QApplication. 3DConnexion device will not work. Define it or derive your QApplication from QVTKApplication.");
147 vtkRenderWindow* win = vtkRenderWindow::New();
176 this->
mRenWin->SetDisplayId(NULL);
178 this->
mRenWin->SetWindowId(NULL);
179 this->
mRenWin->UnRegister(NULL);
198 this->
mRenWin->SetDisplayId(QX11Info::display());
205 this->
mRenWin->SetWindowId( reinterpret_cast<void*>(this->winId()));
208 this->
mRenWin->vtkRenderWindow::SetSize(this->width(), this->height());
209 this->
mRenWin->vtkRenderWindow::SetPosition(this->x(), this->y());
218 if(!this->
mRenWin->GetInteractor())
221 QVTKInteractor* iren = QVTKInteractor::New();
222 iren->SetUseTDx(this->
UseTDx);
223 this->
mRenWin->SetInteractor(iren);
227 vtkInteractorStyle* s = vtkInteractorStyleTrackballCamera::New();
228 iren->SetInteractorStyle(s);
234 this->
mRenWin->GetInteractor()->SetSize(this->width(), this->height());
244 return QVTKInteractor
254 if(e->type() == QEvent::ParentAboutToChange)
266 else if(e->type() == QEvent::ParentChange)
272 this->
mRenWin->SetWindowId( reinterpret_cast<void*>(this->winId()));
282 if(QObject::event(e))
287 if(e->type() == QEvent::KeyPress)
289 QKeyEvent* ke =
static_cast<QKeyEvent*
>(e);
291 return ke->isAccepted();
294 return QWidget::event(e);
303 QWidget::resizeEvent(e);
313 this->
mRenWin->vtkRenderWindow::SetSize(this->width(), this->height());
316 if(this->
mRenWin->GetInteractor())
325 QWidget::moveEvent(e);
335 this->
mRenWin->vtkRenderWindow::SetPosition(this->x(), this->y());
342 std::cout <<
"******************** paintEvent " <<
this << std::endl;
343 std::cout <<
" xy= " << this->x() <<
", " << this->y() <<
" \t wh= " << this->width() <<
", " << this->height() << std::endl;
537 QWidget::showEvent(e);
545 #if defined(VTK_USE_OPENGL_LIBRARY)
546 #include "vtkXOpenGLRenderWindow.h"
553 void CXQVTKWidget::setDevice(vtkTDxDevice *device)
577 bool tracking = this->hasMouseTracking();
578 Qt::FocusPolicy focus_policy = focusPolicy();
579 bool visible = isVisible();
589 Display* display =
reinterpret_cast<Display*
>(
mRenWin->GetGenericDisplayId());
592 #if defined(VTK_USE_OPENGL_LIBRARY)
593 vtkXOpenGLRenderWindow* ogl_win = vtkXOpenGLRenderWindow::SafeDownCast(
mRenWin);
596 vi = ogl_win->GetDesiredVisualInfo();
597 cmap = ogl_win->GetDesiredColormap();
613 XSetWindowAttributes attrib;
614 attrib.colormap = cmap;
615 attrib.border_pixel = 0;
616 attrib.background_pixel = 0;
618 Window p = RootWindow(display, DefaultScreen(display));
621 p = parentWidget()->winId();
625 XGetWindowAttributes(display, this->winId(), &a);
627 Window win = XCreateWindow(display, p, a.x, a.y, a.width, a.height,
628 0, vi->depth, InputOutput, vi->visual,
629 CWBackPixel|CWBorderPixel|CWColormap, &attrib);
635 if ( XGetWMColormapWindows(display, topLevelWidget()->winId(), &cmwret, &count) )
637 cmw =
new Window[count+1];
638 memcpy( (
char *)cmw, (
char *)cmwret,
sizeof(Window)*count );
639 XFree( (
char *)cmwret );
641 for ( i=0; i<count; i++ )
643 if ( cmw[i] == winId() )
657 cmw =
new Window[count];
666 XSetWMColormapWindows( display, topLevelWidget()->winId(), cmw, count );
674 this->setMouseTracking(tracking);
675 this->setAttribute(Qt::WA_NoBackground);
676 this->setAttribute(Qt::WA_PaintOnScreen);
677 this->setFocusPolicy(focus_policy);
686 #if defined(Q_WS_WIN)
687 bool CXQVTKWidget::winEvent(MSG* msg,
long*)
692 if(msg->message == WM_PAINT &&
693 QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA)
695 InvalidateRect(this->winId(), NULL, FALSE);