QFDIcon.cpp 1.6 KB

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