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