File indexing completed on 2025-09-15 09:07:59
0001
0002
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
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 };
0138
0139 inline Qt::BrushStyle QBrush::style() const { return d->style; }
0140 inline const QColor &QBrush::color() const { return d->color; }
0141 inline QTransform QBrush::transform() const { return d->transform; }
0142 inline bool QBrush::isDetached() const { return d->ref.loadRelaxed() == 1; }
0143
0144
0145
0146
0147
0148 class QGradientPrivate;
0149
0150 typedef std::pair<qreal, QColor> QGradientStop;
0151 typedef QList<QGradientStop> QGradientStops;
0152
0153 class Q_GUI_EXPORT QGradient
0154 {
0155 Q_GADGET
0156 public:
0157 enum Type {
0158 LinearGradient,
0159 RadialGradient,
0160 ConicalGradient,
0161 NoGradient
0162 };
0163 Q_ENUM(Type)
0164
0165 enum Spread {
0166 PadSpread,
0167 ReflectSpread,
0168 RepeatSpread
0169 };
0170 Q_ENUM(Spread)
0171
0172 enum CoordinateMode {
0173 LogicalMode,
0174 StretchToDeviceMode,
0175 ObjectBoundingMode,
0176 ObjectMode
0177 };
0178 Q_ENUM(CoordinateMode)
0179
0180 enum InterpolationMode {
0181 ColorInterpolation,
0182 ComponentInterpolation
0183 };
0184
0185 enum Preset {
0186 WarmFlame = 1,
0187 NightFade = 2,
0188 SpringWarmth = 3,
0189 JuicyPeach = 4,
0190 YoungPassion = 5,
0191 LadyLips = 6,
0192 SunnyMorning = 7,
0193 RainyAshville = 8,
0194 FrozenDreams = 9,
0195 WinterNeva = 10,
0196 DustyGrass = 11,
0197 TemptingAzure = 12,
0198 HeavyRain = 13,
0199 AmyCrisp = 14,
0200 MeanFruit = 15,
0201 DeepBlue = 16,
0202 RipeMalinka = 17,
0203 CloudyKnoxville = 18,
0204 MalibuBeach = 19,
0205 NewLife = 20,
0206 TrueSunset = 21,
0207 MorpheusDen = 22,
0208 RareWind = 23,
0209 NearMoon = 24,
0210 WildApple = 25,
0211 SaintPetersburg = 26,
0212 PlumPlate = 28,
0213 EverlastingSky = 29,
0214 HappyFisher = 30,
0215 Blessing = 31,
0216 SharpeyeEagle = 32,
0217 LadogaBottom = 33,
0218 LemonGate = 34,
0219 ItmeoBranding = 35,
0220 ZeusMiracle = 36,
0221 OldHat = 37,
0222 StarWine = 38,
0223 HappyAcid = 41,
0224 AwesomePine = 42,
0225 NewYork = 43,
0226 ShyRainbow = 44,
0227 MixedHopes = 46,
0228 FlyHigh = 47,
0229 StrongBliss = 48,
0230 FreshMilk = 49,
0231 SnowAgain = 50,
0232 FebruaryInk = 51,
0233 KindSteel = 52,
0234 SoftGrass = 53,
0235 GrownEarly = 54,
0236 SharpBlues = 55,
0237 ShadyWater = 56,
0238 DirtyBeauty = 57,
0239 GreatWhale = 58,
0240 TeenNotebook = 59,
0241 PoliteRumors = 60,
0242 SweetPeriod = 61,
0243 WideMatrix = 62,
0244 SoftCherish = 63,
0245 RedSalvation = 64,
0246 BurningSpring = 65,
0247 NightParty = 66,
0248 SkyGlider = 67,
0249 HeavenPeach = 68,
0250 PurpleDivision = 69,
0251 AquaSplash = 70,
0252 SpikyNaga = 72,
0253 LoveKiss = 73,
0254 CleanMirror = 75,
0255 PremiumDark = 76,
0256 ColdEvening = 77,
0257 CochitiLake = 78,
0258 SummerGames = 79,
0259 PassionateBed = 80,
0260 MountainRock = 81,
0261 DesertHump = 82,
0262 JungleDay = 83,
0263 PhoenixStart = 84,
0264 OctoberSilence = 85,
0265 FarawayRiver = 86,
0266 AlchemistLab = 87,
0267 OverSun = 88,
0268 PremiumWhite = 89,
0269 MarsParty = 90,
0270 EternalConstance = 91,
0271 JapanBlush = 92,
0272 SmilingRain = 93,
0273 CloudyApple = 94,
0274 BigMango = 95,
0275 HealthyWater = 96,
0276 AmourAmour = 97,
0277 RiskyConcrete = 98,
0278 StrongStick = 99,
0279 ViciousStance = 100,
0280 PaloAlto = 101,
0281 HappyMemories = 102,
0282 MidnightBloom = 103,
0283 Crystalline = 104,
0284 PartyBliss = 106,
0285 ConfidentCloud = 107,
0286 LeCocktail = 108,
0287 RiverCity = 109,
0288 FrozenBerry = 110,
0289 ChildCare = 112,
0290 FlyingLemon = 113,
0291 NewRetrowave = 114,
0292 HiddenJaguar = 115,
0293 AboveTheSky = 116,
0294 Nega = 117,
0295 DenseWater = 118,
0296 Seashore = 120,
0297 MarbleWall = 121,
0298 CheerfulCaramel = 122,
0299 NightSky = 123,
0300 MagicLake = 124,
0301 YoungGrass = 125,
0302 ColorfulPeach = 126,
0303 GentleCare = 127,
0304 PlumBath = 128,
0305 HappyUnicorn = 129,
0306 AfricanField = 131,
0307 SolidStone = 132,
0308 OrangeJuice = 133,
0309 GlassWater = 134,
0310 NorthMiracle = 136,
0311 FruitBlend = 137,
0312 MillenniumPine = 138,
0313 HighFlight = 139,
0314 MoleHall = 140,
0315 SpaceShift = 142,
0316 ForestInei = 143,
0317 RoyalGarden = 144,
0318 RichMetal = 145,
0319 JuicyCake = 146,
0320 SmartIndigo = 147,
0321 SandStrike = 148,
0322 NorseBeauty = 149,
0323 AquaGuidance = 150,
0324 SunVeggie = 151,
0325 SeaLord = 152,
0326 BlackSea = 153,
0327 GrassShampoo = 154,
0328 LandingAircraft = 155,
0329 WitchDance = 156,
0330 SleeplessNight = 157,
0331 AngelCare = 158,
0332 CrystalRiver = 159,
0333 SoftLipstick = 160,
0334 SaltMountain = 161,
0335 PerfectWhite = 162,
0336 FreshOasis = 163,
0337 StrictNovember = 164,
0338 MorningSalad = 165,
0339 DeepRelief = 166,
0340 SeaStrike = 167,
0341 NightCall = 168,
0342 SupremeSky = 169,
0343 LightBlue = 170,
0344 MindCrawl = 171,
0345 LilyMeadow = 172,
0346 SugarLollipop = 173,
0347 SweetDessert = 174,
0348 MagicRay = 175,
0349 TeenParty = 176,
0350 FrozenHeat = 177,
0351 GagarinView = 178,
0352 FabledSunset = 179,
0353 PerfectBlue = 180,
0354
0355 NumPresets
0356 };
0357 Q_ENUM(Preset)
0358
0359 QGradient();
0360 QGradient(Preset);
0361 ~QGradient();
0362
0363 Type type() const { return m_type; }
0364
0365 inline void setSpread(Spread spread);
0366 Spread spread() const { return m_spread; }
0367
0368 void setColorAt(qreal pos, const QColor &color);
0369
0370 void setStops(const QGradientStops &stops);
0371 QGradientStops stops() const;
0372
0373 CoordinateMode coordinateMode() const;
0374 void setCoordinateMode(CoordinateMode mode);
0375
0376 InterpolationMode interpolationMode() const;
0377 void setInterpolationMode(InterpolationMode mode);
0378
0379 bool operator==(const QGradient &gradient) const;
0380 inline bool operator!=(const QGradient &other) const
0381 { return !operator==(other); }
0382
0383 union QGradientData {
0384 struct {
0385 qreal x1, y1, x2, y2;
0386 } linear;
0387 struct {
0388 qreal cx, cy, fx, fy, cradius, fradius;
0389 } radial;
0390 struct {
0391 qreal cx, cy, angle;
0392 } conical;
0393 };
0394
0395 private:
0396 friend class QLinearGradient;
0397 friend class QRadialGradient;
0398 friend class QConicalGradient;
0399 friend class QBrush;
0400
0401 Type m_type = NoGradient;
0402 Spread m_spread = PadSpread;
0403 QGradientStops m_stops;
0404 QGradientData m_data;
0405 CoordinateMode m_coordinateMode = LogicalMode;
0406 InterpolationMode m_interpolationMode = ColorInterpolation;
0407 };
0408
0409 inline void QGradient::setSpread(Spread aspread)
0410 { m_spread = aspread; }
0411
0412 class Q_GUI_EXPORT QLinearGradient : public QGradient
0413 {
0414 public:
0415 QLinearGradient();
0416 QLinearGradient(const QPointF &start, const QPointF &finalStop);
0417 QLinearGradient(qreal xStart, qreal yStart, qreal xFinalStop, qreal yFinalStop);
0418 ~QLinearGradient();
0419
0420 QPointF start() const;
0421 void setStart(const QPointF &start);
0422 inline void setStart(qreal x, qreal y) { setStart(QPointF(x, y)); }
0423
0424 QPointF finalStop() const;
0425 void setFinalStop(const QPointF &stop);
0426 inline void setFinalStop(qreal x, qreal y) { setFinalStop(QPointF(x, y)); }
0427 };
0428
0429
0430 class Q_GUI_EXPORT QRadialGradient : public QGradient
0431 {
0432 public:
0433 QRadialGradient();
0434 QRadialGradient(const QPointF ¢er, qreal radius, const QPointF &focalPoint);
0435 QRadialGradient(qreal cx, qreal cy, qreal radius, qreal fx, qreal fy);
0436
0437 QRadialGradient(const QPointF ¢er, qreal radius);
0438 QRadialGradient(qreal cx, qreal cy, qreal radius);
0439
0440 QRadialGradient(const QPointF ¢er, qreal centerRadius, const QPointF &focalPoint, qreal focalRadius);
0441 QRadialGradient(qreal cx, qreal cy, qreal centerRadius, qreal fx, qreal fy, qreal focalRadius);
0442
0443 ~QRadialGradient();
0444
0445 QPointF center() const;
0446 void setCenter(const QPointF ¢er);
0447 inline void setCenter(qreal x, qreal y) { setCenter(QPointF(x, y)); }
0448
0449 QPointF focalPoint() const;
0450 void setFocalPoint(const QPointF &focalPoint);
0451 inline void setFocalPoint(qreal x, qreal y) { setFocalPoint(QPointF(x, y)); }
0452
0453 qreal radius() const;
0454 void setRadius(qreal radius);
0455
0456 qreal centerRadius() const;
0457 void setCenterRadius(qreal radius);
0458
0459 qreal focalRadius() const;
0460 void setFocalRadius(qreal radius);
0461 };
0462
0463
0464 class Q_GUI_EXPORT QConicalGradient : public QGradient
0465 {
0466 public:
0467 QConicalGradient();
0468 QConicalGradient(const QPointF ¢er, qreal startAngle);
0469 QConicalGradient(qreal cx, qreal cy, qreal startAngle);
0470 ~QConicalGradient();
0471
0472 QPointF center() const;
0473 void setCenter(const QPointF ¢er);
0474 inline void setCenter(qreal x, qreal y) { setCenter(QPointF(x, y)); }
0475
0476 qreal angle() const;
0477 void setAngle(qreal angle);
0478 };
0479
0480 QT_END_NAMESPACE
0481
0482 #endif