diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 3722bd5e9..51851db0e 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -4885,8 +4885,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "ayu_MessageShotThemeDefault" = "Default"; "ayu_MessageShotThemeSelectTitle" = "Select message theme"; "ayu_MessageShotThemeApply" = "Apply"; -"ayu_MessageShotBackground" = "Background"; -"ayu_MessageShotBackgroundSelected" = "Selected"; +"ayu_MessageShotShowBackground" = "Show background"; "ayu_MessageShotShowDate" = "Show date"; "ayu_MessageShotShowReactions" = "Show reactions"; "ayu_MessageShotShowColorfulReplies" = "Show colorful replies"; diff --git a/Telegram/SourceFiles/ayu/features/messageshot/message_shot.cpp b/Telegram/SourceFiles/ayu/features/messageshot/message_shot.cpp index 051fb0711..531460a1c 100644 --- a/Telegram/SourceFiles/ayu/features/messageshot/message_shot.cpp +++ b/Telegram/SourceFiles/ayu/features/messageshot/message_shot.cpp @@ -7,6 +7,7 @@ #include "message_shot.h" #include "styles/style_layers.h" +#include "styles/style_ayu_styles.h" #include "qguiapplication.h" #include "ayu/ui/boxes/message_shot_box.h" @@ -24,6 +25,7 @@ #include "ui/chat/chat_theme.h" #include "ui/effects/path_shift_gradient.h" #include "ui/layers/box_content.h" +#include "window/themes/window_theme.h" namespace AyuFeatures::MessageShot { @@ -185,7 +187,7 @@ bool MessageShotDelegate::elementIsChatWide() { return true; } -QImage removePadding(const QImage &original) { +QImage removeEmptySpaceAround(const QImage &original) { if (original.isNull()) { return {}; } @@ -211,29 +213,37 @@ QImage removePadding(const QImage &original) { return {}; } - QRect bounds(minX, minY, maxX - minX + 1, maxY - minY + 1); + const QRect bounds(minX, minY, maxX - minX + 1, maxY - minY + 1); return original.copy(bounds); } -QImage addPadding(const QImage &original, int padding) { +QImage addPadding(const QImage &original) { if (original.isNull()) { return {}; } QImage paddedImage( - original.width() + padding * 2 * style::DevicePixelRatio(), - original.height() + padding * 2 * style::DevicePixelRatio(), + original.width() + 2 * st::messageShotPadding, + original.height() + 2 * st::messageShotPadding, QImage::Format_ARGB32_Premultiplied ); paddedImage.fill(Qt::transparent); Painter painter(&paddedImage); - painter.drawImage(padding, padding, original); + painter.drawImage(st::messageShotPadding, st::messageShotPadding, original); painter.end(); return paddedImage; } +QColor makeDefaultBackgroundColor() { + if (Window::Theme::IsNightMode()) { + return st::boxBg->c.lighter(175); + } + + return st::boxBg->c.darker(110); +} + QImage Make(not_null box, const ShotConfig &config) { const auto controller = config.controller; const auto st = config.st; @@ -342,11 +352,6 @@ QImage Make(not_null box, const ShotConfig &config) { rect, true); - // hides too much - // if (AyuFeatures::MessageShot::ignoreRender(AyuFeatures::MessageShot::RenderPart::Date)) { - // context.skipDrawingParts = Ui::ChatPaintContext::SkipDrawingParts::Surrounding; - // } - p.translate(0, y); view->draw(p, context); p.translate(0, -y); @@ -367,9 +372,18 @@ QImage Make(not_null box, const ShotConfig &config) { takingShot = false; - const auto overlay = addPadding(removePadding(image), 4); + auto result = addPadding(removeEmptySpaceAround(image)); + if (!config.showBackground) { + return result; + } - return overlay; + auto newResult = QImage(result.size(), QImage::Format_ARGB32_Premultiplied); + newResult.fill(makeDefaultBackgroundColor()); + + Painter painter(&newResult); + painter.drawImage(0, 0, result); + + return newResult; } void Wrapper(not_null widget) { diff --git a/Telegram/SourceFiles/ayu/features/messageshot/message_shot.h b/Telegram/SourceFiles/ayu/features/messageshot/message_shot.h index 18bd2ad02..4ebe385a6 100644 --- a/Telegram/SourceFiles/ayu/features/messageshot/message_shot.h +++ b/Telegram/SourceFiles/ayu/features/messageshot/message_shot.h @@ -19,6 +19,7 @@ struct ShotConfig std::shared_ptr st; std::vector> messages; + bool showBackground; bool showDate; bool showReactions; }; @@ -63,6 +64,9 @@ rpl::producer themeChosen(); void setPalette(style::palette &palette); rpl::producer paletteChosen(); +// util +QColor makeDefaultBackgroundColor(); + QImage Make(not_null box, const ShotConfig &config); void Wrapper(not_null widget); diff --git a/Telegram/SourceFiles/ayu/ui/ayu_styles.style b/Telegram/SourceFiles/ayu/ui/ayu_styles.style index 719086b53..2b03c40b8 100644 --- a/Telegram/SourceFiles/ayu/ui/ayu_styles.style +++ b/Telegram/SourceFiles/ayu/ui/ayu_styles.style @@ -27,6 +27,8 @@ recentStickersLimitPadding: margins(22px, 4px, 22px, 8px); imageViewPadding: margins(22px, 10px, 22px, 10px); imageViewInnerPadding: margins(16px, 16px, 16px, 16px); +messageShotPadding: 4px; + topBarAdmins: IconButton { width: 40px; height: topBarHeight; diff --git a/Telegram/SourceFiles/ayu/ui/boxes/message_shot_box.cpp b/Telegram/SourceFiles/ayu/ui/boxes/message_shot_box.cpp index e25e36c55..6dd9663cc 100644 --- a/Telegram/SourceFiles/ayu/ui/boxes/message_shot_box.cpp +++ b/Telegram/SourceFiles/ayu/ui/boxes/message_shot_box.cpp @@ -109,6 +109,20 @@ void MessageShotBox::setupContent() { Ui::show(std::move(box), Ui::LayerOption::KeepOther); }); + AddButtonWithIcon( + content, + tr::ayu_MessageShotShowBackground(), + st::settingsButtonNoIcon + )->toggleOn(rpl::single(false) + )->toggledValue( + ) | start_with_next( + [=](bool enabled) + { + _config.showBackground = enabled; + + updatePreview(); + }, + content->lifetime()); AddButtonWithIcon( content, diff --git a/Telegram/SourceFiles/ayu/ui/components/image_view.cpp b/Telegram/SourceFiles/ayu/ui/components/image_view.cpp index ae5ef88bd..b2f369f26 100644 --- a/Telegram/SourceFiles/ayu/ui/components/image_view.cpp +++ b/Telegram/SourceFiles/ayu/ui/components/image_view.cpp @@ -6,12 +6,12 @@ // Copyright @Radolyn, 2024 #include "image_view.h" +#include "ayu/features/messageshot/message_shot.h" #include "styles/style_ayu_styles.h" #include "ayu/utils/telegram_helpers.h" #include "styles/style_chat.h" #include "ui/painter.h" -#include "window/themes/window_theme.h" ImageView::ImageView(QWidget *parent) : RpWidget(parent) { @@ -63,15 +63,8 @@ QImage ImageView::getImage() const { void ImageView::paintEvent(QPaintEvent *e) { Painter p(this); - // PainterHighQualityEnabler hq(p); - auto brush = QBrush(st::boxBg); // copy - - if (Window::Theme::IsNightMode()) { - brush.setColor(brush.color().lighter(120)); - } else { - brush.setColor(brush.color().darker(105)); - } + const auto brush = QBrush(AyuFeatures::MessageShot::makeDefaultBackgroundColor()); QPainterPath path; path.addRoundedRect(rect(), st::bubbleRadiusLarge, st::bubbleRadiusLarge);