File: qwt__marker_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 (301 lines) | stat: -rw-r--r-- 20,487 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
<!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_marker.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_marker.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;qpainter.h&gt;</span>
00013 <span class="preprocessor">#include "qwt_painter.h"</span>
00014 <span class="preprocessor">#include "qwt_marker.h"</span>
00015 <span class="preprocessor">#include "<a class="code" href="qwt__math_8h.html">qwt_math.h</a>"</span>
00016 
00017 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">int</span> LabelDist = 2;
00018 
<a name="l00020"></a><a class="code" href="class_qwt_marker.html#a0">00020</a> <a class="code" href="class_qwt_marker.html#a0">QwtMarker::QwtMarker</a>()
00021 {
00022     <span class="comment">// QwtMarker.draw() assumes that d_label-&gt;alignment() == Qt::AlignCenter. </span>
00023     d_label = <a class="code" href="class_qwt_text.html#e0">QwtText::makeText</a>(QString::null, Qt::AlignCenter, QFont());
00024     d_align = Qt::AlignCenter;
00025     d_style = NoLine;
00026 }
00027 
<a name="l00029"></a><a class="code" href="class_qwt_marker.html#a1">00029</a> <a class="code" href="class_qwt_marker.html#a1">QwtMarker::~QwtMarker</a>()
00030 {
00031     <span class="keyword">delete</span> d_label;
00032 }
00033 
<a name="l00038"></a><a class="code" href="class_qwt_marker.html#a2">00038</a> <a class="code" href="class_qwt_marker.html#a0">QwtMarker::QwtMarker</a>(<span class="keyword">const</span> <a class="code" href="class_qwt_marker.html">QwtMarker</a> &amp;m)
00039 {
00040     d_label = m.<a class="code" href="class_qwt_marker.html#r0">d_label</a>-&gt;<a class="code" href="class_qwt_text.html#a19">clone</a>();
00041     d_align = m.<a class="code" href="class_qwt_marker.html#r1">d_align</a>;
00042     d_pen = m.<a class="code" href="class_qwt_marker.html#r2">d_pen</a>;
00043     d_sym = m.<a class="code" href="class_qwt_marker.html#r3">d_sym</a>;
00044     d_style = m.<a class="code" href="class_qwt_marker.html#r4">d_style</a>;
00045 }
00046 
<a name="l00051"></a><a class="code" href="class_qwt_marker.html#a3">00051</a> <a class="code" href="class_qwt_marker.html">QwtMarker</a>&amp; <a class="code" href="class_qwt_marker.html#a3">QwtMarker::operator=</a>(<span class="keyword">const</span> <a class="code" href="class_qwt_marker.html">QwtMarker</a> &amp;m)
00052 {
00053     <span class="keywordflow">if</span> (<span class="keyword">this</span> != &amp;m)
00054     {
00055         d_label = m.<a class="code" href="class_qwt_marker.html#r0">d_label</a>-&gt;<a class="code" href="class_qwt_text.html#a19">clone</a>();
00056         d_align = m.<a class="code" href="class_qwt_marker.html#r1">d_align</a>;
00057         d_pen = m.<a class="code" href="class_qwt_marker.html#r2">d_pen</a>;
00058         d_sym = m.<a class="code" href="class_qwt_marker.html#r3">d_sym</a>;
00059         d_style = m.<a class="code" href="class_qwt_marker.html#r4">d_style</a>;
00060     }
00061 
00062     <span class="keywordflow">return</span> *<span class="keyword">this</span>;
00063 }
00064 
<a name="l00072"></a><a class="code" href="class_qwt_marker.html#a21">00072</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_marker.html#a21">QwtMarker::draw</a>(QPainter *p, <span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y, <span class="keyword">const</span> QRect &amp;r)
00073 {
00074     <span class="comment">// QwtMarker.draw() assumes that d_label-&gt;alignment() == Qt::AlignCenter. </span>
00075 
00076     <span class="comment">// draw lines</span>
00077     <span class="keywordflow">if</span> (d_style != NoLine)
00078     {
00079         p-&gt;setPen(d_pen);
00080         <span class="keywordflow">if</span> ((d_style == HLine) || (d_style == Cross))
00081             <a class="code" href="class_qwt_painter.html#e16">QwtPainter::drawLine</a>(p, r.left(), y, r.right(), y);
00082         <span class="keywordflow">if</span> ((d_style == VLine)||(d_style == Cross))
00083             <a class="code" href="class_qwt_painter.html#e16">QwtPainter::drawLine</a>(p, x, r.top(), x, r.bottom());
00084     }
00085 
00086     <span class="comment">// draw symbol</span>
00087     QSize sSym(0, 0);
00088     <span class="keywordflow">if</span> (d_sym.<a class="code" href="class_qwt_symbol.html#a13">style</a>() != QwtSymbol::None)
00089     {
00090         sSym = d_sym.<a class="code" href="class_qwt_symbol.html#a12">size</a>();
00091         d_sym.<a class="code" href="class_qwt_symbol.html#a14">draw</a>(p, x, y);
00092     }
00093 
00094     <span class="comment">// draw label</span>
00095     <span class="keywordflow">if</span> (!d_label-&gt;<a class="code" href="class_qwt_text.html#a2">text</a>().isEmpty())
00096     {
00097         <span class="keywordtype">int</span> xlw = qwtMax(<span class="keywordtype">int</span>(d_pen.width()), 1);
00098         <span class="keywordtype">int</span> ylw = xlw;
00099         <span class="keywordtype">int</span> xlw1;
00100         <span class="keywordtype">int</span> ylw1;
00101 
00102         <span class="keyword">const</span> <span class="keywordtype">int</span> xLabelDist = 
00103             <a class="code" href="class_qwt_painter.html#e3">QwtPainter::metricsMap</a>().screenToLayoutX(LabelDist);
00104         <span class="keyword">const</span> <span class="keywordtype">int</span> yLabelDist = 
00105             <a class="code" href="class_qwt_painter.html#e3">QwtPainter::metricsMap</a>().screenToLayoutY(LabelDist);
00106 
00107         <span class="keywordflow">if</span> ((d_style == VLine) || (d_style == HLine))
00108         {
00109             xlw1 = (xlw + 1) / 2 + xLabelDist;
00110             xlw = xlw / 2 + xLabelDist;
00111             ylw1 = (ylw + 1) / 2 + yLabelDist;
00112             ylw = ylw / 2 + yLabelDist;
00113         }
00114         <span class="keywordflow">else</span> 
00115         {
00116             xlw1 = qwtMax((xlw + 1) / 2, (sSym.width() + 1) / 2) + xLabelDist;
00117             xlw = qwtMax(xlw / 2, (sSym.width() + 1) / 2) + xLabelDist;
00118             ylw1 = qwtMax((ylw + 1) / 2, (sSym.height() + 1) / 2) + yLabelDist;
00119             ylw = qwtMax(ylw / 2, (sSym. height() + 1) / 2) + yLabelDist;
00120         }
00121 
00122         <span class="comment">// tr is offset with respect to (0, 0) obeying the immutable flags </span>
00123         <span class="comment">// Qt::AlignCenter. Hence: </span>
00124         <span class="comment">// tr.x() == -tr.width()/2</span>
00125         <span class="comment">// tr.y() == -tr.height()/2</span>
00126         QRect tr = d_label-&gt;<a class="code" href="class_qwt_text.html#a17">boundingRect</a>(p);
00127 
00128         <span class="keywordtype">int</span> dx = x;
00129         <span class="keywordtype">int</span> dy = y;
00130 
00131         <span class="keywordflow">if</span> (d_style == VLine)
00132         {
00133             <span class="keywordflow">if</span> (d_align &amp; (<span class="keywordtype">int</span>) Qt::AlignTop)
00134                 dy = r.top() + yLabelDist - tr.y();
00135             <span class="keywordflow">else</span> <span class="keywordflow">if</span> (d_align &amp; (<span class="keywordtype">int</span>) Qt::AlignBottom)
00136                 dy = r.bottom() - yLabelDist + tr.y();
00137             <span class="keywordflow">else</span>
00138                 dy = r.top() + r.height() / 2;
00139         }
00140         <span class="keywordflow">else</span>
00141         {
00142             <span class="keywordflow">if</span> (d_align &amp; (<span class="keywordtype">int</span>) Qt::AlignTop)
00143                 dy += tr.y() - ylw1;
00144             <span class="keywordflow">else</span> <span class="keywordflow">if</span> (d_align &amp; (<span class="keywordtype">int</span>) Qt::AlignBottom)
00145                 dy -= tr.y() - ylw1;
00146         }
00147 
00148 
00149         <span class="keywordflow">if</span> (d_style == HLine)
00150         {
00151             <span class="keywordflow">if</span> (d_align &amp; (<span class="keywordtype">int</span>) Qt::AlignLeft)
00152                 dx = r.left() + xLabelDist - tr.x();
00153             <span class="keywordflow">else</span> <span class="keywordflow">if</span> (d_align &amp; (<span class="keywordtype">int</span>) Qt::AlignRight)
00154                 dx = r.right() - xLabelDist + tr.x();
00155             <span class="keywordflow">else</span>
00156                 dx = r.left() + r.width() / 2;
00157         }
00158         <span class="keywordflow">else</span>
00159         {
00160             <span class="keywordflow">if</span> (d_align &amp; (<span class="keywordtype">int</span>) Qt::AlignLeft)
00161                 dx += tr.x() - xlw1;
00162             <span class="keywordflow">else</span> <span class="keywordflow">if</span> (d_align &amp; (<span class="keywordtype">int</span>) Qt::AlignRight)
00163                 dx -= tr.x() - xlw1;
00164         }
00165 
00166         tr.moveBy(dx, dy);
00167         d_label-&gt;<a class="code" href="class_qwt_text.html#a18">draw</a>(p, tr);
00168     }
00169 }
00170 
<a name="l00176"></a><a class="code" href="class_qwt_marker.html#a19">00176</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_marker.html#a19">QwtMarker::setFont</a>(<span class="keyword">const</span> QFont &amp;f)
00177 {
00178     <span class="keywordflow">if</span> ( f == d_label-&gt;<a class="code" href="class_qwt_text.html#a6">font</a>() )
00179         <span class="keywordflow">return</span>;
00180     
00181     d_label-&gt;<a class="code" href="class_qwt_text.html#a5">setFont</a>(f);
00182     <a class="code" href="class_qwt_marker.html#b0">markerChanged</a>();
00183 }
00184 
<a name="l00189"></a><a class="code" href="class_qwt_marker.html#a20">00189</a> <span class="keyword">const</span> QFont <a class="code" href="class_qwt_marker.html#a20">QwtMarker::font</a>()<span class="keyword"> const </span>
00190 <span class="keyword"></span>{ 
00191     <span class="keywordflow">return</span> d_label-&gt;<a class="code" href="class_qwt_text.html#a6">font</a>(); 
00192 }
00193 
00194 
<a name="l00201"></a><a class="code" href="class_qwt_marker.html#a4">00201</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_marker.html#a4">QwtMarker::setLineStyle</a>(QwtMarker::LineStyle st)
00202 {
00203     <span class="keywordflow">if</span> ( st != d_style )
00204     {
00205         d_style = st;
00206         <a class="code" href="class_qwt_marker.html#b0">markerChanged</a>();
00207     }
00208 }
00209 
<a name="l00214"></a><a class="code" href="class_qwt_marker.html#a5">00214</a> <a class="code" href="class_qwt_marker.html#w4">QwtMarker::LineStyle</a> <a class="code" href="class_qwt_marker.html#a5">QwtMarker::lineStyle</a>()<span class="keyword"> const </span>
00215 <span class="keyword"></span>{ 
00216     <span class="keywordflow">return</span> d_style; 
00217 }
00218 
<a name="l00224"></a><a class="code" href="class_qwt_marker.html#a6">00224</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_marker.html#a6">QwtMarker::setSymbol</a>(<span class="keyword">const</span> <a class="code" href="class_qwt_symbol.html">QwtSymbol</a> &amp;s)
00225 {
00226     d_sym = s;
00227     <a class="code" href="class_qwt_marker.html#b0">markerChanged</a>();
00228 }
00229 
<a name="l00234"></a><a class="code" href="class_qwt_marker.html#a7">00234</a> <span class="keyword">const</span> <a class="code" href="class_qwt_symbol.html">QwtSymbol</a> &amp;<a class="code" href="class_qwt_marker.html#a7">QwtMarker::symbol</a>()<span class="keyword"> const </span>
00235 <span class="keyword"></span>{ 
00236     <span class="keywordflow">return</span> d_sym; 
00237 }
00238 
<a name="l00244"></a><a class="code" href="class_qwt_marker.html#a9">00244</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_marker.html#a9">QwtMarker::setLabelText</a>(<span class="keyword">const</span> QString &amp;text)
00245 {
00246     <a class="code" href="class_qwt_marker.html#a8">setLabel</a>(text, d_label-&gt;<a class="code" href="class_qwt_text.html#a6">font</a>(), d_label-&gt;<a class="code" href="class_qwt_text.html#a11">color</a>(), 
00247         d_label-&gt;<a class="code" href="class_qwt_text.html#a13">rectPen</a>(), d_label-&gt;<a class="code" href="class_qwt_text.html#a15">rectBrush</a>());
00248 }
00249 
<a name="l00259"></a><a class="code" href="class_qwt_marker.html#a8">00259</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_marker.html#a8">QwtMarker::setLabel</a>(<span class="keyword">const</span> QString &amp;text, <span class="keyword">const</span> QFont &amp;font,
00260     <span class="keyword">const</span> QColor &amp;color, <span class="keyword">const</span> QPen &amp;pen, <span class="keyword">const</span> QBrush &amp;brush)
00261 {
00262     <span class="keywordflow">if</span> ( text == d_label-&gt;<a class="code" href="class_qwt_text.html#a2">text</a>()
00263          &amp;&amp; font == d_label-&gt;<a class="code" href="class_qwt_text.html#a6">font</a>()
00264          &amp;&amp; color == d_label-&gt;<a class="code" href="class_qwt_text.html#a11">color</a>()
00265          &amp;&amp; pen == d_label-&gt;<a class="code" href="class_qwt_text.html#a13">rectPen</a>()
00266          &amp;&amp; brush == d_label-&gt;<a class="code" href="class_qwt_text.html#a15">rectBrush</a>() )
00267         <span class="keywordflow">return</span>;
00268     
00269     <a class="code" href="class_qwt_text.html">QwtText</a> *<a class="code" href="class_qwt_marker.html#a10">label</a> = <a class="code" href="class_qwt_text.html#e0">QwtText::makeText</a>(
00270         text, d_label-&gt;<a class="code" href="class_qwt_text.html#a9">alignment</a>(), font, color, pen, brush);
00271 
00272     <span class="keyword">delete</span> d_label;
00273     d_label = label;
00274 
00275     <a class="code" href="class_qwt_marker.html#b0">markerChanged</a>();
00276 }
00277 
<a name="l00282"></a><a class="code" href="class_qwt_marker.html#a10">00282</a> <span class="keyword">const</span> QString <a class="code" href="class_qwt_marker.html#a10">QwtMarker::label</a>()<span class="keyword"> const </span>
00283 <span class="keyword"></span>{ 
00284     <span class="keywordflow">return</span> d_label-&gt;<a class="code" href="class_qwt_text.html#a2">text</a>(); 
00285 }
00286 
<a name="l00298"></a><a class="code" href="class_qwt_marker.html#a11">00298</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_marker.html#a11">QwtMarker::setLabelAlignment</a>(<span class="keywordtype">int</span> align)
00299 {
00300     <span class="keywordflow">if</span> ( align == d_align )
00301         <span class="keywordflow">return</span>;
00302     
00303     d_align = align;
00304     <a class="code" href="class_qwt_marker.html#b0">markerChanged</a>();
00305 }
00306 
<a name="l00311"></a><a class="code" href="class_qwt_marker.html#a12">00311</a> <span class="keywordtype">int</span> <a class="code" href="class_qwt_marker.html#a12">QwtMarker::labelAlignment</a>()<span class="keyword"> const </span>
00312 <span class="keyword"></span>{ 
00313     <span class="keywordflow">return</span> d_align; 
00314 }
00315 
<a name="l00321"></a><a class="code" href="class_qwt_marker.html#a17">00321</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_marker.html#a17">QwtMarker::setLinePen</a>(<span class="keyword">const</span> QPen &amp;p)
00322 {
00323     <span class="keywordflow">if</span> ( p != d_pen )
00324     {
00325         d_pen = p;
00326         <a class="code" href="class_qwt_marker.html#b0">markerChanged</a>();
00327     }
00328 }
00329 
<a name="l00334"></a><a class="code" href="class_qwt_marker.html#a18">00334</a> <span class="keyword">const</span> QPen &amp;<a class="code" href="class_qwt_marker.html#a18">QwtMarker::linePen</a>()<span class="keyword"> const </span>
00335 <span class="keyword"></span>{ 
00336     <span class="keywordflow">return</span> d_pen; 
00337 }
00338 
<a name="l00344"></a><a class="code" href="class_qwt_marker.html#a13">00344</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_marker.html#a13">QwtMarker::setLabelColor</a>(<span class="keyword">const</span> QColor &amp;color)
00345 {
00346     <span class="keywordflow">if</span> ( color == d_label-&gt;<a class="code" href="class_qwt_text.html#a11">color</a>() )
00347         <span class="keywordflow">return</span>;
00348     
00349     d_label-&gt;<a class="code" href="class_qwt_text.html#a10">setColor</a>(color);
00350     <a class="code" href="class_qwt_marker.html#b0">markerChanged</a>();
00351 }
00352 
<a name="l00357"></a><a class="code" href="class_qwt_marker.html#a14">00357</a> <span class="keyword">const</span> QColor <a class="code" href="class_qwt_marker.html#a14">QwtMarker::labelColor</a>()<span class="keyword"> const </span>
00358 <span class="keyword"></span>{ 
00359     <span class="keywordflow">return</span> d_label-&gt;<a class="code" href="class_qwt_text.html#a11">color</a>(); 
00360 }
00361 
<a name="l00368"></a><a class="code" href="class_qwt_marker.html#a15">00368</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_marker.html#a15">QwtMarker::setLabelPen</a>(<span class="keyword">const</span> QPen &amp;p)
00369 {
00370     <span class="keywordflow">if</span> ( p == QPen(d_label-&gt;<a class="code" href="class_qwt_text.html#a11">color</a>()) )
00371         <span class="keywordflow">return</span>;
00372     
00373     d_label-&gt;<a class="code" href="class_qwt_text.html#a10">setColor</a>(p.color());
00374     <a class="code" href="class_qwt_marker.html#b0">markerChanged</a>();
00375 }
00376 
<a name="l00382"></a><a class="code" href="class_qwt_marker.html#a16">00382</a> <span class="keyword">const</span> QPen <a class="code" href="class_qwt_marker.html#a16">QwtMarker::labelPen</a>()<span class="keyword"> const </span>
00383 <span class="keyword"></span>{ 
00384     <span class="keywordflow">return</span> QPen(d_label-&gt;<a class="code" href="class_qwt_text.html#a11">color</a>()); 
00385 }
00386 
<a name="l00395"></a><a class="code" href="class_qwt_marker.html#b0">00395</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_marker.html#b0">QwtMarker::markerChanged</a>() 
00396 {
00397 }
00398 
00399 <span class="comment">// Local Variables:</span>
00400 <span class="comment">// mode: C++</span>
00401 <span class="comment">// c-file-style: "stroustrup"</span>
00402 <span class="comment">// indent-tabs-mode: nil</span>
00403 <span class="comment">// End:</span>
00404 
</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>