tabbed_panel.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "ui/effects/animations.h"
  9. #include "ui/rp_widget.h"
  10. #include "base/timer.h"
  11. #include "base/object_ptr.h"
  12. namespace Window {
  13. class SessionController;
  14. } // namespace Window
  15. namespace Ui {
  16. class PanelAnimation;
  17. } // namespace Ui
  18. namespace ChatHelpers {
  19. class TabbedSelector;
  20. extern const char kOptionTabbedPanelShowOnClick[];
  21. [[nodiscard]] bool ShowPanelOnClick();
  22. struct TabbedPanelDescriptor {
  23. Window::SessionController *regularWindow = nullptr;
  24. object_ptr<TabbedSelector> ownedSelector = { nullptr };
  25. TabbedSelector *nonOwnedSelector = nullptr;
  26. };
  27. class TabbedPanel : public Ui::RpWidget {
  28. public:
  29. TabbedPanel(
  30. QWidget *parent,
  31. not_null<Window::SessionController*> controller,
  32. not_null<TabbedSelector*> selector);
  33. TabbedPanel(
  34. QWidget *parent,
  35. not_null<Window::SessionController*> controller,
  36. object_ptr<TabbedSelector> selector);
  37. TabbedPanel(QWidget *parent, TabbedPanelDescriptor &&descriptor);
  38. [[nodiscard]] bool isSelectorStolen() const;
  39. [[nodiscard]] not_null<TabbedSelector*> selector() const;
  40. [[nodiscard]] rpl::producer<bool> pauseAnimations() const;
  41. void moveBottomRight(int bottom, int right);
  42. void moveTopRight(int top, int right);
  43. void setDesiredHeightValues(
  44. float64 ratio,
  45. int minHeight,
  46. int maxHeight);
  47. void setDropDown(bool dropDown);
  48. void hideFast();
  49. bool hiding() const {
  50. return _hiding || _hideTimer.isActive();
  51. }
  52. bool overlaps(const QRect &globalRect) const;
  53. void showAnimated();
  54. void hideAnimated();
  55. void toggleAnimated();
  56. ~TabbedPanel();
  57. protected:
  58. void enterEventHook(QEnterEvent *e) override;
  59. void leaveEventHook(QEvent *e) override;
  60. void otherEnter();
  61. void otherLeave();
  62. void paintEvent(QPaintEvent *e) override;
  63. bool eventFilter(QObject *obj, QEvent *e) override;
  64. private:
  65. void hideByTimerOrLeave();
  66. void moveHorizontally();
  67. void showFromSelector();
  68. style::margins innerPadding() const;
  69. // Rounded rect which has shadow around it.
  70. QRect innerRect() const;
  71. QImage grabForAnimation();
  72. void startShowAnimation();
  73. void startOpacityAnimation(bool hiding);
  74. void prepareCacheFor(bool hiding);
  75. void opacityAnimationCallback();
  76. void hideFinished();
  77. void showStarted();
  78. bool preventAutoHide() const;
  79. void updateContentHeight();
  80. Window::SessionController * const _regularWindow = nullptr;
  81. const object_ptr<TabbedSelector> _ownedSelector = { nullptr };
  82. const not_null<TabbedSelector*> _selector;
  83. rpl::event_stream<bool> _pauseAnimations;
  84. int _contentMaxHeight = 0;
  85. int _contentHeight = 0;
  86. int _top = 0;
  87. int _bottom = 0;
  88. int _right = 0;
  89. float64 _heightRatio = 1.;
  90. int _minContentHeight = 0;
  91. int _maxContentHeight = 0;
  92. std::unique_ptr<Ui::PanelAnimation> _showAnimation;
  93. Ui::Animations::Simple _a_show;
  94. bool _shouldFinishHide = false;
  95. bool _dropDown = false;
  96. bool _hiding = false;
  97. bool _hideAfterSlide = false;
  98. QPixmap _cache;
  99. Ui::Animations::Simple _a_opacity;
  100. base::Timer _hideTimer;
  101. };
  102. } // namespace ChatHelpers