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