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