mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 21:27:07 +02:00
feat: allow copying with background
chore: refactor a bit
This commit is contained in:
parent
f583732688
commit
222a643ce3
6 changed files with 50 additions and 24 deletions
|
@ -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";
|
||||
|
|
|
@ -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<QWidget*> box, const ShotConfig &config) {
|
||||
const auto controller = config.controller;
|
||||
const auto st = config.st;
|
||||
|
@ -342,11 +352,6 @@ QImage Make(not_null<QWidget*> 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<QWidget*> 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<HistoryView::ListWidget*> widget) {
|
||||
|
|
|
@ -19,6 +19,7 @@ struct ShotConfig
|
|||
std::shared_ptr<Ui::ChatStyle> st;
|
||||
std::vector<not_null<HistoryItem*>> messages;
|
||||
|
||||
bool showBackground;
|
||||
bool showDate;
|
||||
bool showReactions;
|
||||
};
|
||||
|
@ -63,6 +64,9 @@ rpl::producer<Data::CloudTheme> themeChosen();
|
|||
void setPalette(style::palette &palette);
|
||||
rpl::producer<style::palette> paletteChosen();
|
||||
|
||||
// util
|
||||
QColor makeDefaultBackgroundColor();
|
||||
|
||||
QImage Make(not_null<QWidget*> box, const ShotConfig &config);
|
||||
|
||||
void Wrapper(not_null<HistoryView::ListWidget*> widget);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue