Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/kernel/qpalette.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
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 http://www.qt.io/terms-conditions. For further | - | ||||||||||||
15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||
25 | ** | - | ||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||
29 | ** | - | ||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||
31 | ** | - | ||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||
33 | - | |||||||||||||
34 | #include "qpalette.h" | - | ||||||||||||
35 | #include "qguiapplication.h" | - | ||||||||||||
36 | #include "qguiapplication_p.h" | - | ||||||||||||
37 | #include "qdatastream.h" | - | ||||||||||||
38 | #include "qvariant.h" | - | ||||||||||||
39 | #include "qdebug.h" | - | ||||||||||||
40 | - | |||||||||||||
41 | QT_BEGIN_NAMESPACE | - | ||||||||||||
42 | - | |||||||||||||
43 | static int qt_palette_count = 1; | - | ||||||||||||
44 | - | |||||||||||||
45 | class QPalettePrivate { | - | ||||||||||||
46 | public: | - | ||||||||||||
47 | QPalettePrivate() : ref(1), ser_no(qt_palette_count++), detach_no(0) { } never executed: end of block | 0 | ||||||||||||
48 | QAtomicInt ref; | - | ||||||||||||
49 | QBrush br[QPalette::NColorGroups][QPalette::NColorRoles]; | - | ||||||||||||
50 | int ser_no; | - | ||||||||||||
51 | int detach_no; | - | ||||||||||||
52 | }; | - | ||||||||||||
53 | - | |||||||||||||
54 | static QColor qt_mix_colors(QColor a, QColor b) | - | ||||||||||||
55 | { | - | ||||||||||||
56 | return QColor((a.red() + b.red()) / 2, (a.green() + b.green()) / 2, never executed: return QColor((a.red() + b.red()) / 2, (a.green() + b.green()) / 2, (a.blue() + b.blue()) / 2, (a.alpha() + b.alpha()) / 2); | 0 | ||||||||||||
57 | (a.blue() + b.blue()) / 2, (a.alpha() + b.alpha()) / 2); never executed: return QColor((a.red() + b.red()) / 2, (a.green() + b.green()) / 2, (a.blue() + b.blue()) / 2, (a.alpha() + b.alpha()) / 2); | 0 | ||||||||||||
58 | } | - | ||||||||||||
59 | - | |||||||||||||
60 | static void qt_palette_from_color(QPalette &pal, const QColor &button) | - | ||||||||||||
61 | { | - | ||||||||||||
62 | int h, s, v; | - | ||||||||||||
63 | button.getHsv(&h, &s, &v); | - | ||||||||||||
64 | // inactive and active are the same.. | - | ||||||||||||
65 | const QBrush whiteBrush = QBrush(Qt::white); | - | ||||||||||||
66 | const QBrush blackBrush = QBrush(Qt::black); | - | ||||||||||||
67 | const QBrush baseBrush = v > 128 ? whiteBrush : blackBrush;
| 0 | ||||||||||||
68 | const QBrush foregroundBrush = v > 128 ? blackBrush : whiteBrush;
| 0 | ||||||||||||
69 | const QBrush buttonBrush = QBrush(button); | - | ||||||||||||
70 | const QBrush buttonBrushDark = QBrush(button.darker()); | - | ||||||||||||
71 | const QBrush buttonBrushDark150 = QBrush(button.darker(150)); | - | ||||||||||||
72 | const QBrush buttonBrushLight150 = QBrush(button.lighter(150)); | - | ||||||||||||
73 | pal.setColorGroup(QPalette::Active, foregroundBrush, buttonBrush, buttonBrushLight150, | - | ||||||||||||
74 | buttonBrushDark, buttonBrushDark150, foregroundBrush, whiteBrush, | - | ||||||||||||
75 | baseBrush, buttonBrush); | - | ||||||||||||
76 | pal.setColorGroup(QPalette::Inactive, foregroundBrush, buttonBrush, buttonBrushLight150, | - | ||||||||||||
77 | buttonBrushDark, buttonBrushDark150, foregroundBrush, whiteBrush, | - | ||||||||||||
78 | baseBrush, buttonBrush); | - | ||||||||||||
79 | pal.setColorGroup(QPalette::Disabled, buttonBrushDark, buttonBrush, buttonBrushLight150, | - | ||||||||||||
80 | buttonBrushDark, buttonBrushDark150, buttonBrushDark, | - | ||||||||||||
81 | whiteBrush, buttonBrush, buttonBrush); | - | ||||||||||||
82 | } never executed: end of block | 0 | ||||||||||||
83 | - | |||||||||||||
84 | /*! | - | ||||||||||||
85 | \fn QPalette &QPalette::operator=(QPalette &&other) | - | ||||||||||||
86 | - | |||||||||||||
87 | Move-assigns \a other to this QPalette instance. | - | ||||||||||||
88 | - | |||||||||||||
89 | \since 5.2 | - | ||||||||||||
90 | */ | - | ||||||||||||
91 | - | |||||||||||||
92 | /*! | - | ||||||||||||
93 | \fn const QColor &QPalette::color(ColorRole role) const | - | ||||||||||||
94 | - | |||||||||||||
95 | \overload | - | ||||||||||||
96 | - | |||||||||||||
97 | Returns the color that has been set for the given color \a role in | - | ||||||||||||
98 | the current ColorGroup. | - | ||||||||||||
99 | - | |||||||||||||
100 | \sa brush(), ColorRole | - | ||||||||||||
101 | */ | - | ||||||||||||
102 | - | |||||||||||||
103 | /*! | - | ||||||||||||
104 | \fn const QBrush &QPalette::brush(ColorRole role) const | - | ||||||||||||
105 | - | |||||||||||||
106 | \overload | - | ||||||||||||
107 | - | |||||||||||||
108 | Returns the brush that has been set for the given color \a role in | - | ||||||||||||
109 | the current ColorGroup. | - | ||||||||||||
110 | - | |||||||||||||
111 | \sa color(), setBrush(), ColorRole | - | ||||||||||||
112 | */ | - | ||||||||||||
113 | - | |||||||||||||
114 | /*! | - | ||||||||||||
115 | \fn void QPalette::setColor(ColorRole role, const QColor &color) | - | ||||||||||||
116 | - | |||||||||||||
117 | \overload | - | ||||||||||||
118 | - | |||||||||||||
119 | Sets the color used for the given color \a role, in all color | - | ||||||||||||
120 | groups, to the specified solid \a color. | - | ||||||||||||
121 | - | |||||||||||||
122 | \sa brush(), setColor(), ColorRole | - | ||||||||||||
123 | */ | - | ||||||||||||
124 | - | |||||||||||||
125 | /*! | - | ||||||||||||
126 | \fn void QPalette::setBrush(ColorRole role, const QBrush &brush) | - | ||||||||||||
127 | - | |||||||||||||
128 | Sets the brush for the given color \a role to the specified \a | - | ||||||||||||
129 | brush for all groups in the palette. | - | ||||||||||||
130 | - | |||||||||||||
131 | \sa brush(), setColor(), ColorRole | - | ||||||||||||
132 | */ | - | ||||||||||||
133 | - | |||||||||||||
134 | /*! | - | ||||||||||||
135 | \fn const QBrush & QPalette::foreground() const | - | ||||||||||||
136 | \obsolete | - | ||||||||||||
137 | - | |||||||||||||
138 | Use windowText() instead. | - | ||||||||||||
139 | */ | - | ||||||||||||
140 | - | |||||||||||||
141 | /*! | - | ||||||||||||
142 | \fn const QBrush & QPalette::windowText() const | - | ||||||||||||
143 | - | |||||||||||||
144 | Returns the window text (general foreground) brush of the | - | ||||||||||||
145 | current color group. | - | ||||||||||||
146 | - | |||||||||||||
147 | \sa ColorRole, brush() | - | ||||||||||||
148 | */ | - | ||||||||||||
149 | - | |||||||||||||
150 | /*! | - | ||||||||||||
151 | \fn const QBrush & QPalette::button() const | - | ||||||||||||
152 | - | |||||||||||||
153 | Returns the button brush of the current color group. | - | ||||||||||||
154 | - | |||||||||||||
155 | \sa ColorRole, brush() | - | ||||||||||||
156 | */ | - | ||||||||||||
157 | - | |||||||||||||
158 | /*! | - | ||||||||||||
159 | \fn const QBrush & QPalette::light() const | - | ||||||||||||
160 | - | |||||||||||||
161 | Returns the light brush of the current color group. | - | ||||||||||||
162 | - | |||||||||||||
163 | \sa ColorRole, brush() | - | ||||||||||||
164 | */ | - | ||||||||||||
165 | - | |||||||||||||
166 | /*! | - | ||||||||||||
167 | \fn const QBrush& QPalette::midlight() const | - | ||||||||||||
168 | - | |||||||||||||
169 | Returns the midlight brush of the current color group. | - | ||||||||||||
170 | - | |||||||||||||
171 | \sa ColorRole, brush() | - | ||||||||||||
172 | */ | - | ||||||||||||
173 | - | |||||||||||||
174 | /*! | - | ||||||||||||
175 | \fn const QBrush & QPalette::dark() const | - | ||||||||||||
176 | - | |||||||||||||
177 | Returns the dark brush of the current color group. | - | ||||||||||||
178 | - | |||||||||||||
179 | \sa ColorRole, brush() | - | ||||||||||||
180 | */ | - | ||||||||||||
181 | - | |||||||||||||
182 | /*! | - | ||||||||||||
183 | \fn const QBrush & QPalette::mid() const | - | ||||||||||||
184 | - | |||||||||||||
185 | Returns the mid brush of the current color group. | - | ||||||||||||
186 | - | |||||||||||||
187 | \sa ColorRole, brush() | - | ||||||||||||
188 | */ | - | ||||||||||||
189 | - | |||||||||||||
190 | /*! | - | ||||||||||||
191 | \fn const QBrush & QPalette::text() const | - | ||||||||||||
192 | - | |||||||||||||
193 | Returns the text foreground brush of the current color group. | - | ||||||||||||
194 | - | |||||||||||||
195 | \sa ColorRole, brush() | - | ||||||||||||
196 | */ | - | ||||||||||||
197 | - | |||||||||||||
198 | /*! | - | ||||||||||||
199 | \fn const QBrush & QPalette::brightText() const | - | ||||||||||||
200 | - | |||||||||||||
201 | Returns the bright text foreground brush of the current color group. | - | ||||||||||||
202 | - | |||||||||||||
203 | \sa ColorRole, brush() | - | ||||||||||||
204 | */ | - | ||||||||||||
205 | - | |||||||||||||
206 | /*! | - | ||||||||||||
207 | \fn const QBrush & QPalette::buttonText() const | - | ||||||||||||
208 | - | |||||||||||||
209 | Returns the button text foreground brush of the current color group. | - | ||||||||||||
210 | - | |||||||||||||
211 | \sa ColorRole, brush() | - | ||||||||||||
212 | */ | - | ||||||||||||
213 | - | |||||||||||||
214 | /*! | - | ||||||||||||
215 | \fn const QBrush & QPalette::base() const | - | ||||||||||||
216 | - | |||||||||||||
217 | Returns the base brush of the current color group. | - | ||||||||||||
218 | - | |||||||||||||
219 | \sa ColorRole, brush() | - | ||||||||||||
220 | */ | - | ||||||||||||
221 | - | |||||||||||||
222 | /*! | - | ||||||||||||
223 | \fn const QBrush & QPalette::alternateBase() const | - | ||||||||||||
224 | - | |||||||||||||
225 | Returns the alternate base brush of the current color group. | - | ||||||||||||
226 | - | |||||||||||||
227 | \sa ColorRole, brush() | - | ||||||||||||
228 | */ | - | ||||||||||||
229 | - | |||||||||||||
230 | /*! | - | ||||||||||||
231 | \fn const QBrush & QPalette::toolTipBase() const | - | ||||||||||||
232 | \since 4.4 | - | ||||||||||||
233 | - | |||||||||||||
234 | Returns the tool tip base brush of the current color group. This brush is | - | ||||||||||||
235 | used by QToolTip and QWhatsThis. | - | ||||||||||||
236 | - | |||||||||||||
237 | \note Tool tips use the Inactive color group of QPalette, because tool | - | ||||||||||||
238 | tips are not active windows. | - | ||||||||||||
239 | - | |||||||||||||
240 | \sa ColorRole, brush() | - | ||||||||||||
241 | */ | - | ||||||||||||
242 | - | |||||||||||||
243 | /*! | - | ||||||||||||
244 | \fn const QBrush & QPalette::toolTipText() const | - | ||||||||||||
245 | \since 4.4 | - | ||||||||||||
246 | - | |||||||||||||
247 | Returns the tool tip text brush of the current color group. This brush is | - | ||||||||||||
248 | used by QToolTip and QWhatsThis. | - | ||||||||||||
249 | - | |||||||||||||
250 | \note Tool tips use the Inactive color group of QPalette, because tool | - | ||||||||||||
251 | tips are not active windows. | - | ||||||||||||
252 | - | |||||||||||||
253 | \sa ColorRole, brush() | - | ||||||||||||
254 | */ | - | ||||||||||||
255 | - | |||||||||||||
256 | /*! | - | ||||||||||||
257 | \fn const QBrush & QPalette::background() const | - | ||||||||||||
258 | \obsolete | - | ||||||||||||
259 | - | |||||||||||||
260 | Use window() instead. | - | ||||||||||||
261 | */ | - | ||||||||||||
262 | - | |||||||||||||
263 | /*! | - | ||||||||||||
264 | \fn const QBrush & QPalette::window() const | - | ||||||||||||
265 | - | |||||||||||||
266 | Returns the window (general background) brush of the current | - | ||||||||||||
267 | color group. | - | ||||||||||||
268 | - | |||||||||||||
269 | \sa ColorRole, brush() | - | ||||||||||||
270 | */ | - | ||||||||||||
271 | - | |||||||||||||
272 | /*! | - | ||||||||||||
273 | \fn const QBrush & QPalette::shadow() const | - | ||||||||||||
274 | - | |||||||||||||
275 | Returns the shadow brush of the current color group. | - | ||||||||||||
276 | - | |||||||||||||
277 | \sa ColorRole, brush() | - | ||||||||||||
278 | */ | - | ||||||||||||
279 | - | |||||||||||||
280 | /*! | - | ||||||||||||
281 | \fn const QBrush & QPalette::highlight() const | - | ||||||||||||
282 | - | |||||||||||||
283 | Returns the highlight brush of the current color group. | - | ||||||||||||
284 | - | |||||||||||||
285 | \sa ColorRole, brush() | - | ||||||||||||
286 | */ | - | ||||||||||||
287 | - | |||||||||||||
288 | /*! | - | ||||||||||||
289 | \fn const QBrush & QPalette::highlightedText() const | - | ||||||||||||
290 | - | |||||||||||||
291 | Returns the highlighted text brush of the current color group. | - | ||||||||||||
292 | - | |||||||||||||
293 | \sa ColorRole, brush() | - | ||||||||||||
294 | */ | - | ||||||||||||
295 | - | |||||||||||||
296 | /*! | - | ||||||||||||
297 | \fn const QBrush & QPalette::link() const | - | ||||||||||||
298 | - | |||||||||||||
299 | Returns the unvisited link text brush of the current color group. | - | ||||||||||||
300 | - | |||||||||||||
301 | \sa ColorRole, brush() | - | ||||||||||||
302 | */ | - | ||||||||||||
303 | - | |||||||||||||
304 | /*! | - | ||||||||||||
305 | \fn const QBrush & QPalette::linkVisited() const | - | ||||||||||||
306 | - | |||||||||||||
307 | Returns the visited link text brush of the current color group. | - | ||||||||||||
308 | - | |||||||||||||
309 | \sa ColorRole, brush() | - | ||||||||||||
310 | */ | - | ||||||||||||
311 | - | |||||||||||||
312 | /*! | - | ||||||||||||
313 | \fn ColorGroup QPalette::currentColorGroup() const | - | ||||||||||||
314 | - | |||||||||||||
315 | Returns the palette's current color group. | - | ||||||||||||
316 | */ | - | ||||||||||||
317 | - | |||||||||||||
318 | /*! | - | ||||||||||||
319 | \fn void QPalette::setCurrentColorGroup(ColorGroup cg) | - | ||||||||||||
320 | - | |||||||||||||
321 | Set the palette's current color group to \a cg. | - | ||||||||||||
322 | */ | - | ||||||||||||
323 | - | |||||||||||||
324 | /*! | - | ||||||||||||
325 | \class QPalette | - | ||||||||||||
326 | - | |||||||||||||
327 | \brief The QPalette class contains color groups for each widget state. | - | ||||||||||||
328 | - | |||||||||||||
329 | \inmodule QtGui | - | ||||||||||||
330 | \ingroup appearance | - | ||||||||||||
331 | \ingroup shared | - | ||||||||||||
332 | - | |||||||||||||
333 | A palette consists of three color groups: \e Active, \e Disabled, | - | ||||||||||||
334 | and \e Inactive. All widgets in Qt contain a palette and | - | ||||||||||||
335 | use their palette to draw themselves. This makes the user | - | ||||||||||||
336 | interface easily configurable and easier to keep consistent. | - | ||||||||||||
337 | - | |||||||||||||
338 | - | |||||||||||||
339 | If you create a new widget we strongly recommend that you use the | - | ||||||||||||
340 | colors in the palette rather than hard-coding specific colors. | - | ||||||||||||
341 | - | |||||||||||||
342 | The color groups: | - | ||||||||||||
343 | \list | - | ||||||||||||
344 | \li The Active group is used for the window that has keyboard focus. | - | ||||||||||||
345 | \li The Inactive group is used for other windows. | - | ||||||||||||
346 | \li The Disabled group is used for widgets (not windows) that are | - | ||||||||||||
347 | disabled for some reason. | - | ||||||||||||
348 | \endlist | - | ||||||||||||
349 | - | |||||||||||||
350 | Both active and inactive windows can contain disabled widgets. | - | ||||||||||||
351 | (Disabled widgets are often called \e inaccessible or \e{grayed | - | ||||||||||||
352 | out}.) | - | ||||||||||||
353 | - | |||||||||||||
354 | In most styles, Active and Inactive look the same. | - | ||||||||||||
355 | - | |||||||||||||
356 | Colors and brushes can be set for particular roles in any of a palette's | - | ||||||||||||
357 | color groups with setColor() and setBrush(). A color group contains a | - | ||||||||||||
358 | group of colors used by widgets for drawing themselves. We recommend that | - | ||||||||||||
359 | widgets use color group roles from the palette such as "foreground" and | - | ||||||||||||
360 | "base" rather than literal colors like "red" or "turquoise". The color | - | ||||||||||||
361 | roles are enumerated and defined in the \l ColorRole documentation. | - | ||||||||||||
362 | - | |||||||||||||
363 | We strongly recommend that you use the default palette of the | - | ||||||||||||
364 | current style (returned by QGuiApplication::palette()) and | - | ||||||||||||
365 | modify that as necessary. This is done by Qt's widgets when they | - | ||||||||||||
366 | are drawn. | - | ||||||||||||
367 | - | |||||||||||||
368 | To modify a color group you call the functions | - | ||||||||||||
369 | setColor() and setBrush(), depending on whether you want a pure | - | ||||||||||||
370 | color or a pixmap pattern. | - | ||||||||||||
371 | - | |||||||||||||
372 | There are also corresponding color() and brush() getters, and a | - | ||||||||||||
373 | commonly used convenience function to get the ColorRole for the current ColorGroup: | - | ||||||||||||
374 | window(), windowText(), base(), etc. | - | ||||||||||||
375 | - | |||||||||||||
376 | - | |||||||||||||
377 | You can copy a palette using the copy constructor and test to see | - | ||||||||||||
378 | if two palettes are \e identical using isCopyOf(). | - | ||||||||||||
379 | - | |||||||||||||
380 | QPalette is optimized by the use of \l{implicit sharing}, | - | ||||||||||||
381 | so it is very efficient to pass QPalette objects as arguments. | - | ||||||||||||
382 | - | |||||||||||||
383 | \warning Some styles do not use the palette for all drawing, for | - | ||||||||||||
384 | instance, if they make use of native theme engines. This is the | - | ||||||||||||
385 | case for both the Windows XP, Windows Vista, and the \macos | - | ||||||||||||
386 | styles. | - | ||||||||||||
387 | - | |||||||||||||
388 | \sa QApplication::setPalette(), QWidget::setPalette(), QColor | - | ||||||||||||
389 | */ | - | ||||||||||||
390 | - | |||||||||||||
391 | /*! | - | ||||||||||||
392 | \enum QPalette::ColorGroup | - | ||||||||||||
393 | - | |||||||||||||
394 | \value Disabled | - | ||||||||||||
395 | \value Active | - | ||||||||||||
396 | \value Inactive | - | ||||||||||||
397 | \value Normal synonym for Active | - | ||||||||||||
398 | - | |||||||||||||
399 | \omitvalue All | - | ||||||||||||
400 | \omitvalue NColorGroups | - | ||||||||||||
401 | \omitvalue Current | - | ||||||||||||
402 | */ | - | ||||||||||||
403 | - | |||||||||||||
404 | /*! | - | ||||||||||||
405 | \enum QPalette::ColorRole | - | ||||||||||||
406 | - | |||||||||||||
407 | \image palette.png Color Roles | - | ||||||||||||
408 | - | |||||||||||||
409 | The ColorRole enum defines the different symbolic color roles used | - | ||||||||||||
410 | in current GUIs. | - | ||||||||||||
411 | - | |||||||||||||
412 | The central roles are: | - | ||||||||||||
413 | - | |||||||||||||
414 | \value Window A general background color. | - | ||||||||||||
415 | - | |||||||||||||
416 | \value Background This value is obsolete. Use Window instead. | - | ||||||||||||
417 | - | |||||||||||||
418 | \value WindowText A general foreground color. | - | ||||||||||||
419 | - | |||||||||||||
420 | \value Foreground This value is obsolete. Use WindowText instead. | - | ||||||||||||
421 | - | |||||||||||||
422 | \value Base Used mostly as the background color for text entry widgets, | - | ||||||||||||
423 | but can also be used for other painting - such as the | - | ||||||||||||
424 | background of combobox drop down lists and toolbar handles. | - | ||||||||||||
425 | It is usually white or another light color. | - | ||||||||||||
426 | - | |||||||||||||
427 | \value AlternateBase Used as the alternate background color in views with | - | ||||||||||||
428 | alternating row colors (see | - | ||||||||||||
429 | QAbstractItemView::setAlternatingRowColors()). | - | ||||||||||||
430 | - | |||||||||||||
431 | \value ToolTipBase Used as the background color for QToolTip and | - | ||||||||||||
432 | QWhatsThis. Tool tips use the Inactive color group | - | ||||||||||||
433 | of QPalette, because tool tips are not active | - | ||||||||||||
434 | windows. | - | ||||||||||||
435 | - | |||||||||||||
436 | \value ToolTipText Used as the foreground color for QToolTip and | - | ||||||||||||
437 | QWhatsThis. Tool tips use the Inactive color group | - | ||||||||||||
438 | of QPalette, because tool tips are not active | - | ||||||||||||
439 | windows. | - | ||||||||||||
440 | - | |||||||||||||
441 | \value Text The foreground color used with \c Base. This is usually | - | ||||||||||||
442 | the same as the \c WindowText, in which case it must provide | - | ||||||||||||
443 | good contrast with \c Window and \c Base. | - | ||||||||||||
444 | - | |||||||||||||
445 | \value Button The general button background color. This background can be different from | - | ||||||||||||
446 | \c Window as some styles require a different background color for buttons. | - | ||||||||||||
447 | - | |||||||||||||
448 | \value ButtonText A foreground color used with the \c Button color. | - | ||||||||||||
449 | - | |||||||||||||
450 | \value BrightText A text color that is very different from | - | ||||||||||||
451 | \c WindowText, and contrasts well with e.g. \c | - | ||||||||||||
452 | Dark. Typically used for text that needs to be | - | ||||||||||||
453 | drawn where \c Text or \c WindowText would give | - | ||||||||||||
454 | poor contrast, such as on pressed push buttons. | - | ||||||||||||
455 | Note that text colors can be used for things | - | ||||||||||||
456 | other than just words; text colors are \e | - | ||||||||||||
457 | usually used for text, but it's quite common to | - | ||||||||||||
458 | use the text color roles for lines, icons, etc. | - | ||||||||||||
459 | - | |||||||||||||
460 | - | |||||||||||||
461 | There are some color roles used mostly for 3D bevel and shadow effects. | - | ||||||||||||
462 | All of these are normally derived from \c Window, and used in ways that | - | ||||||||||||
463 | depend on that relationship. For example, buttons depend on it to make the | - | ||||||||||||
464 | bevels look attractive, and Motif scroll bars depend on \c Mid to be | - | ||||||||||||
465 | slightly different from \c Window. | - | ||||||||||||
466 | - | |||||||||||||
467 | \value Light Lighter than \c Button color. | - | ||||||||||||
468 | - | |||||||||||||
469 | \value Midlight Between \c Button and \c Light. | - | ||||||||||||
470 | - | |||||||||||||
471 | \value Dark Darker than \c Button. | - | ||||||||||||
472 | - | |||||||||||||
473 | \value Mid Between \c Button and \c Dark. | - | ||||||||||||
474 | - | |||||||||||||
475 | \value Shadow A very dark color. By default, the shadow color is | - | ||||||||||||
476 | Qt::black. | - | ||||||||||||
477 | - | |||||||||||||
478 | - | |||||||||||||
479 | Selected (marked) items have two roles: | - | ||||||||||||
480 | - | |||||||||||||
481 | \value Highlight A color to indicate a selected item or the current | - | ||||||||||||
482 | item. By default, the highlight color is | - | ||||||||||||
483 | Qt::darkBlue. | - | ||||||||||||
484 | - | |||||||||||||
485 | \value HighlightedText A text color that contrasts with \c Highlight. | - | ||||||||||||
486 | By default, the highlighted text color is Qt::white. | - | ||||||||||||
487 | - | |||||||||||||
488 | There are two color roles related to hyperlinks: | - | ||||||||||||
489 | - | |||||||||||||
490 | \value Link A text color used for unvisited hyperlinks. | - | ||||||||||||
491 | By default, the link color is Qt::blue. | - | ||||||||||||
492 | - | |||||||||||||
493 | \value LinkVisited A text color used for already visited hyperlinks. | - | ||||||||||||
494 | By default, the linkvisited color is Qt::magenta. | - | ||||||||||||
495 | - | |||||||||||||
496 | Note that we do not use the \c Link and \c LinkVisited roles when | - | ||||||||||||
497 | rendering rich text in Qt, and that we recommend that you use CSS | - | ||||||||||||
498 | and the QTextDocument::setDefaultStyleSheet() function to alter | - | ||||||||||||
499 | the appearance of links. For example: | - | ||||||||||||
500 | - | |||||||||||||
501 | \snippet textdocument-css/main.cpp 0 | - | ||||||||||||
502 | - | |||||||||||||
503 | \value NoRole No role; this special role is often used to indicate that a | - | ||||||||||||
504 | role has not been assigned. | - | ||||||||||||
505 | - | |||||||||||||
506 | \omitvalue NColorRoles | - | ||||||||||||
507 | */ | - | ||||||||||||
508 | - | |||||||||||||
509 | /*! | - | ||||||||||||
510 | Constructs a palette object that uses the application's default palette. | - | ||||||||||||
511 | - | |||||||||||||
512 | \sa QApplication::setPalette(), QApplication::palette() | - | ||||||||||||
513 | */ | - | ||||||||||||
514 | QPalette::QPalette() | - | ||||||||||||
515 | : d(0) | - | ||||||||||||
516 | { | - | ||||||||||||
517 | data.current_group = Active; | - | ||||||||||||
518 | data.resolve_mask = 0; | - | ||||||||||||
519 | // Initialize to application palette if present, else default to black. | - | ||||||||||||
520 | // This makes it possible to instantiate QPalette outside QGuiApplication, | - | ||||||||||||
521 | // for example in the platform plugins. | - | ||||||||||||
522 | if (QGuiApplicationPrivate::app_pal) {
| 0 | ||||||||||||
523 | d = QGuiApplicationPrivate::app_pal->d; | - | ||||||||||||
524 | d->ref.ref(); | - | ||||||||||||
525 | } else { never executed: end of block | 0 | ||||||||||||
526 | init(); | - | ||||||||||||
527 | qt_palette_from_color(*this, Qt::black); | - | ||||||||||||
528 | data.resolve_mask = 0; | - | ||||||||||||
529 | } never executed: end of block | 0 | ||||||||||||
530 | } | - | ||||||||||||
531 | - | |||||||||||||
532 | /*! | - | ||||||||||||
533 | Constructs a palette from the \a button color. The other colors are | - | ||||||||||||
534 | automatically calculated, based on this color. \c Window will be | - | ||||||||||||
535 | the button color as well. | - | ||||||||||||
536 | */ | - | ||||||||||||
537 | QPalette::QPalette(const QColor &button) | - | ||||||||||||
538 | { | - | ||||||||||||
539 | init(); | - | ||||||||||||
540 | qt_palette_from_color(*this, button); | - | ||||||||||||
541 | } never executed: end of block | 0 | ||||||||||||
542 | - | |||||||||||||
543 | /*! | - | ||||||||||||
544 | Constructs a palette from the \a button color. The other colors are | - | ||||||||||||
545 | automatically calculated, based on this color. \c Window will be | - | ||||||||||||
546 | the button color as well. | - | ||||||||||||
547 | */ | - | ||||||||||||
548 | QPalette::QPalette(Qt::GlobalColor button) | - | ||||||||||||
549 | { | - | ||||||||||||
550 | init(); | - | ||||||||||||
551 | qt_palette_from_color(*this, button); | - | ||||||||||||
552 | } never executed: end of block | 0 | ||||||||||||
553 | - | |||||||||||||
554 | /*! | - | ||||||||||||
555 | Constructs a palette. You can pass either brushes, pixmaps or | - | ||||||||||||
556 | plain colors for \a windowText, \a button, \a light, \a dark, \a | - | ||||||||||||
557 | mid, \a text, \a bright_text, \a base and \a window. | - | ||||||||||||
558 | - | |||||||||||||
559 | \sa QBrush | - | ||||||||||||
560 | */ | - | ||||||||||||
561 | QPalette::QPalette(const QBrush &windowText, const QBrush &button, | - | ||||||||||||
562 | const QBrush &light, const QBrush &dark, | - | ||||||||||||
563 | const QBrush &mid, const QBrush &text, | - | ||||||||||||
564 | const QBrush &bright_text, const QBrush &base, | - | ||||||||||||
565 | const QBrush &window) | - | ||||||||||||
566 | { | - | ||||||||||||
567 | init(); | - | ||||||||||||
568 | setColorGroup(All, windowText, button, light, dark, mid, text, bright_text, | - | ||||||||||||
569 | base, window); | - | ||||||||||||
570 | } never executed: end of block | 0 | ||||||||||||
571 | - | |||||||||||||
572 | - | |||||||||||||
573 | /*!\obsolete | - | ||||||||||||
574 | - | |||||||||||||
575 | Constructs a palette with the specified \a windowText, \a | - | ||||||||||||
576 | window, \a light, \a dark, \a mid, \a text, and \a base colors. | - | ||||||||||||
577 | The button color will be set to the window color. | - | ||||||||||||
578 | */ | - | ||||||||||||
579 | QPalette::QPalette(const QColor &windowText, const QColor &window, | - | ||||||||||||
580 | const QColor &light, const QColor &dark, const QColor &mid, | - | ||||||||||||
581 | const QColor &text, const QColor &base) | - | ||||||||||||
582 | { | - | ||||||||||||
583 | init(); | - | ||||||||||||
584 | const QBrush windowBrush(window); | - | ||||||||||||
585 | const QBrush lightBrush(light); | - | ||||||||||||
586 | setColorGroup(All, QBrush(windowText), windowBrush, lightBrush, | - | ||||||||||||
587 | QBrush(dark), QBrush(mid), QBrush(text), lightBrush, | - | ||||||||||||
588 | QBrush(base), windowBrush); | - | ||||||||||||
589 | } never executed: end of block | 0 | ||||||||||||
590 | - | |||||||||||||
591 | /*! | - | ||||||||||||
592 | Constructs a palette from a \a button color and a \a window. | - | ||||||||||||
593 | The other colors are automatically calculated, based on these | - | ||||||||||||
594 | colors. | - | ||||||||||||
595 | */ | - | ||||||||||||
596 | QPalette::QPalette(const QColor &button, const QColor &window) | - | ||||||||||||
597 | { | - | ||||||||||||
598 | init(); | - | ||||||||||||
599 | int h, s, v; | - | ||||||||||||
600 | window.getHsv(&h, &s, &v); | - | ||||||||||||
601 | - | |||||||||||||
602 | const QBrush windowBrush = QBrush(window); | - | ||||||||||||
603 | const QBrush whiteBrush = QBrush(Qt::white); | - | ||||||||||||
604 | const QBrush blackBrush = QBrush(Qt::black); | - | ||||||||||||
605 | const QBrush baseBrush = v > 128 ? whiteBrush : blackBrush;
| 0 | ||||||||||||
606 | const QBrush foregroundBrush = v > 128 ? blackBrush : whiteBrush;
| 0 | ||||||||||||
607 | const QBrush disabledForeground = QBrush(Qt::darkGray); | - | ||||||||||||
608 | - | |||||||||||||
609 | const QBrush buttonBrush = QBrush(button); | - | ||||||||||||
610 | const QBrush buttonBrushDark = QBrush(button.darker()); | - | ||||||||||||
611 | const QBrush buttonBrushDark150 = QBrush(button.darker(150)); | - | ||||||||||||
612 | const QBrush buttonBrushLight150 = QBrush(button.lighter(150)); | - | ||||||||||||
613 | - | |||||||||||||
614 | //inactive and active are identical | - | ||||||||||||
615 | setColorGroup(Inactive, foregroundBrush, buttonBrush, buttonBrushLight150, buttonBrushDark, | - | ||||||||||||
616 | buttonBrushDark150, foregroundBrush, whiteBrush, baseBrush, | - | ||||||||||||
617 | windowBrush); | - | ||||||||||||
618 | setColorGroup(Active, foregroundBrush, buttonBrush, buttonBrushLight150, buttonBrushDark, | - | ||||||||||||
619 | buttonBrushDark150, foregroundBrush, whiteBrush, baseBrush, | - | ||||||||||||
620 | windowBrush); | - | ||||||||||||
621 | setColorGroup(Disabled, disabledForeground, buttonBrush, buttonBrushLight150, | - | ||||||||||||
622 | buttonBrushDark, buttonBrushDark150, disabledForeground, | - | ||||||||||||
623 | whiteBrush, baseBrush, windowBrush); | - | ||||||||||||
624 | } never executed: end of block | 0 | ||||||||||||
625 | - | |||||||||||||
626 | /*! | - | ||||||||||||
627 | Constructs a copy of \a p. | - | ||||||||||||
628 | - | |||||||||||||
629 | This constructor is fast thanks to \l{implicit sharing}. | - | ||||||||||||
630 | */ | - | ||||||||||||
631 | QPalette::QPalette(const QPalette &p) | - | ||||||||||||
632 | : d(p.d), data(p.data) | - | ||||||||||||
633 | { | - | ||||||||||||
634 | d->ref.ref(); | - | ||||||||||||
635 | } never executed: end of block | 0 | ||||||||||||
636 | - | |||||||||||||
637 | /*! | - | ||||||||||||
638 | \fn QPalette::QPalette(QPalette &&other) | - | ||||||||||||
639 | \since 5.4 | - | ||||||||||||
640 | - | |||||||||||||
641 | Move-constructs a QPalette instance, making it point at the same | - | ||||||||||||
642 | object that \a other was pointing to. | - | ||||||||||||
643 | - | |||||||||||||
644 | After being moved from, you can only assign to or destroy \a other. | - | ||||||||||||
645 | Any other operation will result in undefined behavior. | - | ||||||||||||
646 | */ | - | ||||||||||||
647 | - | |||||||||||||
648 | /*! | - | ||||||||||||
649 | Destroys the palette. | - | ||||||||||||
650 | */ | - | ||||||||||||
651 | QPalette::~QPalette() | - | ||||||||||||
652 | { | - | ||||||||||||
653 | if (d && !d->ref.deref())
| 0 | ||||||||||||
654 | delete d; never executed: delete d; | 0 | ||||||||||||
655 | } never executed: end of block | 0 | ||||||||||||
656 | - | |||||||||||||
657 | /*!\internal*/ | - | ||||||||||||
658 | void QPalette::init() { | - | ||||||||||||
659 | d = new QPalettePrivate; | - | ||||||||||||
660 | data.resolve_mask = 0; | - | ||||||||||||
661 | data.current_group = Active; //as a default.. | - | ||||||||||||
662 | } never executed: end of block | 0 | ||||||||||||
663 | - | |||||||||||||
664 | /*! | - | ||||||||||||
665 | Assigns \a p to this palette and returns a reference to this | - | ||||||||||||
666 | palette. | - | ||||||||||||
667 | - | |||||||||||||
668 | This operation is fast thanks to \l{implicit sharing}. | - | ||||||||||||
669 | */ | - | ||||||||||||
670 | QPalette &QPalette::operator=(const QPalette &p) | - | ||||||||||||
671 | { | - | ||||||||||||
672 | p.d->ref.ref(); | - | ||||||||||||
673 | data = p.data; | - | ||||||||||||
674 | if (d && !d->ref.deref())
| 0 | ||||||||||||
675 | delete d; never executed: delete d; | 0 | ||||||||||||
676 | d = p.d; | - | ||||||||||||
677 | return *this; never executed: return *this; | 0 | ||||||||||||
678 | } | - | ||||||||||||
679 | - | |||||||||||||
680 | /*! | - | ||||||||||||
681 | \fn void QPalette::swap(QPalette &other) | - | ||||||||||||
682 | \since 5.0 | - | ||||||||||||
683 | - | |||||||||||||
684 | Swaps this palette instance with \a other. This function is very | - | ||||||||||||
685 | fast and never fails. | - | ||||||||||||
686 | */ | - | ||||||||||||
687 | - | |||||||||||||
688 | /*! | - | ||||||||||||
689 | Returns the palette as a QVariant | - | ||||||||||||
690 | */ | - | ||||||||||||
691 | QPalette::operator QVariant() const | - | ||||||||||||
692 | { | - | ||||||||||||
693 | return QVariant(QVariant::Palette, this); never executed: return QVariant(QVariant::Palette, this); | 0 | ||||||||||||
694 | } | - | ||||||||||||
695 | - | |||||||||||||
696 | /*! | - | ||||||||||||
697 | \fn const QColor &QPalette::color(ColorGroup group, ColorRole role) const | - | ||||||||||||
698 | - | |||||||||||||
699 | Returns the color in the specified color \a group, used for the | - | ||||||||||||
700 | given color \a role. | - | ||||||||||||
701 | - | |||||||||||||
702 | \sa brush(), setColor(), ColorRole | - | ||||||||||||
703 | */ | - | ||||||||||||
704 | - | |||||||||||||
705 | /*! | - | ||||||||||||
706 | \fn const QBrush &QPalette::brush(ColorGroup group, ColorRole role) const | - | ||||||||||||
707 | - | |||||||||||||
708 | Returns the brush in the specified color \a group, used for the | - | ||||||||||||
709 | given color \a role. | - | ||||||||||||
710 | - | |||||||||||||
711 | \sa color(), setBrush(), ColorRole | - | ||||||||||||
712 | */ | - | ||||||||||||
713 | const QBrush &QPalette::brush(ColorGroup gr, ColorRole cr) const | - | ||||||||||||
714 | { | - | ||||||||||||
715 | Q_ASSERT(cr < NColorRoles); | - | ||||||||||||
716 | if(gr >= (int)NColorGroups) {
| 0 | ||||||||||||
717 | if(gr == Current) {
| 0 | ||||||||||||
718 | gr = (ColorGroup)data.current_group; | - | ||||||||||||
719 | } else { never executed: end of block | 0 | ||||||||||||
720 | qWarning("QPalette::brush: Unknown ColorGroup: %d", (int)gr); | - | ||||||||||||
721 | gr = Active; | - | ||||||||||||
722 | } never executed: end of block | 0 | ||||||||||||
723 | } | - | ||||||||||||
724 | return d->br[gr][cr]; never executed: return d->br[gr][cr]; | 0 | ||||||||||||
725 | } | - | ||||||||||||
726 | - | |||||||||||||
727 | /*! | - | ||||||||||||
728 | \fn void QPalette::setColor(ColorGroup group, ColorRole role, const QColor &color) | - | ||||||||||||
729 | - | |||||||||||||
730 | Sets the color in the specified color \a group, used for the given | - | ||||||||||||
731 | color \a role, to the specified solid \a color. | - | ||||||||||||
732 | - | |||||||||||||
733 | \sa setBrush(), color(), ColorRole | - | ||||||||||||
734 | */ | - | ||||||||||||
735 | - | |||||||||||||
736 | /*! | - | ||||||||||||
737 | \fn void QPalette::setBrush(ColorGroup group, ColorRole role, const QBrush &brush) | - | ||||||||||||
738 | \overload | - | ||||||||||||
739 | - | |||||||||||||
740 | Sets the brush in the specified color \a group, used for the given | - | ||||||||||||
741 | color \a role, to \a brush. | - | ||||||||||||
742 | - | |||||||||||||
743 | \sa brush(), setColor(), ColorRole | - | ||||||||||||
744 | */ | - | ||||||||||||
745 | void QPalette::setBrush(ColorGroup cg, ColorRole cr, const QBrush &b) | - | ||||||||||||
746 | { | - | ||||||||||||
747 | Q_ASSERT(cr < NColorRoles); | - | ||||||||||||
748 | detach(); | - | ||||||||||||
749 | if(cg >= (int)NColorGroups) {
| 0 | ||||||||||||
750 | if(cg == All) {
| 0 | ||||||||||||
751 | for(int i = 0; i < (int)NColorGroups; i++)
| 0 | ||||||||||||
752 | d->br[i][cr] = b; never executed: d->br[i][cr] = b; | 0 | ||||||||||||
753 | data.resolve_mask |= (1<<cr); | - | ||||||||||||
754 | return; never executed: return; | 0 | ||||||||||||
755 | } else if(cg == Current) {
| 0 | ||||||||||||
756 | cg = (ColorGroup)data.current_group; | - | ||||||||||||
757 | } else { never executed: end of block | 0 | ||||||||||||
758 | qWarning("QPalette::setBrush: Unknown ColorGroup: %d", (int)cg); | - | ||||||||||||
759 | cg = Active; | - | ||||||||||||
760 | } never executed: end of block | 0 | ||||||||||||
761 | } | - | ||||||||||||
762 | d->br[cg][cr] = b; | - | ||||||||||||
763 | data.resolve_mask |= (1<<cr); | - | ||||||||||||
764 | } never executed: end of block | 0 | ||||||||||||
765 | - | |||||||||||||
766 | /*! | - | ||||||||||||
767 | \since 4.2 | - | ||||||||||||
768 | - | |||||||||||||
769 | Returns \c true if the ColorGroup \a cg and ColorRole \a cr has been | - | ||||||||||||
770 | set previously on this palette; otherwise returns \c false. | - | ||||||||||||
771 | - | |||||||||||||
772 | \sa setBrush() | - | ||||||||||||
773 | */ | - | ||||||||||||
774 | bool QPalette::isBrushSet(ColorGroup cg, ColorRole cr) const | - | ||||||||||||
775 | { | - | ||||||||||||
776 | Q_UNUSED(cg); | - | ||||||||||||
777 | return (data.resolve_mask & (1<<cr)); never executed: return (data.resolve_mask & (1<<cr)); | 0 | ||||||||||||
778 | } | - | ||||||||||||
779 | - | |||||||||||||
780 | /*! | - | ||||||||||||
781 | \internal | - | ||||||||||||
782 | */ | - | ||||||||||||
783 | void QPalette::detach() | - | ||||||||||||
784 | { | - | ||||||||||||
785 | if (d->ref.load() != 1) {
| 0 | ||||||||||||
786 | QPalettePrivate *x = new QPalettePrivate; | - | ||||||||||||
787 | for(int grp = 0; grp < (int)NColorGroups; grp++) {
| 0 | ||||||||||||
788 | for(int role = 0; role < (int)NColorRoles; role++)
| 0 | ||||||||||||
789 | x->br[grp][role] = d->br[grp][role]; never executed: x->br[grp][role] = d->br[grp][role]; | 0 | ||||||||||||
790 | } never executed: end of block | 0 | ||||||||||||
791 | if(!d->ref.deref())
| 0 | ||||||||||||
792 | delete d; never executed: delete d; | 0 | ||||||||||||
793 | d = x; | - | ||||||||||||
794 | } never executed: end of block | 0 | ||||||||||||
795 | ++d->detach_no; | - | ||||||||||||
796 | } never executed: end of block | 0 | ||||||||||||
797 | - | |||||||||||||
798 | /*! | - | ||||||||||||
799 | \fn bool QPalette::operator!=(const QPalette &p) const | - | ||||||||||||
800 | - | |||||||||||||
801 | Returns \c true (slowly) if this palette is different from \a p; | - | ||||||||||||
802 | otherwise returns \c false (usually quickly). | - | ||||||||||||
803 | - | |||||||||||||
804 | \note The current ColorGroup is not taken into account when | - | ||||||||||||
805 | comparing palettes | - | ||||||||||||
806 | - | |||||||||||||
807 | \sa operator==() | - | ||||||||||||
808 | */ | - | ||||||||||||
809 | - | |||||||||||||
810 | /*! | - | ||||||||||||
811 | Returns \c true (usually quickly) if this palette is equal to \a p; | - | ||||||||||||
812 | otherwise returns \c false (slowly). | - | ||||||||||||
813 | - | |||||||||||||
814 | \note The current ColorGroup is not taken into account when | - | ||||||||||||
815 | comparing palettes | - | ||||||||||||
816 | - | |||||||||||||
817 | \sa operator!=() | - | ||||||||||||
818 | */ | - | ||||||||||||
819 | bool QPalette::operator==(const QPalette &p) const | - | ||||||||||||
820 | { | - | ||||||||||||
821 | if (isCopyOf(p))
| 0 | ||||||||||||
822 | return true; never executed: return true; | 0 | ||||||||||||
823 | for(int grp = 0; grp < (int)NColorGroups; grp++) {
| 0 | ||||||||||||
824 | for(int role = 0; role < (int)NColorRoles; role++) {
| 0 | ||||||||||||
825 | if(d->br[grp][role] != p.d->br[grp][role])
| 0 | ||||||||||||
826 | return false; never executed: return false; | 0 | ||||||||||||
827 | } never executed: end of block | 0 | ||||||||||||
828 | } never executed: end of block | 0 | ||||||||||||
829 | return true; never executed: return true; | 0 | ||||||||||||
830 | } | - | ||||||||||||
831 | - | |||||||||||||
832 | /*! | - | ||||||||||||
833 | \fn bool QPalette::isEqual(ColorGroup cg1, ColorGroup cg2) const | - | ||||||||||||
834 | - | |||||||||||||
835 | Returns \c true (usually quickly) if color group \a cg1 is equal to | - | ||||||||||||
836 | \a cg2; otherwise returns \c false. | - | ||||||||||||
837 | */ | - | ||||||||||||
838 | bool QPalette::isEqual(QPalette::ColorGroup group1, QPalette::ColorGroup group2) const | - | ||||||||||||
839 | { | - | ||||||||||||
840 | if(group1 >= (int)NColorGroups) {
| 0 | ||||||||||||
841 | if(group1 == Current) {
| 0 | ||||||||||||
842 | group1 = (ColorGroup)data.current_group; | - | ||||||||||||
843 | } else { never executed: end of block | 0 | ||||||||||||
844 | qWarning("QPalette::brush: Unknown ColorGroup(1): %d", (int)group1); | - | ||||||||||||
845 | group1 = Active; | - | ||||||||||||
846 | } never executed: end of block | 0 | ||||||||||||
847 | } | - | ||||||||||||
848 | if(group2 >= (int)NColorGroups) {
| 0 | ||||||||||||
849 | if(group2 == Current) {
| 0 | ||||||||||||
850 | group2 = (ColorGroup)data.current_group; | - | ||||||||||||
851 | } else { never executed: end of block | 0 | ||||||||||||
852 | qWarning("QPalette::brush: Unknown ColorGroup(2): %d", (int)group2); | - | ||||||||||||
853 | group2 = Active; | - | ||||||||||||
854 | } never executed: end of block | 0 | ||||||||||||
855 | } | - | ||||||||||||
856 | if(group1 == group2)
| 0 | ||||||||||||
857 | return true; never executed: return true; | 0 | ||||||||||||
858 | for(int role = 0; role < (int)NColorRoles; role++) {
| 0 | ||||||||||||
859 | if(d->br[group1][role] != d->br[group2][role])
| 0 | ||||||||||||
860 | return false; never executed: return false; | 0 | ||||||||||||
861 | } never executed: end of block | 0 | ||||||||||||
862 | return true; never executed: return true; | 0 | ||||||||||||
863 | } | - | ||||||||||||
864 | - | |||||||||||||
865 | /*! \fn int QPalette::serialNumber() const | - | ||||||||||||
866 | \obsolete | - | ||||||||||||
867 | - | |||||||||||||
868 | Returns a number that identifies the contents of this QPalette | - | ||||||||||||
869 | object. Distinct QPalette objects can only have the same serial | - | ||||||||||||
870 | number if they refer to the same contents (but they don't have | - | ||||||||||||
871 | to). Also, the serial number of a QPalette may change during the | - | ||||||||||||
872 | lifetime of the object. | - | ||||||||||||
873 | - | |||||||||||||
874 | Use cacheKey() instead. | - | ||||||||||||
875 | - | |||||||||||||
876 | \warning The serial number doesn't necessarily change when the | - | ||||||||||||
877 | palette is altered. This means that it may be dangerous to use it | - | ||||||||||||
878 | as a cache key. | - | ||||||||||||
879 | - | |||||||||||||
880 | \sa operator==() | - | ||||||||||||
881 | */ | - | ||||||||||||
882 | - | |||||||||||||
883 | /*! | - | ||||||||||||
884 | Returns a number that identifies the contents of this QPalette | - | ||||||||||||
885 | object. Distinct QPalette objects can have the same key if | - | ||||||||||||
886 | they refer to the same contents. | - | ||||||||||||
887 | - | |||||||||||||
888 | The cacheKey() will change when the palette is altered. | - | ||||||||||||
889 | */ | - | ||||||||||||
890 | qint64 QPalette::cacheKey() const | - | ||||||||||||
891 | { | - | ||||||||||||
892 | return (((qint64) d->ser_no) << 32) | ((qint64) (d->detach_no)); never executed: return (((qint64) d->ser_no) << 32) | ((qint64) (d->detach_no)); | 0 | ||||||||||||
893 | } | - | ||||||||||||
894 | - | |||||||||||||
895 | /*! | - | ||||||||||||
896 | Returns a new QPalette that has attributes copied from \a other. | - | ||||||||||||
897 | */ | - | ||||||||||||
898 | QPalette QPalette::resolve(const QPalette &other) const | - | ||||||||||||
899 | { | - | ||||||||||||
900 | if ((*this == other && data.resolve_mask == other.data.resolve_mask)
| 0 | ||||||||||||
901 | || data.resolve_mask == 0) {
| 0 | ||||||||||||
902 | QPalette o = other; | - | ||||||||||||
903 | o.data.resolve_mask = data.resolve_mask; | - | ||||||||||||
904 | return o; never executed: return o; | 0 | ||||||||||||
905 | } | - | ||||||||||||
906 | - | |||||||||||||
907 | QPalette palette(*this); | - | ||||||||||||
908 | palette.detach(); | - | ||||||||||||
909 | - | |||||||||||||
910 | for(int role = 0; role < (int)NColorRoles; role++)
| 0 | ||||||||||||
911 | if (!(data.resolve_mask & (1<<role)))
| 0 | ||||||||||||
912 | for(int grp = 0; grp < (int)NColorGroups; grp++)
| 0 | ||||||||||||
913 | palette.d->br[grp][role] = other.d->br[grp][role]; never executed: palette.d->br[grp][role] = other.d->br[grp][role]; | 0 | ||||||||||||
914 | - | |||||||||||||
915 | return palette; never executed: return palette; | 0 | ||||||||||||
916 | } | - | ||||||||||||
917 | - | |||||||||||||
918 | /*! | - | ||||||||||||
919 | \fn uint QPalette::resolve() const | - | ||||||||||||
920 | \internal | - | ||||||||||||
921 | */ | - | ||||||||||||
922 | - | |||||||||||||
923 | /*! | - | ||||||||||||
924 | \fn void QPalette::resolve(uint mask) | - | ||||||||||||
925 | \internal | - | ||||||||||||
926 | */ | - | ||||||||||||
927 | - | |||||||||||||
928 | - | |||||||||||||
929 | /***************************************************************************** | - | ||||||||||||
930 | QPalette stream functions | - | ||||||||||||
931 | *****************************************************************************/ | - | ||||||||||||
932 | - | |||||||||||||
933 | #ifndef QT_NO_DATASTREAM | - | ||||||||||||
934 | - | |||||||||||||
935 | static const int NumOldRoles = 7; | - | ||||||||||||
936 | static const int oldRoles[7] = { QPalette::Foreground, QPalette::Background, QPalette::Light, | - | ||||||||||||
937 | QPalette::Dark, QPalette::Mid, QPalette::Text, QPalette::Base }; | - | ||||||||||||
938 | - | |||||||||||||
939 | /*! | - | ||||||||||||
940 | \relates QPalette | - | ||||||||||||
941 | - | |||||||||||||
942 | Writes the palette, \a p to the stream \a s and returns a | - | ||||||||||||
943 | reference to the stream. | - | ||||||||||||
944 | - | |||||||||||||
945 | \sa{Serializing Qt Data Types}{Format of the QDataStream operators} | - | ||||||||||||
946 | */ | - | ||||||||||||
947 | - | |||||||||||||
948 | QDataStream &operator<<(QDataStream &s, const QPalette &p) | - | ||||||||||||
949 | { | - | ||||||||||||
950 | for (int grp = 0; grp < (int)QPalette::NColorGroups; grp++) {
| 0 | ||||||||||||
951 | if (s.version() == 1) {
| 0 | ||||||||||||
952 | // Qt 1.x | - | ||||||||||||
953 | for (int i = 0; i < NumOldRoles; ++i)
| 0 | ||||||||||||
954 | s << p.d->br[grp][oldRoles[i]].color(); never executed: s << p.d->br[grp][oldRoles[i]].color(); | 0 | ||||||||||||
955 | } else { never executed: end of block | 0 | ||||||||||||
956 | int max = QPalette::ToolTipText + 1; | - | ||||||||||||
957 | if (s.version() <= QDataStream::Qt_2_1)
| 0 | ||||||||||||
958 | max = QPalette::HighlightedText + 1; never executed: max = QPalette::HighlightedText + 1; | 0 | ||||||||||||
959 | else if (s.version() <= QDataStream::Qt_4_3)
| 0 | ||||||||||||
960 | max = QPalette::AlternateBase + 1; never executed: max = QPalette::AlternateBase + 1; | 0 | ||||||||||||
961 | for (int r = 0; r < max; r++)
| 0 | ||||||||||||
962 | s << p.d->br[grp][r]; never executed: s << p.d->br[grp][r]; | 0 | ||||||||||||
963 | } never executed: end of block | 0 | ||||||||||||
964 | } | - | ||||||||||||
965 | return s; never executed: return s; | 0 | ||||||||||||
966 | } | - | ||||||||||||
967 | - | |||||||||||||
968 | static void readV1ColorGroup(QDataStream &s, QPalette &pal, QPalette::ColorGroup grp) | - | ||||||||||||
969 | { | - | ||||||||||||
970 | for (int i = 0; i < NumOldRoles; ++i) {
| 0 | ||||||||||||
971 | QColor col; | - | ||||||||||||
972 | s >> col; | - | ||||||||||||
973 | pal.setColor(grp, (QPalette::ColorRole)oldRoles[i], col); | - | ||||||||||||
974 | } never executed: end of block | 0 | ||||||||||||
975 | } never executed: end of block | 0 | ||||||||||||
976 | - | |||||||||||||
977 | /*! | - | ||||||||||||
978 | \relates QPalette | - | ||||||||||||
979 | - | |||||||||||||
980 | Reads a palette from the stream, \a s into the palette \a p, and | - | ||||||||||||
981 | returns a reference to the stream. | - | ||||||||||||
982 | - | |||||||||||||
983 | \sa{Serializing Qt Data Types}{Format of the QDataStream operators} | - | ||||||||||||
984 | */ | - | ||||||||||||
985 | - | |||||||||||||
986 | QDataStream &operator>>(QDataStream &s, QPalette &p) | - | ||||||||||||
987 | { | - | ||||||||||||
988 | if(s.version() == 1) {
| 0 | ||||||||||||
989 | p = QPalette(); | - | ||||||||||||
990 | readV1ColorGroup(s, p, QPalette::Active); | - | ||||||||||||
991 | readV1ColorGroup(s, p, QPalette::Disabled); | - | ||||||||||||
992 | readV1ColorGroup(s, p, QPalette::Inactive); | - | ||||||||||||
993 | } else { never executed: end of block | 0 | ||||||||||||
994 | int max = QPalette::NColorRoles; | - | ||||||||||||
995 | if (s.version() <= QDataStream::Qt_2_1) {
| 0 | ||||||||||||
996 | p = QPalette(); | - | ||||||||||||
997 | max = QPalette::HighlightedText + 1; | - | ||||||||||||
998 | } else if (s.version() <= QDataStream::Qt_4_3) { never executed: end of block
| 0 | ||||||||||||
999 | p = QPalette(); | - | ||||||||||||
1000 | max = QPalette::AlternateBase + 1; | - | ||||||||||||
1001 | } never executed: end of block | 0 | ||||||||||||
1002 | - | |||||||||||||
1003 | QBrush tmp; | - | ||||||||||||
1004 | for(int grp = 0; grp < (int)QPalette::NColorGroups; ++grp) {
| 0 | ||||||||||||
1005 | for(int role = 0; role < max; ++role) {
| 0 | ||||||||||||
1006 | s >> tmp; | - | ||||||||||||
1007 | p.setBrush((QPalette::ColorGroup)grp, (QPalette::ColorRole)role, tmp); | - | ||||||||||||
1008 | } never executed: end of block | 0 | ||||||||||||
1009 | } never executed: end of block | 0 | ||||||||||||
1010 | } never executed: end of block | 0 | ||||||||||||
1011 | return s; never executed: return s; | 0 | ||||||||||||
1012 | } | - | ||||||||||||
1013 | #endif //QT_NO_DATASTREAM | - | ||||||||||||
1014 | - | |||||||||||||
1015 | /*! | - | ||||||||||||
1016 | Returns \c true if this palette and \a p are copies of each other, | - | ||||||||||||
1017 | i.e. one of them was created as a copy of the other and neither | - | ||||||||||||
1018 | was subsequently modified; otherwise returns \c false. This is much | - | ||||||||||||
1019 | stricter than equality. | - | ||||||||||||
1020 | - | |||||||||||||
1021 | \sa operator=(), operator==() | - | ||||||||||||
1022 | */ | - | ||||||||||||
1023 | - | |||||||||||||
1024 | bool QPalette::isCopyOf(const QPalette &p) const | - | ||||||||||||
1025 | { | - | ||||||||||||
1026 | return d == p.d; never executed: return d == p.d; | 0 | ||||||||||||
1027 | } | - | ||||||||||||
1028 | - | |||||||||||||
1029 | /*! | - | ||||||||||||
1030 | - | |||||||||||||
1031 | Sets a the group at \a cg. You can pass either brushes, pixmaps or | - | ||||||||||||
1032 | plain colors for \a windowText, \a button, \a light, \a dark, \a | - | ||||||||||||
1033 | mid, \a text, \a bright_text, \a base and \a window. | - | ||||||||||||
1034 | - | |||||||||||||
1035 | \sa QBrush | - | ||||||||||||
1036 | */ | - | ||||||||||||
1037 | void QPalette::setColorGroup(ColorGroup cg, const QBrush &windowText, const QBrush &button, | - | ||||||||||||
1038 | const QBrush &light, const QBrush &dark, const QBrush &mid, | - | ||||||||||||
1039 | const QBrush &text, const QBrush &bright_text, const QBrush &base, | - | ||||||||||||
1040 | const QBrush &window) | - | ||||||||||||
1041 | { | - | ||||||||||||
1042 | QBrush alt_base = QBrush(qt_mix_colors(base.color(), button.color())); | - | ||||||||||||
1043 | QBrush mid_light = QBrush(qt_mix_colors(button.color(), light.color())); | - | ||||||||||||
1044 | QColor toolTipBase(255, 255, 220); | - | ||||||||||||
1045 | QColor toolTipText(0, 0, 0); | - | ||||||||||||
1046 | - | |||||||||||||
1047 | setColorGroup(cg, windowText, button, light, dark, mid, text, bright_text, base, | - | ||||||||||||
1048 | alt_base, window, mid_light, text, | - | ||||||||||||
1049 | QBrush(Qt::black), QBrush(Qt::darkBlue), QBrush(Qt::white), | - | ||||||||||||
1050 | QBrush(Qt::blue), QBrush(Qt::magenta), QBrush(toolTipBase), | - | ||||||||||||
1051 | QBrush(toolTipText)); | - | ||||||||||||
1052 | - | |||||||||||||
1053 | data.resolve_mask &= ~(1 << Highlight); | - | ||||||||||||
1054 | data.resolve_mask &= ~(1 << HighlightedText); | - | ||||||||||||
1055 | data.resolve_mask &= ~(1 << LinkVisited); | - | ||||||||||||
1056 | data.resolve_mask &= ~(1 << Link); | - | ||||||||||||
1057 | } never executed: end of block | 0 | ||||||||||||
1058 | - | |||||||||||||
1059 | - | |||||||||||||
1060 | /*!\internal*/ | - | ||||||||||||
1061 | void | - | ||||||||||||
1062 | QPalette::setColorGroup(ColorGroup cg, const QBrush &foreground, const QBrush &button, | - | ||||||||||||
1063 | const QBrush &light, const QBrush &dark, const QBrush &mid, | - | ||||||||||||
1064 | const QBrush &text, const QBrush &bright_text, | - | ||||||||||||
1065 | const QBrush &base, const QBrush &alternate_base, | - | ||||||||||||
1066 | const QBrush &background, const QBrush &midlight, | - | ||||||||||||
1067 | const QBrush &button_text, const QBrush &shadow, | - | ||||||||||||
1068 | const QBrush &highlight, const QBrush &highlighted_text, | - | ||||||||||||
1069 | const QBrush &link, const QBrush &link_visited) | - | ||||||||||||
1070 | { | - | ||||||||||||
1071 | setColorGroup(cg, foreground, button, light, dark, mid, | - | ||||||||||||
1072 | text, bright_text, base, alternate_base, background, | - | ||||||||||||
1073 | midlight, button_text, shadow, highlight, highlighted_text, | - | ||||||||||||
1074 | link, link_visited, background, foreground); | - | ||||||||||||
1075 | } never executed: end of block | 0 | ||||||||||||
1076 | - | |||||||||||||
1077 | /*!\internal*/ | - | ||||||||||||
1078 | void QPalette::setColorGroup(ColorGroup cg, const QBrush &foreground, const QBrush &button, | - | ||||||||||||
1079 | const QBrush &light, const QBrush &dark, const QBrush &mid, | - | ||||||||||||
1080 | const QBrush &text, const QBrush &bright_text, | - | ||||||||||||
1081 | const QBrush &base, const QBrush &alternate_base, | - | ||||||||||||
1082 | const QBrush &background, const QBrush &midlight, | - | ||||||||||||
1083 | const QBrush &button_text, const QBrush &shadow, | - | ||||||||||||
1084 | const QBrush &highlight, const QBrush &highlighted_text, | - | ||||||||||||
1085 | const QBrush &link, const QBrush &link_visited, | - | ||||||||||||
1086 | const QBrush &toolTipBase, const QBrush &toolTipText) | - | ||||||||||||
1087 | { | - | ||||||||||||
1088 | detach(); | - | ||||||||||||
1089 | setBrush(cg, WindowText, foreground); | - | ||||||||||||
1090 | setBrush(cg, Button, button); | - | ||||||||||||
1091 | setBrush(cg, Light, light); | - | ||||||||||||
1092 | setBrush(cg, Dark, dark); | - | ||||||||||||
1093 | setBrush(cg, Mid, mid); | - | ||||||||||||
1094 | setBrush(cg, Text, text); | - | ||||||||||||
1095 | setBrush(cg, BrightText, bright_text); | - | ||||||||||||
1096 | setBrush(cg, Base, base); | - | ||||||||||||
1097 | setBrush(cg, AlternateBase, alternate_base); | - | ||||||||||||
1098 | setBrush(cg, Window, background); | - | ||||||||||||
1099 | setBrush(cg, Midlight, midlight); | - | ||||||||||||
1100 | setBrush(cg, ButtonText, button_text); | - | ||||||||||||
1101 | setBrush(cg, Shadow, shadow); | - | ||||||||||||
1102 | setBrush(cg, Highlight, highlight); | - | ||||||||||||
1103 | setBrush(cg, HighlightedText, highlighted_text); | - | ||||||||||||
1104 | setBrush(cg, Link, link); | - | ||||||||||||
1105 | setBrush(cg, LinkVisited, link_visited); | - | ||||||||||||
1106 | setBrush(cg, ToolTipBase, toolTipBase); | - | ||||||||||||
1107 | setBrush(cg, ToolTipText, toolTipText); | - | ||||||||||||
1108 | } never executed: end of block | 0 | ||||||||||||
1109 | - | |||||||||||||
1110 | Q_GUI_EXPORT QPalette qt_fusionPalette() | - | ||||||||||||
1111 | { | - | ||||||||||||
1112 | QColor backGround(239, 235, 231); | - | ||||||||||||
1113 | QColor light = backGround.lighter(150); | - | ||||||||||||
1114 | QColor mid(backGround.darker(130)); | - | ||||||||||||
1115 | QColor midLight = mid.lighter(110); | - | ||||||||||||
1116 | QColor base = Qt::white; | - | ||||||||||||
1117 | QColor disabledBase(backGround); | - | ||||||||||||
1118 | QColor dark = backGround.darker(150); | - | ||||||||||||
1119 | QColor darkDisabled = QColor(209, 200, 191).darker(110); | - | ||||||||||||
1120 | QColor text = Qt::black; | - | ||||||||||||
1121 | QColor hightlightedText = Qt::white; | - | ||||||||||||
1122 | QColor disabledText = QColor(190, 190, 190); | - | ||||||||||||
1123 | QColor button = backGround; | - | ||||||||||||
1124 | QColor shadow = dark.darker(135); | - | ||||||||||||
1125 | QColor disabledShadow = shadow.lighter(150); | - | ||||||||||||
1126 | - | |||||||||||||
1127 | QPalette fusionPalette(Qt::black,backGround,light,dark,mid,text,base); | - | ||||||||||||
1128 | fusionPalette.setBrush(QPalette::Midlight, midLight); | - | ||||||||||||
1129 | fusionPalette.setBrush(QPalette::Button, button); | - | ||||||||||||
1130 | fusionPalette.setBrush(QPalette::Shadow, shadow); | - | ||||||||||||
1131 | fusionPalette.setBrush(QPalette::HighlightedText, hightlightedText); | - | ||||||||||||
1132 | - | |||||||||||||
1133 | fusionPalette.setBrush(QPalette::Disabled, QPalette::Text, disabledText); | - | ||||||||||||
1134 | fusionPalette.setBrush(QPalette::Disabled, QPalette::WindowText, disabledText); | - | ||||||||||||
1135 | fusionPalette.setBrush(QPalette::Disabled, QPalette::ButtonText, disabledText); | - | ||||||||||||
1136 | fusionPalette.setBrush(QPalette::Disabled, QPalette::Base, disabledBase); | - | ||||||||||||
1137 | fusionPalette.setBrush(QPalette::Disabled, QPalette::Dark, darkDisabled); | - | ||||||||||||
1138 | fusionPalette.setBrush(QPalette::Disabled, QPalette::Shadow, disabledShadow); | - | ||||||||||||
1139 | - | |||||||||||||
1140 | fusionPalette.setBrush(QPalette::Active, QPalette::Highlight, QColor(48, 140, 198)); | - | ||||||||||||
1141 | fusionPalette.setBrush(QPalette::Inactive, QPalette::Highlight, QColor(48, 140, 198)); | - | ||||||||||||
1142 | fusionPalette.setBrush(QPalette::Disabled, QPalette::Highlight, QColor(145, 141, 126)); | - | ||||||||||||
1143 | return fusionPalette; never executed: return fusionPalette; | 0 | ||||||||||||
1144 | } | - | ||||||||||||
1145 | - | |||||||||||||
1146 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||||||||
1147 | QDebug operator<<(QDebug dbg, const QPalette &p) | - | ||||||||||||
1148 | { | - | ||||||||||||
1149 | const char *colorGroupNames[] = {"Active", "Disabled", "Inactive"}; | - | ||||||||||||
1150 | const char *colorRoleNames[] = | - | ||||||||||||
1151 | {"WindowText", "Button", "Light", "Midlight", "Dark", "Mid", "Text", | - | ||||||||||||
1152 | "BrightText", "ButtonText", "Base", "Window", "Shadow", "Highlight", | - | ||||||||||||
1153 | "HighlightedText", "Link", "LinkVisited", "AlternateBase", "NoRole", | - | ||||||||||||
1154 | "ToolTipBase","ToolTipText" }; | - | ||||||||||||
1155 | QDebugStateSaver saver(dbg); | - | ||||||||||||
1156 | QDebug nospace = dbg.nospace(); | - | ||||||||||||
1157 | const uint mask = p.resolve(); | - | ||||||||||||
1158 | nospace << "QPalette(resolve=" << hex << showbase << mask << ','; | - | ||||||||||||
1159 | for (int role = 0; role < (int)QPalette::NColorRoles; ++role) {
| 0 | ||||||||||||
1160 | if (mask & (1<<role)) {
| 0 | ||||||||||||
1161 | if (role)
| 0 | ||||||||||||
1162 | nospace << ','; never executed: nospace << ','; | 0 | ||||||||||||
1163 | nospace << colorRoleNames[role] << ":["; | - | ||||||||||||
1164 | for (int group = 0; group < (int)QPalette::NColorGroups; ++group) {
| 0 | ||||||||||||
1165 | if (group)
| 0 | ||||||||||||
1166 | nospace << ','; never executed: nospace << ','; | 0 | ||||||||||||
1167 | const QRgb color = p.color(static_cast<QPalette::ColorGroup>(group), | - | ||||||||||||
1168 | static_cast<QPalette::ColorRole>(role)).rgba(); | - | ||||||||||||
1169 | nospace << colorGroupNames[group] << ':' << color; | - | ||||||||||||
1170 | } never executed: end of block | 0 | ||||||||||||
1171 | nospace << ']'; | - | ||||||||||||
1172 | } never executed: end of block | 0 | ||||||||||||
1173 | } never executed: end of block | 0 | ||||||||||||
1174 | nospace << ')' << noshowbase << dec; | - | ||||||||||||
1175 | return dbg; never executed: return dbg; | 0 | ||||||||||||
1176 | } | - | ||||||||||||
1177 | #endif | - | ||||||||||||
1178 | - | |||||||||||||
1179 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |