mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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_helpers.h"
|
||||||
#include "styles/style_chat.h"
|
#include "styles/style_chat.h"
|
||||||
|
|
||||||
|
#include "editor/photo_editor_layer_widget.h"
|
||||||
|
|
||||||
#include <QtCore/QMimeData>
|
#include <QtCore/QMimeData>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -402,6 +404,47 @@ EditCaptionBox::EditCaptionBox(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
closeBox();
|
closeBox();
|
||||||
}, lifetime());
|
}, 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;
|
EditCaptionBox::~EditCaptionBox() = default;
|
||||||
|
@ -1048,6 +1091,8 @@ void EditCaptionBox::save() {
|
||||||
action.options = options;
|
action.options = options;
|
||||||
action.replaceMediaOf = item->fullId().msg;
|
action.replaceMediaOf = item->fullId().msg;
|
||||||
|
|
||||||
|
Storage::ApplyModifications(_preparedList);
|
||||||
|
|
||||||
_controller->session().api().editMedia(
|
_controller->session().api().editMedia(
|
||||||
std::move(_preparedList),
|
std::move(_preparedList),
|
||||||
(!_asFile && _photo) ? SendMediaType::Photo : SendMediaType::File,
|
(!_asFile && _photo) ? SendMediaType::Photo : SendMediaType::File,
|
||||||
|
|
|
@ -621,33 +621,12 @@ void SendFilesBox::pushBlock(int from, int till) {
|
||||||
|
|
||||||
block.itemModifyRequest(
|
block.itemModifyRequest(
|
||||||
) | rpl::start_with_next([=, controller = _controller](int index) {
|
) | rpl::start_with_next([=, controller = _controller](int index) {
|
||||||
auto &file = _list.files[index];
|
Editor::OpenWithPreparedFile(
|
||||||
if (file.type != Ui::PreparedFile::Type::Photo) {
|
this,
|
||||||
return;
|
controller,
|
||||||
}
|
&_list.files[index],
|
||||||
using ImageInfo = Ui::PreparedFileInformation::Image;
|
st::sendMediaPreviewSize,
|
||||||
const auto image = std::get_if<ImageInfo>(&file.information->media);
|
[=] { refreshAllAfterChanges(from); });
|
||||||
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);
|
|
||||||
}, widget->lifetime());
|
}, widget->lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -294,7 +294,10 @@ style::margins Crop::cropMargins() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
QRect Crop::saveCropRect() {
|
QRect Crop::saveCropRect() {
|
||||||
return _cropOriginal.toRect();
|
const auto savedCrop = _cropOriginal.toRect();
|
||||||
|
return (!savedCrop.topLeft().isNull() || (savedCrop.size() != _imageSize))
|
||||||
|
? savedCrop
|
||||||
|
: QRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Editor
|
} // namespace Editor
|
||||||
|
|
|
@ -166,7 +166,11 @@ void Paint::initDrawing() {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<QGraphicsScene> Paint::saveScene() const {
|
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() {
|
void Paint::cancel() {
|
||||||
|
|
|
@ -33,7 +33,7 @@ QImage ImageModified(QImage image, const PhotoModifications &mods) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PhotoModifications::empty() const {
|
bool PhotoModifications::empty() const {
|
||||||
return !angle && !flipped && !crop.isValid();
|
return !angle && !flipped && !crop.isValid() && !paint;
|
||||||
}
|
}
|
||||||
|
|
||||||
PhotoModifications::operator bool() const {
|
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_layer_widget.h"
|
||||||
|
|
||||||
#include "editor/photo_editor.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 {
|
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(
|
LayerWidget::LayerWidget(
|
||||||
not_null<Ui::RpWidget*> parent,
|
not_null<Ui::RpWidget*> parent,
|
||||||
not_null<Window::Controller*> window,
|
not_null<Window::Controller*> window,
|
||||||
|
@ -38,7 +75,7 @@ LayerWidget::LayerWidget(
|
||||||
_content->doneRequests(
|
_content->doneRequests(
|
||||||
) | rpl::start_with_next([=, done = std::move(doneCallback)](
|
) | rpl::start_with_next([=, done = std::move(doneCallback)](
|
||||||
const PhotoModifications &mods) {
|
const PhotoModifications &mods) {
|
||||||
doneCallback(mods);
|
done(mods);
|
||||||
closeLayer();
|
closeLayer();
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
|
|
|
@ -13,12 +13,24 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "editor/photo_editor_common.h"
|
#include "editor/photo_editor_common.h"
|
||||||
#include "ui/image/image.h"
|
#include "ui/image/image.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
struct PreparedFile;
|
||||||
|
} // namespace Ui
|
||||||
|
|
||||||
namespace Window {
|
namespace Window {
|
||||||
class Controller;
|
class Controller;
|
||||||
|
class SessionController;
|
||||||
} // namespace Window
|
} // namespace Window
|
||||||
|
|
||||||
namespace Editor {
|
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 PhotoEditor;
|
||||||
|
|
||||||
class LayerWidget : public Ui::LayerWidget {
|
class LayerWidget : public Ui::LayerWidget {
|
||||||
|
|
Loading…
Add table
Reference in a new issue