diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 9a36efb1d..f24c6003c 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1464,8 +1464,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_info_add_as_contact" = "Add to contacts"; "lng_profile_shared_media" = "Shared media"; "lng_profile_suggest_photo" = "Suggest Profile Photo"; +"lng_profile_suggest_photo_from_clipboard" = "Suggest From Clipboard"; "lng_profile_set_photo_for" = "Set Profile Photo"; +"lng_profile_set_photo_for_from_clipboard" = "Set From Clipboard"; "lng_profile_photo_reset" = "Reset to Original"; +"lng_profile_photo_from_clipboard" = "From clipboard"; "lng_profile_suggest_sure" = "You can suggest {user} to set this photo for their Telegram profile."; "lng_profile_suggest_button" = "Suggest"; "lng_profile_set_personal_sure" = "Only you will see this photo and it will replace any photo {user} sets for themselves."; diff --git a/Telegram/SourceFiles/ui/controls/userpic_button.cpp b/Telegram/SourceFiles/ui/controls/userpic_button.cpp index 947a15791..472f8e165 100644 --- a/Telegram/SourceFiles/ui/controls/userpic_button.cpp +++ b/Telegram/SourceFiles/ui/controls/userpic_button.cpp @@ -50,6 +50,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_menu_icons.h" #include "styles/style_premium.h" +#include +#include + namespace Ui { namespace { @@ -274,43 +277,45 @@ void UserpicButton::choosePhotoLocally() { _chosenImages.fire({ std::move(image), type }); }; }; - const auto chooseFile = [=](ChosenType type = ChosenType::Set) { + const auto editorData = [=](ChosenType type) { + const auto user = _peer ? _peer->asUser() : nullptr; + const auto name = (user && !user->firstName.isEmpty()) + ? user->firstName + : _peer + ? _peer->name() + : QString(); + const auto phrase = (type == ChosenType::Suggest) + ? &tr::lng_profile_suggest_sure + : (user && EditPeerInfoBox::Available(user)) + ? nullptr + : (user && !user->isSelf()) + ? &tr::lng_profile_set_personal_sure + : nullptr; + return Editor::EditorData{ + .about = (phrase + ? (*phrase)( + tr::now, + lt_user, + Ui::Text::Bold(name), + Ui::Text::WithEntities) + : TextWithEntities()), + .confirm = ((type == ChosenType::Suggest) + ? tr::lng_profile_suggest_button(tr::now) + : tr::lng_profile_set_photo_button(tr::now)), + .cropType = (useForumShape() + ? Editor::EditorData::CropType::RoundedRect + : Editor::EditorData::CropType::Ellipse), + .keepAspectRatio = true, + }; + }; + const auto chooseFile = [=](ChosenType type) { base::call_delayed( _st.changeButton.ripple.hideDuration, crl::guard(this, [=] { - using namespace Editor; - const auto user = _peer ? _peer->asUser() : nullptr; - const auto name = (user && !user->firstName.isEmpty()) - ? user->firstName - : _peer - ? _peer->name() - : QString(); - const auto phrase = (type == ChosenType::Suggest) - ? &tr::lng_profile_suggest_sure - : (user && EditPeerInfoBox::Available(user)) - ? nullptr - : (user && !user->isSelf()) - ? &tr::lng_profile_set_personal_sure - : nullptr; PrepareProfilePhotoFromFile( this, _window, - { - .about = (phrase - ? (*phrase)( - tr::now, - lt_user, - Ui::Text::Bold(name), - Ui::Text::WithEntities) - : TextWithEntities()), - .confirm = ((type == ChosenType::Suggest) - ? tr::lng_profile_suggest_button(tr::now) - : tr::lng_profile_set_photo_button(tr::now)), - .cropType = (useForumShape() - ? EditorData::CropType::RoundedRect - : EditorData::CropType::Ellipse), - .keepAspectRatio = true, - }, + editorData(type), callback(type)); })); }; @@ -334,19 +339,43 @@ void UserpicButton::choosePhotoLocally() { done, _peer ? _peer->isForum() : false); }; + const auto addFromClipboard = [=](ChosenType type, tr::phrase<> text) { + if (const auto data = QGuiApplication::clipboard()->mimeData()) { + if (data->hasImage()) { + auto openEditor = crl::guard(this, [=, this] { + Editor::PrepareProfilePhoto( + this, + _window, + editorData(ChosenType::Set), + callback(ChosenType::Set), + qvariant_cast(data->imageData())); + }); + _menu->addAction( + std::move(text)(tr::now), + std::move(openEditor), + &st::menuIconPhoto); + } + } + }; _menu = base::make_unique_q( this, st::popupMenuWithIcons); if (user && !user->isSelf()) { _menu->addAction( tr::lng_profile_set_photo_for(tr::now), - [=] { chooseFile(); }, + [=] { chooseFile(ChosenType::Set); }, &st::menuIconPhotoSet); + addFromClipboard( + ChosenType::Set, + tr::lng_profile_set_photo_for_from_clipboard); if (canSuggestPhoto(user)) { _menu->addAction( tr::lng_profile_suggest_photo(tr::now), [=] { chooseFile(ChosenType::Suggest); }, &st::menuIconPhotoSuggest); + addFromClipboard( + ChosenType::Suggest, + tr::lng_profile_suggest_photo_from_clipboard); } addUserpicBuilder(ChosenType::Set); if (hasPersonalPhotoLocally()) { @@ -357,7 +386,7 @@ void UserpicButton::choosePhotoLocally() { const auto hasCamera = IsCameraAvailable(); if (hasCamera || _controller) { _menu->addAction(tr::lng_attach_file(tr::now), [=] { - chooseFile(); + chooseFile(ChosenType::Set); }, &st::menuIconPhoto); if (hasCamera) { _menu->addAction(tr::lng_attach_camera(tr::now), [=] { @@ -369,9 +398,12 @@ void UserpicButton::choosePhotoLocally() { callback(ChosenType::Set))); }, &st::menuIconPhotoSet); } + addFromClipboard( + ChosenType::Set, + tr::lng_profile_photo_from_clipboard); addUserpicBuilder(ChosenType::Set); } else { - chooseFile(); + chooseFile(ChosenType::Set); } } _menu->popup(QCursor::pos());