32 #ifndef Qt4Window_INCLUDE_ONCE 33 #define Qt4Window_INCLUDE_ONCE 38 #include <QtGui/QApplication> 39 #include <QtGui/QMouseEvent> 40 #include <QtGui/QWidget> 41 #include <QtCore/QUrl> 42 #include <QtCore/QTimer> 43 #include <QtCore/QObject> 44 #include <QtOpenGL/QGLWidget> 45 #include <QtOpenGL/QGLFormat> 59 using QObject::setObjectName;
62 :QGLWidget(parent,shareWidget,f),
65 setContinuousUpdate(
true);
66 setMouseTracking(
true);
67 setAutoBufferSwap(
false);
75 dispatchDestroyEvent();
80 if (ev->mimeData()->hasUrls())
81 ev->acceptProposedAction();
86 if ( ev->mimeData()->hasUrls() )
88 std::vector<vl::String> files;
89 QList<QUrl> list = ev->mimeData()->urls();
90 for(
int i=0; i<list.size(); ++i)
92 if (list[i].path().isEmpty())
95 if (list[i].path()[0] ==
'/')
96 files.push_back( list[i].path().toStdString().c_str()+1 );
98 files.push_back( list[i].path().toStdString().c_str() );
100 files.push_back( list[i].path().toStdString().c_str() );
103 dispatchFileDroppedEvent(files);
110 QGLContext* glctx =
new QGLContext(context()->format(),
this);
111 QGLFormat fmt = context()->format();
113 #if QT_VERSION >= 0x040700 117 fmt.setProfile( QGLFormat::CompatibilityProfile );
123 fmt.setProfile( QGLFormat::CoreProfile );
138 fmt.setRedBufferSize( info.
rgbaBits().
r() );
139 fmt.setGreenBufferSize( info.
rgbaBits().
g() );
140 fmt.setBlueBufferSize( info.
rgbaBits().
b() );
143 fmt.setAlphaBufferSize( info.
rgbaBits().
a() );
144 fmt.setAlpha( info.
rgbaBits().
a() != 0 );
150 fmt.setAccumBufferSize( accum );
151 fmt.setAccum( accum != 0 );
167 fmt.setStereo( info.
stereo() );
170 fmt.setSwapInterval( info.
vSync() ? 1 : 0 );
172 glctx->setFormat(fmt);
175 glctx->create(shareContext);
178 framebuffer()->setWidth(width);
179 framebuffer()->setHeight(height);
182 printf(
"--------------------------------------------\n");
183 printf(
"REQUESTED OpenGL Format:\n");
184 printf(
"--------------------------------------------\n");
185 printf(
"rgba = %d %d %d %d\n", fmt.redBufferSize(), fmt.greenBufferSize(), fmt.blueBufferSize(), fmt.alphaBufferSize() );
186 printf(
"double buffer = %d\n", (
int)fmt.doubleBuffer() );
187 printf(
"depth buffer size = %d\n", fmt.depthBufferSize() );
188 printf(
"depth buffer = %d\n", fmt.depth() );
189 printf(
"stencil buffer size = %d\n", fmt.stencilBufferSize() );
190 printf(
"stencil buffer = %d\n", fmt.stencil() );
191 printf(
"accum buffer size %d\n", fmt.accumBufferSize() );
192 printf(
"accum buffer %d\n", fmt.accum() );
193 printf(
"stereo = %d\n", (
int)fmt.stereo() );
194 printf(
"swap interval = %d\n", fmt.swapInterval() );
195 printf(
"multisample = %d\n", (
int)fmt.sampleBuffers() );
196 printf(
"multisample samples = %d\n", (
int)fmt.samples() );
200 printf(
"--------------------------------------------\n");
201 printf(
"OBTAINED OpenGL Format:\n");
202 printf(
"--------------------------------------------\n");
203 printf(
"rgba = %d %d %d %d\n", fmt.redBufferSize(), fmt.greenBufferSize(), fmt.blueBufferSize(), fmt.alphaBufferSize() );
204 printf(
"double buffer = %d\n", (
int)fmt.doubleBuffer() );
205 printf(
"depth buffer size = %d\n", fmt.depthBufferSize() );
206 printf(
"depth buffer = %d\n", fmt.depth() );
207 printf(
"stencil buffer size = %d\n", fmt.stencilBufferSize() );
208 printf(
"stencil buffer = %d\n", fmt.stencil() );
209 printf(
"accum buffer size %d\n", fmt.accumBufferSize() );
210 printf(
"accum buffer %d\n", fmt.accum() );
211 printf(
"stereo = %d\n", (
int)fmt.stereo() );
212 printf(
"swap interval = %d\n", fmt.swapInterval() );
213 printf(
"multisample = %d\n", (
int)fmt.sampleBuffers() );
214 printf(
"multisample samples = %d\n", (
int)fmt.samples() );
215 printf(
"--------------------------------------------\n");
218 setWindowTitle(title);
220 resize(width,height);
230 mContinuousUpdate = continuous;
233 disconnect(&mUpdateTimer, SIGNAL(timeout()),
this, SLOT(updateGL()));
234 connect(&mUpdateTimer, SIGNAL(timeout()),
this, SLOT(updateGL()));
235 mUpdateTimer.setSingleShot(
false);
236 mUpdateTimer.setInterval(mRefresh);
237 mUpdateTimer.start(0);
241 disconnect(&mUpdateTimer, SIGNAL(timeout()),
this, SLOT(updateGL()));
249 mUpdateTimer.setInterval(mRefresh);
267 dispatchResizeEvent(width, height);
272 dispatchUpdateEvent();
283 QGLWidget::setWindowTitle( QString::fromStdString(title.
toStdString()) );
288 mFullscreen = fullscreen;
290 QGLWidget::setWindowState(QGLWidget::windowState() | Qt::WindowFullScreen);
292 QGLWidget::setWindowState(QGLWidget::windowState() & (~Qt::WindowFullScreen));
298 eraseAllEventListeners();
299 QApplication::quit();
314 QGLWidget::move(x,y);
319 return vl::ivec2(QGLWidget::pos().x(), QGLWidget::pos().y());
325 QGLWidget::resize(w,h);
331 return vl::ivec2(QGLWidget::size().width(), QGLWidget::size().height());
336 QGLWidget::swapBuffers();
341 QGLWidget::makeCurrent();
346 QCursor::setPos( mapToGlobal(QPoint(x,y)) );
351 if (!mIgnoreNextMouseMoveEvent)
352 dispatchMouseMoveEvent(ev->x(), ev->y());
353 mIgnoreNextMouseMoveEvent =
false;
367 dispatchMouseDownEvent(bt, ev->x(), ev->y());
381 dispatchMouseUpEvent(bt, ev->x(), ev->y());
386 dispatchMouseWheelEvent(ev->delta() / 120);
391 unsigned short unicode_ch = 0;
394 dispatchKeyPressEvent(unicode_ch, key);
399 unsigned short unicode_ch = 0;
402 dispatchKeyReleaseEvent(unicode_ch, key);
407 mMouseVisible=visible;
409 QGLWidget::setCursor(Qt::ArrowCursor);
411 QGLWidget::setCursor(Qt::BlankCursor);
416 QGLWidget::setFocus(Qt::OtherFocusReason);
Vector2< int > ivec2
A 2 components vector with int precision.
void setAutomaticDelete(bool autodel_on)
If set to true the Object is deleted when its reference count reaches 0.
int stencilBufferBits() const
void setObjectName(const char *name)
The name of the object, by default set to the object's class name in debug builds.
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
int multisampleSamples() const
const T_Scalar & r() const
Represents an OpenGL context, possibly a widget or a pbuffer, which can also respond to keyboard...
const T_Scalar & g() const
The OpenGLContextFormat class encapsulates the settings of an OpenGL rendering context.
const ivec4 & rgbaBits() const
float max(float a, float b)
const ivec4 & accumRGBABits() const
The Qt4 bindings namespace.
const T_Scalar & b() const
EOpenGLProfile openGLProfile() const
VLEGL_EXPORT void translateKeyEvent(WPARAM wParam, LPARAM lParam, unsigned short &unicode_out, vl::EKey &key_out)
int depthBufferBits() const
std::string toStdString() const
Returns a UTF8 encoded std::string.
bool doubleBuffer() const
const T_Scalar & a() const