1/****************************************************************************
2**
3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Digia. For licensing terms and
14** conditions see http://qt.digia.com/licensing. For further information
15** use the contact form at http://qt.digia.com/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Digia gives you certain additional
26** rights. These rights are described in the Digia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
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
50QT_BEGIN_HEADER
51
52QT_BEGIN_NAMESPACE
53
54QT_MODULE(Gui)
55
56class QIconPrivate;
57class QIconEngine;
58class QIconEngineV2;
59
60class Q_GUI_EXPORT QIcon
61{
62public:
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
134private:
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
141public:
142 typedef QIconPrivate * DataPtr;
143 inline DataPtr &data_ptr() { return d; }
144};
145
146Q_DECLARE_SHARED(QIcon)
147Q_DECLARE_TYPEINFO(QIcon, Q_MOVABLE_TYPE);
148
149#if !defined(QT_NO_DATASTREAM)
150Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
151Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
152#endif
153
154#ifdef QT3_SUPPORT
155typedef QIcon QIconSet;
156#endif
157
158QT_END_NAMESPACE
159
160QT_END_HEADER
161
162#endif // QICON_H
163