Changeset 561 for trunk/src/gui/painting/qbrush.cpp
- 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/gui/painting/qbrush.cpp
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 QtGui 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 ** … … 218 218 // returns true if the brush has a pixmap (or bitmap) set as the 219 219 // brush texture, false otherwise 220 bool qHasPixmapTexture(const QBrush& brush)220 bool Q_GUI_EXPORT qHasPixmapTexture(const QBrush& brush) 221 221 { 222 222 if (brush.style() != Qt::TexturePattern) 223 223 return false; 224 QTexturedBrushData *tx_data = static_cast<QTexturedBrushData *>(brush.d );224 QTexturedBrushData *tx_data = static_cast<QTexturedBrushData *>(brush.d.data()); 225 225 return tx_data->m_has_pixmap_texture; 226 226 } … … 231 231 }; 232 232 233 struct QBrushDataPointerDeleter 234 { 235 static inline void deleteData(QBrushData *d) 236 { 237 switch (d->style) { 238 case Qt::TexturePattern: 239 delete static_cast<QTexturedBrushData*>(d); 240 break; 241 case Qt::LinearGradientPattern: 242 case Qt::RadialGradientPattern: 243 case Qt::ConicalGradientPattern: 244 delete static_cast<QGradientBrushData*>(d); 245 break; 246 default: 247 delete d; 248 } 249 } 250 251 static inline void cleanup(QBrushData *d) 252 { 253 if (d && !d->ref.deref()) { 254 deleteData(d); 255 } 256 } 257 }; 233 258 234 259 /*! 235 260 \class QBrush 236 \ingroup multimedia261 \ingroup painting 237 262 \ingroup shared 238 263 … … 365 390 switch(style) { 366 391 case Qt::NoBrush: 367 d = nullBrushInstance();392 d.reset(nullBrushInstance()); 368 393 d->ref.ref(); 369 394 if (d->color != color) setColor(color); 370 395 return; 371 396 case Qt::TexturePattern: 372 d = new QTexturedBrushData;397 d.reset(new QTexturedBrushData); 373 398 break; 374 399 case Qt::LinearGradientPattern: 375 400 case Qt::RadialGradientPattern: 376 401 case Qt::ConicalGradientPattern: 377 d = new QGradientBrushData;402 d.reset(new QGradientBrushData); 378 403 break; 379 404 default: 380 d = new QBrushData;405 d.reset(new QBrushData); 381 406 break; 382 407 } … … 392 417 393 418 QBrush::QBrush() 394 { 395 d = nullBrushInstance(); 419 : d(nullBrushInstance()) 420 { 396 421 Q_ASSERT(d); 397 422 d->ref.ref(); … … 436 461 init(Qt::black, style); 437 462 else { 438 d = nullBrushInstance();463 d.reset(nullBrushInstance()); 439 464 d->ref.ref(); 440 465 } … … 452 477 init(color, style); 453 478 else { 454 d = nullBrushInstance();479 d.reset(nullBrushInstance()); 455 480 d->ref.ref(); 456 481 } … … 469 494 init(color, style); 470 495 else { 471 d = nullBrushInstance();496 d.reset(nullBrushInstance()); 472 497 d->ref.ref(); 473 498 } … … 511 536 512 537 QBrush::QBrush(const QBrush &other) 513 { 514 d = other.d; 538 : d(other.d.data()) 539 { 515 540 d->ref.ref(); 516 541 } … … 536 561 537 562 init(QColor(), enum_table[gradient.type()]); 538 QGradientBrushData *grad = static_cast<QGradientBrushData *>(d );563 QGradientBrushData *grad = static_cast<QGradientBrushData *>(d.data()); 539 564 grad->gradient = gradient; 540 565 } … … 546 571 QBrush::~QBrush() 547 572 { 548 if (!d->ref.deref())549 cleanUp(d);550 573 } 551 574 552 575 void QBrush::cleanUp(QBrushData *x) 553 576 { 554 switch (x->style) { 555 case Qt::TexturePattern: 556 delete static_cast<QTexturedBrushData*>(x); 557 break; 558 case Qt::LinearGradientPattern: 559 case Qt::RadialGradientPattern: 560 case Qt::ConicalGradientPattern: 561 delete static_cast<QGradientBrushData*>(x); 562 break; 563 default: 564 delete x; 565 } 577 QBrushDataPointerDeleter::deleteData(x); 566 578 } 567 579 … … 572 584 return; 573 585 574 Q BrushData *x;586 QScopedPointer<QBrushData> x; 575 587 switch(newStyle) { 576 588 case Qt::TexturePattern: { 577 589 QTexturedBrushData *tbd = new QTexturedBrushData; 578 590 if (d->style == Qt::TexturePattern) { 579 QTexturedBrushData *data = static_cast<QTexturedBrushData *>(d );591 QTexturedBrushData *data = static_cast<QTexturedBrushData *>(d.data()); 580 592 if (data->m_has_pixmap_texture) 581 593 tbd->setPixmap(data->pixmap()); … … 583 595 tbd->setImage(data->image()); 584 596 } 585 x = tbd;597 x.reset(tbd); 586 598 break; 587 599 } … … 589 601 case Qt::RadialGradientPattern: 590 602 case Qt::ConicalGradientPattern: 591 x = new QGradientBrushData;592 static_cast<QGradientBrushData *>(x )->gradient =593 static_cast<QGradientBrushData *>(d )->gradient;603 x.reset(new QGradientBrushData); 604 static_cast<QGradientBrushData *>(x.data())->gradient = 605 static_cast<QGradientBrushData *>(d.data())->gradient; 594 606 break; 595 607 default: 596 x = new QBrushData;608 x.reset(new QBrushData); 597 609 break; 598 610 } … … 601 613 x->color = d->color; 602 614 x->transform = d->transform; 603 if (!d->ref.deref()) 604 cleanUp(d); 605 d = x; 615 d.reset(x.take()); 606 616 } 607 617 … … 616 626 QBrush &QBrush::operator=(const QBrush &b) 617 627 { 628 if (d == b.d) 629 return *this; 630 618 631 b.d->ref.ref(); 619 if (!d->ref.deref()) 620 cleanUp(d); 621 d = b.d; 632 d.reset(b.d.data()); 622 633 return *this; 623 634 } … … 714 725 if (d->style != Qt::TexturePattern) 715 726 return 0; 716 QTexturedBrushData *data = static_cast<QTexturedBrushData*>(d );727 QTexturedBrushData *data = static_cast<QTexturedBrushData*>(d.data()); 717 728 QPixmap &pixmap = data->pixmap(); 718 729 return pixmap.isNull() ? 0 : &pixmap; … … 731 742 { 732 743 return d->style == Qt::TexturePattern 733 ? ( (QTexturedBrushData*) d)->pixmap()744 ? (static_cast<QTexturedBrushData *>(d.data()))->pixmap() 734 745 : QPixmap(); 735 746 } … … 749 760 if (!pixmap.isNull()) { 750 761 detach(Qt::TexturePattern); 751 QTexturedBrushData *data = static_cast<QTexturedBrushData *>(d );762 QTexturedBrushData *data = static_cast<QTexturedBrushData *>(d.data()); 752 763 data->setPixmap(pixmap); 753 764 } else { … … 772 783 { 773 784 return d->style == Qt::TexturePattern 774 ? ( (QTexturedBrushData *) d)->image()785 ? (static_cast<QTexturedBrushData *>(d.data()))->image() 775 786 : QImage(); 776 787 } … … 797 808 if (!image.isNull()) { 798 809 detach(Qt::TexturePattern); 799 QTexturedBrushData *data = static_cast<QTexturedBrushData *>(d );810 QTexturedBrushData *data = static_cast<QTexturedBrushData *>(d.data()); 800 811 data->setImage(image); 801 812 } else { … … 813 824 || d->style == Qt::RadialGradientPattern 814 825 || d->style == Qt::ConicalGradientPattern) { 815 return &static_cast<const QGradientBrushData *>(d )->gradient;826 return &static_cast<const QGradientBrushData *>(d.data())->gradient; 816 827 } 817 828 return 0; … … 847 858 return true; 848 859 } else if (d->style == Qt::TexturePattern) { 849 return !texture().hasAlpha(); 860 return qHasPixmapTexture(*this) 861 ? !texture().hasAlphaChannel() && !texture().isQBitmap() 862 : !textureImage().hasAlphaChannel(); 850 863 } 851 864 … … 924 937 switch (d->style) { 925 938 case Qt::TexturePattern: { 926 QPixmap &us = ( (QTexturedBrushData *) d)->pixmap();927 QPixmap &them = ( (QTexturedBrushData *) b.d)->pixmap();939 QPixmap &us = (static_cast<QTexturedBrushData *>(d.data()))->pixmap(); 940 QPixmap &them = (static_cast<QTexturedBrushData *>(b.d.data()))->pixmap(); 928 941 return ((us.isNull() && them.isNull()) || us.cacheKey() == them.cacheKey()); 929 942 } … … 932 945 case Qt::ConicalGradientPattern: 933 946 { 934 QGradientBrushData *d1 = static_cast<QGradientBrushData *>(d );935 QGradientBrushData *d2 = static_cast<QGradientBrushData *>(b.d );947 QGradientBrushData *d1 = static_cast<QGradientBrushData *>(d.data()); 948 QGradientBrushData *d2 = static_cast<QGradientBrushData *>(b.d.data()); 936 949 return d1->gradient == d2->gradient; 937 950 } … … 958 971 { 959 972 #ifndef Q_BROKEN_DEBUG_STREAM 960 dbg.nospace() << "QBrush(" << b.color() << ',' << b.style() << ')'; 973 static const char *BRUSH_STYLES[] = { 974 "NoBrush", 975 "SolidPattern", 976 "Dense1Pattern", 977 "Dense2Pattern", 978 "Dense3Pattern", 979 "Dense4Pattern", 980 "Dense5Pattern", 981 "Dense6Pattern", 982 "Dense7Pattern", 983 "HorPattern", 984 "VerPattern", 985 "CrossPattern", 986 "BDiagPattern", 987 "FDiagPattern", 988 "DiagCrossPattern", 989 "LinearGradientPattern", 990 "RadialGradientPattern", 991 "ConicalGradientPattern", 992 "TexturePattern" 993 }; 994 995 dbg.nospace() << "QBrush(" << b.color() << ',' << BRUSH_STYLES[b.style()] << ')'; 961 996 return dbg.space(); 962 997 #else … … 1152 1187 /*! 1153 1188 \class QGradient 1154 \ingroup multimedia1189 \ingroup painting 1155 1190 \ingroup shared 1156 1191 … … 1516 1551 /*! 1517 1552 \class QLinearGradient 1518 \ingroup multimedia1553 \ingroup painting 1519 1554 1520 1555 \brief The QLinearGradient class is used in combination with QBrush to … … 1695 1730 /*! 1696 1731 \class QRadialGradient 1697 \ingroup multimedia1732 \ingroup painting 1698 1733 1699 1734 \brief The QRadialGradient class is used in combination with QBrush to … … 1952 1987 /*! 1953 1988 \class QConicalGradient 1954 \ingroup multimedia1989 \ingroup painting 1955 1990 1956 1991 \brief The QConicalGradient class is used in combination with QBrush to
Note:
See TracChangeset
for help on using the changeset viewer.