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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
|
diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings
index 23642665f..dafcb82de 100644
--- a/Telegram/Resources/langs/lang.strings
+++ b/Telegram/Resources/langs/lang.strings
@@ -2263,6 +2263,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"ktg_settings_kotato" = "Kotatogram Settings";
"ktg_settings_chats" = "Chats";
"ktg_settings_sticker_height" = "Sticker height: {pixels}px";
+"ktg_settings_adaptive_baloons" = "Adaptive baloons";
"ktg_settings_emoji_outline" = "Big emoji outline";
"ktg_settings_always_show_scheduled" = "Always show scheduled";
"ktg_settings_fonts" = "Change application fonts";
diff --git a/Telegram/Resources/langs/rewrites/ru.json b/Telegram/Resources/langs/rewrites/ru.json
index 8cda92b17..cb1cf53c1 100644
--- a/Telegram/Resources/langs/rewrites/ru.json
+++ b/Telegram/Resources/langs/rewrites/ru.json
@@ -30,6 +30,7 @@
"ktg_settings_kotato": "Настройки Kotatogram",
"ktg_settings_chats": "Чаты",
"ktg_settings_sticker_height": "Высота стикеров: {pixels} пикс.",
+ "ktg_settings_adaptive_baloons": "Адаптивные пузырьки сообщений",
"ktg_settings_emoji_outline": "Обводка у больших эмодзи",
"ktg_settings_always_show_scheduled": "Всегда показывать отложенные",
"ktg_settings_fonts": "Изменить шрифты приложения",
diff --git a/Telegram/SourceFiles/core/kotato_settings.cpp b/Telegram/SourceFiles/core/kotato_settings.cpp
index 4c549b6ff..abcd34807 100644
--- a/Telegram/SourceFiles/core/kotato_settings.cpp
+++ b/Telegram/SourceFiles/core/kotato_settings.cpp
@@ -152,6 +152,11 @@ bool Manager::readCustomFile() {
}
}
+ const auto settingsAdaptiveBaloonsIt = settings.constFind(qsl("adaptive_baloons"));
+ if (settingsAdaptiveBaloonsIt != settings.constEnd() && (*settingsAdaptiveBaloonsIt).isBool()) {
+ cSetAdaptiveBaloons((*settingsAdaptiveBaloonsIt).toBool());
+ }
+
const auto settingsBigEmojiOutlineIt = settings.constFind(qsl("big_emoji_outline"));
if (settingsBigEmojiOutlineIt != settings.constEnd() && (*settingsBigEmojiOutlineIt).isBool()) {
SetBigEmojiOutline((*settingsBigEmojiOutlineIt).toBool());
@@ -235,6 +240,7 @@ void Manager::writeDefaultFile() {
settings.insert(qsl("fonts"), settingsFonts);
settings.insert(qsl("sticker_height"), StickerHeight());
+ settings.insert(qsl("adaptive_baloons"), cAdaptiveBaloons());
settings.insert(qsl("big_emoji_outline"), BigEmojiOutline());
settings.insert(qsl("always_show_scheduled"), cAlwaysShowScheduled());
settings.insert(qsl("show_chat_id"), cShowChatId());
@@ -286,6 +292,7 @@ void Manager::writeCurrentSettings() {
settings.insert(qsl("fonts"), settingsFonts);
settings.insert(qsl("sticker_height"), StickerHeight());
+ settings.insert(qsl("adaptive_baloons"), cAdaptiveBaloons());
settings.insert(qsl("big_emoji_outline"), BigEmojiOutline());
settings.insert(qsl("always_show_scheduled"), cAlwaysShowScheduled());
settings.insert(qsl("show_chat_id"), cShowChatId());
diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp
index dc4812a5f..05aa548b6 100644
--- a/Telegram/SourceFiles/history/history_inner_widget.cpp
+++ b/Telegram/SourceFiles/history/history_inner_widget.cpp
@@ -2038,7 +2038,7 @@ void HistoryInner::recountHistoryGeometry() {
updateBotInfo(false);
if (_botAbout && !_botAbout->info->text.isEmpty()) {
int32 tw = _scroll->width() - st::msgMargin.left() - st::msgMargin.right();
- if (tw > st::msgMaxWidth) tw = st::msgMaxWidth;
+ if (!cAdaptiveBaloons() && tw > st::msgMaxWidth) tw = st::msgMaxWidth;
tw -= st::msgPadding.left() + st::msgPadding.right();
int32 mw = qMax(_botAbout->info->text.maxWidth(), st::msgNameFont->width(tr::lng_bot_description(tr::now)));
if (tw > mw) tw = mw;
@@ -2048,7 +2048,7 @@ void HistoryInner::recountHistoryGeometry() {
int32 descH = st::msgMargin.top() + st::msgPadding.top() + st::msgNameFont->height + st::botDescSkip + _botAbout->height + st::msgPadding.bottom() + st::msgMargin.bottom();
int32 descMaxWidth = _scroll->width();
- if (Adaptive::ChatWide()) {
+ if (Adaptive::ChatWide() && !cAdaptiveBaloons()) {
descMaxWidth = qMin(descMaxWidth, int32(st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left()));
}
int32 descAtX = (descMaxWidth - _botAbout->width) / 2 - st::msgPadding.left();
@@ -2085,7 +2085,7 @@ void HistoryInner::updateBotInfo(bool recount) {
Ui::ItemTextBotNoMonoOptions());
if (recount) {
int32 tw = _scroll->width() - st::msgMargin.left() - st::msgMargin.right();
- if (tw > st::msgMaxWidth) tw = st::msgMaxWidth;
+ if (!cAdaptiveBaloons() && tw > st::msgMaxWidth) tw = st::msgMaxWidth;
tw -= st::msgPadding.left() + st::msgPadding.right();
int32 mw = qMax(_botAbout->info->text.maxWidth(), st::msgNameFont->width(tr::lng_bot_description(tr::now)));
if (tw > mw) tw = mw;
@@ -2240,7 +2240,7 @@ void HistoryInner::updateSize() {
if (_botAbout && _botAbout->height > 0) {
int32 descH = st::msgMargin.top() + st::msgPadding.top() + st::msgNameFont->height + st::botDescSkip + _botAbout->height + st::msgPadding.bottom() + st::msgMargin.bottom();
int32 descMaxWidth = _scroll->width();
- if (Adaptive::ChatWide()) {
+ if (Adaptive::ChatWide() && !cAdaptiveBaloons()) {
descMaxWidth = qMin(descMaxWidth, int32(st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left()));
}
int32 descAtX = (descMaxWidth - _botAbout->width) / 2 - st::msgPadding.left();
@@ -2566,7 +2566,7 @@ void HistoryInner::mouseActionUpdate() {
dateWidth += st::msgServicePadding.left() + st::msgServicePadding.right();
auto dateLeft = st::msgServiceMargin.left();
auto maxwidth = _contentWidth;
- if (Adaptive::ChatWide()) {
+ if (Adaptive::ChatWide() && !cAdaptiveBaloons()) {
maxwidth = qMin(maxwidth, int32(st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left()));
}
auto widthForDate = maxwidth - st::msgServiceMargin.left() - st::msgServiceMargin.left();
diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp
index 3c42a9768..e09f5ac17 100644
--- a/Telegram/SourceFiles/history/view/history_view_element.cpp
+++ b/Telegram/SourceFiles/history/view/history_view_element.cpp
@@ -161,7 +161,7 @@ void UnreadBar::paint(Painter &p, int y, int w) const {
int left = st::msgServiceMargin.left();
int maxwidth = w;
- if (Adaptive::ChatWide()) {
+ if (Adaptive::ChatWide() && !cAdaptiveBaloons()) {
maxwidth = qMin(
maxwidth,
st::msgMaxWidth
@@ -315,6 +315,10 @@ int Element::infoWidth() const {
return 0;
}
+int Element::plainMaxWidth() const {
+ return 0;
+}
+
bool Element::isHiddenByGroup() const {
return _flags & Flag::HiddenByGroup;
}
diff --git a/Telegram/SourceFiles/history/view/history_view_element.h b/Telegram/SourceFiles/history/view/history_view_element.h
index 6d58d5604..6c89c7cde 100644
--- a/Telegram/SourceFiles/history/view/history_view_element.h
+++ b/Telegram/SourceFiles/history/view/history_view_element.h
@@ -170,6 +170,7 @@ public:
int skipBlockHeight() const;
QString skipBlock() const;
virtual int infoWidth() const;
+ virtual int plainMaxWidth() const;
bool isHiddenByGroup() const;
virtual bool isHidden() const;
diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp
index 38745d248..4006f3162 100644
--- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp
+++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp
@@ -2151,7 +2151,7 @@ void ListWidget::mouseActionUpdate() {
dateWidth += st::msgServicePadding.left() + st::msgServicePadding.right();
auto dateLeft = st::msgServiceMargin.left();
auto maxwidth = view->width();
- if (Adaptive::ChatWide()) {
+ if (Adaptive::ChatWide() && !cAdaptiveBaloons()) {
maxwidth = qMin(maxwidth, int32(st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left()));
}
auto widthForDate = maxwidth - st::msgServiceMargin.left() - st::msgServiceMargin.left();
diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp
index 8365366d9..912f87f96 100644
--- a/Telegram/SourceFiles/history/view/history_view_message.cpp
+++ b/Telegram/SourceFiles/history/view/history_view_message.cpp
@@ -1616,7 +1616,9 @@ QRect Message::countGeometry() const {
// contentLeft += st::msgPhotoSkip - (hmaxwidth - hwidth);
}
accumulate_min(contentWidth, maxWidth());
- accumulate_min(contentWidth, st::msgMaxWidth);
+ if (!cAdaptiveBaloons()) {
+ accumulate_min(contentWidth, st::msgMaxWidth);
+ }
if (mediaWidth < contentWidth) {
const auto textualWidth = plainMaxWidth();
if (mediaWidth < textualWidth
@@ -1658,7 +1660,9 @@ int Message::resizeContentGetHeight(int newWidth) {
contentWidth -= st::msgPhotoSkip;
}
accumulate_min(contentWidth, maxWidth());
- accumulate_min(contentWidth, st::msgMaxWidth);
+ if (!cAdaptiveBaloons()) {
+ accumulate_min(contentWidth, st::msgMaxWidth);
+ }
if (mediaDisplayed) {
media->resizeGetHeight(contentWidth);
if (media->width() < contentWidth) {
@@ -1681,7 +1685,7 @@ int Message::resizeContentGetHeight(int newWidth) {
auto mediaOnBottom = (mediaDisplayed && media->isBubbleBottom()) || (entry/* && entry->isBubbleBottom()*/);
auto mediaOnTop = (mediaDisplayed && media->isBubbleTop()) || (entry && entry->isBubbleTop());
- if (contentWidth == maxWidth()) {
+ if (!cAdaptiveBaloons() && contentWidth == maxWidth()) {
if (mediaDisplayed) {
if (entry) {
newHeight += entry->resizeGetHeight(contentWidth);
diff --git a/Telegram/SourceFiles/history/view/history_view_message.h b/Telegram/SourceFiles/history/view/history_view_message.h
index 149b7db30..05479137e 100644
--- a/Telegram/SourceFiles/history/view/history_view_message.h
+++ b/Telegram/SourceFiles/history/view/history_view_message.h
@@ -85,6 +85,7 @@ public:
bool displayEditedBadge() const override;
TimeId displayedEditDate() const override;
int infoWidth() const override;
+ int plainMaxWidth() const override;
protected:
void refreshDataIdHook() override;
@@ -146,7 +147,6 @@ private:
HistoryMessageEdited *displayedEditBadge();
void initTime();
int timeLeft() const;
- int plainMaxWidth() const;
WebPage *logEntryOriginal() const;
diff --git a/Telegram/SourceFiles/history/view/history_view_service_message.cpp b/Telegram/SourceFiles/history/view/history_view_service_message.cpp
index 3264fe1b9..65b1fda10 100644
--- a/Telegram/SourceFiles/history/view/history_view_service_message.cpp
+++ b/Telegram/SourceFiles/history/view/history_view_service_message.cpp
@@ -164,7 +164,7 @@ void paintBubblePart(Painter &p, int x, int y, int width, int height, SideStyle
void paintPreparedDate(Painter &p, const QString &dateText, int dateTextWidth, int y, int w) {
int left = st::msgServiceMargin.left();
int maxwidth = w;
- if (Adaptive::ChatWide()) {
+ if (Adaptive::ChatWide() && !cAdaptiveBaloons()) {
maxwidth = qMin(maxwidth, WideChatWidth());
}
w = maxwidth - st::msgServiceMargin.left() - st::msgServiceMargin.left();
@@ -315,7 +315,7 @@ not_null<HistoryService*> Service::message() const {
QRect Service::countGeometry() const {
auto result = QRect(0, 0, width(), height());
- if (Adaptive::ChatWide()) {
+ if (Adaptive::ChatWide() && !cAdaptiveBaloons()) {
result.setWidth(qMin(result.width(), st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left()));
}
return result.marginsRemoved(st::msgServiceMargin);
@@ -338,7 +338,7 @@ QSize Service::performCountCurrentSize(int newWidth) {
item->_textHeight = 0;
} else {
auto contentWidth = newWidth;
- if (Adaptive::ChatWide()) {
+ if (Adaptive::ChatWide() && !cAdaptiveBaloons()) {
accumulate_min(contentWidth, st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left());
}
contentWidth -= st::msgServiceMargin.left() + st::msgServiceMargin.left(); // two small margins
diff --git a/Telegram/SourceFiles/history/view/media/history_view_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_document.cpp
index 9343d66c8..b0a71b05d 100644
--- a/Telegram/SourceFiles/history/view/media/history_view_document.cpp
+++ b/Telegram/SourceFiles/history/view/media/history_view_document.cpp
@@ -150,7 +150,11 @@ QSize Document::countOptimalSize() {
if (auto named = Get<HistoryDocumentNamed>()) {
accumulate_max(maxWidth, tleft + named->_namew + tright);
- accumulate_min(maxWidth, st::msgMaxWidth);
+ if (cAdaptiveBaloons() && captioned) {
+ accumulate_max(maxWidth, captioned->_caption.maxWidth() + st::msgPadding.left() + st::msgPadding.right());
+ } else {
+ accumulate_min(maxWidth, st::msgMaxWidth);
+ }
}
auto minHeight = 0;
diff --git a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp
index f772eebfe..ac60117be 100644
--- a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp
+++ b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp
@@ -74,15 +74,21 @@ QSize Gif::countOptimalSize() {
setClipReader(::Media::Clip::ReaderPointer::Bad());
}
+ const auto captionWithPaddings = _caption.maxWidth()
+ + st::msgPadding.left()
+ + st::msgPadding.right();
const auto maxSize = _data->isVideoMessage()
? st::maxVideoMessageSize
: st::maxGifSize;
const auto size = style::ConvertScale(videoSize());
auto tw = size.width();
auto th = size.height();
- if (tw > maxSize) {
+ if ((!cAdaptiveBaloons() || captionWithPaddings <= maxSize) && tw > maxSize) {
th = (maxSize * th) / tw;
tw = maxSize;
+ } else if (cAdaptiveBaloons() && captionWithPaddings > maxSize && tw > captionWithPaddings) {
+ th = (captionWithPaddings * th) / tw;
+ tw = captionWithPaddings;
}
if (th > maxSize) {
tw = (maxSize * tw) / th;
@@ -101,6 +107,9 @@ QSize Gif::countOptimalSize() {
}
if (_parent->hasBubble()) {
if (!_caption.isEmpty()) {
+ if (cAdaptiveBaloons()) {
+ accumulate_max(maxWidth, captionWithPaddings);
+ }
auto captionw = maxWidth - st::msgPadding.left() - st::msgPadding.right();
minHeight += st::mediaCaptionSkip + _caption.countHeight(captionw);
if (isBubbleBottom()) {
@@ -123,15 +132,21 @@ QSize Gif::countOptimalSize() {
QSize Gif::countCurrentSize(int newWidth) {
auto availableWidth = newWidth;
+ const auto captionWithPaddings = _caption.maxWidth()
+ + st::msgPadding.left()
+ + st::msgPadding.right();
const auto maxSize = _data->isVideoMessage()
? st::maxVideoMessageSize
: st::maxGifSize;
const auto size = style::ConvertScale(videoSize());
auto tw = size.width();
auto th = size.height();
- if (tw > maxSize) {
+ if ((!cAdaptiveBaloons() || captionWithPaddings <= maxSize) && tw > maxSize) {
th = (maxSize * th) / tw;
tw = maxSize;
+ } else if (cAdaptiveBaloons() && captionWithPaddings > maxSize && tw > captionWithPaddings) {
+ th = (captionWithPaddings * th) / tw;
+ tw = captionWithPaddings;
}
if (th > maxSize) {
tw = (maxSize * tw) / th;
@@ -183,6 +198,10 @@ QSize Gif::countCurrentSize(int newWidth) {
}
if (_parent->hasBubble()) {
if (!_caption.isEmpty()) {
+ if (cAdaptiveBaloons()) {
+ accumulate_max(newWidth, captionWithPaddings);
+ accumulate_min(newWidth, availableWidth);
+ }
auto captionw = newWidth - st::msgPadding.left() - st::msgPadding.right();
newHeight += st::mediaCaptionSkip + _caption.countHeight(captionw);
if (isBubbleBottom()) {
diff --git a/Telegram/SourceFiles/history/view/media/history_view_location.cpp b/Telegram/SourceFiles/history/view/media/history_view_location.cpp
index 36d7c7c11..717a1c223 100644
--- a/Telegram/SourceFiles/history/view/media/history_view_location.cpp
+++ b/Telegram/SourceFiles/history/view/media/history_view_location.cpp
@@ -61,9 +61,15 @@ QSize Location::countOptimalSize() {
if (_parent->hasBubble()) {
if (!_title.isEmpty()) {
+ if (cAdaptiveBaloons()) {
+ maxWidth = qMax(maxWidth, _title.maxWidth() + st::msgPadding.left() + st::msgPadding.right());
+ }
minHeight += qMin(_title.countHeight(maxWidth - st::msgPadding.left() - st::msgPadding.right()), 2 * st::webPageTitleFont->height);
}
if (!_description.isEmpty()) {
+ if (cAdaptiveBaloons()) {
+ maxWidth = qMax(maxWidth, _description.maxWidth() + st::msgPadding.left() + st::msgPadding.right());
+ }
minHeight += qMin(_description.countHeight(maxWidth - st::msgPadding.left() - st::msgPadding.right()), 3 * st::webPageDescriptionFont->height);
}
if (!_title.isEmpty() || !_description.isEmpty()) {
@@ -88,8 +94,10 @@ QSize Location::countCurrentSize(int newWidth) {
auto newHeight = th;
if (tw > newWidth) {
newHeight = (newWidth * newHeight / tw);
- } else {
+ } else if (!cAdaptiveBaloons()) {
newWidth = tw;
+ } else {
+ newHeight = (newWidth * newHeight / tw);
}
auto minWidth = qMax(st::minPhotoSize, _parent->infoWidth() + 2 * (st::msgDateImgDelta + st::msgDateImgPadding.x()));
accumulate_max(newWidth, minWidth);
diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp b/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp
index cccc8ea96..97c08e380 100644
--- a/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp
+++ b/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp
@@ -76,9 +76,17 @@ QSize GroupedMedia::countOptimalSize() {
sizes.push_back(media->sizeForGrouping());
}
+ const auto captionWithPaddings = _caption.maxWidth()
+ + st::msgPadding.left()
+ + st::msgPadding.right();
+ auto groupMaxWidth = st::historyGroupWidthMax;
+ if (cAdaptiveBaloons()) {
+ accumulate_max(groupMaxWidth, captionWithPaddings);
+ }
+
const auto layout = Ui::LayoutMediaGroup(
sizes,
- st::historyGroupWidthMax,
+ groupMaxWidth,
st::historyGroupWidthMin,
st::historyGroupSkip);
Assert(layout.size() == _parts.size());
@@ -94,6 +102,9 @@ QSize GroupedMedia::countOptimalSize() {
}
if (!_caption.isEmpty()) {
+ if (cAdaptiveBaloons()) {
+ maxWidth = qMax(maxWidth, captionWithPaddings);
+ }
auto captionw = maxWidth - st::msgPadding.left() - st::msgPadding.right();
minHeight += st::mediaCaptionSkip + _caption.countHeight(captionw);
if (isBubbleBottom()) {
diff --git a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp
index 8a527da80..01d6c47e2 100644
--- a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp
+++ b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp
@@ -71,14 +71,21 @@ QSize Photo::countOptimalSize() {
auto maxWidth = 0;
auto minHeight = 0;
+ const auto captionWithPaddings = _caption.maxWidth()
+ + st::msgPadding.left()
+ + st::msgPadding.right();
+ auto inWebPage = (_parent->media() != this);
auto tw = style::ConvertScale(_data->width());
auto th = style::ConvertScale(_data->height());
if (!tw || !th) {
tw = th = 1;
}
- if (tw > st::maxMediaSize) {
+ if ((!cAdaptiveBaloons() || (captionWithPaddings <= st::maxMediaSize && !inWebPage)) && tw > st::maxMediaSize) {
th = (st::maxMediaSize * th) / tw;
tw = st::maxMediaSize;
+ } else if (cAdaptiveBaloons() && captionWithPaddings > st::maxMediaSize && tw > captionWithPaddings) {
+ th = (captionWithPaddings * th) / tw;
+ tw = captionWithPaddings;
}
if (th > st::maxMediaSize) {
tw = (st::maxMediaSize * tw) / th;
@@ -89,10 +96,14 @@ QSize Photo::countOptimalSize() {
return { _serviceWidth, _serviceWidth };
}
const auto minWidth = qMax((_parent->hasBubble() ? st::historyPhotoBubbleMinWidth : st::minPhotoSize), _parent->infoWidth() + 2 * (st::msgDateImgDelta + st::msgDateImgPadding.x()));
- const auto maxActualWidth = qMax(tw, minWidth);
+ auto maxActualWidth = qMax(tw, minWidth);
maxWidth = qMax(maxActualWidth, th);
minHeight = qMax(th, st::minPhotoSize);
if (_parent->hasBubble() && !_caption.isEmpty()) {
+ if (cAdaptiveBaloons()) {
+ maxActualWidth = qMax(maxActualWidth, captionWithPaddings);
+ maxWidth = qMax(maxWidth, captionWithPaddings);
+ }
auto captionw = maxActualWidth - st::msgPadding.left() - st::msgPadding.right();
minHeight += st::mediaCaptionSkip + _caption.countHeight(captionw);
if (isBubbleBottom()) {
@@ -103,11 +114,20 @@ QSize Photo::countOptimalSize() {
}
QSize Photo::countCurrentSize(int newWidth) {
+ auto availableWidth = newWidth;
+
+ const auto captionWithPaddings = _caption.maxWidth()
+ + st::msgPadding.left()
+ + st::msgPadding.right();
+ auto inWebPage = (_parent->media() != this);
auto tw = style::ConvertScale(_data->width());
auto th = style::ConvertScale(_data->height());
- if (tw > st::maxMediaSize) {
+ if ((!cAdaptiveBaloons() || (captionWithPaddings <= st::maxMediaSize && !inWebPage)) && tw > st::maxMediaSize) {
th = (st::maxMediaSize * th) / tw;
tw = st::maxMediaSize;
+ } else if (cAdaptiveBaloons() && captionWithPaddings > st::maxMediaSize && tw > captionWithPaddings) {
+ th = (captionWithPaddings * th) / tw;
+ tw = captionWithPaddings;
}
if (th > st::maxMediaSize) {
tw = (st::maxMediaSize * tw) / th;
@@ -132,6 +152,10 @@ QSize Photo::countCurrentSize(int newWidth) {
newWidth = qMax(_pixw, minWidth);
auto newHeight = qMax(_pixh, st::minPhotoSize);
if (_parent->hasBubble() && !_caption.isEmpty()) {
+ if (cAdaptiveBaloons()) {
+ newWidth = qMax(newWidth, captionWithPaddings);
+ newWidth = qMin(newWidth, availableWidth);
+ }
const auto captionw = newWidth
- st::msgPadding.left()
- st::msgPadding.right();
diff --git a/Telegram/SourceFiles/history/view/media/history_view_video.cpp b/Telegram/SourceFiles/history/view/media/history_view_video.cpp
index f8a6f3552..bcae354fc 100644
--- a/Telegram/SourceFiles/history/view/media/history_view_video.cpp
+++ b/Telegram/SourceFiles/history/view/media/history_view_video.cpp
@@ -58,15 +58,22 @@ QSize Video::sizeForAspectRatio() const {
}
QSize Video::countOptimalDimensions() const {
+ const auto captionWithPaddings = _caption.maxWidth()
+ + st::msgPadding.left()
+ + st::msgPadding.right();
+ auto inWebPage = (_parent->media() != this);
const auto desired = style::ConvertScale(_data->dimensions);
const auto size = desired.isEmpty() ? sizeForAspectRatio() : desired;
auto tw = size.width();
auto th = size.height();
if (!tw || !th) {
tw = th = 1;
- } else if (tw >= th && tw > st::maxMediaSize) {
+ } else if ((!cAdaptiveBaloons() || (captionWithPaddings <= st::maxMediaSize && !inWebPage)) && tw >= th && tw > st::maxMediaSize) {
th = qRound((st::maxMediaSize / float64(tw)) * th);
tw = st::maxMediaSize;
+ } else if (cAdaptiveBaloons() && tw >= th && captionWithPaddings > st::maxMediaSize && tw > captionWithPaddings) {
+ th = qRound((captionWithPaddings / float64(tw)) * th);
+ tw = captionWithPaddings;
} else if (tw < th && th > st::maxMediaSize) {
tw = qRound((st::maxMediaSize / float64(th)) * tw);
th = st::maxMediaSize;
@@ -104,6 +111,9 @@ QSize Video::countOptimalSize() {
auto maxWidth = qMax(_thumbw, minWidth);
auto minHeight = qMax(th, st::minVideoSize);
if (_parent->hasBubble() && !_caption.isEmpty()) {
+ if (cAdaptiveBaloons()) {
+ maxWidth = qMax(maxWidth, _caption.maxWidth() + st::msgPadding.left() + st::msgPadding.right());
+ }
const auto captionw = maxWidth
- st::msgPadding.left()
- st::msgPadding.right();
@@ -116,6 +126,8 @@ QSize Video::countOptimalSize() {
}
QSize Video::countCurrentSize(int newWidth) {
+ auto availableWidth = newWidth;
+
const auto size = countOptimalDimensions();
auto tw = size.width();
auto th = size.height();
@@ -131,6 +143,10 @@ QSize Video::countCurrentSize(int newWidth) {
newWidth = qMax(_thumbw, minWidth);
auto newHeight = qMax(th, st::minPhotoSize);
if (_parent->hasBubble() && !_caption.isEmpty()) {
+ if (cAdaptiveBaloons()) {
+ newWidth = qMax(newWidth, _caption.maxWidth() + st::msgPadding.left() + st::msgPadding.right());
+ newWidth = qMin(newWidth, availableWidth);
+ }
const auto captionw = newWidth
- st::msgPadding.left()
- st::msgPadding.right();
diff --git a/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp b/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp
index 6a096c283..f3bcf257a 100644
--- a/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp
+++ b/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp
@@ -278,6 +278,10 @@ QSize WebPage::countOptimalSize() {
_durationWidth = st::msgDateFont->width(_duration);
}
maxWidth += st::msgPadding.left() + st::webPageLeft + st::msgPadding.right();
+ if (cAdaptiveBaloons()) {
+ accumulate_min(maxWidth, st::msgMaxWidth);
+ accumulate_max(maxWidth, _parent->plainMaxWidth());
+ }
auto padding = inBubblePadding();
minHeight += padding.top() + padding.bottom();
@@ -292,6 +296,10 @@ QSize WebPage::countCurrentSize(int newWidth) {
return { newWidth, minHeight() };
}
+ if (cAdaptiveBaloons() && !asArticle()) {
+ accumulate_min(newWidth, maxWidth());
+ }
+
auto innerWidth = newWidth - st::msgPadding.left() - st::webPageLeft - st::msgPadding.right();
auto newHeight = 0;
diff --git a/Telegram/SourceFiles/settings.cpp b/Telegram/SourceFiles/settings.cpp
index a3b8b1d17..97e66dcb9 100644
--- a/Telegram/SourceFiles/settings.cpp
+++ b/Telegram/SourceFiles/settings.cpp
@@ -232,6 +232,7 @@ rpl::producer<bool> BigEmojiOutlineChanges() {
return gBigEmojiOutline.changes();
}
+bool gAdaptiveBaloons = false;
bool gAlwaysShowScheduled = true;
bool gShowChatId = true;
diff --git a/Telegram/SourceFiles/settings.h b/Telegram/SourceFiles/settings.h
index 9fa9407af..4dbc67ade 100644
--- a/Telegram/SourceFiles/settings.h
+++ b/Telegram/SourceFiles/settings.h
@@ -192,6 +192,7 @@ void SetStickerHeight(int height);
[[nodiscard]] int StickerHeight();
[[nodiscard]] rpl::producer<int> StickerHeightChanges();
+DeclareSetting(bool, AdaptiveBaloons);
DeclareSetting(bool, AlwaysShowScheduled);
DeclareSetting(bool, ShowChatId);
diff --git a/Telegram/SourceFiles/settings/settings_kotato.cpp b/Telegram/SourceFiles/settings/settings_kotato.cpp
index 31a10dd0d..f96bc4a19 100644
--- a/Telegram/SourceFiles/settings/settings_kotato.cpp
+++ b/Telegram/SourceFiles/settings/settings_kotato.cpp
@@ -69,6 +69,33 @@ void SetupKotatoChats(not_null<Ui::VerticalLayout*> container) {
updateStickerHeight);
updateStickerHeightLabel(StickerHeight());
+ const auto adaptiveBaloonsToggled = Ui::CreateChild<rpl::event_stream<bool>>(
+ container.get());
+ AddButton(
+ container,
+ tr::ktg_settings_adaptive_baloons(),
+ st::settingsButton
+ )->toggleOn(
+ adaptiveBaloonsToggled->events_starting_with_copy(cAdaptiveBaloons())
+ )->toggledValue(
+ ) | rpl::filter([](bool enabled) {
+ return (enabled != cAdaptiveBaloons());
+ }) | rpl::start_with_next([=](bool enabled) {
+ const auto confirmed = [=] {
+ cSetAdaptiveBaloons(enabled);
+ KotatoSettings::Write();
+ App::restart();
+ };
+ const auto cancelled = [=] {
+ adaptiveBaloonsToggled->fire(cAdaptiveBaloons() == true);
+ };
+ Ui::show(Box<ConfirmBox>(
+ tr::lng_settings_need_restart(tr::now),
+ tr::lng_settings_restart_now(tr::now),
+ confirmed,
+ cancelled));
+ }, container->lifetime());
+
AddButton(
container,
tr::ktg_settings_emoji_outline(),
diff --git a/Telegram/SourceFiles/window/themes/window_theme_preview.cpp b/Telegram/SourceFiles/window/themes/window_theme_preview.cpp
index 8df16f30b..d0f5fa851 100644
--- a/Telegram/SourceFiles/window/themes/window_theme_preview.cpp
+++ b/Telegram/SourceFiles/window/themes/window_theme_preview.cpp
@@ -248,7 +248,9 @@ void Generator::addAudioBubble(QVector<int> waveform, int waveactive, QString wa
tleft = st::msgFilePadding.left() + st::msgFileSize + st::msgFilePadding.right();
tright = st::msgFileThumbPadding.left();
accumulate_max(width, tleft + st::normalFont->width(wavestatus) + skipBlock.width() + st::msgPadding.right());
- accumulate_min(width, st::msgMaxWidth);
+ if (!cAdaptiveBaloons()) {
+ accumulate_min(width, st::msgMaxWidth);
+ }
auto height = st::msgFilePadding.top() + st::msgFileSize + st::msgFilePadding.bottom();
addBubble(std::move(bubble), width, height, date, status);
@@ -276,7 +278,9 @@ void Generator::addTextBubble(QString text, QString date, Status status) {
auto width = _history.width() - st::msgMargin.left() - st::msgMargin.right();
accumulate_min(width, st::msgPadding.left() + bubble.text.maxWidth() + st::msgPadding.right());
- accumulate_min(width, st::msgMaxWidth);
+ if (!cAdaptiveBaloons()) {
+ accumulate_min(width, st::msgMaxWidth);
+ }
auto textWidth = qMax(width - st::msgPadding.left() - st::msgPadding.right(), 1);
auto textHeight = bubble.text.countHeight(textWidth);
@@ -300,7 +304,9 @@ void Generator::addPhotoBubble(QString image, QString caption, QString date, Sta
auto width = _history.width() - st::msgMargin.left() - st::msgMargin.right();
accumulate_min(width, bubble.photoWidth);
- accumulate_min(width, st::msgMaxWidth);
+ if (!cAdaptiveBaloons()) {
+ accumulate_min(width, st::msgMaxWidth);
+ }
auto textWidth = qMax(width - st::msgPadding.left() - st::msgPadding.right(), 1);
auto textHeight = bubble.text.countHeight(textWidth);
|