QtBase  v6.3.1
qpalette.h
Go to the documentation of this file.
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 QPALETTE_H
41 #define QPALETTE_H
42 
43 #include <QtGui/qtguiglobal.h>
44 #include <QtGui/qwindowdefs.h>
45 #include <QtGui/qcolor.h>
46 #include <QtGui/qbrush.h>
47 
49 
50 
51 class QPalettePrivate;
52 class QVariant;
53 
54 class Q_GUI_EXPORT QPalette
55 {
56  Q_GADGET
57 public:
58  QPalette();
59  QPalette(const QColor &button);
61  QPalette(const QColor &button, const QColor &window);
62  QPalette(const QBrush &windowText, const QBrush &button, const QBrush &light,
63  const QBrush &dark, const QBrush &mid, const QBrush &text,
64  const QBrush &bright_text, const QBrush &base, const QBrush &window);
65  QPalette(const QColor &windowText, const QColor &window, const QColor &light,
66  const QColor &dark, const QColor &mid, const QColor &text, const QColor &base);
67  QPalette(const QPalette &palette);
68  ~QPalette();
69  QPalette &operator=(const QPalette &palette);
70  QPalette(QPalette &&other) noexcept
71  : d(qExchange(other.d, nullptr)), currentGroup(other.currentGroup)
72  {}
74 
75  void swap(QPalette &other) noexcept
76  {
77  std::swap(currentGroup, other.currentGroup);
78  qt_ptr_swap(d, other.d);
79  }
80 
81  operator QVariant() const;
82 
83  // Do not change the order, the serialization format depends on it
84  enum ColorGroup { Active, Disabled, Inactive, NColorGroups, Current, All, Normal = Active };
85  Q_ENUM(ColorGroup)
86  enum ColorRole { WindowText, Button, Light, Midlight, Dark, Mid,
87  Text, BrightText, ButtonText, Base, Window, Shadow,
88  Highlight, HighlightedText,
89  Link, LinkVisited,
92  ToolTipBase, ToolTipText,
94  NColorRoles = PlaceholderText + 1,
95  };
96  Q_ENUM(ColorRole)
97 
98  inline ColorGroup currentColorGroup() const { return currentGroup; }
99  inline void setCurrentColorGroup(ColorGroup cg) { currentGroup = cg; }
100 
101  inline const QColor &color(ColorGroup cg, ColorRole cr) const
102  { return brush(cg, cr).color(); }
103  const QBrush &brush(ColorGroup cg, ColorRole cr) const;
104  inline void setColor(ColorGroup cg, ColorRole cr, const QColor &color);
105  inline void setColor(ColorRole cr, const QColor &color);
106  inline void setBrush(ColorRole cr, const QBrush &brush);
107  bool isBrushSet(ColorGroup cg, ColorRole cr) const;
108  void setBrush(ColorGroup cg, ColorRole cr, const QBrush &brush);
109  void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button,
110  const QBrush &light, const QBrush &dark, const QBrush &mid,
111  const QBrush &text, const QBrush &bright_text, const QBrush &base,
112  const QBrush &window);
113  bool isEqual(ColorGroup cr1, ColorGroup cr2) const;
114 
115  inline const QColor &color(ColorRole cr) const { return color(Current, cr); }
116  inline const QBrush &brush(ColorRole cr) const { return brush(Current, cr); }
117  inline const QBrush &windowText() const { return brush(WindowText); }
118  inline const QBrush &button() const { return brush(Button); }
119  inline const QBrush &light() const { return brush(Light); }
120  inline const QBrush &dark() const { return brush(Dark); }
121  inline const QBrush &mid() const { return brush(Mid); }
122  inline const QBrush &text() const { return brush(Text); }
123  inline const QBrush &base() const { return brush(Base); }
124  inline const QBrush &alternateBase() const { return brush(AlternateBase); }
125  inline const QBrush &toolTipBase() const { return brush(ToolTipBase); }
126  inline const QBrush &toolTipText() const { return brush(ToolTipText); }
127  inline const QBrush &window() const { return brush(Window); }
128  inline const QBrush &midlight() const { return brush(Midlight); }
129  inline const QBrush &brightText() const { return brush(BrightText); }
130  inline const QBrush &buttonText() const { return brush(ButtonText); }
131  inline const QBrush &shadow() const { return brush(Shadow); }
132  inline const QBrush &highlight() const { return brush(Highlight); }
133  inline const QBrush &highlightedText() const { return brush(HighlightedText); }
134  inline const QBrush &link() const { return brush(Link); }
135  inline const QBrush &linkVisited() const { return brush(LinkVisited); }
136  inline const QBrush &placeholderText() const { return brush(PlaceholderText); }
137 
138  bool operator==(const QPalette &p) const;
139  inline bool operator!=(const QPalette &p) const { return !(operator==(p)); }
140  bool isCopyOf(const QPalette &p) const;
141 
142  qint64 cacheKey() const;
143 
144  QPalette resolve(const QPalette &other) const;
145 
147  ResolveMask resolveMask() const;
148  void setResolveMask(ResolveMask mask);
149 
150 private:
151  void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button,
152  const QBrush &light, const QBrush &dark, const QBrush &mid,
153  const QBrush &text, const QBrush &bright_text,
154  const QBrush &base, const QBrush &alternate_base,
155  const QBrush &window, const QBrush &midlight,
156  const QBrush &button_text, const QBrush &shadow,
157  const QBrush &highlight, const QBrush &highlighted_text,
158  const QBrush &link, const QBrush &link_visited);
159  void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button,
160  const QBrush &light, const QBrush &dark, const QBrush &mid,
161  const QBrush &text, const QBrush &bright_text,
162  const QBrush &base, const QBrush &alternate_base,
163  const QBrush &window, const QBrush &midlight,
164  const QBrush &button_text, const QBrush &shadow,
165  const QBrush &highlight, const QBrush &highlighted_text,
166  const QBrush &link, const QBrush &link_visited,
167  const QBrush &toolTipBase, const QBrush &toolTipText);
168  void init();
169  void detach();
170 
172  ColorGroup currentGroup{Active};
173 
174  friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const QPalette &p);
175 };
176 
178 
180  const QColor &acolor)
181 { setBrush(acg, acr, QBrush(acolor)); }
182 inline void QPalette::setColor(ColorRole acr, const QColor &acolor)
183 { setColor(All, acr, acolor); }
184 inline void QPalette::setBrush(ColorRole acr, const QBrush &abrush)
185 { setBrush(All, acr, abrush); }
186 
187 /*****************************************************************************
188  QPalette stream functions
189  *****************************************************************************/
190 #ifndef QT_NO_DATASTREAM
191 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &ds, const QPalette &p);
193 #endif // QT_NO_DATASTREAM
194 
195 #ifndef QT_NO_DEBUG_STREAM
196 Q_GUI_EXPORT QDebug operator<<(QDebug, const QPalette &);
197 #endif
198 
200 
201 #endif // QPALETTE_H
[0]
Definition: button.h:58
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:66
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:66
operator>>(QDataStream &ds, qfloat16 &f)
Definition: qfloat16.cpp:344
operator<<(QDataStream &ds, qfloat16 f)
Definition: qfloat16.cpp:327
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:65
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:55
const QBrush & highlight() const
Definition: qpalette.h:132
const QBrush & button() const
Definition: qpalette.h:118
const QBrush & text() const
Definition: qpalette.h:122
const QBrush & toolTipBase() const
Definition: qpalette.h:125
const QBrush & windowText() const
Definition: qpalette.h:117
QPalette(QPalette &&other) noexcept
Definition: qpalette.h:70
const QBrush & dark() const
Definition: qpalette.h:120
bool operator!=(const QPalette &p) const
Definition: qpalette.h:139
const QBrush & toolTipText() const
Definition: qpalette.h:126
const QBrush & link() const
Definition: qpalette.h:134
const QBrush & shadow() const
Definition: qpalette.h:131
const QBrush & brightText() const
Definition: qpalette.h:129
const QBrush & brush(ColorRole cr) const
Definition: qpalette.h:116
const QBrush & light() const
Definition: qpalette.h:119
quint64 ResolveMask
Definition: qpalette.h:146
void setCurrentColorGroup(ColorGroup cg)
Definition: qpalette.h:99
const QColor & color(ColorGroup cg, ColorRole cr) const
Definition: qpalette.h:101
const QBrush & linkVisited() const
Definition: qpalette.h:135
const QBrush & mid() const
Definition: qpalette.h:121
void setBrush(ColorRole cr, const QBrush &brush)
Definition: qpalette.h:184
const QBrush & alternateBase() const
Definition: qpalette.h:124
const QColor & color(ColorRole cr) const
Definition: qpalette.h:115
const QBrush & midlight() const
Definition: qpalette.h:128
ColorGroup
Definition: qpalette.h:84
@ Active
Definition: qpalette.h:84
void setColor(ColorGroup cg, ColorRole cr, const QColor &color)
Definition: qpalette.h:179
const QBrush & placeholderText() const
Definition: qpalette.h:136
const QBrush & window() const
Definition: qpalette.h:127
const QBrush & base() const
Definition: qpalette.h:123
@ ToolTipBase
Definition: qpalette.h:92
@ Button
Definition: qpalette.h:86
@ Link
Definition: qpalette.h:89
@ AlternateBase
Definition: qpalette.h:90
@ Base
Definition: qpalette.h:87
@ Highlight
Definition: qpalette.h:88
@ NoRole
Definition: qpalette.h:91
@ PlaceholderText
Definition: qpalette.h:93
const QBrush & buttonText() const
Definition: qpalette.h:130
const QBrush & highlightedText() const
Definition: qpalette.h:133
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:95
[Window class definition]
Definition: window.h:64
Definition: base.h:37
QPushButton * button
[2]
palette
auto it unsigned count const
Definition: hb-iter.hh:848
#define inline
Definition: md4c.c:45
@ Active
Definition: qprint_p.h:92
GlobalColor
Definition: qnamespace.h:58
Definition: brush.cpp:52
void swap(SimpleVector< T > &v1, SimpleVector< T > &v2)
Definition: simplevector.h:331
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld init[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1 beq endif SRC MASK if dst_r_bpp DST_R else add endif PF add sub src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head pixblock_size cache_preload_simple process_pixblock_tail pixinterleave dst_w_basereg irp beq endif process_pixblock_tail_head tst beq irp if pixblock_size chunk_size tst beq pixld SRC pixld MASK if DST_R else pixld DST_R endif if src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head if pixblock_size cache_preload_simple endif process_pixblock_tail pixinterleave dst_w_basereg irp if pixblock_size chunk_size tst beq if DST_W else pixst DST_W else mov ORIG_W endif add lsl if lsl endif if lsl endif lsl endif lsl endif lsl endif subs mov DST_W if regs_shortage str endif bge start_of_loop_label endm macro generate_composite_function
void
Definition: png.h:1080
unsigned long long quint64
Definition: qglobal.h:299
long long qint64
Definition: qglobal.h:298
#define QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(Class)
Definition: qglobal.h:563
@ text
bool operator==(const QMakeBaseKey &one, const QMakeBaseKey &two)
GLuint color
[2]
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLdouble s
[6]
Definition: qopenglext.h:235
GLfloat GLfloat p
[1]
Definition: qopenglext.h:12698
Q_GUI_EXPORT QDataStream & operator<<(QDataStream &ds, const QPalette &p)
#define Q_ENUM(x)
Definition: qtmetamacros.h:104
#define Q_GADGET
Definition: qtmetamacros.h:193
#define Q_DECLARE_SHARED(TYPE)
Definition: qtypeinfo.h:197
struct Window Window
Definition: sqlite3.c:14312
QSharedPointer< T > other(t)
[5]
this swap(other)
myFilter setColor(QColor(128, 0, 0))
aWidget window() -> setWindowTitle("New Window Title")
[2]
void light()