src/svg/qsvgstyle_p.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtSvg module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef QSVGSTYLE_P_H
       
    43 #define QSVGSTYLE_P_H
       
    44 
       
    45 //
       
    46 //  W A R N I N G
       
    47 //  -------------
       
    48 //
       
    49 // This file is not part of the Qt API.  It exists purely as an
       
    50 // implementation detail.  This header file may change from version to
       
    51 // version without notice, or even be removed.
       
    52 //
       
    53 // We mean it.
       
    54 //
       
    55 
       
    56 #include "QtGui/qpainter.h"
       
    57 
       
    58 #ifndef QT_NO_SVG
       
    59 
       
    60 #include "QtGui/qpen.h"
       
    61 #include "QtGui/qbrush.h"
       
    62 #include "QtGui/qmatrix.h"
       
    63 #include "QtGui/qcolor.h"
       
    64 #include "QtGui/qfont.h"
       
    65 #include <qdebug.h>
       
    66 
       
    67 QT_BEGIN_NAMESPACE
       
    68 
       
    69 class QPainter;
       
    70 class QSvgNode;
       
    71 class QSvgFont;
       
    72 class QSvgTinyDocument;
       
    73 
       
    74 template <class T> class QSvgRefCounter
       
    75 {
       
    76 public:
       
    77     QSvgRefCounter() { t = 0; }
       
    78     QSvgRefCounter(T *_t)
       
    79     {
       
    80         t = _t;
       
    81         if (t)
       
    82             t->ref();
       
    83     }
       
    84     QSvgRefCounter(const QSvgRefCounter &other)
       
    85     {
       
    86         t = other.t;
       
    87         if (t)
       
    88             t->ref();
       
    89     }
       
    90     QSvgRefCounter &operator =(T *_t)
       
    91     {
       
    92         if(_t)
       
    93             _t->ref();
       
    94         if (t)
       
    95             t->deref();
       
    96         t = _t;
       
    97         return *this;
       
    98     }
       
    99     QSvgRefCounter &operator =(const QSvgRefCounter &other)
       
   100     {
       
   101         if(other.t)
       
   102             other.t->ref();
       
   103         if (t)
       
   104             t->deref();
       
   105         t = other.t;
       
   106         return *this;
       
   107     }
       
   108     ~QSvgRefCounter()
       
   109     {
       
   110         if (t)
       
   111             t->deref();
       
   112     }
       
   113 
       
   114     inline T *operator->() const { return t; }
       
   115     inline operator T*() const { return t; }
       
   116 
       
   117 private:
       
   118     T *t;
       
   119 };
       
   120 
       
   121 class QSvgRefCounted
       
   122 {
       
   123 public:
       
   124     QSvgRefCounted() { _ref = 0; }
       
   125     virtual ~QSvgRefCounted() {}
       
   126     void ref() {
       
   127         ++_ref;
       
   128 //        qDebug() << this << ": adding ref, now " << _ref;
       
   129     }
       
   130     void deref() {
       
   131 //        qDebug() << this << ": removing ref, now " << _ref;
       
   132         if(!--_ref) {
       
   133 //            qDebug("     deleting");
       
   134             delete this;
       
   135         }
       
   136     }
       
   137 private:
       
   138     int _ref;
       
   139 };
       
   140 
       
   141 struct QSvgExtraStates
       
   142 {
       
   143     QSvgExtraStates();
       
   144 
       
   145     qreal fillOpacity;
       
   146     qreal strokeOpacity;
       
   147     QSvgFont *svgFont;
       
   148     Qt::Alignment textAnchor;
       
   149     int fontWeight;
       
   150     Qt::FillRule fillRule;
       
   151     qreal strokeDashOffset;
       
   152     bool vectorEffect; // true if pen is cosmetic
       
   153 };
       
   154 
       
   155 class QSvgStyleProperty : public QSvgRefCounted
       
   156 {
       
   157 public:
       
   158     enum Type
       
   159     {
       
   160         QUALITY,
       
   161         FILL,
       
   162         VIEWPORT_FILL,
       
   163         FONT,
       
   164         STROKE,
       
   165         SOLID_COLOR,
       
   166         GRADIENT,
       
   167         TRANSFORM,
       
   168         ANIMATE_TRANSFORM,
       
   169         ANIMATE_COLOR,
       
   170         OPACITY,
       
   171         COMP_OP
       
   172     };
       
   173 public:
       
   174     virtual ~QSvgStyleProperty();
       
   175     virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states)  =0;
       
   176     virtual void revert(QPainter *p, QSvgExtraStates &states) =0;
       
   177     virtual Type type() const=0;
       
   178 };
       
   179 
       
   180 class QSvgFillStyleProperty : public QSvgStyleProperty
       
   181 {
       
   182 public:
       
   183     virtual QBrush brush(QPainter *p, QSvgExtraStates &states) = 0;
       
   184     virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states);
       
   185     virtual void revert(QPainter *p, QSvgExtraStates &states);
       
   186 };
       
   187 
       
   188 class QSvgQualityStyle : public QSvgStyleProperty
       
   189 {
       
   190 public:
       
   191     QSvgQualityStyle(int color);
       
   192     virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states);
       
   193     virtual void revert(QPainter *p, QSvgExtraStates &states);
       
   194     virtual Type type() const;
       
   195 private:
       
   196     // color-render ing v 	v 	'auto' | 'optimizeSpeed' |
       
   197     //                                  'optimizeQuality' | 'inherit'
       
   198     int m_colorRendering;
       
   199 
       
   200     // shape-rendering v 	v 	'auto' | 'optimizeSpeed' | 'crispEdges' |
       
   201     //                                  'geometricPrecision' | 'inherit'
       
   202     //QSvgShapeRendering m_shapeRendering;
       
   203 
       
   204 
       
   205     // text-rendering    v 	v 	'auto' | 'optimizeSpeed' | 'optimizeLegibility'
       
   206     //                                | 'geometricPrecision' | 'inherit'
       
   207     //QSvgTextRendering m_textRendering;
       
   208 
       
   209 
       
   210     // vector-effect         v 	x 	'default' | 'non-scaling-stroke' | 'inherit'
       
   211     //QSvgVectorEffect m_vectorEffect;
       
   212 
       
   213     // image-rendering v 	v 	'auto' | 'optimizeSpeed' | 'optimizeQuality' |
       
   214     //                                      'inherit'
       
   215     //QSvgImageRendering m_imageRendering;
       
   216 };
       
   217 
       
   218 
       
   219 
       
   220 class QSvgOpacityStyle : public QSvgStyleProperty
       
   221 {
       
   222 public:
       
   223     QSvgOpacityStyle(qreal opacity);
       
   224     virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states);
       
   225     virtual void revert(QPainter *p, QSvgExtraStates &states);
       
   226     virtual Type type() const;
       
   227 private:
       
   228     qreal m_opacity;
       
   229     qreal m_oldOpacity;
       
   230 };
       
   231 
       
   232 class QSvgFillStyle : public QSvgStyleProperty
       
   233 {
       
   234 public:
       
   235     QSvgFillStyle();
       
   236     virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states);
       
   237     virtual void revert(QPainter *p, QSvgExtraStates &states);
       
   238     virtual Type type() const;
       
   239 
       
   240     void setFillRule(Qt::FillRule f);
       
   241     void setFillOpacity(qreal opacity);
       
   242     void setFillStyle(QSvgFillStyleProperty* style);
       
   243     void setBrush(QBrush brush);
       
   244 
       
   245     const QBrush & qbrush() const
       
   246     {
       
   247         return m_fill;
       
   248     }
       
   249 
       
   250     qreal fillOpacity() const
       
   251     {
       
   252         return m_fillOpacity;
       
   253     }
       
   254 
       
   255     Qt::FillRule fillRule() const
       
   256     {
       
   257         return m_fillRule;
       
   258     }
       
   259 
       
   260     QSvgFillStyleProperty* style() const
       
   261     {
       
   262         return m_style;
       
   263     }
       
   264 
       
   265     void setGradientId(const QString &Id)
       
   266     {
       
   267         m_gradientId = Id;
       
   268     }
       
   269 
       
   270     QString gradientId() const
       
   271     {
       
   272         return m_gradientId;
       
   273     }
       
   274 
       
   275     void setGradientResolved(bool resolved)
       
   276     {
       
   277         m_gradientResolved = resolved;
       
   278     }
       
   279 
       
   280     bool isGradientResolved() const
       
   281     {
       
   282         return m_gradientResolved;
       
   283     }
       
   284 
       
   285 private:
       
   286     // fill            v 	v 	'inherit' | <Paint.datatype>
       
   287     // fill-opacity    v 	v 	'inherit' | <OpacityValue.datatype>
       
   288     QBrush m_fill;
       
   289     QBrush m_oldFill;
       
   290     QSvgFillStyleProperty *m_style;
       
   291 
       
   292     Qt::FillRule m_fillRule;
       
   293     Qt::FillRule m_oldFillRule;
       
   294     qreal m_fillOpacity;
       
   295     qreal m_oldFillOpacity;
       
   296 
       
   297     QString m_gradientId;
       
   298     uint m_gradientResolved : 1;
       
   299 
       
   300     uint m_fillRuleSet : 1;
       
   301     uint m_fillOpacitySet : 1;
       
   302     uint m_fillSet : 1;
       
   303 };
       
   304 
       
   305 class QSvgViewportFillStyle : public QSvgStyleProperty
       
   306 {
       
   307 public:
       
   308     QSvgViewportFillStyle(const QBrush &brush);
       
   309     virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states);
       
   310     virtual void revert(QPainter *p, QSvgExtraStates &states);
       
   311     virtual Type type() const;
       
   312 
       
   313     const QBrush & qbrush() const
       
   314     {
       
   315         return m_viewportFill;
       
   316     }
       
   317 private:
       
   318     // viewport-fill         v 	x 	'inherit' | <Paint.datatype>
       
   319     // viewport-fill-opacity 	v 	x 	'inherit' | <OpacityValue.datatype>
       
   320     QBrush m_viewportFill;
       
   321 
       
   322     QBrush m_oldFill;
       
   323 };
       
   324 
       
   325 class QSvgFontStyle : public QSvgStyleProperty
       
   326 {
       
   327 public:
       
   328     static const int LIGHTER = -1;
       
   329     static const int BOLDER = 1;
       
   330 
       
   331     QSvgFontStyle(QSvgFont *font, QSvgTinyDocument *doc);
       
   332     QSvgFontStyle();
       
   333     virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states);
       
   334     virtual void revert(QPainter *p, QSvgExtraStates &states);
       
   335     virtual Type type() const;
       
   336 
       
   337     void setSize(qreal size)
       
   338     {
       
   339         // Store the _pixel_ size in the font. Since QFont::setPixelSize() only takes an int, call
       
   340         // QFont::SetPointSize() instead. Set proper font size just before rendering.
       
   341         m_qfont.setPointSize(size);
       
   342         m_sizeSet = 1;
       
   343     }
       
   344 
       
   345     void setTextAnchor(Qt::Alignment anchor)
       
   346     {
       
   347         m_textAnchor = anchor;
       
   348         m_textAnchorSet = 1;
       
   349     }
       
   350 
       
   351     void setFamily(const QString &family)
       
   352     {
       
   353         m_qfont.setFamily(family);
       
   354         m_familySet = 1;
       
   355     }
       
   356 
       
   357     void setStyle(QFont::Style fontStyle) {
       
   358         m_qfont.setStyle(fontStyle);
       
   359         m_styleSet = 1;
       
   360     }
       
   361 
       
   362     void setVariant(QFont::Capitalization fontVariant)
       
   363     {
       
   364         m_qfont.setCapitalization(fontVariant);
       
   365         m_variantSet = 1;
       
   366     }
       
   367 
       
   368     static int SVGToQtWeight(int weight);
       
   369 
       
   370     void setWeight(int weight)
       
   371     {
       
   372         m_weight = weight;
       
   373         m_weightSet = 1;
       
   374     }
       
   375 
       
   376     QSvgFont * svgFont() const
       
   377     {
       
   378         return m_svgFont;
       
   379     }
       
   380 
       
   381     const QFont &qfont() const
       
   382     {
       
   383         return m_qfont;
       
   384     }
       
   385 
       
   386     QSvgTinyDocument *doc() const {return m_doc;}
       
   387 
       
   388 private:
       
   389     QSvgFont *m_svgFont;
       
   390     QSvgTinyDocument *m_doc;
       
   391     QFont m_qfont;
       
   392 
       
   393     int m_weight;
       
   394     Qt::Alignment m_textAnchor;
       
   395 
       
   396     QSvgFont *m_oldSvgFont;
       
   397     QFont m_oldQFont;
       
   398     Qt::Alignment m_oldTextAnchor;
       
   399     int m_oldWeight;
       
   400 
       
   401     uint m_familySet : 1;
       
   402     uint m_sizeSet : 1;
       
   403     uint m_styleSet : 1;
       
   404     uint m_variantSet : 1;
       
   405     uint m_weightSet : 1;
       
   406     uint m_textAnchorSet : 1;
       
   407 };
       
   408 
       
   409 class QSvgStrokeStyle : public QSvgStyleProperty
       
   410 {
       
   411 public:
       
   412     QSvgStrokeStyle();
       
   413     virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states);
       
   414     virtual void revert(QPainter *p, QSvgExtraStates &states);
       
   415     virtual Type type() const;
       
   416 
       
   417     void setStroke(QBrush brush)
       
   418     {
       
   419         m_stroke.setBrush(brush);
       
   420         m_style = 0;
       
   421         m_strokeSet = 1;
       
   422     }
       
   423 
       
   424     void setStyle(QSvgFillStyleProperty *style)
       
   425     {
       
   426         m_style = style;
       
   427         m_strokeSet = 1;
       
   428     }
       
   429 
       
   430     void setDashArray(const QVector<qreal> &dashes);
       
   431 
       
   432     void setDashArrayNone()
       
   433     {
       
   434         m_stroke.setStyle(Qt::SolidLine);
       
   435         m_strokeDashArraySet = 1;
       
   436     }
       
   437 
       
   438     void setDashOffset(qreal offset)
       
   439     {
       
   440         m_strokeDashOffset = offset;
       
   441         m_strokeDashOffsetSet = 1;
       
   442     }
       
   443 
       
   444     void setLineCap(Qt::PenCapStyle cap)
       
   445     {
       
   446         m_stroke.setCapStyle(cap);
       
   447         m_strokeLineCapSet = 1;
       
   448     }
       
   449 
       
   450     void setLineJoin(Qt::PenJoinStyle join)
       
   451     {
       
   452         m_stroke.setJoinStyle(join);
       
   453         m_strokeLineJoinSet = 1;
       
   454     }
       
   455 
       
   456     void setMiterLimit(qreal limit)
       
   457     {
       
   458         m_stroke.setMiterLimit(limit);
       
   459         m_strokeMiterLimitSet = 1;
       
   460     }
       
   461 
       
   462     void setOpacity(qreal opacity)
       
   463     {
       
   464         m_strokeOpacity = opacity;
       
   465         m_strokeOpacitySet = 1;
       
   466     }
       
   467 
       
   468     void setWidth(qreal width)
       
   469     {
       
   470         m_stroke.setWidthF(width);
       
   471         m_strokeWidthSet = 1;
       
   472         Q_ASSERT(!m_strokeDashArraySet); // set width before dash array.
       
   473     }
       
   474 
       
   475     qreal width()
       
   476     {
       
   477         return m_stroke.widthF();
       
   478     }
       
   479 
       
   480     void setVectorEffect(bool nonScalingStroke)
       
   481     {
       
   482         m_vectorEffect = nonScalingStroke;
       
   483         m_vectorEffectSet = 1;
       
   484     }
       
   485 
       
   486     QSvgFillStyleProperty* style() const
       
   487     {
       
   488         return m_style;
       
   489     }
       
   490 
       
   491     void setGradientId(const QString &Id)
       
   492     {
       
   493         m_gradientId = Id;
       
   494     }
       
   495 
       
   496     QString gradientId() const
       
   497     {
       
   498         return m_gradientId;
       
   499     }
       
   500 
       
   501     void setGradientResolved(bool resolved)
       
   502     {
       
   503         m_gradientResolved = resolved;
       
   504     }
       
   505 
       
   506     bool isGradientResolved() const
       
   507     {
       
   508         return m_gradientResolved;
       
   509     }
       
   510 
       
   511     QPen stroke() const
       
   512     {
       
   513         return m_stroke;
       
   514     }
       
   515 
       
   516 private:
       
   517     // stroke            v 	v 	'inherit' | <Paint.datatype>
       
   518     // stroke-dasharray  v 	v 	'inherit' | <StrokeDashArrayValue.datatype>
       
   519     // stroke-dashoffset v 	v 	'inherit' | <StrokeDashOffsetValue.datatype>
       
   520     // stroke-linecap    v 	v 	'butt' | 'round' | 'square' | 'inherit'
       
   521     // stroke-linejoin   v 	v 	'miter' | 'round' | 'bevel' | 'inherit'
       
   522     // stroke-miterlimit v 	v 	'inherit' | <StrokeMiterLimitValue.datatype>
       
   523     // stroke-opacity    v 	v 	'inherit' | <OpacityValue.datatype>
       
   524     // stroke-width      v 	v 	'inherit' | <StrokeWidthValue.datatype>
       
   525     QPen m_stroke;
       
   526     QPen m_oldStroke;
       
   527     qreal m_strokeOpacity;
       
   528     qreal m_oldStrokeOpacity;
       
   529     qreal m_strokeDashOffset;
       
   530     qreal m_oldStrokeDashOffset;
       
   531 
       
   532     QSvgFillStyleProperty *m_style;
       
   533     QString m_gradientId;
       
   534     uint m_gradientResolved : 1;
       
   535     uint m_vectorEffect : 1;
       
   536     uint m_oldVectorEffect : 1;
       
   537 
       
   538     uint m_strokeSet : 1;
       
   539     uint m_strokeDashArraySet : 1;
       
   540     uint m_strokeDashOffsetSet : 1;
       
   541     uint m_strokeLineCapSet : 1;
       
   542     uint m_strokeLineJoinSet : 1;
       
   543     uint m_strokeMiterLimitSet : 1;
       
   544     uint m_strokeOpacitySet : 1;
       
   545     uint m_strokeWidthSet : 1;
       
   546     uint m_vectorEffectSet : 1;
       
   547 };
       
   548 
       
   549 class QSvgSolidColorStyle : public QSvgFillStyleProperty
       
   550 {
       
   551 public:
       
   552     QSvgSolidColorStyle(const QColor &color);
       
   553     virtual Type type() const;
       
   554 
       
   555     const QColor & qcolor() const
       
   556     {
       
   557         return m_solidColor;
       
   558     }
       
   559 
       
   560     QBrush brush(QPainter *, QSvgExtraStates &)
       
   561     {
       
   562         return m_solidColor;
       
   563     }
       
   564 
       
   565 private:
       
   566     // solid-color       v 	x 	'inherit' | <SVGColor.datatype>
       
   567     // solid-opacity     v 	x 	'inherit' | <OpacityValue.datatype>
       
   568     QColor m_solidColor;
       
   569 
       
   570     QBrush m_oldFill;
       
   571     QPen   m_oldStroke;
       
   572 };
       
   573 
       
   574 class QSvgGradientStyle : public QSvgFillStyleProperty
       
   575 {
       
   576 public:
       
   577     QSvgGradientStyle(QGradient *grad);
       
   578     ~QSvgGradientStyle() { delete m_gradient; }
       
   579     virtual Type type() const;
       
   580 
       
   581     void setStopLink(const QString &link, QSvgTinyDocument *doc);
       
   582     QString stopLink() const { return m_link; }
       
   583     void resolveStops();
       
   584 
       
   585     void setMatrix(const QMatrix &matrix);
       
   586     QMatrix  qmatrix() const
       
   587     {
       
   588         return m_matrix;
       
   589     }
       
   590 
       
   591     QGradient *qgradient() const
       
   592     {
       
   593         return m_gradient;
       
   594     }
       
   595 
       
   596     bool gradientStopsSet() const
       
   597     {
       
   598         return m_gradientStopsSet;
       
   599     }
       
   600 
       
   601     void setGradientStopsSet(bool set)
       
   602     {
       
   603         m_gradientStopsSet = set;
       
   604     }
       
   605 
       
   606     QBrush brush(QPainter *, QSvgExtraStates &);
       
   607 private:
       
   608     QGradient      *m_gradient;
       
   609     QMatrix m_matrix;
       
   610 
       
   611     QSvgTinyDocument *m_doc;
       
   612     QString           m_link;
       
   613     bool m_gradientStopsSet;
       
   614 };
       
   615 
       
   616 class QSvgTransformStyle : public QSvgStyleProperty
       
   617 {
       
   618 public:
       
   619     QSvgTransformStyle(const QTransform &transform);
       
   620     virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states);
       
   621     virtual void revert(QPainter *p, QSvgExtraStates &states);
       
   622     virtual Type type() const;
       
   623 
       
   624     const QTransform & qtransform() const
       
   625     {
       
   626         return m_transform;
       
   627     }
       
   628 private:
       
   629     //7.6 The transform  attribute
       
   630     QTransform m_transform;
       
   631     QTransform m_oldWorldTransform;
       
   632 };
       
   633 
       
   634 
       
   635 class QSvgAnimateTransform : public QSvgStyleProperty
       
   636 {
       
   637 public:
       
   638     enum TransformType
       
   639     {
       
   640         Empty,
       
   641         Translate,
       
   642         Scale,
       
   643         Rotate,
       
   644         SkewX,
       
   645         SkewY
       
   646     };
       
   647     enum Additive
       
   648     {
       
   649         Sum,
       
   650         Replace
       
   651     };
       
   652 public:
       
   653     QSvgAnimateTransform(int startMs, int endMs, int by = 0);
       
   654     void setArgs(TransformType type, Additive additive, const QVector<qreal> &args);
       
   655     void setFreeze(bool freeze);
       
   656     void setRepeatCount(qreal repeatCount);
       
   657     virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states);
       
   658     virtual void revert(QPainter *p, QSvgExtraStates &states);
       
   659     virtual Type type() const;
       
   660     QSvgAnimateTransform::Additive additiveType() const
       
   661     {
       
   662         return m_additive;
       
   663     }
       
   664 
       
   665     bool animActive(qreal totalTimeElapsed)
       
   666     {
       
   667         if (totalTimeElapsed < m_from)
       
   668             return false;
       
   669         if (m_freeze || m_repeatCount < 0) // fill="freeze" or repeat="indefinite"
       
   670             return true;
       
   671         if (m_totalRunningTime == 0)
       
   672             return false;
       
   673         qreal animationFrame = (totalTimeElapsed - m_from) / m_totalRunningTime;
       
   674         if (animationFrame > m_repeatCount)
       
   675             return false;
       
   676         return true;
       
   677     }
       
   678 
       
   679     bool transformApplied() const
       
   680     {
       
   681         return m_transformApplied;
       
   682     }
       
   683 
       
   684     // Call this instead of revert if you know that revert is unnecessary.
       
   685     void clearTransformApplied()
       
   686     {
       
   687         m_transformApplied = false;
       
   688     }
       
   689 
       
   690 protected:
       
   691     void resolveMatrix(QSvgNode *node);
       
   692 private:
       
   693     qreal m_from, m_to, m_by;
       
   694     qreal m_totalRunningTime;
       
   695     TransformType m_type;
       
   696     Additive m_additive;
       
   697     QVector<qreal> m_args;
       
   698     int m_count;
       
   699     QTransform m_transform;
       
   700     QTransform m_oldWorldTransform;
       
   701     bool m_finished;
       
   702     bool m_freeze;
       
   703     qreal m_repeatCount;
       
   704     bool m_transformApplied;
       
   705 };
       
   706 
       
   707 
       
   708 class QSvgAnimateColor : public QSvgStyleProperty
       
   709 {
       
   710 public:
       
   711     QSvgAnimateColor(int startMs, int endMs, int by = 0);
       
   712     void setArgs(bool fill, const QList<QColor> &colors);
       
   713     void setFreeze(bool freeze);
       
   714     void setRepeatCount(qreal repeatCount);
       
   715     virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states);
       
   716     virtual void revert(QPainter *p, QSvgExtraStates &states);
       
   717     virtual Type type() const;
       
   718 private:
       
   719     qreal m_from, m_to, m_by;
       
   720     qreal m_totalRunningTime;
       
   721     QList<QColor> m_colors;
       
   722     QBrush m_oldBrush;
       
   723     QPen   m_oldPen;
       
   724     bool m_fill;
       
   725     bool m_finished;
       
   726     bool m_freeze;
       
   727     qreal m_repeatCount;
       
   728 };
       
   729 
       
   730 
       
   731 class QSvgCompOpStyle : public QSvgStyleProperty
       
   732 {
       
   733 public:
       
   734     QSvgCompOpStyle(QPainter::CompositionMode mode);
       
   735     virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states);
       
   736     virtual void revert(QPainter *p, QSvgExtraStates &states);
       
   737     virtual Type type() const;
       
   738 
       
   739     const QPainter::CompositionMode & compOp() const
       
   740     {
       
   741         return m_mode;
       
   742     }
       
   743 private:
       
   744     //comp-op attribute
       
   745     QPainter::CompositionMode m_mode;
       
   746 
       
   747     QPainter::CompositionMode m_oldMode;
       
   748 };
       
   749 
       
   750 
       
   751 class QSvgStyle
       
   752 {
       
   753 public:
       
   754     QSvgStyle()
       
   755         : quality(0),
       
   756           fill(0),
       
   757           viewportFill(0),
       
   758           font(0),
       
   759           stroke(0),
       
   760           solidColor(0),
       
   761           gradient(0),
       
   762           transform(0),
       
   763           animateColor(0),
       
   764           opacity(0),
       
   765           compop(0)
       
   766     {}
       
   767     ~QSvgStyle();
       
   768 
       
   769     void apply(QPainter *p, const QRectF &rect, QSvgNode *node, QSvgExtraStates &states);
       
   770     void revert(QPainter *p, QSvgExtraStates &states);
       
   771     QSvgRefCounter<QSvgQualityStyle>      quality;
       
   772     QSvgRefCounter<QSvgFillStyle>         fill;
       
   773     QSvgRefCounter<QSvgViewportFillStyle> viewportFill;
       
   774     QSvgRefCounter<QSvgFontStyle>         font;
       
   775     QSvgRefCounter<QSvgStrokeStyle>       stroke;
       
   776     QSvgRefCounter<QSvgSolidColorStyle>   solidColor;
       
   777     QSvgRefCounter<QSvgGradientStyle>     gradient;
       
   778     QSvgRefCounter<QSvgTransformStyle>    transform;
       
   779     QSvgRefCounter<QSvgAnimateColor>      animateColor;
       
   780     QList<QSvgRefCounter<QSvgAnimateTransform> >   animateTransforms;
       
   781     QSvgRefCounter<QSvgOpacityStyle>      opacity;
       
   782     QSvgRefCounter<QSvgCompOpStyle>       compop;
       
   783 };
       
   784 
       
   785 /********************************************************/
       
   786 // NOT implemented:
       
   787 
       
   788 // color           v 	v 	'inherit' | <Color.datatype>
       
   789 //QColor m_color;
       
   790 
       
   791 // display         v 	x 	'inline' | 'block' | 'list-item'
       
   792 //                                 | 'run-in' | 'compact' | 'marker' |
       
   793 //                                 'table' | 'inline-table' |
       
   794 //                                 'table-row-group' | 'table-header-group' |
       
   795 //                                 'table-footer-group' | 'table-row' |
       
   796 //                                 'table-column-group' | 'table-column' |
       
   797 //                                 'table-cell' | 'table-caption' |
       
   798 //                                 'none' | 'inherit'
       
   799 //QSvgDisplayStyle m_display;
       
   800 
       
   801 // display-align   v 	v 	'auto' | 'before' | 'center' | 'after' | 'inherit'
       
   802 //QSvgDisplayAlign m_displayAlign;
       
   803 
       
   804 // line-increment  v 	v 	'auto' | 'inherit' | <Number.datatype>
       
   805 //int m_lineIncrement;
       
   806 
       
   807 // text-anchor       v 	v 	'start' | 'middle' | 'end' | 'inherit'
       
   808 //QSvgTextAnchor m_textAnchor;
       
   809 
       
   810 // visibility 	v 	v 	'visible' | 'hidden' | 'inherit'
       
   811 //QSvgVisibility m_visibility;
       
   812 
       
   813 /******************************************************/
       
   814 // the following do not make sense for us
       
   815 
       
   816 // pointer-events  v 	v 	'visiblePainted' | 'visibleFill' | 'visibleStroke' |
       
   817 //                              'visible' | 'painted' | 'fill' | 'stroke' | 'all' |
       
   818 //                              'none' | 'inherit'
       
   819 //QSvgPointEvents m_pointerEvents;
       
   820 
       
   821 // audio-level     v  	x  	'inherit' | <Number.datatype>
       
   822 
       
   823 QT_END_NAMESPACE
       
   824 
       
   825 #endif // QT_NO_SVG
       
   826 #endif // QSVGSTYLE_P_H