qicon.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtGui module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QICON_H
00043 #define QICON_H
00044 
00045 #include <QtCore/qglobal.h>
00046 #include <QtCore/qsize.h>
00047 #include <QtCore/qlist.h>
00048 #include <QtGui/qpixmap.h>
00049 
00050 QT_BEGIN_HEADER
00051 
00052 QT_BEGIN_NAMESPACE
00053 
00054 QT_MODULE(Gui)
00055 
00056 class QIconPrivate;
00057 class QIconEngine;
00058 class QIconEngineV2;
00059 
00060 class Q_GUI_EXPORT QIcon
00061 {
00062 public:
00063     enum Mode { Normal, Disabled, Active, Selected };
00064     enum State { On, Off };
00065 
00066     QIcon();
00067     QIcon(const QPixmap &pixmap);
00068     QIcon(const QIcon &other);
00069     explicit QIcon(const QString &fileName); // file or resource name
00070     explicit QIcon(QIconEngine *engine);
00071     explicit QIcon(QIconEngineV2 *engine);
00072     ~QIcon();
00073     QIcon &operator=(const QIcon &other);
00074     operator QVariant() const;
00075 
00076     QPixmap pixmap(const QSize &size, Mode mode = Normal, State state = Off) const;
00077     inline QPixmap pixmap(int w, int h, Mode mode = Normal, State state = Off) const
00078         { return pixmap(QSize(w, h), mode, state); }
00079     inline QPixmap pixmap(int extent, Mode mode = Normal, State state = Off) const
00080         { return pixmap(QSize(extent, extent), mode, state); }
00081 
00082     QSize actualSize(const QSize &size, Mode mode = Normal, State state = Off) const;
00083 
00084     QString name() const;
00085 
00086     void paint(QPainter *painter, const QRect &rect, Qt::Alignment alignment = Qt::AlignCenter, Mode mode = Normal, State state = Off) const;
00087     inline void paint(QPainter *painter, int x, int y, int w, int h, Qt::Alignment alignment = Qt::AlignCenter, Mode mode = Normal, State state = Off) const
00088         { paint(painter, QRect(x, y, w, h), alignment, mode, state); }
00089 
00090     bool isNull() const;
00091     bool isDetached() const;
00092     void detach();
00093 
00094     int serialNumber() const;
00095     qint64 cacheKey() const;
00096 
00097     void addPixmap(const QPixmap &pixmap, Mode mode = Normal, State state = Off);
00098     void addFile(const QString &fileName, const QSize &size = QSize(), Mode mode = Normal, State state = Off);
00099 
00100     QList<QSize> availableSizes(Mode mode = Normal, State state = Off) const;
00101 
00102     static QIcon fromTheme(const QString &name, const QIcon &fallback = QIcon());
00103     static bool hasThemeIcon(const QString &name);
00104 
00105     static QStringList themeSearchPaths();
00106     static void setThemeSearchPaths(const QStringList &searchpath);
00107 
00108     static QString themeName();
00109     static void setThemeName(const QString &path);
00110 
00111 
00112 #ifdef QT3_SUPPORT
00113     enum Size { Small, Large, Automatic = Small };
00114     static QT3_SUPPORT void setPixmapSize(Size which, const QSize &size);
00115     static QT3_SUPPORT QSize pixmapSize(Size which);
00116     inline QT3_SUPPORT void reset(const QPixmap &pixmap, Size /*size*/) { *this = QIcon(pixmap); }
00117     inline QT3_SUPPORT void setPixmap(const QPixmap &pixmap, Size, Mode mode = Normal, State state = Off)
00118         { addPixmap(pixmap, mode, state); }
00119     inline QT3_SUPPORT void setPixmap(const QString &fileName, Size, Mode mode = Normal, State state = Off)
00120         { addPixmap(QPixmap(fileName), mode, state); }
00121     QT3_SUPPORT QPixmap pixmap(Size size, Mode mode, State state = Off) const;
00122     QT3_SUPPORT QPixmap pixmap(Size size, bool enabled, State state = Off) const;
00123     QT3_SUPPORT QPixmap pixmap() const;
00124 #endif
00125 
00126     Q_DUMMY_COMPARISON_OPERATOR(QIcon)
00127 
00128 private:
00129     QIconPrivate *d;
00130 #if !defined(QT_NO_DATASTREAM)
00131     friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
00132     friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
00133 #endif
00134 
00135 public:
00136     typedef QIconPrivate * DataPtr;
00137     inline DataPtr &data_ptr() { return d; }
00138 };
00139 
00140 Q_DECLARE_SHARED(QIcon)
00141 Q_DECLARE_TYPEINFO(QIcon, Q_MOVABLE_TYPE);
00142 
00143 #if !defined(QT_NO_DATASTREAM)
00144 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
00145 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
00146 #endif
00147 
00148 #ifdef QT3_SUPPORT
00149 typedef QIcon QIconSet;
00150 #endif
00151 
00152 QT_END_NAMESPACE
00153 
00154 QT_END_HEADER
00155 
00156 #endif // QICON_H