| 1 | // Copyright (C) 2023 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 | |
| 4 | #ifndef QPALETTE_P_H |
| 5 | #define QPALETTE_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include "qpalette.h" |
| 19 | |
| 20 | QT_BEGIN_NAMESPACE |
| 21 | |
| 22 | class Q_GUI_EXPORT QPalettePrivate |
| 23 | { |
| 24 | public: |
| 25 | class Data : public QSharedData { |
| 26 | public: |
| 27 | // Every instance of Data has to have a unique serial number, even |
| 28 | // if it gets created by copying another - we wouldn't create a copy |
| 29 | // in the first place if the serial number should be the same! |
| 30 | Data(const Data &other) |
| 31 | : QSharedData(other) |
| 32 | { |
| 33 | for (int grp = 0; grp < int(QPalette::NColorGroups); grp++) { |
| 34 | for (int role = 0; role < int(QPalette::NColorRoles); role++) |
| 35 | br[grp][role] = other.br[grp][role]; |
| 36 | } |
| 37 | } |
| 38 | Data() = default; |
| 39 | |
| 40 | QBrush br[QPalette::NColorGroups][QPalette::NColorRoles]; |
| 41 | const int ser_no = qt_palette_count++; |
| 42 | }; |
| 43 | |
| 44 | QPalettePrivate(const QExplicitlySharedDataPointer<Data> &data) |
| 45 | : ref(1), data(data) |
| 46 | { } |
| 47 | QPalettePrivate() |
| 48 | : QPalettePrivate(QExplicitlySharedDataPointer<Data>(new Data)) |
| 49 | { } |
| 50 | |
| 51 | static constexpr QPalette::ResolveMask colorRoleOffset(QPalette::ColorGroup colorGroup) |
| 52 | { |
| 53 | // Exclude NoRole; that bit is used for Accent |
| 54 | return (qToUnderlying(e: QPalette::NColorRoles) - 1) * qToUnderlying(e: colorGroup); |
| 55 | } |
| 56 | |
| 57 | static constexpr QPalette::ResolveMask bitPosition(QPalette::ColorGroup colorGroup, |
| 58 | QPalette::ColorRole colorRole) |
| 59 | { |
| 60 | // Map Accent into NoRole for resolving purposes |
| 61 | if (colorRole == QPalette::Accent) |
| 62 | colorRole = QPalette::NoRole; |
| 63 | |
| 64 | return colorRole + colorRoleOffset(colorGroup); |
| 65 | } |
| 66 | |
| 67 | QAtomicInt ref; |
| 68 | QPalette::ResolveMask resolveMask = {0}; |
| 69 | static inline int qt_palette_count = 0; |
| 70 | static inline int qt_palette_private_count = 0; |
| 71 | int detach_no = ++qt_palette_private_count; |
| 72 | QExplicitlySharedDataPointer<Data> data; |
| 73 | }; |
| 74 | |
| 75 | QT_END_NAMESPACE |
| 76 | |
| 77 | #endif // QPALETTE_P_H |
| 78 |
