Logo Search packages:      
Sourcecode: qt4-x11 version File versions

qpalette.h

/****************************************************************************
**
** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** This file may be used under the terms of the GNU General Public
** License version 2.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file.  Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
** http://www.trolltech.com/products/qt/opensource.html
**
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://www.trolltech.com/products/qt/licensing.html or contact the
** sales department at sales@trolltech.com.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/

#ifndef QPALETTE_H
#define QPALETTE_H

#include <QtGui/qwindowdefs.h>
#include <QtGui/qcolor.h>
#include <QtGui/qbrush.h>

QT_BEGIN_HEADER

QT_MODULE(Gui)

#ifdef QT3_SUPPORT
class QColorGroup;
#endif
class QPalettePrivate;
class QVariant;

00041 class Q_GUI_EXPORT QPalette
{
    Q_GADGET
    Q_ENUMS(ColorGroup ColorRole)
public:
    QPalette();
    QPalette(const QColor &button);
    QPalette(Qt::GlobalColor button);
    QPalette(const QColor &button, const QColor &window);
    QPalette(const QBrush &windowText, const QBrush &button, const QBrush &light,
             const QBrush &dark, const QBrush &mid, const QBrush &text,
             const QBrush &bright_text, const QBrush &base, const QBrush &window);
    QPalette(const QColor &windowText, const QColor &window, const QColor &light,
             const QColor &dark, const QColor &mid, const QColor &text, const QColor &base);
#ifdef QT3_SUPPORT
    QT3_SUPPORT_CONSTRUCTOR QPalette(const QColorGroup &active, const QColorGroup &disabled, const QColorGroup &inactive);
#endif
    QPalette(const QPalette &palette);
    ~QPalette();
    QPalette &operator=(const QPalette &palette);
    operator QVariant() const;

    // Do not change the order, the serialization format depends on it
00064     enum ColorGroup { Active, Disabled, Inactive, NColorGroups, Current, All, Normal = Active };
00065     enum ColorRole { WindowText, Button, Light, Midlight, Dark, Mid,
                     Text, BrightText, ButtonText, Base, Window, Shadow,
                     Highlight, HighlightedText,
                     Link, LinkVisited, // ### Qt 5: remove
                     AlternateBase, NoRole, NColorRoles = NoRole,
                     Foreground = WindowText, Background = Window // ### Qt 5: remove
                   };

00073     inline ColorGroup currentColorGroup() const { return static_cast<ColorGroup>(current_group); }
00074     inline void setCurrentColorGroup(ColorGroup cg) { current_group = cg; }

00076     inline const QColor &color(ColorGroup cg, ColorRole cr) const
    { return brush(cg, cr).color(); }
    const QBrush &brush(ColorGroup cg, ColorRole cr) const;
    inline void setColor(ColorGroup cg, ColorRole cr, const QColor &color);
    inline void setColor(ColorRole cr, const QColor &color);
    inline void setBrush(ColorRole cr, const QBrush &brush);
    bool isBrushSet(ColorGroup cg, ColorRole cr) const;
    void setBrush(ColorGroup cg, ColorRole cr, const QBrush &brush);
    void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button,
                       const QBrush &light, const QBrush &dark, const QBrush &mid,
                       const QBrush &text, const QBrush &bright_text, const QBrush &base,
                       const QBrush &window);
    bool isEqual(ColorGroup cr1, ColorGroup cr2) const;

00090     inline const QColor &color(ColorRole cr) const { return color(Current, cr); }
00091     inline const QBrush &brush(ColorRole cr) const { return brush(Current, cr); }
00092     inline const QBrush &foreground() const { return brush(WindowText); }
00093     inline const QBrush &windowText() const { return brush(WindowText); }
00094     inline const QBrush &button() const { return brush(Button); }
00095     inline const QBrush &light() const { return brush(Light); }
00096     inline const QBrush &dark() const { return brush(Dark); }
00097     inline const QBrush &mid() const { return brush(Mid); }
00098     inline const QBrush &text() const { return brush(Text); }
00099     inline const QBrush &base() const { return brush(Base); }
00100     inline const QBrush &alternateBase() const { return brush(AlternateBase); }
00101     inline const QBrush &background() const { return brush(Window); }
00102     inline const QBrush &window() const { return brush(Window); }
00103     inline const QBrush &midlight() const { return brush(Midlight); }
00104     inline const QBrush &brightText() const { return brush(BrightText); }
00105     inline const QBrush &buttonText() const { return brush(ButtonText); }
00106     inline const QBrush &shadow() const { return brush(Shadow); }
00107     inline const QBrush &highlight() const { return brush(Highlight); }
00108     inline const QBrush &highlightedText() const { return brush(HighlightedText); }
00109     inline const QBrush &link() const { return brush(Link); }
00110     inline const QBrush &linkVisited() const { return brush(LinkVisited); }

#ifdef QT3_SUPPORT
    inline QT3_SUPPORT QPalette copy() const { QPalette p = *this; p.detach(); return p; }
    QT3_SUPPORT QColorGroup normal() const;
    inline QT3_SUPPORT void setNormal(const QColorGroup &cg) { setColorGroup(Active, cg); }

    QT3_SUPPORT QColorGroup active() const;
    QT3_SUPPORT QColorGroup disabled() const;
    QT3_SUPPORT QColorGroup inactive() const;
    inline QT3_SUPPORT void setActive(const QColorGroup &cg) { setColorGroup(Active, cg); }
    inline QT3_SUPPORT void setDisabled(const QColorGroup &cg) { setColorGroup(Disabled, cg); }
    inline QT3_SUPPORT void setInactive(const QColorGroup &cg) { setColorGroup(Inactive, cg); }
#endif

    bool operator==(const QPalette &p) const;
00126     inline bool operator!=(const QPalette &p) const { return !(operator==(p)); }
    bool isCopyOf(const QPalette &p) const;

    int serialNumber() const;

    QPalette resolve(const QPalette &) const;
00132     inline uint resolve() const { return resolve_mask; }
00133     inline void resolve(uint mask) { resolve_mask = mask; }

private:
    void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button,
                       const QBrush &light, const QBrush &dark, const QBrush &mid,
                       const QBrush &text, const QBrush &bright_text,
                       const QBrush &base, const QBrush &alternate_base,
                       const QBrush &window, const QBrush &midlight,
                       const QBrush &button_text, const QBrush &shadow,
                       const QBrush &highlight, const QBrush &highlighted_text,
                       const QBrush &link, const QBrush &link_visited);
#ifdef QT3_SUPPORT
    friend class QColorGroup;
    void setColorGroup(ColorGroup, const QColorGroup &);
    QColorGroup createColorGroup(ColorGroup) const;
#endif
    void init();
    void detach();

    QPalettePrivate *d;
    uint current_group : 4;
    uint resolve_mask : 28;
    friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const QPalette &p);
};

00158 inline void QPalette::setColor(ColorGroup acg, ColorRole acr,
                               const QColor &acolor)
{ setBrush(acg, acr, QBrush(acolor)); }
00161 inline void QPalette::setColor(ColorRole acr, const QColor &acolor)
{ setColor(All, acr, acolor); }
00163 inline void QPalette::setBrush(ColorRole acr, const QBrush &abrush)
{ setBrush(All, acr, abrush); }

#ifdef QT3_SUPPORT
class Q_GUI_EXPORT QColorGroup : public QPalette
{
public:
    inline QColorGroup() : QPalette() {}
    inline QColorGroup(const QBrush &foreground, const QBrush &button, const QBrush &light,
                const QBrush &dark, const QBrush &mid, const QBrush &text,
                const QBrush &bright_text, const QBrush &base, const QBrush &background)
        : QPalette(foreground, button, light, dark, mid, text, bright_text, base, background)
    {}
    inline QColorGroup(const QColor &foreground, const QColor &background, const QColor &light,
                const QColor &dark, const QColor &mid, const QColor &text, const QColor &base)
        : QPalette(foreground, background, light, dark, mid, text, base) {}
    inline QColorGroup(const QColorGroup &cg) : QPalette(cg) {}
    inline QColorGroup(const QPalette &pal) : QPalette(pal) {}
    bool operator==(const QColorGroup &other) const;
    inline bool operator!=(const QColorGroup &other) const { return !(operator==(other)); }
    operator QVariant() const;

    inline QT3_SUPPORT const QColor &foreground() const { return color(WindowText); }
    inline QT3_SUPPORT const QColor &button() const { return color(Button); }
    inline QT3_SUPPORT const QColor &light() const { return color(Light); }
    inline QT3_SUPPORT const QColor &dark() const { return color(Dark); }
    inline QT3_SUPPORT const QColor &mid() const { return color(Mid); }
    inline QT3_SUPPORT const QColor &text() const { return color(Text); }
    inline QT3_SUPPORT const QColor &base() const { return color(Base); }
    inline QT3_SUPPORT const QColor &background() const { return color(Window); }
    inline QT3_SUPPORT const QColor &midlight() const { return color(Midlight); }
    inline QT3_SUPPORT const QColor &brightText() const { return color(BrightText); }
    inline QT3_SUPPORT const QColor &buttonText() const { return color(ButtonText); }
    inline QT3_SUPPORT const QColor &shadow() const { return color(Shadow); }
    inline QT3_SUPPORT const QColor &highlight() const { return color(Highlight); }
    inline QT3_SUPPORT const QColor &highlightedText() const { return color(HighlightedText); }
    inline QT3_SUPPORT const QColor &link() const { return color(Link); }
    inline QT3_SUPPORT const QColor &linkVisited() const { return color(LinkVisited); }
};

#ifndef QT_NO_DATASTREAM
Q_GUI_EXPORT QT3_SUPPORT QDataStream &operator<<(QDataStream &ds, const QColorGroup &cg);
Q_GUI_EXPORT QT3_SUPPORT QDataStream &operator>>(QDataStream &ds, QColorGroup &cg);
#endif

inline QColorGroup QPalette::inactive() const { return createColorGroup(Inactive); }
inline QColorGroup QPalette::disabled() const { return createColorGroup(Disabled); }
inline QColorGroup QPalette::active() const { return createColorGroup(Active); }
inline QColorGroup QPalette::normal() const { return createColorGroup(Active); }

#endif

/*****************************************************************************
  QPalette stream functions
 *****************************************************************************/
#ifndef QT_NO_DATASTREAM
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &ds, const QPalette &p);
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &ds, QPalette &p);
#endif // QT_NO_DATASTREAM

QT_END_HEADER

#endif // QPALETTE_H

Generated by  Doxygen 1.6.0   Back to index