StyleSheet.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #ifndef STYLESHEET_H
  2. #define STYLESHEET_H
  3. #include <QHash>
  4. #include <QWidget>
  5. #include <QVariant>
  6. #include "Theme.h"
  7. /**
  8. * @brief 样式单例
  9. */
  10. class StyleSheetManager : public QObject
  11. {
  12. Q_OBJECT
  13. Q_DISABLE_COPY(StyleSheetManager);
  14. // Q_DISABLE_MOVE
  15. StyleSheetManager(StyleSheetManager &&) = delete;
  16. StyleSheetManager &operator=(StyleSheetManager &&) = delete;
  17. public:
  18. static StyleSheetManager &instance()
  19. {
  20. static StyleSheetManager ins;
  21. return ins;
  22. }
  23. void Register(const QString &file, QWidget *widget);
  24. void DeRegister(QWidget *widget);
  25. QHash<QWidget *, QString> widgets() const;
  26. private:
  27. StyleSheetManager();
  28. QHash<QWidget *, QString> m_widgets;
  29. };
  30. /// Style sheet base class
  31. class StyleSheetBase
  32. {
  33. public:
  34. virtual QString path(Qfw::Theme theme = Qfw::Theme::AUTO) = 0;
  35. virtual QString content(Qfw::Theme theme = Qfw::Theme::AUTO) { return getStyleSheet(path(theme), theme); }
  36. static QString getStyleSheet(const QString &file, Qfw::Theme theme = Qfw::Theme::AUTO);
  37. static void setStyleSheet(QWidget *widget, const QString &file, Qfw::Theme theme = Qfw::Theme::AUTO,
  38. bool reg = true);
  39. static QString applyThemeColor(const QString &qss);
  40. };
  41. class FluentStyleSheet : public StyleSheetBase
  42. {
  43. public:
  44. enum Type
  45. {
  46. MENU = 0,
  47. BUTTON,
  48. DIALOG,
  49. SLIDER,
  50. INFO_BAR,
  51. SPIN_BOX,
  52. TOOL_TIP,
  53. CHECK_BOX,
  54. COMBO_BOX,
  55. LINE_EDIT,
  56. TREE_VIEW,
  57. TIME_PICKER,
  58. SETTING_CARD,
  59. COLOR_DIALOG,
  60. SWITCH_BUTTON,
  61. MESSAGE_DIALOG,
  62. STATE_TOOL_TIP,
  63. FOLDER_LIST_DIALOG,
  64. SETTING_CARD_GROUP,
  65. EXPAND_SETTING_CARD,
  66. NAVIGATION_INTERFACE,
  67. };
  68. static QString typeName(Type t);
  69. QString path(Qfw::Theme theme) override;
  70. static QString content(const QString &name);
  71. QString operator[](Type t);
  72. static void apply(Type t, QWidget *widget);
  73. static void apply(const QString &name, QWidget *widget);
  74. };
  75. class ThemeColor
  76. {
  77. public:
  78. enum Type
  79. {
  80. PRIMARY = 0,
  81. DARK_1,
  82. DARK_2,
  83. DARK_3,
  84. LIGHT_1,
  85. LIGHT_2,
  86. LIGHT_3
  87. };
  88. ThemeColor(Type t);
  89. QString type();
  90. QString operator[](Type t);
  91. QString name() const;
  92. QColor color() const;
  93. private:
  94. Type m_type;
  95. };
  96. QColor themeColor();
  97. void setThemeColor(const QColor &color, bool save = false);
  98. #endif // STYLESHEET_H