QFDIcon.cpp 1.4 KB

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