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