mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added ability to change userpic with image from clipboard.
This commit is contained in:
parent
83df3cba66
commit
67bbdbfc70
2 changed files with 69 additions and 34 deletions
|
@ -1464,8 +1464,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_info_add_as_contact" = "Add to contacts";
|
"lng_info_add_as_contact" = "Add to contacts";
|
||||||
"lng_profile_shared_media" = "Shared media";
|
"lng_profile_shared_media" = "Shared media";
|
||||||
"lng_profile_suggest_photo" = "Suggest Profile Photo";
|
"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" = "Set Profile Photo";
|
||||||
|
"lng_profile_set_photo_for_from_clipboard" = "Set From Clipboard";
|
||||||
"lng_profile_photo_reset" = "Reset to Original";
|
"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_sure" = "You can suggest {user} to set this photo for their Telegram profile.";
|
||||||
"lng_profile_suggest_button" = "Suggest";
|
"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.";
|
"lng_profile_set_personal_sure" = "Only you will see this photo and it will replace any photo {user} sets for themselves.";
|
||||||
|
|
|
@ -50,6 +50,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "styles/style_menu_icons.h"
|
#include "styles/style_menu_icons.h"
|
||||||
#include "styles/style_premium.h"
|
#include "styles/style_premium.h"
|
||||||
|
|
||||||
|
#include <QtGui/QClipboard>
|
||||||
|
#include <QtGui/QGuiApplication>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -274,43 +277,45 @@ void UserpicButton::choosePhotoLocally() {
|
||||||
_chosenImages.fire({ std::move(image), type });
|
_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(
|
base::call_delayed(
|
||||||
_st.changeButton.ripple.hideDuration,
|
_st.changeButton.ripple.hideDuration,
|
||||||
crl::guard(this, [=] {
|
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(
|
PrepareProfilePhotoFromFile(
|
||||||
this,
|
this,
|
||||||
_window,
|
_window,
|
||||||
{
|
editorData(type),
|
||||||
.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,
|
|
||||||
},
|
|
||||||
callback(type));
|
callback(type));
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
@ -334,19 +339,43 @@ void UserpicButton::choosePhotoLocally() {
|
||||||
done,
|
done,
|
||||||
_peer ? _peer->isForum() : false);
|
_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<QImage>(data->imageData()));
|
||||||
|
});
|
||||||
|
_menu->addAction(
|
||||||
|
std::move(text)(tr::now),
|
||||||
|
std::move(openEditor),
|
||||||
|
&st::menuIconPhoto);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
_menu = base::make_unique_q<Ui::PopupMenu>(
|
_menu = base::make_unique_q<Ui::PopupMenu>(
|
||||||
this,
|
this,
|
||||||
st::popupMenuWithIcons);
|
st::popupMenuWithIcons);
|
||||||
if (user && !user->isSelf()) {
|
if (user && !user->isSelf()) {
|
||||||
_menu->addAction(
|
_menu->addAction(
|
||||||
tr::lng_profile_set_photo_for(tr::now),
|
tr::lng_profile_set_photo_for(tr::now),
|
||||||
[=] { chooseFile(); },
|
[=] { chooseFile(ChosenType::Set); },
|
||||||
&st::menuIconPhotoSet);
|
&st::menuIconPhotoSet);
|
||||||
|
addFromClipboard(
|
||||||
|
ChosenType::Set,
|
||||||
|
tr::lng_profile_set_photo_for_from_clipboard);
|
||||||
if (canSuggestPhoto(user)) {
|
if (canSuggestPhoto(user)) {
|
||||||
_menu->addAction(
|
_menu->addAction(
|
||||||
tr::lng_profile_suggest_photo(tr::now),
|
tr::lng_profile_suggest_photo(tr::now),
|
||||||
[=] { chooseFile(ChosenType::Suggest); },
|
[=] { chooseFile(ChosenType::Suggest); },
|
||||||
&st::menuIconPhotoSuggest);
|
&st::menuIconPhotoSuggest);
|
||||||
|
addFromClipboard(
|
||||||
|
ChosenType::Suggest,
|
||||||
|
tr::lng_profile_suggest_photo_from_clipboard);
|
||||||
}
|
}
|
||||||
addUserpicBuilder(ChosenType::Set);
|
addUserpicBuilder(ChosenType::Set);
|
||||||
if (hasPersonalPhotoLocally()) {
|
if (hasPersonalPhotoLocally()) {
|
||||||
|
@ -357,7 +386,7 @@ void UserpicButton::choosePhotoLocally() {
|
||||||
const auto hasCamera = IsCameraAvailable();
|
const auto hasCamera = IsCameraAvailable();
|
||||||
if (hasCamera || _controller) {
|
if (hasCamera || _controller) {
|
||||||
_menu->addAction(tr::lng_attach_file(tr::now), [=] {
|
_menu->addAction(tr::lng_attach_file(tr::now), [=] {
|
||||||
chooseFile();
|
chooseFile(ChosenType::Set);
|
||||||
}, &st::menuIconPhoto);
|
}, &st::menuIconPhoto);
|
||||||
if (hasCamera) {
|
if (hasCamera) {
|
||||||
_menu->addAction(tr::lng_attach_camera(tr::now), [=] {
|
_menu->addAction(tr::lng_attach_camera(tr::now), [=] {
|
||||||
|
@ -369,9 +398,12 @@ void UserpicButton::choosePhotoLocally() {
|
||||||
callback(ChosenType::Set)));
|
callback(ChosenType::Set)));
|
||||||
}, &st::menuIconPhotoSet);
|
}, &st::menuIconPhotoSet);
|
||||||
}
|
}
|
||||||
|
addFromClipboard(
|
||||||
|
ChosenType::Set,
|
||||||
|
tr::lng_profile_photo_from_clipboard);
|
||||||
addUserpicBuilder(ChosenType::Set);
|
addUserpicBuilder(ChosenType::Set);
|
||||||
} else {
|
} else {
|
||||||
chooseFile();
|
chooseFile(ChosenType::Set);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_menu->popup(QCursor::pos());
|
_menu->popup(QCursor::pos());
|
||||||
|
|
Loading…
Add table
Reference in a new issue