mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Added draft menu to EditCaptionBox to open photo editor.
This commit is contained in:
parent
671a06c407
commit
d1b6cf1fae
7 changed files with 111 additions and 31 deletions
|
@ -64,6 +64,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "styles/style_chat_helpers.h"
|
||||
#include "styles/style_chat.h"
|
||||
|
||||
#include "editor/photo_editor_layer_widget.h"
|
||||
|
||||
#include <QtCore/QMimeData>
|
||||
|
||||
namespace {
|
||||
|
@ -402,6 +404,47 @@ EditCaptionBox::EditCaptionBox(
|
|||
) | rpl::start_with_next([=] {
|
||||
closeBox();
|
||||
}, lifetime());
|
||||
|
||||
AddPhotoEditorMenu(this, [=, _controller = controller] {
|
||||
const auto previewWidth = st::sendMediaPreviewSize;
|
||||
if (!_preparedList.files.empty()) {
|
||||
Editor::OpenWithPreparedFile(
|
||||
this,
|
||||
controller,
|
||||
&_preparedList.files.front(),
|
||||
previewWidth,
|
||||
[=] { updateEditPreview(); });
|
||||
} else {
|
||||
auto callback = [=](const Editor::PhotoModifications &mods) {
|
||||
if (!mods) {
|
||||
return;
|
||||
}
|
||||
auto copy = computeImage()->original();
|
||||
_preparedList = Storage::PrepareMediaFromImage(
|
||||
std::move(copy),
|
||||
QByteArray(),
|
||||
previewWidth);
|
||||
|
||||
using ImageInfo = Ui::PreparedFileInformation::Image;
|
||||
auto &file = _preparedList.files.front();
|
||||
const auto image = std::get_if<ImageInfo>(
|
||||
&file.information->media);
|
||||
|
||||
image->modifications = mods;
|
||||
Storage::UpdateImageDetails(file, previewWidth);
|
||||
updateEditPreview();
|
||||
};
|
||||
const auto fileImage = std::make_shared<Image>(*computeImage());
|
||||
controller->showLayer(
|
||||
std::make_unique<Editor::LayerWidget>(
|
||||
this,
|
||||
&controller->window(),
|
||||
fileImage,
|
||||
Editor::PhotoModifications(),
|
||||
std::move(callback)),
|
||||
Ui::LayerOption::KeepOther);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
EditCaptionBox::~EditCaptionBox() = default;
|
||||
|
@ -1048,6 +1091,8 @@ void EditCaptionBox::save() {
|
|||
action.options = options;
|
||||
action.replaceMediaOf = item->fullId().msg;
|
||||
|
||||
Storage::ApplyModifications(_preparedList);
|
||||
|
||||
_controller->session().api().editMedia(
|
||||
std::move(_preparedList),
|
||||
(!_asFile && _photo) ? SendMediaType::Photo : SendMediaType::File,
|
||||
|
|
|
@ -621,33 +621,12 @@ void SendFilesBox::pushBlock(int from, int till) {
|
|||
|
||||
block.itemModifyRequest(
|
||||
) | rpl::start_with_next([=, controller = _controller](int index) {
|
||||
auto &file = _list.files[index];
|
||||
if (file.type != Ui::PreparedFile::Type::Photo) {
|
||||
return;
|
||||
}
|
||||
using ImageInfo = Ui::PreparedFileInformation::Image;
|
||||
const auto image = std::get_if<ImageInfo>(&file.information->media);
|
||||
if (!image) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto callback = [=](const Editor::PhotoModifications &mods) {
|
||||
image->modifications = mods;
|
||||
Storage::UpdateImageDetails(
|
||||
_list.files[index],
|
||||
st::sendMediaPreviewSize);
|
||||
refreshAllAfterChanges(from);
|
||||
};
|
||||
auto copy = image->data;
|
||||
const auto fileImage = std::make_shared<Image>(std::move(copy));
|
||||
controller->showLayer(
|
||||
std::make_unique<Editor::LayerWidget>(
|
||||
this,
|
||||
&controller->window(),
|
||||
fileImage,
|
||||
image->modifications,
|
||||
std::move(callback)),
|
||||
Ui::LayerOption::KeepOther);
|
||||
Editor::OpenWithPreparedFile(
|
||||
this,
|
||||
controller,
|
||||
&_list.files[index],
|
||||
st::sendMediaPreviewSize,
|
||||
[=] { refreshAllAfterChanges(from); });
|
||||
}, widget->lifetime());
|
||||
}
|
||||
|
||||
|
|
|
@ -294,7 +294,10 @@ style::margins Crop::cropMargins() const {
|
|||
}
|
||||
|
||||
QRect Crop::saveCropRect() {
|
||||
return _cropOriginal.toRect();
|
||||
const auto savedCrop = _cropOriginal.toRect();
|
||||
return (!savedCrop.topLeft().isNull() || (savedCrop.size() != _imageSize))
|
||||
? savedCrop
|
||||
: QRect();
|
||||
}
|
||||
|
||||
} // namespace Editor
|
||||
|
|
|
@ -166,7 +166,11 @@ void Paint::initDrawing() {
|
|||
}
|
||||
|
||||
std::shared_ptr<QGraphicsScene> Paint::saveScene() const {
|
||||
return _scene;
|
||||
return _scene->items().empty()
|
||||
? nullptr
|
||||
: ranges::none_of(_scene->items(), &QGraphicsItem::isVisible)
|
||||
? nullptr
|
||||
: _scene;
|
||||
}
|
||||
|
||||
void Paint::cancel() {
|
||||
|
|
|
@ -33,7 +33,7 @@ QImage ImageModified(QImage image, const PhotoModifications &mods) {
|
|||
}
|
||||
|
||||
bool PhotoModifications::empty() const {
|
||||
return !angle && !flipped && !crop.isValid();
|
||||
return !angle && !flipped && !crop.isValid() && !paint;
|
||||
}
|
||||
|
||||
PhotoModifications::operator bool() const {
|
||||
|
|
|
@ -8,9 +8,46 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "editor/photo_editor_layer_widget.h"
|
||||
|
||||
#include "editor/photo_editor.h"
|
||||
#include "storage/storage_media_prepare.h"
|
||||
#include "ui/chat/attach/attach_prepare.h"
|
||||
#include "window/window_session_controller.h"
|
||||
|
||||
namespace Editor {
|
||||
|
||||
void OpenWithPreparedFile(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::PreparedFile*> file,
|
||||
int previewWidth,
|
||||
Fn<void()> &&doneCallback) {
|
||||
|
||||
if (file->type != Ui::PreparedFile::Type::Photo) {
|
||||
return;
|
||||
}
|
||||
using ImageInfo = Ui::PreparedFileInformation::Image;
|
||||
const auto image = std::get_if<ImageInfo>(&file->information->media);
|
||||
if (!image) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto callback = [=, done = std::move(doneCallback)](
|
||||
const PhotoModifications &mods) {
|
||||
image->modifications = mods;
|
||||
Storage::UpdateImageDetails(*file, previewWidth);
|
||||
done();
|
||||
};
|
||||
auto copy = image->data;
|
||||
const auto fileImage = std::make_shared<Image>(std::move(copy));
|
||||
controller->showLayer(
|
||||
std::make_unique<LayerWidget>(
|
||||
parent,
|
||||
&controller->window(),
|
||||
fileImage,
|
||||
image->modifications,
|
||||
std::move(callback)),
|
||||
Ui::LayerOption::KeepOther);
|
||||
}
|
||||
|
||||
LayerWidget::LayerWidget(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
not_null<Window::Controller*> window,
|
||||
|
@ -38,7 +75,7 @@ LayerWidget::LayerWidget(
|
|||
_content->doneRequests(
|
||||
) | rpl::start_with_next([=, done = std::move(doneCallback)](
|
||||
const PhotoModifications &mods) {
|
||||
doneCallback(mods);
|
||||
done(mods);
|
||||
closeLayer();
|
||||
}, lifetime());
|
||||
|
||||
|
|
|
@ -13,12 +13,24 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "editor/photo_editor_common.h"
|
||||
#include "ui/image/image.h"
|
||||
|
||||
namespace Ui {
|
||||
struct PreparedFile;
|
||||
} // namespace Ui
|
||||
|
||||
namespace Window {
|
||||
class Controller;
|
||||
class SessionController;
|
||||
} // namespace Window
|
||||
|
||||
namespace Editor {
|
||||
|
||||
void OpenWithPreparedFile(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::PreparedFile*> file,
|
||||
int previewWidth,
|
||||
Fn<void()> &&doneCallback);
|
||||
|
||||
class PhotoEditor;
|
||||
|
||||
class LayerWidget : public Ui::LayerWidget {
|
||||
|
|
Loading…
Add table
Reference in a new issue