32 #ifndef Qt6Window_INCLUDE_ONCE 33 #define Qt6Window_INCLUDE_ONCE 38 #include <QApplication> 39 #include <QMouseEvent> 45 #include <QOpenGLWidget> 46 #include <QOpenGLContext> 60 using QObject::setObjectName;
64 QWidget *parent =
NULL,
65 Qt::WindowFlags f = Qt::WindowFlags()
67 QOpenGLWidget(parent, f),
70 setContinuousUpdate(
true);
71 setMouseTracking(
true);
80 dispatchDestroyEvent();
85 if (ev->mimeData()->hasUrls())
86 ev->acceptProposedAction();
91 if (ev->mimeData()->hasUrls())
93 std::vector<vl::String> files;
94 QList<QUrl> list = ev->mimeData()->urls();
95 for (
int i = 0; i < list.size(); ++i)
97 if (list[i].path().isEmpty())
100 if (list[i].path()[0] ==
'/')
101 files.push_back(list[i].path().toStdString().c_str() + 1);
103 files.push_back(list[i].path().toStdString().c_str());
105 files.push_back(list[i].path().toStdString().c_str());
108 dispatchFileDroppedEvent(files);
114 QSurfaceFormat fmt = format();
119 fmt.setProfile(QSurfaceFormat::CompatibilityProfile);
126 fmt.setProfile(QSurfaceFormat::CoreProfile);
138 fmt.setSwapBehavior( info.
doubleBuffer() ? QSurfaceFormat::DoubleBuffer : QSurfaceFormat::SingleBuffer );
142 fmt.setRedBufferSize(info.
rgbaBits().
r());
143 fmt.setGreenBufferSize(info.
rgbaBits().
g());
144 fmt.setBlueBufferSize(info.
rgbaBits().
b());
147 fmt.setAlphaBufferSize(info.
rgbaBits().
a());
171 fmt.setStereo(info.
stereo());
174 fmt.setSwapInterval( info.
vSync() ? 1 : 0 );
176 this->QOpenGLWidget::setFormat( fmt );
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.swapBehavior() == QSurfaceFormat::DoubleBuffer );
187 printf(
"depth buffer size = %d\n", fmt.depthBufferSize());
188 printf(
"depth buffer = %d\n", fmt.depthBufferSize());
189 printf(
"stencil buffer size = %d\n", fmt.stencilBufferSize());
190 printf(
"stencil buffer = %d\n", fmt.stencilBufferSize());
191 printf(
"accum buffer size %d\n", 0);
192 printf(
"accum buffer %d\n", 0);
193 printf(
"stereo = %d\n", (
int)fmt.stereo());
194 printf(
"swap interval = %d\n", fmt.swapInterval());
195 printf(
"multisample = %d\n", (
int)fmt.samples() != 0);
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.swapBehavior() == QSurfaceFormat::DoubleBuffer );
205 printf(
"depth buffer size = %d\n", fmt.depthBufferSize());
206 printf(
"depth buffer = %d\n", fmt.depthBufferSize());
207 printf(
"stencil buffer size = %d\n", fmt.stencilBufferSize());
208 printf(
"stencil buffer = %d\n", fmt.stencilBufferSize());
209 printf(
"accum buffer size %d\n", 0);
210 printf(
"accum buffer %d\n", 0);
211 printf(
"stereo = %d\n", (
int)fmt.stereo());
212 printf(
"swap interval = %d\n", fmt.swapInterval());
213 printf(
"multisample = %d\n", (
int)fmt.samples() != 0);
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(update()));
234 connect(&mUpdateTimer, SIGNAL(timeout()),
this, SLOT(update()));
235 mUpdateTimer.setSingleShot(
false);
236 mUpdateTimer.setInterval(mRefresh);
237 mUpdateTimer.start(0);
241 disconnect(&mUpdateTimer, SIGNAL(timeout()),
this, SLOT(update()));
249 mUpdateTimer.setInterval(mRefresh);
271 dispatchResizeEvent(width, height);
276 dispatchUpdateEvent();
281 QOpenGLWidget::update();
286 QOpenGLWidget::setWindowTitle(QString::fromStdString(title.
toStdString()));
291 mFullscreen = fullscreen;
293 QOpenGLWidget::setWindowState(QOpenGLWidget::windowState() | Qt::WindowFullScreen);
295 QOpenGLWidget::setWindowState(QOpenGLWidget::windowState() & (~Qt::WindowFullScreen));
301 eraseAllEventListeners();
302 QApplication::quit();
307 QOpenGLWidget::show();
312 QOpenGLWidget::hide();
317 QOpenGLWidget::move(x, y);
322 return vl::ivec2(QOpenGLWidget::pos().x(), QOpenGLWidget::pos().y());
328 QOpenGLWidget::resize(w, h);
334 return vl::ivec2(QOpenGLWidget::size().width(), QOpenGLWidget::size().height());
345 QOpenGLWidget::makeCurrent();
350 QCursor::setPos(mapToGlobal(QPoint(x, y)));
355 if (!mIgnoreNextMouseMoveEvent)
356 dispatchMouseMoveEvent(ev->position().x(), ev->position().y());
357 mIgnoreNextMouseMoveEvent =
false;
363 switch (ev->button())
378 dispatchMouseDownEvent(bt, ev->position().x(), ev->position().y());
384 switch (ev->button())
399 dispatchMouseUpEvent(bt, ev->position().x(), ev->position().y());
404 dispatchMouseWheelEvent(ev->angleDelta().y() / 120);
409 unsigned short unicode_ch = 0;
412 dispatchKeyPressEvent(unicode_ch, key);
417 unsigned short unicode_ch = 0;
420 dispatchKeyReleaseEvent(unicode_ch, key);
425 mMouseVisible = visible;
427 QOpenGLWidget::setCursor(Qt::ArrowCursor);
429 QOpenGLWidget::setCursor(Qt::BlankCursor);
434 QOpenGLWidget::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.
void setExternallyManaged(bool em)
Wen externallyManaged() == true then this function does nothing.
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...
FramebufferObject * framebuffer()
The default render target (always returns leftFramebuffer()).
const T_Scalar & g() const
The OpenGLContextFormat class encapsulates the settings of an OpenGL rendering context.
const ivec4 & rgbaBits() 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
std::string toStdString() const
Returns a UTF8 encoded std::string.
bool doubleBuffer() const
const T_Scalar & a() const