1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
3
<title>Qwt User's Guide: qwt_plot_print.cpp Source File</title>
4
<link href="doxygen.css" rel="stylesheet" type="text/css">
5
<link href="tabs.css" rel="stylesheet" type="text/css">
7
<!-- Generated by Doxygen 1.4.6 -->
10
<li><a href="index.html"><span>Main Page</span></a></li>
11
<li><a href="classes.html"><span>Classes</span></a></li>
12
<li id="current"><a href="files.html"><span>Files</span></a></li>
13
<li><a href="pages.html"><span>Related Pages</span></a></li>
15
<h1>qwt_plot_print.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************</span>
16
<a name="l00002"></a>00002 <span class="comment"> * Qwt Widget Library</span>
17
<a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 1997 Josef Wilgen</span>
18
<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002 Uwe Rathmann</span>
19
<a name="l00005"></a>00005 <span class="comment"> *</span>
20
<a name="l00006"></a>00006 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
21
<a name="l00007"></a>00007 <span class="comment"> * modify it under the terms of the Qwt License, Version 1.0</span>
22
<a name="l00008"></a>00008 <span class="comment"> *****************************************************************************/</span>
23
<a name="l00009"></a>00009
24
<a name="l00010"></a>00010 <span class="comment">// vim: expandtab</span>
25
<a name="l00011"></a>00011
26
<a name="l00012"></a>00012 <span class="preprocessor">#include <qpainter.h></span>
27
<a name="l00013"></a>00013 <span class="preprocessor">#if QT_VERSION < 0x040000</span>
28
<a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#include <qpaintdevicemetrics.h></span>
29
<a name="l00015"></a>00015 <span class="preprocessor">#else</span>
30
<a name="l00016"></a>00016 <span class="preprocessor"></span><span class="preprocessor">#include <qpaintengine.h></span>
31
<a name="l00017"></a>00017 <span class="preprocessor">#endif</span>
32
<a name="l00018"></a>00018 <span class="preprocessor"></span><span class="preprocessor">#include "qwt_painter.h"</span>
33
<a name="l00019"></a>00019 <span class="preprocessor">#include "qwt_legend_item.h"</span>
34
<a name="l00020"></a>00020 <span class="preprocessor">#include "qwt_plot.h"</span>
35
<a name="l00021"></a>00021 <span class="preprocessor">#include "qwt_plot_canvas.h"</span>
36
<a name="l00022"></a>00022 <span class="preprocessor">#include "qwt_plot_layout.h"</span>
37
<a name="l00023"></a>00023 <span class="preprocessor">#include "qwt_legend.h"</span>
38
<a name="l00024"></a>00024 <span class="preprocessor">#include "qwt_rect.h"</span>
39
<a name="l00025"></a>00025 <span class="preprocessor">#include "qwt_dyngrid_layout.h"</span>
40
<a name="l00026"></a>00026 <span class="preprocessor">#include "qwt_scale_widget.h"</span>
41
<a name="l00027"></a>00027 <span class="preprocessor">#include "qwt_scale_engine.h"</span>
42
<a name="l00028"></a>00028 <span class="preprocessor">#include "qwt_text.h"</span>
43
<a name="l00029"></a>00029 <span class="preprocessor">#include "qwt_text_label.h"</span>
44
<a name="l00030"></a>00030 <span class="preprocessor">#include "qwt_math.h"</span>
45
<a name="l00031"></a>00031
46
<a name="l00044"></a><a class="code" href="class_qwt_plot.html#db2f14174770601e55d6822437c3fe26">00044</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot.html#db2f14174770601e55d6822437c3fe26">QwtPlot::print</a>(QPaintDevice &paintDev,
47
<a name="l00045"></a>00045 <span class="keyword">const</span> <a class="code" href="class_qwt_plot_print_filter.html">QwtPlotPrintFilter</a> &pfilter)<span class="keyword"> const</span>
48
<a name="l00046"></a>00046 <span class="keyword"></span>{
49
<a name="l00047"></a>00047 <span class="preprocessor">#if QT_VERSION < 0x040000</span>
50
<a name="l00048"></a>00048 <span class="preprocessor"></span> QPaintDeviceMetrics mpr(&paintDev);
51
<a name="l00049"></a>00049 <span class="keywordtype">int</span> w = mpr.width();
52
<a name="l00050"></a>00050 <span class="keywordtype">int</span> h = mpr.height();
53
<a name="l00051"></a>00051 <span class="preprocessor">#else</span>
54
<a name="l00052"></a>00052 <span class="preprocessor"></span> <span class="keywordtype">int</span> w = paintDev.width();
55
<a name="l00053"></a>00053 <span class="keywordtype">int</span> h = paintDev.height();
56
<a name="l00054"></a>00054 <span class="preprocessor">#endif</span>
57
<a name="l00055"></a>00055 <span class="preprocessor"></span>
58
<a name="l00056"></a>00056 QRect rect(0, 0, w, h);
59
<a name="l00057"></a>00057 <span class="keywordtype">double</span> aspect = double(rect.width())/<span class="keywordtype">double</span>(rect.height());
60
<a name="l00058"></a>00058 <span class="keywordflow">if</span> ((aspect < 1.0))
61
<a name="l00059"></a>00059 rect.setHeight(<span class="keywordtype">int</span>(aspect*rect.width()));
62
<a name="l00060"></a>00060
63
<a name="l00061"></a>00061 QPainter p(&paintDev);
64
<a name="l00062"></a>00062 <a class="code" href="class_qwt_plot.html#db2f14174770601e55d6822437c3fe26">print</a>(&p, rect, pfilter);
65
<a name="l00063"></a>00063 }
66
<a name="l00064"></a>00064
67
<a name="l00074"></a><a class="code" href="class_qwt_plot.html#2170b35727d35c9b9f4031f490789adc">00074</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot.html#db2f14174770601e55d6822437c3fe26">QwtPlot::print</a>(QPainter *painter, <span class="keyword">const</span> QRect &plotRect,
68
<a name="l00075"></a>00075 <span class="keyword">const</span> <a class="code" href="class_qwt_plot_print_filter.html">QwtPlotPrintFilter</a> &pfilter)<span class="keyword"> const</span>
69
<a name="l00076"></a>00076 <span class="keyword"></span>{
70
<a name="l00077"></a>00077 <span class="keywordtype">int</span> axisId;
71
<a name="l00078"></a>00078
72
<a name="l00079"></a>00079 <span class="keywordflow">if</span> ( painter == 0 || !painter->isActive() ||
73
<a name="l00080"></a>00080 !plotRect.isValid() || size().isNull() )
74
<a name="l00081"></a>00081 <span class="keywordflow">return</span>;
75
<a name="l00082"></a>00082
76
<a name="l00083"></a>00083 painter->save();
77
<a name="l00084"></a>00084
78
<a name="l00085"></a>00085 <span class="comment">// All paint operations need to be scaled according to</span>
79
<a name="l00086"></a>00086 <span class="comment">// the paint device metrics. </span>
80
<a name="l00087"></a>00087
81
<a name="l00088"></a>00088 <a class="code" href="class_qwt_painter.html#952553514abb7ab83c4a43602c899777">QwtPainter::setMetricsMap</a>(<span class="keyword">this</span>, painter->device());
82
<a name="l00089"></a>00089 <span class="keyword">const</span> <a class="code" href="class_qwt_metrics_map.html">QwtMetricsMap</a> &metricsMap = <a class="code" href="class_qwt_painter.html#3de95bfc83c9beee537404b41749bad5">QwtPainter::metricsMap</a>();
83
<a name="l00090"></a>00090
84
<a name="l00091"></a>00091 <span class="comment">// It is almost impossible to integrate into the Qt layout</span>
85
<a name="l00092"></a>00092 <span class="comment">// framework, when using different fonts for printing</span>
86
<a name="l00093"></a>00093 <span class="comment">// and screen. To avoid writing different and Qt unconform</span>
87
<a name="l00094"></a>00094 <span class="comment">// layout engines we change the widget attributes, print and </span>
88
<a name="l00095"></a>00095 <span class="comment">// reset the widget attributes again. This way we produce a lot of</span>
89
<a name="l00096"></a>00096 <span class="comment">// useless layout events ...</span>
90
<a name="l00097"></a>00097
91
<a name="l00098"></a>00098 pfilter.<a class="code" href="class_qwt_plot_print_filter.html#b6ce402443e59a6f4fc68dc24cc6b2ad">apply</a>((<a class="code" href="class_qwt_plot.html">QwtPlot</a> *)<span class="keyword">this</span>);
92
<a name="l00099"></a>00099
93
<a name="l00100"></a>00100 <span class="keywordtype">int</span> baseLineDists[QwtPlot::axisCnt];
94
<a name="l00101"></a>00101 <span class="keywordflow">if</span> ( !(pfilter.<a class="code" href="class_qwt_plot_print_filter.html#0f47c339382f3292d3e71e0585a008e4">options</a>() & QwtPlotPrintFilter::PrintCanvasBackground) )
95
<a name="l00102"></a>00102 {
96
<a name="l00103"></a>00103 <span class="comment">// In case of no background we set the backbone of</span>
97
<a name="l00104"></a>00104 <span class="comment">// the scale on the frame of the canvas.</span>
98
<a name="l00105"></a>00105
99
<a name="l00106"></a>00106 <span class="keywordflow">for</span> (axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
100
<a name="l00107"></a>00107 {
101
<a name="l00108"></a>00108 <a class="code" href="class_qwt_scale_widget.html">QwtScaleWidget</a> *scaleWidget = (<a class="code" href="class_qwt_scale_widget.html">QwtScaleWidget</a> *)<a class="code" href="class_qwt_plot.html#6b495d9b17962be6e098026441a1f7b8">axisWidget</a>(axisId);
102
<a name="l00109"></a>00109 <span class="keywordflow">if</span> ( scaleWidget )
103
<a name="l00110"></a>00110 {
104
<a name="l00111"></a>00111 baseLineDists[axisId] = scaleWidget->margin();
105
<a name="l00112"></a>00112 scaleWidget->setMargin(0);
106
<a name="l00113"></a>00113 }
107
<a name="l00114"></a>00114 }
108
<a name="l00115"></a>00115 }
109
<a name="l00116"></a>00116 <span class="comment">// Calculate the layout for the print.</span>
110
<a name="l00117"></a>00117
111
<a name="l00118"></a>00118 <span class="keywordtype">int</span> layoutOptions = QwtPlotLayout::IgnoreScrollbars
112
<a name="l00119"></a>00119 | QwtPlotLayout::IgnoreFrames;
113
<a name="l00120"></a>00120 <span class="keywordflow">if</span> ( !(pfilter.options() & QwtPlotPrintFilter::PrintMargin) )
114
<a name="l00121"></a>00121 layoutOptions |= QwtPlotLayout::IgnoreMargin;
115
<a name="l00122"></a>00122 <span class="keywordflow">if</span> ( !(pfilter.options() & QwtPlotPrintFilter::PrintLegend) )
116
<a name="l00123"></a>00123 layoutOptions |= QwtPlotLayout::IgnoreLegend;
117
<a name="l00124"></a>00124
118
<a name="l00125"></a>00125 ((<a class="code" href="class_qwt_plot.html">QwtPlot</a> *)<span class="keyword">this</span>)->plotLayout()->activate(<span class="keyword">this</span>,
119
<a name="l00126"></a>00126 <a class="code" href="class_qwt_painter.html#3de95bfc83c9beee537404b41749bad5">QwtPainter::metricsMap</a>().deviceToLayout(plotRect),
120
<a name="l00127"></a>00127 layoutOptions);
121
<a name="l00128"></a>00128
122
<a name="l00129"></a>00129 <span class="keywordflow">if</span> ((pfilter.options() & QwtPlotPrintFilter::PrintTitle)
123
<a name="l00130"></a>00130 && (!titleLabel()->text().isEmpty()))
124
<a name="l00131"></a>00131 {
125
<a name="l00132"></a>00132 printTitle(painter, plotLayout()->titleRect());
126
<a name="l00133"></a>00133 }
127
<a name="l00134"></a>00134
128
<a name="l00135"></a>00135 <span class="keywordflow">if</span> ( (pfilter.options() & QwtPlotPrintFilter::PrintLegend)
129
<a name="l00136"></a>00136 && legend() && !legend()->isEmpty() )
130
<a name="l00137"></a>00137 {
131
<a name="l00138"></a>00138 printLegend(painter, plotLayout()->legendRect());
132
<a name="l00139"></a>00139 }
133
<a name="l00140"></a>00140
134
<a name="l00141"></a>00141 <span class="keywordflow">for</span> ( axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
135
<a name="l00142"></a>00142 {
136
<a name="l00143"></a>00143 <a class="code" href="class_qwt_scale_widget.html">QwtScaleWidget</a> *scaleWidget = (<a class="code" href="class_qwt_scale_widget.html">QwtScaleWidget</a> *)axisWidget(axisId);
137
<a name="l00144"></a>00144 <span class="keywordflow">if</span> (scaleWidget)
138
<a name="l00145"></a>00145 {
139
<a name="l00146"></a>00146 <span class="keywordtype">int</span> baseDist = scaleWidget->margin();
140
<a name="l00147"></a>00147
141
<a name="l00148"></a>00148 <span class="keywordtype">int</span> startDist, endDist;
142
<a name="l00149"></a>00149 scaleWidget->getBorderDistHint(startDist, endDist);
143
<a name="l00150"></a>00150
144
<a name="l00151"></a>00151 printScale(painter, axisId, startDist, endDist,
145
<a name="l00152"></a>00152 baseDist, plotLayout()->scaleRect(axisId));
146
<a name="l00153"></a>00153 }
147
<a name="l00154"></a>00154 }
148
<a name="l00155"></a>00155
149
<a name="l00156"></a>00156 <span class="keyword">const</span> QRect canvasRect = metricsMap.layoutToDevice(plotLayout()->canvasRect());
150
<a name="l00157"></a>00157
151
<a name="l00158"></a>00158 <span class="comment">// When using QwtPainter all sizes where computed in pixel</span>
152
<a name="l00159"></a>00159 <span class="comment">// coordinates and scaled by QwtPainter later. This limits</span>
153
<a name="l00160"></a>00160 <span class="comment">// the precision to screen resolution. A much better solution</span>
154
<a name="l00161"></a>00161 <span class="comment">// is to scale the maps and print in unlimited resolution.</span>
155
<a name="l00162"></a>00162
156
<a name="l00163"></a>00163 <a class="code" href="class_qwt_scale_map.html">QwtScaleMap</a> map[axisCnt];
157
<a name="l00164"></a>00164 <span class="keywordflow">for</span> (axisId = 0; axisId < axisCnt; axisId++)
158
<a name="l00165"></a>00165 {
159
<a name="l00166"></a>00166 map[axisId].setTransformation(axisScaleEngine(axisId)->transformation());
160
<a name="l00167"></a>00167
161
<a name="l00168"></a>00168 <span class="keyword">const</span> <a class="code" href="class_qwt_scale_div.html">QwtScaleDiv</a> &scaleDiv = *axisScaleDiv(axisId);
162
<a name="l00169"></a>00169 map[axisId].<a class="code" href="class_qwt_scale_map.html#aa33bc8e1aed7aa17d345053194e7094">setScaleInterval</a>(scaleDiv.<a class="code" href="class_qwt_scale_div.html#a3b6edf00144cdc0a59fbc91784faec3">lBound</a>(), scaleDiv.<a class="code" href="class_qwt_scale_div.html#94287d3de0b107e66beea42cfeb1caef">hBound</a>());
163
<a name="l00170"></a>00170
164
<a name="l00171"></a>00171 <span class="keywordtype">double</span> from, to;
165
<a name="l00172"></a>00172 <span class="keywordflow">if</span> ( axisEnabled(axisId) )
166
<a name="l00173"></a>00173 {
167
<a name="l00174"></a>00174 <span class="keyword">const</span> <span class="keywordtype">int</span> sDist = axisWidget(axisId)->startBorderDist();
168
<a name="l00175"></a>00175 <span class="keyword">const</span> <span class="keywordtype">int</span> eDist = axisWidget(axisId)->endBorderDist();
169
<a name="l00176"></a>00176 <span class="keyword">const</span> QRect &scaleRect = plotLayout()->scaleRect(axisId);
170
<a name="l00177"></a>00177
171
<a name="l00178"></a>00178 <span class="keywordflow">if</span> ( axisId == xTop || axisId == xBottom )
172
<a name="l00179"></a>00179 {
173
<a name="l00180"></a>00180 from = metricsMap.layoutToDeviceX(scaleRect.left() + sDist);
174
<a name="l00181"></a>00181 to = metricsMap.layoutToDeviceX(scaleRect.right() - eDist);
175
<a name="l00182"></a>00182 }
176
<a name="l00183"></a>00183 <span class="keywordflow">else</span>
177
<a name="l00184"></a>00184 {
178
<a name="l00185"></a>00185 from = metricsMap.layoutToDeviceY(scaleRect.bottom() - eDist);
179
<a name="l00186"></a>00186 to = metricsMap.layoutToDeviceY(scaleRect.top() + sDist);
180
<a name="l00187"></a>00187 }
181
<a name="l00188"></a>00188 }
182
<a name="l00189"></a>00189 <span class="keywordflow">else</span>
183
<a name="l00190"></a>00190 {
184
<a name="l00191"></a>00191 <span class="keyword">const</span> <span class="keywordtype">int</span> margin = plotLayout()->canvasMargin(axisId);
185
<a name="l00192"></a>00192
186
<a name="l00193"></a>00193 <span class="keyword">const</span> QRect &canvasRect = plotLayout()->canvasRect();
187
<a name="l00194"></a>00194 <span class="keywordflow">if</span> ( axisId == yLeft || axisId == yRight )
188
<a name="l00195"></a>00195 {
189
<a name="l00196"></a>00196 from = metricsMap.layoutToDeviceX(canvasRect.bottom() - margin);
190
<a name="l00197"></a>00197 to = metricsMap.layoutToDeviceX(canvasRect.top() + margin);
191
<a name="l00198"></a>00198 }
192
<a name="l00199"></a>00199 <span class="keywordflow">else</span>
193
<a name="l00200"></a>00200 {
194
<a name="l00201"></a>00201 from = metricsMap.layoutToDeviceY(canvasRect.left() + margin);
195
<a name="l00202"></a>00202 to = metricsMap.layoutToDeviceY(canvasRect.right() - margin);
196
<a name="l00203"></a>00203 }
197
<a name="l00204"></a>00204 }
198
<a name="l00205"></a>00205 map[axisId].<a class="code" href="class_qwt_scale_map.html#1679ba72903986ff546c4c197e4680c0">setPaintXInterval</a>(from, to);
199
<a name="l00206"></a>00206 }
200
<a name="l00207"></a>00207
201
<a name="l00208"></a>00208
202
<a name="l00209"></a>00209 <span class="comment">// The canvas maps are already scaled. </span>
203
<a name="l00210"></a>00210 <a class="code" href="class_qwt_painter.html#952553514abb7ab83c4a43602c899777">QwtPainter::setMetricsMap</a>(painter->device(), painter->device());
204
<a name="l00211"></a>00211
205
<a name="l00212"></a>00212 printCanvas(painter, canvasRect, map, pfilter);
206
<a name="l00213"></a>00213
207
<a name="l00214"></a>00214 <a class="code" href="class_qwt_painter.html#0a20214cff4c8edd4c3caa0ad3a2112f">QwtPainter::resetMetricsMap</a>();
208
<a name="l00215"></a>00215
209
<a name="l00216"></a>00216 ((<a class="code" href="class_qwt_plot.html">QwtPlot</a> *)<span class="keyword">this</span>)->plotLayout()->invalidate();
210
<a name="l00217"></a>00217
211
<a name="l00218"></a>00218 <span class="comment">// reset all widgets with their original attributes.</span>
212
<a name="l00219"></a>00219 <span class="keywordflow">if</span> ( !(pfilter.options() & QwtPlotPrintFilter::PrintCanvasBackground) )
213
<a name="l00220"></a>00220 {
214
<a name="l00221"></a>00221 <span class="comment">// restore the previous base line dists</span>
215
<a name="l00222"></a>00222
216
<a name="l00223"></a>00223 <span class="keywordflow">for</span> (axisId = 0; axisId < QwtPlot::axisCnt; axisId++ )
217
<a name="l00224"></a>00224 {
218
<a name="l00225"></a>00225 <a class="code" href="class_qwt_scale_widget.html">QwtScaleWidget</a> *scaleWidget = (<a class="code" href="class_qwt_scale_widget.html">QwtScaleWidget</a> *)axisWidget(axisId);
219
<a name="l00226"></a>00226 <span class="keywordflow">if</span> ( scaleWidget )
220
<a name="l00227"></a>00227 scaleWidget->setMargin(baseLineDists[axisId]);
221
<a name="l00228"></a>00228 }
222
<a name="l00229"></a>00229 }
223
<a name="l00230"></a>00230
224
<a name="l00231"></a>00231 pfilter.reset((<a class="code" href="class_qwt_plot.html">QwtPlot</a> *)<span class="keyword">this</span>);
225
<a name="l00232"></a>00232
226
<a name="l00233"></a>00233 painter->restore();
227
<a name="l00234"></a>00234 }
228
<a name="l00235"></a>00235
229
<a name="l00243"></a><a class="code" href="class_qwt_plot.html#5ec342f0b38eb646f3cc6da8457b234a">00243</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot.html#5ec342f0b38eb646f3cc6da8457b234a">QwtPlot::printTitle</a>(QPainter *painter, <span class="keyword">const</span> QRect &rect)<span class="keyword"> const</span>
230
<a name="l00244"></a>00244 <span class="keyword"></span>{
231
<a name="l00245"></a>00245 painter->setFont(<a class="code" href="class_qwt_plot.html#c39356b86ed70ebf256a8ae964910206">titleLabel</a>()->font());
232
<a name="l00246"></a>00246
233
<a name="l00247"></a>00247 <span class="keyword">const</span> QColor color =
234
<a name="l00248"></a>00248 <span class="preprocessor">#if QT_VERSION < 0x040000</span>
235
<a name="l00249"></a>00249 <span class="preprocessor"></span> <a class="code" href="class_qwt_plot.html#c39356b86ed70ebf256a8ae964910206">titleLabel</a>()->palette().color(
236
<a name="l00250"></a>00250 QPalette::Active, QColorGroup::Text);
237
<a name="l00251"></a>00251 <span class="preprocessor">#else</span>
238
<a name="l00252"></a>00252 <span class="preprocessor"></span> <a class="code" href="class_qwt_plot.html#c39356b86ed70ebf256a8ae964910206">titleLabel</a>()->palette().color(
239
<a name="l00253"></a>00253 QPalette::Active, QPalette::Text);
240
<a name="l00254"></a>00254 <span class="preprocessor">#endif</span>
241
<a name="l00255"></a>00255 <span class="preprocessor"></span>
242
<a name="l00256"></a>00256 painter->setPen(color);
243
<a name="l00257"></a>00257 <a class="code" href="class_qwt_plot.html#c39356b86ed70ebf256a8ae964910206">titleLabel</a>()-><a class="code" href="class_qwt_text_label.html#6ff4f9a87e11594740f312c8522f933e">text</a>().<a class="code" href="class_qwt_text.html#3907eb112ff2259adbaad4c433178354">draw</a>(painter, rect);
244
<a name="l00258"></a>00258 }
245
<a name="l00259"></a>00259
246
<a name="l00267"></a><a class="code" href="class_qwt_plot.html#e64c9c6f3a7a84c9a988c491bc73c71f">00267</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot.html#e64c9c6f3a7a84c9a988c491bc73c71f">QwtPlot::printLegend</a>(QPainter *painter, <span class="keyword">const</span> QRect &rect)<span class="keyword"> const</span>
247
<a name="l00268"></a>00268 <span class="keyword"></span>{
248
<a name="l00269"></a>00269 <span class="keywordflow">if</span> ( !<a class="code" href="class_qwt_plot.html#ab1f2cf0e567e09a4c4bce3181c03ba0">legend</a>() || <a class="code" href="class_qwt_plot.html#ab1f2cf0e567e09a4c4bce3181c03ba0">legend</a>()->isEmpty() )
249
<a name="l00270"></a>00270 <span class="keywordflow">return</span>;
250
<a name="l00271"></a>00271
251
<a name="l00272"></a>00272 QLayout *l = <a class="code" href="class_qwt_plot.html#ab1f2cf0e567e09a4c4bce3181c03ba0">legend</a>()-><a class="code" href="class_qwt_legend.html#a52edeceb553ae703516c984f34d7ab7">contentsWidget</a>()->layout();
252
<a name="l00273"></a>00273 <span class="keywordflow">if</span> ( l == 0 || !l->inherits(<span class="stringliteral">"QwtDynGridLayout"</span>) )
253
<a name="l00274"></a>00274 <span class="keywordflow">return</span>;
254
<a name="l00275"></a>00275
255
<a name="l00276"></a>00276 <a class="code" href="class_qwt_dyn_grid_layout.html">QwtDynGridLayout</a> *legendLayout = (<a class="code" href="class_qwt_dyn_grid_layout.html">QwtDynGridLayout</a> *)l;
256
<a name="l00277"></a>00277
257
<a name="l00278"></a>00278 uint numCols = legendLayout-><a class="code" href="class_qwt_dyn_grid_layout.html#df7cc1acc36b41086fb4815633473901">columnsForWidth</a>(rect.width());
258
<a name="l00279"></a>00279 <span class="preprocessor">#if QT_VERSION < 0x040000</span>
259
<a name="l00280"></a>00280 <span class="preprocessor"></span> QValueList<QRect> itemRects =
260
<a name="l00281"></a>00281 legendLayout-><a class="code" href="class_qwt_dyn_grid_layout.html#0fe5c2a70d1086036fac2487cc982341">layoutItems</a>(rect, numCols);
261
<a name="l00282"></a>00282 <span class="preprocessor">#else</span>
262
<a name="l00283"></a>00283 <span class="preprocessor"></span> QList<QRect> itemRects =
263
<a name="l00284"></a>00284 legendLayout-><a class="code" href="class_qwt_dyn_grid_layout.html#0fe5c2a70d1086036fac2487cc982341">layoutItems</a>(rect, numCols);
264
<a name="l00285"></a>00285 <span class="preprocessor">#endif</span>
265
<a name="l00286"></a>00286 <span class="preprocessor"></span>
266
<a name="l00287"></a>00287 <span class="keywordtype">int</span> index = 0;
267
<a name="l00288"></a>00288
268
<a name="l00289"></a>00289 <span class="preprocessor">#if QT_VERSION < 0x040000</span>
269
<a name="l00290"></a>00290 <span class="preprocessor"></span> QLayoutIterator layoutIterator = legendLayout->iterator();
270
<a name="l00291"></a>00291 <span class="keywordflow">for</span> ( QLayoutItem *item = layoutIterator.current();
271
<a name="l00292"></a>00292 item != 0; item = ++layoutIterator)
272
<a name="l00293"></a>00293 {
273
<a name="l00294"></a>00294 #<span class="keywordflow">else</span>
274
<a name="l00295"></a>00295 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < legendLayout-><a class="code" href="class_qwt_dyn_grid_layout.html#9a74593721ef1eba3d70275c36500ff6">count</a>(); i++ )
275
<a name="l00296"></a>00296 {
276
<a name="l00297"></a>00297 QLayoutItem *item = legendLayout-><a class="code" href="class_qwt_dyn_grid_layout.html#dbec8dc847c4159d0765c8f0dd80d148">itemAt</a>(i);
277
<a name="l00298"></a>00298 <span class="preprocessor">#endif</span>
278
<a name="l00299"></a>00299 <span class="preprocessor"></span> QWidget *w = item->widget();
279
<a name="l00300"></a>00300 <span class="keywordflow">if</span> ( w )
280
<a name="l00301"></a>00301 {
281
<a name="l00302"></a>00302 painter->save();
282
<a name="l00303"></a>00303 painter->setClipping(<span class="keyword">true</span>);
283
<a name="l00304"></a>00304 <a class="code" href="class_qwt_painter.html#7a3b7e59fd56236dd99c5b1772e1a768">QwtPainter::setClipRect</a>(painter, itemRects[index]);
284
<a name="l00305"></a>00305
285
<a name="l00306"></a>00306 <a class="code" href="class_qwt_plot.html#9d8ac6339a83158a0e78def13489d0ca">printLegendItem</a>(painter, w, itemRects[index]);
286
<a name="l00307"></a>00307
287
<a name="l00308"></a>00308 index++;
288
<a name="l00309"></a>00309 painter->restore();
289
<a name="l00310"></a>00310 }
290
<a name="l00311"></a>00311 }
291
<a name="l00312"></a>00312 }
292
<a name="l00313"></a>00313
293
<a name="l00322"></a><a class="code" href="class_qwt_plot.html#9d8ac6339a83158a0e78def13489d0ca">00322</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot.html#9d8ac6339a83158a0e78def13489d0ca">QwtPlot::printLegendItem</a>(QPainter *painter,
294
<a name="l00323"></a>00323 <span class="keyword">const</span> QWidget *w, <span class="keyword">const</span> QRect &rect)<span class="keyword"> const</span>
295
<a name="l00324"></a>00324 <span class="keyword"></span>{
296
<a name="l00325"></a>00325 <span class="keywordflow">if</span> ( w->inherits(<span class="stringliteral">"QwtLegendItem"</span>) )
297
<a name="l00326"></a>00326 {
298
<a name="l00327"></a>00327 <a class="code" href="class_qwt_legend_item.html">QwtLegendItem</a> *item = (<a class="code" href="class_qwt_legend_item.html">QwtLegendItem</a> *)w;
299
<a name="l00328"></a>00328
300
<a name="l00329"></a>00329 painter->setFont(item->font());
301
<a name="l00330"></a>00330 item->drawItem(painter, rect);
302
<a name="l00331"></a>00331 }
303
<a name="l00332"></a>00332 }
304
<a name="l00333"></a>00333
305
<a name="l00346"></a><a class="code" href="class_qwt_plot.html#cc8d22136018342a7f89a341e6fe8cd3">00346</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot.html#cc8d22136018342a7f89a341e6fe8cd3">QwtPlot::printScale</a>(QPainter *painter,
306
<a name="l00347"></a>00347 <span class="keywordtype">int</span> axisId, <span class="keywordtype">int</span> startDist, <span class="keywordtype">int</span> endDist, <span class="keywordtype">int</span> baseDist,
307
<a name="l00348"></a>00348 <span class="keyword">const</span> QRect &rect)<span class="keyword"> const</span>
308
<a name="l00349"></a>00349 <span class="keyword"></span>{
309
<a name="l00350"></a>00350 <span class="keywordflow">if</span> (!<a class="code" href="class_qwt_plot.html#ac5107a1ec8836b53f084a5b1bb8cc43">axisEnabled</a>(axisId))
310
<a name="l00351"></a>00351 <span class="keywordflow">return</span>;
311
<a name="l00352"></a>00352
312
<a name="l00353"></a>00353 <span class="keyword">const</span> <a class="code" href="class_qwt_scale_widget.html">QwtScaleWidget</a> *scaleWidget = <a class="code" href="class_qwt_plot.html#6b495d9b17962be6e098026441a1f7b8">axisWidget</a>(axisId);
313
<a name="l00354"></a>00354 <span class="keywordflow">if</span> ( scaleWidget-><a class="code" href="class_qwt_scale_widget.html#0572bc26f5b99654067b916001bce582">isColorBarEnabled</a>()
314
<a name="l00355"></a>00355 && scaleWidget-><a class="code" href="class_qwt_scale_widget.html#a5877851d15888977621bfe86b945984">colorBarWidth</a>() > 0)
315
<a name="l00356"></a>00356 {
316
<a name="l00357"></a>00357 <span class="keyword">const</span> <a class="code" href="class_qwt_metrics_map.html">QwtMetricsMap</a> map = <a class="code" href="class_qwt_painter.html#3de95bfc83c9beee537404b41749bad5">QwtPainter::metricsMap</a>();
317
<a name="l00358"></a>00358
318
<a name="l00359"></a>00359 <span class="keyword">const</span> QRect r = map.layoutToScreen(rect);
319
<a name="l00360"></a>00360 scaleWidget-><a class="code" href="class_qwt_scale_widget.html#44375609584a468c1d9dc2135f7d6127">drawColorBar</a>(painter, scaleWidget-><a class="code" href="class_qwt_scale_widget.html#4c82dfd348421f5a07088cd6663bdbf8">colorBarRect</a>(r));
320
<a name="l00361"></a>00361
321
<a name="l00362"></a>00362 <span class="keyword">const</span> <span class="keywordtype">int</span> off = scaleWidget-><a class="code" href="class_qwt_scale_widget.html#a5877851d15888977621bfe86b945984">colorBarWidth</a>() + scaleWidget-><a class="code" href="class_qwt_scale_widget.html#1bdb5b6fa77a4535087f1c672ee394ce">spacing</a>();
322
<a name="l00363"></a>00363 <span class="keywordflow">if</span> ( scaleWidget-><a class="code" href="class_qwt_scale_widget.html#d8603e84f851e5d91feb21beebf19896">scaleDraw</a>()-><a class="code" href="class_qwt_scale_draw.html#06bf10d73aa03c16394a85fa70a7a3b1">orientation</a>() == Qt::Horizontal )
323
<a name="l00364"></a>00364 baseDist += map.screenToLayoutY(off);
324
<a name="l00365"></a>00365 <span class="keywordflow">else</span>
325
<a name="l00366"></a>00366 baseDist += map.screenToLayoutX(off);
326
<a name="l00367"></a>00367 }
327
<a name="l00368"></a>00368
328
<a name="l00369"></a>00369 <a class="code" href="class_qwt_scale_draw.html#cd7ceeeac592ef08530788580b461c66">QwtScaleDraw::Alignment</a> align;
329
<a name="l00370"></a>00370 <span class="keywordtype">int</span> x, y, w;
330
<a name="l00371"></a>00371
331
<a name="l00372"></a>00372 <span class="keywordflow">switch</span>(axisId)
332
<a name="l00373"></a>00373 {
333
<a name="l00374"></a>00374 <span class="keywordflow">case</span> yLeft:
334
<a name="l00375"></a>00375 {
335
<a name="l00376"></a>00376 x = rect.right() - baseDist + 1;
336
<a name="l00377"></a>00377 y = rect.y() + startDist;
337
<a name="l00378"></a>00378 w = rect.height() - startDist - endDist;
338
<a name="l00379"></a>00379 align = QwtScaleDraw::LeftScale;
339
<a name="l00380"></a>00380 <span class="keywordflow">break</span>;
340
<a name="l00381"></a>00381 }
341
<a name="l00382"></a>00382 <span class="keywordflow">case</span> yRight:
342
<a name="l00383"></a>00383 {
343
<a name="l00384"></a>00384 x = rect.left() + baseDist;
344
<a name="l00385"></a>00385 y = rect.y() + startDist;
345
<a name="l00386"></a>00386 w = rect.height() - startDist - endDist;
346
<a name="l00387"></a>00387 align = QwtScaleDraw::RightScale;
347
<a name="l00388"></a>00388 <span class="keywordflow">break</span>;
348
<a name="l00389"></a>00389 }
349
<a name="l00390"></a>00390 <span class="keywordflow">case</span> xTop:
350
<a name="l00391"></a>00391 {
351
<a name="l00392"></a>00392 x = rect.left() + startDist;
352
<a name="l00393"></a>00393 y = rect.bottom() - baseDist + 1;
353
<a name="l00394"></a>00394 w = rect.width() - startDist - endDist;
354
<a name="l00395"></a>00395 align = QwtScaleDraw::TopScale;
355
<a name="l00396"></a>00396 <span class="keywordflow">break</span>;
356
<a name="l00397"></a>00397 }
357
<a name="l00398"></a>00398 <span class="keywordflow">case</span> xBottom:
358
<a name="l00399"></a>00399 {
359
<a name="l00400"></a>00400 x = rect.left() + startDist;
360
<a name="l00401"></a>00401 y = rect.top() + baseDist;
361
<a name="l00402"></a>00402 w = rect.width() - startDist - endDist;
362
<a name="l00403"></a>00403 align = QwtScaleDraw::BottomScale;
363
<a name="l00404"></a>00404 <span class="keywordflow">break</span>;
364
<a name="l00405"></a>00405 }
365
<a name="l00406"></a>00406 <span class="keywordflow">default</span>:
366
<a name="l00407"></a>00407 <span class="keywordflow">return</span>;
367
<a name="l00408"></a>00408 }
368
<a name="l00409"></a>00409
369
<a name="l00410"></a>00410 scaleWidget->drawTitle(painter, align, rect);
370
<a name="l00411"></a>00411
371
<a name="l00412"></a>00412 painter->save();
372
<a name="l00413"></a>00413 painter->setFont(scaleWidget->font());
373
<a name="l00414"></a>00414
374
<a name="l00415"></a>00415 QPen pen = painter->pen();
375
<a name="l00416"></a>00416 pen.setWidth(scaleWidget->penWidth());
376
<a name="l00417"></a>00417 painter->setPen(pen);
377
<a name="l00418"></a>00418
378
<a name="l00419"></a>00419 <a class="code" href="class_qwt_scale_draw.html">QwtScaleDraw</a> *sd = (<a class="code" href="class_qwt_scale_draw.html">QwtScaleDraw</a> *)scaleWidget->scaleDraw();
379
<a name="l00420"></a>00420 <span class="keyword">const</span> QPoint sdPos = sd-><a class="code" href="class_qwt_scale_draw.html#6fd3a7c12e05e6c22cc9580e17f954e3">pos</a>();
380
<a name="l00421"></a>00421 <span class="keyword">const</span> <span class="keywordtype">int</span> sdLength = sd-><a class="code" href="class_qwt_scale_draw.html#a982a552071ddfffed21e9bac4e796ef">length</a>();
381
<a name="l00422"></a>00422
382
<a name="l00423"></a>00423 sd-><a class="code" href="class_qwt_scale_draw.html#d301aed0c797c10f0104976d1a62ff69">move</a>(x, y);
383
<a name="l00424"></a>00424 sd-><a class="code" href="class_qwt_scale_draw.html#2094e09579671d0a8e4b14a636eba6ef">setLength</a>(w);
384
<a name="l00425"></a>00425
385
<a name="l00426"></a>00426 <span class="preprocessor">#if QT_VERSION < 0x040000</span>
386
<a name="l00427"></a>00427 <span class="preprocessor"></span> sd-><a class="code" href="class_qwt_abstract_scale_draw.html#ca3c3a7499112f52616d0ee8518fa5a6">draw</a>(painter, scaleWidget->palette().active());
387
<a name="l00428"></a>00428 <span class="preprocessor">#else</span>
388
<a name="l00429"></a>00429 <span class="preprocessor"></span> QPalette palette = scaleWidget->palette();
389
<a name="l00430"></a>00430 palette.setCurrentColorGroup(QPalette::Active);
390
<a name="l00431"></a>00431 sd-><a class="code" href="class_qwt_abstract_scale_draw.html#ca3c3a7499112f52616d0ee8518fa5a6">draw</a>(painter, palette);
391
<a name="l00432"></a>00432 <span class="preprocessor">#endif</span>
392
<a name="l00433"></a>00433 <span class="preprocessor"></span> <span class="comment">// reset previous values</span>
393
<a name="l00434"></a>00434 sd-><a class="code" href="class_qwt_scale_draw.html#d301aed0c797c10f0104976d1a62ff69">move</a>(sdPos);
394
<a name="l00435"></a>00435 sd-><a class="code" href="class_qwt_scale_draw.html#2094e09579671d0a8e4b14a636eba6ef">setLength</a>(sdLength);
395
<a name="l00436"></a>00436
396
<a name="l00437"></a>00437 painter->restore();
397
<a name="l00438"></a>00438 }
398
<a name="l00439"></a>00439
399
<a name="l00450"></a><a class="code" href="class_qwt_plot.html#824015eb3a3908c53159a07c1f5085d8">00450</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot.html#824015eb3a3908c53159a07c1f5085d8">QwtPlot::printCanvas</a>(QPainter *painter, <span class="keyword">const</span> QRect &canvasRect,
400
<a name="l00451"></a>00451 <span class="keyword">const</span> <a class="code" href="class_qwt_scale_map.html">QwtScaleMap</a> map[axisCnt], <span class="keyword">const</span> <a class="code" href="class_qwt_plot_print_filter.html">QwtPlotPrintFilter</a> &pfilter)<span class="keyword"> const</span>
401
<a name="l00452"></a>00452 <span class="keyword"></span>{
402
<a name="l00453"></a>00453 <span class="keywordflow">if</span> ( pfilter.<a class="code" href="class_qwt_plot_print_filter.html#0f47c339382f3292d3e71e0585a008e4">options</a>() & QwtPlotPrintFilter::PrintCanvasBackground )
403
<a name="l00454"></a>00454 {
404
<a name="l00455"></a>00455 painter->setPen(Qt::NoPen);
405
<a name="l00456"></a>00456
406
<a name="l00457"></a>00457 QBrush bgBrush;
407
<a name="l00458"></a>00458 <span class="preprocessor">#if QT_VERSION >= 0x040000</span>
408
<a name="l00459"></a>00459 <span class="preprocessor"></span> bgBrush = <a class="code" href="class_qwt_plot.html#afcc82150034fbeb393ceb9f54ba2f1a">canvas</a>()->palette().brush(backgroundRole());
409
<a name="l00460"></a>00460 <span class="preprocessor">#else</span>
410
<a name="l00461"></a>00461 <span class="preprocessor"></span> QColorGroup::ColorRole role =
411
<a name="l00462"></a>00462 QPalette::backgroundRoleFromMode( backgroundMode() );
412
<a name="l00463"></a>00463 bgBrush = <a class="code" href="class_qwt_plot.html#afcc82150034fbeb393ceb9f54ba2f1a">canvas</a>()->colorGroup().brush( role );
413
<a name="l00464"></a>00464 <span class="preprocessor">#endif</span>
414
<a name="l00465"></a>00465 <span class="preprocessor"></span> painter->setBrush(bgBrush);
415
<a name="l00466"></a>00466
416
<a name="l00467"></a>00467 <span class="keywordtype">int</span> x1 = 0;
417
<a name="l00468"></a>00468 <span class="keywordtype">int</span> x2 = 0;
418
<a name="l00469"></a>00469 <span class="keywordtype">int</span> y1 = 0;
419
<a name="l00470"></a>00470 <span class="keywordtype">int</span> y2 = 0;
420
<a name="l00471"></a>00471
421
<a name="l00472"></a>00472 <span class="preprocessor">#if QT_VERSION >= 0x040000</span>
422
<a name="l00473"></a>00473 <span class="preprocessor"></span> <span class="keywordflow">switch</span>(painter->device()->paintEngine()->type())
423
<a name="l00474"></a>00474 {
424
<a name="l00475"></a>00475 <span class="keywordflow">case</span> QPaintEngine::PostScript:
425
<a name="l00476"></a>00476 x2 = 1;
426
<a name="l00477"></a>00477 y2 = 1;
427
<a name="l00478"></a>00478 <span class="keywordflow">break</span>;
428
<a name="l00479"></a>00479 <span class="keywordflow">default</span>:;
429
<a name="l00480"></a>00480 }
430
<a name="l00481"></a>00481 <span class="preprocessor">#endif</span>
431
<a name="l00482"></a>00482 <span class="preprocessor"></span>
432
<a name="l00483"></a>00483 <span class="keyword">const</span> <a class="code" href="class_qwt_metrics_map.html">QwtMetricsMap</a> map = <a class="code" href="class_qwt_painter.html#3de95bfc83c9beee537404b41749bad5">QwtPainter::metricsMap</a>();
433
<a name="l00484"></a>00484 x1 = map.<a class="code" href="class_qwt_metrics_map.html#e1cce24cb234af56b3e52bfad1d153ac">screenToLayoutX</a>(x1);
434
<a name="l00485"></a>00485 x2 = map.<a class="code" href="class_qwt_metrics_map.html#e1cce24cb234af56b3e52bfad1d153ac">screenToLayoutX</a>(x2);
435
<a name="l00486"></a>00486 y1 = map.<a class="code" href="class_qwt_metrics_map.html#8965c1ac879173a2dcc609f4ed911a8e">screenToLayoutY</a>(y1);
436
<a name="l00487"></a>00487 y2 = map.<a class="code" href="class_qwt_metrics_map.html#8965c1ac879173a2dcc609f4ed911a8e">screenToLayoutY</a>(y2);
437
<a name="l00488"></a>00488
438
<a name="l00489"></a>00489 <a class="code" href="class_qwt_painter.html#9d606b6a681b9e1d0e0823c8a169ac7e">QwtPainter::drawRect</a>(painter,
439
<a name="l00490"></a>00490 canvasRect.x() + x1, canvasRect.y() + y1,
440
<a name="l00491"></a>00491 canvasRect.width() - x2, canvasRect.height() - y2);
441
<a name="l00492"></a>00492 }
442
<a name="l00493"></a>00493 <span class="keywordflow">else</span>
443
<a name="l00494"></a>00494 {
444
<a name="l00495"></a>00495 <span class="comment">// Paint the canvas borders instead.</span>
445
<a name="l00496"></a>00496 painter->setPen(QPen(Qt::black));
446
<a name="l00497"></a>00497 painter->setBrush(QBrush(Qt::NoBrush));
447
<a name="l00498"></a>00498 <a class="code" href="class_qwt_painter.html#9d606b6a681b9e1d0e0823c8a169ac7e">QwtPainter::drawRect</a>(painter, canvasRect);
448
<a name="l00499"></a>00499 }
449
<a name="l00500"></a>00500
450
<a name="l00501"></a>00501
451
<a name="l00502"></a>00502 painter->setClipping(<span class="keyword">true</span>);
452
<a name="l00503"></a>00503 <a class="code" href="class_qwt_painter.html#7a3b7e59fd56236dd99c5b1772e1a768">QwtPainter::setClipRect</a>(painter, canvasRect);
453
<a name="l00504"></a>00504
454
<a name="l00505"></a>00505 drawItems(painter, canvasRect, map, pfilter);
455
<a name="l00506"></a>00506 }
456
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Feb 26 21:22:38 2007 for Qwt User's Guide by
457
<a href="http://www.doxygen.org/index.html">
458
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.6 </small></address>