00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef QPALETTE_H
00043 #define QPALETTE_H
00044
00045 #include <QtGui/qwindowdefs.h>
00046 #include <QtGui/qcolor.h>
00047 #include <QtGui/qbrush.h>
00048
00049 QT_BEGIN_HEADER
00050
00051 QT_BEGIN_NAMESPACE
00052
00053 QT_MODULE(Gui)
00054
00055 #ifdef QT3_SUPPORT
00056 class QColorGroup;
00057 #endif
00058 class QPalettePrivate;
00059 class QVariant;
00060
00061 class Q_GUI_EXPORT QPalette
00062 {
00063 Q_GADGET
00064 Q_ENUMS(ColorGroup ColorRole)
00065 public:
00066 QPalette();
00067 QPalette(const QColor &button);
00068 QPalette(Qt::GlobalColor button);
00069 QPalette(const QColor &button, const QColor &window);
00070 QPalette(const QBrush &windowText, const QBrush &button, const QBrush &light,
00071 const QBrush &dark, const QBrush &mid, const QBrush &text,
00072 const QBrush &bright_text, const QBrush &base, const QBrush &window);
00073 QPalette(const QColor &windowText, const QColor &window, const QColor &light,
00074 const QColor &dark, const QColor &mid, const QColor &text, const QColor &base);
00075 #ifdef QT3_SUPPORT
00076 QT3_SUPPORT_CONSTRUCTOR QPalette(const QColorGroup &active, const QColorGroup &disabled, const QColorGroup &inactive);
00077 #endif
00078 QPalette(const QPalette &palette);
00079 ~QPalette();
00080 QPalette &operator=(const QPalette &palette);
00081 operator QVariant() const;
00082
00083
00084 enum ColorGroup { Active, Disabled, Inactive, NColorGroups, Current, All, Normal = Active };
00085 enum ColorRole { WindowText, Button, Light, Midlight, Dark, Mid,
00086 Text, BrightText, ButtonText, Base, Window, Shadow,
00087 Highlight, HighlightedText,
00088 Link, LinkVisited,
00089 AlternateBase,
00090 NoRole,
00091 ToolTipBase, ToolTipText,
00092 NColorRoles = ToolTipText + 1,
00093 Foreground = WindowText, Background = Window
00094 };
00095
00096 inline ColorGroup currentColorGroup() const { return static_cast<ColorGroup>(current_group); }
00097 inline void setCurrentColorGroup(ColorGroup cg) { current_group = cg; }
00098
00099 inline const QColor &color(ColorGroup cg, ColorRole cr) const
00100 { return brush(cg, cr).color(); }
00101 const QBrush &brush(ColorGroup cg, ColorRole cr) const;
00102 inline void setColor(ColorGroup cg, ColorRole cr, const QColor &color);
00103 inline void setColor(ColorRole cr, const QColor &color);
00104 inline void setBrush(ColorRole cr, const QBrush &brush);
00105 bool isBrushSet(ColorGroup cg, ColorRole cr) const;
00106 void setBrush(ColorGroup cg, ColorRole cr, const QBrush &brush);
00107 void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button,
00108 const QBrush &light, const QBrush &dark, const QBrush &mid,
00109 const QBrush &text, const QBrush &bright_text, const QBrush &base,
00110 const QBrush &window);
00111 bool isEqual(ColorGroup cr1, ColorGroup cr2) const;
00112
00113 inline const QColor &color(ColorRole cr) const { return color(Current, cr); }
00114 inline const QBrush &brush(ColorRole cr) const { return brush(Current, cr); }
00115 inline const QBrush &foreground() const { return brush(WindowText); }
00116 inline const QBrush &windowText() const { return brush(WindowText); }
00117 inline const QBrush &button() const { return brush(Button); }
00118 inline const QBrush &light() const { return brush(Light); }
00119 inline const QBrush &dark() const { return brush(Dark); }
00120 inline const QBrush &mid() const { return brush(Mid); }
00121 inline const QBrush &text() const { return brush(Text); }
00122 inline const QBrush &base() const { return brush(Base); }
00123 inline const QBrush &alternateBase() const { return brush(AlternateBase); }
00124 inline const QBrush &toolTipBase() const { return brush(ToolTipBase); }
00125 inline const QBrush &toolTipText() const { return brush(ToolTipText); }
00126 inline const QBrush &background() const { return brush(Window); }
00127 inline const QBrush &window() const { return brush(Window); }
00128 inline const QBrush &midlight() const { return brush(Midlight); }
00129 inline const QBrush &brightText() const { return brush(BrightText); }
00130 inline const QBrush &buttonText() const { return brush(ButtonText); }
00131 inline const QBrush &shadow() const { return brush(Shadow); }
00132 inline const QBrush &highlight() const { return brush(Highlight); }
00133 inline const QBrush &highlightedText() const { return brush(HighlightedText); }
00134 inline const QBrush &link() const { return brush(Link); }
00135 inline const QBrush &linkVisited() const { return brush(LinkVisited); }
00136
00137 #ifdef QT3_SUPPORT
00138 inline QT3_SUPPORT QPalette copy() const { QPalette p = *this; p.detach(); return p; }
00139 QT3_SUPPORT QColorGroup normal() const;
00140 inline QT3_SUPPORT void setNormal(const QColorGroup &cg) { setColorGroup(Active, cg); }
00141
00142 QT3_SUPPORT QColorGroup active() const;
00143 QT3_SUPPORT QColorGroup disabled() const;
00144 QT3_SUPPORT QColorGroup inactive() const;
00145 inline QT3_SUPPORT void setActive(const QColorGroup &cg) { setColorGroup(Active, cg); }
00146 inline QT3_SUPPORT void setDisabled(const QColorGroup &cg) { setColorGroup(Disabled, cg); }
00147 inline QT3_SUPPORT void setInactive(const QColorGroup &cg) { setColorGroup(Inactive, cg); }
00148 #endif
00149
00150 bool operator==(const QPalette &p) const;
00151 inline bool operator!=(const QPalette &p) const { return !(operator==(p)); }
00152 bool isCopyOf(const QPalette &p) const;
00153
00154 int serialNumber() const;
00155 qint64 cacheKey() const;
00156
00157 QPalette resolve(const QPalette &) const;
00158 inline uint resolve() const { return resolve_mask; }
00159 inline void resolve(uint mask) { resolve_mask = mask; }
00160
00161 private:
00162 void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button,
00163 const QBrush &light, const QBrush &dark, const QBrush &mid,
00164 const QBrush &text, const QBrush &bright_text,
00165 const QBrush &base, const QBrush &alternate_base,
00166 const QBrush &window, const QBrush &midlight,
00167 const QBrush &button_text, const QBrush &shadow,
00168 const QBrush &highlight, const QBrush &highlighted_text,
00169 const QBrush &link, const QBrush &link_visited);
00170 void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button,
00171 const QBrush &light, const QBrush &dark, const QBrush &mid,
00172 const QBrush &text, const QBrush &bright_text,
00173 const QBrush &base, const QBrush &alternate_base,
00174 const QBrush &window, const QBrush &midlight,
00175 const QBrush &button_text, const QBrush &shadow,
00176 const QBrush &highlight, const QBrush &highlighted_text,
00177 const QBrush &link, const QBrush &link_visited,
00178 const QBrush &toolTipBase, const QBrush &toolTipText);
00179 #ifdef QT3_SUPPORT
00180 friend class QColorGroup;
00181 void setColorGroup(ColorGroup, const QColorGroup &);
00182 QColorGroup createColorGroup(ColorGroup) const;
00183 #endif
00184 void init();
00185 void detach();
00186
00187 QPalettePrivate *d;
00188 uint current_group : 4;
00189 uint resolve_mask : 28;
00190 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const QPalette &p);
00191 };
00192
00193 inline void QPalette::setColor(ColorGroup acg, ColorRole acr,
00194 const QColor &acolor)
00195 { setBrush(acg, acr, QBrush(acolor)); }
00196 inline void QPalette::setColor(ColorRole acr, const QColor &acolor)
00197 { setColor(All, acr, acolor); }
00198 inline void QPalette::setBrush(ColorRole acr, const QBrush &abrush)
00199 { setBrush(All, acr, abrush); }
00200
00201 #ifdef QT3_SUPPORT
00202 class Q_GUI_EXPORT QColorGroup : public QPalette
00203 {
00204 public:
00205 inline QColorGroup() : QPalette() {}
00206 inline QColorGroup(const QBrush &foreground, const QBrush &button, const QBrush &light,
00207 const QBrush &dark, const QBrush &mid, const QBrush &text,
00208 const QBrush &bright_text, const QBrush &base, const QBrush &background)
00209 : QPalette(foreground, button, light, dark, mid, text, bright_text, base, background)
00210 {}
00211 inline QColorGroup(const QColor &foreground, const QColor &background, const QColor &light,
00212 const QColor &dark, const QColor &mid, const QColor &text, const QColor &base)
00213 : QPalette(foreground, background, light, dark, mid, text, base) {}
00214 inline QColorGroup(const QColorGroup &cg) : QPalette(cg) {}
00215 inline QColorGroup(const QPalette &pal) : QPalette(pal) {}
00216 bool operator==(const QColorGroup &other) const;
00217 inline bool operator!=(const QColorGroup &other) const { return !(operator==(other)); }
00218 operator QVariant() const;
00219
00220 inline QT3_SUPPORT const QColor &foreground() const { return color(WindowText); }
00221 inline QT3_SUPPORT const QColor &button() const { return color(Button); }
00222 inline QT3_SUPPORT const QColor &light() const { return color(Light); }
00223 inline QT3_SUPPORT const QColor &dark() const { return color(Dark); }
00224 inline QT3_SUPPORT const QColor &mid() const { return color(Mid); }
00225 inline QT3_SUPPORT const QColor &text() const { return color(Text); }
00226 inline QT3_SUPPORT const QColor &base() const { return color(Base); }
00227 inline QT3_SUPPORT const QColor &background() const { return color(Window); }
00228 inline QT3_SUPPORT const QColor &midlight() const { return color(Midlight); }
00229 inline QT3_SUPPORT const QColor &brightText() const { return color(BrightText); }
00230 inline QT3_SUPPORT const QColor &buttonText() const { return color(ButtonText); }
00231 inline QT3_SUPPORT const QColor &shadow() const { return color(Shadow); }
00232 inline QT3_SUPPORT const QColor &highlight() const { return color(Highlight); }
00233 inline QT3_SUPPORT const QColor &highlightedText() const { return color(HighlightedText); }
00234 inline QT3_SUPPORT const QColor &link() const { return color(Link); }
00235 inline QT3_SUPPORT const QColor &linkVisited() const { return color(LinkVisited); }
00236 };
00237
00238 #ifndef QT_NO_DATASTREAM
00239 Q_GUI_EXPORT QT3_SUPPORT QDataStream &operator<<(QDataStream &ds, const QColorGroup &cg);
00240 Q_GUI_EXPORT QT3_SUPPORT QDataStream &operator>>(QDataStream &ds, QColorGroup &cg);
00241 #endif
00242
00243 inline QColorGroup QPalette::inactive() const { return createColorGroup(Inactive); }
00244 inline QColorGroup QPalette::disabled() const { return createColorGroup(Disabled); }
00245 inline QColorGroup QPalette::active() const { return createColorGroup(Active); }
00246 inline QColorGroup QPalette::normal() const { return createColorGroup(Active); }
00247
00248 #endif
00249
00250
00251
00252
00253 #ifndef QT_NO_DATASTREAM
00254 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &ds, const QPalette &p);
00255 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &ds, QPalette &p);
00256 #endif // QT_NO_DATASTREAM
00257
00258 QT_END_NAMESPACE
00259
00260 QT_END_HEADER
00261
00262 #endif // QPALETTE_H