2023-01-23 22:58:02 +00:00
|
|
|
/*
|
|
|
|
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_widget.h"
|
|
|
|
|
|
|
|
#include "api/api_peer_photo.h"
|
2023-01-24 14:35:11 +00:00
|
|
|
#include "apiwrap.h"
|
2023-01-23 22:58:02 +00:00
|
|
|
#include "chat_helpers/emoji_list_widget.h"
|
2023-01-24 14:35:11 +00:00
|
|
|
#include "chat_helpers/stickers_list_widget.h"
|
2023-01-25 18:25:42 +00:00
|
|
|
#include "data/data_document.h"
|
2023-01-23 22:58:02 +00:00
|
|
|
#include "data/data_message_reactions.h"
|
|
|
|
#include "data/data_session.h"
|
|
|
|
#include "data/stickers/data_custom_emoji.h"
|
|
|
|
#include "editor/photo_editor_layer_widget.h" // Editor::kProfilePhotoSize.
|
|
|
|
#include "info/userpic/info_userpic_bubble_wrap.h"
|
2023-01-25 17:31:07 +00:00
|
|
|
#include "info/userpic/info_userpic_color_circle_button.h"
|
2023-01-25 17:48:43 +00:00
|
|
|
#include "info/userpic/info_userpic_colors_editor.h"
|
2023-01-25 16:29:50 +00:00
|
|
|
#include "info/userpic/info_userpic_emoji_builder_common.h"
|
2023-01-24 18:07:09 +00:00
|
|
|
#include "info/userpic/info_userpic_emoji_builder_preview.h"
|
2023-01-23 22:58:02 +00:00
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "main/main_session.h"
|
2023-01-24 14:35:11 +00:00
|
|
|
#include "ui/controls/emoji_button.h"
|
|
|
|
#include "ui/empty_userpic.h"
|
2023-01-25 17:48:43 +00:00
|
|
|
#include "ui/layers/generic_box.h"
|
2023-01-23 22:58:02 +00:00
|
|
|
#include "ui/painter.h"
|
|
|
|
#include "ui/rect.h"
|
|
|
|
#include "ui/widgets/labels.h"
|
|
|
|
#include "ui/widgets/scroll_area.h"
|
|
|
|
#include "ui/wrap/padding_wrap.h"
|
|
|
|
#include "ui/wrap/vertical_layout.h"
|
|
|
|
#include "window/window_session_controller.h"
|
2023-01-24 14:35:11 +00:00
|
|
|
#include "styles/style_chat.h"
|
2023-01-23 22:58:02 +00:00
|
|
|
#include "styles/style_chat_helpers.h"
|
|
|
|
#include "styles/style_info_userpic_builder.h"
|
|
|
|
#include "styles/style_layers.h"
|
|
|
|
#include "styles/style_settings.h"
|
2023-01-24 14:35:11 +00:00
|
|
|
#include "styles/style_menu_icons.h"
|
2023-01-23 22:58:02 +00:00
|
|
|
|
|
|
|
namespace UserpicBuilder {
|
|
|
|
namespace {
|
|
|
|
|
2023-01-25 17:31:07 +00:00
|
|
|
void AlignChildren(not_null<Ui::RpWidget*> widget, int fullWidth) {
|
|
|
|
const auto children = widget->children();
|
|
|
|
const auto widgets = ranges::views::all(
|
|
|
|
children
|
|
|
|
) | ranges::views::filter([](not_null<const QObject*> object) {
|
|
|
|
return object->isWidgetType();
|
|
|
|
}) | ranges::views::transform([](not_null<QObject*> object) {
|
|
|
|
return static_cast<QWidget*>(object.get());
|
|
|
|
}) | ranges::to_vector;
|
|
|
|
|
|
|
|
const auto widgetWidth = widgets.front()->width();
|
|
|
|
const auto widgetsCount = widgets.size();
|
|
|
|
const auto widgetsWidth = widgetWidth * widgetsCount;
|
|
|
|
const auto step = (fullWidth - widgetsWidth) / (widgetsCount - 1);
|
|
|
|
for (auto i = 0; i < widgetsCount; i++) {
|
|
|
|
widgets[i]->move(i * (widgetWidth + step), widgets[i]->y());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-25 18:25:42 +00:00
|
|
|
[[nodiscard]] QImage GenerateSpecial(
|
|
|
|
int size,
|
|
|
|
const std::vector<QColor> colors) {
|
|
|
|
if (colors.empty()) {
|
|
|
|
auto image = QImage(
|
|
|
|
Size(size * style::DevicePixelRatio()),
|
|
|
|
QImage::Format_ARGB32_Premultiplied);
|
|
|
|
image.setDevicePixelRatio(style::DevicePixelRatio());
|
|
|
|
image.fill(Qt::transparent);
|
|
|
|
{
|
|
|
|
auto p = QPainter(&image);
|
|
|
|
st::userpicBuilderEmojiColorPlus.icon.paintInCenter(
|
|
|
|
p,
|
|
|
|
Rect(Size(size)));
|
|
|
|
}
|
|
|
|
return image;
|
|
|
|
} else {
|
|
|
|
auto image = GenerateGradient(Size(size), colors);
|
|
|
|
{
|
|
|
|
auto p = QPainter(&image);
|
|
|
|
constexpr auto kEllipseSize = 1;
|
|
|
|
const auto center = QPointF(size / 2., size / 2.);
|
|
|
|
const auto shift = QPointF(kEllipseSize * 4, 0);
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setBrush(st::boxBg);
|
|
|
|
p.drawEllipse(center, kEllipseSize, kEllipseSize);
|
|
|
|
p.drawEllipse(center + shift, kEllipseSize, kEllipseSize);
|
|
|
|
p.drawEllipse(center - shift, kEllipseSize, kEllipseSize);
|
|
|
|
}
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-03 05:02:49 +00:00
|
|
|
[[nodiscard]] std::vector<std::vector<QColor>> PaletteGradients() {
|
2023-02-07 02:03:18 +00:00
|
|
|
auto v = std::vector<std::vector<QColor>>{
|
2023-02-03 05:02:49 +00:00
|
|
|
{
|
|
|
|
QColor(32, 226, 205),
|
|
|
|
QColor(14, 225, 241),
|
|
|
|
QColor(77, 141, 255),
|
|
|
|
QColor(43, 191, 255),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
QColor(69, 247, 183),
|
|
|
|
QColor(31, 241, 217),
|
|
|
|
QColor(94, 182, 251),
|
|
|
|
QColor(31, 206, 235),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
QColor(193, 229, 38),
|
|
|
|
QColor(128, 223, 43),
|
|
|
|
QColor(9, 210, 96),
|
|
|
|
QColor(94, 220, 64),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
QColor(255, 212, 18),
|
|
|
|
QColor(255, 167, 67),
|
|
|
|
QColor(245, 105, 78),
|
|
|
|
QColor(245, 119, 44),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
QColor(246, 167, 48),
|
|
|
|
QColor(255, 119, 66),
|
|
|
|
QColor(246, 72, 132),
|
|
|
|
QColor(239, 91, 65),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
QColor(255, 178, 58),
|
|
|
|
QColor(254, 126, 98),
|
|
|
|
QColor(249, 75, 160),
|
|
|
|
QColor(251, 92, 128),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
QColor(255, 114, 169),
|
|
|
|
QColor(226, 105, 255),
|
|
|
|
QColor(131, 124, 255),
|
|
|
|
QColor(176, 99, 255),
|
|
|
|
},
|
|
|
|
};
|
2023-02-07 02:03:18 +00:00
|
|
|
for (auto &g : v) {
|
|
|
|
// Rotate 180 degrees.
|
|
|
|
std::swap(g[0], g[2]);
|
|
|
|
std::swap(g[1], g[3]);
|
|
|
|
}
|
|
|
|
return v;
|
2023-01-25 17:31:07 +00:00
|
|
|
}
|
|
|
|
|
2023-01-25 17:48:43 +00:00
|
|
|
void ShowGradientEditor(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
StartData data,
|
|
|
|
Fn<void(std::vector<QColor>)> &&doneCallback) {
|
2023-05-02 09:33:19 +00:00
|
|
|
controller->show(Box([=](not_null<Ui::GenericBox*> box) {
|
2023-01-25 17:48:43 +00:00
|
|
|
struct State {
|
|
|
|
rpl::event_stream<> saveRequests;
|
|
|
|
};
|
|
|
|
const auto state = box->lifetime().make_state<State>();
|
|
|
|
box->setTitle(tr::lng_chat_theme_change());
|
|
|
|
box->addButton(tr::lng_settings_save(), [=] {
|
|
|
|
state->saveRequests.fire({});
|
|
|
|
});
|
|
|
|
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
|
|
|
|
|
|
|
auto content = CreateGradientEditor(
|
|
|
|
box,
|
2023-01-26 05:11:47 +00:00
|
|
|
(data.documentId
|
|
|
|
? controller->session().data().document(
|
|
|
|
data.documentId).get()
|
|
|
|
: nullptr),
|
2023-01-25 17:48:43 +00:00
|
|
|
data.gradientEditorColors,
|
|
|
|
BothWayCommunication<std::vector<QColor>>{
|
|
|
|
state->saveRequests.events(),
|
|
|
|
[=](std::vector<QColor> colors) {
|
|
|
|
box->closeBox();
|
|
|
|
doneCallback(std::move(colors));
|
|
|
|
},
|
|
|
|
});
|
|
|
|
box->setWidth(content->width());
|
|
|
|
box->addRow(std::move(content), {});
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2023-01-23 22:58:02 +00:00
|
|
|
class EmojiSelector final : public Ui::RpWidget {
|
|
|
|
public:
|
|
|
|
EmojiSelector(
|
|
|
|
not_null<Ui::RpWidget*> parent,
|
2023-01-30 14:59:40 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
rpl::producer<std::vector<DocumentId>> recent);
|
2023-01-23 22:58:02 +00:00
|
|
|
|
|
|
|
[[nodiscard]] rpl::producer<not_null<DocumentData*>> chosen() const;
|
|
|
|
|
|
|
|
private:
|
2023-01-24 14:35:11 +00:00
|
|
|
using Footer = ChatHelpers::TabbedSelector::InnerFooter;
|
|
|
|
using List = ChatHelpers::TabbedSelector::Inner;
|
|
|
|
using Type = ChatHelpers::SelectorTab;
|
|
|
|
void createSelector(Type type);
|
|
|
|
|
|
|
|
struct Selector {
|
|
|
|
not_null<List*> list;
|
|
|
|
not_null<Footer*> footer;
|
|
|
|
};
|
2023-01-26 10:02:45 +00:00
|
|
|
[[nodiscard]] Selector createEmojiList(
|
2023-01-30 18:14:16 +00:00
|
|
|
not_null<Ui::ScrollArea*> scroll);
|
2023-01-26 10:02:45 +00:00
|
|
|
[[nodiscard]] Selector createStickersList(
|
|
|
|
not_null<Ui::ScrollArea*> scroll) const;
|
2023-01-23 22:58:02 +00:00
|
|
|
|
|
|
|
const not_null<Window::SessionController*> _controller;
|
2023-01-24 14:35:11 +00:00
|
|
|
base::unique_qptr<Ui::RpWidget> _container;
|
|
|
|
|
2023-01-30 18:14:16 +00:00
|
|
|
rpl::event_stream<> _recentChanges;
|
|
|
|
std::vector<DocumentId> _lastRecent;
|
2023-01-24 14:35:11 +00:00
|
|
|
rpl::event_stream<not_null<DocumentData*>> _chosen;
|
2023-01-23 22:58:02 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
EmojiSelector::EmojiSelector(
|
|
|
|
not_null<Ui::RpWidget*> parent,
|
2023-01-30 14:59:40 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
rpl::producer<std::vector<DocumentId>> recent)
|
2023-01-23 22:58:02 +00:00
|
|
|
: RpWidget(parent)
|
2023-01-30 18:14:16 +00:00
|
|
|
, _controller(controller) {
|
|
|
|
std::move(
|
|
|
|
recent
|
|
|
|
) | rpl::start_with_next([=](std::vector<DocumentId> ids) {
|
|
|
|
_lastRecent = std::move(ids);
|
|
|
|
_recentChanges.fire({});
|
|
|
|
}, lifetime());
|
2023-01-24 14:35:11 +00:00
|
|
|
createSelector(Type::Emoji);
|
2023-01-23 22:58:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<not_null<DocumentData*>> EmojiSelector::chosen() const {
|
2023-01-24 14:35:11 +00:00
|
|
|
return _chosen.events();
|
2023-01-23 22:58:02 +00:00
|
|
|
}
|
|
|
|
|
2023-01-26 10:02:45 +00:00
|
|
|
EmojiSelector::Selector EmojiSelector::createEmojiList(
|
2023-01-30 18:14:16 +00:00
|
|
|
not_null<Ui::ScrollArea*> scroll) {
|
2023-01-23 22:58:02 +00:00
|
|
|
const auto session = &_controller->session();
|
2023-01-24 14:35:11 +00:00
|
|
|
const auto manager = &session->data().customEmojiManager();
|
|
|
|
const auto tag = Data::CustomEmojiManager::SizeTag::Large;
|
2023-01-23 22:58:02 +00:00
|
|
|
auto args = ChatHelpers::EmojiListDescriptor{
|
2023-05-02 09:33:19 +00:00
|
|
|
.show = _controller->uiShow(),
|
2023-01-30 12:20:25 +00:00
|
|
|
.mode = ChatHelpers::EmojiListMode::UserpicBuilder,
|
2023-01-24 17:00:36 +00:00
|
|
|
.paused = [=] { return true; },
|
2023-01-30 18:14:16 +00:00
|
|
|
.customRecentList = _lastRecent,
|
2023-01-23 22:58:02 +00:00
|
|
|
.customRecentFactory = [=](DocumentId id, Fn<void()> repaint) {
|
|
|
|
return manager->create(id, std::move(repaint), tag);
|
|
|
|
},
|
2023-02-09 08:55:44 +00:00
|
|
|
.st = &st::userpicBuilderEmojiPan,
|
2023-01-23 22:58:02 +00:00
|
|
|
};
|
2023-01-26 10:02:45 +00:00
|
|
|
const auto list = scroll->setOwnedWidget(
|
|
|
|
object_ptr<ChatHelpers::EmojiListWidget>(scroll, std::move(args)));
|
2023-01-24 14:35:11 +00:00
|
|
|
const auto footer = list->createFooter().data();
|
|
|
|
list->refreshEmoji();
|
|
|
|
list->customChosen(
|
|
|
|
) | rpl::start_with_next([=](const ChatHelpers::FileChosen &chosen) {
|
|
|
|
_chosen.fire_copy(chosen.document);
|
|
|
|
}, list->lifetime());
|
2023-01-30 18:14:16 +00:00
|
|
|
_recentChanges.events(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
createSelector(Type::Emoji);
|
|
|
|
}, list->lifetime());
|
2023-01-31 16:00:04 +00:00
|
|
|
list->setAllowWithoutPremium(true);
|
2023-01-24 14:35:11 +00:00
|
|
|
return { list, footer };
|
|
|
|
}
|
2023-01-23 22:58:02 +00:00
|
|
|
|
2023-01-26 10:02:45 +00:00
|
|
|
EmojiSelector::Selector EmojiSelector::createStickersList(
|
|
|
|
not_null<Ui::ScrollArea*> scroll) const {
|
|
|
|
const auto list = scroll->setOwnedWidget(
|
2023-01-24 14:35:11 +00:00
|
|
|
object_ptr<ChatHelpers::StickersListWidget>(
|
2023-01-26 10:02:45 +00:00
|
|
|
scroll,
|
2023-01-24 14:35:11 +00:00
|
|
|
_controller,
|
2023-02-08 15:51:11 +00:00
|
|
|
Window::GifPauseReason::Any,
|
|
|
|
ChatHelpers::StickersListMode::UserpicBuilder));
|
2023-01-24 14:35:11 +00:00
|
|
|
const auto footer = list->createFooter().data();
|
|
|
|
list->refreshRecent();
|
|
|
|
list->chosen(
|
|
|
|
) | rpl::start_with_next([=](const ChatHelpers::FileChosen &chosen) {
|
|
|
|
_chosen.fire_copy(chosen.document);
|
|
|
|
}, list->lifetime());
|
|
|
|
return { list, footer };
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiSelector::createSelector(Type type) {
|
|
|
|
Expects((type == Type::Emoji) || (type == Type::Stickers));
|
|
|
|
|
|
|
|
const auto isEmoji = (type == Type::Emoji);
|
|
|
|
const auto &stScroll = st::reactPanelScroll;
|
|
|
|
|
|
|
|
_container = base::make_unique_q<Ui::RpWidget>(this);
|
|
|
|
const auto container = _container.get();
|
|
|
|
container->show();
|
|
|
|
sizeValue(
|
|
|
|
) | rpl::start_with_next([=](const QSize &s) {
|
|
|
|
container->setGeometry(Rect(s));
|
|
|
|
}, container->lifetime());
|
|
|
|
|
2023-01-26 10:02:45 +00:00
|
|
|
const auto scroll = Ui::CreateChild<Ui::ScrollArea>(container, stScroll);
|
2023-01-24 14:35:11 +00:00
|
|
|
|
|
|
|
const auto selector = isEmoji
|
2023-01-26 10:02:45 +00:00
|
|
|
? createEmojiList(scroll)
|
|
|
|
: createStickersList(scroll);
|
2023-01-24 14:35:11 +00:00
|
|
|
selector.footer->setParent(container);
|
|
|
|
|
|
|
|
const auto toggleButton = Ui::CreateChild<Ui::AbstractButton>(container);
|
|
|
|
const auto &togglePos = st::userpicBuilderEmojiSelectorTogglePosition;
|
|
|
|
{
|
|
|
|
const auto &pos = togglePos;
|
|
|
|
toggleButton->resize(st::menuIconStickers.size()
|
|
|
|
// Trying to overlap the settings button under.
|
|
|
|
+ QSize(pos.x() * 2, pos.y() * 2));
|
|
|
|
toggleButton->show();
|
|
|
|
toggleButton->paintRequest(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
auto p = QPainter(toggleButton);
|
|
|
|
const auto r = toggleButton->rect()
|
|
|
|
- QMargins(pos.x(), pos.y(), pos.x(), pos.y());
|
|
|
|
p.fillRect(r, st::boxBg);
|
|
|
|
if (isEmoji) {
|
2023-01-31 16:53:27 +00:00
|
|
|
st::userpicBuilderEmojiToggleStickersIcon.paintInCenter(p, r);
|
2023-01-24 14:35:11 +00:00
|
|
|
} else {
|
2023-05-17 11:51:04 +00:00
|
|
|
st::defaultEmojiPan.icons.people.paintInCenter(p, r);
|
2023-01-24 14:35:11 +00:00
|
|
|
}
|
|
|
|
}, toggleButton->lifetime());
|
|
|
|
}
|
|
|
|
toggleButton->show();
|
|
|
|
toggleButton->setClickedCallback([=] {
|
|
|
|
createSelector(isEmoji ? Type::Stickers : Type::Emoji);
|
|
|
|
});
|
|
|
|
|
2023-01-26 09:59:30 +00:00
|
|
|
rpl::combine(
|
2023-01-26 10:02:45 +00:00
|
|
|
scroll->scrollTopValue(),
|
|
|
|
scroll->heightValue()
|
2023-01-26 09:59:30 +00:00
|
|
|
) | rpl::start_with_next([=](int scrollTop, int scrollHeight) {
|
|
|
|
const auto scrollBottom = scrollTop + scrollHeight;
|
2023-01-24 14:35:11 +00:00
|
|
|
selector.list->setVisibleTopBottom(scrollTop, scrollBottom);
|
|
|
|
}, selector.list->lifetime());
|
2023-01-23 22:58:02 +00:00
|
|
|
|
2023-01-24 14:35:11 +00:00
|
|
|
selector.list->scrollToRequests(
|
2023-01-23 22:58:02 +00:00
|
|
|
) | rpl::start_with_next([=](int y) {
|
2023-01-26 10:02:45 +00:00
|
|
|
scroll->scrollToY(y);
|
2023-01-23 22:58:02 +00:00
|
|
|
// _shadow->update();
|
2023-01-24 14:35:11 +00:00
|
|
|
}, selector.list->lifetime());
|
2023-01-23 22:58:02 +00:00
|
|
|
|
2023-01-24 14:35:11 +00:00
|
|
|
const auto separator = Ui::CreateChild<Ui::RpWidget>(container);
|
2023-01-23 22:58:02 +00:00
|
|
|
separator->paintRequest(
|
|
|
|
) | rpl::start_with_next([=](const QRect &r) {
|
|
|
|
auto p = QPainter(separator);
|
|
|
|
p.fillRect(r, st::shadowFg);
|
|
|
|
}, separator->lifetime());
|
|
|
|
|
2023-01-24 14:35:11 +00:00
|
|
|
selector.footer->show();
|
2023-01-23 22:58:02 +00:00
|
|
|
separator->show();
|
2023-01-26 10:02:45 +00:00
|
|
|
scroll->show();
|
2023-01-23 22:58:02 +00:00
|
|
|
|
|
|
|
const auto scrollWidth = stScroll.width;
|
|
|
|
sizeValue(
|
|
|
|
) | rpl::start_with_next([=](const QSize &s) {
|
|
|
|
const auto left = st::userpicBuilderEmojiSelectorLeft;
|
2023-01-24 14:35:11 +00:00
|
|
|
const auto mostTop = st::userpicBuilderEmojiSelectorLeft;
|
|
|
|
|
|
|
|
toggleButton->move(QPoint(left, mostTop));
|
2023-01-23 22:58:02 +00:00
|
|
|
|
2023-01-24 14:35:11 +00:00
|
|
|
selector.footer->setGeometry(
|
|
|
|
(isEmoji ? (rect::right(toggleButton) - togglePos.x()) : left),
|
|
|
|
mostTop,
|
2023-01-23 22:58:02 +00:00
|
|
|
s.width() - left,
|
2023-01-24 14:35:11 +00:00
|
|
|
selector.footer->height());
|
2023-01-23 22:58:02 +00:00
|
|
|
|
|
|
|
separator->setGeometry(
|
|
|
|
0,
|
2023-01-24 14:35:11 +00:00
|
|
|
rect::bottom(selector.footer),
|
2023-01-23 22:58:02 +00:00
|
|
|
s.width(),
|
|
|
|
st::lineWidth);
|
|
|
|
|
2023-01-31 16:00:04 +00:00
|
|
|
const auto listWidth = s.width() - st::boxRadius * 2;
|
|
|
|
selector.list->resizeToWidth(listWidth);
|
2023-01-26 10:02:45 +00:00
|
|
|
scroll->setGeometry(
|
2023-01-23 22:58:02 +00:00
|
|
|
st::boxRadius,
|
|
|
|
rect::bottom(separator),
|
2023-01-24 14:35:11 +00:00
|
|
|
selector.list->width() + scrollWidth,
|
2023-01-23 22:58:02 +00:00
|
|
|
s.height() - rect::bottom(separator));
|
2023-01-31 16:00:04 +00:00
|
|
|
selector.list->setMinimalHeight(listWidth, scroll->height());
|
2023-01-23 22:58:02 +00:00
|
|
|
}, lifetime());
|
2023-01-31 10:36:57 +00:00
|
|
|
|
|
|
|
// Reset all animations.
|
|
|
|
selector.list->hideFinished();
|
2023-01-23 22:58:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
not_null<Ui::VerticalLayout*> CreateUserpicBuilder(
|
|
|
|
not_null<Ui::RpWidget*> parent,
|
|
|
|
not_null<Window::SessionController*> controller,
|
2023-01-24 12:10:08 +00:00
|
|
|
StartData data,
|
2023-01-30 20:32:41 +00:00
|
|
|
BothWayCommunication<UserpicBuilder::Result> communication) {
|
2023-01-23 22:58:02 +00:00
|
|
|
const auto container = Ui::CreateChild<Ui::VerticalLayout>(parent.get());
|
|
|
|
|
2023-01-25 17:31:07 +00:00
|
|
|
struct State {
|
|
|
|
std::vector<not_null<CircleButton*>> circleButtons;
|
|
|
|
Ui::Animations::Simple chosenColorAnimation;
|
|
|
|
int colorIndex = -1;
|
2023-01-25 18:25:42 +00:00
|
|
|
|
|
|
|
std::vector<QColor> editorColors;
|
|
|
|
StartData gradientEditorStartData;
|
2023-01-25 17:31:07 +00:00
|
|
|
};
|
|
|
|
const auto state = container->lifetime().make_state<State>();
|
|
|
|
|
2023-01-23 22:58:02 +00:00
|
|
|
const auto preview = container->add(
|
|
|
|
object_ptr<Ui::CenterWrap<EmojiUserpic>>(
|
|
|
|
container,
|
|
|
|
object_ptr<EmojiUserpic>(
|
|
|
|
container,
|
2023-01-31 20:41:16 +00:00
|
|
|
Size(st::settingsInfoPhotoSize),
|
|
|
|
data.isForum)),
|
2023-01-23 22:58:02 +00:00
|
|
|
st::userpicBuilderEmojiPreviewPadding)->entity();
|
2023-01-24 12:10:08 +00:00
|
|
|
if (const auto id = data.documentId) {
|
2023-02-08 17:51:31 +00:00
|
|
|
const auto document = controller->session().data().document(id);
|
|
|
|
if (document && document->sticker()) {
|
2023-01-24 12:10:08 +00:00
|
|
|
preview->setDocument(document);
|
|
|
|
}
|
|
|
|
}
|
2023-01-23 22:58:02 +00:00
|
|
|
|
|
|
|
container->add(
|
|
|
|
object_ptr<Ui::CenterWrap<Ui::FlatLabel>>(
|
|
|
|
container,
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
container,
|
|
|
|
tr::lng_userpic_builder_color_subtitle(),
|
|
|
|
st::userpicBuilderEmojiSubtitle)),
|
|
|
|
st::userpicBuilderEmojiSubtitlePadding);
|
|
|
|
|
|
|
|
const auto paletteBg = Ui::AddBubbleWrap(
|
|
|
|
container,
|
2023-02-08 15:40:25 +00:00
|
|
|
QSize(
|
|
|
|
st::userpicBuilderEmojiBubblePaletteWidth,
|
|
|
|
std::abs(Ui::BubbleWrapInnerRect(QRect(0, 0, 0, 0)).height())
|
|
|
|
+ st::userpicBuilderEmojiAccentColorSize
|
|
|
|
+ rect::m::sum::v(
|
|
|
|
st::userpicBuilderEmojiBubblePalettePadding)));
|
|
|
|
const auto palette = Ui::CreateChild<Ui::VerticalLayout>(paletteBg.get());
|
2023-01-25 17:31:07 +00:00
|
|
|
{
|
|
|
|
constexpr auto kColorsCount = int(7);
|
2023-01-25 18:25:42 +00:00
|
|
|
const auto checkIsSpecial = [=](int i) {
|
|
|
|
return (i == kColorsCount);
|
|
|
|
};
|
2023-01-25 17:31:07 +00:00
|
|
|
const auto size = st::userpicBuilderEmojiAccentColorSize;
|
2023-02-03 05:02:49 +00:00
|
|
|
const auto paletteGradients = PaletteGradients();
|
2023-01-25 18:25:42 +00:00
|
|
|
for (auto i = 0; i < kColorsCount + 1; i++) {
|
|
|
|
const auto isSpecial = checkIsSpecial(i);
|
2023-02-03 05:02:49 +00:00
|
|
|
const auto colors = paletteGradients[i % kColorsCount];
|
2023-01-25 17:31:07 +00:00
|
|
|
const auto button = Ui::CreateChild<CircleButton>(palette);
|
|
|
|
state->circleButtons.push_back(button);
|
|
|
|
button->resize(size, size);
|
2023-01-25 18:25:42 +00:00
|
|
|
button->setBrush(isSpecial
|
|
|
|
? GenerateSpecial(size, state->editorColors)
|
|
|
|
: GenerateGradient(Size(size), colors));
|
|
|
|
|
|
|
|
const auto openEditor = isSpecial
|
|
|
|
? Fn<void()>([=] {
|
|
|
|
if (checkIsSpecial(state->colorIndex)) {
|
|
|
|
state->colorIndex = -1;
|
|
|
|
}
|
|
|
|
ShowGradientEditor(
|
|
|
|
controller,
|
|
|
|
state->gradientEditorStartData,
|
|
|
|
[=](std::vector<QColor> colors) {
|
|
|
|
state->editorColors = std::move(colors);
|
|
|
|
button->setBrush(
|
|
|
|
GenerateSpecial(size, state->editorColors));
|
|
|
|
button->clicked({}, Qt::LeftButton);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
: nullptr;
|
|
|
|
|
2023-01-25 17:31:07 +00:00
|
|
|
button->setClickedCallback([=] {
|
2023-01-25 18:25:42 +00:00
|
|
|
if (openEditor && state->editorColors.empty()) {
|
|
|
|
return openEditor();
|
|
|
|
}
|
2023-01-25 17:31:07 +00:00
|
|
|
const auto was = state->colorIndex;
|
|
|
|
const auto now = i;
|
|
|
|
if (was == now) {
|
2023-01-25 18:25:42 +00:00
|
|
|
if (openEditor) {
|
|
|
|
openEditor();
|
|
|
|
}
|
2023-01-25 17:31:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
state->chosenColorAnimation.stop();
|
|
|
|
state->chosenColorAnimation.start([=](float64 progress) {
|
|
|
|
if (was >= 0) {
|
|
|
|
state->circleButtons[was]->setSelectedProgress(
|
|
|
|
1. - progress);
|
|
|
|
}
|
|
|
|
state->circleButtons[now]->setSelectedProgress(progress);
|
2024-04-23 17:23:29 +00:00
|
|
|
}, 0., 1., st::universalDuration);
|
2023-01-25 17:31:07 +00:00
|
|
|
state->colorIndex = now;
|
|
|
|
|
2023-01-25 18:25:42 +00:00
|
|
|
const auto result = isSpecial
|
|
|
|
? state->editorColors
|
|
|
|
: colors;
|
|
|
|
state->gradientEditorStartData.gradientEditorColors = result;
|
|
|
|
preview->setGradientColors(result);
|
2023-01-25 17:31:07 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
const auto current = data.builderColorIndex % kColorsCount;
|
|
|
|
state->circleButtons[current]->setSelectedProgress(1.);
|
|
|
|
state->circleButtons[current]->clicked({}, Qt::LeftButton);
|
|
|
|
}
|
2023-01-31 19:58:57 +00:00
|
|
|
paletteBg->sizeValue(
|
|
|
|
) | rpl::start_with_next([=](const QSize &s) {
|
|
|
|
palette->setGeometry(Ui::BubbleWrapInnerRect(Rect(s))
|
|
|
|
- st::userpicBuilderEmojiBubblePalettePadding);
|
2023-01-25 17:31:07 +00:00
|
|
|
AlignChildren(palette, palette->width());
|
2023-01-23 22:58:02 +00:00
|
|
|
}, palette->lifetime());
|
|
|
|
|
|
|
|
container->add(
|
|
|
|
object_ptr<Ui::CenterWrap<Ui::FlatLabel>>(
|
|
|
|
container,
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
container,
|
|
|
|
tr::lng_userpic_builder_emoji_subtitle(),
|
|
|
|
st::userpicBuilderEmojiSubtitle)),
|
|
|
|
st::userpicBuilderEmojiSubtitlePadding);
|
|
|
|
|
|
|
|
const auto selectorBg = Ui::AddBubbleWrap(
|
|
|
|
container,
|
|
|
|
QSize(
|
2023-02-08 15:40:25 +00:00
|
|
|
st::userpicBuilderEmojiBubblePaletteWidth,
|
2023-01-31 19:58:57 +00:00
|
|
|
st::userpicBuilderEmojiSelectorMinHeight));
|
2023-01-23 22:58:02 +00:00
|
|
|
const auto selector = Ui::CreateChild<EmojiSelector>(
|
|
|
|
selectorBg.get(),
|
2023-01-30 14:59:40 +00:00
|
|
|
controller,
|
|
|
|
base::take(data.documents));
|
2023-01-23 22:58:02 +00:00
|
|
|
selector->chosen(
|
|
|
|
) | rpl::start_with_next([=](not_null<DocumentData*> document) {
|
2023-01-25 18:25:42 +00:00
|
|
|
state->gradientEditorStartData.documentId = document->id;
|
2023-01-23 22:58:02 +00:00
|
|
|
preview->setDocument(document);
|
|
|
|
}, preview->lifetime());
|
2023-01-31 19:58:57 +00:00
|
|
|
selectorBg->sizeValue(
|
|
|
|
) | rpl::start_with_next([=](const QSize &s) {
|
|
|
|
selector->setGeometry(Ui::BubbleWrapInnerRect(Rect(s)));
|
2023-01-23 22:58:02 +00:00
|
|
|
}, selector->lifetime());
|
|
|
|
|
|
|
|
base::take(
|
|
|
|
communication.triggers
|
|
|
|
) | rpl::start_with_next([=, done = base::take(communication.result)] {
|
2023-01-30 20:32:41 +00:00
|
|
|
preview->result(Editor::kProfilePhotoSize, [=](Result result) {
|
|
|
|
done(std::move(result));
|
2023-01-23 22:58:02 +00:00
|
|
|
});
|
|
|
|
}, preview->lifetime());
|
|
|
|
|
|
|
|
return container;
|
|
|
|
}
|
|
|
|
|
2023-01-24 13:25:02 +00:00
|
|
|
not_null<Ui::RpWidget*> CreateEmojiUserpic(
|
|
|
|
not_null<Ui::RpWidget*> parent,
|
|
|
|
const QSize &size,
|
|
|
|
rpl::producer<not_null<DocumentData*>> document,
|
2023-01-31 20:41:16 +00:00
|
|
|
rpl::producer<int> colorIndex,
|
|
|
|
bool isForum) {
|
2023-02-03 05:02:49 +00:00
|
|
|
const auto paletteGradients = PaletteGradients();
|
2023-01-31 20:41:16 +00:00
|
|
|
const auto widget = Ui::CreateChild<EmojiUserpic>(
|
|
|
|
parent.get(),
|
|
|
|
size,
|
|
|
|
isForum);
|
2023-01-24 13:25:02 +00:00
|
|
|
std::move(
|
|
|
|
document
|
|
|
|
) | rpl::start_with_next([=](not_null<DocumentData*> d) {
|
|
|
|
widget->setDocument(d);
|
|
|
|
}, widget->lifetime());
|
|
|
|
std::move(
|
|
|
|
colorIndex
|
|
|
|
) | rpl::start_with_next([=](int index) {
|
2023-02-03 05:02:49 +00:00
|
|
|
widget->setGradientColors(
|
|
|
|
paletteGradients[index % paletteGradients.size()]);
|
2023-01-24 13:25:02 +00:00
|
|
|
}, widget->lifetime());
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2023-01-23 22:58:02 +00:00
|
|
|
} // namespace UserpicBuilder
|