summaryrefslogtreecommitdiffstats
path: root/doc/html/qfd-example.html
blob: 8635ddb175271952391597174f8a6418ba8ae43a (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
<!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>Font Displayer</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>Font Displayer</h1>

   
<p> 
This example program displays all characters of a font.
<p> <hr>
<p> Header file:
<p> <pre>/****************************************************************************
** $Id: qt/fontdisplayer.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 FontDisplayer_H
#define FontDisplayer_H

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

class TQSlider;

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

    <a href="tqsize.html">TQSize</a> sizeHint() const;

signals:
    void fontInformation(const <a href="tqstring.html">TQString</a>&amp;);

public slots:
    void setRow(int);
    void chooseFont();


protected:
    <a href="tqsize.html">TQSize</a> cellSize() const;
    void paintEvent( <a href="tqpaintevent.html">TQPaintEvent</a>* );
private:
    <a href="tqfont.html">TQFont</a> tablefont;
    int row;
};

class FontDisplayer : public <a href="tqmainwindow.html">TQMainWindow</a> {
    TQ_OBJECT
public:
    FontDisplayer( <a href="tqwidget.html">TQWidget</a>* parent=0, const char* name=0 );
};

#endif
</pre>

<p> <hr>
<p> Implementation:
<p> <pre>/****************************************************************************
** $Id: qt/fontdisplayer.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 "fontdisplayer.h"
#include &lt;<a href="qapplication-h.html">ntqapplication.h</a>&gt;
#include &lt;<a href="tqslider-h.html">tqslider.h</a>&gt;
#include &lt;<a href="tqspinbox-h.html">tqspinbox.h</a>&gt;
#include &lt;<a href="tqpainter-h.html">tqpainter.h</a>&gt;
#include &lt;<a href="tqtoolbar-h.html">tqtoolbar.h</a>&gt;
#include &lt;<a href="tqstatusbar-h.html">tqstatusbar.h</a>&gt;
#include &lt;<a href="tqlabel-h.html">tqlabel.h</a>&gt;
#include &lt;<a href="tqpushbutton-h.html">tqpushbutton.h</a>&gt;
#include &lt;<a href="tqfontdialog-h.html">tqfontdialog.h</a>&gt;
#include &lt;stdlib.h&gt;


<a name="f531"></a>FontRowTable::FontRowTable( <a href="tqwidget.html">TQWidget</a>* parent, const char* name ) :
    <a href="tqframe.html">TQFrame</a>(parent,name)
{
    <a href="tqwidget.html#setBackgroundMode">setBackgroundMode</a>(PaletteBase);
    <a href="tqframe.html#setFrameStyle">setFrameStyle</a>(Panel|Sunken);
    <a href="tqframe.html#setMargin">setMargin</a>(8);
    setRow(0);
<a name="x1979"></a>    tablefont = TQApplication::<a href="ntqapplication.html#font">font</a>();
}

<a name="x1996"></a>TQSize FontRowTable::<a href="tqwidget.html#sizeHint">sizeHint</a>() const
{
    return 24*cellSize()+TQSize(2,2)*(<a href="tqframe.html#margin">margin</a>()+frameWidth());
}

TQSize <a name="f532"></a>FontRowTable::cellSize() const
{
    <a href="tqfontmetrics.html">TQFontMetrics</a> fm = <a href="tqwidget.html#fontMetrics">fontMetrics</a>();
<a name="x1990"></a><a name="x1989"></a>    return TQSize( fm.<a href="tqfontmetrics.html#maxWidth">maxWidth</a>(), fm.<a href="tqfontmetrics.html#lineSpacing">lineSpacing</a>()+1 );
}

<a name="x1995"></a>void FontRowTable::<a href="tqframe.html#paintEvent">paintEvent</a>( <a href="tqpaintevent.html">TQPaintEvent</a>* e )
{
    TQFrame::<a href="tqframe.html#paintEvent">paintEvent</a>(e);
    <a href="tqpainter.html">TQPainter</a> p(this);
<a name="x2002"></a><a name="x1999"></a>    p.<a href="tqpainter.html#setClipRegion">setClipRegion</a>(e-&gt;<a href="tqpaintevent.html#region">region</a>());
<a name="x2001"></a>    <a href="tqrect.html">TQRect</a> r = e-&gt;<a href="tqpaintevent.html#rect">rect</a>();
    <a href="tqfontmetrics.html">TQFontMetrics</a> fm = <a href="tqwidget.html#fontMetrics">fontMetrics</a>();
<a name="x1991"></a>    int ml = <a href="tqframe.html#frameWidth">frameWidth</a>()+margin() + 1 + TQMAX(0,-fm.<a href="tqfontmetrics.html#minLeftBearing">minLeftBearing</a>());
    int mt = <a href="tqframe.html#frameWidth">frameWidth</a>()+margin();
    <a href="tqsize.html">TQSize</a> cell((<a href="tqwidget.html#width">width</a>()-15-ml)/16,(<a href="tqwidget.html#height">height</a>()-15-mt)/16);

<a name="x2008"></a><a name="x2007"></a>    if ( !cell.<a href="tqsize.html#width">width</a>() || !cell.<a href="tqsize.html#height">height</a>() )
        return;

    int mini = r.<a href="tqrect.html#left">left</a>() / cell.<a href="tqsize.html#width">width</a>();
    int maxi = (r.<a href="tqrect.html#right">right</a>()+cell.<a href="tqsize.html#width">width</a>()-1) / cell.<a href="tqsize.html#width">width</a>();
    int minj = r.<a href="tqrect.html#top">top</a>() / cell.<a href="tqsize.html#height">height</a>();
<a name="x2003"></a>    int maxj = (r.<a href="tqrect.html#bottom">bottom</a>()+cell.<a href="tqsize.html#height">height</a>()-1) / cell.<a href="tqsize.html#height">height</a>();

<a name="x1986"></a>    int h = fm.<a href="tqfontmetrics.html#height">height</a>();

    <a href="tqcolor.html">TQColor</a> body(255,255,192);
    <a href="tqcolor.html">TQColor</a> negative(255,192,192);
    <a href="tqcolor.html">TQColor</a> positive(192,192,255);
    <a href="tqcolor.html">TQColor</a> rnegative(255,128,128);
    <a href="tqcolor.html">TQColor</a> rpositive(128,128,255);

    for (int j = minj; j&lt;=maxj; j++) {
        for (int i = mini; i&lt;=maxi; i++) {
            if ( i &lt; 16 &amp;&amp; j &lt; 16 ) {
                int x = i*cell.<a href="tqsize.html#width">width</a>();
                int y = j*cell.<a href="tqsize.html#height">height</a>();

                <a href="tqchar.html">TQChar</a> ch = TQChar(j*16+i,row);

<a name="x1987"></a>                if ( fm.<a href="tqfontmetrics.html#inFont">inFont</a>(ch) ) {
<a name="x1994"></a>                    int w = fm.<a href="tqfontmetrics.html#width">width</a>(ch);
<a name="x1988"></a>                    int l = fm.<a href="tqfontmetrics.html#leftBearing">leftBearing</a>(ch);
<a name="x1993"></a>                    int r = fm.<a href="tqfontmetrics.html#rightBearing">rightBearing</a>(ch);

                    x += ml;
                    y += mt+h;

<a name="x1998"></a>                    p.<a href="tqpainter.html#fillRect">fillRect</a>(x,y,w,-h,body);
                    if ( w ) {
                        if ( l ) {
                            p.<a href="tqpainter.html#fillRect">fillRect</a>(x+(l&gt;0?0:l), y-h/2, abs(l),-h/2,
                                       l &lt; 0 ? negative : positive);
                        }
                        if ( r ) {
                            p.<a href="tqpainter.html#fillRect">fillRect</a>(x+w-(r&gt;0?r:0),y+2, abs(r),-h/2,
                                       r &lt; 0 ? rnegative : rpositive);
                        }
                    }
                    <a href="tqstring.html">TQString</a> s;
                    s += ch;
                    p.<a href="tqpainter.html#setPen">setPen</a>(TQPen(TQt::black));
                    p.<a href="tqpainter.html#drawText">drawText</a>(x,y,s);
                }
            }
        }
    }
}

void <a name="f533"></a>FontRowTable::setRow(int r)
{
    row = r;

    <a href="tqfontmetrics.html">TQFontMetrics</a> fm = <a href="tqwidget.html#fontMetrics">fontMetrics</a>();
    <a href="tqfontinfo.html">TQFontInfo</a> fi = <a href="tqwidget.html#fontInfo">fontInfo</a>();
    <a href="tqstring.html">TQString</a> str = TQString("%1 %2pt%3%4 mLB=%5 mRB=%6 mW=%7")
<a name="x1983"></a>                    .arg(fi.<a href="tqfontinfo.html#family">family</a>())
<a name="x1985"></a>                    .arg(fi.<a href="tqfontinfo.html#pointSize">pointSize</a>())
<a name="x1982"></a>                    .arg(fi.<a href="tqfontinfo.html#bold">bold</a>() ? " bold" : "")
<a name="x1984"></a>                    .arg(fi.<a href="tqfontinfo.html#italic">italic</a>() ? " italic" : "")
                    .arg(fm.<a href="tqfontmetrics.html#minLeftBearing">minLeftBearing</a>())
<a name="x1992"></a>                    .arg(fm.<a href="tqfontmetrics.html#minRightBearing">minRightBearing</a>())
                    .arg(fm.<a href="tqfontmetrics.html#maxWidth">maxWidth</a>());

    emit fontInformation(str);
    <a href="tqwidget.html#update">update</a>();
}

void <a name="f534"></a>FontRowTable::chooseFont()
{
    bool ok;
    <a href="tqfont.html">TQFont</a> oldfont = tablefont;
<a name="x1981"></a>    tablefont = TQFontDialog::<a href="tqfontdialog.html#getFont">getFont</a>(&amp;ok, oldfont, this);

    if (ok)
        <a href="tqwidget.html#setFont">setFont</a>(tablefont);
    else
        tablefont = oldfont;
}

<a name="f530"></a>FontDisplayer::FontDisplayer( <a href="tqwidget.html">TQWidget</a>* parent, const char* name ) :
    <a href="tqmainwindow.html">TQMainWindow</a>(parent,name)
{
    FontRowTable* table = new FontRowTable(this);
    <a href="tqtoolbar.html">TQToolBar</a>* controls = new <a href="tqtoolbar.html">TQToolBar</a>(this);
    (void) new <a href="tqlabel.html">TQLabel</a>(<a href="tqobject.html#tr">tr</a>("Row:"), controls);
    <a href="tqspinbox.html">TQSpinBox</a> *row = new <a href="tqspinbox.html">TQSpinBox</a>(0,255,1,controls);
<a name="x2010"></a>    controls-&gt;<a href="tqtoolbar.html#addSeparator">addSeparator</a>();
    <a href="tqpushbutton.html">TQPushButton</a> *fontbutton = new <a href="tqpushbutton.html">TQPushButton</a>(<a href="tqobject.html#tr">tr</a>("Font..."), controls);

<a name="x2009"></a>    <a href="tqobject.html#connect">connect</a>(row,TQ_SIGNAL(<a href="tqspinbox.html#valueChanged">valueChanged</a>(int)),table,TQ_SLOT(setRow(int)));
    <a href="tqobject.html#connect">connect</a>(fontbutton, TQ_SIGNAL(<a href="tqbutton.html#clicked">clicked</a>()), table, TQ_SLOT(chooseFont()));
    <a href="tqobject.html#connect">connect</a>(table,TQ_SIGNAL(fontInformation(const <a href="tqstring.html">TQString</a>&amp;)),
            <a href="tqmainwindow.html#statusBar">statusBar</a>(),TQ_SLOT(message(const <a href="tqstring.html">TQString</a>&amp;)));
    table-&gt;setRow(0);
    <a href="tqmainwindow.html#setCentralWidget">setCentralWidget</a>(table);
}
</pre>

<p> <hr>
<p> Main:
<p> <pre>/****************************************************************************
** $Id: qt/qfd.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 "fontdisplayer.h"

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



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

    FontDisplayer m;
<a name="x2013"></a>    <a href="tqsize.html">TQSize</a> sh = m.<a href="tqmainwindow.html#centralWidget">centralWidget</a>()-&gt;sizeHint();
<a name="x2017"></a>    m.<a href="tqwidget.html#resize">resize</a>(sh.<a href="tqsize.html#width">width</a>(),
<a name="x2016"></a><a name="x2015"></a>             sh.<a href="tqsize.html#height">height</a>()+3*m.<a href="tqmainwindow.html#statusBar">statusBar</a>()-&gt;height());
    app.<a href="ntqapplication.html#setMainWidget">setMainWidget</a>(&amp;m);
    m.<a href="tqwidget.html#setCaption">setCaption</a>("TQt Example - TQFD");
<a name="x2014"></a>    m.<a href="tqwidget.html#show">show</a>();

    return app.<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>