window_connecting_widget.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 "base/timer.h"
  9. #include "base/unique_qptr.h"
  10. #include "ui/effects/animations.h"
  11. namespace Ui {
  12. class RpWidget;
  13. } // namespace Ui
  14. namespace Main {
  15. class Account;
  16. } // namespace Main
  17. namespace Window {
  18. class ConnectionState {
  19. public:
  20. ConnectionState(
  21. not_null<Ui::RpWidget*> parent,
  22. not_null<Main::Account*> account,
  23. rpl::producer<bool> shown);
  24. void raise();
  25. void setForceHidden(bool hidden);
  26. void setBottomSkip(int skip);
  27. rpl::lifetime &lifetime() {
  28. return _lifetime;
  29. }
  30. private:
  31. class Widget;
  32. struct State {
  33. enum class Type {
  34. Connected,
  35. Connecting,
  36. Waiting,
  37. };
  38. Type type = Type::Connected;
  39. bool useProxy = false;
  40. bool exposed = false;
  41. bool underCursor = false;
  42. bool updateReady = false;
  43. int waitTillRetry = 0;
  44. bool operator==(const State &other) const;
  45. };
  46. struct Layout {
  47. bool visible = false;
  48. bool hasRetry = false;
  49. bool proxyEnabled = false;
  50. bool progressShown = false;
  51. int contentWidth = 0;
  52. QString text;
  53. int textWidth = 0;
  54. };
  55. void createWidget();
  56. void finishAnimating();
  57. void refreshState();
  58. void applyState(const State &state);
  59. void changeVisibilityWithLayout(const Layout &layout);
  60. Layout computeLayout(const State &state) const;
  61. void setLayout(const Layout &layout);
  62. float64 currentVisibility() const;
  63. rpl::producer<float64> visibility() const;
  64. void updateWidth();
  65. void updateVisibility();
  66. void refreshProgressVisibility();
  67. const not_null<Main::Account*> _account;
  68. not_null<Ui::RpWidget*> _parent;
  69. rpl::variable<int> _bottomSkip;
  70. base::unique_qptr<Widget> _widget;
  71. bool _forceHidden = false;
  72. base::Timer _refreshTimer;
  73. State _state;
  74. Layout _currentLayout;
  75. crl::time _connectingStartedAt = 0;
  76. Ui::Animations::Simple _contentWidth;
  77. Ui::Animations::Simple _visibility;
  78. rpl::event_stream<float64> _visibilityValues;
  79. rpl::lifetime _lifetime;
  80. };
  81. } // namespace Window