iconutils.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef ICONUTILS_H
  2. #define ICONUTILS_H
  3. #include <QPixmap>
  4. #include <QVector>
  5. #include <QIcon>
  6. namespace vnotex
  7. {
  8. class IconUtils
  9. {
  10. public:
  11. IconUtils() = delete;
  12. struct OverriddenColor
  13. {
  14. OverriddenColor()
  15. : m_mode(QIcon::Normal),
  16. m_state(QIcon::Off)
  17. {
  18. }
  19. OverriddenColor(const QString &p_foreground,
  20. QIcon::Mode p_mode = QIcon::Normal,
  21. QIcon::State p_state = QIcon::Off)
  22. : m_foreground(p_foreground),
  23. m_mode(p_mode),
  24. m_state(p_state)
  25. {
  26. }
  27. QString m_foreground;
  28. QIcon::Mode m_mode;
  29. QIcon::State m_state;
  30. };
  31. static void setDefaultIconForeground(const QString &p_fg, const QString &p_disabledFg);
  32. static QIcon fetchIcon(const QString &p_iconFile,
  33. const QVector<OverriddenColor> &p_overriddenColors,
  34. qreal p_angle = -1);
  35. static QIcon fetchIcon(const QString &p_iconFile, const QString &p_overriddenForeground);
  36. // Fetch icon from @p_iconFile with icon_fg as overridden foreground color.
  37. static QIcon fetchIcon(const QString &p_iconFile);
  38. static QIcon fetchIconWithDisabledState(const QString &p_iconFile);
  39. static QIcon drawTextIcon(const QString &p_text,
  40. const QString &p_fg,
  41. const QString &p_border);
  42. private:
  43. static QString replaceForegroundOfIcon(const QString &p_iconContent, const QString &p_foreground);
  44. static QString s_defaultIconForeground;
  45. static QString s_defaultIconDisabledForeground;
  46. static bool isMonochrome(const QString &p_iconContent);
  47. };
  48. } // ns vnotex
  49. #endif // ICONUTILS_H