File: mdi-main-cpp.html

package info (click to toggle)
qt-embedded 2.3.2-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 68,608 kB
  • ctags: 45,998
  • sloc: cpp: 276,654; ansic: 71,987; makefile: 29,074; sh: 12,305; yacc: 2,465; python: 1,863; perl: 481; lex: 480; xml: 68; lisp: 15
file content (506 lines) | stat: -rw-r--r-- 20,932 bytes parent folder | download
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>
Qt Toolkit - mdi/main.cpp example file
</title><style type="text/css"><!--
h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }
--></style>
</head><body bgcolor="#ffffff">

<table width="100%">
<tr><td><a href="index.html">
<img width="100" height="100" src="qtlogo.png"
alt="Home" border="0"><img width="100"
height="100" src="face.png" alt="Home" border="0">
</a><td valign=top><div align=right><img src="dochead.png" width="472" height="27"><br>
<a href="classes.html"><b>Classes</b></a>
-<a href="annotated.html">Annotated</a>
- <a href="hierarchy.html">Tree</a>
-<a href="functions.html">Functions</a>
-<a href="index.html">Home</a>
-<a href="topicals.html"><b>Structure</b></a>
</div>
</table>

<h1 align=center>A MDI Application</h1><br clear="all">

  This example program is just like the application example, but designed as
  Multiple Document Interface (MDI).

  <hr>

  Header file: <pre>/****************************************************************************
** &#36;Id&#58; qt/examples/mdi/application.h   2.3.2   edited 2001-01-26 $
**
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
**
** This file is part of an example program for Qt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/

#ifndef APPLICATION_H
#define APPLICATION_H

#include &lt;<a href="qmainwindow-h.html">qmainwindow.h</a>&gt;
#include &lt;<a href="qlist-h.html">qlist.h</a>&gt;

class QMultiLineEdit;
class QToolBar;
class QPopupMenu;
class QWorkspace;
class QPopupMenu;
class QMovie;

class MDIWindow: public QMainWindow
{
    Q_OBJECT
public:
    MDIWindow( <a href="qwidget.html">QWidget</a>* parent, const char* name, int wflags );
    ~MDIWindow();

    void load( const QString&amp; fn );
    void save();
    void saveAs();
    void print( <a href="qprinter.html">QPrinter</a>* );

signals:
    void message(const QString&amp;, int );

private:
    <a href="qmultilineedit.html">QMultiLineEdit</a>* medit;
    <a href="qmovie.html">QMovie</a> * mmovie;
    <a href="qstring.html">QString</a> filename;
};

class ApplicationWindow: public QMainWindow
{
    Q_OBJECT
public:
    ApplicationWindow();
    ~ApplicationWindow();

private slots:
    MDIWindow* newDoc();
    void load();
    void save();
    void saveAs();
    void print();
    void closeWindow();

    void about();
    void aboutQt();

    void windowsMenuAboutToShow();
    void windowsMenuActivated( int id );

private:
    <a href="qprinter.html">QPrinter</a> *printer;
    <a href="qworkspace.html">QWorkspace</a>* ws;
    <a href="qtoolbar.html">QToolBar</a> *fileTools;
    <a href="qpopupmenu.html">QPopupMenu</a>* windowsMenu;
};

#endif
</pre>


  <hr>

  Implementation: <pre>/****************************************************************************
** &#36;Id&#58; qt/examples/mdi/application.cpp   2.3.2   edited 2001-10-18 $
**
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
**
** This file is part of an example program for Qt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/

#include "application.h"
#include &lt;<a href="qworkspace-h.html">qworkspace.h</a>&gt;
#include &lt;<a href="qimage-h.html">qimage.h</a>&gt;
#include &lt;<a href="qpixmap-h.html">qpixmap.h</a>&gt;
#include &lt;<a href="qtoolbar-h.html">qtoolbar.h</a>&gt;
#include &lt;<a href="qtoolbutton-h.html">qtoolbutton.h</a>&gt;
#include &lt;<a href="qpopupmenu-h.html">qpopupmenu.h</a>&gt;
#include &lt;<a href="qmenubar-h.html">qmenubar.h</a>&gt;
#include &lt;qkeycode.h&gt;
#include &lt;<a href="qmovie-h.html">qmovie.h</a>&gt;
#include &lt;<a href="qmultilineedit-h.html">qmultilineedit.h</a>&gt;
#include &lt;<a href="qfile-h.html">qfile.h</a>&gt;
#include &lt;<a href="qfiledialog-h.html">qfiledialog.h</a>&gt;
#include &lt;<a href="qlabel-h.html">qlabel.h</a>&gt;
#include &lt;<a href="qstatusbar-h.html">qstatusbar.h</a>&gt;
#include &lt;<a href="qmessagebox-h.html">qmessagebox.h</a>&gt;
#include &lt;<a href="qprinter-h.html">qprinter.h</a>&gt;
#include &lt;<a href="qapplication-h.html">qapplication.h</a>&gt;
#include &lt;<a href="qpushbutton-h.html">qpushbutton.h</a>&gt;
#include &lt;<a href="qaccel-h.html">qaccel.h</a>&gt;
#include &lt;<a href="qtextstream-h.html">qtextstream.h</a>&gt;
#include &lt;<a href="qpainter-h.html">qpainter.h</a>&gt;
#include &lt;<a href="qpaintdevicemetrics-h.html">qpaintdevicemetrics.h</a>&gt;
#include &lt;<a href="qwhatsthis-h.html">qwhatsthis.h</a>&gt;
#include &lt;qobjectlist.h&gt;
#include &lt;<a href="qvbox-h.html">qvbox.h</a>&gt;

#include "filesave.xpm"
#include "fileopen.xpm"
#include "fileprint.xpm"

const char * fileOpenText = "Click this button to open a &lt;em&gt;new file&lt;/em&gt;. &lt;br&gt;&lt;br&gt;"
"You can also select the &lt;b&gt;Open command&lt;/b&gt; from the File menu.";
const char * fileSaveText = "Click this button to save the file you are "
"editing.  You will be prompted for a file name.\n\n"
"You can also select the Save command from the File menu.\n\n"
"Note that implementing this function is left as an exercise for the reader.";
const char * filePrintText = "Click this button to print the file you "
"are editing.\n\n"
"You can also select the Print command from the File menu.";

ApplicationWindow::ApplicationWindow()
    : <a href="qmainwindow.html">QMainWindow</a>( 0, "example application main window", WDestructiveClose )
{
    int id;

    <a href="qpixmap.html">QPixmap</a> openIcon, saveIcon;

    fileTools = new <a href="qtoolbar.html">QToolBar</a>( this, "file operations" );
    <a href="qmainwindow.html#cf504f">addToolBar</a>( fileTools, <a href="qobject.html#2418a9">tr</a>( "File Operations" ), Top, TRUE );

    openIcon = QPixmap( fileopen );
    <a href="qtoolbutton.html">QToolButton</a> * fileOpen
        = new <a href="qtoolbutton.html">QToolButton</a>( openIcon, "Open File", QString::null,
                           this, SLOT(<a href=#443>load</a>()), fileTools, "open file" );

    saveIcon = QPixmap( filesave );
    <a href="qtoolbutton.html">QToolButton</a> * fileSave
        = new <a href="qtoolbutton.html">QToolButton</a>( saveIcon, "Save File", QString::null,
                           this, SLOT(<a href=#444>save</a>()), fileTools, "save file" );

#ifndef QT_NO_PRINTER
    printer = new <a href="qprinter.html">QPrinter</a>;
    <a href="qpixmap.html">QPixmap</a> printIcon;

    printIcon = QPixmap( fileprint );
    <a href="qtoolbutton.html">QToolButton</a> * filePrint
        = new <a href="qtoolbutton.html">QToolButton</a>( printIcon, "Print File", QString::null,
                           this, SLOT(<a href=#446>print</a>()), fileTools, "print file" );
    <a href="qwhatsthis.html#dfcd18">QWhatsThis::add</a>( filePrint, filePrintText );
#endif

    (void)QWhatsThis::whatsThisButton( fileTools );

    <a href="qwhatsthis.html#dfcd18">QWhatsThis::add</a>( fileOpen, fileOpenText );
    <a href="qwhatsthis.html#dfcd18">QWhatsThis::add</a>( fileSave, fileSaveText );

    <a href="qpopupmenu.html">QPopupMenu</a> * file = new <a href="qpopupmenu.html">QPopupMenu</a>( this );
    <a href="qmainwindow.html#0eb7bc">menuBar</a>()-&gt;insertItem( "&amp;File", file );

    file-&gt;<a href="qmenudata.html#0076cb">insertItem</a>( "&amp;New", this, SLOT(<a href=#442>newDoc</a>()), CTRL+Key_N );

    id = file-&gt;<a href="qmenudata.html#0076cb">insertItem</a>( openIcon, "&amp;Open",
                           this, SLOT(<a href=#443>load</a>()), CTRL+Key_O );
    file-&gt;<a href="qmenudata.html#88eb55">setWhatsThis</a>( id, fileOpenText );

    id = file-&gt;<a href="qmenudata.html#0076cb">insertItem</a>( saveIcon, "&amp;Save",
                           this, SLOT(<a href=#444>save</a>()), CTRL+Key_S );
    file-&gt;<a href="qmenudata.html#88eb55">setWhatsThis</a>( id, fileSaveText );
    id = file-&gt;<a href="qmenudata.html#0076cb">insertItem</a>( "Save &amp;as...", this, SLOT(<a href=#445>saveAs</a>()) );
    file-&gt;<a href="qmenudata.html#88eb55">setWhatsThis</a>( id, fileSaveText );
#ifndef QT_NO_PRINTER
    file-&gt;<a href="qmenudata.html#e34b79">insertSeparator</a>();
    id = file-&gt;<a href="qmenudata.html#0076cb">insertItem</a>( printIcon, "&amp;Print",
                           this, SLOT(<a href=#446>print</a>()), CTRL+Key_P );
    file-&gt;<a href="qmenudata.html#88eb55">setWhatsThis</a>( id, filePrintText );
#endif
    file-&gt;<a href="qmenudata.html#e34b79">insertSeparator</a>();
    file-&gt;<a href="qmenudata.html#0076cb">insertItem</a>( "&amp;Close", this, SLOT(<a href=#447>closeWindow</a>()), CTRL+Key_W );
    file-&gt;<a href="qmenudata.html#0076cb">insertItem</a>( "&amp;Quit", qApp, SLOT( closeAllWindows() ), CTRL+Key_Q );

    windowsMenu = new <a href="qpopupmenu.html">QPopupMenu</a>( this );
    windowsMenu-&gt;setCheckable( TRUE );
    <a href="qobject.html#7f8e37">connect</a>( windowsMenu, SIGNAL( aboutToShow() ),
             this, SLOT( <a href=#450>windowsMenuAboutToShow</a>() ) );
    <a href="qmainwindow.html#0eb7bc">menuBar</a>()-&gt;insertItem( "&amp;Windows", windowsMenu );

    <a href="qmainwindow.html#0eb7bc">menuBar</a>()-&gt;insertSeparator();
    <a href="qpopupmenu.html">QPopupMenu</a> * help = new <a href="qpopupmenu.html">QPopupMenu</a>( this );
    <a href="qmainwindow.html#0eb7bc">menuBar</a>()-&gt;insertItem( "&amp;Help", help );

    help-&gt;<a href="qmenudata.html#0076cb">insertItem</a>( "&amp;About", this, SLOT(<a href=#448>about</a>()), Key_F1);
    help-&gt;<a href="qmenudata.html#0076cb">insertItem</a>( "About &amp;<a href="qt.html">Qt</a>", this, SLOT(<a href=#449>aboutQt</a>()));
    help-&gt;<a href="qmenudata.html#e34b79">insertSeparator</a>();
    help-&gt;<a href="qmenudata.html#0076cb">insertItem</a>( "What's &amp;This", this, SLOT(<a href="qmainwindow.html#f50ce2">whatsThis</a>()), SHIFT+Key_F1);

    <a href="qvbox.html">QVBox</a>* vb = new <a href="qvbox.html">QVBox</a>( this );
    vb-&gt;<a href="qframe.html#558f79">setFrameStyle</a>( QFrame::StyledPanel | QFrame::Sunken );
    ws = new <a href="qworkspace.html">QWorkspace</a>( vb );
    <a href="qmainwindow.html#fce9ba">setCentralWidget</a>( vb );
    <a href="qmainwindow.html#530937">statusBar</a>()-&gt;message( "Ready", 2000 );
}

ApplicationWindow::~ApplicationWindow()
{
#ifndef QT_NO_PRINTER
    delete printer;
#endif
}

MDIWindow* <a name="442"></a>ApplicationWindow::newDoc()
{
    MDIWindow* w = new MDIWindow( ws, 0, WDestructiveClose );
    <a href="qobject.html#7f8e37">connect</a>( w, SIGNAL( message(const QString&amp;, int) ), <a href="qmainwindow.html#530937">statusBar</a>(), SLOT( message(const QString&amp;, int )) );
    w-&gt;<a href="qwidget.html#d6a291">setCaption</a>("unnamed document");
    w-&gt;<a href="qwidget.html#504fc4">setIcon</a>( <a href="qpixmap.html">QPixmap</a>("document.xpm") );
    // show the very first window in maximized mode
    if ( ws-&gt;windowList().isEmpty() )
        w-&gt;<a href="qwidget.html#b6e000">showMaximized</a>();
    else
        w-&gt;<a href="qwidget.html#200ee5">show</a>();
    return w;
}

void <a name="443"></a>ApplicationWindow::load()
{
    <a href="qstring.html">QString</a> fn = QFileDialog::getOpenFileName( QString::null, QString::null, this );
    if ( !fn.<a href="qstring.html#c62623">isEmpty</a>() ) {
        MDIWindow* w = newDoc();
        w-&gt;load( fn );
    }  else {
        <a href="qmainwindow.html#530937">statusBar</a>()-&gt;message( "Loading aborted", 2000 );
    }
}

void <a name="444"></a>ApplicationWindow::save()
{
    MDIWindow* m = (MDIWindow*)ws-&gt;activeWindow();
    if ( m )
        m-&gt;save();
}

void <a name="445"></a>ApplicationWindow::saveAs()
{
    MDIWindow* m = (MDIWindow*)ws-&gt;activeWindow();
    if ( m )
        m-&gt;saveAs();
}

void <a name="446"></a>ApplicationWindow::print()
{
#ifndef QT_NO_PRINTER
    MDIWindow* m = (MDIWindow*)ws-&gt;activeWindow();
    if ( m )
        m-&gt;print( printer );
#endif
}

void <a name="447"></a>ApplicationWindow::closeWindow()
{
    MDIWindow* m = (MDIWindow*)ws-&gt;activeWindow();
    if ( m )
        m-&gt;<a href="qwidget.html#3d9c87">close</a>();
}

void <a name="448"></a>ApplicationWindow::about()
{
    <a href="qmessagebox.html#f6c3cd">QMessageBox::about</a>( this, "Qt Application Example",
                        "This example demonstrates simple use of\n "
                        "Qt's Multiple Document Interface (MDI).");
}

void <a name="449"></a>ApplicationWindow::aboutQt()
{
    <a href="qmessagebox.html#b72270">QMessageBox::aboutQt</a>( this, "Qt Application Example" );
}

void <a name="450"></a>ApplicationWindow::windowsMenuAboutToShow()
{
    windowsMenu-&gt;clear();
    int cascadeId = windowsMenu-&gt;insertItem("&amp;Cascade", ws, SLOT(cascade() ) );
    int tileId = windowsMenu-&gt;insertItem("&amp;Tile", ws, SLOT(tile() ) );
    if ( ws-&gt;windowList().isEmpty() ) {
        windowsMenu-&gt;setItemEnabled( cascadeId, FALSE );
        windowsMenu-&gt;setItemEnabled( tileId, FALSE );
    }
    windowsMenu-&gt;insertSeparator();
    QWidgetList windows = ws-&gt;windowList();
    for ( int i = 0; i &lt; int(windows.count()); ++i ) {
        int id = windowsMenu-&gt;insertItem(windows.at(i)-&gt;caption(),
                                         this, SLOT( <a href=#451>windowsMenuActivated</a>( int ) ) );
        windowsMenu-&gt;setItemParameter( id, i );
        windowsMenu-&gt;setItemChecked( id, ws-&gt;activeWindow() == windows.at(i) );
    }
}

void <a name="451"></a>ApplicationWindow::windowsMenuActivated( int id )
{
    <a href="qwidget.html">QWidget</a>* w = ws-&gt;windowList().at( id );
    if ( w ) {
        w-&gt;<a href="qwidget.html#8a8f06">showNormal</a>();
        w-&gt;<a href="qwidget.html#25775a">setFocus</a>();
    }
}

MDIWindow::MDIWindow( <a href="qwidget.html">QWidget</a>* parent, const char* name, int wflags )
    : <a href="qmainwindow.html">QMainWindow</a>( parent, name, wflags )
{
    mmovie = 0;
    medit = new <a href="qmultilineedit.html">QMultiLineEdit</a>( this );
    <a href="qwidget.html#cddadb">setFocusProxy</a>( medit );
    <a href="qmainwindow.html#fce9ba">setCentralWidget</a>( medit );
}

MDIWindow::~MDIWindow()
{
    delete mmovie;
}

void <a name="438"></a>MDIWindow::load( const QString&amp; fn )
{
    filename  = fn;
    <a href="qfile.html">QFile</a> f( filename );
    if ( !f.<a href="qfile.html#255995">open</a>( IO_ReadOnly ) )
        return;

    if(fn.<a href="qstring.html#3c8233">contains</a>(".gif")) {
        <a href="qwidget.html">QWidget</a> * tmp=new <a href="qwidget.html">QWidget</a>(this);
        <a href="qwidget.html#cddadb">setFocusProxy</a>(tmp);
        <a href="qmainwindow.html#fce9ba">setCentralWidget</a>(tmp);
        medit-&gt;hide();
        delete medit;
        <a href="qmovie.html">QMovie</a> * qm=new <a href="qmovie.html">QMovie</a>(fn);
#ifdef _WS_QWS_ // temporary speed-test hack
        qm-&gt;setDisplayWidget(tmp);
#endif
        tmp-&gt;<a href="qwidget.html#e84bbe">setBackgroundMode</a>(QWidget::NoBackground);
        tmp-&gt;<a href="qwidget.html#200ee5">show</a>();
        mmovie=qm;
    } else {
        mmovie = 0;
        medit-&gt;setAutoUpdate( FALSE );
        medit-&gt;clear();

        <a href="qtextstream.html">QTextStream</a> t(&amp;f);
        while ( !t.<a href="qtextstream.html#bb145b">eof</a>() ) {
            <a href="qstring.html">QString</a> s = t.<a href="qtextstream.html#ae4af4">readLine</a>();
            medit-&gt;append( s );
        }
        f.<a href="qfile.html#64e640">close</a>();

        medit-&gt;setAutoUpdate( TRUE );
        medit-&gt;repaint();

    }
    <a href="qwidget.html#d6a291">setCaption</a>( filename );
    emit message( <a href="qstring.html">QString</a>("Loaded document %1").arg(filename), 2000 );
}

void <a name="439"></a>MDIWindow::save()
{
    if ( filename.isEmpty() ) {
        <a href=#440>saveAs</a>();
        return;
    }

    <a href="qstring.html">QString</a> text = medit-&gt;text();
    <a href="qfile.html">QFile</a> f( filename );
    if ( !f.<a href="qfile.html#255995">open</a>( IO_WriteOnly ) ) {
        emit message( <a href="qstring.html">QString</a>("Could not write to %1").arg(filename),
                      2000 );
        return;
    }

    <a href="qtextstream.html">QTextStream</a> t( &amp;f );
    t &lt;&lt; text;
    f.<a href="qfile.html#64e640">close</a>();

    <a href="qwidget.html#d6a291">setCaption</a>( filename );

    emit message( <a href="qstring.html">QString</a>( "File %1 saved" ).arg( filename ), 2000 );
}

void <a name="440"></a>MDIWindow::saveAs()
{
    <a href="qstring.html">QString</a> fn = QFileDialog::getSaveFileName( filename, QString::null, this );
    if ( !fn.<a href="qstring.html#c62623">isEmpty</a>() ) {
        filename = fn;
        <a href=#439>save</a>();
    } else {
        emit message( "Saving aborted", 2000 );
    }
}

void <a name="441"></a>MDIWindow::print( <a href="qprinter.html">QPrinter</a>* printer)
{
#ifndef QT_NO_PRINTER
    const int Margin = 10;
    int pageNo = 1;

    if ( printer-&gt;<a href="qprinter.html#c3cd23">setup</a>(this) ) {               // printer dialog
        emit message( "Printing...", 0 );
        <a href="qpainter.html">QPainter</a> p;
        if ( !p.<a href="qpainter.html#02ed5d">begin</a>( printer ) )
            return;                             // paint on printer
        p.<a href="qpainter.html#998df2">setFont</a>( medit-&gt;font() );
        int yPos        = 0;                    // y position for each line
        <a href="qfontmetrics.html">QFontMetrics</a> fm = p.<a href="qpainter.html#73b2e5">fontMetrics</a>();
        <a href="qpaintdevicemetrics.html">QPaintDeviceMetrics</a> metrics( printer ); // need width/height
        // of printer surface
        for( int i = 0 ; i &lt; medit-&gt;numLines() ; i++ ) {
            if ( Margin + yPos &gt; metrics.<a href="qpaintdevicemetrics.html#d4fedb">height</a>() - Margin ) {
                <a href="qstring.html">QString</a> msg( "Printing (page " );
                msg += QString::number( ++pageNo );
                msg += ")...";
                emit message( msg, 0 );
                printer-&gt;<a href="qprinter.html#d4f693">newPage</a>();             // no more room on this page
                yPos = 0;                       // back to top of page
            }
            p.<a href="qpainter.html#0f088f">drawText</a>( Margin, Margin + yPos,
                        metrics.<a href="qpaintdevicemetrics.html#95eb7b">width</a>(), fm.<a href="qfontmetrics.html#e6e380">lineSpacing</a>(),
                        ExpandTabs | DontClip,
                        medit-&gt;textLine( i ) );
            yPos = yPos + fm.<a href="qfontmetrics.html#e6e380">lineSpacing</a>();
        }
        p.<a href="qpainter.html#365784">end</a>();                                // send job to printer
        emit message( "Printing completed", 2000 );
    } else {
        emit message( "Printing aborted", 2000 );
    }
#endif
}
</pre>


  <hr>

  Main:
<pre>/****************************************************************************
** &#36;Id&#58; qt/examples/mdi/main.cpp   2.3.2   edited 2001-06-12 $
**
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
**
** This file is part of an example program for Qt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/

#include &lt;<a name="qapplication.h"></a><a href="qapplication-h.html">qapplication.h</a>&gt;
#include "application.h"

int main( int argc, char ** argv ) {
    <a name="QApplication"></a><a href="qapplication.html">QApplication</a> a( argc, argv );
    ApplicationWindow * mw = new ApplicationWindow();
    mw-&gt;<a name="setCaption"></a><a href="qwidget.html#d6a291">setCaption</a>( "Qt Example - Multiple Documents Interface (MDI)" );
    mw-&gt;<a name="show"></a><a href="qmainwindow.html#eb53e3">show</a>();
    a.<a name="connect"></a><a href="qobject.html#7f8e37">connect</a>( &amp;a, SIGNAL(lastWindowClosed()), &amp;a, SLOT(quit()) );
    int res = a.<a name="exec"></a><a href="qapplication.html#84c7bf">exec</a>();
    return res;
}
</pre>
<p><address><hr><div align="center">
<table width="100%" cellspacing="0" border="0"><tr>
<td>Copyright  2001 Trolltech<td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align="right"><div align="right">Qt version 2.3.2</div>
</table></div></address></body></html>