SettingCard.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #ifndef SETTINGS_H
  2. #define SETTINGS_H
  3. #include <QBoxLayout>
  4. #include <QFrame>
  5. #include <QLabel>
  6. #include <QPushButton>
  7. #include "Common/Icon.h"
  8. #include "Common/Config.h"
  9. class ComboBox;
  10. class IconWidget;
  11. class SwitchButton;
  12. class Slider;
  13. class HyperlinkButton;
  14. class SettingCard : public QFrame
  15. {
  16. Q_OBJECT
  17. public:
  18. SettingCard(FluentIconBase *ficon, const QString &title, const QString &content = "", QWidget *parent = nullptr);
  19. void setTitle(const QString &title);
  20. void setContent(const QString &content);
  21. FluentIconBase *ficon() const;
  22. virtual void setValue(const QVariant &value);
  23. QHBoxLayout *hBoxLayout;
  24. QVBoxLayout *vBoxLayout;
  25. private:
  26. QScopedPointer<FluentIconBase> m_ficon;
  27. IconWidget *m_iconLabel;
  28. QLabel *m_titleLabel;
  29. QLabel *m_contentLabel;
  30. };
  31. /// Setting card with switch button
  32. class SwitchSettingCard : public SettingCard
  33. {
  34. Q_OBJECT
  35. public:
  36. SwitchSettingCard(FluentIconBase *ficon, const QString &title, const QString &content = "",
  37. Qfw::ConfigItem *configItem = nullptr, QWidget *parent = nullptr);
  38. void setValue(const QVariant &value) override;
  39. bool isChecked() const;
  40. signals:
  41. void checkedChanged(bool);
  42. private slots:
  43. void onCheckedChanged(bool isChecked);
  44. private:
  45. Qfw::ConfigItem *m_configItem;
  46. SwitchButton *m_switchButton;
  47. };
  48. class RangeSettingCard : public SettingCard
  49. {
  50. Q_OBJECT
  51. public:
  52. RangeSettingCard(int min, int max, int value, FluentIconBase *ficon, const QString &title,
  53. const QString &content = "", QWidget *parent = nullptr);
  54. void setValue(const QVariant &value) override;
  55. signals:
  56. void valueChanged(int);
  57. private slots:
  58. void onValueChanged(int value);
  59. private:
  60. int m_min;
  61. int m_max;
  62. Slider *m_slider;
  63. QLabel *m_valueLabel;
  64. };
  65. class PushSettingCard : public SettingCard
  66. {
  67. Q_OBJECT
  68. public:
  69. PushSettingCard(const QString &text, FluentIconBase *ficon, const QString &title, const QString &content = "",
  70. QWidget *parent = nullptr);
  71. QPushButton *button;
  72. signals:
  73. void clicked();
  74. };
  75. class PrimaryPushSettingCard : public PushSettingCard
  76. {
  77. Q_OBJECT
  78. public:
  79. PrimaryPushSettingCard(const QString &text, FluentIconBase *ficon, const QString &title,
  80. const QString &content = "", QWidget *parent = nullptr);
  81. };
  82. class HyperlinkCard : public SettingCard
  83. {
  84. Q_OBJECT
  85. public:
  86. HyperlinkCard(const QString &url, const QString &text, FluentIconBase *ficon, const QString &title,
  87. const QString &content = "", QWidget *parent = nullptr);
  88. HyperlinkButton *linkButton;
  89. };
  90. class ColorPickerButton : public QPushButton
  91. {
  92. Q_OBJECT
  93. public:
  94. ColorPickerButton(const QColor &color, const QString &title, QWidget *parent = nullptr);
  95. void setColor(const QColor &color);
  96. // QWidget interface
  97. protected:
  98. void paintEvent(QPaintEvent *event) override;
  99. signals:
  100. void colorChanged(const QColor &);
  101. private slots:
  102. void showColorDialog();
  103. void onColorChanged(const QColor &color);
  104. private:
  105. QString m_title;
  106. QColor m_color;
  107. };
  108. class ColorSettingCard : public SettingCard
  109. {
  110. Q_OBJECT
  111. public:
  112. explicit ColorSettingCard(const QColor &color, FluentIconBase *ficon, const QString &title,
  113. const QString &content = "", QWidget *parent = nullptr);
  114. void setValue(const QVariant &value) override;
  115. signals:
  116. void colorChanged(const QColor &);
  117. private slots:
  118. void onColorChanged(const QColor &color);
  119. private:
  120. QColor m_color;
  121. ColorPickerButton *m_colorPicker;
  122. };
  123. class ComboBoxSettingCard : public SettingCard
  124. {
  125. Q_OBJECT
  126. public:
  127. explicit ComboBoxSettingCard(const QString &defaultText, const QHash<QString, QVariant> &option,
  128. FluentIconBase *ficon, const QString &title, const QString &content = "",
  129. QWidget *parent = nullptr);
  130. void setValue(const QVariant &value) override;
  131. private slots:
  132. void onCurrentIndexChanged(int index);
  133. private:
  134. QHash<QString, QVariant> m_options;
  135. ComboBox *m_comboBox;
  136. };
  137. #endif // SETTINGS_H