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;
53
54class Q_GUI_EXPORT QIcon
55{
56public:
57 enum Mode { Normal, Disabled, Active, Selected };
58 enum State { On, Off };
59
60 QIcon() Q_DECL_NOEXCEPT;
61 QIcon(const QPixmap &pixmap);
62 QIcon(const QIcon &other);
63#ifdef Q_COMPILER_RVALUE_REFS
64 QIcon(QIcon &&other) Q_DECL_NOEXCEPT
65 : d(other.d)
66 { other.d = nullptr; }
67#endif
68 explicit QIcon(const QString &fileName); // file or resource name
69 explicit QIcon(QIconEngine *engine);
70 ~QIcon();
71 QIcon &operator=(const QIcon &other);
72#ifdef Q_COMPILER_RVALUE_REFS
73 inline QIcon &operator=(QIcon &&other) Q_DECL_NOEXCEPT
74 { swap(other); return *this; }
75#endif
76 inline void swap(QIcon &other) Q_DECL_NOEXCEPT
77 { qSwap(d, other.d); }
78
79 operator QVariant() const;
80
81 QPixmap pixmap(const QSize &size, Mode mode = Normal, State state = Off) const;
82 inline QPixmap pixmap(int w, int h, Mode mode = Normal, State state = Off) const
83 { return pixmap(QSize(w, h), mode, state); }
84 inline QPixmap pixmap(int extent, Mode mode = Normal, State state = Off) const
85 { return pixmap(QSize(extent, extent), mode, state); }
86 QPixmap pixmap(QWindow *window, const QSize &size, Mode mode = Normal, State state = Off) const;
87
88 QSize actualSize(const QSize &size, Mode mode = Normal, State state = Off) const;
89 QSize actualSize(QWindow *window, const QSize &size, Mode mode = Normal, State state = Off) const;
90
91 QString name() const;
92
93 void paint(QPainter *painter, const QRect &rect, Qt::Alignment alignment = Qt::AlignCenter, Mode mode = Normal, State state = Off) const;
94 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
95 { paint(painter, QRect(x, y, w, h), alignment, mode, state); }
96
97 bool isNull() const;
98 bool isDetached() const;
99 void detach();
100
101#if QT_DEPRECATED_SINCE(5, 0)
102 QT_DEPRECATED inline int serialNumber() const { return cacheKey() >> 32; }
103#endif
104 qint64 cacheKey() const;
105
106 void addPixmap(const QPixmap &pixmap, Mode mode = Normal, State state = Off);
107 void addFile(const QString &fileName, const QSize &size = QSize(), Mode mode = Normal, State state = Off);
108
109 QList<QSize> availableSizes(Mode mode = Normal, State state = Off) const;
110
111 void setIsMask(bool isMask);
112 bool isMask() const;
113
114 static QIcon fromTheme(const QString &name);
115 static QIcon fromTheme(const QString &name, const QIcon &fallback);
116 static bool hasThemeIcon(const QString &name);
117
118 static QStringList themeSearchPaths();
119 static void setThemeSearchPaths(const QStringList &searchpath);
120
121 static QStringList fallbackSearchPaths();
122 static void setFallbackSearchPaths(const QStringList &paths);
123
124 static QString themeName();
125 static void setThemeName(const QString &path);
126
127 Q_DUMMY_COMPARISON_OPERATOR(QIcon)
128
129private:
130 QIconPrivate *d;
131#if !defined(QT_NO_DATASTREAM)
132 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
133 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
134#endif
135
136public:
137 typedef QIconPrivate * DataPtr;
138 inline DataPtr &data_ptr() { return d; }
139};
140
141Q_DECLARE_SHARED(QIcon)
142
143#if !defined(QT_NO_DATASTREAM)
144Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
145Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
146#endif
147
148#ifndef QT_NO_DEBUG_STREAM
149Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QIcon &);
150#endif
151
152Q_GUI_EXPORT QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio,
153 qreal *sourceDevicePixelRatio = nullptr);
154
155QT_END_NAMESPACE
156
157#endif // QICON_H
158