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