qwt_plot_canvas.h 4.84 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
5
 *
pixhawk's avatar
pixhawk committed
6 7 8 9 10 11 12 13
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the Qwt License, Version 1.0
 *****************************************************************************/

#ifndef QWT_PLOT_CANVAS_H
#define QWT_PLOT_CANVAS_H

#include "qwt_global.h"
Bryant's avatar
Bryant committed
14 15
#include <qframe.h>
#include <qpainterpath.h>
pixhawk's avatar
pixhawk committed
16 17 18 19 20

class QwtPlot;
class QPixmap;

/*!
Bryant's avatar
Bryant committed
21 22 23 24 25
  \brief Canvas of a QwtPlot.
  
   Canvas is the widget where all plot items are displayed

  \sa QwtPlot::setCanvas(), QwtPlotGLCanvas
pixhawk's avatar
pixhawk committed
26 27 28 29 30
*/
class QWT_EXPORT QwtPlotCanvas : public QFrame
{
    Q_OBJECT

Bryant's avatar
Bryant committed
31 32
    Q_PROPERTY( double borderRadius READ borderRadius WRITE setBorderRadius )

pixhawk's avatar
pixhawk committed
33 34 35 36
public:

    /*!
      \brief Paint attributes
37

Bryant's avatar
Bryant committed
38
      The default setting enables BackingStore and Opaque.
pixhawk's avatar
pixhawk committed
39

Bryant's avatar
Bryant committed
40
      \sa setPaintAttribute(), testPaintAttribute()
pixhawk's avatar
pixhawk committed
41
     */
Bryant's avatar
Bryant committed
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
    enum PaintAttribute
    {
        /*!
          \brief Paint double buffered reusing the content 
                 of the pixmap buffer when possible. 

          Using a backing store might improve the performance
          significantly, when working with widget overlays ( like rubber bands ).
          Disabling the cache might improve the performance for
          incremental paints (using QwtPlotDirectPainter ).

          \sa backingStore(), invalidateBackingStore()
         */
        BackingStore = 1,

        /*!
          \brief Try to fill the complete contents rectangle
                 of the plot canvas

          When using styled backgrounds Qt assumes, that the
          canvas doesn't fill its area completely 
          ( f.e because of rounded borders ) and fills the area
          below the canvas. When this is done with gradients it might
          result in a serious performance bottleneck - depending on the size.

          When the Opaque attribute is enabled the canvas tries to
          identify the gaps with some heuristics and to fill those only. 

          \warning Will not work for semitransparent backgrounds 
         */
        Opaque       = 2,

        /*!
          \brief Try to improve painting of styled backgrounds

          QwtPlotCanvas supports the box model attributes for
          customizing the layout with style sheets. Unfortunately
          the design of Qt style sheets has no concept how to
          handle backgrounds with rounded corners - beside of padding.

          When HackStyledBackground is enabled the plot canvas tries
          to separate the background from the background border
          by reverse engineering to paint the background before and
          the border after the plot items. In this order the border
          gets perfectly antialiased and you can avoid some pixel
          artifacts in the corners.
         */
        HackStyledBackground = 4,

        /*!
          When ImmediatePaint is set replot() calls repaint()
          instead of update().

          \sa replot(), QWidget::repaint(), QWidget::update()
         */
        ImmediatePaint = 8
pixhawk's avatar
pixhawk committed
98 99
    };

Bryant's avatar
Bryant committed
100 101 102
    //! Paint attributes
    typedef QFlags<PaintAttribute> PaintAttributes;

pixhawk's avatar
pixhawk committed
103 104
    /*!
      \brief Focus indicator
Bryant's avatar
Bryant committed
105
      The default setting is NoFocusIndicator
pixhawk's avatar
pixhawk committed
106 107 108
      \sa setFocusIndicator(), focusIndicator(), paintFocus()
    */

Bryant's avatar
Bryant committed
109 110 111
    enum FocusIndicator
    {
        //! Don't paint a focus indicator
pixhawk's avatar
pixhawk committed
112
        NoFocusIndicator,
Bryant's avatar
Bryant committed
113 114 115 116 117

        /*!
          The focus is related to the complete canvas.
          Paint the focus indicator using paintFocus()
         */
pixhawk's avatar
pixhawk committed
118
        CanvasFocusIndicator,
Bryant's avatar
Bryant committed
119 120 121 122 123 124

        /*!
          The focus is related to an item (curve, point, ...) on
          the canvas. It is up to the application to display a
          focus indication using f.e. highlighting.
         */
pixhawk's avatar
pixhawk committed
125 126 127
        ItemFocusIndicator
    };

Bryant's avatar
Bryant committed
128
    explicit QwtPlotCanvas( QwtPlot * = NULL );
pixhawk's avatar
pixhawk committed
129 130 131 132 133
    virtual ~QwtPlotCanvas();

    QwtPlot *plot();
    const QwtPlot *plot() const;

Bryant's avatar
Bryant committed
134
    void setFocusIndicator( FocusIndicator );
pixhawk's avatar
pixhawk committed
135 136
    FocusIndicator focusIndicator() const;

Bryant's avatar
Bryant committed
137 138
    void setBorderRadius( double );
    double borderRadius() const;
pixhawk's avatar
pixhawk committed
139

Bryant's avatar
Bryant committed
140 141
    void setPaintAttribute( PaintAttribute, bool on = true );
    bool testPaintAttribute( PaintAttribute ) const;
pixhawk's avatar
pixhawk committed
142

Bryant's avatar
Bryant committed
143 144
    const QPixmap *backingStore() const;
    void invalidateBackingStore();
pixhawk's avatar
pixhawk committed
145

Bryant's avatar
Bryant committed
146
    virtual bool event( QEvent * );
pixhawk's avatar
pixhawk committed
147

Bryant's avatar
Bryant committed
148
    Q_INVOKABLE QPainterPath borderPath( const QRect & ) const;
pixhawk's avatar
pixhawk committed
149

Bryant's avatar
Bryant committed
150 151 152 153 154 155 156 157 158 159 160
public Q_SLOTS:
    void replot();

protected:
    virtual void paintEvent( QPaintEvent * );
    virtual void resizeEvent( QResizeEvent * );

    virtual void drawFocusIndicator( QPainter * );
    virtual void drawBorder( QPainter * );

    void updateStyleSheetInfo();
pixhawk's avatar
pixhawk committed
161

162
private:
Bryant's avatar
Bryant committed
163
    void drawCanvas( QPainter *, bool withBackground );
pixhawk's avatar
pixhawk committed
164 165 166 167 168

    class PrivateData;
    PrivateData *d_data;
};

Bryant's avatar
Bryant committed
169 170
Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotCanvas::PaintAttributes )

pixhawk's avatar
pixhawk committed
171
#endif