Moved out common structures for userpic emoji builder to single place.

This commit is contained in:
23rd 2023-01-25 19:29:50 +03:00 committed by John Preston
parent 9a717b885a
commit 2f7e4ae8fb
7 changed files with 78 additions and 12 deletions

View File

@ -859,6 +859,8 @@ PRIVATE
info/settings/info_settings_widget.h
info/userpic/info_userpic_emoji_builder.cpp
info/userpic/info_userpic_emoji_builder.h
info/userpic/info_userpic_emoji_builder_common.cpp
info/userpic/info_userpic_emoji_builder_common.h
info/userpic/info_userpic_emoji_builder_menu_item.cpp
info/userpic/info_userpic_emoji_builder_menu_item.h
info/userpic/info_userpic_emoji_builder_preview.cpp

View File

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "info/userpic/info_userpic_emoji_builder.h"
#include "info/userpic/info_userpic_emoji_builder_common.h"
#include "info/userpic/info_userpic_emoji_builder_layer.h"
#include "info/userpic/info_userpic_emoji_builder_widget.h"
#include "lang/lang_keys.h"
@ -33,7 +34,7 @@ void ShowLayer(
layerRaw,
controller,
data,
BothWayCommunication{
BothWayCommunication<QImage&&>{
.triggers = state->clicks.events(),
.result = [=, done = std::move(doneCallback)](QImage &&i) {
done(std::move(i));

View File

@ -0,0 +1,37 @@
/*
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
*/
#include "info/userpic/info_userpic_emoji_builder_common.h"
#include "ui/image/image_prepare.h"
namespace UserpicBuilder {
[[nodiscard]] QImage GenerateGradient(
const QSize &size,
const std::vector<QColor> &colors,
bool circle) {
constexpr auto kRotation = int(45);
auto gradient = Images::GenerateGradient(size, colors, kRotation);
if (!circle) {
return gradient;
} else if (style::DevicePixelRatio() == 1) {
return Images::Circle(std::move(gradient));
}
auto image = QImage(
size * style::DevicePixelRatio(),
QImage::Format_ARGB32_Premultiplied);
image.setDevicePixelRatio(style::DevicePixelRatio());
image.fill(Qt::transparent);
{
auto p = QPainter(&image);
p.drawImage(QRect(QPoint(), size), gradient);
}
return Images::Circle(std::move(image));
}
} // namespace UserpicBuilder

View File

@ -0,0 +1,29 @@
/*
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
namespace UserpicBuilder {
[[nodiscard]] QImage GenerateGradient(
const QSize &size,
const std::vector<QColor> &colors,
bool circle = true);
struct StartData {
DocumentId documentId = DocumentId(0);
int builderColorIndex = 0;
std::vector<QColor> gradientEditorColors;
};
template <typename Result>
struct BothWayCommunication {
rpl::producer<> triggers;
Fn<void(Result)> result;
};
} // namespace UserpicBuilder

View File

@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_document.h"
#include "data/data_session.h"
#include "info/userpic/info_userpic_emoji_builder.h"
#include "info/userpic/info_userpic_emoji_builder_common.h"
#include "info/userpic/info_userpic_emoji_builder_widget.h"
#include "lang/lang_keys.h"
#include "main/main_session.h"

View File

@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "editor/photo_editor_layer_widget.h" // Editor::kProfilePhotoSize.
#include "info/userpic/info_userpic_bubble_wrap.h"
#include "info/userpic/info_userpic_colors_palette_chooser.h"
#include "info/userpic/info_userpic_emoji_builder_common.h"
#include "info/userpic/info_userpic_emoji_builder_preview.h"
#include "lang/lang_keys.h"
#include "main/main_session.h"
@ -241,7 +242,7 @@ not_null<Ui::VerticalLayout*> CreateUserpicBuilder(
not_null<Ui::RpWidget*> parent,
not_null<Window::SessionController*> controller,
StartData data,
BothWayCommunication communication) {
BothWayCommunication<QImage&&> communication) {
const auto container = Ui::CreateChild<Ui::VerticalLayout>(parent.get());
const auto preview = container->add(
@ -273,7 +274,7 @@ not_null<Ui::VerticalLayout*> CreateUserpicBuilder(
const auto palette = Ui::CreateChild<ColorsPalette>(
paletteBg.get(),
data.colorIndex);
data.builderColorIndex);
palette->stopsValue(
) | rpl::start_with_next([=](QGradientStops stops) {
preview->setGradientStops(std::move(stops));

View File

@ -18,21 +18,16 @@ class SessionController;
namespace UserpicBuilder {
struct StartData {
DocumentId documentId = DocumentId(0);
int colorIndex = 0;
};
struct StartData;
struct BothWayCommunication {
rpl::producer<> triggers;
Fn<void(QImage &&image)> result;
};
template <typename Result>
struct BothWayCommunication;
not_null<Ui::VerticalLayout*> CreateUserpicBuilder(
not_null<Ui::RpWidget*> parent,
not_null<Window::SessionController*> controller,
StartData data,
BothWayCommunication communication);
BothWayCommunication<QImage&&> communication);
[[nodiscard]] not_null<Ui::RpWidget*> CreateEmojiUserpic(
not_null<Ui::RpWidget*> parent,