-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Expand file tree
/
Copy pathsettings_common.h
More file actions
356 lines (302 loc) · 8.51 KB
/
Copy pathsettings_common.h
File metadata and controls
356 lines (302 loc) · 8.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "ui/text/text_variant.h"
#include "ui/rp_widget.h"
#include "ui/round_rect.h"
#include "base/object_ptr.h"
#include "base/weak_qptr.h"
#include "settings/settings_type.h"
#include <any>
namespace anim {
enum class repeat : uchar;
} // namespace anim
namespace Info {
struct SelectedItems;
enum class SelectionAction;
} // namespace Info
namespace ChatHelpers {
struct FileChosen;
} // namespace ChatHelpers
namespace SendMenu {
struct Details;
} // namespace SendMenu
namespace Main {
class Session;
} // namespace Main
namespace Ui {
class VerticalLayout;
class FlatLabel;
class InputField;
class SearchFieldController;
class SettingsButton;
class AbstractButton;
class MediaSlider;
class ToggleView;
} // namespace Ui
namespace Ui::Menu {
struct MenuCallback;
} // namespace Ui::Menu
namespace Window {
class SessionController;
} // namespace Window
namespace style {
struct FlatLabel;
struct SettingsButton;
struct MediaSlider;
} // namespace style
namespace Lottie {
struct IconDescriptor;
} // namespace Lottie
namespace Settings {
class KeyNavigation;
using Button = Ui::SettingsButton;
enum class HighlightShape {
Rect,
Ellipse,
};
struct HighlightArgs {
style::margins margin;
HighlightShape shape = HighlightShape::Rect;
int radius = 0;
const style::color *color = nullptr;
float64 opacity = 0.4;
bool below = false;
bool rippleShape = false;
bool scroll = true;
crl::time showDelay = 400;
crl::time showDuration = 600;
crl::time shownDuration = 400;
crl::time hideDuration = 600;
};
void HighlightWidget(QWidget *target, HighlightArgs &&args = {});
void ScrollToWidget(not_null<QWidget*> target);
void RevealWidget(not_null<QWidget*> target, int margin = 0);
[[nodiscard]] HighlightArgs SubsectionTitleHighlight();
struct HighlightEntry {
QPointer<QWidget> widget;
HighlightArgs args;
};
using HighlightRegistry = std::vector<std::pair<QString, HighlightEntry>>;
using SectionBuildMethod = Fn<void(
not_null<Ui::VerticalLayout*> container,
not_null<Window::SessionController*> controller,
Fn<void(Type)> showOther,
rpl::producer<> showFinished)>;
class AbstractSection : public Ui::RpWidget {
public:
AbstractSection(
QWidget *parent,
not_null<Window::SessionController*> controller);
~AbstractSection();
[[nodiscard]] not_null<Window::SessionController*> controller() const {
return _controller;
}
[[nodiscard]] virtual Type id() const = 0;
[[nodiscard]] virtual rpl::producer<Type> sectionShowOther() {
return _showOtherRequests.events();
}
[[nodiscard]] virtual rpl::producer<> sectionShowBack() {
return nullptr;
}
[[nodiscard]] virtual rpl::producer<std::vector<Type>> removeFromStack() {
return nullptr;
}
[[nodiscard]] virtual bool closeByOutsideClick() const {
return true;
}
virtual void checkBeforeClose(Fn<void()> close) {
close();
}
[[nodiscard]] virtual rpl::producer<QString> title() = 0;
virtual void sectionSaveChanges(FnMut<void()> done) {
done();
}
virtual SendMenu::Details sendMenuDetails() const;
virtual bool processChosenSticker(ChatHelpers::FileChosen &&chosen);
virtual void showFinished() {
_showFinished.fire({});
}
virtual void setInnerFocus() {
setFocus();
}
[[nodiscard]] virtual const Ui::RoundRect *bottomSkipRounding() const {
return nullptr;
}
[[nodiscard]] virtual base::weak_qptr<Ui::RpWidget> createPinnedToTop(
not_null<QWidget*> parent) {
return nullptr;
}
[[nodiscard]] virtual base::weak_qptr<Ui::RpWidget> createPinnedToBottom(
not_null<Ui::RpWidget*> parent) {
return nullptr;
}
[[nodiscard]] virtual bool hasFlexibleTopBar() const {
return false;
}
virtual void setStepDataReference(std::any &data) {
}
virtual void sectionSaveState(std::any &state) {
}
virtual void sectionRestoreState(const std::any &state) {
}
[[nodiscard]] virtual auto selectedListValue()
-> rpl::producer<Info::SelectedItems> {
return nullptr;
}
virtual void selectionAction(Info::SelectionAction action) {
}
virtual void fillTopBarMenu(
const Ui::Menu::MenuCallback &addAction) {
}
virtual bool paintOuter(
not_null<QWidget*> outer,
int maxVisibleHeight,
QRect clip) {
return false;
}
[[nodiscard]] rpl::producer<> showFinishes() const {
return _showFinished.events();
}
void showOther(Type type) {
_showOtherRequests.fire_copy(type);
}
[[nodiscard]] Fn<void(Type)> showOtherMethod() {
return crl::guard(this, [=](Type type) {
showOther(type);
});
}
void setNavigationAnchor(not_null<QWidget*> widget);
protected:
void build(
not_null<Ui::VerticalLayout*> container,
SectionBuildMethod method);
void keyPressEvent(QKeyEvent *e) override;
private:
const not_null<Window::SessionController*> _controller;
rpl::event_stream<Type> _showOtherRequests;
rpl::event_stream<> _showFinished;
std::unique_ptr<KeyNavigation> _keyNavigation;
};
enum class IconType {
Rounded,
Round,
Simple,
};
struct IconDescriptor {
const style::icon *icon = nullptr;
IconType type = IconType::Rounded;
const style::color *background = nullptr;
std::optional<QBrush> backgroundBrush; // Can be useful for gradients.
bool newBadge = false;
explicit operator bool() const {
return (icon != nullptr);
}
};
class Icon final {
public:
explicit Icon(IconDescriptor descriptor);
void paint(QPainter &p, QPoint position) const;
void paint(QPainter &p, int x, int y) const;
[[nodiscard]] int width() const;
[[nodiscard]] int height() const;
[[nodiscard]] QSize size() const;
private:
not_null<const style::icon*> _icon;
std::optional<Ui::RoundRect> _background;
std::optional<std::pair<int, QBrush>> _backgroundBrush;
};
void AddButtonIcon(
not_null<Ui::AbstractButton*> button,
const style::SettingsButton &st,
IconDescriptor &&descriptor);
object_ptr<Button> CreateButtonWithIcon(
not_null<QWidget*> parent,
rpl::producer<QString> text,
const style::SettingsButton &st,
IconDescriptor &&descriptor = {});
not_null<Button*> AddButtonWithIcon(
not_null<Ui::VerticalLayout*> container,
rpl::producer<QString> text,
const style::SettingsButton &st,
IconDescriptor &&descriptor = {});
not_null<Button*> AddButtonWithLabel(
not_null<Ui::VerticalLayout*> container,
rpl::producer<QString> text,
rpl::producer<QString> label,
const style::SettingsButton &st,
IconDescriptor &&descriptor = {});
void CreateRightLabel(
not_null<Button*> button,
v::text::data &&label,
const style::SettingsButton &st,
rpl::producer<QString> buttonText,
Ui::Text::MarkedContext context = {});
struct SeparatedToggle {
not_null<Ui::SettingsButton*> button;
not_null<Ui::ToggleView*> checkView;
};
[[nodiscard]] SeparatedToggle AddSeparatedToggle(
not_null<Button*> button,
const style::SettingsButton &st,
bool checked);
struct DividerWithLottieDescriptor {
QString lottie;
std::optional<anim::repeat> lottieRepeat;
std::optional<int> lottieSize;
std::optional<QMargins> lottieMargins;
rpl::producer<> showFinished;
rpl::producer<TextWithEntities> about;
std::optional<QMargins> aboutMargins;
RectParts parts = RectPart::Top | RectPart::Bottom;
};
void AddDividerTextWithLottie(
not_null<Ui::VerticalLayout*> container,
DividerWithLottieDescriptor &&descriptor);
struct LottieIcon {
object_ptr<Ui::RpWidget> widget;
Fn<void(anim::repeat repeat)> animate;
};
[[nodiscard]] LottieIcon CreateLottieIcon(
not_null<QWidget*> parent,
Lottie::IconDescriptor &&descriptor,
style::margins padding = {},
Fn<QColor()> colorOverride = nullptr);
struct SliderWithLabel {
object_ptr<Ui::RpWidget> widget;
not_null<Ui::MediaSlider*> slider;
not_null<Ui::FlatLabel*> label;
};
[[nodiscard]] SliderWithLabel MakeSliderWithLabel(
QWidget *parent,
const style::MediaSlider &sliderSt,
const style::FlatLabel &labelSt,
int skip,
int minLabelWidth = 0,
bool ignoreWheel = false);
void AddLottieIconWithCircle(
not_null<Ui::VerticalLayout*>,
object_ptr<Ui::RpWidget> icon,
QMargins iconPadding,
QSize circleSize);
void AddPremiumStar(
not_null<Button*> button,
bool credits,
Fn<bool()> isPaused);
struct SectionSearchRow {
std::unique_ptr<Ui::SearchFieldController> controller;
not_null<Ui::RpWidget*> row;
not_null<Ui::InputField*> field;
};
[[nodiscard]] SectionSearchRow CreateSectionSearchRow(
not_null<QWidget*> parent,
const QString &query = QString());
[[nodiscard]] QStringList SearchWords(const QString &text);
[[nodiscard]] bool MatchesWords(
const QStringList &terms,
const QStringList &words);
} // namespace Settings