1 /*
2 This file is part of Telegram Desktop,
3 the official desktop application for the Telegram messaging service.
4 
5 For license and copyright information please follow this link:
6 https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
7 */
8 #pragma once
9 
10 #include "ui/wrap/slide_wrap.h"
11 #include "ui/effects/animations.h"
12 #include "base/object_ptr.h"
13 #include "base/timer.h"
14 
15 class Painter;
16 
17 namespace Ui {
18 
19 class PlainShadow;
20 class RoundButton;
21 struct GroupCallUser;
22 class GroupCallUserpics;
23 
24 struct GroupCallBarContent {
25 	QString title;
26 	TimeId scheduleDate = 0;
27 	int count = 0;
28 	bool shown = false;
29 	bool livestream = false;
30 	std::vector<GroupCallUser> users;
31 };
32 
33 class GroupCallScheduledLeft final {
34 public:
35 	enum class Negative {
36 		Show,
37 		Ignore,
38 	};
39 	explicit GroupCallScheduledLeft(TimeId date);
40 
41 	void setDate(TimeId date);
42 
43 	[[nodiscard]] rpl::producer<QString> text(Negative negative) const;
44 	[[nodiscard]] rpl::producer<bool> late() const;
45 
46 private:
47 	[[nodiscard]] crl::time computePreciseDate() const;
48 	void restart();
49 	void update();
50 
51 	rpl::variable<QString> _text;
52 	rpl::variable<QString> _textNonNegative;
53 	rpl::variable<bool> _late;
54 	TimeId _date = 0;
55 	crl::time _datePrecise = 0;
56 	base::Timer _timer;
57 	rpl::lifetime _lifetime;
58 
59 };
60 
61 class GroupCallBar final {
62 public:
63 	GroupCallBar(
64 		not_null<QWidget*> parent,
65 		rpl::producer<GroupCallBarContent> content,
66 		rpl::producer<bool> &&hideBlobs);
67 	~GroupCallBar();
68 
69 	void show();
70 	void hide();
71 	void raise();
72 	void finishAnimating();
73 
74 	void setShadowGeometryPostprocess(Fn<QRect(QRect)> postprocess);
75 
76 	void move(int x, int y);
77 	void resizeToWidth(int width);
78 	[[nodiscard]] int height() const;
79 	[[nodiscard]] rpl::producer<int> heightValue() const;
80 	[[nodiscard]] rpl::producer<> barClicks() const;
81 	[[nodiscard]] rpl::producer<> joinClicks() const;
82 
lifetime()83 	[[nodiscard]] rpl::lifetime &lifetime() {
84 		return _wrap.lifetime();
85 	}
86 
87 private:
88 	using User = GroupCallUser;
89 
90 	void refreshOpenBrush();
91 	void refreshScheduledProcess();
92 	void updateShadowGeometry(QRect wrapGeometry);
93 	void updateControlsGeometry(QRect wrapGeometry);
94 	void updateUserpics();
95 	void setupInner();
96 	void setupRightButton(not_null<RoundButton*> button);
97 	void paint(Painter &p);
98 
99 	SlideWrap<> _wrap;
100 	not_null<RpWidget*> _inner;
101 	std::unique_ptr<RoundButton> _join;
102 	std::unique_ptr<RoundButton> _open;
103 	rpl::event_stream<Qt::MouseButton> _joinClicks;
104 	QBrush _openBrushOverride;
105 	int _openBrushForWidth = 0;
106 	std::unique_ptr<PlainShadow> _shadow;
107 	rpl::event_stream<> _barClicks;
108 	Fn<QRect(QRect)> _shadowGeometryPostprocess;
109 	bool _shouldBeShown = false;
110 	bool _forceHidden = false;
111 
112 	GroupCallBarContent _content;
113 	std::unique_ptr<GroupCallScheduledLeft> _scheduledProcess;
114 	std::unique_ptr<GroupCallUserpics> _userpics;
115 
116 };
117 
118 } // namespace Ui
119