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
|
<!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/examples/aclock/aclock.doc:4 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Analog Clock</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>Analog Clock</h1>
<p>
This example displays an analog clock widget.
<p> <hr>
<p> Header file:
<p> <pre>/****************************************************************************
** $Id: qt/aclock.h 3.3.8 edited Jan 11 14:36 $
**
** 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 ACLOCK_H
#define ACLOCK_H
#include <<a href="tqwidget-h.html">tqwidget.h</a>>
#include <<a href="tqdatetime-h.html">tqdatetime.h</a>>
class TQTimer;
class AnalogClock : public <a href="tqwidget.html">TQWidget</a> // analog clock widget
{
<a href="metaobjects.html#TQ_OBJECT">TQ_OBJECT</a>
public:
AnalogClock( <a href="tqwidget.html">TQWidget</a> *parent=0, const char *name=0 );
void setAutoMask(bool b);
protected:
void updateMask();
void paintEvent( <a href="tqpaintevent.html">TQPaintEvent</a> *);
void mousePressEvent( <a href="qmouseevent.html">TQMouseEvent</a> *);
void mouseMoveEvent( <a href="qmouseevent.html">TQMouseEvent</a> *);
void drawClock( <a href="tqpainter.html">TQPainter</a>* );
private slots:
void timeout();
public slots:
void setTime( const <a href="tqtime.html">TQTime</a> & t );
private:
<a href="tqpoint.html">TQPoint</a> clickPos;
<a href="tqtime.html">TQTime</a> time;
<a href="tqtimer.html">TQTimer</a> *internalTimer;
};
#endif // ACLOCK_H
</pre>
<p> <hr>
<p> Implementation:
<p> <pre>/****************************************************************************
** $Id: qt/aclock.cpp 3.3.8 edited Jan 11 14:36 $
**
** 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 "aclock.h"
#include <<a href="tqtimer-h.html">tqtimer.h</a>>
#include <<a href="tqpainter-h.html">tqpainter.h</a>>
#include <<a href="tqbitmap-h.html">tqbitmap.h</a>>
//
// Constructs an analog clock widget that uses an internal TQTimer.
//
<a name="f384"></a>AnalogClock::AnalogClock( <a href="tqwidget.html">TQWidget</a> *parent, const char *name )
: <a href="tqwidget.html">TQWidget</a>( parent, name )
{
<a name="x1201"></a> time = TQTime::<a href="tqtime.html#currentTime">currentTime</a>(); // get current time
internalTimer = new <a href="tqtimer.html">TQTimer</a>( this ); // create internal timer
<a name="x1205"></a> <a href="tqobject.html#connect">connect</a>( internalTimer, TQ_SIGNAL(<a href="tqtimer.html#timeout">timeout</a>()), TQ_SLOT(timeout()) );
<a name="x1204"></a> internalTimer-><a href="tqtimer.html#start">start</a>( 5000 ); // emit signal every 5 seconds
}
void AnalogClock::<a href="tqwidget.html#mousePressEvent">mousePressEvent</a>( <a href="qmouseevent.html">TQMouseEvent</a> *e )
{
if(<a href="tqwidget.html#isTopLevel">isTopLevel</a>())
clickPos = e-><a href="qmouseevent.html#pos">pos</a>() + TQPoint(<a href="tqwidget.html#geometry">geometry</a>().topLeft() - frameGeometry().topLeft());
}
<a name="x1206"></a>void AnalogClock::<a href="tqwidget.html#mouseMoveEvent">mouseMoveEvent</a>( <a href="qmouseevent.html">TQMouseEvent</a> *e )
{
if(<a href="tqwidget.html#isTopLevel">isTopLevel</a>())
<a name="x1181"></a> <a href="tqwidget.html#move">move</a>( e-><a href="qmouseevent.html#globalPos">globalPos</a>() - clickPos );
}
//
// The TQTimer::timeout() signal is received by this slot.
//
//
// When we set an explicit time we don't want the timeout() slot to be
// called anymore as this relies on currentTime()
//
void <a name="f385"></a>AnalogClock::setTime( const <a href="tqtime.html">TQTime</a> & t )
{
time = t;
<a href="tqobject.html#disconnect">disconnect</a>( internalTimer, TQ_SIGNAL(<a href="tqtimer.html#timeout">timeout</a>()), this, TQ_SLOT(timeout()) );
if (<a href="tqwidget.html#autoMask">autoMask</a>())
<a href="tqwidget.html#updateMask">updateMask</a>();
else
<a href="tqwidget.html#update">update</a>();
}
void <a name="f386"></a>AnalogClock::timeout()
{
<a href="tqtime.html">TQTime</a> old_time = time;
time = TQTime::<a href="tqtime.html#currentTime">currentTime</a>();
<a name="x1203"></a> if ( old_time.<a href="tqtime.html#minute">minute</a>() != time.minute()
<a name="x1202"></a> || old_time.<a href="tqtime.html#hour">hour</a>() != time.hour() ) { // minute or hour has changed
if (<a href="tqwidget.html#autoMask">autoMask</a>())
<a href="tqwidget.html#updateMask">updateMask</a>();
else
<a href="tqwidget.html#update">update</a>();
}
}
void AnalogClock::<a href="tqwidget.html#paintEvent">paintEvent</a>( <a href="tqpaintevent.html">TQPaintEvent</a> * )
{
if ( <a href="tqwidget.html#autoMask">autoMask</a>() )
return;
<a href="tqpainter.html">TQPainter</a> paint( this );
<a name="x1190"></a> paint.<a href="tqpainter.html#setBrush">setBrush</a>( <a href="tqwidget.html#colorGroup">colorGroup</a>().foreground() );
drawClock( &paint );
}
// If the clock is transparent, we use updateMask()
// instead of paintEvent()
void AnalogClock::updateMask() // paint clock mask
{
<a href="tqbitmap.html">TQBitmap</a> bm( <a href="tqwidget.html#size">size</a>() );
bm.<a href="tqpixmap.html#fill">fill</a>( color0 ); //transparent
<a href="tqpainter.html">TQPainter</a> paint;
<a name="x1183"></a> paint.<a href="tqpainter.html#begin">begin</a>( &bm, this );
paint.<a href="tqpainter.html#setBrush">setBrush</a>( color1 ); // use non-transparent color
paint.<a href="tqpainter.html#setPen">setPen</a>( color1 );
drawClock( &paint );
<a name="x1186"></a> paint.<a href="tqpainter.html#end">end</a>();
<a href="tqwidget.html#setMask">setMask</a>( bm );
}
//
// The clock is painted using a 1000x1000 square coordinate system, in
// the a centered square, as big as possible. The painter's pen and
// brush colors are used.
//
void <a name="f387"></a>AnalogClock::drawClock( <a href="tqpainter.html">TQPainter</a> *paint )
{
<a name="x1189"></a> paint-><a href="tqpainter.html#save">save</a>();
<a name="x1193"></a> paint-><a href="tqpainter.html#setWindow">setWindow</a>( -500,-500, 1000,1000 );
<a name="x1194"></a> <a href="tqrect.html">TQRect</a> v = paint-><a href="tqpainter.html#viewport">viewport</a>();
int d = TQMIN( v.<a href="tqrect.html#width">width</a>(), v.<a href="tqrect.html#height">height</a>() );
<a name="x1198"></a><a name="x1192"></a> paint-><a href="tqpainter.html#setViewport">setViewport</a>( v.<a href="tqrect.html#left">left</a>() + (v.<a href="tqrect.html#width">width</a>()-d)/2,
<a name="x1199"></a> v.<a href="tqrect.html#top">top</a>() + (v.<a href="tqrect.html#height">height</a>()-d)/2, d, d );
<a href="tqpointarray.html">TQPointArray</a> pts;
paint-><a href="tqpainter.html#save">save</a>();
<a name="x1188"></a> paint-><a href="tqpainter.html#rotate">rotate</a>( 30*(time.hour()%12-3) + time.minute()/2 );
<a name="x1196"></a> pts.setPoints( 4, -20,0, 0,-20, 300,0, 0,20 );
<a name="x1184"></a> paint-><a href="tqpainter.html#drawConvexPolygon">drawConvexPolygon</a>( pts );
<a name="x1187"></a> paint-><a href="tqpainter.html#restore">restore</a>();
paint-><a href="tqpainter.html#save">save</a>();
paint-><a href="tqpainter.html#rotate">rotate</a>( (time.minute()-15)*6 );
pts.setPoints( 4, -10,0, 0,-10, 400,0, 0,10 );
paint-><a href="tqpainter.html#drawConvexPolygon">drawConvexPolygon</a>( pts );
paint-><a href="tqpainter.html#restore">restore</a>();
for ( int i=0; i<12; i++ ) {
<a name="x1185"></a> paint-><a href="tqpainter.html#drawLine">drawLine</a>( 440,0, 460,0 );
paint-><a href="tqpainter.html#rotate">rotate</a>( 30 );
}
paint-><a href="tqpainter.html#restore">restore</a>();
}
<a name="x1209"></a>void AnalogClock::<a href="tqwidget.html#setAutoMask">setAutoMask</a>(bool b)
{
if (b)
<a href="tqwidget.html#setBackgroundMode">setBackgroundMode</a>( PaletteForeground );
else
<a href="tqwidget.html#setBackgroundMode">setBackgroundMode</a>( PaletteBackground );
TQWidget::<a href="tqwidget.html#setAutoMask">setAutoMask</a>(b);
}
</pre>
<p> <hr>
<p> Main:
<p> <pre>/****************************************************************************
** $Id: qt/main.cpp 3.3.8 edited Jan 11 14:36 $
**
** 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 "aclock.h"
#include <<a href="qapplication-h.html">ntqapplication.h</a>>
int main( int argc, char **argv )
{
<a href="ntqapplication.html">TQApplication</a> a( argc, argv );
AnalogClock *clock = new AnalogClock;
if ( argc == 2 && strcmp( argv[1], "-transparent" ) == 0 )
<a name="x1213"></a> clock-><a href="tqwidget.html#setAutoMask">setAutoMask</a>( TRUE );
<a name="x1212"></a> clock-><a href="tqwidget.html#resize">resize</a>( 100, 100 );
a.<a href="ntqapplication.html#setMainWidget">setMainWidget</a>( clock );
<a name="x1214"></a> clock-><a href="tqwidget.html#setCaption">setCaption</a>("TQt Example - Analog Clock");
<a name="x1215"></a> clock-><a href="tqwidget.html#show">show</a>();
int result = a.<a href="ntqapplication.html#exec">exec</a>();
delete clock;
return result;
}
</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 © 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>
|