source: trunk/src/gui/kernel/qpalette.cpp@ 856

Last change on this file since 856 was 846, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 39.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qpalette.h"
43#include "qapplication.h"
44#include "qdatastream.h"
45#include "qvariant.h"
46
47QT_BEGIN_NAMESPACE
48
49static int qt_palette_count = 1;
50
51class QPalettePrivate {
52public:
53 QPalettePrivate() : ref(1), ser_no(qt_palette_count++), detach_no(0) { }
54 QAtomicInt ref;
55 QBrush br[QPalette::NColorGroups][QPalette::NColorRoles];
56 int ser_no;
57 int detach_no;
58};
59
60static QColor qt_mix_colors(QColor a, QColor b)
61{
62 return QColor((a.red() + b.red()) / 2, (a.green() + b.green()) / 2,
63 (a.blue() + b.blue()) / 2, (a.alpha() + b.alpha()) / 2);
64}
65
66#ifdef QT3_SUPPORT
67
68#ifndef QT_NO_DATASTREAM
69QDataStream &qt_stream_out_qcolorgroup(QDataStream &s, const QColorGroup &g)
70{
71 if(s.version() == 1) {
72 // Qt 1.x
73 s << g.color(QPalette::Foreground) << g.color(QPalette::Background)
74 << g.color(QPalette::Light) << g.color(QPalette::Dark)
75 << g.color(QPalette::Mid) << g.color(QPalette::Text) << g.color(QPalette::Base);
76 } else {
77 int max = QPalette::NColorRoles;
78 if (s.version() <= QDataStream::Qt_2_1)
79 max = QPalette::HighlightedText + 1;
80 else if (s.version() <= QDataStream::Qt_4_3)
81 max = QPalette::AlternateBase + 1;
82 for(int r = 0 ; r < max ; r++)
83 s << g.brush((QPalette::ColorRole)r);
84 }
85 return s;
86}
87
88QDataStream &qt_stream_in_qcolorgroup(QDataStream &s, QColorGroup &g)
89{
90 if(s.version() == 1) { // Qt 1.x
91 QColor fg, bg, light, dark, mid, text, base;
92 s >> fg >> bg >> light >> dark >> mid >> text >> base;
93 QPalette p(bg);
94 p.setColor(QPalette::Active, QPalette::Foreground, fg);
95 p.setColor(QPalette::Active, QPalette::Light, light);
96 p.setColor(QPalette::Active, QPalette::Dark, dark);
97 p.setColor(QPalette::Active, QPalette::Mid, mid);
98 p.setColor(QPalette::Active, QPalette::Text, text);
99 p.setColor(QPalette::Active, QPalette::Base, base);
100 g = p;
101 g.setCurrentColorGroup(QPalette::Active);
102 } else {
103 int max = QPalette::NColorRoles;
104 if (s.version() <= QDataStream::Qt_2_1)
105 max = QPalette::HighlightedText + 1;
106 else if (s.version() <= QDataStream::Qt_3_0)
107 max = QPalette::LinkVisited + 1;
108 else if (s.version() <= QDataStream::Qt_4_3)
109 max = QPalette::AlternateBase + 1;
110 QBrush tmp;
111 for(int r = 0 ; r < max; r++) {
112 s >> tmp;
113 g.setBrush((QPalette::ColorRole)r, tmp);
114 }
115 }
116 return s;
117}
118
119QDataStream &operator<<(QDataStream &s, const QColorGroup &g)
120{
121 return qt_stream_out_qcolorgroup(s, g);
122}
123
124QDataStream &operator>>(QDataStream &s, QColorGroup &g)
125{
126 return qt_stream_in_qcolorgroup(s, g);
127}
128#endif // QT_NO_DATASTREAM
129
130/*!
131 Constructs a palette with the specified \a active, \a disabled and
132 \a inactive color groups.
133*/
134QPalette::QPalette(const QColorGroup &active, const QColorGroup &disabled,
135 const QColorGroup &inactive)
136{
137 Q_ASSERT(QPalette::NColorRoles == QPalette::ToolTipText + 1);
138 init();
139 setColorGroup(Active, active);
140 setColorGroup(Disabled, disabled);
141 setColorGroup(Inactive, inactive);
142}
143
144QColorGroup QPalette::createColorGroup(ColorGroup cr) const
145{
146 QColorGroup ret(*this);
147 ret.setCurrentColorGroup(cr);
148 return ret;
149}
150
151void QPalette::setColorGroup(ColorGroup cg, const QColorGroup &g)
152{
153 setColorGroup(cg, g.brush(WindowText), g.brush(Button), g.brush(Light),
154 g.brush(Dark), g.brush(Mid), g.brush(Text), g.brush(BrightText),
155 g.brush(Base), g.brush(AlternateBase), g.brush(Window),
156 g.brush(Midlight), g.brush(ButtonText), g.brush(Shadow),
157 g.brush(Highlight), g.brush(HighlightedText), g.brush(Link),
158 g.brush(LinkVisited), g.brush(ToolTipBase), g.brush(ToolTipText));
159}
160
161#endif // QT3_SUPPORT
162
163/*!
164 \fn const QColor &QPalette::color(ColorRole role) const
165
166 \overload
167
168 Returns the color that has been set for the given color \a role in
169 the current ColorGroup.
170
171 \sa brush() ColorRole
172 */
173
174/*!
175 \fn const QBrush &QPalette::brush(ColorRole role) const
176
177 \overload
178
179 Returns the brush that has been set for the given color \a role in
180 the current ColorGroup.
181
182 \sa color() setBrush() ColorRole
183*/
184
185/*!
186 \fn void QPalette::setColor(ColorRole role, const QColor &color)
187
188 \overload
189
190 Sets the color used for the given color \a role, in all color
191 groups, to the specified solid \a color.
192
193 \sa brush() setColor() ColorRole
194*/
195
196/*!
197 \fn void QPalette::setBrush(ColorRole role, const QBrush &brush)
198
199 Sets the brush for the given color \a role to the specified \a
200 brush for all groups in the palette.
201
202 \sa brush() setColor() ColorRole
203*/
204
205/*!
206 \fn const QBrush & QPalette::foreground() const
207 \obsolete
208
209 Use windowText() instead.
210*/
211
212/*!
213 \fn const QBrush & QPalette::windowText() const
214
215 Returns the window text (general foreground) brush of the
216 current color group.
217
218 \sa ColorRole brush()
219*/
220
221/*!
222 \fn const QBrush & QPalette::button() const
223
224 Returns the button brush of the current color group.
225
226 \sa ColorRole brush()
227*/
228
229/*!
230 \fn const QBrush & QPalette::light() const
231
232 Returns the light brush of the current color group.
233
234 \sa ColorRole brush()
235*/
236
237/*!
238 \fn const QBrush& QPalette::midlight() const
239
240 Returns the midlight brush of the current color group.
241
242 \sa ColorRole brush()
243*/
244
245/*!
246 \fn const QBrush & QPalette::dark() const
247
248 Returns the dark brush of the current color group.
249
250 \sa ColorRole brush()
251*/
252
253/*!
254 \fn const QBrush & QPalette::mid() const
255
256 Returns the mid brush of the current color group.
257
258 \sa ColorRole brush()
259*/
260
261/*!
262 \fn const QBrush & QPalette::text() const
263
264 Returns the text foreground brush of the current color group.
265
266 \sa ColorRole brush()
267*/
268
269/*!
270 \fn const QBrush & QPalette::brightText() const
271
272 Returns the bright text foreground brush of the current color group.
273
274 \sa ColorRole brush()
275*/
276
277/*!
278 \fn const QBrush & QPalette::buttonText() const
279
280 Returns the button text foreground brush of the current color group.
281
282 \sa ColorRole brush()
283*/
284
285/*!
286 \fn const QBrush & QPalette::base() const
287
288 Returns the base brush of the current color group.
289
290 \sa ColorRole brush()
291*/
292
293/*!
294 \fn const QBrush & QPalette::alternateBase() const
295
296 Returns the alternate base brush of the current color group.
297
298 \sa ColorRole brush()
299*/
300
301/*!
302 \fn const QBrush & QPalette::toolTipBase() const
303 \since 4.4
304
305 Returns the tool tip base brush of the current color group. This brush is
306 used by QToolTip and QWhatsThis.
307
308 \note Tool tips use the Inactive color group of QPalette, because tool
309 tips are not active windows.
310
311 \sa ColorRole brush()
312*/
313
314/*!
315 \fn const QBrush & QPalette::toolTipText() const
316 \since 4.4
317
318 Returns the tool tip text brush of the current color group. This brush is
319 used by QToolTip and QWhatsThis.
320
321 \note Tool tips use the Inactive color group of QPalette, because tool
322 tips are not active windows.
323
324 \sa ColorRole brush()
325*/
326
327/*!
328 \fn const QBrush & QPalette::background() const
329 \obsolete
330
331 Use window() instead.
332*/
333
334/*!
335 \fn const QBrush & QPalette::window() const
336
337 Returns the window (general background) brush of the current
338 color group.
339
340 \sa ColorRole brush()
341*/
342
343/*!
344 \fn const QBrush & QPalette::shadow() const
345
346 Returns the shadow brush of the current color group.
347
348 \sa ColorRole brush()
349*/
350
351/*!
352 \fn const QBrush & QPalette::highlight() const
353
354 Returns the highlight brush of the current color group.
355
356 \sa ColorRole brush()
357*/
358
359/*!
360 \fn const QBrush & QPalette::highlightedText() const
361
362 Returns the highlighted text brush of the current color group.
363
364 \sa ColorRole brush()
365*/
366
367/*!
368 \fn const QBrush & QPalette::link() const
369
370 Returns the unvisited link text brush of the current color group.
371
372 \sa ColorRole brush()
373*/
374
375/*!
376 \fn const QBrush & QPalette::linkVisited() const
377
378 Returns the visited link text brush of the current color group.
379
380 \sa ColorRole brush()
381*/
382
383/*!
384 \fn ColorGroup QPalette::currentColorGroup() const
385
386 Returns the palette's current color group.
387*/
388
389/*!
390 \fn void QPalette::setCurrentColorGroup(ColorGroup cg)
391
392 Set the palette's current color group to \a cg.
393*/
394
395/*!
396 \class QPalette
397
398 \brief The QPalette class contains color groups for each widget state.
399
400 \ingroup appearance
401 \ingroup shared
402 \ingroup painting
403
404
405 A palette consists of three color groups: \e Active, \e Disabled,
406 and \e Inactive. All widgets in Qt contain a palette and
407 use their palette to draw themselves. This makes the user
408 interface easily configurable and easier to keep consistent.
409
410
411 If you create a new widget we strongly recommend that you use the
412 colors in the palette rather than hard-coding specific colors.
413
414 The color groups:
415 \list
416 \i The Active group is used for the window that has keyboard focus.
417 \i The Inactive group is used for other windows.
418 \i The Disabled group is used for widgets (not windows) that are
419 disabled for some reason.
420 \endlist
421
422 Both active and inactive windows can contain disabled widgets.
423 (Disabled widgets are often called \e inaccessible or \e{grayed
424 out}.)
425
426 In most styles, Active and Inactive look the same.
427
428 Colors and brushes can be set for particular roles in any of a palette's
429 color groups with setColor() and setBrush(). A color group contains a
430 group of colors used by widgets for drawing themselves. We recommend that
431 widgets use color group roles from the palette such as "foreground" and
432 "base" rather than literal colors like "red" or "turquoise". The color
433 roles are enumerated and defined in the \l ColorRole documentation.
434
435 We strongly recommend that you use the default palette of the
436 current style (returned by QApplication::palette()) and
437 modify that as necessary. This is done by Qt's widgets when they
438 are drawn.
439
440 To modify a color group you call the functions
441 setColor() and setBrush(), depending on whether you want a pure
442 color or a pixmap pattern.
443
444 There are also corresponding color() and brush() getters, and a
445 commonly used convenience function to get the ColorRole for the current ColorGroup:
446 window(), windowText(), base(), etc.
447
448
449 You can copy a palette using the copy constructor and test to see
450 if two palettes are \e identical using isCopyOf().
451
452 QPalette is optimized by the use of \l{implicit sharing},
453 so it is very efficient to pass QPalette objects as arguments.
454
455 \warning Some styles do not use the palette for all drawing, for
456 instance, if they make use of native theme engines. This is the
457 case for both the Windows XP, Windows Vista, and the Mac OS X
458 styles.
459
460 \sa QApplication::setPalette(), QWidget::setPalette(), QColor
461*/
462
463/*!
464 \enum QPalette::ColorGroup
465
466 \value Disabled
467 \value Active
468 \value Inactive
469 \value Normal synonym for Active
470
471 \omitvalue All
472 \omitvalue NColorGroups
473 \omitvalue Current
474*/
475
476/*!
477 \enum QPalette::ColorRole
478
479 \img palette.png Color Roles
480
481 The ColorRole enum defines the different symbolic color roles used
482 in current GUIs.
483
484 The central roles are:
485
486 \value Window A general background color.
487
488 \value Background This value is obsolete. Use Window instead.
489
490 \value WindowText A general foreground color.
491
492 \value Foreground This value is obsolete. Use WindowText instead.
493
494 \value Base Used mostly as the background color for text entry widgets,
495 but can also be used for other painting - such as the
496 background of combobox drop down lists and toolbar handles.
497 It is usually white or another light color.
498
499 \value AlternateBase Used as the alternate background color in views with
500 alternating row colors (see
501 QAbstractItemView::setAlternatingRowColors()).
502
503 \value ToolTipBase Used as the background color for QToolTip and
504 QWhatsThis. Tool tips use the Inactive color group
505 of QPalette, because tool tips are not active
506 windows.
507
508 \value ToolTipText Used as the foreground color for QToolTip and
509 QWhatsThis. Tool tips use the Inactive color group
510 of QPalette, because tool tips are not active
511 windows.
512
513 \value Text The foreground color used with \c Base. This is usually
514 the same as the \c WindowText, in which case it must provide
515 good contrast with \c Window and \c Base.
516
517 \value Button The general button background color. This background can be different from
518 \c Window as some styles require a different background color for buttons.
519
520 \value ButtonText A foreground color used with the \c Button color.
521
522 \value BrightText A text color that is very different from
523 \c WindowText, and contrasts well with e.g. \c
524 Dark. Typically used for text that needs to be
525 drawn where \c Text or \c WindowText would give
526 poor contrast, such as on pressed push buttons.
527 Note that text colors can be used for things
528 other than just words; text colors are \e
529 usually used for text, but it's quite common to
530 use the text color roles for lines, icons, etc.
531
532
533 There are some color roles used mostly for 3D bevel and shadow effects.
534 All of these are normally derived from \c Window, and used in ways that
535 depend on that relationship. For example, buttons depend on it to make the
536 bevels look attractive, and Motif scroll bars depend on \c Mid to be
537 slightly different from \c Window.
538
539 \value Light Lighter than \c Button color.
540
541 \value Midlight Between \c Button and \c Light.
542
543 \value Dark Darker than \c Button.
544
545 \value Mid Between \c Button and \c Dark.
546
547 \value Shadow A very dark color. By default, the shadow color is
548 Qt::black.
549
550
551 Selected (marked) items have two roles:
552
553 \value Highlight A color to indicate a selected item or the current
554 item. By default, the highlight color is
555 Qt::darkBlue.
556
557 \value HighlightedText A text color that contrasts with \c Highlight.
558 By default, the highlighted text color is Qt::white.
559
560 There are two color roles related to hyperlinks:
561
562 \value Link A text color used for unvisited hyperlinks.
563 By default, the link color is Qt::blue.
564
565 \value LinkVisited A text color used for already visited hyperlinks.
566 By default, the linkvisited color is Qt::magenta.
567
568 Note that we do not use the \c Link and \c LinkVisited roles when
569 rendering rich text in Qt, and that we recommend that you use CSS
570 and the QTextDocument::setDefaultStyleSheet() function to alter
571 the appearance of links. For example:
572
573 \snippet doc/src/snippets/textdocument-css/main.cpp 0
574
575 \value NoRole No role; this special role is often used to indicate that a
576 role has not been assigned.
577
578 \omitvalue NColorRoles
579*/
580
581/*!
582 Constructs a palette object that uses the application's default palette.
583
584 \sa QApplication::setPalette(), QApplication::palette()
585*/
586QPalette::QPalette()
587 : d(QApplication::palette().d),
588 current_group(Active),
589 resolve_mask(0)
590{
591 d->ref.ref();
592}
593
594static void qt_palette_from_color(QPalette &pal, const QColor & button)
595{
596 QColor bg = button,
597 btn = button,
598 fg, base;
599 int h, s, v;
600 bg.getHsv(&h, &s, &v);
601 if(v > 128) {
602 fg = Qt::black;
603 base = Qt::white;
604 } else {
605 fg = Qt::white;
606 base = Qt::black;
607 }
608 //inactive and active are the same..
609 pal.setColorGroup(QPalette::Active, QBrush(fg), QBrush(btn), QBrush(btn.lighter(150)),
610 QBrush(btn.darker()), QBrush(btn.darker(150)), QBrush(fg), QBrush(Qt::white),
611 QBrush(base), QBrush(bg));
612 pal.setColorGroup(QPalette::Inactive, QBrush(fg), QBrush(btn), QBrush(btn.lighter(150)),
613 QBrush(btn.darker()), QBrush(btn.darker(150)), QBrush(fg), QBrush(Qt::white),
614 QBrush(base), QBrush(bg));
615 pal.setColorGroup(QPalette::Disabled, QBrush(btn.darker()), QBrush(btn), QBrush(btn.lighter(150)),
616 QBrush(btn.darker()), QBrush(btn.darker(150)), QBrush(btn.darker()),
617 QBrush(Qt::white), QBrush(bg), QBrush(bg));
618}
619
620
621/*!
622 Constructs a palette from the \a button color. The other colors are
623 automatically calculated, based on this color. \c Window will be
624 the button color as well.
625*/
626QPalette::QPalette(const QColor &button)
627{
628 init();
629 qt_palette_from_color(*this, button);
630}
631
632/*!
633 Constructs a palette from the \a button color. The other colors are
634 automatically calculated, based on this color. \c Window will be
635 the button color as well.
636*/
637QPalette::QPalette(Qt::GlobalColor button)
638{
639 init();
640 qt_palette_from_color(*this, button);
641}
642
643/*!
644 Constructs a palette. You can pass either brushes, pixmaps or
645 plain colors for \a windowText, \a button, \a light, \a dark, \a
646 mid, \a text, \a bright_text, \a base and \a window.
647
648 \sa QBrush
649*/
650QPalette::QPalette(const QBrush &windowText, const QBrush &button,
651 const QBrush &light, const QBrush &dark,
652 const QBrush &mid, const QBrush &text,
653 const QBrush &bright_text, const QBrush &base,
654 const QBrush &window)
655{
656 init();
657 setColorGroup(All, windowText, button, light, dark, mid, text, bright_text,
658 base, window);
659}
660
661
662/*!\obsolete
663
664 Constructs a palette with the specified \a windowText, \a
665 window, \a light, \a dark, \a mid, \a text, and \a base colors.
666 The button color will be set to the window color.
667*/
668QPalette::QPalette(const QColor &windowText, const QColor &window,
669 const QColor &light, const QColor &dark, const QColor &mid,
670 const QColor &text, const QColor &base)
671{
672 init();
673 setColorGroup(All, QBrush(windowText), QBrush(window), QBrush(light),
674 QBrush(dark), QBrush(mid), QBrush(text), QBrush(light),
675 QBrush(base), QBrush(window));
676}
677
678/*!
679 Constructs a palette from a \a button color and a \a window.
680 The other colors are automatically calculated, based on these
681 colors.
682*/
683QPalette::QPalette(const QColor &button, const QColor &window)
684{
685 init();
686 QColor bg = window, btn = button, fg, base, disfg;
687 int h, s, v;
688 bg.getHsv(&h, &s, &v);
689 if(v > 128) {
690 fg = Qt::black;
691 base = Qt::white;
692 disfg = Qt::darkGray;
693 } else {
694 fg = Qt::white;
695 base = Qt::black;
696 disfg = Qt::darkGray;
697 }
698 //inactive and active are identical
699 setColorGroup(Inactive, QBrush(fg), QBrush(btn), QBrush(btn.lighter(150)), QBrush(btn.darker()),
700 QBrush(btn.darker(150)), QBrush(fg), QBrush(Qt::white), QBrush(base),
701 QBrush(bg));
702 setColorGroup(Active, QBrush(fg), QBrush(btn), QBrush(btn.lighter(150)), QBrush(btn.darker()),
703 QBrush(btn.darker(150)), QBrush(fg), QBrush(Qt::white), QBrush(base),
704 QBrush(bg));
705 setColorGroup(Disabled, QBrush(disfg), QBrush(btn), QBrush(btn.lighter(150)),
706 QBrush(btn.darker()), QBrush(btn.darker(150)), QBrush(disfg),
707 QBrush(Qt::white), QBrush(base), QBrush(bg));
708}
709
710/*!
711 Constructs a copy of \a p.
712
713 This constructor is fast thanks to \l{implicit sharing}.
714*/
715QPalette::QPalette(const QPalette &p)
716{
717 d = p.d;
718 d->ref.ref();
719 resolve_mask = p.resolve_mask;
720 current_group = p.current_group;
721}
722
723/*!
724 Destroys the palette.
725*/
726QPalette::~QPalette()
727{
728 if(!d->ref.deref())
729 delete d;
730}
731
732/*!\internal*/
733void QPalette::init() {
734 d = new QPalettePrivate;
735 resolve_mask = 0;
736 current_group = Active; //as a default..
737}
738
739/*!
740 Assigns \a p to this palette and returns a reference to this
741 palette.
742
743 This operation is fast thanks to \l{implicit sharing}.
744*/
745QPalette &QPalette::operator=(const QPalette &p)
746{
747 p.d->ref.ref();
748 resolve_mask = p.resolve_mask;
749 current_group = p.current_group;
750 if(!d->ref.deref())
751 delete d;
752 d = p.d;
753 return *this;
754}
755
756/*!
757 Returns the palette as a QVariant
758*/
759QPalette::operator QVariant() const
760{
761 return QVariant(QVariant::Palette, this);
762}
763
764/*!
765 \fn const QColor &QPalette::color(ColorGroup group, ColorRole role) const
766
767 Returns the color in the specified color \a group, used for the
768 given color \a role.
769
770 \sa brush() setColor() ColorRole
771*/
772
773/*!
774 \fn const QBrush &QPalette::brush(ColorGroup group, ColorRole role) const
775
776 Returns the brush in the specified color \a group, used for the
777 given color \a role.
778
779 \sa color() setBrush() ColorRole
780*/
781const QBrush &QPalette::brush(ColorGroup gr, ColorRole cr) const
782{
783 Q_ASSERT(cr < NColorRoles);
784 if(gr >= (int)NColorGroups) {
785 if(gr == Current) {
786 gr = (ColorGroup)current_group;
787 } else {
788 qWarning("QPalette::brush: Unknown ColorGroup: %d", (int)gr);
789 gr = Active;
790 }
791 }
792 return d->br[gr][cr];
793}
794
795/*!
796 \fn void QPalette::setColor(ColorGroup group, ColorRole role, const QColor &color)
797
798 Sets the color in the specified color \a group, used for the given
799 color \a role, to the specified solid \a color.
800
801 \sa setBrush() color() ColorRole
802*/
803
804/*!
805 \fn void QPalette::setBrush(ColorGroup group, ColorRole role, const QBrush &brush)
806 \overload
807
808 Sets the brush in the specified color \a group, used for the given
809 color \a role, to \a brush.
810
811 \sa brush() setColor() ColorRole
812*/
813void QPalette::setBrush(ColorGroup cg, ColorRole cr, const QBrush &b)
814{
815 Q_ASSERT(cr < NColorRoles);
816 detach();
817 if(cg >= (int)NColorGroups) {
818 if(cg == All) {
819 for(int i = 0; i < (int)NColorGroups; i++)
820 d->br[i][cr] = b;
821 resolve_mask |= (1<<cr);
822 return;
823 } else if(cg == Current) {
824 cg = (ColorGroup)current_group;
825 } else {
826 qWarning("QPalette::setBrush: Unknown ColorGroup: %d", (int)cg);
827 cg = Active;
828 }
829 }
830 d->br[cg][cr] = b;
831 resolve_mask |= (1<<cr);
832}
833
834/*!
835 \since 4.2