Moved out widget of photo for credits history entries to single place.
This commit is contained in:
parent
c27c567225
commit
1edf0ed70b
|
@ -11,8 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "core/ui_integration.h" // Core::MarkedTextContext.
|
#include "core/ui_integration.h" // Core::MarkedTextContext.
|
||||||
#include "data/data_credits.h"
|
#include "data/data_credits.h"
|
||||||
#include "data/data_file_origin.h"
|
|
||||||
#include "data/data_photo_media.h"
|
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
#include "data/stickers/data_custom_emoji.h"
|
#include "data/stickers/data_custom_emoji.h"
|
||||||
|
@ -94,47 +92,9 @@ void SendCreditsBox(
|
||||||
const auto bot = session->data().user(form->botId);
|
const auto bot = session->data().user(form->botId);
|
||||||
|
|
||||||
if (form->photo) {
|
if (form->photo) {
|
||||||
struct State {
|
box->addRow(object_ptr<Ui::CenterWrap<>>(
|
||||||
std::shared_ptr<Data::PhotoMedia> view;
|
|
||||||
Image *image = nullptr;
|
|
||||||
rpl::lifetime downloadLifetime;
|
|
||||||
};
|
|
||||||
const auto state = content->lifetime().make_state<State>();
|
|
||||||
const auto widget = box->addRow(
|
|
||||||
object_ptr<Ui::CenterWrap<>>(
|
|
||||||
content,
|
content,
|
||||||
object_ptr<Ui::RpWidget>(content)))->entity();
|
Settings::HistoryEntryPhoto(content, form->photo, photoSize)));
|
||||||
state->view = form->photo->createMediaView();
|
|
||||||
form->photo->load(Data::PhotoSize::Thumbnail, {});
|
|
||||||
|
|
||||||
widget->resize(Size(photoSize));
|
|
||||||
|
|
||||||
rpl::single(rpl::empty_value()) | rpl::then(
|
|
||||||
session->downloaderTaskFinished()
|
|
||||||
) | rpl::start_with_next([=] {
|
|
||||||
using Size = Data::PhotoSize;
|
|
||||||
if (const auto large = state->view->image(Size::Large)) {
|
|
||||||
state->image = large;
|
|
||||||
} else if (const auto small = state->view->image(Size::Small)) {
|
|
||||||
state->image = small;
|
|
||||||
} else if (const auto t = state->view->image(Size::Thumbnail)) {
|
|
||||||
state->image = t;
|
|
||||||
}
|
|
||||||
widget->update();
|
|
||||||
if (state->view->loaded()) {
|
|
||||||
state->downloadLifetime.destroy();
|
|
||||||
}
|
|
||||||
}, state->downloadLifetime);
|
|
||||||
|
|
||||||
widget->paintRequest(
|
|
||||||
) | rpl::start_with_next([=] {
|
|
||||||
auto p = QPainter(widget);
|
|
||||||
if (state->image) {
|
|
||||||
p.drawPixmap(0, 0, state->image->pix(widget->width(), {
|
|
||||||
.options = Images::Option::RoundCircle,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}, widget->lifetime());
|
|
||||||
} else {
|
} else {
|
||||||
const auto widget = box->addRow(
|
const auto widget = box->addRow(
|
||||||
object_ptr<Ui::CenterWrap<>>(
|
object_ptr<Ui::CenterWrap<>>(
|
||||||
|
|
|
@ -10,6 +10,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "api/api_credits.h"
|
#include "api/api_credits.h"
|
||||||
#include "boxes/gift_premium_box.h"
|
#include "boxes/gift_premium_box.h"
|
||||||
#include "core/click_handler_types.h"
|
#include "core/click_handler_types.h"
|
||||||
|
#include "data/data_file_origin.h"
|
||||||
|
#include "data/data_photo_media.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
#include "info/settings/info_settings_widget.h" // SectionCustomTopBarData.
|
#include "info/settings/info_settings_widget.h" // SectionCustomTopBarData.
|
||||||
|
@ -856,4 +858,51 @@ void ReceiptCreditsBox(
|
||||||
}, button->lifetime());
|
}, button->lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object_ptr<Ui::RpWidget> HistoryEntryPhoto(
|
||||||
|
not_null<Ui::RpWidget*> parent,
|
||||||
|
not_null<PhotoData*> photo,
|
||||||
|
int photoSize) {
|
||||||
|
struct State {
|
||||||
|
std::shared_ptr<Data::PhotoMedia> view;
|
||||||
|
Image *image = nullptr;
|
||||||
|
rpl::lifetime downloadLifetime;
|
||||||
|
};
|
||||||
|
const auto state = parent->lifetime().make_state<State>();
|
||||||
|
auto owned = object_ptr<Ui::RpWidget>(parent);
|
||||||
|
const auto widget = owned.data();
|
||||||
|
state->view = photo->createMediaView();
|
||||||
|
photo->load(Data::PhotoSize::Thumbnail, {});
|
||||||
|
|
||||||
|
widget->resize(Size(photoSize));
|
||||||
|
|
||||||
|
rpl::single(rpl::empty_value()) | rpl::then(
|
||||||
|
photo->owner().session().downloaderTaskFinished()
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
using Size = Data::PhotoSize;
|
||||||
|
if (const auto large = state->view->image(Size::Large)) {
|
||||||
|
state->image = large;
|
||||||
|
} else if (const auto small = state->view->image(Size::Small)) {
|
||||||
|
state->image = small;
|
||||||
|
} else if (const auto t = state->view->image(Size::Thumbnail)) {
|
||||||
|
state->image = t;
|
||||||
|
}
|
||||||
|
widget->update();
|
||||||
|
if (state->view->loaded()) {
|
||||||
|
state->downloadLifetime.destroy();
|
||||||
|
}
|
||||||
|
}, state->downloadLifetime);
|
||||||
|
|
||||||
|
widget->paintRequest(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
auto p = QPainter(widget);
|
||||||
|
if (state->image) {
|
||||||
|
p.drawPixmap(0, 0, state->image->pix(widget->width(), {
|
||||||
|
.options = Images::Option::RoundCircle,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}, widget->lifetime());
|
||||||
|
|
||||||
|
return owned;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Settings
|
} // namespace Settings
|
||||||
|
|
|
@ -9,6 +9,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include "settings/settings_type.h"
|
#include "settings/settings_type.h"
|
||||||
|
|
||||||
|
template <typename Object>
|
||||||
|
class object_ptr;
|
||||||
|
|
||||||
class PeerData;
|
class PeerData;
|
||||||
|
|
||||||
namespace Data {
|
namespace Data {
|
||||||
|
@ -39,5 +42,10 @@ void ReceiptCreditsBox(
|
||||||
PeerData *premiumBot,
|
PeerData *premiumBot,
|
||||||
const Data::CreditsHistoryEntry &e);
|
const Data::CreditsHistoryEntry &e);
|
||||||
|
|
||||||
|
[[nodiscard]] object_ptr<Ui::RpWidget> HistoryEntryPhoto(
|
||||||
|
not_null<Ui::RpWidget*> parent,
|
||||||
|
not_null<PhotoData*> photo,
|
||||||
|
int photoSize);
|
||||||
|
|
||||||
} // namespace Settings
|
} // namespace Settings
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue