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
|
<!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's Guide: qwt_plot_canvas.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 Page</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="globals.html">File Members</a> | <a class="qindex" href="pages.html">Related Pages</a></div>
<h1>qwt_plot_canvas.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 <qpainter.h></span>
00013 <span class="preprocessor">#include <qstyle.h></span>
00014 <span class="preprocessor">#include <qevent.h></span>
00015 <span class="preprocessor">#include "qwt_painter.h"</span>
00016 <span class="preprocessor">#include "<a class="code" href="qwt__math_8h.html">qwt_math.h</a>"</span>
00017 <span class="preprocessor">#include "qwt_plot.h"</span>
00018 <span class="preprocessor">#include "qwt_paint_buffer.h"</span>
00019 <span class="preprocessor">#include "qwt_plot_canvas.h"</span>
00020
00021 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">int</span> dim = 5000;
00022
00024
<a name="l00025"></a><a class="code" href="class_qwt_plot_canvas.html#b0">00025</a> <a class="code" href="class_qwt_plot_canvas.html#b0">QwtPlotCanvas::QwtPlotCanvas</a>(<a class="code" href="class_qwt_plot.html">QwtPlot</a> *plot):
00026 QFrame(plot, <span class="stringliteral">"canvas"</span>, Qt::WRepaintNoErase|Qt::WResizeNoErase),
00027 d_focusIndicator(CanvasFocusIndicator),
00028 d_cacheMode(TRUE),
00029 d_cache(NULL)
00030 #ifndef QWT_NO_COMPAT
00031 ,d_outlineEnabled(FALSE),
00032 d_outlineActive(FALSE),
00033 d_mousePressed(FALSE),
00034 d_outline(Qwt::Rect),
00035 d_pen(Qt::red)
00036 #endif
00037 {
00038 setCursor(Qt::crossCursor);
00039 }
00040
<a name="l00042"></a><a class="code" href="class_qwt_plot_canvas.html#b1">00042</a> <a class="code" href="class_qwt_plot_canvas.html#b1">QwtPlotCanvas::~QwtPlotCanvas</a>()
00043 {
00044 <span class="keyword">delete</span> d_cache;
00045 }
00046
<a name="l00066"></a><a class="code" href="class_qwt_plot_canvas.html#a2">00066</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot_canvas.html#a2">QwtPlotCanvas::setCacheMode</a>(<span class="keywordtype">bool</span> on)
00067 {
00068 <span class="keywordflow">if</span> ( d_cacheMode != on )
00069 {
00070 d_cacheMode = on;
00071 <span class="keywordflow">if</span> (!d_cacheMode )
00072 {
00073 <span class="keyword">delete</span> d_cache;
00074 d_cache = NULL;
00075 }
00076 }
00077 }
00078
<a name="l00083"></a><a class="code" href="class_qwt_plot_canvas.html#a3">00083</a> <span class="keywordtype">bool</span> <a class="code" href="class_qwt_plot_canvas.html#a3">QwtPlotCanvas::cacheMode</a>()<span class="keyword"> const</span>
00084 <span class="keyword"></span>{
00085 <span class="keywordflow">return</span> d_cacheMode;
00086 }
00087
<a name="l00089"></a><a class="code" href="class_qwt_plot_canvas.html#b2">00089</a> QPixmap *<a class="code" href="class_qwt_plot_canvas.html#a4">QwtPlotCanvas::cache</a>()
00090 {
00091 <span class="keywordflow">return</span> d_cache;
00092 }
00093
<a name="l00095"></a><a class="code" href="class_qwt_plot_canvas.html#a4">00095</a> <span class="keyword">const</span> QPixmap *<a class="code" href="class_qwt_plot_canvas.html#a4">QwtPlotCanvas::cache</a>()<span class="keyword"> const</span>
00096 <span class="keyword"></span>{
00097 <span class="keywordflow">return</span> d_cache;
00098 }
00099
<a name="l00101"></a><a class="code" href="class_qwt_plot_canvas.html#a5">00101</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot_canvas.html#a5">QwtPlotCanvas::invalidateCache</a>()
00102 {
00103 <span class="keywordflow">if</span> ( d_cache )
00104 d_cache->resize(0, 0);
00105 }
00106
<a name="l00112"></a><a class="code" href="class_qwt_plot_canvas.html#a0">00112</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot_canvas.html#a0">QwtPlotCanvas::setFocusIndicator</a>(FocusIndicator focusIndicator)
00113 {
00114 d_focusIndicator = focusIndicator;
00115 }
00116
<a name="l00122"></a><a class="code" href="class_qwt_plot_canvas.html#a1">00122</a> <a class="code" href="class_qwt_plot_canvas.html#w3">QwtPlotCanvas::FocusIndicator</a> <a class="code" href="class_qwt_plot_canvas.html#a1">QwtPlotCanvas::focusIndicator</a>()<span class="keyword"> const</span>
00123 <span class="keyword"></span>{
00124 <span class="keywordflow">return</span> d_focusIndicator;
00125 }
00126
<a name="l00128"></a><a class="code" href="class_qwt_plot_canvas.html#b3">00128</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot_canvas.html#b3">QwtPlotCanvas::frameChanged</a>()
00129 {
00130 QFrame::frameChanged();
00131
00132 <span class="comment">// frame changes change the size of the contents rect, what</span>
00133 <span class="comment">// is related to the axes. So we have to update the layout.</span>
00134
00135 ((<a class="code" href="class_qwt_plot.html">QwtPlot</a> *)parent())->updateLayout();
00136 }
00137
<a name="l00139"></a><a class="code" href="class_qwt_plot_canvas.html#b4">00139</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot_canvas.html#b4">QwtPlotCanvas::drawContents</a>(QPainter *painter)
00140 {
00141 <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_plot_canvas.html#a3">cacheMode</a>() && d_cache
00142 && d_cache->size() == contentsRect().size() )
00143 {
00144 painter->drawPixmap(contentsRect().topLeft(), *d_cache);
00145 }
00146 <span class="keywordflow">else</span>
00147 <a class="code" href="class_qwt_plot_canvas.html#b6">drawCanvas</a>(painter);
00148
00149 <span class="preprocessor">#ifndef QWT_NO_COMPAT</span>
00150 <span class="preprocessor"></span> <span class="keywordflow">if</span> ( d_outlineActive )
00151 drawOutline(*painter); <span class="comment">// redraw outline</span>
00152 <span class="preprocessor">#endif</span>
00153 <span class="preprocessor"></span>
00154 <span class="keywordflow">if</span> ( hasFocus() && <a class="code" href="class_qwt_plot_canvas.html#a1">focusIndicator</a>() == CanvasFocusIndicator )
00155 {
00156 <span class="keyword">const</span> <span class="keywordtype">int</span> margin = 1;
00157 QRect focusRect = contentsRect();
00158 focusRect.setRect(focusRect.x() + margin, focusRect.y() + margin,
00159 focusRect.width() - 2 * margin, focusRect.height() - 2 * margin);
00160
00161 <a class="code" href="class_qwt_plot_canvas.html#b5">drawFocusIndicator</a>(painter, focusRect);
00162 }
00163 }
00164
<a name="l00174"></a><a class="code" href="class_qwt_plot_canvas.html#b6">00174</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot_canvas.html#b6">QwtPlotCanvas::drawCanvas</a>(QPainter *painter)
00175 {
00176 <span class="keywordflow">if</span> ( !contentsRect().isValid() )
00177 <span class="keywordflow">return</span>;
00178
00179 QRect clipRect = contentsRect();
00180 <span class="keywordflow">if</span> ( !<a class="code" href="class_qwt_plot_canvas.html#a3">cacheMode</a>() || !<a class="code" href="class_qwt_paint_buffer.html#e1">QwtPaintBuffer::isEnabled</a>() )
00181 {
00182 <span class="comment">// If we dont need the paint buffer as cache we can</span>
00183 <span class="comment">// use the clip for painting to the buffer too. </span>
00184
00185 <span class="keywordflow">if</span> ( painter && !painter->clipRegion().isNull() )
00186 clipRect = painter->clipRegion().boundingRect();
00187 }
00188
00189 <a class="code" href="class_qwt_paint_buffer.html">QwtPaintBuffer</a> paintBuffer(<span class="keyword">this</span>, clipRect, painter);
00190 ((<a class="code" href="class_qwt_plot.html">QwtPlot</a> *)parent())->drawCanvas(paintBuffer.<a class="code" href="class_qwt_paint_buffer.html#a5">painter</a>());
00191
00192 <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_plot_canvas.html#a3">cacheMode</a>() )
00193 {
00194 <span class="keywordflow">if</span> ( d_cache == NULL )
00195 {
00196 d_cache = <span class="keyword">new</span> QPixmap(contentsRect().size());
00197 <span class="preprocessor">#if QT_VERSION >= 300</span>
00198 <span class="preprocessor"></span><span class="preprocessor">#ifdef Q_WS_X11</span>
00199 <span class="preprocessor"></span> <span class="keywordflow">if</span> ( d_cache->x11Screen() != x11Screen() )
00200 d_cache->x11SetScreen(x11Screen());
00201 <span class="preprocessor">#endif</span>
00202 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
00203 <span class="preprocessor"></span> }
00204 <span class="keywordflow">else</span>
00205 d_cache->resize(contentsRect().size());
00206
00207 <span class="keywordflow">if</span> ( <a class="code" href="class_qwt_paint_buffer.html#e1">QwtPaintBuffer::isEnabled</a>() )
00208 *d_cache = paintBuffer.<a class="code" href="class_qwt_paint_buffer.html#a7">buffer</a>();
00209 <span class="keywordflow">else</span>
00210 {
00211 d_cache->fill(<span class="keyword">this</span>, 0, 0);
00212 QPainter cachePainter(d_cache);
00213 cachePainter.translate(-contentsRect().x(),
00214 -contentsRect().y());
00215 ((<a class="code" href="class_qwt_plot.html">QwtPlot</a> *)parent())->drawCanvas(&cachePainter);
00216 }
00217 }
00218 }
00219
<a name="l00221"></a><a class="code" href="class_qwt_plot_canvas.html#b5">00221</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot_canvas.html#b5">QwtPlotCanvas::drawFocusIndicator</a>(QPainter *painter, <span class="keyword">const</span> QRect &rect)
00222 {
00223 <span class="preprocessor">#if QT_VERSION < 300</span>
00224 <span class="preprocessor"></span> style().drawFocusRect(painter, rect, colorGroup());
00225 <span class="preprocessor">#else</span>
00226 <span class="preprocessor"></span> style().drawPrimitive(QStyle::PE_FocusRect, painter,
00227 rect, colorGroup());
00228 <span class="preprocessor">#endif</span>
00229 <span class="preprocessor"></span>}
00230
00231 <span class="preprocessor">#ifndef QWT_NO_COMPAT</span>
00232 <span class="preprocessor"></span>
<a name="l00234"></a><a class="code" href="class_qwt_plot_canvas.html#b7">00234</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot_canvas.html#b7">QwtPlotCanvas::mousePressEvent</a>(QMouseEvent *e)
00235 {
00236 <span class="keywordflow">if</span> (d_outlineActive)
00237 {
00238 QPainter p(<span class="keyword">this</span>);
00239 drawOutline(p); <span class="comment">// Delete active outlines</span>
00240 }
00241
00242 d_outlineActive = FALSE;
00243
00244 <span class="comment">//</span>
00245 <span class="comment">// store this point as entry point</span>
00246 <span class="comment">//</span>
00247 d_lastPoint = e->pos();
00248 d_entryPoint = e->pos();
00249
00250 <span class="keywordflow">if</span> (d_outlineEnabled)
00251 {
00252 QPainter p(<span class="keyword">this</span>);
00253 drawOutline(p); <span class="comment">// draw new outline</span>
00254 d_outlineActive = TRUE;
00255 }
00256
00257 d_mousePressed = TRUE;
00258
00259 QMouseEvent m(QEvent::MouseButtonPress,
00260 e->pos() - rect().topLeft(), e->button(), e->state());
00261
00262 emit <a class="code" href="class_qwt_plot_canvas.html#l0">mousePressed</a>(m);
00263 }
00264
<a name="l00266"></a><a class="code" href="class_qwt_plot_canvas.html#b8">00266</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot_canvas.html#b8">QwtPlotCanvas::mouseReleaseEvent</a>(QMouseEvent *e)
00267 {
00268 <span class="keywordflow">if</span> (d_outlineActive)
00269 {
00270 QPainter p(<span class="keyword">this</span>);
00271 drawOutline(p);
00272 }
00273
00274 d_outlineActive = FALSE;
00275 d_mousePressed = FALSE;
00276
00277 QMouseEvent m(QEvent::MouseButtonRelease,
00278 e->pos() - rect().topLeft(), e->button(), e->state());
00279
00280 emit <a class="code" href="class_qwt_plot_canvas.html#l1">mouseReleased</a>(m);
00281 }
00282
<a name="l00284"></a><a class="code" href="class_qwt_plot_canvas.html#b9">00284</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot_canvas.html#b9">QwtPlotCanvas::mouseMoveEvent</a>(QMouseEvent *e)
00285 {
00286 <span class="keywordflow">if</span> (d_outlineActive)
00287 {
00288 QPainter p(<span class="keyword">this</span>);
00289 drawOutline(p);
00290 d_lastPoint = e->pos();
00291 drawOutline(p);
00292 }
00293
00294 QMouseEvent m(QEvent::MouseMove,
00295 e->pos() - rect().topLeft(), e->button(), e->state());
00296
00297 emit <a class="code" href="class_qwt_plot_canvas.html#l2">mouseMoved</a>(m);
00298 }
00299
<a name="l00315"></a><a class="code" href="class_qwt_plot_canvas.html#a6">00315</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot_canvas.html#a6">QwtPlotCanvas::enableOutline</a>(<span class="keywordtype">bool</span> tf)
00316 {
00317
00318 <span class="comment">//</span>
00319 <span class="comment">// If the mouse is pressed, erase existing outline</span>
00320 <span class="comment">// or draw new outline if 'tf' changes the 'enabled' state.</span>
00321 <span class="comment">//</span>
00322 <span class="keywordflow">if</span> ((tf != d_outlineEnabled) && d_mousePressed)
00323 {
00324 QPainter p(<span class="keyword">this</span>);
00325 drawOutline(p);
00326 d_outlineActive = tf;
00327 }
00328 d_outlineEnabled = tf;
00329 }
00330
<a name="l00340"></a><a class="code" href="class_qwt_plot_canvas.html#a7">00340</a> <span class="keywordtype">bool</span> <a class="code" href="class_qwt_plot_canvas.html#a7">QwtPlotCanvas::outlineEnabled</a>()<span class="keyword"> const </span>
00341 <span class="keyword"></span>{
00342 <span class="keywordflow">return</span> d_outlineEnabled;
00343 }
00344
<a name="l00379"></a><a class="code" href="class_qwt_plot_canvas.html#a10">00379</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot_canvas.html#a10">QwtPlotCanvas::setOutlineStyle</a>(Qwt::Shape os)
00380 {
00381 <span class="keywordflow">if</span> (d_outlineActive)
00382 {
00383 QPainter p(<span class="keyword">this</span>); <span class="comment">// erase old outline</span>
00384 drawOutline(p);
00385 }
00386
00387 d_outline = os;
00388
00389 <span class="keywordflow">if</span> (d_outlineActive)
00390 {
00391 QPainter p(<span class="keyword">this</span>);
00392 drawOutline(p); <span class="comment">// draw new outline</span>
00393 }
00394 }
00395
<a name="l00404"></a><a class="code" href="class_qwt_plot_canvas.html#a11">00404</a> Qwt::Shape <a class="code" href="class_qwt_plot_canvas.html#a11">QwtPlotCanvas::outlineStyle</a>()<span class="keyword"> const </span>
00405 <span class="keyword"></span>{
00406 <span class="keywordflow">return</span> d_outline;
00407 }
00408
<a name="l00419"></a><a class="code" href="class_qwt_plot_canvas.html#a8">00419</a> <span class="keywordtype">void</span> <a class="code" href="class_qwt_plot_canvas.html#a8">QwtPlotCanvas::setOutlinePen</a>(<span class="keyword">const</span> QPen &pen)
00420 {
00421 d_pen = pen;
00422 }
00423
<a name="l00433"></a><a class="code" href="class_qwt_plot_canvas.html#a9">00433</a> <span class="keyword">const</span> QPen& <a class="code" href="class_qwt_plot_canvas.html#a9">QwtPlotCanvas::outlinePen</a>()<span class="keyword"> const </span>
00434 <span class="keyword"></span>{
00435 <span class="keywordflow">return</span> d_pen;
00436 }
00437
00444 <span class="keywordtype">void</span> QwtPlotCanvas::drawOutline(QPainter &p)
00445 {
00446 <span class="keyword">const</span> QRect &r = contentsRect();
00447
00448 QColor bg = ((<a class="code" href="class_qwt_plot.html">QwtPlot</a> *)parent())->canvasBackground();
00449
00450 QPen pn = d_pen;
00451 pn.setColor(QColor(bg.rgb() ^ d_pen.color().rgb()));
00452
00453 p.setPen(pn);
00454 p.setRasterOp(XorROP);
00455 p.setClipRect(r);
00456 p.setClipping(TRUE);
00457
00458 <span class="keywordflow">switch</span>(d_outline)
00459 {
00460 <span class="keywordflow">case</span> Qwt::VLine:
00461 <a class="code" href="class_qwt_painter.html#e16">QwtPainter::drawLine</a>(&p, d_lastPoint.x(),
00462 r.top(), d_lastPoint.x(), r.bottom());
00463 <span class="keywordflow">break</span>;
00464
00465 <span class="keywordflow">case</span> Qwt::HLine:
00466 <a class="code" href="class_qwt_painter.html#e16">QwtPainter::drawLine</a>(&p, r.left(),
00467 d_lastPoint.y(), r.right(), d_lastPoint.y());
00468 <span class="keywordflow">break</span>;
00469
00470 <span class="keywordflow">case</span> Qwt::Cross:
00471 <a class="code" href="class_qwt_painter.html#e16">QwtPainter::drawLine</a>(&p, r.left(),
00472 d_lastPoint.y(), r.right(), d_lastPoint.y());
00473 <a class="code" href="class_qwt_painter.html#e16">QwtPainter::drawLine</a>(&p, d_lastPoint.x(),
00474 r.top(), d_lastPoint.x(), r.bottom());
00475 <span class="keywordflow">break</span>;
00476
00477 <span class="keywordflow">case</span> Qwt::Rect:
00478 <a class="code" href="class_qwt_painter.html#e12">QwtPainter::drawRect</a>(&p, d_entryPoint.x(), d_entryPoint.y(),
00479 d_lastPoint.x() - d_entryPoint.x() + 1,
00480 d_lastPoint.y() - d_entryPoint.y() + 1);
00481 <span class="keywordflow">break</span>;
00482
00483 <span class="keywordflow">case</span> Qwt::Ellipse:
00484 p.drawEllipse(d_entryPoint.x(), d_entryPoint.y(),
00485 d_lastPoint.x() - d_entryPoint.x() + 1,
00486 d_lastPoint.y() - d_entryPoint.y() + 1);
00487 <span class="keywordflow">break</span>;
00488
00489 <span class="keywordflow">default</span>:
00490 <span class="keywordflow">break</span>;
00491 }
00492 }
00493
00494 <span class="preprocessor">#endif // !QWT_NO_COMPAT</span>
00495 <span class="preprocessor"></span>
00496 <span class="comment">// Local Variables:</span>
00497 <span class="comment">// mode: C++</span>
00498 <span class="comment">// c-file-style: "stroustrup"</span>
00499 <span class="comment">// indent-tabs-mode: nil</span>
00500 <span class="comment">// End:</span>
00501
</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>
|