mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
Extracted poll media preview and sticker panel into single place.
This commit is contained in:
@@ -1691,34 +1691,12 @@ object_ptr<Ui::RpWidget> CreatePollBox::setupContent() {
|
||||
const auto showStickerPanel = [=](
|
||||
not_null<Ui::RpWidget*>,
|
||||
std::shared_ptr<PollMediaState> media) {
|
||||
using Selector = ChatHelpers::TabbedSelector;
|
||||
using Descriptor = ChatHelpers::TabbedSelectorDescriptor;
|
||||
using Mode = ChatHelpers::TabbedSelector::Mode;
|
||||
using Panel = ChatHelpers::TabbedPanel;
|
||||
if (!state->stickerPanel) {
|
||||
const auto body = getDelegate()->outerContainer();
|
||||
state->stickerPanel = base::make_unique_q<Panel>(
|
||||
state->stickerPanel = HistoryView::CreatePollStickerPanel(
|
||||
body,
|
||||
_controller,
|
||||
object_ptr<Selector>(
|
||||
nullptr,
|
||||
Descriptor{
|
||||
.show = _controller->uiShow(),
|
||||
.st = st::backgroundEmojiPan,
|
||||
.level = Window::GifPauseReason::Layer,
|
||||
.mode = Mode::StickersOnly,
|
||||
.features = {
|
||||
.megagroupSet = false,
|
||||
.stickersSettings = false,
|
||||
.openStickerSets = false,
|
||||
},
|
||||
}));
|
||||
_controller);
|
||||
state->stickerPanel->setDropDown(true);
|
||||
state->stickerPanel->setDesiredHeightValues(
|
||||
0.,
|
||||
st::emojiPanMinHeight,
|
||||
st::emojiPanMinHeight);
|
||||
state->stickerPanel->hide();
|
||||
base::install_event_filter(
|
||||
body,
|
||||
[=](not_null<QEvent*> event) {
|
||||
@@ -2221,57 +2199,17 @@ object_ptr<Ui::RpWidget> CreatePollBox::setupContent() {
|
||||
std::shared_ptr<PollMediaState> media,
|
||||
bool allowDocuments = false,
|
||||
bool allowStickers = true) {
|
||||
if (media->uploading) {
|
||||
clearMedia(media);
|
||||
return;
|
||||
}
|
||||
const auto document = media->media.document;
|
||||
const auto photo = media->media.photo;
|
||||
const auto remove = [=] { clearMedia(media); };
|
||||
if (document && document->sticker()) {
|
||||
HistoryView::ShowPollStickerPreview(
|
||||
_controller,
|
||||
document,
|
||||
[=] { showStickerPanel(button, media); },
|
||||
remove);
|
||||
return;
|
||||
} else if (photo) {
|
||||
HistoryView::ShowPollPhotoPreview(
|
||||
_controller,
|
||||
photo,
|
||||
[=] { choosePhotoOrVideo(media); },
|
||||
[=] {
|
||||
HistoryView::EditPollPhoto(
|
||||
_controller,
|
||||
photo,
|
||||
crl::guard(this, [=](Ui::PreparedList list) {
|
||||
applyPreparedPhotoList(
|
||||
media,
|
||||
std::move(list));
|
||||
}));
|
||||
},
|
||||
remove);
|
||||
return;
|
||||
} else if (document && document->isVideoFile()) {
|
||||
HistoryView::ShowPollDocumentPreview(
|
||||
_controller,
|
||||
document,
|
||||
[=] { choosePhotoOrVideo(media); },
|
||||
remove);
|
||||
return;
|
||||
} else if (document) {
|
||||
HistoryView::ShowPollDocumentPreview(
|
||||
_controller,
|
||||
document,
|
||||
[=] { chooseDocument(media); },
|
||||
remove);
|
||||
return;
|
||||
} else if (media->media.geo) {
|
||||
HistoryView::ShowPollGeoPreview(
|
||||
_controller,
|
||||
*media->media.geo,
|
||||
nullptr,
|
||||
remove);
|
||||
if (HistoryView::ShowPollMediaPreview(_controller, media, {
|
||||
.choosePhotoOrVideo = [=] { choosePhotoOrVideo(media); },
|
||||
.chooseDocument = [=] { chooseDocument(media); },
|
||||
.chooseSticker = [=] {
|
||||
showStickerPanel(button, media);
|
||||
},
|
||||
.editPhoto = crl::guard(this, [=](Ui::PreparedList list) {
|
||||
applyPreparedPhotoList(media, std::move(list));
|
||||
}),
|
||||
.remove = [=] { clearMedia(media); },
|
||||
})) {
|
||||
return;
|
||||
}
|
||||
state->mediaMenu = base::make_unique_q<Ui::PopupMenu>(
|
||||
|
||||
@@ -30,9 +30,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "lang/lang_keys.h"
|
||||
#include "layout/layout_document_generic_preview.h"
|
||||
#include "main/main_session.h"
|
||||
#include "poll/poll_media_upload.h"
|
||||
#include "mainwidget.h"
|
||||
#include "storage/localimageloader.h"
|
||||
#include "storage/storage_media_prepare.h"
|
||||
#include "chat_helpers/tabbed_panel.h"
|
||||
#include "chat_helpers/tabbed_selector.h"
|
||||
#include "ui/chat/attach/attach_prepare.h"
|
||||
#include "ui/painter.h"
|
||||
#include "ui/rect.h"
|
||||
@@ -600,4 +603,89 @@ void EditPollPhoto(
|
||||
Ui::LayerOption::KeepOther);
|
||||
}
|
||||
|
||||
bool ShowPollMediaPreview(
|
||||
not_null<Window::SessionController*> controller,
|
||||
const std::shared_ptr<PollMediaUpload::PollMediaState> &media,
|
||||
PollMediaActions actions) {
|
||||
if (media->uploading) {
|
||||
actions.remove();
|
||||
return true;
|
||||
}
|
||||
const auto document = media->media.document;
|
||||
const auto photo = media->media.photo;
|
||||
if (document && document->sticker()) {
|
||||
ShowPollStickerPreview(
|
||||
controller,
|
||||
document,
|
||||
std::move(actions.chooseSticker),
|
||||
std::move(actions.remove));
|
||||
return true;
|
||||
} else if (photo) {
|
||||
ShowPollPhotoPreview(
|
||||
controller,
|
||||
photo,
|
||||
std::move(actions.choosePhotoOrVideo),
|
||||
[controller, photo, editPhoto = std::move(actions.editPhoto)] {
|
||||
EditPollPhoto(
|
||||
controller,
|
||||
photo,
|
||||
std::move(editPhoto));
|
||||
},
|
||||
std::move(actions.remove));
|
||||
return true;
|
||||
} else if (document && document->isVideoFile()) {
|
||||
ShowPollDocumentPreview(
|
||||
controller,
|
||||
document,
|
||||
std::move(actions.choosePhotoOrVideo),
|
||||
std::move(actions.remove));
|
||||
return true;
|
||||
} else if (document) {
|
||||
ShowPollDocumentPreview(
|
||||
controller,
|
||||
document,
|
||||
std::move(actions.chooseDocument),
|
||||
std::move(actions.remove));
|
||||
return true;
|
||||
} else if (media->media.geo) {
|
||||
ShowPollGeoPreview(
|
||||
controller,
|
||||
*media->media.geo,
|
||||
nullptr,
|
||||
std::move(actions.remove));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
base::unique_qptr<ChatHelpers::TabbedPanel> CreatePollStickerPanel(
|
||||
not_null<QWidget*> parent,
|
||||
not_null<Window::SessionController*> controller) {
|
||||
using Selector = ChatHelpers::TabbedSelector;
|
||||
using Descriptor = ChatHelpers::TabbedSelectorDescriptor;
|
||||
|
||||
auto panel = base::make_unique_q<ChatHelpers::TabbedPanel>(
|
||||
parent,
|
||||
controller,
|
||||
object_ptr<Selector>(
|
||||
nullptr,
|
||||
Descriptor{
|
||||
.show = controller->uiShow(),
|
||||
.st = st::backgroundEmojiPan,
|
||||
.level = Window::GifPauseReason::Layer,
|
||||
.mode = Selector::Mode::StickersOnly,
|
||||
.features = {
|
||||
.megagroupSet = false,
|
||||
.stickersSettings = false,
|
||||
.openStickerSets = false,
|
||||
},
|
||||
}));
|
||||
panel->setDesiredHeightValues(
|
||||
0.,
|
||||
st::emojiPanMinHeight,
|
||||
st::emojiPanMinHeight);
|
||||
panel->hide();
|
||||
return panel;
|
||||
}
|
||||
|
||||
} // namespace HistoryView
|
||||
|
||||
@@ -7,14 +7,24 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "base/unique_qptr.h"
|
||||
|
||||
namespace Data {
|
||||
class LocationPoint;
|
||||
} // namespace Data
|
||||
|
||||
namespace PollMediaUpload {
|
||||
struct PollMediaState;
|
||||
} // namespace PollMediaUpload
|
||||
|
||||
struct PollData;
|
||||
class DocumentData;
|
||||
class PhotoData;
|
||||
|
||||
namespace ChatHelpers {
|
||||
class TabbedPanel;
|
||||
} // namespace ChatHelpers
|
||||
|
||||
namespace Ui {
|
||||
class DropdownMenu;
|
||||
struct PreparedList;
|
||||
@@ -26,6 +36,14 @@ class SessionController;
|
||||
|
||||
namespace HistoryView {
|
||||
|
||||
struct PollMediaActions {
|
||||
Fn<void()> choosePhotoOrVideo;
|
||||
Fn<void()> chooseDocument;
|
||||
Fn<void()> chooseSticker;
|
||||
Fn<void(Ui::PreparedList)> editPhoto;
|
||||
Fn<void()> remove;
|
||||
};
|
||||
|
||||
void FillPollAnswerMenu(
|
||||
not_null<Ui::DropdownMenu*> menu,
|
||||
not_null<PollData*> poll,
|
||||
@@ -64,4 +82,14 @@ void EditPollPhoto(
|
||||
not_null<PhotoData*> photo,
|
||||
Fn<void(Ui::PreparedList)> done);
|
||||
|
||||
[[nodiscard]] bool ShowPollMediaPreview(
|
||||
not_null<Window::SessionController*> controller,
|
||||
const std::shared_ptr<PollMediaUpload::PollMediaState> &media,
|
||||
PollMediaActions actions);
|
||||
|
||||
[[nodiscard]] base::unique_qptr<ChatHelpers::TabbedPanel>
|
||||
CreatePollStickerPanel(
|
||||
not_null<QWidget*> parent,
|
||||
not_null<Window::SessionController*> controller);
|
||||
|
||||
} // namespace HistoryView
|
||||
|
||||
Reference in New Issue
Block a user