Changeset 561 for trunk/src/svg/qsvgstyle_p.h
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/svg/qsvgstyle_p.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtSvg module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 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 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 142 142 { 143 143 QSvgExtraStates(); 144 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 145 153 }; 146 154 … … 170 178 }; 171 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 172 188 class QSvgQualityStyle : public QSvgStyleProperty 173 189 { … … 217 233 { 218 234 public: 219 QSvgFillStyle(const QBrush &brush); 220 QSvgFillStyle(QSvgStyleProperty *style); 235 QSvgFillStyle(); 221 236 virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states); 222 237 virtual void revert(QPainter *p, QSvgExtraStates &states); … … 225 240 void setFillRule(Qt::FillRule f); 226 241 void setFillOpacity(qreal opacity); 242 void setFillStyle(QSvgFillStyleProperty* style); 243 void setBrush(QBrush brush); 227 244 228 245 const QBrush & qbrush() const … … 230 247 return m_fill; 231 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 232 285 private: 233 286 // fill v v 'inherit' | <Paint.datatype> … … 235 288 QBrush m_fill; 236 289 QBrush m_oldFill; 237 QSvgStyleProperty *m_style; 238 239 bool m_fillRuleSet; 290 QSvgFillStyleProperty *m_style; 291 240 292 Qt::FillRule m_fillRule; 241 bool m_fillOpacitySet;293 Qt::FillRule m_oldFillRule; 242 294 qreal m_fillOpacity; 243 qreal m_oldOpacity; 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; 244 303 }; 245 304 … … 267 326 { 268 327 public: 328 static const int LIGHTER = -1; 329 static const int BOLDER = 1; 330 269 331 QSvgFontStyle(QSvgFont *font, QSvgTinyDocument *doc); 270 QSvgFontStyle(const QFont &font, QSvgTinyDocument *doc); 271 virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states); 272 virtual void revert(QPainter *p, QSvgExtraStates &states); 273 virtual Type type() const; 274 275 void setPointSize(qreal size); 276 qreal pointSize() const; 277 278 //### hack to avoid having a separate style element for text-anchor 279 QString textAnchor() const; 280 void setTextAnchor(const QString &anchor); 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 } 281 375 282 376 QSvgFont * svgFont() const 283 377 { 284 return m_font; 285 } 286 QSvgTinyDocument *doc() const 287 { 288 return m_doc; 289 } 290 291 const QFont & qfont() const 378 return m_svgFont; 379 } 380 381 const QFont &qfont() const 292 382 { 293 383 return m_qfont; 294 384 } 295 private: 296 QSvgFont *m_font; 297 qreal m_pointSize; 385 386 QSvgTinyDocument *doc() const {return m_doc;} 387 388 private: 389 QSvgFont *m_svgFont; 298 390 QSvgTinyDocument *m_doc; 299 300 QString m_textAnchor;301 302 391 QFont m_qfont; 303 QFont m_oldFont; 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; 304 407 }; 305 408 … … 307 410 { 308 411 public: 309 QSvgStrokeStyle(const QPen &pen); 310 virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states); 311 virtual void revert(QPainter *p, QSvgExtraStates &states); 312 virtual Type type() const; 313 314 const QPen & qpen() const 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 315 512 { 316 513 return m_stroke; 317 514 } 515 318 516 private: 319 517 // stroke v v 'inherit' | <Paint.datatype> … … 326 524 // stroke-width v v 'inherit' | <StrokeWidthValue.datatype> 327 525 QPen m_stroke; 328 329 526 QPen m_oldStroke; 330 }; 331 332 333 class QSvgSolidColorStyle : public QSvgStyleProperty 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 334 550 { 335 551 public: 336 552 QSvgSolidColorStyle(const QColor &color); 337 virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states);338 virtual void revert(QPainter *p, QSvgExtraStates &states);339 553 virtual Type type() const; 340 554 … … 343 557 return m_solidColor; 344 558 } 559 560 QBrush brush(QPainter *, QSvgExtraStates &) 561 { 562 return m_solidColor; 563 } 564 345 565 private: 346 566 // solid-color v x 'inherit' | <SVGColor.datatype> … … 352 572 }; 353 573 354 class QSvgGradientStyle : public QSvg StyleProperty574 class QSvgGradientStyle : public QSvgFillStyleProperty 355 575 { 356 576 public: 357 577 QSvgGradientStyle(QGradient *grad); 358 578 ~QSvgGradientStyle() { delete m_gradient; } 359 virtual void apply(QPainter *p, const QRectF &, QSvgNode *node, QSvgExtraStates &states);360 virtual void revert(QPainter *p, QSvgExtraStates &states);361 579 virtual Type type() const; 362 580 … … 376 594 } 377 595 378 void addResolve(qreal offset);379 380 596 bool gradientStopsSet() const 381 597 { … … 387 603 m_gradientStopsSet = set; 388 604 } 605 606 QBrush brush(QPainter *, QSvgExtraStates &); 389 607 private: 390 608 QGradient *m_gradient; 391 QList<qreal> m_resolvePoints;392 393 QBrush m_oldFill;394 395 609 QMatrix m_matrix; 396 610 … … 431 645 SkewY 432 646 }; 647 enum Additive 648 { 649 Sum, 650 Replace 651 }; 433 652 public: 434 653 QSvgAnimateTransform(int startMs, int endMs, int by = 0); 435 void setArgs(TransformType type, const QVector<qreal> &args);654 void setArgs(TransformType type, Additive additive, const QVector<qreal> &args); 436 655 void setFreeze(bool freeze); 437 656 void setRepeatCount(qreal repeatCount); … … 439 658 virtual void revert(QPainter *p, QSvgExtraStates &states); 440 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 441 690 protected: 442 691 void resolveMatrix(QSvgNode *node); … … 445 694 qreal m_totalRunningTime; 446 695 TransformType m_type; 696 Additive m_additive; 447 697 QVector<qreal> m_args; 448 698 int m_count; … … 452 702 bool m_freeze; 453 703 qreal m_repeatCount; 704 bool m_transformApplied; 454 705 }; 455 706
Note:
See TracChangeset
for help on using the changeset viewer.