2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-09-02 23:55:12 +00:00

Added draft menu to SendFilesBox to open photo editor.

This commit is contained in:
23rd
2021-02-20 06:30:14 +03:00
parent 09768ce28a
commit 3ce315111f
8 changed files with 91 additions and 0 deletions

View File

@@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "chat_helpers/tabbed_panel.h"
#include "chat_helpers/tabbed_selector.h"
#include "confirm_box.h"
#include "editor/photo_editor_layer_widget.h"
#include "history/history_drag_area.h"
#include "history/view/history_view_schedule_box.h"
#include "core/file_utilities.h"
@@ -187,6 +188,22 @@ rpl::producer<int> SendFilesBox::Block::itemReplaceRequest() const {
}
}
rpl::producer<int> SendFilesBox::Block::itemModifyRequest() const {
using namespace rpl::mappers;
const auto preview = _preview.get();
const auto from = _from;
if (_isAlbum) {
const auto album = static_cast<Ui::AlbumPreview*>(preview);
return album->thumbModified() | rpl::map(_1 + from);
} else if (_isSingleMedia) {
const auto media = static_cast<Ui::SingleMediaPreview*>(preview);
return media->modifyRequests() | rpl::map_to(from);
} else {
return rpl::never<int>();
}
}
void SendFilesBox::Block::setSendWay(Ui::SendFilesWay way) {
if (!_isAlbum) {
return;
@@ -601,6 +618,41 @@ void SendFilesBox::pushBlock(int from, int till) {
FileDialog::AllOrImagesFilter(),
crl::guard(this, callback));
}, widget->lifetime());
const auto pp = std::make_shared<QPixmap>();
block.itemModifyRequest(
) | rpl::start_with_next([=, controller = _controller](int index) {
auto &file = _list.files[index];
if (file.type != Ui::PreparedFile::Type::Photo) {
return;
}
using Image = Ui::PreparedFileInformation::Image;
const auto image = std::get_if<Image>(&file.information->media);
if (!image) {
return;
}
*pp = QPixmap::fromImage(
image->data,
Qt::ColorOnly);
auto callback = [=](const Editor::PhotoModifications &mods) {
image->modifications = mods;
Storage::UpdateImageDetails(
_list.files[index],
st::sendMediaPreviewSize);
refreshAllAfterChanges(from);
};
controller->showLayer(
std::make_unique<Editor::LayerWidget>(
this,
&controller->window(),
pp,
image->modifications,
std::move(callback)),
Ui::LayerOption::KeepOther);
}, widget->lifetime());
}
void SendFilesBox::refreshControls() {