Qt 4.8
qicon.h
Go to the documentation of this file.
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 
51 
53 
54 QT_MODULE(Gui)
55 
56 class QIconPrivate;
57 class QIconEngine;
58 class QIconEngineV2;
59 
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 
133 
134 private:
136 #if !defined(QT_NO_DATASTREAM)
139 #endif
140 
141 public:
143  inline DataPtr &data_ptr() { return d; }
144 };
145 
148 
149 #if !defined(QT_NO_DATASTREAM)
152 #endif
153 
154 #ifdef QT3_SUPPORT
155 typedef QIcon QIconSet;
156 #endif
157 
159 
161 
162 #endif // QICON_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
#define Q_DUMMY_COMPARISON_OPERATOR(C)
Definition: qglobal.h:2104
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
DataPtr & data_ptr()
Definition: qicon.h:143
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
QIconPrivate * d
Definition: qicon.h:135
QIconPrivate * DataPtr
Definition: qicon.h:142
Q_CORE_EXPORT QTextStream & reset(QTextStream &s)
Q_GUI_EXPORT QDataStream & operator>>(QDataStream &, QIcon &)
Definition: qicon.cpp:1144
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_DECLARE_SHARED(TYPE)
Definition: qglobal.h:2214
QPixmap pixmap(int extent, Mode mode=Normal, State state=Off) const
Returns a pixmap of size QSize(extent, extent).
Definition: qicon.h:85
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void paint(QPainter *painter, int x, int y, int w, int h, Qt::Alignment alignment=Qt::AlignCenter, Mode mode=Normal, State state=Off) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qicon.h:93
Q_GUI_EXPORT QDataStream & operator<<(QDataStream &, const QIcon &)
Definition: qicon.cpp:1096
const char * name
Mode
This enum type describes the mode for which a pixmap is intended to be used.
Definition: qicon.h:63
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
__int64 qint64
Definition: qglobal.h:942
The State element defines configurations of objects and properties.
The QIconEngineV2 class provides an abstract base class for QIcon renderers.
Definition: qiconengine.h:73
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
The QIconEngine class provides an abstract base class for QIcon renderers.
Definition: qiconengine.h:55
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QPixmap pixmap(int w, int h, Mode mode=Normal, State state=Off) const
Returns a pixmap of size QSize(w, h).
Definition: qicon.h:83
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
Q_DECLARE_TYPEINFO(QIcon, Q_MOVABLE_TYPE)
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void swap(QIcon &other)
Swaps icon other with this icon.
Definition: qicon.h:78
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
#define QT_END_HEADER
Definition: qglobal.h:137
static QString fileName(const QString &fileUrl)
#define enabled
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300
static QMenuBar * fallback
Definition: qmenu_mac.mm:1617
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60