qtmaterialtabs_internal.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef QTMATERIALTABS_INTERNAL_H
  2. #define QTMATERIALTABS_INTERNAL_H
  3. #include "lib/qtmaterialoverlaywidget.h"
  4. #include "qtmaterialflatbutton.h"
  5. class QPropertyAnimation;
  6. class QtMaterialTabs;
  7. class QtMaterialTabsInkBar : public QtMaterialOverlayWidget
  8. {
  9. Q_OBJECT
  10. Q_PROPERTY(qreal tweenValue WRITE setTweenValue READ tweenValue)
  11. public:
  12. QtMaterialTabsInkBar(QtMaterialTabs *parent);
  13. ~QtMaterialTabsInkBar();
  14. inline void setTweenValue(qreal value);
  15. inline qreal tweenValue() const;
  16. void refreshGeometry();
  17. void animate();
  18. protected:
  19. bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
  20. void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
  21. private:
  22. Q_DISABLE_COPY(QtMaterialTabsInkBar)
  23. QtMaterialTabs *const m_tabs;
  24. QPropertyAnimation *const m_animation;
  25. QRect m_geometry;
  26. QRect m_previousGeometry;
  27. qreal m_tween;
  28. };
  29. inline void QtMaterialTabsInkBar::setTweenValue(qreal value)
  30. {
  31. m_tween = value;
  32. refreshGeometry();
  33. }
  34. inline qreal QtMaterialTabsInkBar::tweenValue() const
  35. {
  36. return m_tween;
  37. }
  38. class QtMaterialTab : public QtMaterialFlatButton
  39. {
  40. Q_OBJECT
  41. public:
  42. explicit QtMaterialTab(QtMaterialTabs *parent);
  43. ~QtMaterialTab();
  44. inline void setActive(bool state);
  45. inline bool isActive() const;
  46. QSize sizeHint() const Q_DECL_OVERRIDE;
  47. protected slots:
  48. void activateTab();
  49. protected:
  50. void paintForeground(QPainter *painter) Q_DECL_OVERRIDE;
  51. private:
  52. Q_DISABLE_COPY(QtMaterialTab)
  53. QtMaterialTabs *const m_tabs;
  54. bool m_active;
  55. };
  56. inline void QtMaterialTab::setActive(bool state)
  57. {
  58. m_active = state;
  59. update();
  60. }
  61. inline bool QtMaterialTab::isActive() const
  62. {
  63. return m_active;
  64. }
  65. #endif // QTMATERIALTABS_INTERNAL_H