mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added entry point for userpic emoji builder to userpic button.
This commit is contained in:
parent
e0aabe3acf
commit
cf6245af42
7 changed files with 174 additions and 11 deletions
|
@ -859,6 +859,8 @@ PRIVATE
|
||||||
info/settings/info_settings_widget.h
|
info/settings/info_settings_widget.h
|
||||||
info/userpic/info_userpic_emoji_builder.cpp
|
info/userpic/info_userpic_emoji_builder.cpp
|
||||||
info/userpic/info_userpic_emoji_builder.h
|
info/userpic/info_userpic_emoji_builder.h
|
||||||
|
info/userpic/info_userpic_emoji_builder_menu_item.cpp
|
||||||
|
info/userpic/info_userpic_emoji_builder_menu_item.h
|
||||||
info/userpic/info_userpic_emoji_builder_widget.cpp
|
info/userpic/info_userpic_emoji_builder_widget.cpp
|
||||||
info/userpic/info_userpic_emoji_builder_widget.h
|
info/userpic/info_userpic_emoji_builder_widget.h
|
||||||
inline_bots/bot_attach_web_view.cpp
|
inline_bots/bot_attach_web_view.cpp
|
||||||
|
|
|
@ -1786,6 +1786,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_attach_camera" = "Camera";
|
"lng_attach_camera" = "Camera";
|
||||||
"lng_attach_document" = "Document";
|
"lng_attach_document" = "Document";
|
||||||
"lng_attach_photo_or_video" = "Photo or video";
|
"lng_attach_photo_or_video" = "Photo or video";
|
||||||
|
"lng_attach_profile_emoji" = "Use an Emoji";
|
||||||
|
|
||||||
"lng_media_open_with" = "Open With";
|
"lng_media_open_with" = "Open With";
|
||||||
"lng_media_download" = "Download";
|
"lng_media_download" = "Download";
|
||||||
|
|
|
@ -0,0 +1,94 @@
|
||||||
|
/*
|
||||||
|
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_menu_item.h"
|
||||||
|
|
||||||
|
#include "base/random.h"
|
||||||
|
#include "base/timer.h"
|
||||||
|
#include "data/data_document.h"
|
||||||
|
#include "data/data_session.h"
|
||||||
|
#include "info/userpic/info_userpic_emoji_builder.h"
|
||||||
|
#include "info/userpic/info_userpic_emoji_builder_widget.h"
|
||||||
|
#include "lang/lang_keys.h"
|
||||||
|
#include "main/main_session.h"
|
||||||
|
#include "ui/widgets/menu/menu_action.h"
|
||||||
|
#include "ui/widgets/menu/menu_common.h"
|
||||||
|
#include "ui/widgets/popup_menu.h"
|
||||||
|
#include "window/window_session_controller.h"
|
||||||
|
#include "styles/style_boxes.h"
|
||||||
|
#include "styles/style_menu_icons.h"
|
||||||
|
|
||||||
|
#include <random>
|
||||||
|
|
||||||
|
namespace UserpicBuilder {
|
||||||
|
|
||||||
|
void AddEmojiBuilderAction(
|
||||||
|
not_null<Window::SessionController*> controller,
|
||||||
|
not_null<Ui::PopupMenu*> menu,
|
||||||
|
std::vector<DocumentId> documents,
|
||||||
|
Fn<void(QImage &&image)> &&done) {
|
||||||
|
{
|
||||||
|
auto rd = std::random_device();
|
||||||
|
ranges::shuffle(documents, std::mt19937(rd()));
|
||||||
|
}
|
||||||
|
struct State final {
|
||||||
|
rpl::variable<int> documentIndex;
|
||||||
|
rpl::variable<int> colorIndex;
|
||||||
|
|
||||||
|
base::Timer timer;
|
||||||
|
};
|
||||||
|
const auto state = menu->lifetime().make_state<State>();
|
||||||
|
auto item = base::make_unique_q<Ui::Menu::Action>(
|
||||||
|
menu.get(),
|
||||||
|
menu->st().menu,
|
||||||
|
Ui::Menu::CreateAction(
|
||||||
|
menu.get(),
|
||||||
|
tr::lng_attach_profile_emoji(tr::now),
|
||||||
|
[=, done = std::move(done)] {
|
||||||
|
const auto index = state->documentIndex.current();
|
||||||
|
const auto id = index < documents.size()
|
||||||
|
? documents[index]
|
||||||
|
: 0;
|
||||||
|
UserpicBuilder::ShowLayer(
|
||||||
|
controller,
|
||||||
|
{ id, state->colorIndex.current() },
|
||||||
|
base::duplicate(done));
|
||||||
|
}),
|
||||||
|
nullptr,
|
||||||
|
nullptr);
|
||||||
|
const auto timerCallback = [=] {
|
||||||
|
state->documentIndex = state->documentIndex.current() + 1;
|
||||||
|
if (state->documentIndex.current() >= documents.size()) {
|
||||||
|
state->documentIndex = 0;
|
||||||
|
}
|
||||||
|
state->colorIndex = base::RandomIndex(
|
||||||
|
std::numeric_limits<int>::max());
|
||||||
|
};
|
||||||
|
timerCallback();
|
||||||
|
state->timer.setCallback(timerCallback);
|
||||||
|
constexpr auto kTimeout = crl::time(1500);
|
||||||
|
state->timer.callEach(kTimeout);
|
||||||
|
const auto icon = UserpicBuilder::CreateEmojiUserpic(
|
||||||
|
item.get(),
|
||||||
|
st::restoreUserpicIcon.size,
|
||||||
|
state->documentIndex.value(
|
||||||
|
) | rpl::filter([=](int index) {
|
||||||
|
return index < documents.size();
|
||||||
|
}) | rpl::map([=](int index) {
|
||||||
|
return controller->session().data().document(documents[index]);
|
||||||
|
}),
|
||||||
|
state->colorIndex.value());
|
||||||
|
icon->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
|
icon->move(menu->st().menu.itemIconPosition
|
||||||
|
+ QPoint(
|
||||||
|
(st::menuIconRemove.width() - icon->width()) / 2,
|
||||||
|
(st::menuIconRemove.height() - icon->height()) / 2));
|
||||||
|
|
||||||
|
menu->addAction(std::move(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace UserpicBuilder
|
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
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 Ui {
|
||||||
|
class PopupMenu;
|
||||||
|
} // namespace Ui
|
||||||
|
|
||||||
|
namespace UserpicBuilder {
|
||||||
|
|
||||||
|
void AddEmojiBuilderAction(
|
||||||
|
not_null<Window::SessionController*> controller,
|
||||||
|
not_null<Ui::PopupMenu*> menu,
|
||||||
|
std::vector<DocumentId> documents,
|
||||||
|
Fn<void(QImage &&image)> &&done);
|
||||||
|
|
||||||
|
} // namespace UserpicBuilder
|
|
@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "history/view/media/history_view_sticker_player.h"
|
#include "history/view/media/history_view_sticker_player.h"
|
||||||
#include "info/userpic/info_userpic_bubble_wrap.h"
|
#include "info/userpic/info_userpic_bubble_wrap.h"
|
||||||
#include "info/userpic/info_userpic_colors_palette_chooser.h"
|
#include "info/userpic/info_userpic_colors_palette_chooser.h"
|
||||||
|
#include "ui/empty_userpic.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "settings/settings_common.h"
|
#include "settings/settings_common.h"
|
||||||
|
@ -438,4 +439,25 @@ not_null<Ui::VerticalLayout*> CreateUserpicBuilder(
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
not_null<Ui::RpWidget*> CreateEmojiUserpic(
|
||||||
|
not_null<Ui::RpWidget*> parent,
|
||||||
|
const QSize &size,
|
||||||
|
rpl::producer<not_null<DocumentData*>> document,
|
||||||
|
rpl::producer<int> colorIndex) {
|
||||||
|
const auto widget = Ui::CreateChild<EmojiUserpic>(parent.get(), size);
|
||||||
|
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) {
|
||||||
|
const auto c = Ui::EmptyUserpic::UserpicColor(
|
||||||
|
Ui::EmptyUserpic::ColorIndex(index));
|
||||||
|
widget->setGradientStops({ { 0, c.color1->c }, { 1, c.color2->c } });
|
||||||
|
}, widget->lifetime());
|
||||||
|
return widget;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace UserpicBuilder
|
} // namespace UserpicBuilder
|
||||||
|
|
|
@ -34,4 +34,10 @@ not_null<Ui::VerticalLayout*> CreateUserpicBuilder(
|
||||||
StartData data,
|
StartData data,
|
||||||
BothWayCommunication communication);
|
BothWayCommunication communication);
|
||||||
|
|
||||||
|
[[nodiscard]] not_null<Ui::RpWidget*> CreateEmojiUserpic(
|
||||||
|
not_null<Ui::RpWidget*> parent,
|
||||||
|
const QSize &size,
|
||||||
|
rpl::producer<not_null<DocumentData*>> document,
|
||||||
|
rpl::producer<int> colorIndex);
|
||||||
|
|
||||||
} // namespace UserpicBuilder
|
} // namespace UserpicBuilder
|
||||||
|
|
|
@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#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"
|
||||||
|
#include "info/userpic/info_userpic_emoji_builder_menu_item.h"
|
||||||
#include "media/streaming/media_streaming_instance.h"
|
#include "media/streaming/media_streaming_instance.h"
|
||||||
#include "media/streaming/media_streaming_player.h"
|
#include "media/streaming/media_streaming_player.h"
|
||||||
#include "media/streaming/media_streaming_document.h"
|
#include "media/streaming/media_streaming_document.h"
|
||||||
|
@ -337,20 +338,31 @@ void UserpicButton::choosePhotoLocally() {
|
||||||
_menu->addAction(makeResetToOriginalAction());
|
_menu->addAction(makeResetToOriginalAction());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!IsCameraAvailable()) {
|
const auto hasCamera = IsCameraAvailable();
|
||||||
chooseFile();
|
if (hasCamera || _controller) {
|
||||||
} else {
|
|
||||||
_menu->addAction(tr::lng_attach_file(tr::now), [=] {
|
_menu->addAction(tr::lng_attach_file(tr::now), [=] {
|
||||||
chooseFile();
|
chooseFile();
|
||||||
}, &st::menuIconPhoto);
|
}, &st::menuIconPhoto);
|
||||||
_menu->addAction(tr::lng_attach_camera(tr::now), [=] {
|
if (hasCamera) {
|
||||||
_window->show(Box(
|
_menu->addAction(tr::lng_attach_camera(tr::now), [=] {
|
||||||
CameraBox,
|
_window->show(Box(
|
||||||
_window,
|
CameraBox,
|
||||||
_peer,
|
_window,
|
||||||
_forceForumShape,
|
_peer,
|
||||||
callback(ChosenType::Set)));
|
_forceForumShape,
|
||||||
}, &st::menuIconPhotoSet);
|
callback(ChosenType::Set)));
|
||||||
|
}, &st::menuIconPhotoSet);
|
||||||
|
}
|
||||||
|
if (_controller) {
|
||||||
|
auto &session = _controller->session();
|
||||||
|
UserpicBuilder::AddEmojiBuilderAction(
|
||||||
|
_controller,
|
||||||
|
_menu,
|
||||||
|
session.api().peerPhoto().profileEmojiList(),
|
||||||
|
callback(ChosenType::Set));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
chooseFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_menu->popup(QCursor::pos());
|
_menu->popup(QCursor::pos());
|
||||||
|
|
Loading…
Add table
Reference in a new issue