QtBase  v6.3.1
qicon.h
Go to the documentation of this file.
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 
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;
64  QIcon(QIcon &&other) noexcept
65  : d(qExchange(other.d, nullptr))
66  {}
67  explicit QIcon(const QString &fileName); // file or resource name
68  explicit QIcon(QIconEngine *engine);
69  ~QIcon();
70  QIcon &operator=(const QIcon &other);
72  inline void swap(QIcon &other) noexcept
73  { qt_ptr_swap(d, other.d); }
74  bool operator==(const QIcon &) const = delete;
75  bool operator!=(const QIcon &) const = delete;
76 
77  operator QVariant() const;
78 
79  QPixmap pixmap(const QSize &size, Mode mode = Normal, State state = Off) const;
80  inline QPixmap pixmap(int w, int h, Mode mode = Normal, State state = Off) const
81  { return pixmap(QSize(w, h), mode, state); }
82  inline QPixmap pixmap(int extent, Mode mode = Normal, State state = Off) const
83  { return pixmap(QSize(extent, extent), mode, state); }
84  QPixmap pixmap(const QSize &size, qreal devicePixelRatio, Mode mode = Normal, State state = Off) const;
85 #if QT_DEPRECATED_SINCE(6, 0)
86  QT_DEPRECATED_VERSION_X_6_0("Use pixmap(size, devicePixelRatio) instead")
88 #endif
89 
90  QSize actualSize(const QSize &size, Mode mode = Normal, State state = Off) const;
91 #if QT_DEPRECATED_SINCE(6, 0)
92  QT_DEPRECATED_VERSION_X_6_0("Use actualSize(size) instead")
93  QSize actualSize(QWindow *window, const QSize &size, Mode mode = Normal, State state = Off) const;
94 #endif
95 
96  QString name() const;
97 
98  void paint(QPainter *painter, const QRect &rect, Qt::Alignment alignment = Qt::AlignCenter, Mode mode = Normal, State state = Off) const;
99  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
100  { paint(painter, QRect(x, y, w, h), alignment, mode, state); }
101 
102  bool isNull() const;
103  bool isDetached() const;
104  void detach();
105 
106  qint64 cacheKey() const;
107 
108  void addPixmap(const QPixmap &pixmap, Mode mode = Normal, State state = Off);
109  void addFile(const QString &fileName, const QSize &size = QSize(), Mode mode = Normal, State state = Off);
110 
111  QList<QSize> availableSizes(Mode mode = Normal, State state = Off) const;
112 
113  void setIsMask(bool isMask);
114  bool isMask() const;
115 
116  static QIcon fromTheme(const QString &name);
117  static QIcon fromTheme(const QString &name, const QIcon &fallback);
118  static bool hasThemeIcon(const QString &name);
119 
120  static QStringList themeSearchPaths();
121  static void setThemeSearchPaths(const QStringList &searchpath);
122 
123  static QStringList fallbackSearchPaths();
124  static void setFallbackSearchPaths(const QStringList &paths);
125 
126  static QString themeName();
127  static void setThemeName(const QString &path);
128 
129  static QString fallbackThemeName();
130  static void setFallbackThemeName(const QString &name);
131 
132  Q_DUMMY_COMPARISON_OPERATOR(QIcon)
133 
134 private:
135  QIconPrivate *d;
136 #if !defined(QT_NO_DATASTREAM)
137  friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
138  friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
139 #endif
140 
141 public:
143  inline DataPtr &data_ptr() { return d; }
144 };
145 
147 
148 #if !defined(QT_NO_DATASTREAM)
149 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
150 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
151 #endif
152 
153 #ifndef QT_NO_DEBUG_STREAM
154 Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QIcon &);
155 #endif
156 
157 Q_GUI_EXPORT QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio,
158  qreal *sourceDevicePixelRatio = nullptr);
159 
161 
162 #endif // QICON_H
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:66
operator>>(QDataStream &ds, qfloat16 &f)
Definition: qfloat16.cpp:344
operator<<(QDataStream &ds, qfloat16 f)
Definition: qfloat16.cpp:327
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:65
The QIconEngine class provides an abstract base class for QIcon renderers.
Definition: qiconengine.h:51
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:56
QPixmap pixmap(int w, int h, Mode mode=Normal, State state=Off) const
Definition: qicon.h:80
Mode
Definition: qicon.h:58
@ Active
Definition: qicon.h:58
QIconPrivate * DataPtr
Definition: qicon.h:142
bool operator!=(const QIcon &) const =delete
QPixmap pixmap(int extent, Mode mode=Normal, State state=Off) const
Definition: qicon.h:82
DataPtr & data_ptr()
Definition: qicon.h:143
bool operator==(const QIcon &) const =delete
void paint(QPainter *painter, int x, int y, int w, int h, Qt::Alignment alignment=Qt::AlignCenter, Mode mode=Normal, State state=Off) const
Definition: qicon.h:99
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:82
The QPixmap class is an off-screen image representation that can be used as a paint device.
Definition: qpixmap.h:63
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:59
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:55
The QString class provides a Unicode character string.
Definition: qstring.h:388
The QStringList class provides a list of strings.
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:95
The QWindow class represents a window in the underlying windowing system.
Definition: qwindow.h:99
QPainter paint
rect
[4]
uint alignment
else opt state
[0]
union Alignment_ Alignment
auto it unsigned count const
Definition: hb-iter.hh:848
#define inline
Definition: md4c.c:45
@ AlignCenter
Definition: qnamespace.h:188
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
#define QT_DEPRECATED_VERSION_X_6_0(text)
Definition: qglobal.h:444
long long qint64
Definition: qglobal.h:298
#define QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(Class)
Definition: qglobal.h:556
Q_GUI_EXPORT QDataStream & operator<<(QDataStream &, const QIcon &)
Definition: qicon.cpp:1415
Q_GUI_EXPORT QDataStream & operator>>(QDataStream &, QIcon &)
Definition: qicon.cpp:1454
Q_GUI_EXPORT QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio, qreal *sourceDevicePixelRatio=nullptr)
Definition: qicon.cpp:1550
GLint GLint GLint GLint GLint x
[0]
GLenum mode
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLsizei const GLuint * paths
GLuint name
GLint y
GLfloat GLfloat GLfloat GLfloat h
GLsizei const GLchar *const * path
Definition: qopenglext.h:4283
#define Q_DECLARE_SHARED(TYPE)
Definition: qtypeinfo.h:197
QSharedPointer< T > other(t)
[5]
this swap(other)
widget render & pixmap
QPainter painter(this)
[7]
aWidget window() -> setWindowTitle("New Window Title")
[2]