File: qwt__picker_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 (851 lines) | stat: -rw-r--r-- 52,454 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
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
<!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_picker.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_picker.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="preprocessor">#include &lt;qapplication.h&gt;</span>
00011 <span class="preprocessor">#include &lt;qevent.h&gt;</span>
00012 <span class="preprocessor">#include &lt;qpainter.h&gt;</span>
00013 <span class="preprocessor">#include &lt;qframe.h&gt;</span>
00014 <span class="preprocessor">#include &lt;qcursor.h&gt;</span>
00015 <span class="preprocessor">#include "qwt_text.h"</span>
00016 <span class="preprocessor">#include "qwt_painter.h"</span>
00017 <span class="preprocessor">#include "qwt_picker_machine.h"</span>
00018 <span class="preprocessor">#include "qwt_picker.h"</span>
00019 
<a name="l00030"></a><a class="code" href="class_qwt_picker.html#a0">00030</a> <a class="code" href="class_qwt_picker.html#a0">QwtPicker::QwtPicker</a>(QWidget *parent, <span class="keyword">const</span> <span class="keywordtype">char</span> *name):
00031     QObject(parent, name)
00032 {
00033     init(parent, NoSelection, NoRubberBand, AlwaysOff);
00034 }
00035 
<a name="l00046"></a><a class="code" href="class_qwt_picker.html#a1">00046</a> <a class="code" href="class_qwt_picker.html#a0">QwtPicker::QwtPicker</a>(<span class="keywordtype">int</span> selectionFlags, RubberBand rubberBand,
00047         DisplayMode cursorLabelMode, QWidget *parent, <span class="keyword">const</span> <span class="keywordtype">char</span> *name):
00048     QObject(parent, name)
00049 {
00050     init(parent, selectionFlags, rubberBand, cursorLabelMode);
00051 }
00052 
<a name="l00054"></a><a class="code" href="class_qwt_picker.html#a2">00054</a> <a class="code" href="class_qwt_picker.html#a2">QwtPicker::~QwtPicker</a>()
00055 {
00056     setMouseTracking(FALSE);
00057     <span class="keyword">delete</span> d_stateMachine;
00058 }
00059 
00061 <span class="keywordtype">void</span> QwtPicker::init(QWidget *parent, <span class="keywordtype">int</span> selectionFlags, 
00062     RubberBand rubberBand, DisplayMode cursorLabelMode)
00063 {
00064     d_rubberBand = rubberBand;
00065     d_enabled = FALSE;
00066     d_resizeMode = Stretch;
00067     d_cursorLabelMode = AlwaysOff;
00068     d_isActive = FALSE;
00069     d_labelPosition = QPoint(-1, -1);
00070     d_mouseTracking = FALSE;
00071 
00072     d_stateMachine = NULL;
00073     <a class="code" href="class_qwt_picker.html#a3">setSelectionFlags</a>(selectionFlags);
00074 
00075     <span class="keywordflow">if</span> ( parent )
00076     {
00077         <span class="keywordflow">if</span> ( parent-&gt;focusPolicy() == QWidget::NoFocus )
00078             parent-&gt;setFocusPolicy(QWidget::WheelFocus);
00079 
00080         d_cursorLabelFont = parent-&gt;font();
00081         d_mouseTracking = parent-&gt;hasMouseTracking();
00082         <a class="code" href="class_qwt_picker.html#a18">setEnabled</a>(TRUE);
00083     }
00084     <a class="code" href="class_qwt_picker.html#a7">setCursorLabelMode</a>(cursorLabelMode);
00085 }
00086 
00090 <span class="keywordtype">void</span> QwtPicker::setStateMachine(<a class="code" href="class_qwt_picker_machine.html">QwtPickerMachine</a> *stateMachine)
00091 {
00092     <span class="keywordflow">if</span> ( d_stateMachine != stateMachine )
00093     {
00094         <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_picker.html#a19">isActive</a>() )
00095             <a class="code" href="class_qwt_picker.html#b5">end</a>(FALSE);
00096 
00097         <span class="keyword">delete</span> d_stateMachine;
00098         d_stateMachine = stateMachine;
00099 
00100         <span class="keywordflow">if</span> ( d_stateMachine )
00101             d_stateMachine-&gt;<a class="code" href="class_qwt_picker_machine.html#a2">reset</a>();
00102     }
00103 }
00104 
<a name="l00121"></a><a class="code" href="class_qwt_picker.html#b19">00121</a> <a class="code" href="class_qwt_picker_machine.html">QwtPickerMachine</a> *<a class="code" href="class_qwt_picker.html#b19">QwtPicker::stateMachine</a>(<span class="keywordtype">int</span> flags)<span class="keyword"> const</span>
00122 <span class="keyword"></span>{
00123     <span class="keywordflow">if</span> ( flags &amp; PointSelection )
00124     {
00125         <span class="keywordflow">if</span> ( flags &amp; ClickSelection )
00126             <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="class_qwt_picker_click_point_machine.html">QwtPickerClickPointMachine</a>;
00127         <span class="keywordflow">else</span>
00128             <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="class_qwt_picker_drag_point_machine.html">QwtPickerDragPointMachine</a>;
00129     }
00130     <span class="keywordflow">if</span> ( flags &amp; RectSelection )
00131     {
00132         <span class="keywordflow">if</span> ( flags &amp; ClickSelection )
00133             <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="class_qwt_picker_click_rect_machine.html">QwtPickerClickRectMachine</a>;
00134         <span class="keywordflow">else</span>
00135             <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="class_qwt_picker_drag_rect_machine.html">QwtPickerDragRectMachine</a>;
00136     }
00137     <span class="keywordflow">if</span> ( flags &amp; PolygonSelection )
00138     {
00139         <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="class_qwt_picker_polygon_machine.html">QwtPickerPolygonMachine</a>();
00140     }
00141     <span class="keywordflow">return</span> NULL;
00142 }
00143 
<a name="l00145"></a><a class="code" href="class_qwt_picker.html#a21">00145</a> QWidget *<a class="code" href="class_qwt_picker.html#a21">QwtPicker::parentWidget</a>()
00146 {
00147     QObject *obj = parent();
00148     <span class="keywordflow">if</span> ( obj &amp;&amp; obj-&gt;isWidgetType() )
00149         <span class="keywordflow">return</span> (QWidget *)obj;
00150 
00151     <span class="keywordflow">return</span> NULL;
00152 }
00153 
<a name="l00155"></a><a class="code" href="class_qwt_picker.html#a22">00155</a> <span class="keyword">const</span> QWidget *<a class="code" href="class_qwt_picker.html#a21">QwtPicker::parentWidget</a>()<span class="keyword"> const</span>
00156 <span class="keyword"></span>{
00157     QObject *obj = parent();
00158     <span class="keywordflow">if</span> ( obj &amp;&amp; obj-&gt;isWidgetType() )
00159         <span class="keywordflow">return</span> (QWidget *)obj;
00160 
00161     <span class="keywordflow">return</span> NULL;
00162 }
00163 
<a name="l00173"></a><a class="code" href="class_qwt_picker.html#a3">00173</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_picker.html#a3">QwtPicker::setSelectionFlags</a>(<span class="keywordtype">int</span> flags)
00174 {
00175     d_selectionFlags = flags;
00176     setStateMachine(<a class="code" href="class_qwt_picker.html#b19">stateMachine</a>(flags));
00177 }
00178 
<a name="l00184"></a><a class="code" href="class_qwt_picker.html#a4">00184</a> <span class="keywordtype">int</span> <a class="code" href="class_qwt_picker.html#a4">QwtPicker::selectionFlags</a>()<span class="keyword"> const</span>
00185 <span class="keyword"></span>{
00186     <span class="keywordflow">return</span> d_selectionFlags;
00187 }
00188 
<a name="l00197"></a><a class="code" href="class_qwt_picker.html#a5">00197</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_picker.html#a5">QwtPicker::setRubberBand</a>(RubberBand rubberBand)
00198 {
00199     d_rubberBand = rubberBand;
00200 }
00201 
<a name="l00206"></a><a class="code" href="class_qwt_picker.html#a6">00206</a> <a class="code" href="class_qwt_picker.html#w25">QwtPicker::RubberBand</a> <a class="code" href="class_qwt_picker.html#a6">QwtPicker::rubberBand</a>()<span class="keyword"> const</span>
00207 <span class="keyword"></span>{
00208     <span class="keywordflow">return</span> d_rubberBand;
00209 }
00210 
<a name="l00227"></a><a class="code" href="class_qwt_picker.html#a7">00227</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_picker.html#a7">QwtPicker::setCursorLabelMode</a>(DisplayMode mode)
00228 {   
00229     <span class="keywordflow">if</span> ( d_cursorLabelMode != mode )
00230     {
00231         d_cursorLabelMode = mode;
00232         setMouseTracking(d_cursorLabelMode == AlwaysOn);
00233     }
00234 }   
00235 
<a name="l00240"></a><a class="code" href="class_qwt_picker.html#a8">00240</a> <a class="code" href="class_qwt_picker.html#w26">QwtPicker::DisplayMode</a> <a class="code" href="class_qwt_picker.html#a8">QwtPicker::cursorLabelMode</a>()<span class="keyword"> const</span>
00241 <span class="keyword"></span>{   
00242     <span class="keywordflow">return</span> d_cursorLabelMode;
00243 }   
00244 
<a name="l00259"></a><a class="code" href="class_qwt_picker.html#a9">00259</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_picker.html#a9">QwtPicker::setResizeMode</a>(ResizeMode mode)
00260 {
00261     d_resizeMode = mode;
00262 }   
00263 
<a name="l00269"></a><a class="code" href="class_qwt_picker.html#a10">00269</a> <a class="code" href="class_qwt_picker.html#w27">QwtPicker::ResizeMode</a> <a class="code" href="class_qwt_picker.html#a10">QwtPicker::resizeMode</a>()<span class="keyword"> const</span>
00270 <span class="keyword"></span>{   
00271     <span class="keywordflow">return</span> d_resizeMode;
00272 }
00273 
<a name="l00283"></a><a class="code" href="class_qwt_picker.html#a18">00283</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_picker.html#a18">QwtPicker::setEnabled</a>(<span class="keywordtype">bool</span> enabled)
00284 {
00285     <span class="keywordflow">if</span> ( d_enabled != enabled )
00286     {
00287         QWidget *w = <a class="code" href="class_qwt_picker.html#a21">parentWidget</a>();
00288         <span class="keywordflow">if</span> ( !w )
00289             <span class="keywordflow">return</span>;
00290 
00291         d_enabled = enabled;
00292         <a class="code" href="class_qwt_picker.html#b15">drawCursorLabel</a>();
00293 
00294         <span class="keywordflow">if</span> ( d_enabled )
00295             w-&gt;installEventFilter(<span class="keyword">this</span>);
00296         <span class="keywordflow">else</span>
00297             w-&gt;removeEventFilter(<span class="keyword">this</span>);
00298     }
00299 }
00300 
<a name="l00306"></a><a class="code" href="class_qwt_picker.html#a17">00306</a> <span class="keywordtype">bool</span> <a class="code" href="class_qwt_picker.html#a17">QwtPicker::isEnabled</a>()<span class="keyword"> const</span>
00307 <span class="keyword"></span>{
00308     <span class="keywordflow">return</span> d_enabled;
00309 }
00310 
<a name="l00317"></a><a class="code" href="class_qwt_picker.html#a15">00317</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_picker.html#a15">QwtPicker::setCursorLabelFont</a>(<span class="keyword">const</span> QFont &amp;font)
00318 {
00319     <span class="keywordflow">if</span> ( font != d_cursorLabelFont )
00320     {
00321         <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_picker.html#a17">isEnabled</a>() )
00322             <a class="code" href="class_qwt_picker.html#b15">drawCursorLabel</a>(); <span class="comment">// erase</span>
00323 
00324         d_cursorLabelFont = font;
00325 
00326         <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_picker.html#a17">isEnabled</a>() )
00327             <a class="code" href="class_qwt_picker.html#b15">drawCursorLabel</a>(); <span class="comment">// repaint</span>
00328     }
00329 }
00330 
<a name="l00336"></a><a class="code" href="class_qwt_picker.html#a16">00336</a> QFont <a class="code" href="class_qwt_picker.html#a16">QwtPicker::cursorLabelFont</a>()<span class="keyword"> const</span>
00337 <span class="keyword"></span>{
00338     <span class="keywordflow">return</span> d_cursorLabelFont;
00339 }
00340 
<a name="l00347"></a><a class="code" href="class_qwt_picker.html#a13">00347</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_picker.html#a13">QwtPicker::setCursorLabelPen</a>(<span class="keyword">const</span> QPen &amp;pen)
00348 {
00349     <span class="keywordflow">if</span> ( pen != d_cursorLabelPen )
00350     {
00351         <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_picker.html#a17">isEnabled</a>() )
00352             <a class="code" href="class_qwt_picker.html#b15">drawCursorLabel</a>(); <span class="comment">// erase</span>
00353 
00354         d_cursorLabelPen = pen;
00355 
00356         <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_picker.html#a17">isEnabled</a>() )
00357             <a class="code" href="class_qwt_picker.html#b15">drawCursorLabel</a>(); <span class="comment">// repaint</span>
00358     }
00359 }
00360 
<a name="l00365"></a><a class="code" href="class_qwt_picker.html#a14">00365</a> QPen <a class="code" href="class_qwt_picker.html#a14">QwtPicker::cursorLabelPen</a>()<span class="keyword"> const</span>
00366 <span class="keyword"></span>{
00367     <span class="keywordflow">return</span> d_cursorLabelPen;
00368 }
00369 
<a name="l00376"></a><a class="code" href="class_qwt_picker.html#a11">00376</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_picker.html#a11">QwtPicker::setRubberBandPen</a>(<span class="keyword">const</span> QPen &amp;pen)
00377 {
00378     <span class="keywordflow">if</span> ( pen != d_rubberBandPen )
00379     {
00380         <a class="code" href="class_qwt_picker.html#b13">drawRubberBand</a>(); <span class="comment">// erase</span>
00381         d_rubberBandPen = pen;
00382         <a class="code" href="class_qwt_picker.html#b13">drawRubberBand</a>(); <span class="comment">// repaint</span>
00383     }
00384 }
00385 
<a name="l00390"></a><a class="code" href="class_qwt_picker.html#a12">00390</a> QPen <a class="code" href="class_qwt_picker.html#a12">QwtPicker::rubberBandPen</a>()<span class="keyword"> const</span>
00391 <span class="keyword"></span>{
00392     <span class="keywordflow">return</span> d_rubberBandPen;
00393 }
00394 
<a name="l00408"></a><a class="code" href="class_qwt_picker.html#b18">00408</a> QString <a class="code" href="class_qwt_picker.html#b18">QwtPicker::cursorLabel</a>(<span class="keyword">const</span> QPoint &amp;pos)<span class="keyword"> const</span>
00409 <span class="keyword"></span>{
00410     QString label;
00411 
00412     <span class="keywordflow">switch</span>(<a class="code" href="class_qwt_picker.html#a6">rubberBand</a>())
00413     {
00414         <span class="keywordflow">case</span> HLineRubberBand:
00415             label.sprintf(<span class="stringliteral">"%d"</span>, pos.y());
00416             <span class="keywordflow">break</span>;
00417         <span class="keywordflow">case</span> VLineRubberBand:
00418             label.sprintf(<span class="stringliteral">"%d"</span>, pos.x());
00419             <span class="keywordflow">break</span>;
00420         <span class="keywordflow">default</span>:
00421             label.sprintf(<span class="stringliteral">"%d, %d"</span>, pos.x(), pos.y());
00422     }
00423     <span class="keywordflow">return</span> label;
00424 }
00425 
<a name="l00437"></a><a class="code" href="class_qwt_picker.html#b13">00437</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_picker.html#b13">QwtPicker::drawRubberBand</a>(<span class="keyword">const</span> QRect &amp;clipRect)<span class="keyword"> const</span>
00438 <span class="keyword"></span>{
00439     QWidget *widget = (QWidget *)<a class="code" href="class_qwt_picker.html#a21">parentWidget</a>();
00440     <span class="keywordflow">if</span> ( !widget || !<a class="code" href="class_qwt_picker.html#a19">isActive</a>() || <a class="code" href="class_qwt_picker.html#a6">rubberBand</a>() == NoRubberBand || 
00441         <a class="code" href="class_qwt_picker.html#a12">rubberBandPen</a>().style() == Qt::NoPen )
00442     {
00443         <span class="keywordflow">return</span>;
00444     }
00445 
00446     <span class="keyword">const</span> QColor bg = widget-&gt;backgroundColor();
00447 
00448     QPainter painter(widget);
00449     painter.setClipRect(clipRect.isValid() ? clipRect : <a class="code" href="class_qwt_picker.html#a23">pickRect</a>());
00450     painter.setClipping(TRUE);
00451     painter.setRasterOp(XorROP);
00452 
00453     QPen pen = d_rubberBandPen;
00454     pen.setColor(QColor(bg.rgb() ^ pen.color().rgb()));
00455     painter.setPen(pen);
00456 
00457     <a class="code" href="class_qwt_picker.html#b13">drawRubberBand</a>(&amp;painter, <a class="code" href="class_qwt_picker.html#a23">pickRect</a>(), d_selection);
00458 }
00459 
<a name="l00472"></a><a class="code" href="class_qwt_picker.html#b14">00472</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_picker.html#b13">QwtPicker::drawRubberBand</a>(QPainter *painter,
00473     <span class="keyword">const</span> QRect &amp;pickRect, <span class="keyword">const</span> QPointArray &amp;pa)<span class="keyword"> const</span>
00474 <span class="keyword"></span>{
00475     <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_picker.html#a6">rubberBand</a>() == NoRubberBand )
00476         <span class="keywordflow">return</span>;
00477 
00478     <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_picker.html#a4">selectionFlags</a>() &amp; PointSelection )
00479     {
00480         <span class="keywordflow">if</span> ( pa.count() &lt; 1 )
00481             <span class="keywordflow">return</span>;
00482 
00483         <span class="keyword">const</span> QPoint pos = pa[0];
00484 
00485         <span class="keywordflow">switch</span>(<a class="code" href="class_qwt_picker.html#a6">rubberBand</a>())
00486         {
00487             <span class="keywordflow">case</span> VLineRubberBand:
00488                 <a class="code" href="class_qwt_painter.html#e16">QwtPainter::drawLine</a>(painter, pos.x(),
00489                     pickRect.top(), pos.x(), pickRect.bottom());
00490                 <span class="keywordflow">break</span>;
00491 
00492             <span class="keywordflow">case</span> HLineRubberBand:
00493                 <a class="code" href="class_qwt_painter.html#e16">QwtPainter::drawLine</a>(painter, pickRect.left(), 
00494                     pos.y(), pickRect.right(), pos.y());
00495                 <span class="keywordflow">break</span>;
00496 
00497             <span class="keywordflow">case</span> CrossRubberBand:
00498                 <a class="code" href="class_qwt_painter.html#e16">QwtPainter::drawLine</a>(painter, pos.x(),
00499                     pickRect.top(), pos.x(), pickRect.bottom());
00500                 <a class="code" href="class_qwt_painter.html#e16">QwtPainter::drawLine</a>(painter, pickRect.left(), 
00501                     pos.y(), pickRect.right(), pos.y());
00502                 <span class="keywordflow">break</span>;
00503             <span class="keywordflow">default</span>:
00504                 <span class="keywordflow">break</span>;
00505         }
00506     }
00507 
00508     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_picker.html#a4">selectionFlags</a>() &amp; RectSelection )
00509     {
00510         <span class="keywordflow">if</span> ( pa.count() &lt; 2 )
00511             <span class="keywordflow">return</span>;
00512 
00513         QPoint p1 = pa[0];
00514         QPoint p2 = pa[int(pa.count() - 1)];
00515 
00516         <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_picker.html#a4">selectionFlags</a>() &amp; CenterToCorner )
00517         {
00518             p1.setX(p1.x() - (p2.x() - p1.x()));
00519             p1.setY(p1.y() - (p2.y() - p1.y()));
00520         }
00521         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_picker.html#a4">selectionFlags</a>() &amp; CenterToRadius )
00522         {
00523             <span class="keyword">const</span> <span class="keywordtype">int</span> radius = QMAX(QABS(p2.x() - p1.x()), 
00524                 QABS(p2.y() - p1.y()));
00525             p2.setX(p1.x() + radius);
00526             p2.setY(p1.y() + radius);
00527             p1.setX(p1.x() - radius);
00528             p1.setY(p1.y() - radius);
00529         }
00530 
00531         <span class="keyword">const</span> QRect rect = QRect(p1, p2).normalize();
00532         <span class="keywordflow">switch</span>(<a class="code" href="class_qwt_picker.html#a6">rubberBand</a>())
00533         {
00534             <span class="keywordflow">case</span> EllipseRubberBand:
00535                 <a class="code" href="class_qwt_painter.html#e15">QwtPainter::drawEllipse</a>(painter, rect);
00536                 <span class="keywordflow">break</span>;
00537 
00538             <span class="keywordflow">case</span> RectRubberBand:
00539             {
00540                 <span class="comment">// In case of height == 0 or width == 0 the</span>
00541                 <span class="comment">// 2 edges erase each other in XOR mode.</span>
00542 
00543                 <span class="keywordflow">if</span> ( rect.height() &lt;= 1 )
00544                 {
00545                     <a class="code" href="class_qwt_painter.html#e16">QwtPainter::drawLine</a>(painter, 
00546                         rect.topLeft(), rect.topRight());
00547                 }
00548                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( rect.width() &lt;= 1 )
00549                 {
00550                     <a class="code" href="class_qwt_painter.html#e16">QwtPainter::drawLine</a>(painter, 
00551                         rect.topLeft(), rect.bottomLeft());
00552                 }
00553                 <span class="keywordflow">else</span>
00554                     <a class="code" href="class_qwt_painter.html#e12">QwtPainter::drawRect</a>(painter, rect);
00555                 <span class="keywordflow">break</span>;
00556             }
00557             <span class="keywordflow">default</span>:
00558                 <span class="keywordflow">break</span>;
00559         }
00560     }
00561     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_picker.html#a4">selectionFlags</a>() &amp; PolygonSelection )
00562     {
00563         <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_picker.html#a6">rubberBand</a>() == PolygonRubberBand )
00564             painter-&gt;drawPolyline(pa);
00565     }
00566 }
00567 
<a name="l00580"></a><a class="code" href="class_qwt_picker.html#b15">00580</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_picker.html#b15">QwtPicker::drawCursorLabel</a>(<span class="keyword">const</span> QRect &amp;clipRect)<span class="keyword"> const</span>
00581 <span class="keyword"></span>{
00582     QWidget *widget = (QWidget *)<a class="code" href="class_qwt_picker.html#a21">QwtPicker::parentWidget</a>();
00583     <span class="keywordflow">if</span> ( !widget )
00584         <span class="keywordflow">return</span>;
00585 
00586     <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_picker.html#a8">cursorLabelMode</a>() == AlwaysOff || 
00587         (<a class="code" href="class_qwt_picker.html#a8">cursorLabelMode</a>() == ActiveOnly &amp;&amp; !<a class="code" href="class_qwt_picker.html#a19">isActive</a>() ) )
00588     {
00589         <span class="keywordflow">return</span>;
00590     }
00591 
00592     <span class="keywordflow">if</span> ( d_labelPosition.x() &lt; 0 || d_labelPosition.y() &lt; 0 )
00593         <span class="keywordflow">return</span>;
00594 
00595     <span class="keyword">const</span> QColor bg = widget-&gt;backgroundColor();
00596 
00597     QPainter painter(widget);
00598     painter.setClipRect(clipRect.isValid() ? clipRect : <a class="code" href="class_qwt_picker.html#a23">pickRect</a>());
00599     painter.setClipping(TRUE);
00600     painter.setRasterOp(XorROP);
00601 
00602     QPen pen = d_cursorLabelPen;
00603     pen.setColor(QColor((bg.rgb() ^ pen.color().rgb())));
00604 
00605     painter.setPen(pen);
00606     painter.setFont(d_cursorLabelFont);
00607 
00608     <a class="code" href="class_qwt_picker.html#b15">drawCursorLabel</a>(&amp;painter, <a class="code" href="class_qwt_picker.html#a23">pickRect</a>(), d_labelPosition, d_selection);
00609 }
00610 
<a name="l00627"></a><a class="code" href="class_qwt_picker.html#b16">00627</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_picker.html#b15">QwtPicker::drawCursorLabel</a>(QPainter *painter, <span class="keyword">const</span> QRect &amp;pickRect,
00628         <span class="keyword">const</span> QPoint &amp;pos, <span class="keyword">const</span> QPointArray &amp;pa)<span class="keyword"> const</span>
00629 <span class="keyword"></span>{
00630     <span class="keywordtype">int</span> alignment = 0;
00631     <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_picker.html#a19">isActive</a>() &amp;&amp; pa.count() &gt; 1 &amp;&amp; <a class="code" href="class_qwt_picker.html#a6">rubberBand</a>() != NoRubberBand )
00632     {
00633         <span class="keyword">const</span> QPoint last = pa[int(pa.count()) - 2];
00634 
00635         alignment |= (pos.x() &gt;= last.x()) ? Qt::AlignRight : Qt::AlignLeft;
00636         alignment |= (pos.y() &gt; last.y()) ? Qt::AlignBottom : Qt::AlignTop;
00637     }
00638     <span class="keywordflow">else</span>
00639         alignment = Qt::AlignTop | Qt::AlignRight;
00640 
00641     QString label = <a class="code" href="class_qwt_picker.html#b18">cursorLabel</a>(pos);
00642     <span class="keywordflow">if</span> ( !label.isEmpty() )
00643     {
00644         <a class="code" href="class_qwt_text.html">QwtText</a> *text = <a class="code" href="class_qwt_text.html#e0">QwtText::makeText</a>(label, 0, painter-&gt;font(),
00645             painter-&gt;pen().color());
00646 
00647         QRect textRect = text-&gt;<a class="code" href="class_qwt_text.html#a17">boundingRect</a>(painter);
00648 
00649         <span class="keyword">const</span> <span class="keywordtype">int</span> margin = 5;
00650 
00651         <span class="keywordtype">int</span> x = pos.x();
00652         <span class="keywordflow">if</span> ( alignment &amp; Qt::AlignLeft )
00653             x -= textRect.width() + margin;
00654         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( alignment &amp; Qt::AlignRight )
00655             x += margin;
00656 
00657         <span class="keywordtype">int</span> y = pos.y();
00658         <span class="keywordflow">if</span> ( alignment &amp; Qt::AlignBottom )
00659             y += margin;
00660         <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( alignment &amp; Qt::AlignTop )
00661             y -= textRect.height() + margin;
00662         
00663         textRect.moveTopLeft(QPoint(x, y));
00664 
00665         <span class="keywordtype">int</span> right = QMIN(textRect.right(), pickRect.right() - margin);
00666         <span class="keywordtype">int</span> bottom = QMIN(textRect.bottom(), pickRect.bottom() - margin);
00667         textRect.moveBottomRight(QPoint(right, bottom));
00668 
00669         <span class="keywordtype">int</span> left = QMAX(textRect.left(), pickRect.left() + margin);
00670         <span class="keywordtype">int</span> top = QMAX(textRect.top(), pickRect.top() + margin);
00671         textRect.moveTopLeft(QPoint(left, top));
00672 
00673         text-&gt;<a class="code" href="class_qwt_text.html#a18">draw</a>(painter, textRect);
00674 
00675         <span class="keyword">delete</span> text;
00676     }
00677 }
00678 
<a name="l00687"></a><a class="code" href="class_qwt_picker.html#b20">00687</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_picker.html#b20">QwtPicker::repaint</a>(<span class="keyword">const</span> QRect &amp;rect)
00688 {
00689     QApplication::postEvent(<span class="keyword">this</span>, <span class="keyword">new</span> QPaintEvent(rect));
00690 }
00691 
<a name="l00702"></a><a class="code" href="class_qwt_picker.html#a25">00702</a> <span class="keywordtype">bool</span> <a class="code" href="class_qwt_picker.html#a25">QwtPicker::event</a>(QEvent *e)
00703 {
00704     <span class="keywordflow">if</span> ( e-&gt;type() == QEvent::Paint )
00705     {
00706         <span class="keyword">const</span> QRect clipRect = ((<span class="keyword">const</span> QPaintEvent *)e)-&gt;rect();
00707 
00708         <a class="code" href="class_qwt_picker.html#b13">drawRubberBand</a>(clipRect);
00709         <a class="code" href="class_qwt_picker.html#b15">drawCursorLabel</a>(clipRect);
00710         <span class="keywordflow">return</span> TRUE;
00711     }
00712 
00713     <span class="keywordflow">return</span> QObject::event(e);
00714 }
00715 
<a name="l00728"></a><a class="code" href="class_qwt_picker.html#a20">00728</a> <span class="keywordtype">bool</span> <a class="code" href="class_qwt_picker.html#a20">QwtPicker::eventFilter</a>(QObject *o, QEvent *e)
00729 {
00730     <span class="comment">/*</span>
00731 <span class="comment">      Because of the XorROP mode the delayed paint has to</span>
00732 <span class="comment">      be completed to have a stable state for processing other</span>
00733 <span class="comment">      events. Unfortunately the internally posted paint event</span>
00734 <span class="comment">      might be too late in event queue. So we process it first.</span>
00735 <span class="comment">     */</span>
00736 
00737     QApplication::sendPostedEvents(<span class="keyword">this</span>, QEvent::Paint);
00738 
00739     <span class="keywordflow">if</span> ( o &amp;&amp; o == <a class="code" href="class_qwt_picker.html#a21">parentWidget</a>() )
00740     {
00741         <span class="keywordflow">switch</span>(e-&gt;type())
00742         {
00743             <span class="keywordflow">case</span> QEvent::Paint:
00744             {
00745                 <span class="comment">// We have to wait until the widget is updated</span>
00746                 <span class="comment">// before we can repaint cursor label and</span>
00747                 <span class="comment">// rubberband. So we post an event to delay the repaint.</span>
00748 
00749                 <span class="keyword">const</span> QPaintEvent *re = (QPaintEvent *)e;
00750                 <a class="code" href="class_qwt_picker.html#b20">repaint</a>(re-&gt;rect());
00751                 <span class="keywordflow">break</span>;
00752             }
00753             <span class="keywordflow">case</span> QEvent::Resize:
00754             {
00755                 <span class="keywordflow">if</span> ( d_resizeMode == Stretch )
00756                 {
00757                     <span class="comment">// erase</span>
00758                     <a class="code" href="class_qwt_picker.html#b13">drawRubberBand</a>();
00759                     <a class="code" href="class_qwt_picker.html#b15">drawCursorLabel</a>();
00760 
00761                     <span class="keyword">const</span> QResizeEvent *re = (QResizeEvent *)e;
00762                     <a class="code" href="class_qwt_picker.html#b17">stretchSelection</a>(re-&gt;oldSize(), re-&gt;size());
00763 
00764                     <span class="comment">// repaint</span>
00765                     <a class="code" href="class_qwt_picker.html#b13">drawRubberBand</a>();
00766                     <a class="code" href="class_qwt_picker.html#b15">drawCursorLabel</a>(); 
00767                 }
00768                 <span class="keywordflow">break</span>;
00769             }
00770             <span class="keywordflow">case</span> QEvent::MouseButtonPress:
00771                 <a class="code" href="class_qwt_picker.html#b6">widgetMousePressEvent</a>((QMouseEvent *)e);
00772                 <span class="keywordflow">break</span>;
00773             <span class="keywordflow">case</span> QEvent::MouseButtonRelease:
00774                 <a class="code" href="class_qwt_picker.html#b7">widgetMouseReleaseEvent</a>((QMouseEvent *)e);
00775                 <span class="keywordflow">break</span>;
00776             <span class="keywordflow">case</span> QEvent::MouseButtonDblClick:
00777                 <a class="code" href="class_qwt_picker.html#b8">widgetMouseDoubleClickEvent</a>((QMouseEvent *)e);
00778                 <span class="keywordflow">break</span>;
00779             <span class="keywordflow">case</span> QEvent::MouseMove:
00780                 <a class="code" href="class_qwt_picker.html#b9">widgetMouseMoveEvent</a>((QMouseEvent *)e);
00781                 <span class="keywordflow">break</span>;
00782             <span class="keywordflow">case</span> QEvent::KeyPress:
00783                 <a class="code" href="class_qwt_picker.html#b11">widgetKeyPressEvent</a>((QKeyEvent *)e);
00784                 <span class="keywordflow">break</span>;
00785             <span class="keywordflow">case</span> QEvent::KeyRelease:
00786                 <a class="code" href="class_qwt_picker.html#b12">widgetKeyReleaseEvent</a>((QKeyEvent *)e);
00787                 <span class="keywordflow">break</span>;
00788             <span class="keywordflow">case</span> QEvent::Wheel:
00789                 <a class="code" href="class_qwt_picker.html#b10">widgetWheelEvent</a>((QWheelEvent *)e);
00790                 <span class="keywordflow">break</span>;
00791             <span class="keywordflow">default</span>:
00792                 <span class="keywordflow">break</span>;
00793         }
00794     }
00795     <span class="keywordflow">return</span> FALSE;
00796 }
00797 
<a name="l00808"></a><a class="code" href="class_qwt_picker.html#b6">00808</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_picker.html#b6">QwtPicker::widgetMousePressEvent</a>(QMouseEvent *e)
00809 {
00810     <a class="code" href="class_qwt_picker.html#b1">transition</a>(e);
00811 }
00812 
<a name="l00822"></a><a class="code" href="class_qwt_picker.html#b9">00822</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_picker.html#b9">QwtPicker::widgetMouseMoveEvent</a>(QMouseEvent *e)
00823 {
00824     <a class="code" href="class_qwt_picker.html#b15">drawCursorLabel</a>(); <span class="comment">// erase</span>
00825 
00826     <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_picker.html#a23">pickRect</a>().contains(e-&gt;pos()) )
00827     {
00828         d_labelPosition = e-&gt;pos();
00829         <a class="code" href="class_qwt_picker.html#b15">drawCursorLabel</a>(); <span class="comment">// Paint</span>
00830     }
00831     <span class="keywordflow">else</span>
00832         d_labelPosition = QPoint(-1, -1);
00833 
00834     <a class="code" href="class_qwt_picker.html#b1">transition</a>(e);
00835 }
00836 
<a name="l00847"></a><a class="code" href="class_qwt_picker.html#b7">00847</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_picker.html#b7">QwtPicker::widgetMouseReleaseEvent</a>(QMouseEvent *e)
00848 {
00849     <a class="code" href="class_qwt_picker.html#b1">transition</a>(e);
00850 }
00851 
<a name="l00861"></a><a class="code" href="class_qwt_picker.html#b8">00861</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_picker.html#b8">QwtPicker::widgetMouseDoubleClickEvent</a>(QMouseEvent *me)
00862 {
00863     <a class="code" href="class_qwt_picker.html#b1">transition</a>(me);
00864 }
00865     
00866 
<a name="l00876"></a><a class="code" href="class_qwt_picker.html#b10">00876</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_picker.html#b10">QwtPicker::widgetWheelEvent</a>(QWheelEvent *e)
00877 {
00878     <a class="code" href="class_qwt_picker.html#b15">drawCursorLabel</a>(); <span class="comment">// erase</span>
00879 
00880     <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_picker.html#a23">pickRect</a>().contains(e-&gt;pos()) )
00881     {
00882         d_labelPosition = e-&gt;pos();
00883         <a class="code" href="class_qwt_picker.html#b15">drawCursorLabel</a>(); <span class="comment">// Paint</span>
00884     }
00885     <span class="keywordflow">else</span>
00886         d_labelPosition = QPoint(-1, -1);
00887 
00888     <a class="code" href="class_qwt_picker.html#b1">transition</a>(e);
00889 }
00890 
<a name="l00904"></a><a class="code" href="class_qwt_picker.html#b11">00904</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_picker.html#b11">QwtPicker::widgetKeyPressEvent</a>(QKeyEvent *ke)
00905 {
00906     <span class="keywordtype">int</span> dx = 0;
00907     <span class="keywordtype">int</span> dy = 0;
00908 
00909     <span class="keywordtype">int</span> offset = 1;
00910     <span class="keywordflow">if</span> ( ke-&gt;isAutoRepeat() )
00911         offset = 5;
00912 
00913     <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_event_pattern.html#a13">keyMatch</a>(KeyLeft, ke) )
00914         dx = -offset;
00915     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_event_pattern.html#a13">keyMatch</a>(KeyRight, ke) )
00916         dx = offset;
00917     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_event_pattern.html#a13">keyMatch</a>(KeyUp, ke) )
00918         dy = -offset;
00919     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_event_pattern.html#a13">keyMatch</a>(KeyDown, ke) )
00920         dy = offset;
00921     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_event_pattern.html#a13">keyMatch</a>(KeyAbort, ke) )
00922     {
00923         <span class="keywordflow">if</span> ( d_stateMachine )
00924             d_stateMachine-&gt;<a class="code" href="class_qwt_picker_machine.html#a2">reset</a>();
00925 
00926         <span class="keywordflow">if</span> (<a class="code" href="class_qwt_picker.html#a19">isActive</a>())
00927             <a class="code" href="class_qwt_picker.html#b5">end</a>(FALSE);
00928     }
00929     <span class="keywordflow">else</span>
00930         <a class="code" href="class_qwt_picker.html#b1">transition</a>(ke);
00931 
00932     <span class="keywordflow">if</span> ( dx != 0 || dy != 0 )
00933     {
00934         <span class="keyword">const</span> QRect rect = <a class="code" href="class_qwt_picker.html#a23">pickRect</a>();
00935         <span class="keyword">const</span> QPoint pos = <a class="code" href="class_qwt_picker.html#a21">parentWidget</a>()-&gt;mapFromGlobal(QCursor::pos());
00936 
00937         <span class="keywordtype">int</span> x = pos.x() + dx;
00938         x = QMAX(rect.left(), x);
00939         x = QMIN(rect.right(), x);
00940 
00941         <span class="keywordtype">int</span> y = pos.y() + dy;
00942         y = QMAX(rect.top(), y);
00943         y = QMIN(rect.bottom(), y);
00944 
00945         QCursor::setPos(<a class="code" href="class_qwt_picker.html#a21">parentWidget</a>()-&gt;mapToGlobal(QPoint(x, y)));
00946     }
00947 }
00948  
<a name="l00958"></a><a class="code" href="class_qwt_picker.html#b12">00958</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_picker.html#b12">QwtPicker::widgetKeyReleaseEvent</a>(QKeyEvent *ke)
00959 {
00960     <a class="code" href="class_qwt_picker.html#b1">transition</a>(ke);
00961 }
00962 
<a name="l00970"></a><a class="code" href="class_qwt_picker.html#b1">00970</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_picker.html#b1">QwtPicker::transition</a>(<span class="keyword">const</span> QEvent *e)
00971 {
00972     <span class="keywordflow">if</span> ( !d_stateMachine )
00973         <span class="keywordflow">return</span>;
00974 
00975     QValueList&lt;QwtPickerMachine::Command&gt; commandList =
00976         d_stateMachine-&gt;<a class="code" href="class_qwt_picker_machine.html#a1">transition</a>(*<span class="keyword">this</span>, e);
00977 
00978     <span class="keyword">const</span> QPoint pos = <a class="code" href="class_qwt_picker.html#a21">parentWidget</a>()-&gt;mapFromGlobal(QCursor::pos());
00979 
00980     <span class="keywordflow">for</span> ( uint i = 0; i &lt; commandList.count(); i++ )
00981     {
00982         <span class="keywordflow">switch</span>(commandList[i])
00983         {
00984             <span class="keywordflow">case</span> QwtPickerMachine::Begin:
00985             {
00986                 <a class="code" href="class_qwt_picker.html#b2">begin</a>();
00987                 <span class="keywordflow">break</span>;
00988             }
00989             <span class="keywordflow">case</span> QwtPickerMachine::Append:
00990             {
00991                 <a class="code" href="class_qwt_picker.html#b3">append</a>(pos);
00992                 <span class="keywordflow">break</span>;
00993             }
00994             <span class="keywordflow">case</span> QwtPickerMachine::Move:
00995             {
00996                 <a class="code" href="class_qwt_picker.html#b4">move</a>(pos);
00997                 <span class="keywordflow">break</span>;
00998             }
00999             <span class="keywordflow">case</span> QwtPickerMachine::End:
01000             {
01001                 <a class="code" href="class_qwt_picker.html#b5">end</a>();
01002                 <span class="keywordflow">break</span>;
01003             }
01004         }
01005     }
01006 }
01007 
<a name="l01013"></a><a class="code" href="class_qwt_picker.html#b2">01013</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_picker.html#b2">QwtPicker::begin</a>()
01014 {
01015     <a class="code" href="class_qwt_picker.html#b15">drawCursorLabel</a>(); <span class="comment">// erase</span>
01016 
01017     d_selection.resize(0);
01018     d_isActive = TRUE;
01019 
01020     <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_picker.html#a8">cursorLabelMode</a>() != AlwaysOff )
01021     {
01022         <span class="keywordflow">if</span> ( d_labelPosition.x() &lt; 0 || d_labelPosition.y() &lt; 0 ) 
01023         {
01024             QWidget *w = <a class="code" href="class_qwt_picker.html#a21">parentWidget</a>();
01025             <span class="keywordflow">if</span> ( w )
01026                 d_labelPosition = w-&gt;mapFromGlobal(QCursor::pos());
01027         }
01028     }
01029 
01030     <a class="code" href="class_qwt_picker.html#b15">drawCursorLabel</a>(); <span class="comment">// repaint</span>
01031     setMouseTracking(TRUE);
01032 }
01033 
<a name="l01044"></a><a class="code" href="class_qwt_picker.html#b5">01044</a> <span class="keywordtype">bool</span> <a class="code" href="class_qwt_picker.html#b5">QwtPicker::end</a>(<span class="keywordtype">bool</span> ok)
01045 {
01046     <span class="keywordflow">if</span> ( d_isActive )
01047     {
01048         setMouseTracking(FALSE);
01049 
01050         <a class="code" href="class_qwt_picker.html#b15">drawCursorLabel</a>(); <span class="comment">// erase</span>
01051         <a class="code" href="class_qwt_picker.html#b13">drawRubberBand</a>(); <span class="comment">// erase</span>
01052 
01053         d_isActive = FALSE;
01054 
01055         <a class="code" href="class_qwt_picker.html#b15">drawCursorLabel</a>(); <span class="comment">// repaint</span>
01056 
01057         <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_picker.html#a8">cursorLabelMode</a>() == ActiveOnly )
01058             d_labelPosition = QPoint(-1, -1);
01059 
01060         <span class="keywordflow">if</span> ( ok )
01061             ok = <a class="code" href="class_qwt_picker.html#b0">accept</a>(d_selection);
01062 
01063         <span class="keywordflow">if</span> ( ok )
01064             emit <a class="code" href="class_qwt_picker.html#l0">selected</a>(d_selection);
01065         <span class="keywordflow">else</span>
01066             d_selection.resize(0);
01067     }
01068     <span class="keywordflow">else</span>
01069         ok = FALSE;
01070 
01071     <span class="keywordflow">return</span> ok;
01072 }
01073 
<a name="l01082"></a><a class="code" href="class_qwt_picker.html#b3">01082</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_picker.html#b3">QwtPicker::append</a>(<span class="keyword">const</span> QPoint &amp;pos)
01083 {
01084     <span class="keywordflow">if</span> ( d_isActive )
01085     {
01086         <a class="code" href="class_qwt_picker.html#b13">drawRubberBand</a>(); <span class="comment">// erase</span>
01087         <a class="code" href="class_qwt_picker.html#b15">drawCursorLabel</a>(); <span class="comment">// erase</span>
01088 
01089         <span class="keyword">const</span> <span class="keywordtype">int</span> idx = d_selection.count();
01090         d_selection.resize(idx + 1);
01091         d_selection[idx] = pos;
01092 
01093         <a class="code" href="class_qwt_picker.html#b13">drawRubberBand</a>(); <span class="comment">// repaint</span>
01094         <a class="code" href="class_qwt_picker.html#b15">drawCursorLabel</a>(); <span class="comment">// repaint</span>
01095 
01096         emit <a class="code" href="class_qwt_picker.html#l1">appended</a>(pos);
01097     }
01098 }
01099 
<a name="l01108"></a><a class="code" href="class_qwt_picker.html#b4">01108</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_picker.html#b4">QwtPicker::move</a>(<span class="keyword">const</span> QPoint &amp;pos)
01109 {
01110     <span class="keywordflow">if</span> ( d_isActive )
01111     {
01112         <span class="keyword">const</span> <span class="keywordtype">int</span> idx = d_selection.count() - 1;
01113         <span class="keywordflow">if</span> ( idx &gt;= 0 )
01114         {
01115             <a class="code" href="class_qwt_picker.html#b13">drawRubberBand</a>(); <span class="comment">// erase</span>
01116             d_selection[idx] = pos;
01117             <a class="code" href="class_qwt_picker.html#b13">drawRubberBand</a>(); <span class="comment">// repaint</span>
01118 
01119             emit <a class="code" href="class_qwt_picker.html#l2">moved</a>(pos);
01120         }
01121     }
01122 }
01123 
<a name="l01124"></a><a class="code" href="class_qwt_picker.html#b0">01124</a> <span class="keywordtype">bool</span> <a class="code" href="class_qwt_picker.html#b0">QwtPicker::accept</a>(QPointArray &amp;)<span class="keyword"> const</span>
01125 <span class="keyword"></span>{
01126     <span class="keywordflow">return</span> TRUE;
01127 }
01128 
<a name="l01133"></a><a class="code" href="class_qwt_picker.html#a19">01133</a> <span class="keywordtype">bool</span> <a class="code" href="class_qwt_picker.html#a19">QwtPicker::isActive</a>()<span class="keyword"> const </span>
01134 <span class="keyword"></span>{
01135     <span class="keywordflow">return</span> d_isActive;
01136 }
01137 
<a name="l01139"></a><a class="code" href="class_qwt_picker.html#a24">01139</a> <span class="keyword">const</span> QPointArray &amp;<a class="code" href="class_qwt_picker.html#a24">QwtPicker::selection</a>()<span class="keyword"> const</span>
01140 <span class="keyword"></span>{
01141     <span class="keywordflow">return</span> d_selection;
01142 }
01143 
<a name="l01153"></a><a class="code" href="class_qwt_picker.html#b17">01153</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_picker.html#b17">QwtPicker::stretchSelection</a>(<span class="keyword">const</span> QSize &amp;oldSize, <span class="keyword">const</span> QSize &amp;newSize)
01154 {
01155     <span class="keyword">const</span> <span class="keywordtype">double</span> xRatio =
01156         double(newSize.width()) / double(oldSize.width());
01157     <span class="keyword">const</span> <span class="keywordtype">double</span> yRatio =
01158         double(newSize.height()) / double(oldSize.height());
01159 
01160     <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i &lt; int(d_selection.count()); i++ )
01161     {
01162         QPoint &amp;p = d_selection[i];
01163         p.setX(qRound(p.x() * xRatio));
01164         p.setY(qRound(p.y() * yRatio));
01165 
01166         emit <a class="code" href="class_qwt_picker.html#l3">changed</a>(d_selection);
01167     }
01168 }
01169 
01183 <span class="keywordtype">void</span> QwtPicker::setMouseTracking(<span class="keywordtype">bool</span> enable)
01184 {
01185     QWidget *widget = <a class="code" href="class_qwt_picker.html#a21">parentWidget</a>();
01186     <span class="keywordflow">if</span> ( !widget )
01187         <span class="keywordflow">return</span>;
01188 
01189     <span class="keywordflow">if</span> ( enable )
01190     {
01191         d_mouseTracking = widget-&gt;hasMouseTracking();
01192         widget-&gt;setMouseTracking(TRUE);
01193     }
01194     <span class="keywordflow">else</span>
01195     {
01196         widget-&gt;setMouseTracking(d_mouseTracking);
01197     }
01198 }
01199 
<a name="l01205"></a><a class="code" href="class_qwt_picker.html#a23">01205</a> QRect <a class="code" href="class_qwt_picker.html#a23">QwtPicker::pickRect</a>()<span class="keyword"> const</span>
01206 <span class="keyword"></span>{
01207     QRect rect;
01208 
01209     <span class="keyword">const</span> QWidget *widget = <a class="code" href="class_qwt_picker.html#a21">parentWidget</a>();
01210     <span class="keywordflow">if</span> ( !widget )
01211         <span class="keywordflow">return</span> rect;
01212 
01213     <span class="keywordflow">if</span> ( widget-&gt;inherits(<span class="stringliteral">"QFrame"</span>) )
01214         rect = ((QFrame *)widget)-&gt;contentsRect();
01215     <span class="keywordflow">else</span>
01216         rect = widget-&gt;rect();
01217 
01218     <span class="keywordflow">return</span> rect;
01219 }
01220 
01221 <span class="comment">// Local Variables:</span>
01222 <span class="comment">// mode: C++</span>
01223 <span class="comment">// c-file-style: "stroustrup"</span>
01224 <span class="comment">// indent-tabs-mode: nil</span>
01225 <span class="comment">// End:</span>
</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>