Icon.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. #ifndef ICON_H
  2. #define ICON_H
  3. #include <QIconEngine>
  4. #include "StyleSheet.h"
  5. QString getIconColor();
  6. class IconEngine : public QIconEngine
  7. {
  8. public:
  9. IconEngine(const QString &path);
  10. void setIndexes(const QVector<int> &indexes);
  11. void setAttributes(const QHash<QString, QString> &attributes);
  12. void setIconPath(const QString &iconPath);
  13. QString iconPath() const;
  14. void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) override;
  15. QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override;
  16. QIconEngine *clone() const override;
  17. private:
  18. QString m_iconPath;
  19. QVector<int> m_indexes;
  20. QHash<QString, QString> m_attributes;
  21. bool m_isSvg;
  22. };
  23. class MenuIconEngine : public QIconEngine
  24. {
  25. public:
  26. MenuIconEngine(const QIcon &icon);
  27. QIcon m_icon;
  28. // QIconEngine interface
  29. public:
  30. void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) override;
  31. QIconEngine *clone() const override;
  32. };
  33. class FluentIconBase : public QObject
  34. {
  35. Q_OBJECT
  36. public:
  37. explicit FluentIconBase(const QString &path);
  38. virtual ~FluentIconBase();
  39. virtual QIcon icon() = 0;
  40. virtual QString typeName() const = 0;
  41. virtual QString enumName() const = 0;
  42. virtual FluentIconBase *clone() = 0;
  43. virtual void setTheme(const Qfw::Theme &theme) = 0;
  44. virtual void render(QPainter *painter, const QRect &rect, const QVector<int> &indexes = QVector<int>(),
  45. const QHash<QString, QString> &attributes = QHash<QString, QString>());
  46. QScopedPointer<IconEngine> iconEngine;
  47. };
  48. class FluentIcon : public FluentIconBase
  49. {
  50. Q_OBJECT
  51. public:
  52. enum IconType
  53. {
  54. UNKNOWN = -1,
  55. ADD = 0,
  56. CUT,
  57. PIN,
  58. TAG,
  59. CHAT,
  60. COPY,
  61. CODE,
  62. EDIT,
  63. FONT,
  64. HELP,
  65. HIDE,
  66. HOME,
  67. INFO,
  68. LINK,
  69. MAIL,
  70. MENU,
  71. MORE,
  72. SAVE,
  73. SEND,
  74. SYNC,
  75. VIEW,
  76. ZOOM,
  77. ALBUM,
  78. BRUSH,
  79. CLOSE,
  80. EMBED,
  81. GLOBE,
  82. HEART,
  83. MEDIA,
  84. MOVIE,
  85. MUSIC,
  86. PASTE,
  87. PHOTO,
  88. PHONE,
  89. PRINT,
  90. SHARE,
  91. UNPIN,
  92. VIDEO,
  93. ACCEPT,
  94. CAMERA,
  95. CANCEL,
  96. DELETE,
  97. FOLDER,
  98. SCROLL,
  99. LAYOUT,
  100. GITHUB,
  101. UPDATE,
  102. RETURN,
  103. RINGER,
  104. SEARCH,
  105. SAVE_AS,
  106. ZOOM_IN,
  107. HISTORY,
  108. SETTING,
  109. PALETTE,
  110. MESSAGE,
  111. ZOOM_OUT,
  112. FEEDBACK,
  113. MINIMIZE,
  114. CHECKBOX,
  115. DOCUMENT,
  116. LANGUAGE,
  117. DOWNLOAD,
  118. QUESTION,
  119. DATE_TIME,
  120. SEND_FILL,
  121. COMPLETED,
  122. CONSTRACT,
  123. ALIGNMENT,
  124. BOOK_SHELF,
  125. HIGHTLIGHT,
  126. FOLDER_ADD,
  127. PENCIL_INK,
  128. ZIP_FOLDER,
  129. MICROPHONE,
  130. ARROW_DOWN,
  131. TRANSPARENT,
  132. MUSIC_FOLDER,
  133. CHEVRON_RIGHT,
  134. BACKGROUND_FILL
  135. };
  136. Q_ENUM(IconType)
  137. static QString iconName(IconType type);
  138. FluentIcon(const QString &customPath);
  139. FluentIcon(IconType type, Qfw::Theme t = Qfw::Theme::AUTO);
  140. ~FluentIcon();
  141. QString iconPath();
  142. // FluentIconBase interface
  143. QIcon icon() override;
  144. QString typeName() const override;
  145. QString enumName() const override;
  146. FluentIconBase *clone() override;
  147. Qfw::Theme theme() const;
  148. void setTheme(const Qfw::Theme &theme) override;
  149. private:
  150. Qfw::Theme m_theme;
  151. IconType m_type;
  152. };
  153. #define NEWFLICON(cls, type) (new cls(cls::type))
  154. #endif // ICON_H