1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/ |
5 | ** |
6 | ** This file is part of the QtGui module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** GNU Lesser General Public License Usage |
10 | ** This file may be used under the terms of the GNU Lesser General Public |
11 | ** License version 2.1 as published by the Free Software Foundation and |
12 | ** appearing in the file LICENSE.LGPL included in the packaging of this |
13 | ** file. Please review the following information to ensure the GNU Lesser |
14 | ** General Public License version 2.1 requirements will be met: |
15 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
16 | ** |
17 | ** In addition, as a special exception, Nokia gives you certain additional |
18 | ** rights. These rights are described in the Nokia Qt LGPL Exception |
19 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
20 | ** |
21 | ** GNU General Public License Usage |
22 | ** Alternatively, this file may be used under the terms of the GNU General |
23 | ** Public License version 3.0 as published by the Free Software Foundation |
24 | ** and appearing in the file LICENSE.GPL included in the packaging of this |
25 | ** file. Please review the following information to ensure the GNU General |
26 | ** Public License version 3.0 requirements will be met: |
27 | ** http://www.gnu.org/copyleft/gpl.html. |
28 | ** |
29 | ** Other Usage |
30 | ** Alternatively, this file may be used in accordance with the terms and |
31 | ** conditions contained in a signed written agreement between you and Nokia. |
32 | ** |
33 | ** |
34 | ** |
35 | ** |
36 | ** |
37 | ** |
38 | ** $QT_END_LICENSE$ |
39 | ** |
40 | ****************************************************************************/ |
41 | |
42 | #ifndef QICON_H |
43 | #define QICON_H |
44 | |
45 | #include <QtCore/qglobal.h> |
46 | #include <QtCore/qsize.h> |
47 | #include <QtCore/qlist.h> |
48 | #include <QtGui/qpixmap.h> |
49 | |
50 | QT_BEGIN_HEADER |
51 | |
52 | QT_BEGIN_NAMESPACE |
53 | |
54 | QT_MODULE(Gui) |
55 | |
56 | class QIconPrivate; |
57 | class QIconEngine; |
58 | class QIconEngineV2; |
59 | |
60 | class Q_GUI_EXPORT QIcon |
61 | { |
62 | public: |
63 | enum Mode { Normal, Disabled, Active, Selected }; |
64 | enum State { On, Off }; |
65 | |
66 | QIcon(); |
67 | QIcon(const QPixmap &pixmap); |
68 | QIcon(const QIcon &other); |
69 | explicit QIcon(const QString &fileName); // file or resource name |
70 | explicit QIcon(QIconEngine *engine); |
71 | explicit QIcon(QIconEngineV2 *engine); |
72 | ~QIcon(); |
73 | QIcon &operator=(const QIcon &other); |
74 | #ifdef Q_COMPILER_RVALUE_REFS |
75 | inline QIcon &operator=(QIcon &&other) |
76 | { qSwap(d, other.d); return *this; } |
77 | #endif |
78 | inline void swap(QIcon &other) { qSwap(d, other.d); } |
79 | |
80 | operator QVariant() const; |
81 | |
82 | QPixmap pixmap(const QSize &size, Mode mode = Normal, State state = Off) const; |
83 | inline QPixmap pixmap(int w, int h, Mode mode = Normal, State state = Off) const |
84 | { return pixmap(QSize(w, h), mode, state); } |
85 | inline QPixmap pixmap(int extent, Mode mode = Normal, State state = Off) const |
86 | { return pixmap(QSize(extent, extent), mode, state); } |
87 | |
88 | QSize actualSize(const QSize &size, Mode mode = Normal, State state = Off) const; |
89 | |
90 | QString name() const; |
91 | |
92 | void paint(QPainter *painter, const QRect &rect, Qt::Alignment alignment = Qt::AlignCenter, Mode mode = Normal, State state = Off) const; |
93 | 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 |
94 | { paint(painter, QRect(x, y, w, h), alignment, mode, state); } |
95 | |
96 | bool isNull() const; |
97 | bool isDetached() const; |
98 | void detach(); |
99 | |
100 | int serialNumber() const; |
101 | qint64 cacheKey() const; |
102 | |
103 | void addPixmap(const QPixmap &pixmap, Mode mode = Normal, State state = Off); |
104 | void addFile(const QString &fileName, const QSize &size = QSize(), Mode mode = Normal, State state = Off); |
105 | |
106 | QList<QSize> availableSizes(Mode mode = Normal, State state = Off) const; |
107 | |
108 | static QIcon fromTheme(const QString &name, const QIcon &fallback = QIcon()); |
109 | static bool hasThemeIcon(const QString &name); |
110 | |
111 | static QStringList themeSearchPaths(); |
112 | static void setThemeSearchPaths(const QStringList &searchpath); |
113 | |
114 | static QString themeName(); |
115 | static void setThemeName(const QString &path); |
116 | |
117 | |
118 | #ifdef QT3_SUPPORT |
119 | enum Size { Small, Large, Automatic = Small }; |
120 | static QT3_SUPPORT void setPixmapSize(Size which, const QSize &size); |
121 | static QT3_SUPPORT QSize pixmapSize(Size which); |
122 | inline QT3_SUPPORT void reset(const QPixmap &pixmap, Size /*size*/) { *this = QIcon(pixmap); } |
123 | inline QT3_SUPPORT void setPixmap(const QPixmap &pixmap, Size, Mode mode = Normal, State state = Off) |
124 | { addPixmap(pixmap, mode, state); } |
125 | inline QT3_SUPPORT void setPixmap(const QString &fileName, Size, Mode mode = Normal, State state = Off) |
126 | { addPixmap(QPixmap(fileName), mode, state); } |
127 | QT3_SUPPORT QPixmap pixmap(Size size, Mode mode, State state = Off) const; |
128 | QT3_SUPPORT QPixmap pixmap(Size size, bool enabled, State state = Off) const; |
129 | QT3_SUPPORT QPixmap pixmap() const; |
130 | #endif |
131 | |
132 | Q_DUMMY_COMPARISON_OPERATOR(QIcon) |
133 | |
134 | private: |
135 | QIconPrivate *d; |
136 | #if !defined(QT_NO_DATASTREAM) |
137 | friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &); |
138 | friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &); |
139 | #endif |
140 | |
141 | public: |
142 | typedef QIconPrivate * DataPtr; |
143 | inline DataPtr &data_ptr() { return d; } |
144 | }; |
145 | |
146 | Q_DECLARE_SHARED(QIcon) |
147 | Q_DECLARE_TYPEINFO(QIcon, Q_MOVABLE_TYPE); |
148 | |
149 | #if !defined(QT_NO_DATASTREAM) |
150 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &); |
151 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &); |
152 | #endif |
153 | |
154 | #ifdef QT3_SUPPORT |
155 | typedef QIcon QIconSet; |
156 | #endif |
157 | |
158 | QT_END_NAMESPACE |
159 | |
160 | QT_END_HEADER |
161 | |
162 | #endif // QICON_H |
163 | |