32 #ifndef Qt5Window_INCLUDE_ONCE 33 #define Qt5Window_INCLUDE_ONCE 38 #include <QApplication> 39 #include <QMouseEvent> 60 using QObject::setObjectName;
63 :QGLWidget(parent,shareWidget,f),
66 setContinuousUpdate(
true);
67 setMouseTracking(
true);
68 setAutoBufferSwap(
false);
76 dispatchDestroyEvent();
81 if (ev->mimeData()->hasUrls())
82 ev->acceptProposedAction();
87 if ( ev->mimeData()->hasUrls() )
89 std::vector<vl::String> files;
90 QList<QUrl> list = ev->mimeData()->urls();
91 for(
int i=0; i<list.size(); ++i)
93 if (list[i].path().isEmpty())
96 if (list[i].path()[0] ==
'/')
97 files.push_back( list[i].path().toStdString().c_str()+1 );
99 files.push_back( list[i].path().toStdString().c_str() );
101 files.push_back( list[i].path().toStdString().c_str() );
104 dispatchFileDroppedEvent(files);
111 QGLContext* glctx =
new QGLContext(context()->format(),
this);
112 QGLFormat fmt = context()->format();
117 fmt.setProfile( QGLFormat::CompatibilityProfile );
123 fmt.setProfile( QGLFormat::CoreProfile );
137 fmt.setRedBufferSize( info.
rgbaBits().
r() );
138 fmt.setGreenBufferSize( info.
rgbaBits().
g() );
139 fmt.setBlueBufferSize( info.
rgbaBits().
b() );
142 fmt.setAlphaBufferSize( info.
rgbaBits().
a() );
143 fmt.setAlpha( info.
rgbaBits().
a() != 0 );
149 fmt.setAccumBufferSize( accum );
150 fmt.setAccum( accum != 0 );
166 fmt.setStereo( info.
stereo() );
169 fmt.setSwapInterval( info.
vSync() ? 1 : 0 );
171 glctx->setFormat(fmt);
174 glctx->create(shareContext);
177 framebuffer()->setWidth(width);
178 framebuffer()->setHeight(height);
181 printf(
"--------------------------------------------\n");
182 printf(
"REQUESTED OpenGL Format:\n");
183 printf(
"--------------------------------------------\n");
184 printf(
"rgba = %d %d %d %d\n", fmt.redBufferSize(), fmt.greenBufferSize(), fmt.blueBufferSize(), fmt.alphaBufferSize() );
185 printf(
"double buffer = %d\n", (
int)fmt.doubleBuffer() );
186 printf(
"depth buffer size = %d\n", fmt.depthBufferSize() );
187 printf(
"depth buffer = %d\n", fmt.depth() );
188 printf(
"stencil buffer size = %d\n", fmt.stencilBufferSize() );
189 printf(
"stencil buffer = %d\n", fmt.stencil() );
190 printf(
"accum buffer size %d\n", fmt.accumBufferSize() );
191 printf(
"accum buffer %d\n", fmt.accum() );
192 printf(
"stereo = %d\n", (
int)fmt.stereo() );
193 printf(
"swap interval = %d\n", fmt.swapInterval() );
194 printf(
"multisample = %d\n", (
int)fmt.sampleBuffers() );
195 printf(
"multisample samples = %d\n", (
int)fmt.samples() );
199 printf(
"--------------------------------------------\n");
200 printf(
"OBTAINED OpenGL Format:\n");
201 printf(
"--------------------------------------------\n");
202 printf(
"rgba = %d %d %d %d\n", fmt.redBufferSize(), fmt.greenBufferSize(), fmt.blueBufferSize(), fmt.alphaBufferSize() );
203 printf(
"double buffer = %d\n", (
int)fmt.doubleBuffer() );
204 printf(
"depth buffer size = %d\n", fmt.depthBufferSize() );
205 printf(
"depth buffer = %d\n", fmt.depth() );
206 printf(
"stencil buffer size = %d\n", fmt.stencilBufferSize() );
207 printf(
"stencil buffer = %d\n", fmt.stencil() );
208 printf(
"accum buffer size %d\n", fmt.accumBufferSize() );
209 printf(
"accum buffer %d\n", fmt.accum() );
210 printf(
"stereo = %d\n", (
int)fmt.stereo() );
211 printf(
"swap interval = %d\n", fmt.swapInterval() );
212 printf(
"multisample = %d\n", (
int)fmt.sampleBuffers() );
213 printf(
"multisample samples = %d\n", (
int)fmt.samples() );
214 printf(
"--------------------------------------------\n");
217 setWindowTitle(title);
219 resize(width,height);
229 mContinuousUpdate = continuous;
232 disconnect(&mUpdateTimer, SIGNAL(timeout()),
this, SLOT(updateGL()));
233 connect(&mUpdateTimer, SIGNAL(timeout()),
this, SLOT(updateGL()));
234 mUpdateTimer.setSingleShot(
false);
235 mUpdateTimer.setInterval(mRefresh);
236 mUpdateTimer.start(0);
240 disconnect(&mUpdateTimer, SIGNAL(timeout()),
this, SLOT(updateGL()));
248 mUpdateTimer.setInterval(mRefresh);
266 dispatchResizeEvent(width, height);
271 dispatchUpdateEvent();
282 QGLWidget::setWindowTitle( QString::fromStdString(title.
toStdString()) );
287 mFullscreen = fullscreen;
289 QGLWidget::setWindowState(QGLWidget::windowState() | Qt::WindowFullScreen);
291 QGLWidget::setWindowState(QGLWidget::windowState() & (~Qt::WindowFullScreen));
297 eraseAllEventListeners();
298 QApplication::quit();
313 QGLWidget::move(x,y);
318 return vl::ivec2(QGLWidget::pos().x(), QGLWidget::pos().y());
324 QGLWidget::resize(w,h);
330 return vl::ivec2(QGLWidget::size().width(), QGLWidget::size().height());
335 QGLWidget::swapBuffers();
340 QGLWidget::makeCurrent();
345 QCursor::setPos( mapToGlobal(QPoint(x,y)) );
350 if (!mIgnoreNextMouseMoveEvent)
351 dispatchMouseMoveEvent(ev->x(), ev->y());
352 mIgnoreNextMouseMoveEvent =
false;
366 dispatchMouseDownEvent(bt, ev->x(), ev->y());
380 dispatchMouseUpEvent(bt, ev->x(), ev->y());
385 dispatchMouseWheelEvent(ev->delta() / 120);
390 unsigned short unicode_ch = 0;
393 dispatchKeyPressEvent(unicode_ch, key);
398 unsigned short unicode_ch = 0;
401 dispatchKeyReleaseEvent(unicode_ch, key);
406 mMouseVisible=visible;
408 QGLWidget::setCursor(Qt::ArrowCursor);
410 QGLWidget::setCursor(Qt::BlankCursor);
415 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
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
The Qt5 bindings namespace.
std::string toStdString() const
Returns a UTF8 encoded std::string.
bool doubleBuffer() const
const T_Scalar & a() const