SpinBox.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #ifndef SPINBOX_H
  2. #define SPINBOX_H
  3. #include "Common/Icon.h"
  4. #include <QToolButton>
  5. #include <QSpinBox>
  6. #include <QBoxLayout>
  7. #include <QTimeEdit>
  8. class SpinIcon : public FluentIconBase
  9. {
  10. Q_OBJECT
  11. public:
  12. enum IconType
  13. {
  14. UP = 0,
  15. DOWN
  16. };
  17. Q_ENUM(IconType)
  18. // const QString UP = "UP";
  19. // const QString DOWN = "DOWN";
  20. static QString iconName(IconType type);
  21. SpinIcon(IconType type, Qfw::Theme t = Qfw::LIGHT);
  22. ~SpinIcon();
  23. QString iconPath();
  24. // FluentIconBase interface
  25. QIcon icon() override;
  26. QString typeName() const override;
  27. QString enumName() const override;
  28. FluentIconBase *clone() override;
  29. Qfw::Theme theme() const;
  30. void setTheme(const Qfw::Theme &theme) override;
  31. private:
  32. Qfw::Theme m_theme;
  33. IconType m_type;
  34. };
  35. class SpinButton : public QToolButton
  36. {
  37. Q_OBJECT
  38. public:
  39. explicit SpinButton(FluentIconBase *icon, QWidget *parent = nullptr);
  40. // QWidget interface
  41. protected:
  42. virtual void paintEvent(QPaintEvent *event) override;
  43. private:
  44. QScopedPointer<FluentIconBase> m_icon;
  45. };
  46. class SpinBoxBase
  47. {
  48. public:
  49. SpinBoxBase() { }
  50. QHBoxLayout *hBoxLayout;
  51. SpinButton *upButton;
  52. SpinButton *downButton;
  53. protected:
  54. virtual void setUpUi(QAbstractSpinBox *spinbox);
  55. virtual void showContextMenu(QAbstractSpinBox *spinbox, const QPoint &pos);
  56. virtual void drawBorderBottom(QAbstractSpinBox *spinbox);
  57. virtual QLineEdit *lineEdit() const = 0;
  58. };
  59. class SpinBox : public QSpinBox, public SpinBoxBase
  60. {
  61. Q_OBJECT
  62. public:
  63. explicit SpinBox(QWidget *parent = nullptr);
  64. // SpinBoxBase interface
  65. protected:
  66. virtual QLineEdit *lineEdit() const override;
  67. virtual void paintEvent(QPaintEvent *event) override;
  68. signals:
  69. };
  70. class DoubleSpinBox : public QDoubleSpinBox, public SpinBoxBase
  71. {
  72. Q_OBJECT
  73. public:
  74. explicit DoubleSpinBox(QWidget *parent = nullptr);
  75. // SpinBoxBase interface
  76. protected:
  77. virtual QLineEdit *lineEdit() const override;
  78. virtual void paintEvent(QPaintEvent *event) override;
  79. signals:
  80. };
  81. class TimeEdit : public QTimeEdit, public SpinBoxBase
  82. {
  83. Q_OBJECT
  84. public:
  85. explicit TimeEdit(QWidget *parent = nullptr);
  86. // SpinBoxBase interface
  87. protected:
  88. virtual QLineEdit *lineEdit() const override;
  89. virtual void paintEvent(QPaintEvent *event) override;
  90. signals:
  91. };
  92. class DateTimeEdit : public QDateTimeEdit, public SpinBoxBase
  93. {
  94. Q_OBJECT
  95. public:
  96. explicit DateTimeEdit(QWidget *parent = nullptr);
  97. // SpinBoxBase interface
  98. protected:
  99. virtual QLineEdit *lineEdit() const override;
  100. virtual void paintEvent(QPaintEvent *event) override;
  101. signals:
  102. };
  103. class DateEdit : public QDateEdit, public SpinBoxBase
  104. {
  105. Q_OBJECT
  106. public:
  107. explicit DateEdit(QWidget *parent = nullptr);
  108. // SpinBoxBase interface
  109. protected:
  110. virtual QLineEdit *lineEdit() const override;
  111. virtual void paintEvent(QPaintEvent *event) override;
  112. signals:
  113. };
  114. #endif // SPINBOX_H