summaryrefslogtreecommitdiffstats
path: root/doc/html/qwerty-example.html
blob: 4c076f173e55741798621d317c570451b8b7e24f (plain)
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
507
508
<!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>Simple editor that can load encodings</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&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;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>Simple editor that can load encodings</h1>

   
<p> 
<hr>
<p> Header file:
<p> <pre>/****************************************************************************
** $Id: qt/qwerty.h   3.3.8   edited Jan 11 14:37 $
**
** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
**
** This file is part of an example program for TQt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/

#ifndef TQWERTY_H
#define TQWERTY_H

#include &lt;<a href="tqwidget-h.html">tqwidget.h</a>&gt;
#include &lt;<a href="tqmenubar-h.html">tqmenubar.h</a>&gt;
#include &lt;<a href="tqmultilineedit-h.html">tqmultilineedit.h</a>&gt;
#include &lt;<a href="tqprinter-h.html">tqprinter.h</a>&gt;

class Editor : public <a href="tqwidget.html">TQWidget</a>
{
    <a href="metaobjects.html#TQ_OBJECT">TQ_OBJECT</a>
public:
    Editor( <a href="tqwidget.html">TQWidget</a> *parent=0, const char *name="qwerty" );
   ~Editor();

    void load( const <a href="tqstring.html">TQString</a>&amp; fileName, int code=-1 );

public slots:
    void newDoc();
    void load();
    bool save();
    void print();
    void addEncoding();
    void toUpper();
    void toLower();
    void font();
protected:
    void resizeEvent( <a href="tqresizeevent.html">TQResizeEvent</a> * );
    void closeEvent( <a href="tqcloseevent.html">TQCloseEvent</a> * );

private slots:
    void saveAsEncoding( int );
    void openAsEncoding( int );
    void textChanged();

private:
    bool saveAs( const <a href="tqstring.html">TQString</a>&amp; fileName, int code=-1 );
    void rebuildCodecList();
    <a href="tqmenubar.html">TQMenuBar</a>       *m;
    <a href="tqmultilineedit.html">TQMultiLineEdit</a> *e;
#ifndef TQT_NO_PRINTER
    <a href="tqprinter.html">TQPrinter</a>        printer;
#endif
    <a href="tqpopupmenu.html">TQPopupMenu</a>     *save_as;
    <a href="tqpopupmenu.html">TQPopupMenu</a>     *open_as;
    bool changed;
};

#endif // TQWERTY_H
</pre>

<p> <hr>
<p> Implementation:
<p> <pre>/****************************************************************************
** $Id: qt/qwerty.cpp   3.3.8   edited Jan 11 14:37 $
**
** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
**
** This file is part of an example program for TQt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/

#include "qwerty.h"
#include &lt;<a href="qapplication-h.html">ntqapplication.h</a>&gt;
#include &lt;<a href="tqfile-h.html">tqfile.h</a>&gt;
#include &lt;<a href="tqfiledialog-h.html">tqfiledialog.h</a>&gt;
#include &lt;<a href="tqpopupmenu-h.html">tqpopupmenu.h</a>&gt;
#include &lt;<a href="tqtextstream-h.html">tqtextstream.h</a>&gt;
#include &lt;<a href="tqpainter-h.html">tqpainter.h</a>&gt;
#include &lt;<a href="tqmessagebox-h.html">tqmessagebox.h</a>&gt;
#include &lt;<a href="tqpaintdevicemetrics-h.html">tqpaintdevicemetrics.h</a>&gt;
#include &lt;<a href="tqptrlist-h.html">tqptrlist.h</a>&gt;
#include &lt;<a href="tqfontdialog-h.html">tqfontdialog.h</a>&gt;

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

const bool no_writing = FALSE;

static TQPtrList&lt;TQTextCodec&gt; *codecList = 0;

enum { Uni = 0, MBug = 1, Lat1 = 2, Local = 3, Guess = 4, Codec = 5 };


<a name="f235"></a>Editor::Editor( <a href="tqwidget.html">TQWidget</a> * parent , const char * name )
    : <a href="tqwidget.html">TQWidget</a>( parent, name, WDestructiveClose )
{
    m = new <a href="tqmenubar.html">TQMenuBar</a>( this, "menu" );

    <a href="tqpopupmenu.html">TQPopupMenu</a> * file = new <a href="tqpopupmenu.html">TQPopupMenu</a>();
    <a href="ntqapplication.html#TQ_CHECK_PTR">TQ_CHECK_PTR</a>( file );
<a name="x371"></a>    m-&gt;<a href="tqmenudata.html#insertItem">insertItem</a>( "&amp;File", file );

    file-&gt;<a href="tqmenudata.html#insertItem">insertItem</a>( "&amp;New",   this, TQ_SLOT(newDoc()),   ALT+Key_N );
    file-&gt;<a href="tqmenudata.html#insertItem">insertItem</a>( "&amp;Open...",  this, TQ_SLOT(load()),     ALT+Key_O );
    file-&gt;<a href="tqmenudata.html#insertItem">insertItem</a>( "&amp;Save...",  this, TQ_SLOT(save()),     ALT+Key_S );
<a name="x372"></a>    file-&gt;<a href="tqmenudata.html#insertSeparator">insertSeparator</a>();
    open_as = new <a href="tqpopupmenu.html">TQPopupMenu</a>();
    file-&gt;<a href="tqmenudata.html#insertItem">insertItem</a>( "Open &amp;As",  open_as );
    save_as = new <a href="tqpopupmenu.html">TQPopupMenu</a>();
    file-&gt;<a href="tqmenudata.html#insertItem">insertItem</a>( "Sa&amp;ve As",  save_as );
    file-&gt;<a href="tqmenudata.html#insertItem">insertItem</a>( "Add &amp;Encoding", this, TQ_SLOT(addEncoding()) );
#ifndef TQT_NO_PRINTER
    file-&gt;<a href="tqmenudata.html#insertSeparator">insertSeparator</a>();
    file-&gt;<a href="tqmenudata.html#insertItem">insertItem</a>( "&amp;Print...", this, TQ_SLOT(print()),    ALT+Key_P );
#endif
    file-&gt;<a href="tqmenudata.html#insertSeparator">insertSeparator</a>();
    file-&gt;<a href="tqmenudata.html#insertItem">insertItem</a>( "&amp;Close", this, TQ_SLOT(<a href="tqwidget.html#close">close</a>()),ALT+Key_W );
<a name="x358"></a>    file-&gt;<a href="tqmenudata.html#insertItem">insertItem</a>( "&amp;Quit",  tqApp, TQ_SLOT(<a href="ntqapplication.html#closeAllWindows">closeAllWindows</a>()),     ALT+Key_Q );

<a name="x386"></a>    <a href="tqobject.html#connect">connect</a>( save_as, TQ_SIGNAL(<a href="tqpopupmenu.html#activated">activated</a>(int)), this, TQ_SLOT(saveAsEncoding(int)) );
    <a href="tqobject.html#connect">connect</a>( open_as, TQ_SIGNAL(<a href="tqpopupmenu.html#activated">activated</a>(int)), this, TQ_SLOT(openAsEncoding(int)) );
    rebuildCodecList();

    <a href="tqpopupmenu.html">TQPopupMenu</a> * edit = new <a href="tqpopupmenu.html">TQPopupMenu</a>();
    <a href="ntqapplication.html#TQ_CHECK_PTR">TQ_CHECK_PTR</a>( edit );
    m-&gt;<a href="tqmenudata.html#insertItem">insertItem</a>( "&amp;Edit", edit );

    edit-&gt;<a href="tqmenudata.html#insertItem">insertItem</a>( "To &amp;Uppercase",   this, TQ_SLOT(toUpper()),   ALT+Key_U );
    edit-&gt;<a href="tqmenudata.html#insertItem">insertItem</a>( "To &amp;Lowercase",   this, TQ_SLOT(toLower()),   ALT+Key_L );
#ifndef TQT_NO_FONTDIALOG
    edit-&gt;<a href="tqmenudata.html#insertSeparator">insertSeparator</a>();
    edit-&gt;<a href="tqmenudata.html#insertItem">insertItem</a>( "&amp;Select Font" ,   this, TQ_SLOT(<a href="tqwidget.html#font">font</a>()),     ALT+Key_T );
#endif
    changed = FALSE;
    e = new <a href="tqmultilineedit.html">TQMultiLineEdit</a>( this, "editor" );
<a name="x400"></a>    <a href="tqobject.html#connect">connect</a>( e, TQ_SIGNAL( <a href="tqtextedit.html#textChanged">textChanged</a>() ), this, TQ_SLOT( textChanged() ) );

    // We use Unifont - if you have it installed you'll see all
    // Unicode character glyphs.
    //
    // Unifont only comes in one pixel size, so we cannot let
    // it change pixel size as the display DPI changes.
    //
<a name="x367"></a>    <a href="tqfont.html">TQFont</a> unifont("unifont",16,50); unifont.<a href="tqfont.html#setPixelSize">setPixelSize</a>(16);
<a name="x397"></a>    e-&gt;<a href="tqwidget.html#setFont">setFont</a>( unifont );

    e-&gt;<a href="tqwidget.html#setFocus">setFocus</a>();
}

Editor::~Editor()
{
}

<a name="x405"></a>void Editor::<a href="tqwidget.html#font">font</a>()
{
#ifndef TQT_NO_FONTDIALOG
    bool ok;
<a name="x396"></a><a name="x368"></a>    <a href="tqfont.html">TQFont</a> f = TQFontDialog::<a href="tqfontdialog.html#getFont">getFont</a>( &amp;ok, e-&gt;<a href="tqtextedit.html#font">font</a>() );
    if ( ok ) {
        e-&gt;<a href="tqwidget.html#setFont">setFont</a>( f );
    }
#endif
}



void <a name="f236"></a>Editor::rebuildCodecList()
{
    delete codecList;
    codecList = new <a href="tqptrlist.html">TQPtrList</a>&lt;TQTextCodec&gt;;
    <a href="tqtextcodec.html">TQTextCodec</a> *codec;
    int i;
<a name="x392"></a>    for (i = 0; (codec = TQTextCodec::<a href="tqtextcodec.html#codecForIndex">codecForIndex</a>(i)); i++)
<a name="x387"></a>        codecList-&gt;<a href="tqptrlist.html#append">append</a>( codec );
<a name="x389"></a>    int n = codecList-&gt;<a href="tqptrlist.html#count">count</a>();
    for (int pm=0; pm&lt;2; pm++) {
        <a href="tqpopupmenu.html">TQPopupMenu</a>* menu = pm ? open_as : save_as;
<a name="x370"></a>        menu-&gt;<a href="tqmenudata.html#clear">clear</a>();
        <a href="tqstring.html">TQString</a> local = "Local (";
<a name="x393"></a>        local += TQTextCodec::<a href="tqtextcodec.html#codecForLocale">codecForLocale</a>()-&gt;name();
        local += ")";
        menu-&gt;<a href="tqmenudata.html#insertItem">insertItem</a>( local, Local );
        menu-&gt;<a href="tqmenudata.html#insertItem">insertItem</a>( "Unicode", Uni );
        menu-&gt;<a href="tqmenudata.html#insertItem">insertItem</a>( "Latin1", Lat1 );
        menu-&gt;<a href="tqmenudata.html#insertItem">insertItem</a>( "Microsoft Unicode", MBug );
        if ( pm )
            menu-&gt;<a href="tqmenudata.html#insertItem">insertItem</a>( "[guess]", Guess );
        for ( i = 0; i &lt; n; i++ )
<a name="x388"></a>            menu-&gt;<a href="tqmenudata.html#insertItem">insertItem</a>( codecList-&gt;<a href="tqptrlist.html#at">at</a>(i)-&gt;name(), Codec + i );
    }
}

void <a name="f237"></a>Editor::newDoc()
{
    Editor *ed = new Editor;
    if ( tqApp-&gt;<a href="ntqapplication.html#desktop">desktop</a>()-&gt;size().width() &lt; 450
         || tqApp-&gt;<a href="ntqapplication.html#desktop">desktop</a>()-&gt;size().height() &lt; 450 ) {
<a name="x413"></a>        ed-&gt;<a href="tqwidget.html#showMaximized">showMaximized</a>();
    } else {
        ed-&gt;<a href="tqwidget.html#resize">resize</a>( 400, 400 );
        ed-&gt;<a href="tqwidget.html#show">show</a>();
    }
}


void <a name="f238"></a>Editor::load()
{
#ifndef TQT_NO_FILEDIALOG
<a name="x365"></a>    <a href="tqstring.html">TQString</a> fn = TQFileDialog::<a href="tqfiledialog.html#getOpenFileName">getOpenFileName</a>( <a href="tqstring.html#TQString-null">TQString::null</a>, TQString::null, this );
<a name="x390"></a>    if ( !fn.<a href="tqstring.html#isEmpty">isEmpty</a>() )
        load( fn, -1 );
#endif
}

void Editor::load( const <a href="tqstring.html">TQString</a>&amp; fileName, int code )
{
    <a href="tqfile.html">TQFile</a> f( fileName );
<a name="x363"></a>    if ( !f.<a href="tqfile.html#open">open</a>( <a href="tqfile.html#open">IO_ReadOnly</a> ) )
        return;

<a name="x376"></a>    e-&gt;<a href="tqmultilineedit.html#setAutoUpdate">setAutoUpdate</a>( FALSE );

    <a href="tqtextstream.html">TQTextStream</a> t(&amp;f);
    if ( code &gt;= Codec )
<a name="x402"></a>        t.<a href="tqtextstream.html#setCodec">setCodec</a>( codecList-&gt;<a href="tqptrlist.html#at">at</a>(code-Codec) );
    else if ( code == Uni )
<a name="x403"></a>        t.<a href="tqtextstream.html#setEncoding">setEncoding</a>( TQTextStream::Unicode );
    else if ( code == MBug )
        t.<a href="tqtextstream.html#setEncoding">setEncoding</a>( TQTextStream::UnicodeReverse );
    else if ( code == Lat1 )
        t.<a href="tqtextstream.html#setEncoding">setEncoding</a>( TQTextStream::Latin1 );
    else if ( code == Guess ) {
        <a href="tqfile.html">TQFile</a> f(fileName);
        f.<a href="tqfile.html#open">open</a>(IO_ReadOnly);
        char buffer[256];
        int l = 256;
<a name="x364"></a>        l=f.<a href="tqiodevice.html#readBlock">readBlock</a>(buffer,l);
<a name="x391"></a>        <a href="tqtextcodec.html">TQTextCodec</a>* codec = TQTextCodec::<a href="tqtextcodec.html#codecForContent">codecForContent</a>(buffer, l);
        if ( codec ) {
<a name="x395"></a><a name="x373"></a>            TQMessageBox::<a href="tqmessagebox.html#information">information</a>(this,"Encoding",TQString("Codec: ")+codec-&gt;<a href="tqtextcodec.html#name">name</a>());
            t.<a href="tqtextstream.html#setCodec">setCodec</a>( codec );
        }
    }
<a name="x401"></a><a name="x398"></a>    e-&gt;<a href="tqtextedit.html#setText">setText</a>( t.<a href="tqtextstream.html#read">read</a>() );
<a name="x362"></a>    f.<a href="tqfile.html#close">close</a>();

    e-&gt;<a href="tqmultilineedit.html#setAutoUpdate">setAutoUpdate</a>( TRUE );
<a name="x407"></a>    e-&gt;<a href="tqwidget.html#repaint">repaint</a>();
    <a href="tqwidget.html#setCaption">setCaption</a>( fileName );

    changed = FALSE;
}

void <a name="f239"></a>Editor::openAsEncoding( int code )
{
#ifndef TQT_NO_FILEDIALOG
    //storing filename (proper save) is left as an exercise...
    <a href="tqstring.html">TQString</a> fn = TQFileDialog::<a href="tqfiledialog.html#getOpenFileName">getOpenFileName</a>( TQString::null, TQString::null, this );
    if ( !fn.<a href="tqstring.html#isEmpty">isEmpty</a>() )
        (void) load( fn, code );
#endif
}

bool <a name="f240"></a>Editor::save()
{
#ifndef TQT_NO_FILEDIALOG
    //storing filename (proper save) is left as an exercise...
<a name="x366"></a>    <a href="tqstring.html">TQString</a> fn = TQFileDialog::<a href="tqfiledialog.html#getSaveFileName">getSaveFileName</a>( TQString::null, TQString::null, this );
    if ( !fn.<a href="tqstring.html#isEmpty">isEmpty</a>() )
        return saveAs( fn );
    return FALSE;
#endif
}

void <a name="f241"></a>Editor::saveAsEncoding( int code )
{
#ifndef TQT_NO_FILEDIALOG
    //storing filename (proper save) is left as an exercise...
    <a href="tqstring.html">TQString</a> fn = TQFileDialog::<a href="tqfiledialog.html#getSaveFileName">getSaveFileName</a>( TQString::null, TQString::null, this );
    if ( !fn.<a href="tqstring.html#isEmpty">isEmpty</a>() )
        (void) saveAs( fn, code );
#endif
}

void <a name="f242"></a>Editor::addEncoding()
{
#ifndef TQT_NO_FILEDIALOG
    <a href="tqstring.html">TQString</a> fn = TQFileDialog::<a href="tqfiledialog.html#getOpenFileName">getOpenFileName</a>( TQString::null, "*.map", this );
    if ( !fn.<a href="tqstring.html#isEmpty">isEmpty</a>() ) {
        <a href="tqfile.html">TQFile</a> f(fn);
        if (f.<a href="tqfile.html#open">open</a>(IO_ReadOnly)) {
<a name="x394"></a>            if (TQTextCodec::<a href="tqtextcodec.html#loadCharmap">loadCharmap</a>(&amp;f)) {
                rebuildCodecList();
            } else {
<a name="x374"></a>                TQMessageBox::<a href="tqmessagebox.html#warning">warning</a>(0,"Charmap error",
                    "The file did not contain a valid charmap.\n\n"
                    "A charmap file should look like this:\n"
                       "  &lt;code_set_name&gt; thename\n"
                       "  &lt;escape_char&gt; /\n"
                       "  % alias thealias\n"
                       "  CHARMAP\n"
                       "  &lt;tokenname&gt; /x12 &lt;U3456&gt;\n"
                       "  &lt;tokenname&gt; /xAB/x12 &lt;U0023&gt;\n"
                       "  ...\n"
                       "  END CHARMAP\n"
                );
            }
        }
    }
#endif
}


bool <a name="f243"></a>Editor::saveAs( const <a href="tqstring.html">TQString</a>&amp; fileName, int code )
{
    <a href="tqfile.html">TQFile</a> f( fileName );
    if ( no_writing || !f.<a href="tqfile.html#open">open</a>( <a href="tqfile.html#open">IO_WriteOnly</a> ) ) {
        TQMessageBox::<a href="tqmessagebox.html#warning">warning</a>(this,"I/O Error",
                    TQString("The file could not be opened.\n\n")
                        +fileName);
        return FALSE;
    }
    <a href="tqtextstream.html">TQTextStream</a> t(&amp;f);
    if ( code &gt;= Codec )
        t.<a href="tqtextstream.html#setCodec">setCodec</a>( codecList-&gt;<a href="tqptrlist.html#at">at</a>(code-Codec) );
    else if ( code == Uni )
        t.<a href="tqtextstream.html#setEncoding">setEncoding</a>( TQTextStream::Unicode );
    else if ( code == MBug )
        t.<a href="tqtextstream.html#setEncoding">setEncoding</a>( TQTextStream::UnicodeReverse );
    else if ( code == Lat1 )
        t.<a href="tqtextstream.html#setEncoding">setEncoding</a>( TQTextStream::Latin1 );
<a name="x399"></a>    t &lt;&lt; e-&gt;<a href="tqtextedit.html#text">text</a>();
    f.<a href="tqfile.html#close">close</a>();
    <a href="tqwidget.html#setCaption">setCaption</a>( fileName );
    changed = FALSE;
    return TRUE;
}

void <a name="f244"></a>Editor::print()
{
#ifndef TQT_NO_PRINTER
    if ( printer.setup(this) ) {                // opens printer dialog
        printer.setFullPage(TRUE);              // we'll set our own margins
        <a href="tqpainter.html">TQPainter</a> p;
        p.<a href="tqpainter.html#begin">begin</a>( &amp;printer );                    // paint on printer
<a name="x385"></a>        p.<a href="tqpainter.html#setFont">setFont</a>( e-&gt;<a href="tqtextedit.html#font">font</a>() );
<a name="x384"></a>        <a href="tqfontmetrics.html">TQFontMetrics</a> fm = p.<a href="tqpainter.html#fontMetrics">fontMetrics</a>();
        <a href="tqpaintdevicemetrics.html">TQPaintDeviceMetrics</a> metrics( &amp;printer ); // need width/height
                                                 // of printer surface
<a name="x379"></a>        const int MARGIN = metrics.<a href="tqpaintdevicemetrics.html#logicalDpiX">logicalDpiX</a>() / 2; // half-inch margin
        int yPos        = MARGIN;               // y position for each line

<a name="x375"></a>        for( int i = 0 ; i &lt; e-&gt;<a href="tqmultilineedit.html#numLines">numLines</a>() ; i++ ) {
            if ( printer.aborted() )
                break;
<a name="x378"></a><a name="x369"></a>            if ( yPos + fm.<a href="tqfontmetrics.html#lineSpacing">lineSpacing</a>() &gt; metrics.<a href="tqpaintdevicemetrics.html#height">height</a>() - MARGIN ) {
                // no more room on this page
                if ( !printer.newPage() )          // start new page
                    break;                           // some error
                yPos = MARGIN;                   // back to top of page
            }
<a name="x380"></a>            p.<a href="tqpainter.html#drawText">drawText</a>( MARGIN, yPos, metrics.<a href="tqpaintdevicemetrics.html#width">width</a>() - 2*MARGIN,
<a name="x377"></a>                        fm.<a href="tqfontmetrics.html#lineSpacing">lineSpacing</a>(), ExpandTabs, e-&gt;<a href="tqmultilineedit.html#textLine">textLine</a>( i ) );
            yPos += fm.<a href="tqfontmetrics.html#lineSpacing">lineSpacing</a>();
        }
        p.<a href="tqpainter.html#end">end</a>();                                // send job to printer
    }
#endif
}

void Editor::<a href="tqwidget.html#resizeEvent">resizeEvent</a>( <a href="tqresizeevent.html">TQResizeEvent</a> * )
{
    if ( e &amp;&amp; m )
        e-&gt;<a href="tqwidget.html#setGeometry">setGeometry</a>( 0, m-&gt;<a href="tqwidget.html#height">height</a>(), width(), height() - m-&gt;<a href="tqwidget.html#height">height</a>() );
}

<a name="x404"></a>void Editor::<a href="tqwidget.html#closeEvent">closeEvent</a>( <a href="tqcloseevent.html">TQCloseEvent</a> *event )
{
<a name="x360"></a>    event-&gt;<a href="tqcloseevent.html#accept">accept</a>();

    if ( changed ) { // the text has been changed
        switch ( TQMessageBox::<a href="tqmessagebox.html#warning">warning</a>( this, "Qwerty",
                                        "Save changes to Document?",
                                        <a href="tqobject.html#tr">tr</a>("&amp;Yes"),
                                        <a href="tqobject.html#tr">tr</a>("&amp;No"),
                                        <a href="tqobject.html#tr">tr</a>("Cancel"),
                                        0, 2) ) {
        case 0: // yes
            if ( save() )
                event-&gt;<a href="tqcloseevent.html#accept">accept</a>();
            else
<a name="x361"></a>                event-&gt;<a href="tqcloseevent.html#ignore">ignore</a>();
            break;
        case 1: // no
            event-&gt;<a href="tqcloseevent.html#accept">accept</a>();
            break;
        default: // cancel
            event-&gt;<a href="tqcloseevent.html#ignore">ignore</a>();
            break;
        }
    }
}

void <a name="f245"></a>Editor::toUpper()
{
    e-&gt;<a href="tqtextedit.html#setText">setText</a>(e-&gt;<a href="tqtextedit.html#text">text</a>().upper());
}

void <a name="f246"></a>Editor::toLower()
{
    e-&gt;<a href="tqtextedit.html#setText">setText</a>(e-&gt;<a href="tqtextedit.html#text">text</a>().lower());
}

void <a name="f247"></a>Editor::textChanged()
{
    changed = TRUE;
}
</pre>

<p> <hr>
<p> Main:
<p> <pre>/****************************************************************************
** $Id: qt/main.cpp   3.3.8   edited Jan 11 14:37 $
**
** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
**
** This file is part of an example program for TQt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/

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


int main( int argc, char **argv )
{
    <a href="ntqapplication.html">TQApplication</a> a( argc, argv );


<a name="x414"></a>    bool isSmall =  tqApp-&gt;<a href="ntqapplication.html#desktop">desktop</a>()-&gt;size().width() &lt; 450
                  || tqApp-&gt;<a href="ntqapplication.html#desktop">desktop</a>()-&gt;size().height() &lt; 450;

    int i;
    for ( i= argc &lt;= 1 ? 0 : 1; i&lt;argc; i++ ) {
        Editor *e = new Editor;
        e-&gt;<a href="tqwidget.html#setCaption">setCaption</a>("TQt Example - TQWERTY");
        if ( i &gt; 0 )
            e-&gt;load( argv[i] );
        if ( isSmall ) {
<a name="x422"></a>            e-&gt;<a href="tqwidget.html#showMaximized">showMaximized</a>();
        } else {
            e-&gt;<a href="tqwidget.html#resize">resize</a>( 400, 400 );
            e-&gt;<a href="tqwidget.html#show">show</a>();
        }
    }
<a name="x416"></a>    a.<a href="tqobject.html#connect">connect</a>( &amp;a, TQ_SIGNAL(<a href="ntqapplication.html#lastWindowClosed">lastWindowClosed</a>()), &amp;a, TQ_SLOT(<a href="ntqapplication.html#quit">quit</a>()) );
    return a.<a href="ntqapplication.html#exec">exec</a>();
}
</pre>

<p>See also <a href="examples.html">Examples</a>.

<!-- eof -->
<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 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>