qicon.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. #ifndef QICON_H
  40. #define QICON_H
  41. #include <QtCore/qglobal.h>
  42. #include <QtCore/qsize.h>
  43. #include <QtCore/qlist.h>
  44. #include <QtGui/qpixmap.h>
  45. QT_BEGIN_NAMESPACE
  46. class QIconPrivate;
  47. class QIconEngine;
  48. class Q_GUI_EXPORT QIcon
  49. {
  50. public:
  51. enum Mode { Normal, Disabled, Active, Selected };
  52. enum State { On, Off };
  53. QIcon() Q_DECL_NOEXCEPT;
  54. QIcon(const QPixmap &pixmap);
  55. QIcon(const QIcon &other);
  56. #ifdef Q_COMPILER_RVALUE_REFS
  57. QIcon(QIcon &&other) Q_DECL_NOEXCEPT
  58. : d(other.d)
  59. { other.d = Q_NULLPTR; }
  60. #endif
  61. explicit QIcon(const QString &fileName); // file or resource name
  62. explicit QIcon(QIconEngine *engine);
  63. ~QIcon();
  64. QIcon &operator=(const QIcon &other);
  65. #ifdef Q_COMPILER_RVALUE_REFS
  66. inline QIcon &operator=(QIcon &&other) Q_DECL_NOEXCEPT
  67. { swap(other); return *this; }
  68. #endif
  69. inline void swap(QIcon &other) Q_DECL_NOEXCEPT
  70. { qSwap(d, other.d); }
  71. operator QVariant() const;
  72. QPixmap pixmap(const QSize &size, Mode mode = Normal, State state = Off) const;
  73. inline QPixmap pixmap(int w, int h, Mode mode = Normal, State state = Off) const
  74. { return pixmap(QSize(w, h), mode, state); }
  75. inline QPixmap pixmap(int extent, Mode mode = Normal, State state = Off) const
  76. { return pixmap(QSize(extent, extent), mode, state); }
  77. QPixmap pixmap(QWindow *window, const QSize &size, Mode mode = Normal, State state = Off) const;
  78. QSize actualSize(const QSize &size, Mode mode = Normal, State state = Off) const;
  79. QSize actualSize(QWindow *window, const QSize &size, Mode mode = Normal, State state = Off) const;
  80. QString name() const;
  81. void paint(QPainter *painter, const QRect &rect, Qt::Alignment alignment = Qt::AlignCenter, Mode mode = Normal, State state = Off) const;
  82. 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
  83. { paint(painter, QRect(x, y, w, h), alignment, mode, state); }
  84. bool isNull() const;
  85. bool isDetached() const;
  86. void detach();
  87. #if QT_DEPRECATED_SINCE(5, 0)
  88. QT_DEPRECATED inline int serialNumber() const { return cacheKey() >> 32; }
  89. #endif
  90. qint64 cacheKey() const;
  91. void addPixmap(const QPixmap &pixmap, Mode mode = Normal, State state = Off);
  92. void addFile(const QString &fileName, const QSize &size = QSize(), Mode mode = Normal, State state = Off);
  93. QList<QSize> availableSizes(Mode mode = Normal, State state = Off) const;
  94. void setIsMask(bool isMask);
  95. bool isMask() const;
  96. static QIcon fromTheme(const QString &name);
  97. static QIcon fromTheme(const QString &name, const QIcon &fallback);
  98. static bool hasThemeIcon(const QString &name);
  99. static QStringList themeSearchPaths();
  100. static void setThemeSearchPaths(const QStringList &searchpath);
  101. static QString themeName();
  102. static void setThemeName(const QString &path);
  103. Q_DUMMY_COMPARISON_OPERATOR(QIcon)
  104. private:
  105. QIconPrivate *d;
  106. #if !defined(QT_NO_DATASTREAM)
  107. friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
  108. friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
  109. #endif
  110. public:
  111. typedef QIconPrivate * DataPtr;
  112. inline DataPtr &data_ptr() { return d; }
  113. };
  114. Q_DECLARE_SHARED(QIcon)
  115. #if !defined(QT_NO_DATASTREAM)
  116. Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QIcon &);
  117. Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QIcon &);
  118. #endif
  119. #ifndef QT_NO_DEBUG_STREAM
  120. Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QIcon &);
  121. #endif
  122. Q_GUI_EXPORT QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio,
  123. qreal *sourceDevicePixelRatio = Q_NULLPTR);
  124. QT_END_NAMESPACE
  125. #endif // QICON_H