QFDIcon.cpp 1.3 KB

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