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">
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" />
15
10
<table border="0" cellpadding="0" cellspacing="0" width="100%">
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"> </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="mainclasses.html"><font color="#004faf">Main Classes</font></a> · <a href="groups.html"><font color="#004faf">Grouped Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a> · <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> /****************************************************************************
22
** Copyright (C) 2005-2006 Trolltech ASA. All rights reserved.
24
** This file is part of the documentation of the Qt Toolkit.
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
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.
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.
41
****************************************************************************/
43
#include <QtGui>
45
#include "mainwindow.h"
47
MainWindow::MainWindow()
52
QMenu *fileMenu = new QMenu(tr("&File"), this);
53
QAction *openAction = fileMenu->addAction(tr("&Open..."));
54
openAction->setShortcut(QKeySequence(tr("Ctrl+O")));
55
QAction *quitAction = fileMenu->addAction(tr("E&xit"));
56
quitAction->setShortcut(QKeySequence(tr("Ctrl+Q")));
58
menuBar()->addMenu(fileMenu);
60
QMenu *rendererMenu = new QMenu(tr("&Renderer"), this);
61
nativeAction = rendererMenu->addAction(tr("&Native"));
62
nativeAction->setCheckable(true);
63
nativeAction->setChecked(true);
65
glAction = rendererMenu->addAction(tr("&OpenGL"));
66
glAction->setCheckable(true);
68
imageAction = rendererMenu->addAction(tr("&Image"));
69
imageAction->setCheckable(true);
71
QActionGroup *rendererGroup = new QActionGroup(this);
72
rendererGroup->addAction(nativeAction);
74
rendererGroup->addAction(glAction);
76
rendererGroup->addAction(imageAction);
78
menuBar()->addMenu(rendererMenu);
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 *)));
85
setCentralWidget(area);
86
setWindowTitle(tr("SVG Viewer"));
89
void MainWindow::openFile(const QString &path)
93
fileName = QFileDialog::getOpenFileName(this, tr("Open SVG File"),
94
currentPath, "*.svg");
98
if (!fileName.isEmpty()) {
99
area->openFile(fileName);
100
if (!fileName.startsWith(":/")) {
101
currentPath = fileName;
102
setWindowTitle(tr("%1 - SVGViewer").arg(currentPath));
107
void MainWindow::setRenderer(QAction *action)
109
if (action == nativeAction)
110
area->setRenderer(SvgWindow::Native);
112
else if (action == glAction)
113
area->setRenderer(SvgWindow::OpenGL);
115
else if (action == imageAction)
116
area->setRenderer(SvgWindow::Image);
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> /****************************************************************************
17
** Copyright (C) 2005-2006 Trolltech ASA. All rights reserved.
19
** This file is part of the example classes of the Qt Toolkit.
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>
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.
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.
36
****************************************************************************/
38
#include <QtGui>
40
#include "mainwindow.h"
42
MainWindow::MainWindow()
47
QMenu *fileMenu = new QMenu(tr("&File"), this);
48
QAction *openAction = fileMenu->addAction(tr("&Open..."));
49
openAction->setShortcut(QKeySequence(tr("Ctrl+O")));
50
QAction *quitAction = fileMenu->addAction(tr("E&xit"));
51
quitAction->setShortcut(QKeySequence(tr("Ctrl+Q")));
53
menuBar()->addMenu(fileMenu);
55
QMenu *rendererMenu = new QMenu(tr("&Renderer"), this);
56
nativeAction = rendererMenu->addAction(tr("&Native"));
57
nativeAction->setCheckable(true);
58
nativeAction->setChecked(true);
60
glAction = rendererMenu->addAction(tr("&OpenGL"));
61
glAction->setCheckable(true);
63
imageAction = rendererMenu->addAction(tr("&Image"));
64
imageAction->setCheckable(true);
66
QActionGroup *rendererGroup = new QActionGroup(this);
67
rendererGroup->addAction(nativeAction);
69
rendererGroup->addAction(glAction);
71
rendererGroup->addAction(imageAction);
73
menuBar()->addMenu(rendererMenu);
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 *)));
80
setCentralWidget(area);
81
setWindowTitle(tr("SVG Viewer"));
84
void MainWindow::openFile(const QString &path)
88
fileName = QFileDialog::getOpenFileName(this, tr("Open SVG File"),
89
currentPath, "*.svg");
93
if (!fileName.isEmpty()) {
94
area->openFile(fileName);
95
if (!fileName.startsWith(":/")) {
96
currentPath = fileName;
97
setWindowTitle(tr("%1 - SVGViewer").arg(currentPath));
102
void MainWindow::setRenderer(QAction *action)
104
if (action == nativeAction)
105
area->setRenderer(SvgWindow::Native);
107
else if (action == glAction)
108
area->setRenderer(SvgWindow::OpenGL);
110
else if (action == imageAction)
111
area->setRenderer(SvgWindow::Image);
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 © 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>