qwt_plot_abstract_canvas.cpp
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2  * Qwt Widget Library
3  * Copyright (C) 1997 Josef Wilgen
4  * Copyright (C) 2002 Uwe Rathmann
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the Qwt License, Version 1.0
8  *****************************************************************************/
9 
11 #include "qwt_plot.h"
12 #include "qwt_painter.h"
13 #include "qwt_null_paintdevice.h"
14 #include "qwt_math.h"
15 
16 #include <qpainter.h>
17 #include <qpainterpath.h>
18 #include <qstyle.h>
19 #include <qstyleoption.h>
20 
21 namespace
22 {
23  class QwtStyleSheetRecorder QWT_FINAL : public QwtNullPaintDevice
24  {
25  public:
26  explicit QwtStyleSheetRecorder( const QSize &size ):
27  d_size( size )
28  {
29  }
30 
31  virtual void updateState( const QPaintEngineState &state ) QWT_OVERRIDE
32  {
33  if ( state.state() & QPaintEngine::DirtyPen )
34  {
35  d_pen = state.pen();
36  }
37  if ( state.state() & QPaintEngine::DirtyBrush )
38  {
39  d_brush = state.brush();
40  }
41  if ( state.state() & QPaintEngine::DirtyBrushOrigin )
42  {
43  d_origin = state.brushOrigin();
44  }
45  }
46 
47  virtual void drawRects(const QRectF *rects, int count ) QWT_OVERRIDE
48  {
49  for ( int i = 0; i < count; i++ )
50  border.rectList += rects[i];
51  }
52 
53  virtual void drawRects(const QRect *rects, int count ) QWT_OVERRIDE
54  {
55  for ( int i = 0; i < count; i++ )
56  border.rectList += rects[i];
57  }
58 
59  virtual void drawPath( const QPainterPath &path ) QWT_OVERRIDE
60  {
61  const QRectF rect( QPointF( 0.0, 0.0 ), d_size );
62  if ( path.controlPointRect().contains( rect.center() ) )
63  {
64  setCornerRects( path );
65  alignCornerRects( rect );
66 
67  background.path = path;
68  background.brush = d_brush;
69  background.origin = d_origin;
70  }
71  else
72  {
73  border.pathList += path;
74  }
75  }
76 
77  void setCornerRects( const QPainterPath &path )
78  {
79  QPointF pos( 0.0, 0.0 );
80 
81  for ( int i = 0; i < path.elementCount(); i++ )
82  {
83  QPainterPath::Element el = path.elementAt(i);
84  switch( el.type )
85  {
86  case QPainterPath::MoveToElement:
87  case QPainterPath::LineToElement:
88  {
89  pos.setX( el.x );
90  pos.setY( el.y );
91  break;
92  }
93  case QPainterPath::CurveToElement:
94  {
95  QRectF r( pos, QPointF( el.x, el.y ) );
96  clipRects += r.normalized();
97 
98  pos.setX( el.x );
99  pos.setY( el.y );
100 
101  break;
102  }
103  case QPainterPath::CurveToDataElement:
104  {
105  if ( clipRects.size() > 0 )
106  {
107  QRectF r = clipRects.last();
108  r.setCoords(
109  qwtMinF( r.left(), el.x ),
110  qwtMinF( r.top(), el.y ),
111  qwtMaxF( r.right(), el.x ),
112  qwtMaxF( r.bottom(), el.y )
113  );
114  clipRects.last() = r.normalized();
115  }
116  break;
117  }
118  }
119  }
120  }
121 
122  protected:
123  virtual QSize sizeMetrics() const QWT_OVERRIDE
124  {
125  return d_size;
126  }
127 
128  private:
129  void alignCornerRects( const QRectF &rect )
130  {
131  for ( int i = 0; i < clipRects.size(); i++ )
132  {
133  QRectF &r = clipRects[i];
134  if ( r.center().x() < rect.center().x() )
135  r.setLeft( rect.left() );
136  else
137  r.setRight( rect.right() );
138 
139  if ( r.center().y() < rect.center().y() )
140  r.setTop( rect.top() );
141  else
142  r.setBottom( rect.bottom() );
143  }
144  }
145 
146 
147  public:
148  QVector<QRectF> clipRects;
149 
150  struct Border
151  {
152  QList<QPainterPath> pathList;
153  QList<QRectF> rectList;
154  QRegion clipRegion;
155  } border;
156 
157  struct Background
158  {
159  QPainterPath path;
160  QBrush brush;
161  QPointF origin;
162  } background;
163 
164  private:
165  const QSize d_size;
166 
167  QPen d_pen;
168  QBrush d_brush;
169  QPointF d_origin;
170  };
171 }
172 
173 static void qwtUpdateContentsRect( int fw, QWidget *canvas )
174 {
175  canvas->setContentsMargins( fw, fw, fw, fw );
176 }
177 
178 static void qwtFillRegion( QPainter *painter, const QRegion& region )
179 {
180 #if QT_VERSION >= 0x050800
181  for ( QRegion::const_iterator it = region.cbegin();
182  it != region.cend(); ++it )
183  {
184  painter->drawRect( *it );
185  }
186 #else
187  painter->drawRects( region.rects() );
188 #endif
189 }
190 
191 static void qwtDrawBackground( QPainter *painter, QWidget *canvas )
192 {
193  painter->save();
194 
195  QPainterPath borderClip;
196 
197  ( void )QMetaObject::invokeMethod(
198  canvas, "borderPath", Qt::DirectConnection,
199  Q_RETURN_ARG( QPainterPath, borderClip ), Q_ARG( QRect, canvas->rect() ) );
200 
201  if ( !borderClip.isEmpty() )
202  painter->setClipPath( borderClip, Qt::IntersectClip );
203 
204  const QBrush &brush = canvas->palette().brush( canvas->backgroundRole() );
205 
206  if ( brush.style() == Qt::TexturePattern )
207  {
208  QPixmap pm( canvas->size() );
209  QwtPainter::fillPixmap( canvas, pm );
210  painter->drawPixmap( 0, 0, pm );
211  }
212  else if ( brush.gradient() )
213  {
214  const bool fillClipRegion =
215  brush.gradient()->coordinateMode() != QGradient::ObjectBoundingMode;
216 
217  painter->setPen( Qt::NoPen );
218  painter->setBrush( brush );
219 
220  if ( fillClipRegion )
221  qwtFillRegion( painter, painter->clipRegion() );
222  else
223  painter->drawRect( canvas->rect() );
224  }
225  else
226  {
227  painter->setPen( Qt::NoPen );
228  painter->setBrush( brush );
229  qwtFillRegion( painter, painter->clipRegion() );
230  }
231 
232  painter->restore();
233 }
234 
235 static inline void qwtDrawStyledBackground(
236  QWidget *w, QPainter *painter )
237 {
238  QStyleOption opt;
239  opt.initFrom(w);
240  w->style()->drawPrimitive( QStyle::PE_Widget, &opt, painter, w);
241 }
242 
243 static QWidget *qwtBackgroundWidget( QWidget *w )
244 {
245  if ( w->parentWidget() == NULL )
246  return w;
247 
248  if ( w->autoFillBackground() )
249  {
250  const QBrush brush = w->palette().brush( w->backgroundRole() );
251  if ( brush.color().alpha() > 0 )
252  return w;
253  }
254 
255  if ( w->testAttribute( Qt::WA_StyledBackground ) )
256  {
257  QImage image( 1, 1, QImage::Format_ARGB32 );
258  image.fill( Qt::transparent );
259 
260  QPainter painter( &image );
261  painter.translate( -w->rect().center() );
262  qwtDrawStyledBackground( w, &painter );
263  painter.end();
264 
265  if ( qAlpha( image.pixel( 0, 0 ) ) != 0 )
266  return w;
267  }
268 
269  return qwtBackgroundWidget( w->parentWidget() );
270 }
271 
272 static void qwtFillBackground( QPainter *painter,
273  QWidget *widget, const QVector<QRectF> &fillRects )
274 {
275  if ( fillRects.isEmpty() )
276  return;
277 
278  QRegion clipRegion;
279  if ( painter->hasClipping() )
280  clipRegion = painter->transform().map( painter->clipRegion() );
281  else
282  clipRegion = widget->contentsRect();
283 
284  // Try to find out which widget fills
285  // the unfilled areas of the styled background
286 
287  QWidget *bgWidget = qwtBackgroundWidget( widget->parentWidget() );
288 
289  for ( int i = 0; i < fillRects.size(); i++ )
290  {
291  const QRect rect = fillRects[i].toAlignedRect();
292  if ( clipRegion.intersects( rect ) )
293  {
294  QPixmap pm( rect.size() );
295  QwtPainter::fillPixmap( bgWidget, pm, widget->mapTo( bgWidget, rect.topLeft() ) );
296  painter->drawPixmap( rect, pm );
297  }
298  }
299 }
300 
301 static void qwtFillBackground( QPainter *painter, QWidget *canvas )
302 {
303  QVector<QRectF> rects;
304 
305  if ( canvas->testAttribute( Qt::WA_StyledBackground ) )
306  {
307  QwtStyleSheetRecorder recorder( canvas->size() );
308 
309  QPainter p( &recorder );
310  qwtDrawStyledBackground( canvas, &p );
311  p.end();
312 
313  if ( recorder.background.brush.isOpaque() )
314  rects = recorder.clipRects;
315  else
316  rects += canvas->rect();
317  }
318  else
319  {
320  const double borderRadius = canvas->property( "borderRadius" ).toDouble();
321  if ( borderRadius > 0.0 )
322  {
323  QSizeF sz( borderRadius, borderRadius );
324 
325  const QRectF r = canvas->rect();
326  rects += QRectF( r.topLeft(), sz );
327  rects += QRectF( r.topRight() - QPointF( borderRadius, 0 ), sz );
328  rects += QRectF( r.bottomRight() - QPointF( borderRadius, borderRadius ), sz );
329  rects += QRectF( r.bottomLeft() - QPointF( 0, borderRadius ), sz );
330  }
331  }
332 
333  qwtFillBackground( painter, canvas, rects);
334 }
335 
336 static inline void qwtRevertPath( QPainterPath &path )
337 {
338  if ( path.elementCount() == 4 )
339  {
340  QPainterPath::Element el0 = path.elementAt(0);
341  QPainterPath::Element el3 = path.elementAt(3);
342 
343  path.setElementPositionAt( 0, el3.x, el3.y );
344  path.setElementPositionAt( 3, el0.x, el0.y );
345  }
346 }
347 
348 static QPainterPath qwtCombinePathList( const QRectF &rect,
349  const QList<QPainterPath> &pathList )
350 {
351  if ( pathList.isEmpty() )
352  return QPainterPath();
353 
354  QPainterPath ordered[8]; // starting top left
355 
356  for ( int i = 0; i < pathList.size(); i++ )
357  {
358  int index = -1;
359  QPainterPath subPath = pathList[i];
360 
361  const QRectF br = pathList[i].controlPointRect();
362  if ( br.center().x() < rect.center().x() )
363  {
364  if ( br.center().y() < rect.center().y() )
365  {
366  if ( qAbs( br.top() - rect.top() ) <
367  qAbs( br.left() - rect.left() ) )
368  {
369  index = 1;
370  }
371  else
372  {
373  index = 0;
374  }
375  }
376  else
377  {
378  if ( qAbs( br.bottom() - rect.bottom() ) <
379  qAbs( br.left() - rect.left() ) )
380  {
381  index = 6;
382  }
383  else
384  {
385  index = 7;
386  }
387  }
388 
389  if ( subPath.currentPosition().y() > br.center().y() )
390  qwtRevertPath( subPath );
391  }
392  else
393  {
394  if ( br.center().y() < rect.center().y() )
395  {
396  if ( qAbs( br.top() - rect.top() ) <
397  qAbs( br.right() - rect.right() ) )
398  {
399  index = 2;
400  }
401  else
402  {
403  index = 3;
404  }
405  }
406  else
407  {
408  if ( qAbs( br.bottom() - rect.bottom() ) <
409  qAbs( br.right() - rect.right() ) )
410  {
411  index = 5;
412  }
413  else
414  {
415  index = 4;
416  }
417  }
418  if ( subPath.currentPosition().y() < br.center().y() )
419  qwtRevertPath( subPath );
420  }
421  ordered[index] = subPath;
422  }
423 
424  for ( int i = 0; i < 4; i++ )
425  {
426  if ( ordered[ 2 * i].isEmpty() != ordered[2 * i + 1].isEmpty() )
427  {
428  // we don't accept incomplete rounded borders
429  return QPainterPath();
430  }
431  }
432 
433 
434  const QPolygonF corners( rect );
435 
436  QPainterPath path;
437  //path.moveTo( rect.topLeft() );
438 
439  for ( int i = 0; i < 4; i++ )
440  {
441  if ( ordered[2 * i].isEmpty() )
442  {
443  path.lineTo( corners[i] );
444  }
445  else
446  {
447  path.connectPath( ordered[2 * i] );
448  path.connectPath( ordered[2 * i + 1] );
449  }
450  }
451 
452  path.closeSubpath();
453 
454 #if 0
455  return path.simplified();
456 #else
457  return path;
458 #endif
459 }
460 
461 static QPainterPath qwtBorderPath( const QWidget *canvas, const QRect &rect )
462 {
463  if ( canvas->testAttribute(Qt::WA_StyledBackground ) )
464  {
465  QwtStyleSheetRecorder recorder( rect.size() );
466 
467  QPainter painter( &recorder );
468 
469  QStyleOption opt;
470  opt.initFrom( canvas );
471  opt.rect = rect;
472  canvas->style()->drawPrimitive( QStyle::PE_Widget, &opt, &painter, canvas );
473 
474  painter.end();
475 
476  if ( !recorder.background.path.isEmpty() )
477  return recorder.background.path;
478 
479  if ( !recorder.border.rectList.isEmpty() )
480  return qwtCombinePathList( rect, recorder.border.pathList );
481  }
482  else
483  {
484  const double borderRadius = canvas->property( "borderRadius" ).toDouble();
485 
486  if ( borderRadius > 0.0 )
487  {
488  double fw2 = canvas->property( "frameWidth" ).toInt() * 0.5;
489  QRectF r = QRectF(rect).adjusted( fw2, fw2, -fw2, -fw2 );
490 
491  QPainterPath path;
492  path.addRoundedRect( r, borderRadius, borderRadius );
493  return path;
494  }
495  }
496 
497  return QPainterPath();
498 }
499 
501 {
502 public:
504  focusIndicator( NoFocusIndicator ),
505  borderRadius( 0 )
506  {
507  styleSheet.hasBorder = false;
508  }
509 
511  double borderRadius;
512 
513  struct StyleSheet
514  {
515  bool hasBorder;
516  QPainterPath borderPath;
518 
520  {
521  QBrush brush;
522  QPointF origin;
523  } background;
524 
525  } styleSheet;
526 
527  QWidget *canvasWidget;
528 };
529 
531 {
532  d_data = new PrivateData;
533  d_data->canvasWidget = canvasWidget;
534 
535 #ifndef QT_NO_CURSOR
536  canvasWidget->setCursor( Qt::CrossCursor );
537 #endif
538 
539  canvasWidget->setAutoFillBackground( true );
540 
541  canvasWidget->setProperty( "lineWidth", 2 );
542  canvasWidget->setProperty( "frameShadow", QFrame::Sunken );
543  canvasWidget->setProperty( "frameShape", QFrame::Panel );
544 }
545 
547 {
548  delete d_data;
549 }
550 
553 {
554  return qobject_cast<QwtPlot *>( d_data->canvasWidget->parent() );
555 }
556 
559 {
560  return qobject_cast<const QwtPlot *>( d_data->canvasWidget->parent() );
561 }
562 
569 {
570  d_data->focusIndicator = focusIndicator;
571 }
572 
579 {
580  return d_data->focusIndicator;
581 }
582 
588 {
589  const int margin = 1;
590 
591  QRect focusRect = d_data->canvasWidget->contentsRect();
592  focusRect.setRect( focusRect.x() + margin, focusRect.y() + margin,
593  focusRect.width() - 2 * margin, focusRect.height() - 2 * margin );
594 
595  QwtPainter::drawFocusRect( painter, d_data->canvasWidget, focusRect );
596 }
597 
605 {
606  d_data->borderRadius = qwtMaxF( 0.0, radius );
607 }
608 
614 {
615  return d_data->borderRadius;
616 }
617 
618 QPainterPath QwtPlotAbstractCanvas::borderPath2( const QRect &rect ) const
619 {
620  return qwtBorderPath( canvasWidget(), rect );
621 }
622 
627 void QwtPlotAbstractCanvas::drawBorder( QPainter *painter )
628 {
629  const QWidget *w = canvasWidget();
630 
631  if ( d_data->borderRadius > 0 )
632  {
633  const int frameWidth = w->property( "frameWidth" ).toInt();
634  if ( frameWidth > 0 )
635  {
636  const int frameShape = w->property( "frameShape" ).toInt();
637  const int frameShadow = w->property( "frameShadow" ).toInt();
638 
639  const QRectF frameRect = w->property( "frameRect" ).toRect();
640 
641  QwtPainter::drawRoundedFrame( painter, frameRect,
642  d_data->borderRadius, d_data->borderRadius,
643  w->palette(), frameWidth, frameShape | frameShadow );
644  }
645  }
646  else
647  {
648  const int frameShape = w->property( "frameShape" ).toInt();
649  const int frameShadow = w->property( "frameShadow" ).toInt();
650 
651 #if QT_VERSION < 0x050000
652  QStyleOptionFrameV3 opt;
653 #else
654  QStyleOptionFrame opt;
655 #endif
656  opt.initFrom( w );
657 
658  opt.frameShape = QFrame::Shape( int( opt.frameShape ) | frameShape );
659 
660  switch (frameShape)
661  {
662  case QFrame::Box:
663  case QFrame::HLine:
664  case QFrame::VLine:
665  case QFrame::StyledPanel:
666  case QFrame::Panel:
667  {
668  opt.lineWidth = w->property( "lineWidth" ).toInt();
669  opt.midLineWidth = w->property( "midLineWidth" ).toInt();
670  break;
671  }
672  default:
673  {
674  opt.lineWidth = w->property( "frameWidth" ).toInt();
675  break;
676  }
677  }
678 
679  if ( frameShadow == QFrame::Sunken )
680  opt.state |= QStyle::State_Sunken;
681  else if ( frameShadow == QFrame::Raised )
682  opt.state |= QStyle::State_Raised;
683 
684  w->style()->drawControl(QStyle::CE_ShapedFrame, &opt, painter, w );
685  }
686 }
687 
688 void QwtPlotAbstractCanvas::drawBackground( QPainter *painter )
689 {
690  qwtDrawBackground( painter, canvasWidget() );
691 }
692 
693 void QwtPlotAbstractCanvas::fillBackground( QPainter *painter )
694 {
695  qwtFillBackground( painter, canvasWidget() );
696 }
697 
698 void QwtPlotAbstractCanvas::drawUnstyled( QPainter *painter )
699 {
700  fillBackground( painter );
701 
702  QWidget *w = canvasWidget();
703 
704  if ( w->autoFillBackground() )
705  {
706  const QRect canvasRect = w->rect();
707 
708  painter->save();
709 
710  painter->setPen( Qt::NoPen );
711  painter->setBrush( w->palette().brush( w->backgroundRole() ) );
712 
713  const QRect frameRect = w->property( "frameRect" ).toRect();
714  if ( borderRadius() > 0.0 && ( canvasRect == frameRect ) )
715  {
716  const int frameWidth = w->property( "frameWidth" ).toInt();
717  if ( frameWidth > 0 )
718  {
719  painter->setClipPath( borderPath2( canvasRect ) );
720  painter->drawRect( canvasRect );
721  }
722  else
723  {
724  painter->setRenderHint( QPainter::Antialiasing, true );
725  painter->drawPath( borderPath2( canvasRect ) );
726  }
727  }
728  else
729  {
730  painter->drawRect( canvasRect );
731  }
732 
733  painter->restore();
734  }
735 
736  drawCanvas( painter );
737 }
738 
739 void QwtPlotAbstractCanvas::drawStyled( QPainter *painter, bool hackStyledBackground )
740 {
741  fillBackground( painter );
742 
743  if ( hackStyledBackground )
744  {
745  // Antialiasing rounded borders is done by
746  // inserting pixels with colors between the
747  // border color and the color on the canvas,
748  // When the border is painted before the plot items
749  // these colors are interpolated for the canvas
750  // and the plot items need to be clipped excluding
751  // the anialiased pixels. In situations, where
752  // the plot items fill the area at the rounded
753  // borders this is noticeable.
754  // The only way to avoid these annoying "artefacts"
755  // is to paint the border on top of the plot items.
756 
757  if ( !d_data->styleSheet.hasBorder ||
758  d_data->styleSheet.borderPath.isEmpty() )
759  {
760  // We have no border with at least one rounded corner
761  hackStyledBackground = false;
762  }
763  }
764 
765  QWidget *w = canvasWidget();
766 
767  if ( hackStyledBackground )
768  {
769  painter->save();
770 
771  // paint background without border
772  painter->setPen( Qt::NoPen );
773  painter->setBrush( d_data->styleSheet.background.brush );
774  painter->setBrushOrigin( d_data->styleSheet.background.origin );
775  painter->setClipPath( d_data->styleSheet.borderPath );
776  painter->drawRect( w->contentsRect() );
777 
778  painter->restore();
779 
780  drawCanvas( painter );
781 
782  // Now paint the border on top
783  QStyleOptionFrame opt;
784  opt.initFrom( w );
785  w->style()->drawPrimitive( QStyle::PE_Frame, &opt, painter, w);
786  }
787  else
788  {
789  QStyleOption opt;
790  opt.initFrom( w );
791  w->style()->drawPrimitive( QStyle::PE_Widget, &opt, painter, w );
792 
793  drawCanvas( painter );
794  }
795 }
796 
797 void QwtPlotAbstractCanvas::drawCanvas( QPainter *painter )
798 {
799  QWidget *w = canvasWidget();
800 
801  painter->save();
802 
803  if ( !d_data->styleSheet.borderPath.isEmpty() )
804  {
805  painter->setClipPath(
806  d_data->styleSheet.borderPath, Qt::IntersectClip );
807  }
808  else
809  {
810  if ( borderRadius() > 0.0 )
811  {
812  const QRect frameRect = w->property( "frameRect" ).toRect();
813  painter->setClipPath( borderPath2( frameRect ), Qt::IntersectClip );
814  }
815  else
816  {
817  painter->setClipRect( w->contentsRect(), Qt::IntersectClip );
818  }
819  }
820 
821  QwtPlot *plot = qobject_cast< QwtPlot *>( w->parent() );
822  if ( plot )
823  plot->drawCanvas( painter );
824 
825  painter->restore();
826 }
827 
830 {
831  QWidget *w = canvasWidget();
832 
833  if ( !w->testAttribute( Qt::WA_StyledBackground ) )
834  return;
835 
836  QwtStyleSheetRecorder recorder( w->size() );
837 
838  QPainter painter( &recorder );
839 
840  QStyleOption opt;
841  opt.initFrom(w);
842  w->style()->drawPrimitive( QStyle::PE_Widget, &opt, &painter, w);
843 
844  painter.end();
845 
846  d_data->styleSheet.hasBorder = !recorder.border.rectList.isEmpty();
847  d_data->styleSheet.cornerRects = recorder.clipRects;
848 
849  if ( recorder.background.path.isEmpty() )
850  {
851  if ( !recorder.border.rectList.isEmpty() )
852  {
853  d_data->styleSheet.borderPath =
854  qwtCombinePathList( w->rect(), recorder.border.pathList );
855  }
856  }
857  else
858  {
859  d_data->styleSheet.borderPath = recorder.background.path;
860  d_data->styleSheet.background.brush = recorder.background.brush;
861  d_data->styleSheet.background.origin = recorder.background.origin;
862  }
863 }
864 
866 {
867  return d_data->canvasWidget;
868 }
869 
871 {
872  return d_data->canvasWidget;
873 }
874 
876 {
877 public:
879  frameStyle( QFrame::Panel | QFrame::Sunken),
880  lineWidth( 2 ),
881  midLineWidth( 0 )
882  {
883  }
884 
886  {
887  }
888 
890 
894 };
895 
897  QwtPlotAbstractCanvas( canvasWidget )
898 {
899  d_data = new PrivateData;
900 
901  qwtUpdateContentsRect( frameWidth(), canvasWidget );
903 }
904 
906 {
907  delete d_data;
908 }
909 
919 {
920  if ( bool( d_data->paintAttributes & attribute ) == on )
921  return;
922 
923  if ( on )
924  {
925  d_data->paintAttributes |= attribute;
926  }
927  else
928  {
929  d_data->paintAttributes &= ~attribute;
930 
931  if ( attribute == BackingStore )
933  }
934 }
935 
944 {
945  return d_data->paintAttributes & attribute;
946 }
947 
957 {
958  if ( style != d_data->frameStyle )
959  {
960  d_data->frameStyle = style;
962 
963  canvasWidget()->update();
964  }
965 }
966 
972 {
973  return d_data->frameStyle;
974 }
975 
982 void QwtPlotAbstractGLCanvas::setFrameShadow( QFrame::Shadow shadow )
983 {
984  setFrameStyle(( d_data->frameStyle & QFrame::Shape_Mask ) | shadow );
985 }
986 
992 {
993  return (QFrame::Shadow) ( d_data->frameStyle & QFrame::Shadow_Mask );
994 }
995 
1002 void QwtPlotAbstractGLCanvas::setFrameShape( QFrame::Shape shape )
1003 {
1004  setFrameStyle( ( d_data->frameStyle & QFrame::Shadow_Mask ) | shape );
1005 }
1006 
1012 {
1013  return (QFrame::Shape) ( d_data->frameStyle & QFrame::Shape_Mask );
1014 }
1015 
1025 {
1026  width = qMax( width, 0 );
1027  if ( width != d_data->lineWidth )
1028  {
1029  d_data->lineWidth = qMax( width, 0 );
1031  canvasWidget()->update();
1032  }
1033 }
1034 
1040 {
1041  return d_data->lineWidth;
1042 }
1043 
1053 {
1054  width = qMax( width, 0 );
1055  if ( width != d_data->midLineWidth )
1056  {
1057  d_data->midLineWidth = width;
1059  canvasWidget()->update();
1060  }
1061 }
1062 
1068 {
1069  return d_data->midLineWidth;
1070 }
1071 
1076 {
1077  return ( frameStyle() != QFrame::NoFrame ) ? d_data->lineWidth : 0;
1078 }
1079 
1085 {
1087 
1088  QWidget *w = canvasWidget();
1090  w->repaint( w->contentsRect() );
1091  else
1092  w->update( w->contentsRect() );
1093 }
1094 
1097 {
1098  const int fw = frameWidth();
1099  return canvasWidget()->contentsRect().adjusted( -fw, -fw, fw, fw );
1100 }
1101 
1102 void QwtPlotAbstractGLCanvas::draw( QPainter *painter )
1103 {
1104 #if FIX_GL_TRANSLATION
1105  if ( painter->paintEngine()->type() == QPaintEngine::OpenGL2 )
1106  {
1107  // work around a translation bug of QPaintEngine::OpenGL2
1108  painter->translate( 1, 1 );
1109  }
1110 #endif
1111 
1112  if ( canvasWidget()->testAttribute( Qt::WA_StyledBackground ) )
1113  drawStyled( painter, true );
1114  else
1115  drawUnstyled( painter );
1116 
1117  if ( frameWidth() > 0 )
1118  drawBorder( painter );
1119 }
virtual void clearBackingStore()=0
Paint double buffered reusing the content of the pixmap buffer when possible.
virtual void drawBackground(QPainter *)
static void fillPixmap(const QWidget *, QPixmap &, const QPoint &offset=QPoint())
static heap_info state
Definition: Heap.c:58
virtual void drawRects(const QRect *, int)
See QPaintEngine::drawRects()
static void qwtRevertPath(QPainterPath &path)
void setPaintAttribute(PaintAttribute, bool on=true)
Changing the paint attributes.
static void drawFocusRect(QPainter *, const QWidget *)
Draw a focus rectangle on a widget using its style.
bool testPaintAttribute(PaintAttribute) const
QWT_CONSTEXPR float qwtMaxF(float a, float b)
Definition: qwt_math.h:123
QwtPlotAbstractGLCanvas::PaintAttributes paintAttributes
A null paint device doing nothing.
FocusIndicator focusIndicator() const
static void qwtUpdateContentsRect(int fw, QWidget *canvas)
static void qwtDrawBackground(QPainter *painter, QWidget *canvas)
A 2-D plotting widget.
Definition: qwt_plot.h:75
virtual void updateState(const QPaintEngineState &)
See QPaintEngine::updateState()
QWT_CONSTEXPR float qwtMinF(float a, float b)
Definition: qwt_math.h:99
void drawStyled(QPainter *, bool)
static void drawRoundedFrame(QPainter *, const QRectF &, qreal xRadius, qreal yRadius, const QPalette &, int lineWidth, int frameStyle)
constexpr size_t count()
Definition: core.h:960
virtual void drawPath(const QPainterPath &)
See QPaintEngine::drawPath()
virtual void drawCanvas(QPainter *)
Definition: qwt_plot.cpp:728
static QPainterPath qwtBorderPath(const QWidget *canvas, const QRect &rect)
static QPainterPath qwtCombinePathList(const QRectF &rect, const QList< QPainterPath > &pathList)
QFrame::Shadow frameShadow() const
static void qwtDrawStyledBackground(QWidget *w, QPainter *painter)
QwtPlotAbstractGLCanvas(QWidget *canvasWidget)
j template void())
Definition: json.hpp:3707
void setFocusIndicator(FocusIndicator)
virtual QSize sizeMetrics() const =0
#define QWT_FINAL
Definition: qwt_global.h:57
QPainterPath borderPath2(const QRect &rect) const
virtual void drawBorder(QPainter *)
QFlags< PaintAttribute > PaintAttributes
Paint attributes.
FocusIndicator
Focus indicator The default setting is NoFocusIndicator.
QwtPlot * plot()
Return parent plot widget.
static QWidget * qwtBackgroundWidget(QWidget *w)
QwtPlotAbstractCanvas(QWidget *canvasWidget)
virtual void drawFocusIndicator(QPainter *)
static void qwtFillRegion(QPainter *painter, const QRegion &region)
void updateStyleSheetInfo()
Update the cached information about the current style sheet.
static void qwtFillBackground(QPainter *painter, QWidget *widget, const QVector< QRectF > &fillRects)
virtual void invalidateBackingStore()=0
#define QWT_OVERRIDE
Definition: qwt_global.h:53


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:10