[4271] | 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 |
|
---|
| 10 | #ifndef QWT_PLOT_CANVAS_H
|
---|
| 11 | #define QWT_PLOT_CANVAS_H
|
---|
| 12 |
|
---|
| 13 | #include "qwt_global.h"
|
---|
| 14 | #include <qframe.h>
|
---|
| 15 | #include <qpainterpath.h>
|
---|
| 16 |
|
---|
| 17 | class QwtPlot;
|
---|
| 18 | class QPixmap;
|
---|
| 19 |
|
---|
| 20 | /*!
|
---|
| 21 | \brief Canvas of a QwtPlot.
|
---|
[8127] | 22 |
|
---|
| 23 | Canvas is the widget where all plot items are displayed
|
---|
| 24 |
|
---|
| 25 | \sa QwtPlot::setCanvas(), QwtPlotGLCanvas
|
---|
[4271] | 26 | */
|
---|
| 27 | class QWT_EXPORT QwtPlotCanvas : public QFrame
|
---|
| 28 | {
|
---|
| 29 | Q_OBJECT
|
---|
| 30 |
|
---|
[8127] | 31 | Q_PROPERTY( double borderRadius READ borderRadius WRITE setBorderRadius )
|
---|
| 32 |
|
---|
[4271] | 33 | public:
|
---|
| 34 |
|
---|
| 35 | /*!
|
---|
| 36 | \brief Paint attributes
|
---|
| 37 |
|
---|
| 38 | The default setting enables BackingStore and Opaque.
|
---|
| 39 |
|
---|
| 40 | \sa setPaintAttribute(), testPaintAttribute()
|
---|
| 41 | */
|
---|
| 42 | enum PaintAttribute
|
---|
| 43 | {
|
---|
| 44 | /*!
|
---|
| 45 | \brief Paint double buffered reusing the content
|
---|
| 46 | of the pixmap buffer when possible.
|
---|
| 47 |
|
---|
| 48 | Using a backing store might improve the performance
|
---|
[8127] | 49 | significantly, when working with widget overlays ( like rubber bands ).
|
---|
[4271] | 50 | Disabling the cache might improve the performance for
|
---|
| 51 | incremental paints (using QwtPlotDirectPainter ).
|
---|
| 52 |
|
---|
| 53 | \sa backingStore(), invalidateBackingStore()
|
---|
| 54 | */
|
---|
| 55 | BackingStore = 1,
|
---|
| 56 |
|
---|
| 57 | /*!
|
---|
| 58 | \brief Try to fill the complete contents rectangle
|
---|
| 59 | of the plot canvas
|
---|
| 60 |
|
---|
| 61 | When using styled backgrounds Qt assumes, that the
|
---|
| 62 | canvas doesn't fill its area completely
|
---|
| 63 | ( f.e because of rounded borders ) and fills the area
|
---|
| 64 | below the canvas. When this is done with gradients it might
|
---|
| 65 | result in a serious performance bottleneck - depending on the size.
|
---|
| 66 |
|
---|
| 67 | When the Opaque attribute is enabled the canvas tries to
|
---|
| 68 | identify the gaps with some heuristics and to fill those only.
|
---|
| 69 |
|
---|
| 70 | \warning Will not work for semitransparent backgrounds
|
---|
| 71 | */
|
---|
| 72 | Opaque = 2,
|
---|
| 73 |
|
---|
| 74 | /*!
|
---|
| 75 | \brief Try to improve painting of styled backgrounds
|
---|
| 76 |
|
---|
| 77 | QwtPlotCanvas supports the box model attributes for
|
---|
| 78 | customizing the layout with style sheets. Unfortunately
|
---|
| 79 | the design of Qt style sheets has no concept how to
|
---|
| 80 | handle backgrounds with rounded corners - beside of padding.
|
---|
| 81 |
|
---|
| 82 | When HackStyledBackground is enabled the plot canvas tries
|
---|
[8127] | 83 | to separate the background from the background border
|
---|
| 84 | by reverse engineering to paint the background before and
|
---|
[4271] | 85 | the border after the plot items. In this order the border
|
---|
[8127] | 86 | gets perfectly antialiased and you can avoid some pixel
|
---|
[4271] | 87 | artifacts in the corners.
|
---|
| 88 | */
|
---|
| 89 | HackStyledBackground = 4,
|
---|
| 90 |
|
---|
| 91 | /*!
|
---|
| 92 | When ImmediatePaint is set replot() calls repaint()
|
---|
| 93 | instead of update().
|
---|
| 94 |
|
---|
| 95 | \sa replot(), QWidget::repaint(), QWidget::update()
|
---|
| 96 | */
|
---|
| 97 | ImmediatePaint = 8
|
---|
| 98 | };
|
---|
| 99 |
|
---|
| 100 | //! Paint attributes
|
---|
| 101 | typedef QFlags<PaintAttribute> PaintAttributes;
|
---|
| 102 |
|
---|
| 103 | /*!
|
---|
| 104 | \brief Focus indicator
|
---|
[8127] | 105 | The default setting is NoFocusIndicator
|
---|
| 106 | \sa setFocusIndicator(), focusIndicator(), drawFocusIndicator()
|
---|
[4271] | 107 | */
|
---|
| 108 |
|
---|
| 109 | enum FocusIndicator
|
---|
| 110 | {
|
---|
[8127] | 111 | //! Don't paint a focus indicator
|
---|
[4271] | 112 | NoFocusIndicator,
|
---|
[8127] | 113 |
|
---|
| 114 | /*!
|
---|
| 115 | The focus is related to the complete canvas.
|
---|
| 116 | Paint the focus indicator using drawFocusIndicator()
|
---|
| 117 | */
|
---|
[4271] | 118 | CanvasFocusIndicator,
|
---|
[8127] | 119 |
|
---|
| 120 | /*!
|
---|
| 121 | The focus is related to an item (curve, point, ...) on
|
---|
| 122 | the canvas. It is up to the application to display a
|
---|
| 123 | focus indication using f.e. highlighting.
|
---|
| 124 | */
|
---|
[4271] | 125 | ItemFocusIndicator
|
---|
| 126 | };
|
---|
| 127 |
|
---|
[8127] | 128 | explicit QwtPlotCanvas( QwtPlot * = NULL );
|
---|
[4271] | 129 | virtual ~QwtPlotCanvas();
|
---|
| 130 |
|
---|
| 131 | QwtPlot *plot();
|
---|
| 132 | const QwtPlot *plot() const;
|
---|
| 133 |
|
---|
| 134 | void setFocusIndicator( FocusIndicator );
|
---|
| 135 | FocusIndicator focusIndicator() const;
|
---|
| 136 |
|
---|
| 137 | void setBorderRadius( double );
|
---|
| 138 | double borderRadius() const;
|
---|
| 139 |
|
---|
| 140 | void setPaintAttribute( PaintAttribute, bool on = true );
|
---|
| 141 | bool testPaintAttribute( PaintAttribute ) const;
|
---|
| 142 |
|
---|
| 143 | const QPixmap *backingStore() const;
|
---|
| 144 | void invalidateBackingStore();
|
---|
| 145 |
|
---|
[8127] | 146 | virtual bool event( QEvent * );
|
---|
| 147 |
|
---|
| 148 | Q_INVOKABLE QPainterPath borderPath( const QRect & ) const;
|
---|
| 149 |
|
---|
| 150 | public Q_SLOTS:
|
---|
[4271] | 151 | void replot();
|
---|
| 152 |
|
---|
| 153 | protected:
|
---|
| 154 | virtual void paintEvent( QPaintEvent * );
|
---|
| 155 | virtual void resizeEvent( QResizeEvent * );
|
---|
| 156 |
|
---|
| 157 | virtual void drawFocusIndicator( QPainter * );
|
---|
| 158 | virtual void drawBorder( QPainter * );
|
---|
| 159 |
|
---|
| 160 | void updateStyleSheetInfo();
|
---|
| 161 |
|
---|
| 162 | private:
|
---|
| 163 | void drawCanvas( QPainter *, bool withBackground );
|
---|
| 164 |
|
---|
| 165 | class PrivateData;
|
---|
| 166 | PrivateData *d_data;
|
---|
| 167 | };
|
---|
| 168 |
|
---|
| 169 | Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotCanvas::PaintAttributes )
|
---|
| 170 |
|
---|
| 171 | #endif
|
---|