From 9bc4c0a551a1265226aafa1bef56502610f7da44 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 24 Jan 2023 01:58:18 +0300 Subject: [PATCH] Added initial implementation of userpic emoji builder. --- Telegram/CMakeLists.txt | 2 + .../info/userpic/info_userpic_builder.style | 19 +++++ .../userpic/info_userpic_emoji_builder.cpp | 75 +++++++++++++++++++ .../info/userpic/info_userpic_emoji_builder.h | 20 +++++ 4 files changed, 116 insertions(+) create mode 100644 Telegram/SourceFiles/info/userpic/info_userpic_emoji_builder.cpp create mode 100644 Telegram/SourceFiles/info/userpic/info_userpic_emoji_builder.h diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index fe175db3f1..ba6f3de809 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -857,6 +857,8 @@ PRIVATE info/profile/info_profile_widget.h info/settings/info_settings_widget.cpp 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_widget.cpp info/userpic/info_userpic_emoji_builder_widget.h inline_bots/bot_attach_web_view.cpp diff --git a/Telegram/SourceFiles/info/userpic/info_userpic_builder.style b/Telegram/SourceFiles/info/userpic/info_userpic_builder.style index 4407a435e5..cde69ccab4 100644 --- a/Telegram/SourceFiles/info/userpic/info_userpic_builder.style +++ b/Telegram/SourceFiles/info/userpic/info_userpic_builder.style @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ using "ui/basic.style"; +using "boxes/boxes.style"; using "ui/widgets/widgets.style"; userpicBuilderEmojiPreviewPadding: margins(0px, 36px, 0px, 8px); @@ -22,6 +23,24 @@ userpicBuilderEmojiBubblePalettePadding: margins(12px, 8px, 12px, 8px); userpicBuilderEmojiSelectorLeft: 5px; +userpicBuilderEmojiButton: RoundButton(defaultBoxButton) { + textFg: boxTextFg; + textFgOver: boxTextFg; + textBg: boxDividerBg; + textBgOver: boxDividerBg; + + ripple: universalRippleAnimation; +} +userpicBuilderEmojiBackButton: IconButton(backButton) { + icon: icon {{ "box_button_back", boxTextFg }}; + iconOver: icon {{ "box_button_back", boxTextFg }}; + + ripple: universalRippleAnimation; +} + +userpicBuilderEmojiBackPosiiton: point(8px, 8px); +userpicBuilderEmojiSavePosiiton: point(7px, 12px); + userpicBuilderEmojiAccentColorSize: 30px; userpicBuilderEmojiBubblePadding: margins(5px, 5px, 5px, 5px); diff --git a/Telegram/SourceFiles/info/userpic/info_userpic_emoji_builder.cpp b/Telegram/SourceFiles/info/userpic/info_userpic_emoji_builder.cpp new file mode 100644 index 0000000000..d266f36eb4 --- /dev/null +++ b/Telegram/SourceFiles/info/userpic/info_userpic_emoji_builder.cpp @@ -0,0 +1,75 @@ +/* +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.h" + +#include "info/userpic/info_userpic_emoji_builder_layer.h" +#include "info/userpic/info_userpic_emoji_builder_widget.h" +#include "lang/lang_keys.h" +#include "ui/widgets/buttons.h" +#include "ui/wrap/vertical_layout.h" +#include "window/window_session_controller.h" +#include "styles/style_info_userpic_builder.h" + +namespace UserpicBuilder { + +void ShowLayer( + not_null controller, + Fn &&doneCallback) { + auto layer = std::make_unique(); + const auto layerRaw = layer.get(); + { + struct State { + rpl::event_stream<> clicks; + }; + const auto state = layer->lifetime().make_state(); + + const auto content = CreateUserpicBuilder( + layerRaw, + controller, + BothWayCommunication{ + .triggers = state->clicks.events(), + .result = [=, done = std::move(doneCallback)](QImage &&i) { + done(std::move(i)); + layerRaw->closeLayer(); + }, + }); + const auto save = Ui::CreateChild( + content.get(), + tr::lng_connection_save(), + st::userpicBuilderEmojiButton); + save->setTextTransform(Ui::RoundButton::TextTransform::NoTransform); + content->sizeValue( + ) | rpl::start_with_next([=] { + const auto &p = st::userpicBuilderEmojiSavePosiiton; + save->moveToRight(p.x(), p.y()); + }, save->lifetime()); + + save->clicks() | rpl::to_empty | rpl::start_to_stream( + state->clicks, + save->lifetime()); + + const auto back = Ui::CreateChild( + content.get(), + st::userpicBuilderEmojiBackButton); + back->setClickedCallback([=] { + layerRaw->closeLayer(); + }); + content->sizeValue( + ) | rpl::start_with_next([=] { + const auto &p = st::userpicBuilderEmojiBackPosiiton; + back->moveToLeft(p.x(), p.y()); + }, back->lifetime()); + + layer->setContent(content); + } + + controller->showLayer(std::move(layer), Ui::LayerOption::KeepOther); +} + +} // namespace UserpicBuilder + diff --git a/Telegram/SourceFiles/info/userpic/info_userpic_emoji_builder.h b/Telegram/SourceFiles/info/userpic/info_userpic_emoji_builder.h new file mode 100644 index 0000000000..2352541fff --- /dev/null +++ b/Telegram/SourceFiles/info/userpic/info_userpic_emoji_builder.h @@ -0,0 +1,20 @@ +/* +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 Window { +class SessionController; +} // namespace Window + +namespace UserpicBuilder { + +void ShowLayer( + not_null controller, + Fn &&doneCallback); + +} // namespace UserpicBuilder