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