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

« back to all changes in this revision

Viewing changes to doc/html/painting-svgviewer-mainwindow-cpp.html

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2006-10-12 23:14:14 UTC
  • mto: (15.1.1 lenny) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20061012231414-y2oqbom5dy389os0
Tags: upstream-4.2.0
ImportĀ upstreamĀ versionĀ 4.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
4
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
5
<head>
6
 
    <title>Qt 4.1: mainwindow.cpp Example File (painting/svgviewer/mainwindow.cpp)</title>
7
 
    <style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
8
 
a:link { color: #004faf; text-decoration: none }
9
 
a:visited { color: #672967; text-decoration: none }
10
 
td.postheader { font-family: sans-serif }
11
 
tr.address { font-family: sans-serif }
12
 
body { background: #ffffff; color: black; }</style>
 
6
  <title>Qt 4.2: mainwindow.cpp Example File (painting/svgviewer/mainwindow.cpp)</title>
 
7
  <link href="classic.css" rel="stylesheet" type="text/css" />
13
8
</head>
14
9
<body>
15
10
<table border="0" cellpadding="0" cellspacing="0" width="100%">
16
11
<tr>
17
 
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
 
12
<td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td>
18
13
<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="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
19
 
<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">mainwindow.cpp Example File<br /><sup><sup>painting/svgviewer/mainwindow.cpp</sup></sup></h1>
20
 
<pre>&nbsp;   /****************************************************************************
21
 
    **
22
 
    ** Copyright (C) 2005-2006 Trolltech ASA. All rights reserved.
23
 
    **
24
 
    ** This file is part of the documentation of the Qt Toolkit.
25
 
    **
26
 
    ** This file may be used under the terms of the GNU General Public
27
 
    ** License version 2.0 as published by the Free Software Foundation
28
 
    ** and appearing in the file LICENSE.GPL included in the packaging of
29
 
    ** this file.  Please review the following information to ensure GNU
30
 
    ** General Public Licensing requirements will be met:
31
 
    ** http://www.trolltech.com/products/qt/opensource.html
32
 
    **
33
 
    ** If you are unsure which license is appropriate for your use, please
34
 
    ** review the following information:
35
 
    ** http://www.trolltech.com/products/qt/licensing.html or contact the
36
 
    ** sales department at sales@trolltech.com.
37
 
    **
38
 
    ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
39
 
    ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
40
 
    **
41
 
    ****************************************************************************/
42
 
 
43
 
    #include &lt;QtGui&gt;
44
 
 
45
 
    #include &quot;mainwindow.h&quot;
46
 
 
47
 
    MainWindow::MainWindow()
48
 
        : QMainWindow()
49
 
    {
50
 
        area = new SvgWindow;
51
 
 
52
 
        QMenu *fileMenu = new QMenu(tr(&quot;&amp;File&quot;), this);
53
 
        QAction *openAction = fileMenu-&gt;addAction(tr(&quot;&amp;Open...&quot;));
54
 
        openAction-&gt;setShortcut(QKeySequence(tr(&quot;Ctrl+O&quot;)));
55
 
        QAction *quitAction = fileMenu-&gt;addAction(tr(&quot;E&amp;xit&quot;));
56
 
        quitAction-&gt;setShortcut(QKeySequence(tr(&quot;Ctrl+Q&quot;)));
57
 
 
58
 
        menuBar()-&gt;addMenu(fileMenu);
59
 
 
60
 
        QMenu *rendererMenu = new QMenu(tr(&quot;&amp;Renderer&quot;), this);
61
 
        nativeAction = rendererMenu-&gt;addAction(tr(&quot;&amp;Native&quot;));
62
 
        nativeAction-&gt;setCheckable(true);
63
 
        nativeAction-&gt;setChecked(true);
64
 
        #ifndef QT_NO_OPENGL
65
 
        glAction = rendererMenu-&gt;addAction(tr(&quot;&amp;OpenGL&quot;));
66
 
        glAction-&gt;setCheckable(true);
67
 
        #endif
68
 
        imageAction = rendererMenu-&gt;addAction(tr(&quot;&amp;Image&quot;));
69
 
        imageAction-&gt;setCheckable(true);
70
 
 
71
 
        QActionGroup *rendererGroup = new QActionGroup(this);
72
 
        rendererGroup-&gt;addAction(nativeAction);
73
 
        #ifndef QT_NO_OPENGL
74
 
        rendererGroup-&gt;addAction(glAction);
75
 
        #endif
76
 
        rendererGroup-&gt;addAction(imageAction);
77
 
 
78
 
        menuBar()-&gt;addMenu(rendererMenu);
79
 
 
80
 
        connect(openAction, SIGNAL(triggered()), this, SLOT(openFile()));
81
 
        connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
82
 
        connect(rendererGroup, SIGNAL(triggered(QAction *)),
83
 
                this, SLOT(setRenderer(QAction *)));
84
 
 
85
 
        setCentralWidget(area);
86
 
        setWindowTitle(tr(&quot;SVG Viewer&quot;));
87
 
    }
88
 
 
89
 
    void MainWindow::openFile(const QString &amp;path)
90
 
    {
91
 
        QString fileName;
92
 
        if (path.isNull())
93
 
            fileName = QFileDialog::getOpenFileName(this, tr(&quot;Open SVG File&quot;),
94
 
                                                    currentPath, &quot;*.svg&quot;);
95
 
        else
96
 
            fileName = path;
97
 
 
98
 
        if (!fileName.isEmpty()) {
99
 
            area-&gt;openFile(fileName);
100
 
            if (!fileName.startsWith(&quot;:/&quot;)) {
101
 
                currentPath = fileName;
102
 
                setWindowTitle(tr(&quot;%1 - SVGViewer&quot;).arg(currentPath));
103
 
            }
104
 
        }
105
 
    }
106
 
 
107
 
    void MainWindow::setRenderer(QAction *action)
108
 
    {
109
 
        if (action == nativeAction)
110
 
            area-&gt;setRenderer(SvgWindow::Native);
111
 
        #ifndef QT_NO_OPENGL
112
 
        else if (action == glAction)
113
 
            area-&gt;setRenderer(SvgWindow::OpenGL);
114
 
        #endif
115
 
        else if (action == imageAction)
116
 
            area-&gt;setRenderer(SvgWindow::Image);
117
 
    }</pre>
 
14
<td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">mainwindow.cpp Example File<br /><sup><sup>painting/svgviewer/mainwindow.cpp</sup></sup></h1>
 
15
<pre> /****************************************************************************
 
16
 **
 
17
 ** Copyright (C) 2005-2006 Trolltech ASA. All rights reserved.
 
18
 **
 
19
 ** This file is part of the example classes of the Qt Toolkit.
 
20
 **
 
21
 ** This file may be used under the terms of the GNU General Public
 
22
 ** License version 2.0 as published by the Free Software Foundation
 
23
 ** and appearing in the file LICENSE.GPL included in the packaging of
 
24
 ** this file.  Please review the following information to ensure GNU
 
25
 ** General Public Licensing requirements will be met:
 
26
 ** http:<span class="comment">//www.trolltech.com/products/qt/opensource.html</span>
 
27
 **
 
28
 ** If you are unsure which license is appropriate for your use, please
 
29
 ** review the following information:
 
30
 ** http:<span class="comment">//www.trolltech.com/products/qt/licensing.html or contact the</span>
 
31
 ** sales department at sales@trolltech.com.
 
32
 **
 
33
 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
34
 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
35
 **
 
36
 ****************************************************************************/
 
37
 
 
38
 #include &lt;QtGui&gt;
 
39
 
 
40
 #include &quot;mainwindow.h&quot;
 
41
 
 
42
 MainWindow::MainWindow()
 
43
     : QMainWindow()
 
44
 {
 
45
     area = new SvgWindow;
 
46
 
 
47
     QMenu *fileMenu = new QMenu(tr(&quot;&amp;File&quot;), this);
 
48
     QAction *openAction = fileMenu-&gt;addAction(tr(&quot;&amp;Open...&quot;));
 
49
     openAction-&gt;setShortcut(QKeySequence(tr(&quot;Ctrl+O&quot;)));
 
50
     QAction *quitAction = fileMenu-&gt;addAction(tr(&quot;E&amp;xit&quot;));
 
51
     quitAction-&gt;setShortcut(QKeySequence(tr(&quot;Ctrl+Q&quot;)));
 
52
 
 
53
     menuBar()-&gt;addMenu(fileMenu);
 
54
 
 
55
     QMenu *rendererMenu = new QMenu(tr(&quot;&amp;Renderer&quot;), this);
 
56
     nativeAction = rendererMenu-&gt;addAction(tr(&quot;&amp;Native&quot;));
 
57
     nativeAction-&gt;setCheckable(true);
 
58
     nativeAction-&gt;setChecked(true);
 
59
     #ifndef QT_NO_OPENGL
 
60
     glAction = rendererMenu-&gt;addAction(tr(&quot;&amp;OpenGL&quot;));
 
61
     glAction-&gt;setCheckable(true);
 
62
     #endif
 
63
     imageAction = rendererMenu-&gt;addAction(tr(&quot;&amp;Image&quot;));
 
64
     imageAction-&gt;setCheckable(true);
 
65
 
 
66
     QActionGroup *rendererGroup = new QActionGroup(this);
 
67
     rendererGroup-&gt;addAction(nativeAction);
 
68
     #ifndef QT_NO_OPENGL
 
69
     rendererGroup-&gt;addAction(glAction);
 
70
     #endif
 
71
     rendererGroup-&gt;addAction(imageAction);
 
72
 
 
73
     menuBar()-&gt;addMenu(rendererMenu);
 
74
 
 
75
     connect(openAction, SIGNAL(triggered()), this, SLOT(openFile()));
 
76
     connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
 
77
     connect(rendererGroup, SIGNAL(triggered(QAction *)),
 
78
             this, SLOT(setRenderer(QAction *)));
 
79
 
 
80
     setCentralWidget(area);
 
81
     setWindowTitle(tr(&quot;SVG Viewer&quot;));
 
82
 }
 
83
 
 
84
 void MainWindow::openFile(const QString &amp;path)
 
85
 {
 
86
     QString fileName;
 
87
     if (path.isNull())
 
88
         fileName = QFileDialog::getOpenFileName(this, tr(&quot;Open SVG File&quot;),
 
89
                                                 currentPath, &quot;*.svg&quot;);
 
90
     else
 
91
         fileName = path;
 
92
 
 
93
     if (!fileName.isEmpty()) {
 
94
         area-&gt;openFile(fileName);
 
95
         if (!fileName.startsWith(&quot;:/&quot;)) {
 
96
             currentPath = fileName;
 
97
             setWindowTitle(tr(&quot;%1 - SVGViewer&quot;).arg(currentPath));
 
98
         }
 
99
     }
 
100
 }
 
101
 
 
102
 void MainWindow::setRenderer(QAction *action)
 
103
 {
 
104
     if (action == nativeAction)
 
105
         area-&gt;setRenderer(SvgWindow::Native);
 
106
     #ifndef QT_NO_OPENGL
 
107
     else if (action == glAction)
 
108
         area-&gt;setRenderer(SvgWindow::OpenGL);
 
109
     #endif
 
110
     else if (action == imageAction)
 
111
         area-&gt;setRenderer(SvgWindow::Image);
 
112
 }</pre>
118
113
<p /><address><hr /><div align="center">
119
114
<table width="100%" cellspacing="0" border="0"><tr class="address">
120
115
<td width="30%">Copyright &copy; 2006 <a href="trolltech.html">Trolltech</a></td>
121
116
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
122
 
<td width="30%" align="right"><div align="right">Qt 4.1.4</div></td>
 
117
<td width="30%" align="right"><div align="right">Qt 4.2.0</div></td>
123
118
</tr></table></div></address></body>
124
119
</html>