Coverage Report

Created: 2025-09-08 07:52

/src/qtbase/src/gui/kernel/qpalette.h
Line
Count
Source (jump to first uncovered line)
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
4
#ifndef QPALETTE_H
5
#define QPALETTE_H
6
7
#include <QtGui/qtguiglobal.h>
8
#include <QtGui/qwindowdefs.h>
9
#include <QtGui/qcolor.h>
10
#include <QtGui/qbrush.h>
11
12
QT_BEGIN_NAMESPACE
13
14
15
class QPalettePrivate;
16
class QVariant;
17
18
class Q_GUI_EXPORT QPalette
19
{
20
    Q_GADGET
21
public:
22
    QPalette();
23
    QPalette(const QColor &button);
24
    QPalette(Qt::GlobalColor button);
25
    QPalette(const QColor &button, const QColor &window);
26
    QPalette(const QBrush &windowText, const QBrush &button, const QBrush &light,
27
             const QBrush &dark, const QBrush &mid, const QBrush &text,
28
             const QBrush &bright_text, const QBrush &base, const QBrush &window);
29
    QPalette(const QColor &windowText, const QColor &window, const QColor &light,
30
             const QColor &dark, const QColor &mid, const QColor &text, const QColor &base);
31
    QPalette(const QPalette &palette);
32
    ~QPalette();
33
    QPalette &operator=(const QPalette &palette);
34
    QPalette(QPalette &&other) noexcept
35
0
        : d(std::exchange(other.d, nullptr)), currentGroup(other.currentGroup)
36
0
    {}
37
    QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QPalette)
38
39
    void swap(QPalette &other) noexcept
40
0
    {
41
0
        std::swap(currentGroup, other.currentGroup);
42
0
        qt_ptr_swap(d, other.d);
43
0
    }
44
45
    operator QVariant() const;
46
47
    // Do not change the order, the serialization format depends on it
48
    // Ensure these values are kept in sync with QQuickColorGroup's properties
49
    // and QCss::KnownValue!
50
    enum ColorGroup { Active, Disabled, Inactive, NColorGroups, Current, All, Normal = Active };
51
    Q_ENUM(ColorGroup)
52
    enum ColorRole { WindowText, Button, Light, Midlight, Dark, Mid,
53
                     Text, BrightText, ButtonText, Base, Window, Shadow,
54
                     Highlight, HighlightedText,
55
                     Link, LinkVisited,
56
                     AlternateBase,
57
                     NoRole,
58
                     ToolTipBase, ToolTipText,
59
                     PlaceholderText,
60
                     Accent,
61
                     NColorRoles = Accent + 1,
62
                   };
63
    Q_ENUM(ColorRole)
64
65
0
    inline ColorGroup currentColorGroup() const { return currentGroup; }
66
0
    inline void setCurrentColorGroup(ColorGroup cg) { currentGroup = cg; }
67
68
    inline const QColor &color(ColorGroup cg, ColorRole cr) const
69
0
    { return brush(cg, cr).color(); }
70
    const QBrush &brush(ColorGroup cg, ColorRole cr) const;
71
    inline void setColor(ColorGroup cg, ColorRole cr, const QColor &color);
72
    inline void setColor(ColorRole cr, const QColor &color);
73
    inline void setBrush(ColorRole cr, const QBrush &brush);
74
    bool isBrushSet(ColorGroup cg, ColorRole cr) const;
75
    void setBrush(ColorGroup cg, ColorRole cr, const QBrush &brush);
76
    void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button,
77
                       const QBrush &light, const QBrush &dark, const QBrush &mid,
78
                       const QBrush &text, const QBrush &bright_text, const QBrush &base,
79
                       const QBrush &window);
80
    bool isEqual(ColorGroup cr1, ColorGroup cr2) const;
81
82
0
    inline const QColor &color(ColorRole cr) const { return color(Current, cr); }
83
0
    inline const QBrush &brush(ColorRole cr) const { return brush(Current, cr); }
84
0
    inline const QBrush &windowText() const { return brush(WindowText); }
85
0
    inline const QBrush &button() const { return brush(Button); }
86
0
    inline const QBrush &light() const { return brush(Light); }
87
0
    inline const QBrush &dark() const { return brush(Dark); }
88
0
    inline const QBrush &mid() const { return brush(Mid); }
89
0
    inline const QBrush &text() const { return brush(Text); }
90
0
    inline const QBrush &base() const { return brush(Base); }
91
0
    inline const QBrush &alternateBase() const { return brush(AlternateBase); }
92
0
    inline const QBrush &toolTipBase() const { return brush(ToolTipBase); }
93
0
    inline const QBrush &toolTipText() const { return brush(ToolTipText); }
94
0
    inline const QBrush &window() const { return brush(Window); }
95
0
    inline const QBrush &midlight() const { return brush(Midlight); }
96
0
    inline const QBrush &brightText() const { return brush(BrightText); }
97
0
    inline const QBrush &buttonText() const { return brush(ButtonText); }
98
0
    inline const QBrush &shadow() const { return brush(Shadow); }
99
0
    inline const QBrush &highlight() const { return brush(Highlight); }
100
0
    inline const QBrush &highlightedText() const { return brush(HighlightedText); }
101
0
    inline const QBrush &link() const { return brush(Link); }
102
0
    inline const QBrush &linkVisited() const { return brush(LinkVisited); }
103
0
    inline const QBrush &placeholderText() const { return brush(PlaceholderText); }
104
0
    inline const QBrush &accent() const { return brush(Accent); }
105
106
    bool operator==(const QPalette &p) const;
107
0
    inline bool operator!=(const QPalette &p) const { return !(operator==(p)); }
108
    bool isCopyOf(const QPalette &p) const;
109
110
    qint64 cacheKey() const;
111
112
    QPalette resolve(const QPalette &other) const;
113
114
    using ResolveMask = quint64;
115
    ResolveMask resolveMask() const;
116
    void setResolveMask(ResolveMask mask);
117
118
private:
119
    void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button,
120
                       const QBrush &light, const QBrush &dark, const QBrush &mid,
121
                       const QBrush &text, const QBrush &bright_text,
122
                       const QBrush &base, const QBrush &alternate_base,
123
                       const QBrush &window, const QBrush &midlight,
124
                       const QBrush &button_text, const QBrush &shadow,
125
                       const QBrush &highlight, const QBrush &highlighted_text,
126
                       const QBrush &link, const QBrush &link_visited);
127
    void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button,
128
                       const QBrush &light, const QBrush &dark, const QBrush &mid,
129
                       const QBrush &text, const QBrush &bright_text,
130
                       const QBrush &base, const QBrush &alternate_base,
131
                       const QBrush &window, const QBrush &midlight,
132
                       const QBrush &button_text, const QBrush &shadow,
133
                       const QBrush &highlight, const QBrush &highlighted_text,
134
                       const QBrush &link, const QBrush &link_visited,
135
                       const QBrush &toolTipBase, const QBrush &toolTipText);
136
    void init();
137
    void detach();
138
139
    QPalettePrivate *d;
140
    ColorGroup currentGroup{Active};
141
142
    friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const QPalette &p);
143
};
144
145
Q_DECLARE_SHARED(QPalette)
146
147
inline void QPalette::setColor(ColorGroup acg, ColorRole acr,
148
                               const QColor &acolor)
149
0
{ setBrush(acg, acr, QBrush(acolor)); }
150
inline void QPalette::setColor(ColorRole acr, const QColor &acolor)
151
0
{ setColor(All, acr, acolor); }
152
inline void QPalette::setBrush(ColorRole acr, const QBrush &abrush)
153
0
{ setBrush(All, acr, abrush); }
154
155
/*****************************************************************************
156
  QPalette stream functions
157
 *****************************************************************************/
158
#ifndef QT_NO_DATASTREAM
159
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &ds, const QPalette &p);
160
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &ds, QPalette &p);
161
#endif // QT_NO_DATASTREAM
162
163
#ifndef QT_NO_DEBUG_STREAM
164
Q_GUI_EXPORT QDebug operator<<(QDebug, const QPalette &);
165
#endif
166
167
QT_END_NAMESPACE
168
169
#endif // QPALETTE_H