Warning: That file was not part of the compilation database. It may have many parsing errors.

1/****************************************************************************
2**
3** Copyright (C) 2015 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the examples of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:BSD$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** BSD License Usage
18** Alternatively, you may use this file under the terms of the BSD license
19** as follows:
20**
21** "Redistribution and use in source and binary forms, with or without
22** modification, are permitted provided that the following conditions are
23** met:
24** * Redistributions of source code must retain the above copyright
25** notice, this list of conditions and the following disclaimer.
26** * Redistributions in binary form must reproduce the above copyright
27** notice, this list of conditions and the following disclaimer in
28** the documentation and/or other materials provided with the
29** distribution.
30** * Neither the name of The Qt Company Ltd nor the names of its
31** contributors may be used to endorse or promote products derived
32** from this software without specific prior written permission.
33**
34**
35** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46**
47** $QT_END_LICENSE$
48**
49****************************************************************************/
50
51/****************************************************************************
52**
53** This is a simple QGLWidget displaying an openGL wireframe box
54**
55** The OpenGL code is mostly borrowed from Brian Pauls "spin" example
56** in the Mesa distribution
57**
58****************************************************************************/
59
60#include "glbox.h"
61#include <QAxAggregated>
62#include <QUuid>
63//! [0]
64#include <objsafe.h>
65//! [0]
66
67#if defined(Q_CC_MSVC)
68#pragma warning(disable:4305) // init: truncation from const double to float
69#endif
70
71/*!
72 Create a GLBox widget
73*/
74
75GLBox::GLBox(QWidget *parent, const char *name)
76 : QGLWidget(parent)
77{
78 m_xRot = m_yRot = m_zRot = 0.0; // default object rotation
79 m_scale = 1.25; // default object scale
80 m_object = 0;
81}
82
83
84/*!
85 Release allocated resources
86*/
87
88GLBox::~GLBox()
89{
90 makeCurrent();
91
92 if (m_object)
93 glDeleteLists(m_object, 1);
94}
95
96
97/*!
98 Paint the box. The actual openGL commands for drawing the box are
99 performed here.
100*/
101
102void GLBox::paintGL()
103{
104 glClear(GL_COLOR_BUFFER_BIT);
105
106 glLoadIdentity();
107 glTranslatef(0.0, 0.0, -10.0);
108 glScalef(m_scale, m_scale, m_scale);
109
110 glRotatef(m_xRot, 1.0, 0.0, 0.0);
111 glRotatef(m_yRot, 0.0, 1.0, 0.0);
112 glRotatef(m_zRot, 0.0, 0.0, 1.0);
113
114 glCallList(m_object);
115}
116
117
118/*!
119 Set up the OpenGL rendering state, and define display list
120*/
121
122void GLBox::initializeGL()
123{
124 initializeOpenGLFunctions();
125
126 qglClearColor(Qt::black); // Let OpenGL clear to black
127 m_object = makeObject(); // Generate an OpenGL display list
128 glShadeModel(GL_FLAT);
129}
130
131
132
133/*!
134 Set up the OpenGL view port, matrix mode, etc.
135*/
136
137void GLBox::resizeGL(int w, int h)
138{
139 glViewport(0, 0, (GLint)w, (GLint)h);
140 glMatrixMode(GL_PROJECTION);
141 glLoadIdentity();
142 glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 15.0);
143 glMatrixMode(GL_MODELVIEW);
144}
145
146
147/*!
148 Generate an OpenGL display list for the object to be shown, i.e. the box
149*/
150
151GLuint GLBox::makeObject()
152{
153 GLuint list;
154
155 list = glGenLists(1);
156
157 glNewList(list, GL_COMPILE);
158
159 qglColor(Qt::white); // Shorthand for glColor3f or glIndex
160
161 glLineWidth(2.0);
162
163 glBegin(GL_LINE_LOOP);
164 glVertex3f( 1.0, 0.5, -0.4);
165 glVertex3f( 1.0, -0.5, -0.4);
166 glVertex3f(-1.0, -0.5, -0.4);
167 glVertex3f(-1.0, 0.5, -0.4);
168 glEnd();
169
170 glBegin(GL_LINE_LOOP);
171 glVertex3f( 1.0, 0.5, 0.4);
172 glVertex3f( 1.0, -0.5, 0.4);
173 glVertex3f(-1.0, -0.5, 0.4);
174 glVertex3f(-1.0, 0.5, 0.4);
175 glEnd();
176
177 glBegin(GL_LINES);
178 glVertex3f( 1.0, 0.5, -0.4); glVertex3f( 1.0, 0.5, 0.4);
179 glVertex3f( 1.0, -0.5, -0.4); glVertex3f( 1.0, -0.5, 0.4);
180 glVertex3f(-1.0, -0.5, -0.4); glVertex3f(-1.0, -0.5, 0.4);
181 glVertex3f(-1.0, 0.5, -0.4); glVertex3f(-1.0, 0.5, 0.4);
182 glEnd();
183
184 glEndList();
185
186 return list;
187}
188
189
190/*!
191 Set the rotation angle of the object to \e degrees around the X axis.
192*/
193
194void GLBox::setXRotation(int degrees)
195{
196 m_xRot = (GLfloat)(degrees % 360);
197 updateGL();
198}
199
200
201/*!
202 Set the rotation angle of the object to \e degrees around the Y axis.
203*/
204
205void GLBox::setYRotation(int degrees)
206{
207 m_yRot = (GLfloat)(degrees % 360);
208 updateGL();
209}
210
211
212/*!
213 Set the rotation angle of the object to \e degrees around the Z axis.
214*/
215
216void GLBox::setZRotation(int degrees)
217{
218 m_zRot = (GLfloat)(degrees % 360);
219 updateGL();
220}
221
222//! [1]
223class ObjectSafetyImpl : public QAxAggregated,
224 public IObjectSafety
225{
226public:
227//! [1] //! [2]
228 explicit ObjectSafetyImpl() = default;
229
230 long queryInterface(const QUuid &iid, void **iface) override
231 {
232 *iface = nullptr;
233 if (iid == IID_IObjectSafety)
234 *iface = (IObjectSafety*)this;
235 else
236 return E_NOINTERFACE;
237
238 AddRef();
239 return S_OK;
240 }
241
242//! [2] //! [3]
243 QAXAGG_IUNKNOWN;
244
245//! [3] //! [4]
246 HRESULT WINAPI GetInterfaceSafetyOptions(REFIID riid, DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions) override
247 {
248 *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACESAFE_FOR_UNTRUSTED_CALLER;
249 *pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACESAFE_FOR_UNTRUSTED_CALLER;
250 return S_OK;
251 }
252
253 HRESULT WINAPI SetInterfaceSafetyOptions(REFIID riid, DWORD pdwSupportedOptions, DWORD pdwEnabledOptions) override
254 {
255 return S_OK;
256 }
257};
258//! [4] //! [5]
259
260QAxAggregated *GLBox::createAggregate()
261{
262 return new ObjectSafetyImpl();
263}
264//! [5]
265

Warning: That file was not part of the compilation database. It may have many parsing errors.