QFDIcon.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "QFDIcon.h"
  2. #include <QFluentWidgets.h>
  3. QString QFDIcon::iconName(QFDIcon::IconType type)
  4. {
  5. switch (type) {
  6. case Data:
  7. return "Data";
  8. case Detail:
  9. return "Detail";
  10. case Expert:
  11. return "Expert";
  12. case Logout:
  13. return "Logout";
  14. case Minus:
  15. return "Minus";
  16. case Project:
  17. return "Project";
  18. case Schecme:
  19. return "Scheme";
  20. case User:
  21. return "User";
  22. }
  23. return "Unknown";
  24. }
  25. QFDIcon::QFDIcon(IconType type, Qfw::Theme t) : FluentIconBase(""), m_theme(t), m_type(type)
  26. {
  27. iconEngine->setIconPath(iconPath());
  28. }
  29. QString QFDIcon::iconPath()
  30. {
  31. QString colorName;
  32. if (m_theme == Qfw::Theme::AUTO) {
  33. colorName = QFWIns.isDarkTheme() ? "white" : "black";
  34. } else {
  35. colorName = Qfw::ThemeString(m_theme).toLower();
  36. }
  37. return QString(":/resource/svg/%1_%2.svg").arg(iconName(m_type)).arg(colorName);
  38. }
  39. QIcon QFDIcon::icon()
  40. {
  41. return QIcon(iconEngine->clone());
  42. }
  43. QString QFDIcon::typeName() const
  44. {
  45. return iconName(m_type);
  46. }
  47. QString QFDIcon::enumName() const
  48. {
  49. QMetaEnum metaEnum = QMetaEnum::fromType<IconType>();
  50. return metaEnum.valueToKey(m_type);
  51. }
  52. FluentIconBase *QFDIcon::clone()
  53. {
  54. return new QFDIcon(m_type, m_theme);
  55. }
  56. Qfw::Theme QFDIcon::theme() const
  57. {
  58. return m_theme;
  59. }
  60. void QFDIcon::setTheme(const Qfw::Theme &theme)
  61. {
  62. m_theme = theme;
  63. iconEngine->setIconPath(iconPath());
  64. }