source: trunk/src/gui/image/qicon.h@ 503

Last change on this file since 503 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 5.3 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
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 operator QVariant() const;
75
76 QPixmap pixmap(const QSize &size, Mode mode = Normal, State state = Off) const;
77 inline QPixmap pixmap(int w, int h, Mode mode = Normal, State state = Off) const
78 { return pixmap(QSize(w, h), mode, state); }
79 inline QPixmap pixmap(int extent, Mode mode = Normal, State state = Off) const
80 { return pixmap(QSize(extent, extent), mode, state); }
81
82 QSize actualSize(const QSize &size, Mode mode = Normal, State state = Off) const;
83
84 void paint(QPainter *painter, const QRect &rect, Qt::Alignment alignment = Qt::AlignCenter, Mode mode = Normal, State state = Off) const;
85 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
86 { paint(painter, QRect(x, y, w, h), alignment, mode, state); }
87
88 bool isNull() const;
89 bool isDetached() const;
90 void detach();
91
92 int serialNumber() const;
93 qint64 cacheKey() const;
94
95 void addPixmap(const QPixmap &pixmap, Mode mode = Normal, State state = Off);
96 void addFile(const QString &fileName, const QSize &size = QSize(), Mode mode = Normal, State state = Off);
97
98 QList<QSize> availableSizes(Mode mode = Normal, State state = Off) const;
99
100#ifdef QT3_SUPPORT
101 enum Size { Small, Large, Automatic = Small };
102 static QT3_SUPPORT void setPixmapSize(Size which, const QSize &size);
103 static QT3_SUPPORT QSize pixmapSize(Size which);
104 inline QT3_SUPPORT void reset(const QPixmap &pixmap, Size /*size*/) { *this = QIcon(pixmap); }
105 inline QT3_SUPPORT void setPixmap(const QPixmap &pixmap, Size, Mode mode = Normal, State state = Off)
106 { addPixmap(pixmap, mode, state); }
107 inline QT3_SUPPORT void setPixmap(const QString &fileName, Size, Mode mode = Normal, State state = Off)
108 { addPixmap(QPixmap(fileName), mode, state); }
109 QT3_SUPPORT QPixmap pixmap(Size size, Mode mode, State state = Off) const;
110 QT3_SUPPORT QPixmap pixmap(Size size, bool enabled, State state = Off) const;
111 QT3_SUPPORT QPixmap pixmap() const;
112#endif
113
114 Q_DUMMY_COMPARISON_OPERATOR(QIcon)
115
116private:
117 QIconPrivate *d;
118#if !defined(QT_NO_DATASTREAM)
119 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
120 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
121#endif
122
123public:
124 typedef QIconPrivate * DataPtr;
125 inline DataPtr &data_ptr() { return d; }
126};
127
128Q_DECLARE_SHARED(QIcon)
129Q_DECLARE_TYPEINFO(QIcon, Q_MOVABLE_TYPE);
130
131#if !defined(QT_NO_DATASTREAM)
132Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
133Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
134#endif
135
136#ifdef QT3_SUPPORT
137typedef QIcon QIconSet;
138#endif
139
140QT_END_NAMESPACE
141
142QT_END_HEADER
143
144#endif // QICON_H
Note: See TracBrowser for help on using the repository browser.