QFDIcon.cpp 1.4 KB

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