Coverage Report

Created: 2026-03-31 07:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/prefix/include/QtGui/qbrush.h
Line
Count
Source
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#ifndef QBRUSH_H
6
#define QBRUSH_H
7
8
#include <QtGui/qtguiglobal.h>
9
#include <QtCore/qlist.h>
10
#include <QtCore/qpoint.h>
11
#include <QtCore/qscopedpointer.h>
12
#include <QtGui/qcolor.h>
13
#include <QtGui/qimage.h>
14
#include <QtGui/qpixmap.h>
15
#include <QtGui/qtransform.h>
16
17
QT_BEGIN_NAMESPACE
18
19
20
struct QBrushData;
21
class QPixmap;
22
class QGradient;
23
class QVariant;
24
struct QBrushDataPointerDeleter
25
{
26
    void operator()(QBrushData *d) const noexcept;
27
};
28
29
class Q_GUI_EXPORT QBrush
30
{
31
public:
32
    QBrush();
33
    QBrush(Qt::BrushStyle bs);
34
    QBrush(const QColor &color, Qt::BrushStyle bs=Qt::SolidPattern);
35
    QBrush(Qt::GlobalColor color, Qt::BrushStyle bs=Qt::SolidPattern);
36
37
    QBrush(const QColor &color, const QPixmap &pixmap);
38
    QBrush(Qt::GlobalColor color, const QPixmap &pixmap);
39
    QBrush(const QPixmap &pixmap);
40
    QBrush(const QImage &image);
41
42
    QBrush(const QBrush &brush);
43
44
    QBrush(const QGradient &gradient);
45
46
    ~QBrush();
47
    QBrush &operator=(const QBrush &brush);
48
    QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QBrush)
49
    inline void swap(QBrush &other) noexcept
50
0
    { d.swap(other.d); }
51
52
    QBrush &operator=(Qt::BrushStyle style);
53
    QBrush &operator=(QColor color);
54
0
    QBrush &operator=(Qt::GlobalColor color) { return operator=(QColor(color)); }
55
56
    operator QVariant() const;
57
58
    inline Qt::BrushStyle style() const;
59
    void setStyle(Qt::BrushStyle);
60
61
    inline QTransform transform() const;
62
    void setTransform(const QTransform &);
63
64
    QPixmap texture() const;
65
    void setTexture(const QPixmap &pixmap);
66
67
    QImage textureImage() const;
68
    void setTextureImage(const QImage &image);
69
70
    inline const QColor &color() const;
71
    void setColor(const QColor &color);
72
    inline void setColor(Qt::GlobalColor color);
73
74
    const QGradient *gradient() const;
75
76
    bool isOpaque() const;
77
78
    bool operator==(const QBrush &b) const;
79
0
    inline bool operator!=(const QBrush &b) const { return !(operator==(b)); }
80
81
    using DataPtr = std::unique_ptr<QBrushData, QBrushDataPointerDeleter>;
82
83
private:
84
    friend class QRasterPaintEngine;
85
    friend class QRasterPaintEnginePrivate;
86
    friend struct QSpanData;
87
    friend class QPainter;
88
    friend bool Q_GUI_EXPORT qHasPixmapTexture(const QBrush& brush);
89
90
    bool doCompareEqualColor(QColor rhs) const noexcept;
91
    friend bool comparesEqual(const QBrush &lhs, QColor rhs) noexcept
92
0
    {
93
0
        return lhs.doCompareEqualColor(rhs);
94
0
    }
95
    Q_DECLARE_EQUALITY_COMPARABLE(QBrush, QColor)
96
    Q_DECLARE_EQUALITY_COMPARABLE(QBrush, Qt::GlobalColor)
97
98
    bool doCompareEqualStyle(Qt::BrushStyle rhs) const noexcept;
99
    friend bool comparesEqual(const QBrush &lhs, Qt::BrushStyle rhs) noexcept
100
0
    {
101
0
        return lhs.doCompareEqualStyle(rhs);
102
0
    }
103
    Q_DECLARE_EQUALITY_COMPARABLE(QBrush, Qt::BrushStyle)
104
105
    void detach(Qt::BrushStyle newStyle);
106
    void init(const QColor &color, Qt::BrushStyle bs);
107
    DataPtr d;
108
109
public:
110
    inline bool isDetached() const;
111
0
    inline DataPtr &data_ptr() { return d; }
112
};
113
114
inline void QBrush::setColor(Qt::GlobalColor acolor)
115
0
{ setColor(QColor(acolor)); }
116
117
Q_DECLARE_SHARED(QBrush)
118
119
/*****************************************************************************
120
  QBrush stream functions
121
 *****************************************************************************/
122
123
#ifndef QT_NO_DATASTREAM
124
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QBrush &);
125
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QBrush &);
126
#endif
127
128
#ifndef QT_NO_DEBUG_STREAM
129
Q_GUI_EXPORT QDebug operator<<(QDebug, const QBrush &);
130
#endif
131
132
struct QBrushData
133
{
134
    QAtomicInt ref;
135
    Qt::BrushStyle style;
136
    QColor color;
137
    QTransform transform;
138
protected:
139
    QBrushData() = default;
140
    QT_DECLARE_RO5_SMF_AS_DEFAULTED(QBrushData)
141
};
142
143
0
inline Qt::BrushStyle QBrush::style() const { return d->style; }
144
0
inline const QColor &QBrush::color() const { return d->color; }
145
0
inline QTransform QBrush::transform() const { return d->transform; }
146
0
inline bool QBrush::isDetached() const { return d->ref.loadRelaxed() == 1; }
147
148
149
/*******************************************************************************
150
 * QGradients
151
 */
152
class QGradientPrivate;
153
154
typedef std::pair<qreal, QColor> QGradientStop;
155
typedef QList<QGradientStop> QGradientStops;
156
157
class Q_GUI_EXPORT QGradient
158
{
159
    Q_GADGET
160
public:
161
    enum Type {
162
        LinearGradient,
163
        RadialGradient,
164
        ConicalGradient,
165
        NoGradient
166
    };
167
    Q_ENUM(Type)
168
169
    enum Spread {
170
        PadSpread,
171
        ReflectSpread,
172
        RepeatSpread
173
    };
174
    Q_ENUM(Spread)
175
176
    enum CoordinateMode {
177
        LogicalMode,
178
        StretchToDeviceMode,
179
        ObjectBoundingMode,
180
        ObjectMode
181
    };
182
    Q_ENUM(CoordinateMode)
183
184
    enum InterpolationMode {
185
        ColorInterpolation,
186
        ComponentInterpolation
187
    };
188
189
    enum Preset {
190
        WarmFlame = 1,
191
        NightFade = 2,
192
        SpringWarmth = 3,
193
        JuicyPeach = 4,
194
        YoungPassion = 5,
195
        LadyLips = 6,
196
        SunnyMorning = 7,
197
        RainyAshville = 8,
198
        FrozenDreams = 9,
199
        WinterNeva = 10,
200
        DustyGrass = 11,
201
        TemptingAzure = 12,
202
        HeavyRain = 13,
203
        AmyCrisp = 14,
204
        MeanFruit = 15,
205
        DeepBlue = 16,
206
        RipeMalinka = 17,
207
        CloudyKnoxville = 18,
208
        MalibuBeach = 19,
209
        NewLife = 20,
210
        TrueSunset = 21,
211
        MorpheusDen = 22,
212
        RareWind = 23,
213
        NearMoon = 24,
214
        WildApple = 25,
215
        SaintPetersburg = 26,
216
        PlumPlate = 28,
217
        EverlastingSky = 29,
218
        HappyFisher = 30,
219
        Blessing = 31,
220
        SharpeyeEagle = 32,
221
        LadogaBottom = 33,
222
        LemonGate = 34,
223
        ItmeoBranding = 35,
224
        ZeusMiracle = 36,
225
        OldHat = 37,
226
        StarWine = 38,
227
        HappyAcid = 41,
228
        AwesomePine = 42,
229
        NewYork = 43,
230
        ShyRainbow = 44,
231
        MixedHopes = 46,
232
        FlyHigh = 47,
233
        StrongBliss = 48,
234
        FreshMilk = 49,
235
        SnowAgain = 50,
236
        FebruaryInk = 51,
237
        KindSteel = 52,
238
        SoftGrass = 53,
239
        GrownEarly = 54,
240
        SharpBlues = 55,
241
        ShadyWater = 56,
242
        DirtyBeauty = 57,
243
        GreatWhale = 58,
244
        TeenNotebook = 59,
245
        PoliteRumors = 60,
246
        SweetPeriod = 61,
247
        WideMatrix = 62,
248
        SoftCherish = 63,
249
        RedSalvation = 64,
250
        BurningSpring = 65,
251
        NightParty = 66,
252
        SkyGlider = 67,
253
        HeavenPeach = 68,
254
        PurpleDivision = 69,
255
        AquaSplash = 70,
256
        SpikyNaga = 72,
257
        LoveKiss = 73,
258
        CleanMirror = 75,
259
        PremiumDark = 76,
260
        ColdEvening = 77,
261
        CochitiLake = 78,
262
        SummerGames = 79,
263
        PassionateBed = 80,
264
        MountainRock = 81,
265
        DesertHump = 82,
266
        JungleDay = 83,
267
        PhoenixStart = 84,
268
        OctoberSilence = 85,
269
        FarawayRiver = 86,
270
        AlchemistLab = 87,
271
        OverSun = 88,
272
        PremiumWhite = 89,
273
        MarsParty = 90,
274
        EternalConstance = 91,
275
        JapanBlush = 92,
276
        SmilingRain = 93,
277
        CloudyApple = 94,
278
        BigMango = 95,
279
        HealthyWater = 96,
280
        AmourAmour = 97,
281
        RiskyConcrete = 98,
282
        StrongStick = 99,
283
        ViciousStance = 100,
284
        PaloAlto = 101,
285
        HappyMemories = 102,
286
        MidnightBloom = 103,
287
        Crystalline = 104,
288
        PartyBliss = 106,
289
        ConfidentCloud = 107,
290
        LeCocktail = 108,
291
        RiverCity = 109,
292
        FrozenBerry = 110,
293
        ChildCare = 112,
294
        FlyingLemon = 113,
295
        NewRetrowave = 114,
296
        HiddenJaguar = 115,
297
        AboveTheSky = 116,
298
        Nega = 117,
299
        DenseWater = 118,
300
        Seashore = 120,
301
        MarbleWall = 121,
302
        CheerfulCaramel = 122,
303
        NightSky = 123,
304
        MagicLake = 124,
305
        YoungGrass = 125,
306
        ColorfulPeach = 126,
307
        GentleCare = 127,
308
        PlumBath = 128,
309
        HappyUnicorn = 129,
310
        AfricanField = 131,
311
        SolidStone = 132,
312
        OrangeJuice = 133,
313
        GlassWater = 134,
314
        NorthMiracle = 136,
315
        FruitBlend = 137,
316
        MillenniumPine = 138,
317
        HighFlight = 139,
318
        MoleHall = 140,
319
        SpaceShift = 142,
320
        ForestInei = 143,
321
        RoyalGarden = 144,
322
        RichMetal = 145,
323
        JuicyCake = 146,
324
        SmartIndigo = 147,
325
        SandStrike = 148,
326
        NorseBeauty = 149,
327
        AquaGuidance = 150,
328
        SunVeggie = 151,
329
        SeaLord = 152,
330
        BlackSea = 153,
331
        GrassShampoo = 154,
332
        LandingAircraft = 155,
333
        WitchDance = 156,
334
        SleeplessNight = 157,
335
        AngelCare = 158,
336
        CrystalRiver = 159,
337
        SoftLipstick = 160,
338
        SaltMountain = 161,
339
        PerfectWhite = 162,
340
        FreshOasis = 163,
341
        StrictNovember = 164,
342
        MorningSalad = 165,
343
        DeepRelief = 166,
344
        SeaStrike = 167,
345
        NightCall = 168,
346
        SupremeSky = 169,
347
        LightBlue = 170,
348
        MindCrawl = 171,
349
        LilyMeadow = 172,
350
        SugarLollipop = 173,
351
        SweetDessert = 174,
352
        MagicRay = 175,
353
        TeenParty = 176,
354
        FrozenHeat = 177,
355
        GagarinView = 178,
356
        FabledSunset = 179,
357
        PerfectBlue = 180,
358
359
        NumPresets
360
    };
361
    Q_ENUM(Preset)
362
363
    QGradient();
364
    QGradient(Preset);
365
    ~QGradient();
366
367
0
    Type type() const { return m_type; }
368
369
    inline void setSpread(Spread spread);
370
0
    Spread spread() const { return m_spread; }
371
372
    void setColorAt(qreal pos, const QColor &color);
373
374
    void setStops(const QGradientStops &stops);
375
    QGradientStops stops() const;
376
377
    CoordinateMode coordinateMode() const;
378
    void setCoordinateMode(CoordinateMode mode);
379
380
    InterpolationMode interpolationMode() const;
381
    void setInterpolationMode(InterpolationMode mode);
382
383
    bool operator==(const QGradient &gradient) const;
384
    inline bool operator!=(const QGradient &other) const
385
0
    { return !operator==(other); }
386
387
    union QGradientData {
388
        struct {
389
            qreal x1, y1, x2, y2;
390
        } linear;
391
        struct {
392
            qreal cx, cy, fx, fy, cradius, fradius;
393
        } radial;
394
        struct {
395
            qreal cx, cy, angle;
396
        } conical;
397
    };
398
399
private:
400
    friend class QLinearGradient;
401
    friend class QRadialGradient;
402
    friend class QConicalGradient;
403
    friend class QBrush;
404
405
    Type m_type = NoGradient;
406
    Spread m_spread = PadSpread;
407
    QGradientStops m_stops;
408
    QGradientData m_data;
409
    CoordinateMode m_coordinateMode = LogicalMode;
410
    InterpolationMode m_interpolationMode = ColorInterpolation;
411
};
412
413
inline void QGradient::setSpread(Spread aspread)
414
0
{ m_spread = aspread; }
415
416
class Q_GUI_EXPORT QLinearGradient : public QGradient
417
{
418
public:
419
    QLinearGradient();
420
    QLinearGradient(const QPointF &start, const QPointF &finalStop);
421
    QLinearGradient(qreal xStart, qreal yStart, qreal xFinalStop, qreal yFinalStop);
422
    ~QLinearGradient();
423
424
    QPointF start() const;
425
    void setStart(const QPointF &start);
426
0
    inline void setStart(qreal x, qreal y) { setStart(QPointF(x, y)); }
427
428
    QPointF finalStop() const;
429
    void setFinalStop(const QPointF &stop);
430
0
    inline void setFinalStop(qreal x, qreal y) { setFinalStop(QPointF(x, y)); }
431
};
432
433
434
class Q_GUI_EXPORT QRadialGradient : public QGradient
435
{
436
public:
437
    QRadialGradient();
438
    QRadialGradient(const QPointF &center, qreal radius, const QPointF &focalPoint);
439
    QRadialGradient(qreal cx, qreal cy, qreal radius, qreal fx, qreal fy);
440
441
    QRadialGradient(const QPointF &center, qreal radius);
442
    QRadialGradient(qreal cx, qreal cy, qreal radius);
443
444
    QRadialGradient(const QPointF &center, qreal centerRadius, const QPointF &focalPoint, qreal focalRadius);
445
    QRadialGradient(qreal cx, qreal cy, qreal centerRadius, qreal fx, qreal fy, qreal focalRadius);
446
447
    ~QRadialGradient();
448
449
    QPointF center() const;
450
    void setCenter(const QPointF &center);
451
0
    inline void setCenter(qreal x, qreal y) { setCenter(QPointF(x, y)); }
452
453
    QPointF focalPoint() const;
454
    void setFocalPoint(const QPointF &focalPoint);
455
0
    inline void setFocalPoint(qreal x, qreal y) { setFocalPoint(QPointF(x, y)); }
456
457
    qreal radius() const;
458
    void setRadius(qreal radius);
459
460
    qreal centerRadius() const;
461
    void setCenterRadius(qreal radius);
462
463
    qreal focalRadius() const;
464
    void setFocalRadius(qreal radius);
465
};
466
467
468
class Q_GUI_EXPORT QConicalGradient : public QGradient
469
{
470
public:
471
    QConicalGradient();
472
    QConicalGradient(const QPointF &center, qreal startAngle);
473
    QConicalGradient(qreal cx, qreal cy, qreal startAngle);
474
    ~QConicalGradient();
475
476
    QPointF center() const;
477
    void setCenter(const QPointF &center);
478
0
    inline void setCenter(qreal x, qreal y) { setCenter(QPointF(x, y)); }
479
480
    qreal angle() const;
481
    void setAngle(qreal angle);
482
};
483
484
QT_END_NAMESPACE
485
486
#endif // QBRUSH_H