File: qwt__legend_8cpp-source.html

package info (click to toggle)
libqwt 4.2.0-4.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 9,832 kB
  • ctags: 5,512
  • sloc: cpp: 22,973; ansic: 244; makefile: 66
file content (536 lines) | stat: -rw-r--r-- 32,731 bytes parent folder | download | duplicates (5)
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
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Qwt User&apos;s Guide: qwt_legend.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.3.8 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
<h1>qwt_legend.cpp</h1><pre class="fragment"><div>00001 <span class="comment">/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************</span>
00002 <span class="comment"> * Qwt Widget Library</span>
00003 <span class="comment"> * Copyright (C) 1997   Josef Wilgen</span>
00004 <span class="comment"> * Copyright (C) 2002   Uwe Rathmann</span>
00005 <span class="comment"> * </span>
00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
00007 <span class="comment"> * modify it under the terms of the Qwt License, Version 1.0</span>
00008 <span class="comment"> *****************************************************************************/</span>
00009 
00010 <span class="comment">// vim: expandtab</span>
00011 
00012 <span class="preprocessor">#include &lt;qapplication.h&gt;</span> 
00013 <span class="preprocessor">#include &lt;qpainter.h&gt;</span>
00014 <span class="preprocessor">#include &lt;qbitmap.h&gt;</span>
00015 <span class="preprocessor">#include &lt;qstyle.h&gt;</span>
00016 <span class="preprocessor">#include "qwt_text.h"</span>
00017 <span class="preprocessor">#include "qwt_legend.h"</span>
00018 <span class="preprocessor">#include "qwt_painter.h"</span>
00019 <span class="preprocessor">#include "qwt_dyngrid_layout.h"</span>
00020 
00021 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">int</span> IdentifierWidth = 8;
00022 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">int</span> Margin = 2;
00023 
<a name="l00025"></a><a class="code" href="class_qwt_legend_item.html#a0">00025</a> <a class="code" href="class_qwt_legend_item.html#a0">QwtLegendItem::QwtLegendItem</a>():
00026     d_identifierMode(ShowLine | ShowText),
00027     d_curvePen(Qt::NoPen)
00028 {
00029 }
00030 
<a name="l00036"></a><a class="code" href="class_qwt_legend_item.html#a1">00036</a> <a class="code" href="class_qwt_legend_item.html#a0">QwtLegendItem::QwtLegendItem</a>(<span class="keyword">const</span> <a class="code" href="class_qwt_symbol.html">QwtSymbol</a> &amp;symbol, <span class="keyword">const</span> QPen &amp;curvePen):
00037     d_identifierMode(ShowLine | ShowText),
00038     d_symbol(symbol),
00039     d_curvePen(curvePen)
00040 {
00041 }
00042 
<a name="l00044"></a><a class="code" href="class_qwt_legend_item.html#a2">00044</a> <a class="code" href="class_qwt_legend_item.html#a2">QwtLegendItem::~QwtLegendItem</a>()
00045 {
00046 }
00047 
<a name="l00055"></a><a class="code" href="class_qwt_legend_item.html#a3">00055</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_legend_item.html#a3">QwtLegendItem::setIdentifierMode</a>(<span class="keywordtype">int</span> mode) 
00056 {
00057     <span class="keywordflow">if</span> ( mode != d_identifierMode )
00058     {
00059         d_identifierMode = mode;
00060         <a class="code" href="class_qwt_legend_item.html#b1">updateItem</a>();
00061     }
00062 }
00063 
<a name="l00068"></a><a class="code" href="class_qwt_legend_item.html#a4">00068</a> <span class="keywordtype">int</span> <a class="code" href="class_qwt_legend_item.html#a4">QwtLegendItem::identifierMode</a>()<span class="keyword"> const </span>
00069 <span class="keyword"></span>{ 
00070     <span class="keywordflow">return</span> d_identifierMode; 
00071 }
00072 
<a name="l00079"></a><a class="code" href="class_qwt_legend_item.html#a5">00079</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_legend_item.html#a5">QwtLegendItem::setSymbol</a>(<span class="keyword">const</span> <a class="code" href="class_qwt_symbol.html">QwtSymbol</a> &amp;symbol) 
00080 {
00081     <span class="keywordflow">if</span> ( symbol != d_symbol )
00082     {
00083         d_symbol = symbol;
00084         <a class="code" href="class_qwt_legend_item.html#b1">updateItem</a>();
00085     }
00086 }
00087     
<a name="l00092"></a><a class="code" href="class_qwt_legend_item.html#a6">00092</a> <span class="keyword">const</span> <a class="code" href="class_qwt_symbol.html">QwtSymbol</a>&amp; <a class="code" href="class_qwt_legend_item.html#a6">QwtLegendItem::symbol</a>()<span class="keyword"> const </span>
00093 <span class="keyword"></span>{ 
00094     <span class="keywordflow">return</span> d_symbol; 
00095 }
00096     
00097 
<a name="l00104"></a><a class="code" href="class_qwt_legend_item.html#a7">00104</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_legend_item.html#a7">QwtLegendItem::setCurvePen</a>(<span class="keyword">const</span> QPen &amp;pen) 
00105 {
00106     <span class="keywordflow">if</span> ( pen != d_curvePen )
00107     {
00108         d_curvePen = pen;
00109         <a class="code" href="class_qwt_legend_item.html#b1">updateItem</a>();
00110     }
00111 }
00112 
<a name="l00117"></a><a class="code" href="class_qwt_legend_item.html#a8">00117</a> <span class="keyword">const</span> QPen&amp; <a class="code" href="class_qwt_legend_item.html#a8">QwtLegendItem::curvePen</a>()<span class="keyword"> const </span>
00118 <span class="keyword"></span>{ 
00119     <span class="keywordflow">return</span> d_curvePen; 
00120 }
00121 
<a name="l00123"></a><a class="code" href="class_qwt_legend_item.html#b1">00123</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_legend_item.html#b1">QwtLegendItem::updateItem</a>()
00124 {
00125 }
00126 
<a name="l00132"></a><a class="code" href="class_qwt_legend_item.html#a9">00132</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_legend_item.html#a9">QwtLegendItem::drawIdentifier</a>(
00133     QPainter *painter, <span class="keyword">const</span> QRect &amp;rect)<span class="keyword"> const</span>
00134 <span class="keyword"></span>{
00135     <span class="keywordflow">if</span> ( rect.isEmpty() )
00136         <span class="keywordflow">return</span>;
00137 
00138     <span class="keywordflow">if</span> ( (d_identifierMode &amp; ShowLine ) &amp;&amp; (d_curvePen.style() != Qt::NoPen) )
00139     {
00140         painter-&gt;save();
00141         painter-&gt;setPen(d_curvePen);
00142         <a class="code" href="class_qwt_painter.html#e16">QwtPainter::drawLine</a>(painter, rect.left(), rect.center().y(), 
00143             rect.right(), rect.center().y());
00144         painter-&gt;restore();
00145     }
00146 
00147     <span class="keywordflow">if</span> ( (d_identifierMode &amp; ShowSymbol) 
00148         &amp;&amp; (d_symbol.<a class="code" href="class_qwt_symbol.html#a13">style</a>() != QwtSymbol::None) )
00149     {
00150         QSize symbolSize = 
00151             <a class="code" href="class_qwt_painter.html#e3">QwtPainter::metricsMap</a>().screenToLayout(d_symbol.<a class="code" href="class_qwt_symbol.html#a12">size</a>());
00152 
00153         <span class="comment">// scale the symbol size down if it doesn't fit into rect.</span>
00154 
00155         <span class="keywordflow">if</span> ( rect.width() &lt; symbolSize.width() )
00156         {
00157             <span class="keyword">const</span> <span class="keywordtype">double</span> ratio = 
00158                 double(symbolSize.width()) / double(rect.width());
00159             symbolSize.setWidth(rect.width());
00160             symbolSize.setHeight(qRound(symbolSize.height() / ratio));
00161         }
00162         <span class="keywordflow">if</span> ( rect.height() &lt; symbolSize.height() )
00163         {
00164             <span class="keyword">const</span> <span class="keywordtype">double</span> ratio = 
00165                 double(symbolSize.width()) / double(rect.width());
00166             symbolSize.setHeight(rect.height());
00167             symbolSize.setWidth(qRound(symbolSize.width() / ratio));
00168         }
00169 
00170         QRect symbolRect;
00171         symbolRect.setSize(symbolSize);
00172         symbolRect.moveCenter(rect.center());
00173 
00174         painter-&gt;save();
00175         painter-&gt;setBrush(d_symbol.<a class="code" href="class_qwt_symbol.html#a10">brush</a>());
00176         painter-&gt;setPen(d_symbol.<a class="code" href="class_qwt_symbol.html#a11">pen</a>());
00177         d_symbol.<a class="code" href="class_qwt_symbol.html#a14">draw</a>(painter, symbolRect);
00178         painter-&gt;restore();
00179     }
00180 }
00181 
<a name="l00188"></a><a class="code" href="class_qwt_legend_item.html#a10">00188</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_legend_item.html#a10">QwtLegendItem::drawItem</a>(QPainter *painter, <span class="keyword">const</span> QRect &amp;rect)<span class="keyword"> const</span>
00189 <span class="keyword"></span>{
00190     <span class="keyword">const</span> QwtMetricsMap &amp;map = <a class="code" href="class_qwt_painter.html#e3">QwtPainter::metricsMap</a>();
00191 
00192     <span class="keyword">const</span> <span class="keywordtype">int</span> margin = map.screenToLayoutX(Margin);
00193 
00194     <span class="keyword">const</span> QRect identifierRect(rect.x() + margin, rect.y(), 
00195         map.screenToLayoutX(IdentifierWidth), rect.height());
00196     <a class="code" href="class_qwt_legend_item.html#a9">drawIdentifier</a>(painter, identifierRect);
00197 
00198     <span class="comment">// Label</span>
00199 
00200     <a class="code" href="class_qwt_text.html">QwtText</a> *txt = titleText();
00201     <span class="keywordflow">if</span> ( txt )
00202     {
00203         QRect titleRect = rect;
00204         titleRect.setX(identifierRect.right() + 2 * margin);
00205      
00206         txt-&gt;<a class="code" href="class_qwt_text.html#a18">draw</a>(painter, titleRect);
00207         <span class="keyword">delete</span> txt;
00208     }
00209 }
00210 
00211 
<a name="l00216"></a><a class="code" href="class_qwt_legend_button.html#a0">00216</a> <a class="code" href="class_qwt_legend_button.html#a0">QwtLegendButton::QwtLegendButton</a>(QWidget *parent, <span class="keyword">const</span> <span class="keywordtype">char</span> *name): 
00217     <a class="code" href="class_qwt_push_button.html">QwtPushButton</a>(parent, name)
00218 {
00219     init();
00220 }
00221     
<a name="l00229"></a><a class="code" href="class_qwt_legend_button.html#a1">00229</a> <a class="code" href="class_qwt_legend_button.html#a0">QwtLegendButton::QwtLegendButton</a>(
00230         <span class="keyword">const</span> <a class="code" href="class_qwt_symbol.html">QwtSymbol</a> &amp;symbol, <span class="keyword">const</span> QPen &amp;curvePen, <span class="keyword">const</span> QString &amp;text,
00231         QWidget *parent, <span class="keyword">const</span> <span class="keywordtype">char</span> *name): 
00232     <a class="code" href="class_qwt_push_button.html">QwtPushButton</a>(text, parent, name),
00233     <a class="code" href="class_qwt_legend_item.html">QwtLegendItem</a>(symbol, curvePen)
00234 {
00235     init();
00236 }
00237 
00238 <span class="keywordtype">void</span> QwtLegendButton::init()
00239 {
00240     setFlat(TRUE);
00241     <a class="code" href="class_qwt_push_button.html#a7">setAlignment</a>(Qt::AlignLeft | Qt::AlignVCenter | 
00242         Qt::ExpandTabs | Qt::WordBreak);
00243     <a class="code" href="class_qwt_push_button.html#a8">setIndent</a>(2 * Margin);
00244     <a class="code" href="class_qwt_legend_button.html#b2">updateIconset</a>();
00245 }
00246 
<a name="l00247"></a><a class="code" href="class_qwt_legend_button.html#b1">00247</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_legend_button.html#b1">QwtLegendButton::updateItem</a>()
00248 {
00249     <a class="code" href="class_qwt_legend_button.html#b2">updateIconset</a>();
00250 }
00251 
<a name="l00255"></a><a class="code" href="class_qwt_legend_button.html#b2">00255</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_legend_button.html#b2">QwtLegendButton::updateIconset</a>()
00256 {
00257     <span class="keyword">const</span> QFontMetrics fm(font());
00258 
00259     QPixmap pm(IdentifierWidth, fm.height());
00260     pm.fill(<span class="keyword">this</span>, 0, 0);
00261 
00262     QPainter p(&amp;pm);
00263     <a class="code" href="class_qwt_legend_item.html#a9">drawIdentifier</a>(&amp;p, QRect(0, 0, pm.width(), pm.height()) );
00264     p.end();
00265 
00266     pm.setMask(pm.createHeuristicMask());
00267 
00268     setIconSet(QIconSet(pm));
00269 }
00270 
<a name="l00277"></a><a class="code" href="class_qwt_legend_button.html#a2">00277</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_legend_button.html#a2">QwtLegendButton::setTitle</a>(<span class="keyword">const</span> QString &amp;title)
00278 {
00279     setText(title);
00280 }
00281 
<a name="l00286"></a><a class="code" href="class_qwt_legend_button.html#a3">00286</a> QString <a class="code" href="class_qwt_legend_button.html#a3">QwtLegendButton::title</a>()<span class="keyword"> const</span>
00287 <span class="keyword"></span>{
00288     <span class="keywordflow">return</span> text();
00289 }
00290 
<a name="l00295"></a><a class="code" href="class_qwt_legend_button.html#b0">00295</a> <a class="code" href="class_qwt_text.html">QwtText</a> *<a class="code" href="class_qwt_legend_button.html#b0">QwtLegendButton::titleText</a>()<span class="keyword"> const</span>
00296 <span class="keyword"></span>{
00297     <span class="keywordflow">return</span> <a class="code" href="class_qwt_text.html#e0">QwtText::makeText</a>(text(), <a class="code" href="class_qwt_push_button.html#a5">usedTextFormat</a>(),
00298         <a class="code" href="class_qwt_push_button.html#a6">alignment</a>(), font());
00299 }
00300 
<a name="l00305"></a><a class="code" href="class_qwt_legend_label.html#a0">00305</a> <a class="code" href="class_qwt_legend_label.html#a0">QwtLegendLabel::QwtLegendLabel</a>(QWidget *parent, <span class="keyword">const</span> <span class="keywordtype">char</span> *name):
00306     QLabel(parent, name)
00307 {
00308     init();
00309 }
00310 
<a name="l00318"></a><a class="code" href="class_qwt_legend_label.html#a1">00318</a> <a class="code" href="class_qwt_legend_label.html#a0">QwtLegendLabel::QwtLegendLabel</a>(<span class="keyword">const</span> <a class="code" href="class_qwt_symbol.html">QwtSymbol</a> &amp;symbol, 
00319         <span class="keyword">const</span> QPen &amp;curvePen, <span class="keyword">const</span> QString &amp;text, 
00320         QWidget *parent, <span class="keyword">const</span> <span class="keywordtype">char</span> *name):
00321     QLabel(text, parent, name),
00322     <a class="code" href="class_qwt_legend_item.html">QwtLegendItem</a>(symbol, curvePen)
00323 {
00324     init();
00325 }
00326 
00327 <span class="keywordtype">void</span> QwtLegendLabel::init()
00328 {
00329     setAlignment(Qt::AlignLeft | Qt::AlignVCenter | 
00330         Qt::ExpandTabs | Qt::WordBreak);
00331     setIndent(Margin + IdentifierWidth + 2 * Margin);
00332     setMargin(Margin);
00333 }
00334 
<a name="l00341"></a><a class="code" href="class_qwt_legend_label.html#a2">00341</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_legend_label.html#a2">QwtLegendLabel::setTitle</a>(<span class="keyword">const</span> QString &amp;title)
00342 {
00343     setText(title);
00344 }
00345 
<a name="l00350"></a><a class="code" href="class_qwt_legend_label.html#a3">00350</a> QString <a class="code" href="class_qwt_legend_label.html#a3">QwtLegendLabel::title</a>()<span class="keyword"> const</span>
00351 <span class="keyword"></span>{
00352     <span class="keywordflow">return</span> text();
00353 }
00354 
<a name="l00359"></a><a class="code" href="class_qwt_legend_label.html#b0">00359</a> <a class="code" href="class_qwt_text.html">QwtText</a> *<a class="code" href="class_qwt_legend_label.html#b0">QwtLegendLabel::titleText</a>()<span class="keyword"> const</span>
00360 <span class="keyword"></span>{
00361     <span class="keywordflow">return</span> <a class="code" href="class_qwt_text.html#e0">QwtText::makeText</a>(text(), textFormat(), 
00362         alignment(), font());
00363 }
00364 
<a name="l00368"></a><a class="code" href="class_qwt_legend_label.html#b1">00368</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_legend_label.html#b1">QwtLegendLabel::drawContents</a>(QPainter *painter)
00369 {
00370     QLabel::drawContents(painter);
00371 
00372     QRect rect = contentsRect();
00373     rect.setX(rect.x() + Margin);
00374     rect.setWidth(IdentifierWidth);
00375 
00376     <a class="code" href="class_qwt_legend_item.html#a9">drawIdentifier</a>(painter, rect);
00377 }
00378 
<a name="l00379"></a><a class="code" href="class_qwt_legend_label.html#b2">00379</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_legend_label.html#b2">QwtLegendLabel::updateItem</a>()
00380 {
00381     update();
00382 }
00383 
<a name="l00388"></a><a class="code" href="class_qwt_legend.html#a0">00388</a> <a class="code" href="class_qwt_legend.html#a0">QwtLegend::QwtLegend</a>(QWidget *parent, <span class="keyword">const</span> <span class="keywordtype">char</span> *name): 
00389     QScrollView(parent, name),
00390     d_readOnly(FALSE),
00391     d_displayPolicy(<a class="code" href="class_qwt_legend.html">QwtLegend</a>::Auto),
00392     d_identifierMode(<a class="code" href="class_qwt_legend_button.html">QwtLegendButton</a>::ShowLine
00393              | <a class="code" href="class_qwt_legend_button.html">QwtLegendButton</a>::ShowSymbol
00394              | <a class="code" href="class_qwt_legend_button.html">QwtLegendButton</a>::ShowText)
00395 {
00396     setFrameStyle(NoFrame);
00397     setResizePolicy(Manual);
00398 
00399     viewport()-&gt;setBackgroundMode(NoBackground); <span class="comment">// Avoid flicker</span>
00400 
00401     d_contentsWidget = <span class="keyword">new</span> QWidget(viewport());
00402     d_contentsWidget-&gt;installEventFilter(<span class="keyword">this</span>);
00403 
00404     <a class="code" href="class_qwt_dyn_grid_layout.html">QwtDynGridLayout</a> *layout = <span class="keyword">new</span> <a class="code" href="class_qwt_dyn_grid_layout.html">QwtDynGridLayout</a>(d_contentsWidget);
00405     layout-&gt;setAlignment(Qt::AlignHCenter | Qt::AlignTop);
00406     layout-&gt;setAutoAdd(TRUE);
00407 
00408     addChild(d_contentsWidget);
00409 }
00410 
<a name="l00415"></a><a class="code" href="class_qwt_legend.html#a1">00415</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_legend.html#a1">QwtLegend::setReadOnly</a>(<span class="keywordtype">bool</span> readOnly)
00416 {
00417     d_readOnly = readOnly;
00418 }
00419 
<a name="l00424"></a><a class="code" href="class_qwt_legend.html#a2">00424</a> <span class="keywordtype">bool</span> <a class="code" href="class_qwt_legend.html#a2">QwtLegend::isReadOnly</a>()<span class="keyword"> const</span>
00425 <span class="keyword"></span>{
00426     <span class="keywordflow">return</span> d_readOnly;
00427 }
00428 
<a name="l00437"></a><a class="code" href="class_qwt_legend.html#a3">00437</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_legend.html#a3">QwtLegend::setDisplayPolicy</a>(LegendDisplayPolicy policy, <span class="keywordtype">int</span> mode)
00438 {
00439     d_displayPolicy = policy;
00440     <span class="keywordflow">if</span> (-1 != mode)
00441        d_identifierMode = mode;
00442 }
00443 
<a name="l00450"></a><a class="code" href="class_qwt_legend.html#a4">00450</a> <a class="code" href="class_qwt_legend.html#w3">QwtLegend::LegendDisplayPolicy</a> <a class="code" href="class_qwt_legend.html#a4">QwtLegend::displayPolicy</a>()<span class="keyword"> const </span>
00451 <span class="keyword"></span>{ 
00452     <span class="keywordflow">return</span> d_displayPolicy; 
00453 }
00454 
<a name="l00462"></a><a class="code" href="class_qwt_legend.html#a5">00462</a> <span class="keywordtype">int</span> <a class="code" href="class_qwt_legend.html#a5">QwtLegend::identifierMode</a>()<span class="keyword"> const</span>
00463 <span class="keyword"></span>{
00464     <span class="keywordflow">return</span> d_identifierMode;
00465 }
00466 
<a name="l00471"></a><a class="code" href="class_qwt_legend.html#a6">00471</a> QWidget *<a class="code" href="class_qwt_legend.html#a6">QwtLegend::contentsWidget</a>() 
00472 { 
00473     <span class="keywordflow">return</span> d_contentsWidget; 
00474 }
00475 
<a name="l00481"></a><a class="code" href="class_qwt_legend.html#a7">00481</a> <span class="keyword">const</span> QWidget *<a class="code" href="class_qwt_legend.html#a6">QwtLegend::contentsWidget</a>()<span class="keyword"> const </span>
00482 <span class="keyword"></span>{ 
00483     <span class="keywordflow">return</span> d_contentsWidget; 
00484 }
00485 
<a name="l00493"></a><a class="code" href="class_qwt_legend.html#a8">00493</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_legend.html#a8">QwtLegend::insertItem</a>(QWidget *item, <span class="keywordtype">long</span> key)
00494 {
00495     <span class="keywordflow">if</span> ( item == NULL || key &lt; 0 )
00496         <span class="keywordflow">return</span>;
00497 
00498     <span class="keywordflow">if</span> ( item-&gt;parent() != d_contentsWidget )
00499         item-&gt;reparent(d_contentsWidget, QPoint(0, 0));
00500 
00501     item-&gt;show();
00502 
00503     <span class="keywordflow">if</span> ( d_items.count() &gt; d_items.size() - 5 )
00504         d_items.resize(d_items.count() + 5);
00505 
00506     d_items.insert(key, item);
00507 
00508     <a class="code" href="class_qwt_legend.html#b1">layoutContents</a>();
00509 
00510     QWidget *w = 0;
00511 
00512     <span class="keywordflow">if</span> ( d_contentsWidget-&gt;layout() )
00513     {
00514         <span class="comment">// set tab focus chain</span>
00515 
00516         QLayoutIterator layoutIterator = 
00517             d_contentsWidget-&gt;layout()-&gt;iterator();
00518 
00519         <span class="keywordflow">for</span> ( QLayoutItem *item = layoutIterator.current();
00520             item != 0; item = ++layoutIterator)
00521         {
00522             <span class="keywordflow">if</span> ( w &amp;&amp; item-&gt;widget() )
00523                 QWidget::setTabOrder(w, item-&gt;widget());
00524 
00525             w = item-&gt;widget();
00526         }
00527     }
00528 }
00529 
<a name="l00531"></a><a class="code" href="class_qwt_legend.html#a9">00531</a> QWidget *<a class="code" href="class_qwt_legend.html#a9">QwtLegend::findItem</a>(<span class="keywordtype">long</span> key)
00532 {
00533     <span class="keywordflow">return</span> d_items.find(key);
00534 }
00535 
<a name="l00537"></a><a class="code" href="class_qwt_legend.html#a10">00537</a> <span class="keyword">const</span> QWidget *<a class="code" href="class_qwt_legend.html#a9">QwtLegend::findItem</a>(<span class="keywordtype">long</span> key)<span class="keyword"> const </span>
00538 <span class="keyword"></span>{ 
00539     <span class="keywordflow">return</span> d_items.find(key); 
00540 }
00541     
<a name="l00543"></a><a class="code" href="class_qwt_legend.html#a11">00543</a> QWidget *<a class="code" href="class_qwt_legend.html#a11">QwtLegend::takeItem</a>(<span class="keywordtype">long</span> key) 
00544 { 
00545     <span class="keywordflow">return</span> d_items.take(key); 
00546 }
00547 
<a name="l00553"></a><a class="code" href="class_qwt_legend.html#a13">00553</a> <span class="keywordtype">long</span> <a class="code" href="class_qwt_legend.html#a13">QwtLegend::key</a>(<span class="keyword">const</span> QWidget *item)<span class="keyword"> const</span>
00554 <span class="keyword"></span>{
00555     QWidgetIntDictIt it(d_items);
00556     <span class="keywordflow">for</span> ( <span class="keyword">const</span> QWidget *w = it.toFirst(); w != 0; w = ++it)
00557     {
00558         <span class="keywordflow">if</span> ( w == item )
00559             <span class="keywordflow">return</span> it.currentKey();
00560     }
00561     <span class="keywordflow">return</span> -1;
00562 }
00563 
<a name="l00565"></a><a class="code" href="class_qwt_legend.html#a14">00565</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_legend.html#a14">QwtLegend::clear</a>()
00566 {
00567     <span class="comment">// We can't delete the items while we are running</span>
00568     <span class="comment">// through the iterator. So we collect them in</span>
00569     <span class="comment">// a list first.</span>
00570 
00571     QValueList&lt;QWidget *&gt; clearList;
00572     
00573     QWidgetIntDictIt it(d_items);
00574     <span class="keywordflow">for</span> ( QWidget *item = it.toFirst(); item != 0; item = ++it)
00575         clearList += item;
00576 
00577     <span class="keywordflow">for</span> ( uint i = 0; i &lt; clearList.count(); i++ )
00578         <span class="keyword">delete</span> clearList[i];
00579 
00580 <span class="preprocessor">#if QT_VERSION &lt; 232</span>
00581 <span class="preprocessor"></span>    <span class="comment">// In Qt 2.3.0 the ChildRemoved events are not sent, before the</span>
00582     <span class="comment">// first show of the legend. Thus the deleted items are not cleared</span>
00583     <span class="comment">// from the list in QwtLegend::eventFilter. In most cases</span>
00584     <span class="comment">// the following clear is useless, but is is safe to do so.</span>
00585     
00586     d_items.clear();
00587 <span class="preprocessor">#endif</span>
00588 <span class="preprocessor"></span>}
00589 
<a name="l00591"></a><a class="code" href="class_qwt_legend.html#a12">00591</a> QWidgetIntDictIt <a class="code" href="class_qwt_legend.html#a12">QwtLegend::itemIterator</a>()<span class="keyword"> const</span>
00592 <span class="keyword"></span>{
00593     <span class="keywordflow">return</span> QWidgetIntDictIt(d_items);
00594 }
00595 
<a name="l00597"></a><a class="code" href="class_qwt_legend.html#a18">00597</a> QSize <a class="code" href="class_qwt_legend.html#a18">QwtLegend::sizeHint</a>()<span class="keyword"> const</span>
00598 <span class="keyword"></span>{
00599     QSize hint = d_contentsWidget-&gt;sizeHint();
00600     hint += QSize(2 * frameWidth(), 2 * frameWidth());
00601     
00602     <span class="keywordflow">return</span> hint;
00603 }
00604 
<a name="l00608"></a><a class="code" href="class_qwt_legend.html#a19">00608</a> <span class="keywordtype">int</span> <a class="code" href="class_qwt_legend.html#a19">QwtLegend::heightForWidth</a>(<span class="keywordtype">int</span> w)<span class="keyword"> const</span>
00609 <span class="keyword"></span>{
00610     w -= 2 * frameWidth();
00611 
00612     <span class="keywordtype">int</span> h = d_contentsWidget-&gt;heightForWidth(w);
00613     <span class="keywordflow">if</span> ( h &lt;= 0 ) <span class="comment">// not implemented, we try the layout</span>
00614     {
00615         QLayout *l = d_contentsWidget-&gt;layout();
00616         <span class="keywordflow">if</span> ( l &amp;&amp; l-&gt;hasHeightForWidth() )
00617         {
00618             h = l-&gt;heightForWidth(w);
00619             h += 2 * frameWidth();
00620         }
00621     }
00622 
00623     <span class="keywordflow">return</span> h;
00624 }
00625 
<a name="l00629"></a><a class="code" href="class_qwt_legend.html#b1">00629</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_legend.html#b1">QwtLegend::layoutContents</a>()
00630 {
00631     <span class="keyword">const</span> QSize visibleSize = viewport()-&gt;size();
00632 
00633     <span class="keyword">const</span> QLayout *l = d_contentsWidget-&gt;layout();
00634     <span class="keywordflow">if</span> ( l &amp;&amp; l-&gt;inherits(<span class="stringliteral">"QwtDynGridLayout"</span>) )
00635     {
00636         <span class="keyword">const</span> <a class="code" href="class_qwt_dyn_grid_layout.html">QwtDynGridLayout</a> *tl = (<span class="keyword">const</span> <a class="code" href="class_qwt_dyn_grid_layout.html">QwtDynGridLayout</a> *)l;
00637 
00638         <span class="keyword">const</span> <span class="keywordtype">int</span> minW = int(tl-&gt;<a class="code" href="class_qwt_dyn_grid_layout.html#a11">maxItemWidth</a>()) + 2 * tl-&gt;margin();
00639 
00640         <span class="keywordtype">int</span> w = QMAX(visibleSize.width(), minW);
00641         <span class="keywordtype">int</span> h = QMAX(tl-&gt;<a class="code" href="class_qwt_dyn_grid_layout.html#a14">heightForWidth</a>(w), visibleSize.height());
00642 
00643         <span class="keyword">const</span> <span class="keywordtype">int</span> vpWidth = viewportSize(w, h).width();
00644 
00645         <span class="keywordflow">if</span> ( w &gt; vpWidth )
00646         {
00647             w = QMAX(vpWidth, minW);
00648             h = QMAX(tl-&gt;<a class="code" href="class_qwt_dyn_grid_layout.html#a14">heightForWidth</a>(w), visibleSize.height());
00649         }
00650 
00651         d_contentsWidget-&gt;resize(w, h);
00652         resizeContents(w, h);
00653     }
00654 }
00655 
00656 <span class="comment">/*</span>
00657 <span class="comment">  Filter QEvent::ChildRemoved, and QEvent::LayoutHint for</span>
00658 <span class="comment">  QwtLegend::contentsWidget().</span>
00659 <span class="comment">*/</span>
00660 
<a name="l00662"></a><a class="code" href="class_qwt_legend.html#a17">00662</a> <span class="keywordtype">bool</span> <a class="code" href="class_qwt_legend.html#a17">QwtLegend::eventFilter</a>(QObject *o, QEvent *e)
00663 {
00664     <span class="keywordflow">if</span> ( o == d_contentsWidget )
00665     {
00666         <span class="keywordflow">switch</span>(e-&gt;type())
00667         {
00668             <span class="keywordflow">case</span> QEvent::ChildRemoved:
00669             {   
00670                 <span class="keyword">const</span> QChildEvent *ce = (<span class="keyword">const</span> QChildEvent *)e;
00671                 <span class="keywordflow">if</span> ( ce-&gt;child()-&gt;isWidgetType() )
00672                     (<span class="keywordtype">void</span>)<a class="code" href="class_qwt_legend.html#a11">takeItem</a>(<a class="code" href="class_qwt_legend.html#a13">key</a>((QWidget *)ce-&gt;child()));
00673                 <span class="keywordflow">break</span>;
00674             }
00675             <span class="keywordflow">case</span> QEvent::LayoutHint:
00676             {
00677                 <a class="code" href="class_qwt_legend.html#b1">layoutContents</a>();
00678                 <span class="keywordflow">break</span>;
00679             }
00680             <span class="keywordflow">default</span>:
00681                 <span class="keywordflow">break</span>;
00682         }
00683     }
00684     
00685     <span class="keywordflow">return</span> QScrollView::eventFilter(o, e);
00686 }
00687 
<a name="l00692"></a><a class="code" href="class_qwt_legend.html#b0">00692</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_legend.html#b0">QwtLegend::viewportResizeEvent</a>(QResizeEvent *e)
00693 {
00694     QScrollView::viewportResizeEvent(e);
00695 
00696     <span class="comment">// It's not safe to update the layout now, because</span>
00697     <span class="comment">// we are in an internal update of the scrollview framework.</span>
00698     <span class="comment">// So we delay the update by posting a LayoutHint.</span>
00699 
00700     QApplication::postEvent(d_contentsWidget, <span class="keyword">new</span> QEvent(QEvent::LayoutHint));
00701 }
</div></pre><hr size="1"><address style="align: right;"><small>Generated on Tue Nov 16 21:12:20 2004 for Qwt User's Guide by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 ></a> 1.3.8 </small></address>
</body>
</html>