~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/activeqt-opengl.html

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="iso-8859-1"?>
 
2
<!DOCTYPE html
 
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
 
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
5
<!-- /tmp/qt-4.0.0-espenr-1119621036935/qt-x11-opensource-desktop-4.0.0/doc/src/examples/activeqt/opengl.qdoc -->
 
6
<head>
 
7
    <title>Qt 4.0: OpenGL Example (ActiveQt)</title>
 
8
    <style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
 
9
a:link { color: #004faf; text-decoration: none }
 
10
a:visited { color: #672967; text-decoration: none }
 
11
td.postheader { font-family: sans-serif }
 
12
tr.address { font-family: sans-serif }
 
13
body { background: #ffffff; color: black; }</style>
 
14
</head>
 
15
<body>
 
16
<table border="0" cellpadding="0" cellspacing="0" width="100%">
 
17
<tr>
 
18
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
 
19
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="annotated.html"><font color="#004faf">Annotated</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
 
20
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">OpenGL Example (ActiveQt)</h1>
 
21
<p>Files:</p>
 
22
<ul>
 
23
<li><a href="activeqt-opengl-glbox-cpp.html">activeqt/opengl/glbox.cpp</a></li>
 
24
<li><a href="activeqt-opengl-glbox-h.html">activeqt/opengl/glbox.h</a></li>
 
25
<li><a href="activeqt-opengl-globjwin-cpp.html">activeqt/opengl/globjwin.cpp</a></li>
 
26
<li><a href="activeqt-opengl-globjwin-h.html">activeqt/opengl/globjwin.h</a></li>
 
27
<li><a href="activeqt-opengl-main-cpp.html">activeqt/opengl/main.cpp</a></li>
 
28
</ul>
 
29
<p>The OpenGL example demonstrates the use of the default factory and <a href="qaxfactory.html#isServer">QAxFactory::isServer</a>(), and the implementation of an additional COM interface using <a href="qaxbindable.html">QAxBindable</a> and <a href="qaxaggregated.html">QAxAggregated</a>. The server executable can run both as an ActiveX server and as a stand-alone application.</p>
 
30
<p>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.</p>
 
31
<p>The application uses the default factory as provided by the QAXFACTORY_DEFAULT macro to expose the <tt>GLBox</tt> widget as an ActiveX control.</p>
 
32
<pre>&nbsp;   #include &lt;qaxfactory.h&gt;
 
33
 
 
34
    QAXFACTORY_DEFAULT( GLBox,
 
35
                        &quot;{5fd9c22e-ed45-43fa-ba13-1530bb6b03e0}&quot;,
 
36
                        &quot;{33b051af-bb25-47cf-a390-5cfd2987d26a}&quot;,
 
37
                        &quot;{8c996c29-eafa-46ac-a6f9-901951e765b5}&quot;,
 
38
                        &quot;{2c3c183a-eeda-41a4-896e-3d9c12c3577d}&quot;,
 
39
                        &quot;{83e16271-6480-45d5-aaf1-3f40b7661ae4}&quot;
 
40
                      )</pre>
 
41
<p>The implementation of <tt>main</tt> initializes the <a href="qapplication.html">QApplication</a> object, and uses <tt>QAxFactory::isServer()</tt> to determine whether or not it is appropriate to create and show the application interface.</p>
 
42
<pre>&nbsp;   /*
 
43
      The main program is here.
 
44
    */
 
45
 
 
46
    int main( int argc, char **argv )
 
47
    {
 
48
        QApplication::setColorSpec( QApplication::CustomColor );
 
49
        QApplication a(argc,argv);
 
50
 
 
51
        if ( !QGLFormat::hasOpenGL() ) {
 
52
            qWarning( &quot;This system has no OpenGL support. Exiting.&quot; );
 
53
            return -1;
 
54
        }
 
55
 
 
56
        if ( !QAxFactory::isServer() ) {
 
57
            GLObjectWindow w;
 
58
            w.resize( 400, 350 );
 
59
            w.show();
 
60
            return a.exec();
 
61
        }
 
62
        return a.exec();
 
63
    }</pre>
 
64
<p>The <tt>GLBox</tt> class inherits from both the <a href="qglwidget.html">QGLWidget</a> class to be able to render OpenGL, and from <a href="qaxbindable.html">QAxBindable</a>.</p>
 
65
<pre>&nbsp;   #include &lt;qaxbindable.h&gt;
 
66
 
 
67
    class GLBox : public QGLWidget,
 
68
                  public QAxBindable
 
69
    {
 
70
        Q_OBJECT</pre>
 
71
<p>The class reimplements the <a href="qaxbindable.html#createAggregate">QAxBindable::createAggregate</a>() function from <a href="qaxbindable.html">QAxBindable</a> to return the pointer to a <a href="qaxaggregated.html">QAxAggregated</a> object.</p>
 
72
<pre>&nbsp;   public:
 
73
 
 
74
        GLBox( QWidget* parent, const char* name = 0 );
 
75
        ~GLBox();
 
76
 
 
77
        QAxAggregated *createAggregate();
 
78
 
 
79
    public slots:
 
80
 
 
81
        void                setXRotation( int degrees );</pre>
 
82
<p>The rest of the class declaration and the implementation of the OpenGL rendering is identical to the original &quot;box&quot; example.</p>
 
83
<p>The implementation file of the <tt>GLBox</tt> class includes the <tt>objsafe.h</tt> system header, in which the <tt>IObjectSafety</tt> COM interface is defined.</p>
 
84
<pre>&nbsp;   #include &lt;objsafe.h&gt;</pre>
 
85
<p>A class <tt>ObjectSafetyImpl</tt> is declared using multiple inheritance to subclass the <a href="qaxaggregated.html">QAxAggregated</a> class, and to implement the IObjectSafety interface.</p>
 
86
<pre>&nbsp;   class ObjectSafetyImpl : public QAxAggregated,
 
87
                             public IObjectSafety
 
88
    {
 
89
    public:</pre>
 
90
<p>The class declares a default constructor, and implements the queryInterface function to support the IObjectSafety interface.</p>
 
91
<pre>&nbsp;       ObjectSafetyImpl() {}
 
92
 
 
93
        long queryInterface( const QUuid &amp;iid, void **iface )
 
94
        {
 
95
            *iface = 0;
 
96
            if ( iid == IID_IObjectSafety )
 
97
                *iface = (IObjectSafety*)this;
 
98
            else
 
99
                return E_NOINTERFACE;
 
100
 
 
101
            AddRef();
 
102
            return S_OK;
 
103
        }</pre>
 
104
<p>Since every COM interface inherits <tt>IUnknown</tt> the <tt>QAXAGG_IUNKNOWN</tt> macro is used to provide the default implementation of the <tt>IUnknown</tt> interface. The macro is defined to delegate all calls to <tt>QueryInterface</tt>, <tt>AddRef</tt> and <tt>Release</tt> to the interface returned by the controllingUnknown() function.</p>
 
105
<pre>&nbsp;       QAXAGG_IUNKNOWN;</pre>
 
106
<p>The implementation of the <tt>IObjectSafety</tt> interface provides the caller with information about supported and enabled safety options, and returns <tt>S_OK</tt> for all calls to indicate that the ActiveX control is safe.</p>
 
107
<pre>&nbsp;       HRESULT WINAPI GetInterfaceSafetyOptions( REFIID riid, DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions )
 
108
        {
 
109
            *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACESAFE_FOR_UNTRUSTED_CALLER;
 
110
            *pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACESAFE_FOR_UNTRUSTED_CALLER;
 
111
            return S_OK;
 
112
        }
 
113
        HRESULT WINAPI SetInterfaceSafetyOptions( REFIID riid, DWORD pdwSupportedOptions, DWORD pdwEnabledOptions )
 
114
        {
 
115
            return S_OK;
 
116
        }
 
117
    };</pre>
 
118
<p>The implementation of the <tt>createAggregate()</tt> function just returns a new <tt>ObjectSafetyImpl</tt> object.</p>
 
119
<pre>&nbsp;   QAxAggregated *GLBox::createAggregate()
 
120
    {
 
121
        return new ObjectSafetyImpl();
 
122
    }</pre>
 
123
<p>To build the example you must first build the <a href="qaxserver.html#qaxserver">QAxServer</a> library. Then run <tt>qmake</tt> and your make tool in <tt>examples/activeqt/wrapper</tt>.</p>
 
124
<p>The <a href="qaxserver-demo-opengl.html">demonstration</a> requires your WebBrowser to support ActiveX controls, and scripting to be enabled.</p>
 
125
<p>In contrast to the other <a href="qaxserver.html#qaxserver">QAxServer</a> 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).</p>
 
126
<pre>&nbsp;   &lt;SCRIPT LANGUAGE=&quot;JavaScript&quot;&gt;
 
127
    function setRot( form )
 
128
    {
 
129
        GLBox.setXRotation( form.XEdit.value );
 
130
        GLBox.setYRotation( form.YEdit.value );
 
131
        GLBox.setZRotation( form.ZEdit.value );
 
132
    }
 
133
    &lt;/SCRIPT&gt;
 
134
 
 
135
    &lt;p /&gt;
 
136
    An OpenGL scene:&lt;br /&gt;
 
137
    &lt;object ID=&quot;GLBox&quot; CLASSID=&quot;CLSID:5fd9c22e-ed45-43fa-ba13-1530bb6b03e0&quot;
 
138
    CODEBASE=&quot;http://www.trolltech.com/demos/openglax.cab&quot;&gt;
 
139
    [Object not available! Did you forget to build and register the server?]
 
140
    &lt;/object&gt;&lt;br /&gt;
 
141
 
 
142
    &lt;form&gt;
 
143
    Rotate the scene:&lt;br /&gt;
 
144
    X:&lt;input type=&quot;edit&quot; ID=&quot;XEdit&quot; value=&quot;0&quot; /&gt;&lt;br /&gt;
 
145
    Y:&lt;input type=&quot;edit&quot; name=&quot;YEdit&quot; value=&quot;0&quot; /&gt;&lt;br /&gt;
 
146
    Z:&lt;input type=&quot;edit&quot; name=&quot;ZEdit&quot; value=&quot;0&quot; /&gt;&lt;br /&gt;
 
147
    &lt;input type=&quot;button&quot; value=&quot;Set&quot; onClick=&quot;setRot(this.form)&quot; /&gt;
 
148
    &lt;/form&gt;</pre>
 
149
<p /><address><hr /><div align="center">
 
150
<table width="100%" cellspacing="0" border="0"><tr class="address">
 
151
<td width="30%">Copyright &copy; 2005 <a href="trolltech.html">Trolltech</a></td>
 
152
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
153
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
 
154
</tr></table></div></address></body>
 
155
</html>