1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/extensions/motif/doc/walkthrough.doc:1477 -->
|
---|
3 | <html>
|
---|
4 | <head>
|
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
6 | <title>Replacing the Print Dialog</title>
|
---|
7 | <style type="text/css"><!--
|
---|
8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
9 | a:link { color: #004faf; text-decoration: none }
|
---|
10 | a:visited { color: #672967; text-decoration: none }
|
---|
11 | body { background: #ffffff; color: black; }
|
---|
12 | --></style>
|
---|
13 | </head>
|
---|
14 | <body>
|
---|
15 |
|
---|
16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
17 | <tr bgcolor="#E5E5E5">
|
---|
18 | <td valign=center>
|
---|
19 | <a href="index.html">
|
---|
20 | <font color="#004faf">Home</font></a>
|
---|
21 | | <a href="classes.html">
|
---|
22 | <font color="#004faf">All Classes</font></a>
|
---|
23 | | <a href="mainclasses.html">
|
---|
24 | <font color="#004faf">Main Classes</font></a>
|
---|
25 | | <a href="annotated.html">
|
---|
26 | <font color="#004faf">Annotated</font></a>
|
---|
27 | | <a href="groups.html">
|
---|
28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
29 | | <a href="functions.html">
|
---|
30 | <font color="#004faf">Functions</font></a>
|
---|
31 | </td>
|
---|
32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Replacing the Print Dialog</h1>
|
---|
33 |
|
---|
34 |
|
---|
35 |
|
---|
36 | [ <a href="motif-walkthrough-8.html">Previous: Replacing the View Widget</a> ]
|
---|
37 | [ <a href="motif-walkthrough.html">Home</a> ]
|
---|
38 | [ <a href="motif-walkthrough-10.html">Next: Continuing Development</a> ]
|
---|
39 | <p> The <em>Print</em> dialog is the last component in our application that
|
---|
40 | uses <a href="motif-extension.html#Motif">Motif</a>. The current <tt>Print()</tt> function does nothing more than
|
---|
41 | write the plain text to a temporary file, and then executes 'lpr' to
|
---|
42 | send the text to the printer. Since we will use <a href="qprinter.html">QPrinter</a>, we do not
|
---|
43 | this function any more, so we remove it. The current <tt>MainWindow::filePrint()</tt> implementation is removed as well. We will
|
---|
44 | write a new <tt>MainWindow::filePrint()</tt> implementation in <tt>mainwindow.ui.h</tt>.
|
---|
45 | <p> Note: The steps involved in using the QPrinter class are beyond the
|
---|
46 | scope of this walkthrough and will not be discussed here. The
|
---|
47 | QPrinter Class Reference, <a href="qsimplerichtext.html">QSimpleRichText</a> Class Reference and the
|
---|
48 | <a href="simple-application.html">Simple Application Walkthrough</a>
|
---|
49 | contain information on the use of QPrinter.
|
---|
50 | <p> For completeness, the code to initialize a QPrinter object is included below.
|
---|
51 | <p>
|
---|
52 |
|
---|
53 | <pre></pre>
|
---|
54 | <p> <h2> Using Rich Text for Printing
|
---|
55 | </h2>
|
---|
56 | <a name="1"></a><p> Qt provides rich text using a subset of HTML. The QSimpleRichText
|
---|
57 | class makes rich-text printing simple. All we need to do is create a
|
---|
58 | string with the proper format tags inserted at the appropriate
|
---|
59 | places. For our example, we will keep the printing output similar to
|
---|
60 | previous versions.
|
---|
61 | <p> First, we create the format tags that we will use.
|
---|
62 | <p> <pre></pre>
|
---|
63 | <p> Next we just loop over all pages, appending the page label, contents
|
---|
64 | and formatting characters to a <tt>printtext</tt> variable (which is a
|
---|
65 | <a href="qstring.html">QString</a>).
|
---|
66 | <p> <pre></pre>
|
---|
67 | <p> The rest of the <tt>MainWindow::filePrint()</tt> function is the actual
|
---|
68 | printing code. Here we simply create a <a href="qsimplerichtext.html">QSimpleRichText</a> object using
|
---|
69 | the string we created above, and draw this string on the <a href="qprinter.html">QPrinter</a>
|
---|
70 | object using <a href="qpainter.html">QPainter</a>.
|
---|
71 | <p> <pre></pre>
|
---|
72 | <p> <h2> Removing the Dependency on Xt/Motif
|
---|
73 | </h2>
|
---|
74 | <a name="2"></a><p> Our application no longer uses any Xt or Motif widgets. We can now
|
---|
75 | finish removing the dependencies on Xt and Motif.
|
---|
76 | <p> First, we cleanup the <tt>#include</tt> statements in <tt>mainwindow.ui.h</tt>.
|
---|
77 | <p>
|
---|
78 |
|
---|
79 | <p> <pre></pre><pre></pre>
|
---|
80 | <p> The <tt>MainWindow::fileNew()</tt> function uses the <tt>Boolean</tt> and <tt>False</tt>
|
---|
81 | keywords from the Xt library. C++ has these built into the language,
|
---|
82 | so we use <tt>bool</tt> and <tt>false</tt> instead.
|
---|
83 | <p> The last modification needed to completely remove Xt and Motif from
|
---|
84 | our application is to stop using the <a href="qmotif.html">QMotif</a> class. We remove the
|
---|
85 | qmotif.h <tt>#include</tt> statement from <tt>todo.cpp</tt>, and remove the
|
---|
86 | instantiation from the <tt>main()</tt> function.
|
---|
87 | <p> After doing this, we can remove the <tt>-lXm</tt> and <tt>-lqmotif</tt> from the
|
---|
88 | <tt>LIBS</tt> variable in our project file. Our project file also contains
|
---|
89 | source and headers for the the old custom Motif widgets previously
|
---|
90 | used in our application. We remove these as well.
|
---|
91 | <p> After regenerating the <tt>Makefile</tt> and building our project, we
|
---|
92 | confirm that the application works correctly.
|
---|
93 | <p> [ <a href="motif-walkthrough-8.html">Previous: Replacing the View Widget</a> ]
|
---|
94 | [ <a href="motif-walkthrough.html">Home</a> ]
|
---|
95 | [ <a href="motif-walkthrough-10.html">Next: Continuing Development</a> ]
|
---|
96 | <p>
|
---|
97 | <!-- eof -->
|
---|
98 | <p><address><hr><div align=center>
|
---|
99 | <table width=100% cellspacing=0 border=0><tr>
|
---|
100 | <td>Copyright © 2007
|
---|
101 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
102 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
103 | </table></div></address></body>
|
---|
104 | </html>
|
---|