Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-10 10:22:04

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QBRUSH_H
0005 #define QBRUSH_H
0006 
0007 #include <QtGui/qtguiglobal.h>
0008 #include <QtCore/qlist.h>
0009 #include <QtCore/qpoint.h>
0010 #include <QtCore/qscopedpointer.h>
0011 #include <QtGui/qcolor.h>
0012 #include <QtGui/qimage.h>
0013 #include <QtGui/qpixmap.h>
0014 #include <QtGui/qtransform.h>
0015 
0016 QT_BEGIN_NAMESPACE
0017 
0018 
0019 struct QBrushData;
0020 class QPixmap;
0021 class QGradient;
0022 class QVariant;
0023 struct QBrushDataPointerDeleter
0024 {
0025     void operator()(QBrushData *d) const noexcept;
0026 };
0027 
0028 class Q_GUI_EXPORT QBrush
0029 {
0030 public:
0031     QBrush();
0032     QBrush(Qt::BrushStyle bs);
0033     QBrush(const QColor &color, Qt::BrushStyle bs=Qt::SolidPattern);
0034     QBrush(Qt::GlobalColor color, Qt::BrushStyle bs=Qt::SolidPattern);
0035 
0036     QBrush(const QColor &color, const QPixmap &pixmap);
0037     QBrush(Qt::GlobalColor color, const QPixmap &pixmap);
0038     QBrush(const QPixmap &pixmap);
0039     QBrush(const QImage &image);
0040 
0041     QBrush(const QBrush &brush);
0042 
0043     QBrush(const QGradient &gradient);
0044 
0045     ~QBrush();
0046     QBrush &operator=(const QBrush &brush);
0047     QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QBrush)
0048     inline void swap(QBrush &other) noexcept
0049     { d.swap(other.d); }
0050 
0051     QBrush &operator=(Qt::BrushStyle style);
0052     QBrush &operator=(QColor color);
0053     QBrush &operator=(Qt::GlobalColor color) { return operator=(QColor(color)); }
0054 
0055     operator QVariant() const;
0056 
0057     inline Qt::BrushStyle style() const;
0058     void setStyle(Qt::BrushStyle);
0059 
0060     inline QTransform transform() const;
0061     void setTransform(const QTransform &);
0062 
0063     QPixmap texture() const;
0064     void setTexture(const QPixmap &pixmap);
0065 
0066     QImage textureImage() const;
0067     void setTextureImage(const QImage &image);
0068 
0069     inline const QColor &color() const;
0070     void setColor(const QColor &color);
0071     inline void setColor(Qt::GlobalColor color);
0072 
0073     const QGradient *gradient() const;
0074 
0075     bool isOpaque() const;
0076 
0077     bool operator==(const QBrush &b) const;
0078     inline bool operator!=(const QBrush &b) const { return !(operator==(b)); }
0079 
0080     using DataPtr = std::unique_ptr<QBrushData, QBrushDataPointerDeleter>;
0081 
0082 private:
0083     friend class QRasterPaintEngine;
0084     friend class QRasterPaintEnginePrivate;
0085     friend struct QSpanData;
0086     friend class QPainter;
0087     friend bool Q_GUI_EXPORT qHasPixmapTexture(const QBrush& brush);
0088 
0089     bool doCompareEqualColor(QColor rhs) const noexcept;
0090     friend bool comparesEqual(const QBrush &lhs, QColor rhs) noexcept
0091     {
0092         return lhs.doCompareEqualColor(rhs);
0093     }
0094     Q_DECLARE_EQUALITY_COMPARABLE(QBrush, QColor)
0095     Q_DECLARE_EQUALITY_COMPARABLE(QBrush, Qt::GlobalColor)
0096 
0097     bool doCompareEqualStyle(Qt::BrushStyle rhs) const noexcept;
0098     friend bool comparesEqual(const QBrush &lhs, Qt::BrushStyle rhs) noexcept
0099     {
0100         return lhs.doCompareEqualStyle(rhs);
0101     }
0102     Q_DECLARE_EQUALITY_COMPARABLE(QBrush, Qt::BrushStyle)
0103 
0104     void detach(Qt::BrushStyle newStyle);
0105     void init(const QColor &color, Qt::BrushStyle bs);
0106     DataPtr d;
0107 
0108 public:
0109     inline bool isDetached() const;
0110     inline DataPtr &data_ptr() { return d; }
0111 };
0112 
0113 inline void QBrush::setColor(Qt::GlobalColor acolor)
0114 { setColor(QColor(acolor)); }
0115 
0116 Q_DECLARE_SHARED(QBrush)
0117 
0118 /*****************************************************************************
0119   QBrush stream functions
0120  *****************************************************************************/
0121 
0122 #ifndef QT_NO_DATASTREAM
0123 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QBrush &);
0124 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QBrush &);
0125 #endif
0126 
0127 #ifndef QT_NO_DEBUG_STREAM
0128 Q_GUI_EXPORT QDebug operator<<(QDebug, const QBrush &);
0129 #endif
0130 
0131 struct QBrushData
0132 {
0133     QAtomicInt ref;
0134     Qt::BrushStyle style;
0135     QColor color;
0136     QTransform transform;
0137 protected:
0138     QBrushData() = default;
0139     QT_DECLARE_RO5_SMF_AS_DEFAULTED(QBrushData)
0140 };
0141 
0142 inline Qt::BrushStyle QBrush::style() const { return d->style; }
0143 inline const QColor &QBrush::color() const { return d->color; }
0144 inline QTransform QBrush::transform() const { return d->transform; }
0145 inline bool QBrush::isDetached() const { return d->ref.loadRelaxed() == 1; }
0146 
0147 
0148 /*******************************************************************************
0149  * QGradients
0150  */
0151 class QGradientPrivate;
0152 
0153 typedef std::pair<qreal, QColor> QGradientStop;
0154 typedef QList<QGradientStop> QGradientStops;
0155 
0156 class Q_GUI_EXPORT QGradient
0157 {
0158     Q_GADGET
0159 public:
0160     enum Type {
0161         LinearGradient,
0162         RadialGradient,
0163         ConicalGradient,
0164         NoGradient
0165     };
0166     Q_ENUM(Type)
0167 
0168     enum Spread {
0169         PadSpread,
0170         ReflectSpread,
0171         RepeatSpread
0172     };
0173     Q_ENUM(Spread)
0174 
0175     enum CoordinateMode {
0176         LogicalMode,
0177         StretchToDeviceMode,
0178         ObjectBoundingMode,
0179         ObjectMode
0180     };
0181     Q_ENUM(CoordinateMode)
0182 
0183     enum InterpolationMode {
0184         ColorInterpolation,
0185         ComponentInterpolation
0186     };
0187 
0188     enum Preset {
0189         WarmFlame = 1,
0190         NightFade = 2,
0191         SpringWarmth = 3,
0192         JuicyPeach = 4,
0193         YoungPassion = 5,
0194         LadyLips = 6,
0195         SunnyMorning = 7,
0196         RainyAshville = 8,
0197         FrozenDreams = 9,
0198         WinterNeva = 10,
0199         DustyGrass = 11,
0200         TemptingAzure = 12,
0201         HeavyRain = 13,
0202         AmyCrisp = 14,
0203         MeanFruit = 15,
0204         DeepBlue = 16,
0205         RipeMalinka = 17,
0206         CloudyKnoxville = 18,
0207         MalibuBeach = 19,
0208         NewLife = 20,
0209         TrueSunset = 21,
0210         MorpheusDen = 22,
0211         RareWind = 23,
0212         NearMoon = 24,
0213         WildApple = 25,
0214         SaintPetersburg = 26,
0215         PlumPlate = 28,
0216         EverlastingSky = 29,
0217         HappyFisher = 30,
0218         Blessing = 31,
0219         SharpeyeEagle = 32,
0220         LadogaBottom = 33,
0221         LemonGate = 34,
0222         ItmeoBranding = 35,
0223         ZeusMiracle = 36,
0224         OldHat = 37,
0225         StarWine = 38,
0226         HappyAcid = 41,
0227         AwesomePine = 42,
0228         NewYork = 43,
0229         ShyRainbow = 44,
0230         MixedHopes = 46,
0231         FlyHigh = 47,
0232         StrongBliss = 48,
0233         FreshMilk = 49,
0234         SnowAgain = 50,
0235         FebruaryInk = 51,
0236         KindSteel = 52,
0237         SoftGrass = 53,
0238         GrownEarly = 54,
0239         SharpBlues = 55,
0240         ShadyWater = 56,
0241         DirtyBeauty = 57,
0242         GreatWhale = 58,
0243         TeenNotebook = 59,
0244         PoliteRumors = 60,
0245         SweetPeriod = 61,
0246         WideMatrix = 62,
0247         SoftCherish = 63,
0248         RedSalvation = 64,
0249         BurningSpring = 65,
0250         NightParty = 66,
0251         SkyGlider = 67,
0252         HeavenPeach = 68,
0253         PurpleDivision = 69,
0254         AquaSplash = 70,
0255         SpikyNaga = 72,
0256         LoveKiss = 73,
0257         CleanMirror = 75,
0258         PremiumDark = 76,
0259         ColdEvening = 77,
0260         CochitiLake = 78,
0261         SummerGames = 79,
0262         PassionateBed = 80,
0263         MountainRock = 81,
0264         DesertHump = 82,
0265         JungleDay = 83,
0266         PhoenixStart = 84,
0267         OctoberSilence = 85,
0268         FarawayRiver = 86,
0269         AlchemistLab = 87,
0270         OverSun = 88,
0271         PremiumWhite = 89,
0272         MarsParty = 90,
0273         EternalConstance = 91,
0274         JapanBlush = 92,
0275         SmilingRain = 93,
0276         CloudyApple = 94,
0277         BigMango = 95,
0278         HealthyWater = 96,
0279         AmourAmour = 97,
0280         RiskyConcrete = 98,
0281         StrongStick = 99,
0282         ViciousStance = 100,
0283         PaloAlto = 101,
0284         HappyMemories = 102,
0285         MidnightBloom = 103,
0286         Crystalline = 104,
0287         PartyBliss = 106,
0288         ConfidentCloud = 107,
0289         LeCocktail = 108,
0290         RiverCity = 109,
0291         FrozenBerry = 110,
0292         ChildCare = 112,
0293         FlyingLemon = 113,
0294         NewRetrowave = 114,
0295         HiddenJaguar = 115,
0296         AboveTheSky = 116,
0297         Nega = 117,
0298         DenseWater = 118,
0299         Seashore = 120,
0300         MarbleWall = 121,
0301         CheerfulCaramel = 122,
0302         NightSky = 123,
0303         MagicLake = 124,
0304         YoungGrass = 125,
0305         ColorfulPeach = 126,
0306         GentleCare = 127,
0307         PlumBath = 128,
0308         HappyUnicorn = 129,
0309         AfricanField = 131,
0310         SolidStone = 132,
0311         OrangeJuice = 133,
0312         GlassWater = 134,
0313         NorthMiracle = 136,
0314         FruitBlend = 137,
0315         MillenniumPine = 138,
0316         HighFlight = 139,
0317         MoleHall = 140,
0318         SpaceShift = 142,
0319         ForestInei = 143,
0320         RoyalGarden = 144,
0321         RichMetal = 145,
0322         JuicyCake = 146,
0323         SmartIndigo = 147,
0324         SandStrike = 148,
0325         NorseBeauty = 149,
0326         AquaGuidance = 150,
0327         SunVeggie = 151,
0328         SeaLord = 152,
0329         BlackSea = 153,
0330         GrassShampoo = 154,
0331         LandingAircraft = 155,
0332         WitchDance = 156,
0333         SleeplessNight = 157,
0334         AngelCare = 158,
0335         CrystalRiver = 159,
0336         SoftLipstick = 160,
0337         SaltMountain = 161,
0338         PerfectWhite = 162,
0339         FreshOasis = 163,
0340         StrictNovember = 164,
0341         MorningSalad = 165,
0342         DeepRelief = 166,
0343         SeaStrike = 167,
0344         NightCall = 168,
0345         SupremeSky = 169,
0346         LightBlue = 170,
0347         MindCrawl = 171,
0348         LilyMeadow = 172,
0349         SugarLollipop = 173,
0350         SweetDessert = 174,
0351         MagicRay = 175,
0352         TeenParty = 176,
0353         FrozenHeat = 177,
0354         GagarinView = 178,
0355         FabledSunset = 179,
0356         PerfectBlue = 180,
0357 
0358         NumPresets
0359     };
0360     Q_ENUM(Preset)
0361 
0362     QGradient();
0363     QGradient(Preset);
0364     ~QGradient();
0365 
0366     Type type() const { return m_type; }
0367 
0368     inline void setSpread(Spread spread);
0369     Spread spread() const { return m_spread; }
0370 
0371     void setColorAt(qreal pos, const QColor &color);
0372 
0373     void setStops(const QGradientStops &stops);
0374     QGradientStops stops() const;
0375 
0376     CoordinateMode coordinateMode() const;
0377     void setCoordinateMode(CoordinateMode mode);
0378 
0379     InterpolationMode interpolationMode() const;
0380     void setInterpolationMode(InterpolationMode mode);
0381 
0382     bool operator==(const QGradient &gradient) const;
0383     inline bool operator!=(const QGradient &other) const
0384     { return !operator==(other); }
0385 
0386     union QGradientData {
0387         struct {
0388             qreal x1, y1, x2, y2;
0389         } linear;
0390         struct {
0391             qreal cx, cy, fx, fy, cradius, fradius;
0392         } radial;
0393         struct {
0394             qreal cx, cy, angle;
0395         } conical;
0396     };
0397 
0398 private:
0399     friend class QLinearGradient;
0400     friend class QRadialGradient;
0401     friend class QConicalGradient;
0402     friend class QBrush;
0403 
0404     Type m_type = NoGradient;
0405     Spread m_spread = PadSpread;
0406     QGradientStops m_stops;
0407     QGradientData m_data;
0408     CoordinateMode m_coordinateMode = LogicalMode;
0409     InterpolationMode m_interpolationMode = ColorInterpolation;
0410 };
0411 
0412 inline void QGradient::setSpread(Spread aspread)
0413 { m_spread = aspread; }
0414 
0415 class Q_GUI_EXPORT QLinearGradient : public QGradient
0416 {
0417 public:
0418     QLinearGradient();
0419     QLinearGradient(const QPointF &start, const QPointF &finalStop);
0420     QLinearGradient(qreal xStart, qreal yStart, qreal xFinalStop, qreal yFinalStop);
0421     ~QLinearGradient();
0422 
0423     QPointF start() const;
0424     void setStart(const QPointF &start);
0425     inline void setStart(qreal x, qreal y) { setStart(QPointF(x, y)); }
0426 
0427     QPointF finalStop() const;
0428     void setFinalStop(const QPointF &stop);
0429     inline void setFinalStop(qreal x, qreal y) { setFinalStop(QPointF(x, y)); }
0430 };
0431 
0432 
0433 class Q_GUI_EXPORT QRadialGradient : public QGradient
0434 {
0435 public:
0436     QRadialGradient();
0437     QRadialGradient(const QPointF &center, qreal radius, const QPointF &focalPoint);
0438     QRadialGradient(qreal cx, qreal cy, qreal radius, qreal fx, qreal fy);
0439 
0440     QRadialGradient(const QPointF &center, qreal radius);
0441     QRadialGradient(qreal cx, qreal cy, qreal radius);
0442 
0443     QRadialGradient(const QPointF &center, qreal centerRadius, const QPointF &focalPoint, qreal focalRadius);
0444     QRadialGradient(qreal cx, qreal cy, qreal centerRadius, qreal fx, qreal fy, qreal focalRadius);
0445 
0446     ~QRadialGradient();
0447 
0448     QPointF center() const;
0449     void setCenter(const QPointF &center);
0450     inline void setCenter(qreal x, qreal y) { setCenter(QPointF(x, y)); }
0451 
0452     QPointF focalPoint() const;
0453     void setFocalPoint(const QPointF &focalPoint);
0454     inline void setFocalPoint(qreal x, qreal y) { setFocalPoint(QPointF(x, y)); }
0455 
0456     qreal radius() const;
0457     void setRadius(qreal radius);
0458 
0459     qreal centerRadius() const;
0460     void setCenterRadius(qreal radius);
0461 
0462     qreal focalRadius() const;
0463     void setFocalRadius(qreal radius);
0464 };
0465 
0466 
0467 class Q_GUI_EXPORT QConicalGradient : public QGradient
0468 {
0469 public:
0470     QConicalGradient();
0471     QConicalGradient(const QPointF &center, qreal startAngle);
0472     QConicalGradient(qreal cx, qreal cy, qreal startAngle);
0473     ~QConicalGradient();
0474 
0475     QPointF center() const;
0476     void setCenter(const QPointF &center);
0477     inline void setCenter(qreal x, qreal y) { setCenter(QPointF(x, y)); }
0478 
0479     qreal angle() const;
0480     void setAngle(qreal angle);
0481 };
0482 
0483 QT_END_NAMESPACE
0484 
0485 #endif // QBRUSH_H