[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_SYMBOL_H
|
---|
| 11 | #define QWT_SYMBOL_H
|
---|
| 12 |
|
---|
| 13 | #include "qwt_global.h"
|
---|
[8127] | 14 | #include <qpolygon.h>
|
---|
[4271] | 15 |
|
---|
| 16 | class QPainter;
|
---|
| 17 | class QRect;
|
---|
| 18 | class QSize;
|
---|
| 19 | class QBrush;
|
---|
| 20 | class QPen;
|
---|
| 21 | class QColor;
|
---|
| 22 | class QPointF;
|
---|
[8127] | 23 | class QPolygonF;
|
---|
| 24 | class QPainterPath;
|
---|
| 25 | class QPixmap;
|
---|
| 26 | class QByteArray;
|
---|
| 27 | class QwtGraphic;
|
---|
[4271] | 28 |
|
---|
| 29 | //! A class for drawing symbols
|
---|
| 30 | class QWT_EXPORT QwtSymbol
|
---|
| 31 | {
|
---|
| 32 | public:
|
---|
| 33 | /*!
|
---|
| 34 | Symbol Style
|
---|
| 35 | \sa setStyle(), style()
|
---|
| 36 | */
|
---|
| 37 | enum Style
|
---|
| 38 | {
|
---|
| 39 | //! No Style. The symbol cannot be drawn.
|
---|
| 40 | NoSymbol = -1,
|
---|
| 41 |
|
---|
| 42 | //! Ellipse or circle
|
---|
| 43 | Ellipse,
|
---|
| 44 |
|
---|
| 45 | //! Rectangle
|
---|
| 46 | Rect,
|
---|
| 47 |
|
---|
| 48 | //! Diamond
|
---|
| 49 | Diamond,
|
---|
| 50 |
|
---|
| 51 | //! Triangle pointing upwards
|
---|
| 52 | Triangle,
|
---|
| 53 |
|
---|
| 54 | //! Triangle pointing downwards
|
---|
| 55 | DTriangle,
|
---|
| 56 |
|
---|
| 57 | //! Triangle pointing upwards
|
---|
| 58 | UTriangle,
|
---|
| 59 |
|
---|
| 60 | //! Triangle pointing left
|
---|
| 61 | LTriangle,
|
---|
| 62 |
|
---|
| 63 | //! Triangle pointing right
|
---|
| 64 | RTriangle,
|
---|
| 65 |
|
---|
| 66 | //! Cross (+)
|
---|
| 67 | Cross,
|
---|
| 68 |
|
---|
| 69 | //! Diagonal cross (X)
|
---|
| 70 | XCross,
|
---|
| 71 |
|
---|
| 72 | //! Horizontal line
|
---|
| 73 | HLine,
|
---|
| 74 |
|
---|
| 75 | //! Vertical line
|
---|
| 76 | VLine,
|
---|
| 77 |
|
---|
| 78 | //! X combined with +
|
---|
| 79 | Star1,
|
---|
| 80 |
|
---|
| 81 | //! Six-pointed star
|
---|
| 82 | Star2,
|
---|
| 83 |
|
---|
| 84 | //! Hexagon
|
---|
| 85 | Hexagon,
|
---|
| 86 |
|
---|
| 87 | /*!
|
---|
[8127] | 88 | The symbol is represented by a painter path, where the
|
---|
| 89 | origin ( 0, 0 ) of the path coordinate system is mapped to
|
---|
| 90 | the position of the symbol.
|
---|
| 91 |
|
---|
| 92 | \sa setPath(), path()
|
---|
| 93 | */
|
---|
| 94 | Path,
|
---|
| 95 |
|
---|
| 96 | /*!
|
---|
| 97 | The symbol is represented by a pixmap. The pixmap is centered
|
---|
| 98 | or aligned to its pin point.
|
---|
| 99 |
|
---|
| 100 | \sa setPinPoint()
|
---|
| 101 | */
|
---|
| 102 | Pixmap,
|
---|
| 103 |
|
---|
| 104 | /*!
|
---|
| 105 | The symbol is represented by a graphic. The graphic is centered
|
---|
| 106 | or aligned to its pin point.
|
---|
| 107 |
|
---|
| 108 | \sa setPinPoint()
|
---|
| 109 | */
|
---|
| 110 | Graphic,
|
---|
| 111 |
|
---|
| 112 | /*!
|
---|
| 113 | The symbol is represented by a SVG graphic. The graphic is centered
|
---|
| 114 | or aligned to its pin point.
|
---|
| 115 |
|
---|
| 116 | \sa setPinPoint()
|
---|
| 117 | */
|
---|
| 118 | SvgDocument,
|
---|
| 119 |
|
---|
| 120 | /*!
|
---|
[4271] | 121 | Styles >= QwtSymbol::UserSymbol are reserved for derived
|
---|
| 122 | classes of QwtSymbol that overload drawSymbols() with
|
---|
| 123 | additional application specific symbol types.
|
---|
| 124 | */
|
---|
| 125 | UserStyle = 1000
|
---|
| 126 | };
|
---|
| 127 |
|
---|
[8127] | 128 | /*!
|
---|
| 129 | Depending on the render engine and the complexity of the
|
---|
| 130 | symbol shape it might be faster to render the symbol
|
---|
| 131 | to a pixmap and to paint this pixmap.
|
---|
| 132 |
|
---|
| 133 | F.e. the raster paint engine is a pure software renderer
|
---|
| 134 | where in cache mode a draw operation usually ends in
|
---|
| 135 | raster operation with the the backing store, that are usually
|
---|
| 136 | faster, than the algorithms for rendering polygons.
|
---|
| 137 | But the opposite can be expected for graphic pipelines
|
---|
| 138 | that can make use of hardware acceleration.
|
---|
| 139 |
|
---|
| 140 | The default setting is AutoCache
|
---|
| 141 |
|
---|
| 142 | \sa setCachePolicy(), cachePolicy()
|
---|
| 143 |
|
---|
| 144 | \note The policy has no effect, when the symbol is painted
|
---|
| 145 | to a vector graphics format ( PDF, SVG ).
|
---|
| 146 | \warning Since Qt 4.8 raster is the default backend on X11
|
---|
| 147 | */
|
---|
| 148 |
|
---|
| 149 | enum CachePolicy
|
---|
| 150 | {
|
---|
| 151 | //! Don't use a pixmap cache
|
---|
| 152 | NoCache,
|
---|
| 153 |
|
---|
| 154 | //! Always use a pixmap cache
|
---|
| 155 | Cache,
|
---|
| 156 |
|
---|
| 157 | /*!
|
---|
| 158 | Use a cache when one of the following conditions is true:
|
---|
| 159 |
|
---|
| 160 | - The symbol is rendered with the software
|
---|
| 161 | renderer ( QPaintEngine::Raster )
|
---|
| 162 | */
|
---|
| 163 | AutoCache
|
---|
| 164 | };
|
---|
| 165 |
|
---|
[4271] | 166 | public:
|
---|
| 167 | QwtSymbol( Style = NoSymbol );
|
---|
| 168 | QwtSymbol( Style, const QBrush &, const QPen &, const QSize & );
|
---|
[8127] | 169 | QwtSymbol( const QPainterPath &, const QBrush &, const QPen & );
|
---|
| 170 |
|
---|
[4271] | 171 | virtual ~QwtSymbol();
|
---|
| 172 |
|
---|
[8127] | 173 | void setCachePolicy( CachePolicy );
|
---|
| 174 | CachePolicy cachePolicy() const;
|
---|
[4271] | 175 |
|
---|
| 176 | void setSize( const QSize & );
|
---|
| 177 | void setSize( int width, int height = -1 );
|
---|
| 178 | const QSize& size() const;
|
---|
| 179 |
|
---|
[8127] | 180 | void setPinPoint( const QPointF &pos, bool enable = true );
|
---|
| 181 | QPointF pinPoint() const;
|
---|
| 182 |
|
---|
| 183 | void setPinPointEnabled( bool );
|
---|
| 184 | bool isPinPointEnabled() const;
|
---|
| 185 |
|
---|
[4271] | 186 | virtual void setColor( const QColor & );
|
---|
| 187 |
|
---|
| 188 | void setBrush( const QBrush& b );
|
---|
| 189 | const QBrush& brush() const;
|
---|
| 190 |
|
---|
[8127] | 191 | void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
|
---|
[4271] | 192 | void setPen( const QPen & );
|
---|
| 193 | const QPen& pen() const;
|
---|
| 194 |
|
---|
| 195 | void setStyle( Style );
|
---|
| 196 | Style style() const;
|
---|
| 197 |
|
---|
[8127] | 198 | void setPath( const QPainterPath & );
|
---|
| 199 | const QPainterPath &path() const;
|
---|
| 200 |
|
---|
| 201 | void setPixmap( const QPixmap & );
|
---|
| 202 | const QPixmap &pixmap() const;
|
---|
| 203 |
|
---|
| 204 | void setGraphic( const QwtGraphic & );
|
---|
| 205 | const QwtGraphic &graphic() const;
|
---|
| 206 |
|
---|
| 207 | #ifndef QWT_NO_SVG
|
---|
| 208 | void setSvgDocument( const QByteArray & );
|
---|
| 209 | #endif
|
---|
| 210 |
|
---|
| 211 | void drawSymbol( QPainter *, const QRectF & ) const;
|
---|
[4271] | 212 | void drawSymbol( QPainter *, const QPointF & ) const;
|
---|
| 213 | void drawSymbols( QPainter *, const QPolygonF & ) const;
|
---|
[8127] | 214 | void drawSymbols( QPainter *,
|
---|
| 215 | const QPointF *, int numPoints ) const;
|
---|
[4271] | 216 |
|
---|
[8127] | 217 | virtual QRect boundingRect() const;
|
---|
| 218 | void invalidateCache();
|
---|
[4271] | 219 |
|
---|
| 220 | protected:
|
---|
[8127] | 221 | virtual void renderSymbols( QPainter *,
|
---|
[4271] | 222 | const QPointF *, int numPoints ) const;
|
---|
| 223 |
|
---|
| 224 | private:
|
---|
[8127] | 225 | // Disabled copy constructor and operator=
|
---|
| 226 | QwtSymbol( const QwtSymbol & );
|
---|
| 227 | QwtSymbol &operator=( const QwtSymbol & );
|
---|
| 228 |
|
---|
[4271] | 229 | class PrivateData;
|
---|
| 230 | PrivateData *d_data;
|
---|
| 231 | };
|
---|
| 232 |
|
---|
| 233 | /*!
|
---|
| 234 | \brief Draw the symbol at a specified position
|
---|
| 235 |
|
---|
| 236 | \param painter Painter
|
---|
| 237 | \param pos Position of the symbol in screen coordinates
|
---|
| 238 | */
|
---|
| 239 | inline void QwtSymbol::drawSymbol(
|
---|
| 240 | QPainter *painter, const QPointF &pos ) const
|
---|
| 241 | {
|
---|
| 242 | drawSymbols( painter, &pos, 1 );
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | /*!
|
---|
| 246 | \brief Draw symbols at the specified points
|
---|
| 247 |
|
---|
| 248 | \param painter Painter
|
---|
| 249 | \param points Positions of the symbols in screen coordinates
|
---|
| 250 | */
|
---|
| 251 |
|
---|
| 252 | inline void QwtSymbol::drawSymbols(
|
---|
| 253 | QPainter *painter, const QPolygonF &points ) const
|
---|
| 254 | {
|
---|
| 255 | drawSymbols( painter, points.data(), points.size() );
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 | #endif
|
---|