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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
<!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:776 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Using TQt Main Window Classes</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>Using TQt Main Window Classes</h1>
[ <a href="motif-walkthrough-5.html">Previous: Using Existing Dialogs with TQMotifDialog</a> ]
[ <a href="motif-walkthrough.html">Home</a> ]
[ <a href="motif-walkthrough-7.html">Next: Refactoring Existing Code</a> ]
<p> After we have replaced all the dialogs, we are ready to begin replacing
the <em>Main Window</em>. <a href="motif-walkthrough.html#4">As mentioned
above</a>, we will replace the existing <tt>XmMainWindow</tt> and
popup-menu heirarchy with <a href="application.html">TQt Main Window
Classes</a>.
<p> We will use <a href="designer-manual.html">TQt Designer</a> to design
our new main window.
<p> <h2> Implementing the <em>Main Window</em>
</h2>
<a name="1"></a><p> The description for the <em>Main Window</em> is saved as <tt>mainwindow.ui</tt>.
We add this file to the project file and regenerate the <tt>Makefile</tt>.
The <em>uic</em> utility generates the code for our <em>Main Window</em>, which
is then compiled and linked into our application.
<p> <em>TQt Designer</em> also created the <tt>mainwindow.ui.h</tt> file. We need to
add the implementation for our <em>Main Window</em> to this skeleton
implementation.
<p> We begin by adding the necessary includes for <a href="qapplication.html">TQApplication</a>
and <a href="qmotifwidget.html">TQMotifWidget</a>.
<p>
<p> <pre></pre>
<p> We need includes for the <a href="motif-extension.html#Motif">Motif</a> callback structs and the <tt>XmdPrint</tt>
widget.
<p> <pre></pre><pre></pre>
<p> We are now ready to add implementations for the slots in our <em>Main Window</em>. We have one slot per menu item. Each slot will call the
existing callback functions found in <tt>todo.cpp</tt> and <tt>actions.cpp</tt>.
<p> <center><table cellpadding="4" cellspacing="2" border="0">
<tr bgcolor="#a2c511"> <th valign="top" colspan="3" rowspan="1"> File menu
<tr bgcolor="#f0f0f0"> <td valign="top">New <td valign="top"><tt>MainWindow::fileNew()</tt> <td valign="top">calls the <tt>New()</tt> callback
<tr bgcolor="#d0d0d0"> <td valign="top">Open <td valign="top"><tt>MainWindow::fileOpen()</tt> <td valign="top">calls the <tt>Open()</tt> callback
<tr bgcolor="#f0f0f0"> <td valign="top">Save <td valign="top"><tt>MainWindow::fileSave()</tt> <td valign="top">calls the <tt>SaveIt()</tt> callback
<tr bgcolor="#d0d0d0"> <td valign="top">Save As <td valign="top"><tt>MainWindow::fileSaveAs()</tt> <td valign="top">calls the <tt>Save()</tt> callback
<tr bgcolor="#f0f0f0"> <td valign="top">Print <td valign="top"><tt>MainWindow::filePrint()</tt> <td valign="top">calls the <tt>ShowPrintDialog()</tt> callback
<tr bgcolor="#d0d0d0"> <td valign="top">Exit <td valign="top"><tt>MainWindow::fileExit()</tt> <td valign="top">calls <a href="qapplication.html#tquit">TQApplication::tquit</a>()
<tr bgcolor="#a2c511"> <th valign="top" colspan="3" rowspan="1"> Selected menu
<tr bgcolor="#f0f0f0"> <td valign="top">Properties <td valign="top"><tt>MainWindow::selProperties()</tt> <td valign="top">calls the <tt>EditPage()</tt> callback
<tr bgcolor="#d0d0d0"> <td valign="top">New <td valign="top"><tt>MainWindow::selNewPage()</tt> <td valign="top">calls the <tt>NewPage()</tt> callback
<tr bgcolor="#f0f0f0"> <td valign="top">Delete to Trash <td valign="top"><tt>MainWindow::selDeletePage()</tt> <td valign="top">calls the <tt>DeletePage()</tt> callback
</table></center>
<p> We need to add forward declarations for these callbacks before we can
use them.
<p> <pre></pre>
<p> Each of the existing callback functions takes three arguments. We pass
<em>NULL</em> to all of the arguments in this example (with a few exceptions,
see below). The existing code does not rely on any of the arguments.
Each slot implementation is a single line calling the related callback
function. The code is not very interesting and would just take up
space, so we've omitted it.
<p> There are four exceptions to the above. The <tt>Open()</tt>, <tt>Save()</tt>, <tt>EditPage()</tt> and <tt>DeletePage()</tt> callbacks accept a pointer to the
toplevel <a href="qwidget.html">TQWidget</a> as argument 2 (the <em>client_data</em> argument). For
these four functions, we pass <em>this</em> as the second argument, which is
a toplevel <tt>MainWindow</tt> derived from <a href="qmainwindow.html">TQMainWindow</a>.
<p> <h2> Replacing the <em>Main Window</em>
</h2>
<a name="2"></a><p> The next step is to use the new <em>Main Window</em> in our application.
The changes needed in <tt>todo.cpp</tt> are large due to the large amount of
code being removed.
<p> First, we add the include for our new <em>Main Window</em>.
<p>
<p> <pre></pre>
<p> We can cleanup the Motif includes, since many of them are no longer
needed.
<p> <pre></pre><pre></pre><pre></pre>
<p> The <tt>QuitAppl()</tt> and <tt>manageCB()</tt> callbacks are not needed any more,
so we remove them. We do not need the global <tt>shell</tt> variable
either. We remove it and all references to it in the <tt>New()</tt>, <tt>Save()</tt> and <tt>Open()</tt> callbacks.
<p> In <tt>main()</tt>, we make the large changes. First, we use our new <tt>MainWindow</tt> instead of <a href="qmotifwidget.html">TQMotifWidget</a> with <tt>XmMainWindow</tt>.
<p>
<p> <pre></pre>
<p> We will now use TQMotifWidget to create the <tt>XmNotebook</tt> widget.
<p> <pre></pre>
<p> We remove all of the code used to create the Motif menus. The
remaining code in <tt>main()</tt> is self-explanatory.
<p> <pre></pre>
<p> Our application is now using <a href="qmainwindow.html">TQMainWindow</a> instead of <tt>XmMainWindow</tt>.
After we build the project, the application runs and operates as
expected.
<p> [ <a href="motif-walkthrough-5.html">Previous: Using Existing Dialogs with TQMotifDialog</a> ]
[ <a href="motif-walkthrough.html">Home</a> ]
[ <a href="motif-walkthrough-7.html">Next: Refactoring Existing Code</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>
|