mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added ability to pass data for photo editor.
This commit is contained in:
parent
a2e674bdb6
commit
2045252cfd
9 changed files with 44 additions and 13 deletions
|
@ -44,7 +44,8 @@ QSizeF FlipSizeByRotation(const QSizeF &size, int angle) {
|
||||||
Crop::Crop(
|
Crop::Crop(
|
||||||
not_null<Ui::RpWidget*> parent,
|
not_null<Ui::RpWidget*> parent,
|
||||||
const PhotoModifications &modifications,
|
const PhotoModifications &modifications,
|
||||||
const QSize &imageSize)
|
const QSize &imageSize,
|
||||||
|
EditorData data)
|
||||||
: RpWidget(parent)
|
: RpWidget(parent)
|
||||||
, _pointSize(st::cropPointSize)
|
, _pointSize(st::cropPointSize)
|
||||||
, _pointSizeH(_pointSize / 2.)
|
, _pointSizeH(_pointSize / 2.)
|
||||||
|
@ -53,11 +54,13 @@ Crop::Crop(
|
||||||
, _offset(_innerMargins.left(), _innerMargins.top())
|
, _offset(_innerMargins.left(), _innerMargins.top())
|
||||||
, _edgePointMargins(_pointSizeH, _pointSizeH, -_pointSizeH, -_pointSizeH)
|
, _edgePointMargins(_pointSizeH, _pointSizeH, -_pointSizeH, -_pointSizeH)
|
||||||
, _imageSize(imageSize)
|
, _imageSize(imageSize)
|
||||||
|
, _data(std::move(data))
|
||||||
, _cropOriginal(modifications.crop.isValid()
|
, _cropOriginal(modifications.crop.isValid()
|
||||||
? modifications.crop
|
? modifications.crop
|
||||||
: QRectF(QPoint(), _imageSize))
|
: QRectF(QPoint(), _imageSize))
|
||||||
, _angle(modifications.angle)
|
, _angle(modifications.angle)
|
||||||
, _flipped(modifications.flipped) {
|
, _flipped(modifications.flipped)
|
||||||
|
, _keepAspectRatio(_data.keepAspectRatio) {
|
||||||
|
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
|
|
||||||
|
@ -140,7 +143,11 @@ void Crop::setCropPaint(QRectF &&rect) {
|
||||||
|
|
||||||
_painterPath.clear();
|
_painterPath.clear();
|
||||||
_painterPath.addRect(_innerRect);
|
_painterPath.addRect(_innerRect);
|
||||||
_painterPath.addRect(_cropPaint);
|
if (_data.cropType == EditorData::CropType::Ellipse) {
|
||||||
|
_painterPath.addEllipse(_cropPaint);
|
||||||
|
} else {
|
||||||
|
_painterPath.addRect(_cropPaint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Crop::convertCropPaintToOriginal() {
|
void Crop::convertCropPaintToOriginal() {
|
||||||
|
|
|
@ -20,7 +20,8 @@ public:
|
||||||
Crop(
|
Crop(
|
||||||
not_null<Ui::RpWidget*> parent,
|
not_null<Ui::RpWidget*> parent,
|
||||||
const PhotoModifications &modifications,
|
const PhotoModifications &modifications,
|
||||||
const QSize &imageSize);
|
const QSize &imageSize,
|
||||||
|
EditorData type);
|
||||||
|
|
||||||
void applyTransform(
|
void applyTransform(
|
||||||
const QRect &geometry,
|
const QRect &geometry,
|
||||||
|
@ -68,6 +69,7 @@ private:
|
||||||
const QPoint _offset;
|
const QPoint _offset;
|
||||||
const QMarginsF _edgePointMargins;
|
const QMarginsF _edgePointMargins;
|
||||||
const QSize _imageSize;
|
const QSize _imageSize;
|
||||||
|
const EditorData _data;
|
||||||
|
|
||||||
base::flat_map<Qt::Edges, QRectF> _edges;
|
base::flat_map<Qt::Edges, QRectF> _edges;
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,8 @@ constexpr auto kPrecision = 100000;
|
||||||
PhotoEditor::PhotoEditor(
|
PhotoEditor::PhotoEditor(
|
||||||
not_null<Ui::RpWidget*> parent,
|
not_null<Ui::RpWidget*> parent,
|
||||||
std::shared_ptr<Image> photo,
|
std::shared_ptr<Image> photo,
|
||||||
PhotoModifications modifications)
|
PhotoModifications modifications,
|
||||||
|
EditorData data)
|
||||||
: RpWidget(parent)
|
: RpWidget(parent)
|
||||||
, _modifications(std::move(modifications))
|
, _modifications(std::move(modifications))
|
||||||
, _undoController(std::make_shared<UndoController>())
|
, _undoController(std::make_shared<UndoController>())
|
||||||
|
@ -54,7 +55,8 @@ PhotoEditor::PhotoEditor(
|
||||||
this,
|
this,
|
||||||
photo,
|
photo,
|
||||||
_modifications,
|
_modifications,
|
||||||
_undoController))
|
_undoController,
|
||||||
|
std::move(data)))
|
||||||
, _controls(base::make_unique_q<PhotoEditorControls>(this, _undoController))
|
, _controls(base::make_unique_q<PhotoEditorControls>(this, _undoController))
|
||||||
, _colorPicker(std::make_unique<ColorPicker>(
|
, _colorPicker(std::make_unique<ColorPicker>(
|
||||||
this,
|
this,
|
||||||
|
|
|
@ -25,7 +25,8 @@ public:
|
||||||
PhotoEditor(
|
PhotoEditor(
|
||||||
not_null<Ui::RpWidget*> parent,
|
not_null<Ui::RpWidget*> parent,
|
||||||
std::shared_ptr<Image> photo,
|
std::shared_ptr<Image> photo,
|
||||||
PhotoModifications modifications);
|
PhotoModifications modifications,
|
||||||
|
EditorData data = EditorData());
|
||||||
|
|
||||||
void save();
|
void save();
|
||||||
rpl::producer<PhotoModifications> doneRequests() const;
|
rpl::producer<PhotoModifications> doneRequests() const;
|
||||||
|
|
|
@ -36,6 +36,16 @@ struct PhotoModifications {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct EditorData {
|
||||||
|
enum class CropType {
|
||||||
|
Rect,
|
||||||
|
Ellipse,
|
||||||
|
};
|
||||||
|
|
||||||
|
CropType cropType = CropType::Rect;
|
||||||
|
bool keepAspectRatio = false;
|
||||||
|
};
|
||||||
|
|
||||||
struct Brush {
|
struct Brush {
|
||||||
float sizeRatio = 0.;
|
float sizeRatio = 0.;
|
||||||
QColor color;
|
QColor color;
|
||||||
|
|
|
@ -20,7 +20,8 @@ PhotoEditorContent::PhotoEditorContent(
|
||||||
not_null<Ui::RpWidget*> parent,
|
not_null<Ui::RpWidget*> parent,
|
||||||
std::shared_ptr<Image> photo,
|
std::shared_ptr<Image> photo,
|
||||||
PhotoModifications modifications,
|
PhotoModifications modifications,
|
||||||
std::shared_ptr<UndoController> undoController)
|
std::shared_ptr<UndoController> undoController,
|
||||||
|
EditorData data)
|
||||||
: RpWidget(parent)
|
: RpWidget(parent)
|
||||||
, _photoSize(photo->size())
|
, _photoSize(photo->size())
|
||||||
, _paint(base::make_unique_q<Paint>(
|
, _paint(base::make_unique_q<Paint>(
|
||||||
|
@ -28,7 +29,11 @@ PhotoEditorContent::PhotoEditorContent(
|
||||||
modifications,
|
modifications,
|
||||||
_photoSize,
|
_photoSize,
|
||||||
std::move(undoController)))
|
std::move(undoController)))
|
||||||
, _crop(base::make_unique_q<Crop>(this, modifications, _photoSize))
|
, _crop(base::make_unique_q<Crop>(
|
||||||
|
this,
|
||||||
|
modifications,
|
||||||
|
_photoSize,
|
||||||
|
std::move(data)))
|
||||||
, _photo(std::move(photo))
|
, _photo(std::move(photo))
|
||||||
, _modifications(modifications) {
|
, _modifications(modifications) {
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,8 @@ public:
|
||||||
not_null<Ui::RpWidget*> parent,
|
not_null<Ui::RpWidget*> parent,
|
||||||
std::shared_ptr<Image> photo,
|
std::shared_ptr<Image> photo,
|
||||||
PhotoModifications modifications,
|
PhotoModifications modifications,
|
||||||
std::shared_ptr<UndoController> undoController);
|
std::shared_ptr<UndoController> undoController,
|
||||||
|
EditorData data);
|
||||||
|
|
||||||
void applyModifications(PhotoModifications modifications);
|
void applyModifications(PhotoModifications modifications);
|
||||||
void applyMode(const PhotoEditorMode &mode);
|
void applyMode(const PhotoEditorMode &mode);
|
||||||
|
|
|
@ -53,12 +53,14 @@ LayerWidget::LayerWidget(
|
||||||
not_null<Window::Controller*> window,
|
not_null<Window::Controller*> window,
|
||||||
std::shared_ptr<Image> photo,
|
std::shared_ptr<Image> photo,
|
||||||
PhotoModifications modifications,
|
PhotoModifications modifications,
|
||||||
Fn<void(PhotoModifications)> &&doneCallback)
|
Fn<void(PhotoModifications)> &&doneCallback,
|
||||||
|
EditorData data)
|
||||||
: Ui::LayerWidget(parent)
|
: Ui::LayerWidget(parent)
|
||||||
, _content(base::make_unique_q<PhotoEditor>(
|
, _content(base::make_unique_q<PhotoEditor>(
|
||||||
this,
|
this,
|
||||||
photo,
|
photo,
|
||||||
std::move(modifications))) {
|
std::move(modifications),
|
||||||
|
std::move(data))) {
|
||||||
|
|
||||||
paintRequest(
|
paintRequest(
|
||||||
) | rpl::start_with_next([=](const QRect &clip) {
|
) | rpl::start_with_next([=](const QRect &clip) {
|
||||||
|
|
|
@ -40,7 +40,8 @@ public:
|
||||||
not_null<Window::Controller*> window,
|
not_null<Window::Controller*> window,
|
||||||
std::shared_ptr<Image> photo,
|
std::shared_ptr<Image> photo,
|
||||||
PhotoModifications modifications,
|
PhotoModifications modifications,
|
||||||
Fn<void(PhotoModifications)> &&doneCallback);
|
Fn<void(PhotoModifications)> &&doneCallback,
|
||||||
|
EditorData data = EditorData());
|
||||||
|
|
||||||
void parentResized() override;
|
void parentResized() override;
|
||||||
bool closeByOutsideClick() const override;
|
bool closeByOutsideClick() const override;
|
||||||
|
|
Loading…
Add table
Reference in a new issue