diff options
Diffstat (limited to 'examples/activeqt/opengl')
-rw-r--r-- | examples/activeqt/opengl/glbox.cpp | 115 | ||||
-rw-r--r-- | examples/activeqt/opengl/glbox.h | 38 | ||||
-rw-r--r-- | examples/activeqt/opengl/globjwin.cpp | 69 | ||||
-rw-r--r-- | examples/activeqt/opengl/globjwin.h | 14 | ||||
-rw-r--r-- | examples/activeqt/opengl/main.cpp | 23 |
5 files changed, 153 insertions, 106 deletions
diff --git a/examples/activeqt/opengl/glbox.cpp b/examples/activeqt/opengl/glbox.cpp index 04c854c..e0796cc 100644 --- a/examples/activeqt/opengl/glbox.cpp +++ b/examples/activeqt/opengl/glbox.cpp @@ -6,7 +6,17 @@ ** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are @@ -62,12 +72,12 @@ Create a GLBox widget */ -GLBox::GLBox( QWidget* parent, const char* name ) - : QGLWidget( parent ) +GLBox::GLBox(QWidget *parent, const char *name) + : QGLWidget(parent) { - xRot = yRot = zRot = 0.0; // default object rotation - scale = 1.25; // default object scale - object = 0; + m_xRot = m_yRot = m_zRot = 0.0; // default object rotation + m_scale = 1.25; // default object scale + m_object = 0; } @@ -79,8 +89,8 @@ GLBox::~GLBox() { makeCurrent(); - if (object) - glDeleteLists( object, 1 ); + if (m_object) + glDeleteLists(m_object, 1); } @@ -91,17 +101,17 @@ GLBox::~GLBox() void GLBox::paintGL() { - glClear( GL_COLOR_BUFFER_BIT ); + glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); - glTranslatef( 0.0, 0.0, -10.0 ); - glScalef( scale, scale, scale ); + glTranslatef(0.0, 0.0, -10.0); + glScalef(m_scale, m_scale, m_scale); - glRotatef( xRot, 1.0, 0.0, 0.0 ); - glRotatef( yRot, 0.0, 1.0, 0.0 ); - glRotatef( zRot, 0.0, 0.0, 1.0 ); + glRotatef(m_xRot, 1.0, 0.0, 0.0); + glRotatef(m_yRot, 0.0, 1.0, 0.0); + glRotatef(m_zRot, 0.0, 0.0, 1.0); - glCallList( object ); + glCallList(m_object); } @@ -114,8 +124,8 @@ void GLBox::initializeGL() initializeOpenGLFunctions(); qglClearColor(Qt::black); // Let OpenGL clear to black - object = makeObject(); // Generate an OpenGL display list - glShadeModel( GL_FLAT ); + m_object = makeObject(); // Generate an OpenGL display list + glShadeModel(GL_FLAT); } @@ -124,13 +134,13 @@ void GLBox::initializeGL() Set up the OpenGL view port, matrix mode, etc. */ -void GLBox::resizeGL( int w, int h ) +void GLBox::resizeGL(int w, int h) { - glViewport( 0, 0, (GLint)w, (GLint)h ); - glMatrixMode( GL_PROJECTION ); + glViewport(0, 0, (GLint)w, (GLint)h); + glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 15.0 ); - glMatrixMode( GL_MODELVIEW ); + glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 15.0); + glMatrixMode(GL_MODELVIEW); } @@ -142,33 +152,33 @@ GLuint GLBox::makeObject() { GLuint list; - list = glGenLists( 1 ); + list = glGenLists(1); - glNewList( list, GL_COMPILE ); + glNewList(list, GL_COMPILE); qglColor(Qt::white); // Shorthand for glColor3f or glIndex - glLineWidth( 2.0 ); + glLineWidth(2.0); - glBegin( GL_LINE_LOOP ); - glVertex3f( 1.0, 0.5, -0.4 ); - glVertex3f( 1.0, -0.5, -0.4 ); - glVertex3f( -1.0, -0.5, -0.4 ); - glVertex3f( -1.0, 0.5, -0.4 ); + glBegin(GL_LINE_LOOP); + glVertex3f( 1.0, 0.5, -0.4); + glVertex3f( 1.0, -0.5, -0.4); + glVertex3f(-1.0, -0.5, -0.4); + glVertex3f(-1.0, 0.5, -0.4); glEnd(); - glBegin( GL_LINE_LOOP ); - glVertex3f( 1.0, 0.5, 0.4 ); - glVertex3f( 1.0, -0.5, 0.4 ); - glVertex3f( -1.0, -0.5, 0.4 ); - glVertex3f( -1.0, 0.5, 0.4 ); + glBegin(GL_LINE_LOOP); + glVertex3f( 1.0, 0.5, 0.4); + glVertex3f( 1.0, -0.5, 0.4); + glVertex3f(-1.0, -0.5, 0.4); + glVertex3f(-1.0, 0.5, 0.4); glEnd(); - glBegin( GL_LINES ); - glVertex3f( 1.0, 0.5, -0.4 ); glVertex3f( 1.0, 0.5, 0.4 ); - glVertex3f( 1.0, -0.5, -0.4 ); glVertex3f( 1.0, -0.5, 0.4 ); - glVertex3f( -1.0, -0.5, -0.4 ); glVertex3f( -1.0, -0.5, 0.4 ); - glVertex3f( -1.0, 0.5, -0.4 ); glVertex3f( -1.0, 0.5, 0.4 ); + glBegin(GL_LINES); + glVertex3f( 1.0, 0.5, -0.4); glVertex3f( 1.0, 0.5, 0.4); + glVertex3f( 1.0, -0.5, -0.4); glVertex3f( 1.0, -0.5, 0.4); + glVertex3f(-1.0, -0.5, -0.4); glVertex3f(-1.0, -0.5, 0.4); + glVertex3f(-1.0, 0.5, -0.4); glVertex3f(-1.0, 0.5, 0.4); glEnd(); glEndList(); @@ -181,9 +191,9 @@ GLuint GLBox::makeObject() Set the rotation angle of the object to \e degrees around the X axis. */ -void GLBox::setXRotation( int degrees ) +void GLBox::setXRotation(int degrees) { - xRot = (GLfloat)(degrees % 360); + m_xRot = (GLfloat)(degrees % 360); updateGL(); } @@ -192,9 +202,9 @@ void GLBox::setXRotation( int degrees ) Set the rotation angle of the object to \e degrees around the Y axis. */ -void GLBox::setYRotation( int degrees ) +void GLBox::setYRotation(int degrees) { - yRot = (GLfloat)(degrees % 360); + m_yRot = (GLfloat)(degrees % 360); updateGL(); } @@ -203,9 +213,9 @@ void GLBox::setYRotation( int degrees ) Set the rotation angle of the object to \e degrees around the Z axis. */ -void GLBox::setZRotation( int degrees ) +void GLBox::setZRotation(int degrees) { - zRot = (GLfloat)(degrees % 360); + m_zRot = (GLfloat)(degrees % 360); updateGL(); } @@ -215,12 +225,12 @@ class ObjectSafetyImpl : public QAxAggregated, { public: //! [1] //! [2] - ObjectSafetyImpl() {} + explicit ObjectSafetyImpl() {} - long queryInterface( const QUuid &iid, void **iface ) + long queryInterface(const QUuid &iid, void **iface) { - *iface = 0; - if ( iid == IID_IObjectSafety ) + *iface = nullptr; + if (iid == IID_IObjectSafety) *iface = (IObjectSafety*)this; else return E_NOINTERFACE; @@ -233,13 +243,14 @@ public: QAXAGG_IUNKNOWN; //! [3] //! [4] - HRESULT WINAPI GetInterfaceSafetyOptions( REFIID riid, DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions ) + HRESULT WINAPI GetInterfaceSafetyOptions(REFIID riid, DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions) { *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 ) + + HRESULT WINAPI SetInterfaceSafetyOptions(REFIID riid, DWORD pdwSupportedOptions, DWORD pdwEnabledOptions) { return S_OK; } diff --git a/examples/activeqt/opengl/glbox.h b/examples/activeqt/opengl/glbox.h index 5c09912..00be3b9 100644 --- a/examples/activeqt/opengl/glbox.h +++ b/examples/activeqt/opengl/glbox.h @@ -6,7 +6,17 @@ ** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are @@ -63,32 +73,28 @@ class GLBox : public QGLWidget, //! [0] //! [1] public: - - GLBox( QWidget* parent, const char* name = 0 ); - ~GLBox(); - + explicit GLBox(QWidget *parent, const char *name = nullptr); + virtual ~GLBox(); QAxAggregated *createAggregate(); public slots: - - void setXRotation( int degrees ); + void setXRotation(int degrees); //! [1] - void setYRotation( int degrees ); - void setZRotation( int degrees ); + void setYRotation(int degrees); + void setZRotation(int degrees); protected: - void initializeGL(); void paintGL(); - void resizeGL( int w, int h ); - + void resizeGL(int w, int h); virtual GLuint makeObject(); private: - - GLuint object; - GLfloat xRot, yRot, zRot, scale; - + GLuint m_object; + GLfloat m_xRot; + GLfloat m_yRot; + GLfloat m_zRot; + GLfloat m_scale; }; #endif // GLBOX_H diff --git a/examples/activeqt/opengl/globjwin.cpp b/examples/activeqt/opengl/globjwin.cpp index 367ede2..dbb7e82 100644 --- a/examples/activeqt/opengl/globjwin.cpp +++ b/examples/activeqt/opengl/globjwin.cpp @@ -6,7 +6,17 @@ ** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are @@ -49,62 +59,61 @@ #include <QApplication> -GLObjectWindow::GLObjectWindow(QWidget* parent) +GLObjectWindow::GLObjectWindow(QWidget *parent) : QWidget(parent) { - // Create a menu - QMenu *file = new QMenu( this ); - file->addAction( "Exit", qApp, SLOT(quit())/*, CTRL+Key_Q*/); + 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("&File"); + 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 ); + QFrame *f = new QFrame(this); + f->setFrameStyle(QFrame::Sunken | QFrame::Panel); + f->setLineWidth(2); // Create our OpenGL widget - GLBox* c = new GLBox( f, "glbox"); + GLBox *c = new GLBox(f, "glbox"); // Create the three sliders; one for each rotation axis - QSlider* x = new QSlider(Qt::Vertical, this); + QSlider *x = new QSlider(Qt::Vertical, this); x->setMaximum(360); x->setPageStep(60); - x->setTickPosition( QSlider::TicksLeft ); - QObject::connect( x, SIGNAL(valueChanged(int)),c,SLOT(setXRotation(int)) ); + x->setTickPosition(QSlider::TicksLeft); + connect(x, &QSlider::valueChanged, c, &GLBox::setXRotation); - QSlider* y = new QSlider(Qt::Vertical, this); + QSlider *y = new QSlider(Qt::Vertical, this); y->setMaximum(360); y->setPageStep(60); - y->setTickPosition( QSlider::TicksLeft ); - QObject::connect( y, SIGNAL(valueChanged(int)),c,SLOT(setYRotation(int)) ); + y->setTickPosition(QSlider::TicksLeft); + connect(y, &QSlider::valueChanged, c, &GLBox::setYRotation); - QSlider* z = new QSlider(Qt::Vertical, this); + QSlider *z = new QSlider(Qt::Vertical, this); z->setMaximum(360); z->setPageStep(60); - z->setTickPosition( QSlider::TicksLeft ); - QObject::connect( z, SIGNAL(valueChanged(int)),c,SLOT(setZRotation(int)) ); + 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); + 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 ); + 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); + QHBoxLayout *flayout = new QHBoxLayout(f); flayout->setMargin(0); - flayout->addWidget( c, 1 ); + flayout->addWidget(c, 1); - hlayout->setMenuBar( m ); - hlayout->addLayout( vlayout ); - hlayout->addWidget( f, 1 ); + hlayout->setMenuBar(m); + hlayout->addLayout(vlayout); + hlayout->addWidget(f, 1); } diff --git a/examples/activeqt/opengl/globjwin.h b/examples/activeqt/opengl/globjwin.h index cd9a8d9..500c241 100644 --- a/examples/activeqt/opengl/globjwin.h +++ b/examples/activeqt/opengl/globjwin.h @@ -6,7 +6,17 @@ ** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are @@ -55,7 +65,7 @@ class GLObjectWindow : public QWidget Q_OBJECT public: - GLObjectWindow(QWidget *parent = 0); + explicit GLObjectWindow(QWidget *parent = nullptr); }; #endif diff --git a/examples/activeqt/opengl/main.cpp b/examples/activeqt/opengl/main.cpp index 1c8a79b..4b4a4df 100644 --- a/examples/activeqt/opengl/main.cpp +++ b/examples/activeqt/opengl/main.cpp @@ -6,7 +6,17 @@ ** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are @@ -65,19 +75,20 @@ QAXFACTORY_END() The main program is here. */ -int main( int argc, char **argv ) +int main(int argc, char *argv[]) { - QApplication::setColorSpec( QApplication::CustomColor ); + QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QApplication::setColorSpec(QApplication::CustomColor); QApplication a(argc,argv); if (QOpenGLContext::openGLModuleType() != QOpenGLContext::LibGL) { - qWarning( "This system does not support OpenGL. Exiting." ); + qWarning("This system does not support OpenGL. Exiting."); return -1; } - if ( !QAxFactory::isServer() ) { + if (!QAxFactory::isServer()) { GLObjectWindow w; - w.resize( 400, 350 ); + w.resize(400, 350); w.show(); return a.exec(); //! [1] //! [2] |