Add original userpic to "Reset to Original" menu item.

This commit is contained in:
John Preston 2022-12-22 17:42:44 +04:00
parent 68b1b595a5
commit 349fbeeb23
3 changed files with 61 additions and 24 deletions

View file

@ -70,6 +70,10 @@ uploadUserpicButton: UserpicButton(defaultUserpicButton) {
changeIconPosition: point(4px, 4px); changeIconPosition: point(4px, 4px);
} }
uploadUserpicButtonBorder: 2px; uploadUserpicButtonBorder: 2px;
restoreUserpicIcon: UserpicButton(defaultUserpicButton) {
size: size(22px, 22px);
photoSize: 22px;
}
confirmInviteTitle: FlatLabel(defaultFlatLabel) { confirmInviteTitle: FlatLabel(defaultFlatLabel) {
align: align(center); align: align(center);

View file

@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/application.h" #include "core/application.h"
#include "ui/layers/generic_box.h" #include "ui/layers/generic_box.h"
#include "ui/text/text_utilities.h" #include "ui/text/text_utilities.h"
#include "ui/widgets/menu/menu_action.h"
#include "ui/painter.h" #include "ui/painter.h"
#include "editor/photo_editor_common.h" #include "editor/photo_editor_common.h"
#include "editor/photo_editor_layer_widget.h" #include "editor/photo_editor_layer_widget.h"
@ -301,30 +302,27 @@ void UserpicButton::choosePhotoLocally() {
callback(type)); callback(type));
})); }));
}; };
if (!IsCameraAvailable()) { _menu = base::make_unique_q<Ui::PopupMenu>(
chooseFile(); this,
} else { st::popupMenuWithIcons);
_menu = base::make_unique_q<Ui::PopupMenu>( const auto user = _peer ? _peer->asUser() : nullptr;
this, if (user && !user->isSelf()) {
st::popupMenuWithIcons); _menu->addAction(
const auto user = _peer ? _peer->asUser() : nullptr; tr::lng_profile_set_photo_for(tr::now),
if (user && !user->isSelf()) { [=] { chooseFile(); },
&st::menuIconPhotoSet);
if (canSuggestPhoto(user)) {
_menu->addAction( _menu->addAction(
tr::lng_profile_set_photo_for(tr::now), tr::lng_profile_suggest_photo(tr::now),
[=] { chooseFile(); }, [=] { chooseFile(ChosenType::Suggest); },
&st::menuIconPhotoSet); &st::menuIconPhotoSuggest);
if (canSuggestPhoto(user)) { }
_menu->addAction( if (hasPersonalPhotoLocally()) {
tr::lng_profile_suggest_photo(tr::now), _menu->addAction(makeResetToOriginalAction());
[=] { chooseFile(ChosenType::Suggest); }, }
&st::menuIconPhotoSuggest); } else {
} if (!IsCameraAvailable()) {
if (hasPersonalPhotoLocally()) { chooseFile();
_menu->addAction(
tr::lng_profile_photo_reset(tr::now),
[=] { _resetPersonalRequests.fire({}); },
&st::menuIconRemove);
}
} else { } else {
_menu->addAction(tr::lng_attach_file(tr::now), [=] { _menu->addAction(tr::lng_attach_file(tr::now), [=] {
chooseFile(); chooseFile();
@ -337,8 +335,37 @@ void UserpicButton::choosePhotoLocally() {
callback(ChosenType::Set))); callback(ChosenType::Set)));
}, &st::menuIconPhotoSet); }, &st::menuIconPhotoSet);
} }
_menu->popup(QCursor::pos());
} }
_menu->popup(QCursor::pos());
}
auto UserpicButton::makeResetToOriginalAction()
-> base::unique_qptr<Menu::ItemBase> {
auto item = base::make_unique_q<Menu::Action>(
_menu.get(),
_menu->st().menu,
Menu::CreateAction(
_menu.get(),
tr::lng_profile_photo_reset(tr::now),
[=] { _resetPersonalRequests.fire({}); }),
nullptr,
nullptr);
const auto icon = CreateChild<UserpicButton>(
item.get(),
_controller,
_peer,
Ui::UserpicButton::Role::Custom,
Ui::UserpicButton::Source::NonPersonalIfHasPersonal,
st::restoreUserpicIcon);
if (_source == Source::Custom) {
icon->showCustom(base::duplicate(_result));
}
icon->setAttribute(Qt::WA_TransparentForMouseEvents);
icon->move(_menu->st().menu.itemIconPosition
+ QPoint(
(st::menuIconRemove.width() - icon->width()) / 2,
(st::menuIconRemove.height() - icon->height()) / 2));
return item;
} }
void UserpicButton::openPeerPhoto() { void UserpicButton::openPeerPhoto() {

View file

@ -34,6 +34,10 @@ namespace style {
struct UserpicButton; struct UserpicButton;
} // namespace style } // namespace style
namespace Ui::Menu {
class ItemBase;
} // namespace Ui::Menu
namespace Ui { namespace Ui {
class PopupMenu; class PopupMenu;
@ -142,6 +146,8 @@ private:
void choosePhotoLocally(); void choosePhotoLocally();
[[nodiscard]] bool canSuggestPhoto(not_null<UserData*> user) const; [[nodiscard]] bool canSuggestPhoto(not_null<UserData*> user) const;
[[nodiscard]] bool hasPersonalPhotoLocally() const; [[nodiscard]] bool hasPersonalPhotoLocally() const;
[[nodiscard]] auto makeResetToOriginalAction()
-> base::unique_qptr<Menu::ItemBase>;
const style::UserpicButton &_st; const style::UserpicButton &_st;
::Window::SessionController *_controller = nullptr; ::Window::SessionController *_controller = nullptr;