1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
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 The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QICON_H
41#define QICON_H
42
43#include <QtGui/qtguiglobal.h>
44#include <QtCore/qsize.h>
45#include <QtCore/qlist.h>
46#include <QtGui/qpixmap.h>
47
48QT_BEGIN_NAMESPACE
49
50
51class QIconPrivate;
52class QIconEngine;
53class QPainter;
54
55class Q_GUI_EXPORT QIcon
56{
57public:
58 enum Mode { Normal, Disabled, Active, Selected };
59 enum State { On, Off };
60
61 QIcon() Q_DECL_NOEXCEPT;
62 QIcon(const QPixmap &pixmap);
63 QIcon(const QIcon &other);
64#ifdef Q_COMPILER_RVALUE_REFS
65 QIcon(QIcon &&other) Q_DECL_NOEXCEPT
66 : d(other.d)
67 { other.d = nullptr; }
68#endif
69 explicit QIcon(const QString &fileName); // file or resource name
70 explicit QIcon(QIconEngine *engine);
71 ~QIcon();
72 QIcon &operator=(const QIcon &other);
73#ifdef Q_COMPILER_RVALUE_REFS
74 inline QIcon &operator=(QIcon &&other) Q_DECL_NOEXCEPT
75 { swap(other); return *this; }
76#endif
77 inline void swap(QIcon &other) Q_DECL_NOEXCEPT
78 { 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 QPixmap pixmap(QWindow *window, const QSize &size, Mode mode = Normal, State state = Off) const;
88
89 QSize actualSize(const QSize &size, Mode mode = Normal, State state = Off) const;
90 QSize actualSize(QWindow *window, const QSize &size, Mode mode = Normal, State state = Off) const;
91
92 QString name() const;
93
94 void paint(QPainter *painter, const QRect &rect, Qt::Alignment alignment = Qt::AlignCenter, Mode mode = Normal, State state = Off) const;
95 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
96 { paint(painter, QRect(x, y, w, h), alignment, mode, state); }
97
98 bool isNull() const;
99 bool isDetached() const;
100 void detach();
101
102#if QT_DEPRECATED_SINCE(5, 0)
103 QT_DEPRECATED inline int serialNumber() const { return cacheKey() >> 32; }
104#endif
105 qint64 cacheKey() const;
106
107 void addPixmap(const QPixmap &pixmap, Mode mode = Normal, State state = Off);
108 void addFile(const QString &fileName, const QSize &size = QSize(), Mode mode = Normal, State state = Off);
109
110 QList<QSize> availableSizes(Mode mode = Normal, State state = Off) const;
111
112 void setIsMask(bool isMask);
113 bool isMask() const;
114
115 static QIcon fromTheme(const QString &name);
116 static QIcon fromTheme(const QString &name, const QIcon &fallback);
117 static bool hasThemeIcon(const QString &name);
118
119 static QStringList themeSearchPaths();
120 static void setThemeSearchPaths(const QStringList &searchpath);
121
122 static QStringList fallbackSearchPaths();
123 static void setFallbackSearchPaths(const QStringList &paths);
124
125 static QString themeName();
126 static void setThemeName(const QString &path);
127
128 static QString fallbackThemeName();
129 static void setFallbackThemeName(const QString &name);
130
131 Q_DUMMY_COMPARISON_OPERATOR(QIcon)
132
133private:
134 QIconPrivate *d;
135#if !defined(QT_NO_DATASTREAM)
136 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
137 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
138#endif
139
140public:
141 typedef QIconPrivate * DataPtr;
142 inline DataPtr &data_ptr() { return d; }
143};
144
145Q_DECLARE_SHARED(QIcon)
146
147#if !defined(QT_NO_DATASTREAM)
148Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
149Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
150#endif
151
152#ifndef QT_NO_DEBUG_STREAM
153Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QIcon &);
154#endif
155
156Q_GUI_EXPORT QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio,
157 qreal *sourceDevicePixelRatio = nullptr);
158
159QT_END_NAMESPACE
160
161#endif // QICON_H
162