summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorOliver Wolff <oliver.wolff@qt.io>2023-04-03 10:35:41 +0200
committerOliver Wolff <oliver.wolff@qt.io>2023-04-06 10:36:26 +0200
commitf013e692ca7d6ed84cdece82d06ae73ec04bcc1d (patch)
tree483b5612c222c3a59075869a6f6a6af6465fbcf1 /tests
parent1bad3a86dcdc6c168090f17e93c86490d601d4f1 (diff)
examples: Remove opengl example
We should not have examples that are specific to opengl on Windows. In order to keep the use case's code in source, the example was moved to tests/manual. Pick-to: 6.5 Change-Id: Ie55aea777c449913e66279728c53f08c4105b66c Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/manual/opengl/CMakeLists.txt27
-rw-r--r--tests/manual/opengl/doc/src/opengl.qdoc105
-rw-r--r--tests/manual/opengl/glbox.cpp218
-rw-r--r--tests/manual/opengl/glbox.h53
-rw-r--r--tests/manual/opengl/globjwin.cpp72
-rw-r--r--tests/manual/opengl/globjwin.h24
-rw-r--r--tests/manual/opengl/main.cpp49
-rw-r--r--tests/manual/opengl/opengl.def6
-rw-r--r--tests/manual/opengl/opengl.icobin0 -> 766 bytes
-rw-r--r--tests/manual/opengl/opengl.inf9
-rw-r--r--tests/manual/opengl/opengl.pro18
-rw-r--r--tests/manual/opengl/opengl.rc2
12 files changed, 583 insertions, 0 deletions
diff --git a/tests/manual/opengl/CMakeLists.txt b/tests/manual/opengl/CMakeLists.txt
new file mode 100644
index 0000000..e8e4255
--- /dev/null
+++ b/tests/manual/opengl/CMakeLists.txt
@@ -0,0 +1,27 @@
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+#####################################################################
+## testcontrol Binary:
+#####################################################################
+
+set(CMAKE_AUTOMOC ON)
+
+qt_internal_add_manual_test(tst_opengl
+ GUI
+ SOURCES
+ glbox.cpp glbox.h
+ globjwin.cpp globjwin.h
+ main.cpp
+ opengl.def
+ opengl.rc
+ LIBRARIES
+ Qt::AxServer
+ Qt::Gui
+ Qt::OpenGL
+ Qt::OpenGLWidgets
+ Qt::Widgets
+)
+
+# qt_disable_warnings(tst_opengl)
+qt6_target_idl(tst_opengl)
diff --git a/tests/manual/opengl/doc/src/opengl.qdoc b/tests/manual/opengl/doc/src/opengl.qdoc
new file mode 100644
index 0000000..2558363
--- /dev/null
+++ b/tests/manual/opengl/doc/src/opengl.qdoc
@@ -0,0 +1,105 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \page qaxserver-demo-opengl.html
+
+ \title OpenGL in an HTML page
+
+ \raw HTML
+ <SCRIPT LANGUAGE="JavaScript">
+ function setRot( form )
+ {
+ GLBox.setXRotation( form.XEdit.value );
+ GLBox.setYRotation( form.YEdit.value );
+ GLBox.setZRotation( form.ZEdit.value );
+ }
+ </SCRIPT>
+
+ <p />
+ An OpenGL scene:<br />
+ <object ID="GLBox" CLASSID="CLSID:5fd9c22e-ed45-43fa-ba13-1530bb6b03e0"
+ CODEBASE="http://www.qt-project.org/demos/openglax.cab">
+ [Object not available! Did you forget to build and register the server?]
+ </object><br />
+
+ <form>
+ Rotate the scene:<br />
+ X:<input type="edit" ID="XEdit" value="0" /><br />
+ Y:<input type="edit" name="YEdit" value="0" /><br />
+ Z:<input type="edit" name="ZEdit" value="0" /><br />
+ <input type="button" value="Set" onClick="setRot(this.form)" />
+ </form>
+ \endraw
+*/
+
+/*!
+ \example activeqt/opengl
+ \title OpenGL Example (ActiveQt)
+
+ \brief The OpenGL example demonstrates the use of the default factory
+ and QAxFactory::isServer(), and the implementation of an
+ additional COM interface using QAxBindable and QAxAggregated.
+ The server executable can run both as an ActiveX server and as a
+ stand-alone application.
+
+ The ActiveX control in this example uses the QGlWidget class in
+ Qt to render an OpenGL scene in an ActiveX. The control exposes a few
+ methods to change the scene.
+
+ The application uses QAxFactory through the \c QAXFACTORY_BEGIN(),
+ \c QAXCLASS() and \c QAXFACTORY_END() macros to expose the
+ \c GLBox widget as an ActiveX control.
+ \snippet activeqt/opengl/main.cpp 0
+ The implementation of \c main initializes the QApplication object,
+ and uses \c QAxFactory::isServer() to determine whether or not it is
+ appropriate to create and show the application interface.
+ \snippet activeqt/opengl/main.cpp 1
+ \snippet activeqt/opengl/main.cpp 2
+ \snippet activeqt/opengl/main.cpp 3
+
+ The \c GLBox class inherits from both the \l QOpenGLWidget class to be able
+ to render OpenGL, and from \l QAxBindable.
+ \snippet activeqt/opengl/glbox.h 0
+ The class reimplements the \l QAxBindable::createAggregate() function from QAxBindable
+ to return the pointer to a \l QAxAggregated object.
+ \snippet activeqt/opengl/glbox.h 1
+
+ The implementation file of the \c GLBox class includes the \c objsafe.h
+ system header, in which the \c IObjectSafety COM interface is defined.
+ \snippet activeqt/opengl/glbox.cpp 0
+ A class \c ObjectSafetyImpl is declared using multiple inheritance
+ to subclass the QAxAggregated class, and to implement the IObjectSafety
+ interface.
+ \snippet activeqt/opengl/glbox.cpp 1
+ The class declares a default constructor, and implements the queryInterface
+ function to support the IObjectSafety interface.
+ \snippet activeqt/opengl/glbox.cpp 2
+ Since every COM interface inherits \c IUnknown the \c QAXAGG_IUNKNOWN macro
+ is used to provide the default implementation of the \c IUnknown interface.
+ The macro is defined to delegate all calls to \c QueryInterface, \c AddRef
+ and \c Release to the interface returned by the controllingUnknown() function.
+ \snippet activeqt/opengl/glbox.cpp 3
+ The implementation of the \c IObjectSafety interface provides the caller
+ with information about supported and enabled safety options, and returns
+ \c S_OK for all calls to indicate that the ActiveX control is safe.
+ \snippet activeqt/opengl/glbox.cpp 4
+ The implementation of the \c createAggregate() function just returns a new
+ \c ObjectSafetyImpl object.
+ \snippet activeqt/opengl/glbox.cpp 5
+
+ To build the example you must first build the QAxServer library.
+ Then run \c qmake and your make tool in \c
+ examples/activeqt/wrapper.
+
+ The \l{qaxserver-demo-opengl.html}{demonstration} requires your
+ WebBrowser to support ActiveX controls, and scripting to be
+ enabled.
+
+ In contrast to the other QAxServer examples Internet Explorer will not
+ open a dialog box to ask the user whether or not the scripting of the GLBox
+ control should be allowed (the exact browser behaviour depends on the security
+ settings in the Internet Options dialog).
+
+ \input doc/src/examples/opengl-demo.qdocinc
+*/
diff --git a/tests/manual/opengl/glbox.cpp b/tests/manual/opengl/glbox.cpp
new file mode 100644
index 0000000..3388670
--- /dev/null
+++ b/tests/manual/opengl/glbox.cpp
@@ -0,0 +1,218 @@
+// Copyright (C) 2015 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+/****************************************************************************
+**
+** This is a simple QGLWidget displaying an openGL wireframe box
+**
+** The OpenGL code is mostly borrowed from Brian Pauls "spin" example
+** in the Mesa distribution
+**
+****************************************************************************/
+
+#include "glbox.h"
+#include <QAxAggregated>
+#include <QUuid>
+//! [0]
+#include <objsafe.h>
+//! [0]
+
+/*!
+ Create a GLBox widget
+*/
+
+GLBox::GLBox(QWidget *parent, const char *name)
+ : QOpenGLWidget(parent)
+{
+ setObjectName(name);
+
+ QSurfaceFormat format;
+ format.setVersion(1, 1);
+ format.setProfile(QSurfaceFormat::CompatibilityProfile);
+ setFormat(format);
+}
+
+
+/*!
+ Release allocated resources
+*/
+
+GLBox::~GLBox()
+{
+ makeCurrent();
+
+ if (m_object)
+ glDeleteLists(m_object, 1);
+}
+
+
+/*!
+ Paint the box. The actual openGL commands for drawing the box are
+ performed here.
+*/
+
+void GLBox::paintGL()
+{
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ glLoadIdentity();
+ glTranslated(0, 0, -10);
+ glScaled(m_scale, m_scale, m_scale);
+
+ glRotated(m_xRot, 1, 0, 0);
+ glRotated(m_yRot, 0, 1, 0);
+ glRotated(m_zRot, 0, 0, 1);
+
+ glCallList(m_object);
+}
+
+
+/*!
+ Set up the OpenGL rendering state, and define display list
+*/
+
+void GLBox::initializeGL()
+{
+ initializeOpenGLFunctions();
+ glClearColor(0, 0, 0, 1); // Let OpenGL clear to black
+ m_object = makeObject(); // Generate an OpenGL display list
+ glShadeModel(GL_FLAT);
+}
+
+
+
+/*!
+ Set up the OpenGL view port, matrix mode, etc.
+*/
+
+void GLBox::resizeGL(int w, int h)
+{
+ glViewport(0, 0, (GLint)w, (GLint)h);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum(-1, 1, -1, 1, 5, 15);
+ glMatrixMode(GL_MODELVIEW);
+}
+
+
+/*!
+ Generate an OpenGL display list for the object to be shown, i.e. the box
+*/
+
+GLuint GLBox::makeObject()
+{
+ GLuint list;
+
+ list = glGenLists(1);
+
+ glNewList(list, GL_COMPILE);
+
+ glColor3d(1, 1, 1); // Shorthand for glColor3f or glIndex
+
+ glLineWidth(2);
+
+ glBegin(GL_LINE_LOOP);
+ glVertex3d( 1, 0.5, -0.4);
+ glVertex3d( 1, -0.5, -0.4);
+ glVertex3d(-1, -0.5, -0.4);
+ glVertex3d(-1, 0.5, -0.4);
+ glEnd();
+
+ glBegin(GL_LINE_LOOP);
+ glVertex3d( 1, 0.5, 0.4);
+ glVertex3d( 1, -0.5, 0.4);
+ glVertex3d(-1, -0.5, 0.4);
+ glVertex3d(-1, 0.5, 0.4);
+ glEnd();
+
+ glBegin(GL_LINES);
+ glVertex3d( 1, 0.5, -0.4); glVertex3d( 1, 0.5, 0.4);
+ glVertex3d( 1, -0.5, -0.4); glVertex3d( 1, -0.5, 0.4);
+ glVertex3d(-1, -0.5, -0.4); glVertex3d(-1, -0.5, 0.4);
+ glVertex3d(-1, 0.5, -0.4); glVertex3d(-1, 0.5, 0.4);
+ glEnd();
+
+ glEndList();
+
+ return list;
+}
+
+
+/*!
+ Set the rotation angle of the object to \e degrees around the X axis.
+*/
+
+void GLBox::setXRotation(int degrees)
+{
+ m_xRot = GLdouble(degrees % 360);
+ update();
+}
+
+
+/*!
+ Set the rotation angle of the object to \e degrees around the Y axis.
+*/
+
+void GLBox::setYRotation(int degrees)
+{
+ m_yRot = GLdouble(degrees % 360);
+ update();
+}
+
+
+/*!
+ Set the rotation angle of the object to \e degrees around the Z axis.
+*/
+
+void GLBox::setZRotation(int degrees)
+{
+ m_zRot = GLdouble(degrees % 360);
+ update();
+}
+
+//! [1]
+class ObjectSafetyImpl : public QAxAggregated,
+ public IObjectSafety
+{
+public:
+//! [1] //! [2]
+ explicit ObjectSafetyImpl() = default;
+
+ long queryInterface(const QUuid &iid, void **iface) override
+ {
+ *iface = nullptr;
+ if (iid != IID_IObjectSafety)
+ return E_NOINTERFACE;
+
+ *iface = static_cast<IObjectSafety*>(this);
+ AddRef();
+ return S_OK;
+ }
+
+//! [2] //! [3]
+ QAXAGG_IUNKNOWN;
+
+//! [3] //! [4]
+ HRESULT WINAPI GetInterfaceSafetyOptions(REFIID riid, DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions) override
+ {
+ Q_UNUSED(riid);
+ *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACESAFE_FOR_UNTRUSTED_CALLER;
+ *pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACESAFE_FOR_UNTRUSTED_CALLER;
+ return S_OK;
+ }
+
+ HRESULT WINAPI SetInterfaceSafetyOptions(REFIID riid, DWORD pdwSupportedOptions, DWORD pdwEnabledOptions) override
+ {
+ Q_UNUSED(riid);
+ Q_UNUSED(pdwSupportedOptions);
+ Q_UNUSED(pdwEnabledOptions);
+ return S_OK;
+ }
+};
+//! [4] //! [5]
+
+QAxAggregated *GLBox::createAggregate()
+{
+ return new ObjectSafetyImpl();
+}
+//! [5]
diff --git a/tests/manual/opengl/glbox.h b/tests/manual/opengl/glbox.h
new file mode 100644
index 0000000..a1b58da
--- /dev/null
+++ b/tests/manual/opengl/glbox.h
@@ -0,0 +1,53 @@
+// Copyright (C) 2015 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+/****************************************************************************
+**
+** This is a simple QGLWidget displaying an openGL wireframe box
+**
+****************************************************************************/
+
+#ifndef GLBOX_H
+#define GLBOX_H
+
+#include <QOpenGLWidget>
+#include <QOpenGLFunctions_1_1>
+//! [0]
+#include <QAxBindable>
+
+class GLBox : public QOpenGLWidget,
+ public QOpenGLFunctions_1_1,
+ public QAxBindable
+{
+ Q_OBJECT
+ Q_CLASSINFO("ClassID", "{5fd9c22e-ed45-43fa-ba13-1530bb6b03e0}")
+ Q_CLASSINFO("InterfaceID", "{33b051af-bb25-47cf-a390-5cfd2987d26a}")
+ Q_CLASSINFO("EventsID", "{8c996c29-eafa-46ac-a6f9-901951e765b5}")
+ //! [0] //! [1]
+
+public:
+ explicit GLBox(QWidget *parent, const char *name = nullptr);
+ virtual ~GLBox();
+ QAxAggregated *createAggregate() override;
+
+public slots:
+ void setXRotation(int degrees);
+//! [1]
+ void setYRotation(int degrees);
+ void setZRotation(int degrees);
+
+protected:
+ void initializeGL() override;
+ void paintGL() override;
+ void resizeGL(int w, int h) override;
+ virtual GLuint makeObject();
+
+private:
+ GLuint m_object = 0;
+ GLdouble m_xRot = 0;
+ GLdouble m_yRot = 0;
+ GLdouble m_zRot = 0;
+ GLdouble m_scale = 1.25;
+};
+
+#endif // GLBOX_H
diff --git a/tests/manual/opengl/globjwin.cpp b/tests/manual/opengl/globjwin.cpp
new file mode 100644
index 0000000..0b9cea1
--- /dev/null
+++ b/tests/manual/opengl/globjwin.cpp
@@ -0,0 +1,72 @@
+// Copyright (C) 2015 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "globjwin.h"
+#include "glbox.h"
+#include <QPushButton>
+#include <QSlider>
+#include <QLayout>
+#include <QFrame>
+#include <QMenuBar>
+#include <QMenu>
+#include <QApplication>
+
+
+GLObjectWindow::GLObjectWindow(QWidget *parent)
+ : QWidget(parent)
+{
+ // Create a menu
+ QMenu *file = new QMenu(this);
+ file->addAction(tr("Exit"), qApp, &QApplication::quit);
+
+ // Create a menu bar
+ QMenuBar *m = new QMenuBar(this);
+ m->addMenu(file)->setText(tr("&File"));
+
+ // Create a nice frame to put around the OpenGL widget
+ QFrame *f = new QFrame(this);
+ f->setFrameStyle(QFrame::Sunken | QFrame::Panel);
+ f->setLineWidth(2);
+
+ // Create our OpenGL widget
+ GLBox *c = new GLBox(f, "glbox");
+
+ // Create the three sliders; one for each rotation axis
+ QSlider *x = new QSlider(Qt::Vertical, this);
+ x->setMaximum(360);
+ x->setPageStep(60);
+ x->setTickPosition(QSlider::TicksLeft);
+ connect(x, &QSlider::valueChanged, c, &GLBox::setXRotation);
+
+ QSlider *y = new QSlider(Qt::Vertical, this);
+ y->setMaximum(360);
+ y->setPageStep(60);
+ y->setTickPosition(QSlider::TicksLeft);
+ connect(y, &QSlider::valueChanged, c, &GLBox::setYRotation);
+
+ QSlider *z = new QSlider(Qt::Vertical, this);
+ z->setMaximum(360);
+ z->setPageStep(60);
+ z->setTickPosition(QSlider::TicksLeft);
+ connect(z, &QSlider::valueChanged, c, &GLBox::setZRotation);
+
+ // Now that we have all the widgets, put them into a nice layout
+
+ // Top level layout, puts the sliders to the left of the frame/GL widget
+ QHBoxLayout *hlayout = new QHBoxLayout(this);
+
+ // Put the sliders on top of each other
+ QVBoxLayout *vlayout = new QVBoxLayout();
+ vlayout->addWidget(x);
+ vlayout->addWidget(y);
+ vlayout->addWidget(z);
+
+ // Put the GL widget inside the frame
+ QHBoxLayout *flayout = new QHBoxLayout(f);
+ flayout->setContentsMargins(0, 0, 0, 0);
+ flayout->addWidget(c, 1);
+
+ hlayout->setMenuBar(m);
+ hlayout->addLayout(vlayout);
+ hlayout->addWidget(f, 1);
+}
diff --git a/tests/manual/opengl/globjwin.h b/tests/manual/opengl/globjwin.h
new file mode 100644
index 0000000..58ff614
--- /dev/null
+++ b/tests/manual/opengl/globjwin.h
@@ -0,0 +1,24 @@
+// Copyright (C) 2015 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+/****************************************************************************
+**
+** The GLObjectWindow contains a GLBox and three sliders connected to
+** the GLBox's rotation slots.
+**
+****************************************************************************/
+
+#ifndef GLOBJWIN_H
+#define GLOBJWIN_H
+
+#include <qwidget.h>
+
+class GLObjectWindow : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit GLObjectWindow(QWidget *parent = nullptr);
+};
+
+#endif
diff --git a/tests/manual/opengl/main.cpp b/tests/manual/opengl/main.cpp
new file mode 100644
index 0000000..2f78324
--- /dev/null
+++ b/tests/manual/opengl/main.cpp
@@ -0,0 +1,49 @@
+// Copyright (C) 2015 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+//
+// Qt OpenGL example: Box
+//
+// A small example showing how a GLWidget can be used just as any Qt widget
+//
+// File: main.cpp
+//
+// The main() function
+//
+
+#include "globjwin.h"
+#include "glbox.h"
+#include <QApplication>
+//! [0]
+#include <QAxFactory>
+
+QAXFACTORY_BEGIN(
+ "{2c3c183a-eeda-41a4-896e-3d9c12c3577d}", // type library ID
+ "{83e16271-6480-45d5-aaf1-3f40b7661ae4}") // application ID
+ QAXCLASS(GLBox)
+QAXFACTORY_END()
+
+//! [0] //! [1]
+/*
+ The main program is here.
+*/
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc,argv);
+
+ if (QOpenGLContext::openGLModuleType() != QOpenGLContext::LibGL) {
+ qWarning("This system does not support OpenGL. Exiting.");
+ return -1;
+ }
+
+ if (!QAxFactory::isServer()) {
+ GLObjectWindow w;
+ w.resize(400, 350);
+ w.show();
+ return a.exec();
+//! [1] //! [2]
+ }
+ return a.exec();
+//! [2] //! [3]
+}
+//! [3]
diff --git a/tests/manual/opengl/opengl.def b/tests/manual/opengl/opengl.def
new file mode 100644
index 0000000..bc82a03
--- /dev/null
+++ b/tests/manual/opengl/opengl.def
@@ -0,0 +1,6 @@
+EXPORTS
+ DllCanUnloadNow PRIVATE
+ DllGetClassObject PRIVATE
+ DllRegisterServer PRIVATE
+ DllUnregisterServer PRIVATE
+ DumpIDL PRIVATE
diff --git a/tests/manual/opengl/opengl.ico b/tests/manual/opengl/opengl.ico
new file mode 100644
index 0000000..c80d36a
--- /dev/null
+++ b/tests/manual/opengl/opengl.ico
Binary files differ
diff --git a/tests/manual/opengl/opengl.inf b/tests/manual/opengl/opengl.inf
new file mode 100644
index 0000000..4a79e67
--- /dev/null
+++ b/tests/manual/opengl/opengl.inf
@@ -0,0 +1,9 @@
+[version]
+ signature="$CHICAGO$"
+ AdvancedINF=2.0
+ [Add.Code]
+ openglax.exe=openglax.exe
+ [openglax.exe]
+ file-win32-x86=thiscab
+ clsid={5fd9c22e-ed45-43fa-ba13-1530bb6b03e0}
+ RegisterServer=yes
diff --git a/tests/manual/opengl/opengl.pro b/tests/manual/opengl/opengl.pro
new file mode 100644
index 0000000..1ece9b9
--- /dev/null
+++ b/tests/manual/opengl/opengl.pro
@@ -0,0 +1,18 @@
+TEMPLATE = app
+TARGET = openglax
+
+CONFIG += warn_off
+QT += widgets axserver opengl openglwidgets
+
+HEADERS = glbox.h \
+ globjwin.h
+SOURCES = glbox.cpp \
+ globjwin.cpp \
+ main.cpp
+
+RC_FILE = opengl.rc
+DEF_FILE = opengl.def
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/activeqt/opengl
+INSTALLS += target
diff --git a/tests/manual/opengl/opengl.rc b/tests/manual/opengl/opengl.rc
new file mode 100644
index 0000000..02c0898
--- /dev/null
+++ b/tests/manual/opengl/opengl.rc
@@ -0,0 +1,2 @@
+1 TYPELIB "opengl.rc"
+1 ICON "opengl.ico"