diff --git a/Telegram/SourceFiles/settings/settings_scale_preview.cpp b/Telegram/SourceFiles/settings/settings_scale_preview.cpp index 6da0a861e..7e840e31c 100644 --- a/Telegram/SourceFiles/settings/settings_scale_preview.cpp +++ b/Telegram/SourceFiles/settings/settings_scale_preview.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_peer_values.h" #include "history/history_item_components.h" #include "main/main_session.h" +#include "ui/chat/chat_style.h" #include "ui/chat/chat_theme.h" #include "ui/image/image_prepare.h" #include "ui/platform/ui_platform_utility.h" @@ -103,7 +104,7 @@ private: int _bubbleShadow = 0; int _localShiftLeft = 0; QImage _bubbleTail; - QRect _replyBar; + QRect _replyRect; QRect _name; QRect _reply; QRect _message; @@ -329,14 +330,7 @@ style::font Preview::scaled(const style::font &font, int size) const { style::QuoteStyle Preview::scaled(const style::QuoteStyle &value) const { return { - .padding = scaled(value.padding), - .verticalSkip = scaled(value.verticalSkip), - .header = scaled(value.header), - .headerPosition = scaled(value.headerPosition), .icon = value.icon, - .iconPosition = scaled(value.iconPosition), - .outline = scaled(value.outline), - .radius = scaled(value.radius), .scrollable = value.scrollable, }; } @@ -347,7 +341,6 @@ style::TextStyle Preview::scaled( return { .font = scaled(value.font, fontSize), .linkUnderline = value.linkUnderline, - .lineHeight = scaled(value.lineHeight), .blockquote = scaled(value.blockquote), .pre = scaled(value.pre), }; @@ -366,8 +359,22 @@ void Preview::updateToScale(int scale) { return; } _scale = scale; - _nameStyle = scaled(_nameStyle, 13); - _textStyle = scaled(_textStyle, 13); + _nameStyle = scaled(st::fwdTextStyle, 13); + _textStyle = scaled(st::messageTextStyle, 13); + _textStyle.blockquote.verticalSkip = scaled(4); + _textStyle.blockquote.outline = scaled(3); + _textStyle.blockquote.outlineShift = scaled(2); + _textStyle.blockquote.radius = scaled(5); + _textStyle.blockquote.padding = scaled(QMargins{ 10, 2, 20, 2 }); + _textStyle.blockquote.iconPosition = scaled(QPoint{ 4, 4 }); + _textStyle.pre.verticalSkip = scaled(4); + _textStyle.pre.outline = scaled(3); + _textStyle.pre.outlineShift = scaled(2); + _textStyle.pre.radius = scaled(5); + _textStyle.pre.header = scaled(20); + _textStyle.pre.headerPosition = scaled(QPoint{ 10, 2 }); + _textStyle.pre.padding = scaled(QMargins{ 10, 2, 4, 2 }); + _textStyle.pre.iconPosition = scaled(QPoint{ 4, 2 }); _nameText.setText( _nameStyle, u"Bob Harris"_q, @@ -381,21 +388,18 @@ void Preview::updateToScale(int scale) { u"Do you know what time it is?"_q, Ui::ItemTextDefaultOptions()); - _replyBar = QRect( - scaled(1), // st::msgReplyBarPos.x(), - scaled(6) + 0,// st::msgReplyPadding.top() + st::msgReplyBarPos.y(), - scaled(2), //st::msgReplyBarSize.width(), - scaled(36)); // st::msgReplyBarSize.height(), const auto namePosition = QPoint( - scaled(10), // st::msgReplyBarSkip - scaled(6)); // st::msgReplyPadding.top() + scaled(11), // st::historyReplyPadding.left() + scaled(2)); // st::historyReplyPadding.top() const auto replyPosition = QPoint( - scaled(10), // st::msgReplyBarSkip - scaled(6) + _nameStyle.font->height); // st::msgReplyPadding.top() + scaled(11), // st::historyReplyPadding.left() + (scaled(2) // st::historyReplyPadding.top() + + _nameStyle.font->height)); // + st::msgServiceNameFont->height + const auto paddingRight = scaled(6); // st::historyReplyPadding.right() const auto wantedWidth = std::max({ - namePosition.x() + _nameText.maxWidth(), - replyPosition.x() + _replyText.maxWidth(), + namePosition.x() + _nameText.maxWidth() + paddingRight, + replyPosition.x() + _replyText.maxWidth() + paddingRight, _messageText.maxWidth(), }); @@ -409,16 +413,25 @@ void Preview::updateToScale(int scale) { _messageText.countHeight(maxTextWidth), kMaxTextLines * _textStyle.font->height); + _replyRect = QRect( + 0, // st::msgReplyBarPos.x(), + scaled(2),// st::historyReplyTop + messageWidth, + (scaled(2) // st::historyReplyPadding.top() + + _nameStyle.font->height // + st::msgServiceNameFont->height + + _textStyle.font->height // + st::normalFont->height + + scaled(2))); // + st::historyReplyPadding.bottom() + _name = QRect( - namePosition, + _replyRect.topLeft() + namePosition, QSize(messageWidth - namePosition.x(), _nameStyle.font->height)); _reply = QRect( - replyPosition, + _replyRect.topLeft() + replyPosition, QSize(messageWidth - replyPosition.x(), _textStyle.font->height)); _message = QRect(0, 0, messageWidth, messageHeight); - // replyBar.bottom + st::msgReplyPadding.bottom(); - const auto replySkip = _replyBar.y() + _replyBar.height() + scaled(6); + // replyRect.bottom + st::historyReplyBottom; + const auto replySkip = _replyRect.y() + _replyRect.height() + scaled(2); _message.moveTop(replySkip); _content = QRect(0, 0, messageWidth, replySkip + messageHeight); @@ -676,9 +689,30 @@ void Preview::paintContent(Painter &p, QRect clip) { } void Preview::paintReply(Painter &p, QRect clip) { - p.setOpacity(HistoryMessageReply::kBarAlpha); - p.fillRect(_replyBar, st::msgInReplyBarColor); + { + auto hq = PainterHighQualityEnabler(p); + p.setPen(Qt::NoPen); + p.setBrush(st::msgInReplyBarColor); + + const auto outline = _textStyle.blockquote.outline; + const auto radius = _textStyle.blockquote.radius; + p.setOpacity(Ui::kDefaultOutline1Opacity); + p.setClipRect( + _replyRect.x(), + _replyRect.y(), + outline, + _replyRect.height()); + p.drawRoundedRect(_replyRect, radius, radius); + p.setOpacity(Ui::kDefaultBgOpacity); + p.setClipRect( + _replyRect.x() + outline, + _replyRect.y(), + _replyRect.width() - outline, + _replyRect.height()); + p.drawRoundedRect(_replyRect, radius, radius); + } p.setOpacity(1.); + p.setClipping(false); p.setPen(st::msgInServiceFg); _nameText.drawLeftElided( diff --git a/Telegram/SourceFiles/ui/chat/chat_style.cpp b/Telegram/SourceFiles/ui/chat/chat_style.cpp index 7055248db..7bdebaee1 100644 --- a/Telegram/SourceFiles/ui/chat/chat_style.cpp +++ b/Telegram/SourceFiles/ui/chat/chat_style.cpp @@ -54,15 +54,15 @@ void EnsurePreCache( const auto bg = bgOverride(); cache->bg = bg.value_or(color->c); if (!bg) { - cache->bg.setAlpha(0.12 * 255); + cache->bg.setAlpha(kDefaultBgOpacity * 255); } cache->outlines[0] = color->c; - cache->outlines[0].setAlpha(0.9 * 255); + cache->outlines[0].setAlpha(kDefaultOutline1Opacity * 255); cache->outlines[1] = cache->outlines[2] = QColor(0, 0, 0, 0); cache->header = color->c; - cache->header.setAlpha(0.25 * 255); + cache->header.setAlpha(kDefaultOutline2Opacity * 255); cache->icon = cache->outlines[0]; - cache->icon.setAlpha(0.6 * 255); + cache->icon.setAlpha(kDefaultOutline3Opacity * 255); } } // namespace @@ -110,21 +110,21 @@ int HistoryServiceMsgInvertedShrink() { ColorIndexValues SimpleColorIndexValues(QColor color, int patternIndex) { auto bg = color; - bg.setAlpha(0.12 * 255); + bg.setAlpha(kDefaultBgOpacity * 255); auto result = ColorIndexValues{ .name = color, .bg = bg, }; result.outlines[0] = color; - result.outlines[0].setAlpha(0.9 * 255); + result.outlines[0].setAlpha(kDefaultOutline1Opacity * 255); if (patternIndex > 1) { result.outlines[1] = result.outlines[0]; - result.outlines[1].setAlpha(0.3 * 255); + result.outlines[1].setAlpha(kDefaultOutline2Opacity * 255); result.outlines[2] = result.outlines[0]; - result.outlines[2].setAlpha(0.6 * 255); + result.outlines[2].setAlpha(kDefaultOutline3Opacity * 255); } else if (patternIndex > 0) { result.outlines[1] = result.outlines[0]; - result.outlines[1].setAlpha(0.5 * 255); + result.outlines[1].setAlpha(kDefaultOutlineOpacitySecond * 255); result.outlines[2] = QColor(0, 0, 0, 0); } else { result.outlines[1] = result.outlines[2] = QColor(0, 0, 0, 0); @@ -757,9 +757,9 @@ ColorIndexValues ChatStyle::computeColorIndexValues( .name = (*(selected ? listSelected : list)[paletteIndex])->c, }; result.bg = result.name; - result.bg.setAlphaF(0.12); + result.bg.setAlpha(kDefaultBgOpacity * 255); result.outlines[0] = result.name; - result.outlines[0].setAlphaF(0.9); + result.outlines[0].setAlpha(kDefaultOutline1Opacity * 255); result.outlines[1] = result.outlines[2] = QColor(0, 0, 0, 0); return result; } @@ -780,7 +780,7 @@ ColorIndexValues ChatStyle::computeColorIndexValues( .outlines = { color(0), color(1), color(2) } }; result.bg = result.outlines[0]; - result.bg.setAlpha(0.12 * 255); + result.bg.setAlpha(kDefaultBgOpacity * 255); result.name = result.outlines[0]; return result; } diff --git a/Telegram/SourceFiles/ui/chat/chat_style.h b/Telegram/SourceFiles/ui/chat/chat_style.h index c60993df6..8ba606941 100644 --- a/Telegram/SourceFiles/ui/chat/chat_style.h +++ b/Telegram/SourceFiles/ui/chat/chat_style.h @@ -35,6 +35,12 @@ inline constexpr auto kColorPatternsCount = Text::kMaxQuoteOutlines; inline constexpr auto kColorIndexCount = uint8(1 << 6); inline constexpr auto kSimpleColorIndexCount = uint8(7); +inline constexpr auto kDefaultBgOpacity = 0.12; +inline constexpr auto kDefaultOutline1Opacity = 0.9; +inline constexpr auto kDefaultOutline2Opacity = 0.3; +inline constexpr auto kDefaultOutline3Opacity = 0.6; +inline constexpr auto kDefaultOutlineOpacitySecond = 0.5; + struct MessageStyle { CornersPixmaps msgBgCornersSmall; CornersPixmaps msgBgCornersLarge; diff --git a/Telegram/SourceFiles/window/themes/window_theme_preview.cpp b/Telegram/SourceFiles/window/themes/window_theme_preview.cpp index a3ea8a708..a77de2d7f 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_preview.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_preview.cpp @@ -794,7 +794,12 @@ void Generator::paintRow(const Row &row) { void Generator::paintBubble(const Bubble &bubble) { auto height = bubble.height; if (!bubble.replyName.isEmpty()) { - height += st::msgReplyPadding.top() + st::msgReplyBarSize.height() + st::msgReplyPadding.bottom(); + height += st::historyReplyTop + + st::historyReplyPadding.top() + + st::msgServiceNameFont->height + + st::normalFont->height + + st::historyReplyPadding.bottom() + + st::historyReplyBottom; } auto isPhoto = !bubble.photo.isNull(); @@ -854,19 +859,45 @@ void Generator::paintBubble(const Bubble &bubble) { trect = trect.marginsRemoved(st::msgPadding); } if (!bubble.replyName.isEmpty()) { - auto h = st::msgReplyPadding.top() + st::msgReplyBarSize.height() + st::msgReplyPadding.bottom(); - + trect.setY(trect.y() + st::historyReplyTop); auto bar = (bubble.outbg ? st::msgOutReplyBarColor[_palette] : st::msgInReplyBarColor[_palette]); - auto rbar = style::rtlrect(trect.x() + st::msgReplyBarPos.x(), trect.y() + st::msgReplyPadding.top() + st::msgReplyBarPos.y(), st::msgReplyBarSize.width(), st::msgReplyBarSize.height(), _rect.width()); - _p->fillRect(rbar, bar); + auto rbar = style::rtlrect( + trect.x(), + trect.y(), + trect.width(), + (st::historyReplyPadding.top() + + st::msgServiceNameFont->height + + st::normalFont->height + + st::historyReplyPadding.bottom()), + _rect.width()); + { + auto hq = PainterHighQualityEnabler(*_p); + _p->setPen(Qt::NoPen); + _p->setBrush(bar); + + const auto outline = st::messageTextStyle.blockquote.outline; + const auto radius = st::messageTextStyle.blockquote.radius; + _p->setOpacity(Ui::kDefaultOutline1Opacity); + _p->setClipRect(rbar.x(), rbar.y(), outline, rbar.height()); + _p->drawRoundedRect(rbar, radius, radius); + _p->setOpacity(Ui::kDefaultBgOpacity); + _p->setClipRect( + rbar.x() + outline, + rbar.y(), + rbar.width() - outline, + rbar.height()); + _p->drawRoundedRect(rbar, radius, radius); + } + _p->setOpacity(1.); + _p->setClipping(false); _p->setPen(bubble.outbg ? st::msgOutServiceFg[_palette] : st::msgInServiceFg[_palette]); - bubble.replyName.drawLeftElided(*_p, trect.x() + st::msgReplyBarSkip, trect.y() + st::msgReplyPadding.top(), bubble.width - st::msgReplyBarSkip, _rect.width()); + bubble.replyName.drawLeftElided(*_p, trect.x() + st::historyReplyPadding.left(), trect.y() + st::historyReplyPadding.top(), bubble.width - st::historyReplyPadding.left() - st::historyReplyPadding.right(), _rect.width()); _p->setPen(bubble.outbg ? st::historyTextOutFg[_palette] : st::historyTextInFg[_palette]); - bubble.replyText.drawLeftElided(*_p, trect.x() + st::msgReplyBarSkip, trect.y() + st::msgReplyPadding.top() + st::msgServiceNameFont->height, bubble.width - st::msgReplyBarSkip, _rect.width()); + bubble.replyText.drawLeftElided(*_p, trect.x() + st::historyReplyPadding.left(), trect.y() + st::historyReplyPadding.top() + st::msgServiceNameFont->height, bubble.width - st::historyReplyPadding.left() - st::historyReplyPadding.right(), _rect.width()); - trect.setY(trect.y() + h); + trect.setY(trect.y() + rbar.height() + st::historyReplyBottom); } if (!bubble.text.isEmpty()) {