mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Replaced using of QPixmap in photo editor with Image.
This commit is contained in:
parent
3ce315111f
commit
671a06c407
7 changed files with 27 additions and 25 deletions
|
@ -619,23 +619,18 @@ void SendFilesBox::pushBlock(int from, int till) {
|
|||
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);
|
||||
using ImageInfo = Ui::PreparedFileInformation::Image;
|
||||
const auto image = std::get_if<ImageInfo>(&file.information->media);
|
||||
if (!image) {
|
||||
return;
|
||||
}
|
||||
|
||||
*pp = QPixmap::fromImage(
|
||||
image->data,
|
||||
Qt::ColorOnly);
|
||||
|
||||
auto callback = [=](const Editor::PhotoModifications &mods) {
|
||||
image->modifications = mods;
|
||||
Storage::UpdateImageDetails(
|
||||
|
@ -643,12 +638,13 @@ void SendFilesBox::pushBlock(int from, int till) {
|
|||
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(),
|
||||
pp,
|
||||
fileImage,
|
||||
image->modifications,
|
||||
std::move(callback)),
|
||||
Ui::LayerOption::KeepOther);
|
||||
|
|
|
@ -45,7 +45,7 @@ constexpr auto kPrecision = 100000;
|
|||
|
||||
PhotoEditor::PhotoEditor(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
std::shared_ptr<QPixmap> photo,
|
||||
std::shared_ptr<Image> photo,
|
||||
PhotoModifications modifications)
|
||||
: RpWidget(parent)
|
||||
, _modifications(std::move(modifications))
|
||||
|
|
|
@ -9,9 +9,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "ui/rp_widget.h"
|
||||
|
||||
#include "editor/photo_editor_common.h"
|
||||
|
||||
#include "base/unique_qptr.h"
|
||||
#include "editor/photo_editor_common.h"
|
||||
#include "ui/image/image.h"
|
||||
|
||||
namespace Editor {
|
||||
|
||||
|
@ -24,7 +24,7 @@ class PhotoEditor final : public Ui::RpWidget {
|
|||
public:
|
||||
PhotoEditor(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
std::shared_ptr<QPixmap> photo,
|
||||
std::shared_ptr<Image> photo,
|
||||
PhotoModifications modifications);
|
||||
|
||||
void save();
|
||||
|
|
|
@ -18,17 +18,18 @@ using Media::View::RotatedRect;
|
|||
|
||||
PhotoEditorContent::PhotoEditorContent(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
std::shared_ptr<QPixmap> photo,
|
||||
std::shared_ptr<Image> photo,
|
||||
PhotoModifications modifications,
|
||||
std::shared_ptr<UndoController> undoController)
|
||||
: RpWidget(parent)
|
||||
, _photoSize(photo->size())
|
||||
, _paint(base::make_unique_q<Paint>(
|
||||
this,
|
||||
modifications,
|
||||
photo->size(),
|
||||
_photoSize,
|
||||
std::move(undoController)))
|
||||
, _crop(base::make_unique_q<Crop>(this, modifications, photo->size()))
|
||||
, _photo(photo)
|
||||
, _crop(base::make_unique_q<Crop>(this, modifications, _photoSize))
|
||||
, _photo(std::move(photo))
|
||||
, _modifications(modifications) {
|
||||
|
||||
rpl::combine(
|
||||
|
@ -45,7 +46,7 @@ PhotoEditorContent::PhotoEditorContent(
|
|||
const auto m = _crop->cropMargins();
|
||||
const auto sizeForCrop = rotatedSize
|
||||
- QSize(m.left() + m.right(), m.top() + m.bottom());
|
||||
const auto originalSize = QSizeF(photo->size());
|
||||
const auto originalSize = QSizeF(_photoSize);
|
||||
if ((originalSize.width() > sizeForCrop.width())
|
||||
|| (originalSize.height() > sizeForCrop.height())) {
|
||||
return originalSize.scaled(
|
||||
|
@ -82,7 +83,9 @@ PhotoEditorContent::PhotoEditorContent(
|
|||
|
||||
p.setMatrix(_imageMatrix);
|
||||
|
||||
p.drawPixmap(_imageRect, *photo);
|
||||
p.drawPixmap(
|
||||
_imageRect,
|
||||
_photo->pix(_imageRect.width(), _imageRect.height()));
|
||||
}, lifetime());
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/rp_widget.h"
|
||||
|
||||
#include "editor/photo_editor_common.h"
|
||||
#include "ui/image/image.h"
|
||||
|
||||
namespace Editor {
|
||||
|
||||
|
@ -21,7 +22,7 @@ class PhotoEditorContent final : public Ui::RpWidget {
|
|||
public:
|
||||
PhotoEditorContent(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
std::shared_ptr<QPixmap> photo,
|
||||
std::shared_ptr<Image> photo,
|
||||
PhotoModifications modifications,
|
||||
std::shared_ptr<UndoController> undoController);
|
||||
|
||||
|
@ -32,9 +33,10 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
const QSize _photoSize;
|
||||
const base::unique_qptr<Paint> _paint;
|
||||
const base::unique_qptr<Crop> _crop;
|
||||
const std::shared_ptr<QPixmap> _photo;
|
||||
const std::shared_ptr<Image> _photo;
|
||||
|
||||
rpl::variable<PhotoModifications> _modifications;
|
||||
|
||||
|
|
|
@ -14,13 +14,13 @@ namespace Editor {
|
|||
LayerWidget::LayerWidget(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
not_null<Window::Controller*> window,
|
||||
std::shared_ptr<QPixmap> photo,
|
||||
std::shared_ptr<Image> photo,
|
||||
PhotoModifications modifications,
|
||||
Fn<void(PhotoModifications)> &&doneCallback)
|
||||
: Ui::LayerWidget(parent)
|
||||
, _content(base::make_unique_q<PhotoEditor>(
|
||||
this,
|
||||
std::move(photo),
|
||||
photo,
|
||||
std::move(modifications))) {
|
||||
|
||||
paintRequest(
|
||||
|
|
|
@ -9,8 +9,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "ui/layers/layer_widget.h"
|
||||
|
||||
#include "editor/photo_editor_common.h"
|
||||
#include "base/unique_qptr.h"
|
||||
#include "editor/photo_editor_common.h"
|
||||
#include "ui/image/image.h"
|
||||
|
||||
namespace Window {
|
||||
class Controller;
|
||||
|
@ -25,7 +26,7 @@ public:
|
|||
LayerWidget(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
not_null<Window::Controller*> window,
|
||||
std::shared_ptr<QPixmap> photo,
|
||||
std::shared_ptr<Image> photo,
|
||||
PhotoModifications modifications,
|
||||
Fn<void(PhotoModifications)> &&doneCallback);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue