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));
|
crl::guard(this, callback));
|
||||||
}, widget->lifetime());
|
}, widget->lifetime());
|
||||||
|
|
||||||
const auto pp = std::make_shared<QPixmap>();
|
|
||||||
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];
|
auto &file = _list.files[index];
|
||||||
if (file.type != Ui::PreparedFile::Type::Photo) {
|
if (file.type != Ui::PreparedFile::Type::Photo) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
using Image = Ui::PreparedFileInformation::Image;
|
using ImageInfo = Ui::PreparedFileInformation::Image;
|
||||||
const auto image = std::get_if<Image>(&file.information->media);
|
const auto image = std::get_if<ImageInfo>(&file.information->media);
|
||||||
if (!image) {
|
if (!image) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
*pp = QPixmap::fromImage(
|
|
||||||
image->data,
|
|
||||||
Qt::ColorOnly);
|
|
||||||
|
|
||||||
auto callback = [=](const Editor::PhotoModifications &mods) {
|
auto callback = [=](const Editor::PhotoModifications &mods) {
|
||||||
image->modifications = mods;
|
image->modifications = mods;
|
||||||
Storage::UpdateImageDetails(
|
Storage::UpdateImageDetails(
|
||||||
|
@ -643,12 +638,13 @@ void SendFilesBox::pushBlock(int from, int till) {
|
||||||
st::sendMediaPreviewSize);
|
st::sendMediaPreviewSize);
|
||||||
refreshAllAfterChanges(from);
|
refreshAllAfterChanges(from);
|
||||||
};
|
};
|
||||||
|
auto copy = image->data;
|
||||||
|
const auto fileImage = std::make_shared<Image>(std::move(copy));
|
||||||
controller->showLayer(
|
controller->showLayer(
|
||||||
std::make_unique<Editor::LayerWidget>(
|
std::make_unique<Editor::LayerWidget>(
|
||||||
this,
|
this,
|
||||||
&controller->window(),
|
&controller->window(),
|
||||||
pp,
|
fileImage,
|
||||||
image->modifications,
|
image->modifications,
|
||||||
std::move(callback)),
|
std::move(callback)),
|
||||||
Ui::LayerOption::KeepOther);
|
Ui::LayerOption::KeepOther);
|
||||||
|
|
|
@ -45,7 +45,7 @@ constexpr auto kPrecision = 100000;
|
||||||
|
|
||||||
PhotoEditor::PhotoEditor(
|
PhotoEditor::PhotoEditor(
|
||||||
not_null<Ui::RpWidget*> parent,
|
not_null<Ui::RpWidget*> parent,
|
||||||
std::shared_ptr<QPixmap> photo,
|
std::shared_ptr<Image> photo,
|
||||||
PhotoModifications modifications)
|
PhotoModifications modifications)
|
||||||
: RpWidget(parent)
|
: RpWidget(parent)
|
||||||
, _modifications(std::move(modifications))
|
, _modifications(std::move(modifications))
|
||||||
|
|
|
@ -9,9 +9,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include "ui/rp_widget.h"
|
#include "ui/rp_widget.h"
|
||||||
|
|
||||||
#include "editor/photo_editor_common.h"
|
|
||||||
|
|
||||||
#include "base/unique_qptr.h"
|
#include "base/unique_qptr.h"
|
||||||
|
#include "editor/photo_editor_common.h"
|
||||||
|
#include "ui/image/image.h"
|
||||||
|
|
||||||
namespace Editor {
|
namespace Editor {
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ class PhotoEditor final : public Ui::RpWidget {
|
||||||
public:
|
public:
|
||||||
PhotoEditor(
|
PhotoEditor(
|
||||||
not_null<Ui::RpWidget*> parent,
|
not_null<Ui::RpWidget*> parent,
|
||||||
std::shared_ptr<QPixmap> photo,
|
std::shared_ptr<Image> photo,
|
||||||
PhotoModifications modifications);
|
PhotoModifications modifications);
|
||||||
|
|
||||||
void save();
|
void save();
|
||||||
|
|
|
@ -18,17 +18,18 @@ using Media::View::RotatedRect;
|
||||||
|
|
||||||
PhotoEditorContent::PhotoEditorContent(
|
PhotoEditorContent::PhotoEditorContent(
|
||||||
not_null<Ui::RpWidget*> parent,
|
not_null<Ui::RpWidget*> parent,
|
||||||
std::shared_ptr<QPixmap> photo,
|
std::shared_ptr<Image> photo,
|
||||||
PhotoModifications modifications,
|
PhotoModifications modifications,
|
||||||
std::shared_ptr<UndoController> undoController)
|
std::shared_ptr<UndoController> undoController)
|
||||||
: RpWidget(parent)
|
: RpWidget(parent)
|
||||||
|
, _photoSize(photo->size())
|
||||||
, _paint(base::make_unique_q<Paint>(
|
, _paint(base::make_unique_q<Paint>(
|
||||||
this,
|
this,
|
||||||
modifications,
|
modifications,
|
||||||
photo->size(),
|
_photoSize,
|
||||||
std::move(undoController)))
|
std::move(undoController)))
|
||||||
, _crop(base::make_unique_q<Crop>(this, modifications, photo->size()))
|
, _crop(base::make_unique_q<Crop>(this, modifications, _photoSize))
|
||||||
, _photo(photo)
|
, _photo(std::move(photo))
|
||||||
, _modifications(modifications) {
|
, _modifications(modifications) {
|
||||||
|
|
||||||
rpl::combine(
|
rpl::combine(
|
||||||
|
@ -45,7 +46,7 @@ PhotoEditorContent::PhotoEditorContent(
|
||||||
const auto m = _crop->cropMargins();
|
const auto m = _crop->cropMargins();
|
||||||
const auto sizeForCrop = rotatedSize
|
const auto sizeForCrop = rotatedSize
|
||||||
- QSize(m.left() + m.right(), m.top() + m.bottom());
|
- 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())
|
if ((originalSize.width() > sizeForCrop.width())
|
||||||
|| (originalSize.height() > sizeForCrop.height())) {
|
|| (originalSize.height() > sizeForCrop.height())) {
|
||||||
return originalSize.scaled(
|
return originalSize.scaled(
|
||||||
|
@ -82,7 +83,9 @@ PhotoEditorContent::PhotoEditorContent(
|
||||||
|
|
||||||
p.setMatrix(_imageMatrix);
|
p.setMatrix(_imageMatrix);
|
||||||
|
|
||||||
p.drawPixmap(_imageRect, *photo);
|
p.drawPixmap(
|
||||||
|
_imageRect,
|
||||||
|
_photo->pix(_imageRect.width(), _imageRect.height()));
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/rp_widget.h"
|
#include "ui/rp_widget.h"
|
||||||
|
|
||||||
#include "editor/photo_editor_common.h"
|
#include "editor/photo_editor_common.h"
|
||||||
|
#include "ui/image/image.h"
|
||||||
|
|
||||||
namespace Editor {
|
namespace Editor {
|
||||||
|
|
||||||
|
@ -21,7 +22,7 @@ class PhotoEditorContent final : public Ui::RpWidget {
|
||||||
public:
|
public:
|
||||||
PhotoEditorContent(
|
PhotoEditorContent(
|
||||||
not_null<Ui::RpWidget*> parent,
|
not_null<Ui::RpWidget*> parent,
|
||||||
std::shared_ptr<QPixmap> photo,
|
std::shared_ptr<Image> photo,
|
||||||
PhotoModifications modifications,
|
PhotoModifications modifications,
|
||||||
std::shared_ptr<UndoController> undoController);
|
std::shared_ptr<UndoController> undoController);
|
||||||
|
|
||||||
|
@ -32,9 +33,10 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
const QSize _photoSize;
|
||||||
const base::unique_qptr<Paint> _paint;
|
const base::unique_qptr<Paint> _paint;
|
||||||
const base::unique_qptr<Crop> _crop;
|
const base::unique_qptr<Crop> _crop;
|
||||||
const std::shared_ptr<QPixmap> _photo;
|
const std::shared_ptr<Image> _photo;
|
||||||
|
|
||||||
rpl::variable<PhotoModifications> _modifications;
|
rpl::variable<PhotoModifications> _modifications;
|
||||||
|
|
||||||
|
|
|
@ -14,13 +14,13 @@ namespace Editor {
|
||||||
LayerWidget::LayerWidget(
|
LayerWidget::LayerWidget(
|
||||||
not_null<Ui::RpWidget*> parent,
|
not_null<Ui::RpWidget*> parent,
|
||||||
not_null<Window::Controller*> window,
|
not_null<Window::Controller*> window,
|
||||||
std::shared_ptr<QPixmap> photo,
|
std::shared_ptr<Image> photo,
|
||||||
PhotoModifications modifications,
|
PhotoModifications modifications,
|
||||||
Fn<void(PhotoModifications)> &&doneCallback)
|
Fn<void(PhotoModifications)> &&doneCallback)
|
||||||
: Ui::LayerWidget(parent)
|
: Ui::LayerWidget(parent)
|
||||||
, _content(base::make_unique_q<PhotoEditor>(
|
, _content(base::make_unique_q<PhotoEditor>(
|
||||||
this,
|
this,
|
||||||
std::move(photo),
|
photo,
|
||||||
std::move(modifications))) {
|
std::move(modifications))) {
|
||||||
|
|
||||||
paintRequest(
|
paintRequest(
|
||||||
|
|
|
@ -9,8 +9,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include "ui/layers/layer_widget.h"
|
#include "ui/layers/layer_widget.h"
|
||||||
|
|
||||||
#include "editor/photo_editor_common.h"
|
|
||||||
#include "base/unique_qptr.h"
|
#include "base/unique_qptr.h"
|
||||||
|
#include "editor/photo_editor_common.h"
|
||||||
|
#include "ui/image/image.h"
|
||||||
|
|
||||||
namespace Window {
|
namespace Window {
|
||||||
class Controller;
|
class Controller;
|
||||||
|
@ -25,7 +26,7 @@ public:
|
||||||
LayerWidget(
|
LayerWidget(
|
||||||
not_null<Ui::RpWidget*> parent,
|
not_null<Ui::RpWidget*> parent,
|
||||||
not_null<Window::Controller*> window,
|
not_null<Window::Controller*> window,
|
||||||
std::shared_ptr<QPixmap> photo,
|
std::shared_ptr<Image> photo,
|
||||||
PhotoModifications modifications,
|
PhotoModifications modifications,
|
||||||
Fn<void(PhotoModifications)> &&doneCallback);
|
Fn<void(PhotoModifications)> &&doneCallback);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue