QFDIcon.cpp 1.5 KB

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