diff --git a/Telegram/SourceFiles/editor/editor_crop.cpp b/Telegram/SourceFiles/editor/editor_crop.cpp index 0d72e8d08..49bd4caa7 100644 --- a/Telegram/SourceFiles/editor/editor_crop.cpp +++ b/Telegram/SourceFiles/editor/editor_crop.cpp @@ -44,7 +44,8 @@ QSizeF FlipSizeByRotation(const QSizeF &size, int angle) { Crop::Crop( not_null parent, const PhotoModifications &modifications, - const QSize &imageSize) + const QSize &imageSize, + EditorData data) : RpWidget(parent) , _pointSize(st::cropPointSize) , _pointSizeH(_pointSize / 2.) @@ -53,11 +54,13 @@ Crop::Crop( , _offset(_innerMargins.left(), _innerMargins.top()) , _edgePointMargins(_pointSizeH, _pointSizeH, -_pointSizeH, -_pointSizeH) , _imageSize(imageSize) +, _data(std::move(data)) , _cropOriginal(modifications.crop.isValid() ? modifications.crop : QRectF(QPoint(), _imageSize)) , _angle(modifications.angle) -, _flipped(modifications.flipped) { +, _flipped(modifications.flipped) +, _keepAspectRatio(_data.keepAspectRatio) { setMouseTracking(true); @@ -140,7 +143,11 @@ void Crop::setCropPaint(QRectF &&rect) { _painterPath.clear(); _painterPath.addRect(_innerRect); - _painterPath.addRect(_cropPaint); + if (_data.cropType == EditorData::CropType::Ellipse) { + _painterPath.addEllipse(_cropPaint); + } else { + _painterPath.addRect(_cropPaint); + } } void Crop::convertCropPaintToOriginal() { diff --git a/Telegram/SourceFiles/editor/editor_crop.h b/Telegram/SourceFiles/editor/editor_crop.h index f0290f6f2..490d00aad 100644 --- a/Telegram/SourceFiles/editor/editor_crop.h +++ b/Telegram/SourceFiles/editor/editor_crop.h @@ -20,7 +20,8 @@ public: Crop( not_null parent, const PhotoModifications &modifications, - const QSize &imageSize); + const QSize &imageSize, + EditorData type); void applyTransform( const QRect &geometry, @@ -68,6 +69,7 @@ private: const QPoint _offset; const QMarginsF _edgePointMargins; const QSize _imageSize; + const EditorData _data; base::flat_map _edges; diff --git a/Telegram/SourceFiles/editor/photo_editor.cpp b/Telegram/SourceFiles/editor/photo_editor.cpp index 3cca94298..cd2ad4136 100644 --- a/Telegram/SourceFiles/editor/photo_editor.cpp +++ b/Telegram/SourceFiles/editor/photo_editor.cpp @@ -46,7 +46,8 @@ constexpr auto kPrecision = 100000; PhotoEditor::PhotoEditor( not_null parent, std::shared_ptr photo, - PhotoModifications modifications) + PhotoModifications modifications, + EditorData data) : RpWidget(parent) , _modifications(std::move(modifications)) , _undoController(std::make_shared()) @@ -54,7 +55,8 @@ PhotoEditor::PhotoEditor( this, photo, _modifications, - _undoController)) + _undoController, + std::move(data))) , _controls(base::make_unique_q(this, _undoController)) , _colorPicker(std::make_unique( this, diff --git a/Telegram/SourceFiles/editor/photo_editor.h b/Telegram/SourceFiles/editor/photo_editor.h index 6d9c7cea9..275ffe59e 100644 --- a/Telegram/SourceFiles/editor/photo_editor.h +++ b/Telegram/SourceFiles/editor/photo_editor.h @@ -25,7 +25,8 @@ public: PhotoEditor( not_null parent, std::shared_ptr photo, - PhotoModifications modifications); + PhotoModifications modifications, + EditorData data = EditorData()); void save(); rpl::producer doneRequests() const; diff --git a/Telegram/SourceFiles/editor/photo_editor_common.h b/Telegram/SourceFiles/editor/photo_editor_common.h index b45991315..3c9708058 100644 --- a/Telegram/SourceFiles/editor/photo_editor_common.h +++ b/Telegram/SourceFiles/editor/photo_editor_common.h @@ -36,6 +36,16 @@ struct PhotoModifications { }; +struct EditorData { + enum class CropType { + Rect, + Ellipse, + }; + + CropType cropType = CropType::Rect; + bool keepAspectRatio = false; +}; + struct Brush { float sizeRatio = 0.; QColor color; diff --git a/Telegram/SourceFiles/editor/photo_editor_content.cpp b/Telegram/SourceFiles/editor/photo_editor_content.cpp index 0564fe862..6311af681 100644 --- a/Telegram/SourceFiles/editor/photo_editor_content.cpp +++ b/Telegram/SourceFiles/editor/photo_editor_content.cpp @@ -20,7 +20,8 @@ PhotoEditorContent::PhotoEditorContent( not_null parent, std::shared_ptr photo, PhotoModifications modifications, - std::shared_ptr undoController) + std::shared_ptr undoController, + EditorData data) : RpWidget(parent) , _photoSize(photo->size()) , _paint(base::make_unique_q( @@ -28,7 +29,11 @@ PhotoEditorContent::PhotoEditorContent( modifications, _photoSize, std::move(undoController))) -, _crop(base::make_unique_q(this, modifications, _photoSize)) +, _crop(base::make_unique_q( + this, + modifications, + _photoSize, + std::move(data))) , _photo(std::move(photo)) , _modifications(modifications) { diff --git a/Telegram/SourceFiles/editor/photo_editor_content.h b/Telegram/SourceFiles/editor/photo_editor_content.h index a8ce390df..9290f8b3f 100644 --- a/Telegram/SourceFiles/editor/photo_editor_content.h +++ b/Telegram/SourceFiles/editor/photo_editor_content.h @@ -24,7 +24,8 @@ public: not_null parent, std::shared_ptr photo, PhotoModifications modifications, - std::shared_ptr undoController); + std::shared_ptr undoController, + EditorData data); void applyModifications(PhotoModifications modifications); void applyMode(const PhotoEditorMode &mode); diff --git a/Telegram/SourceFiles/editor/photo_editor_layer_widget.cpp b/Telegram/SourceFiles/editor/photo_editor_layer_widget.cpp index 58b6fccd2..7ddc06246 100644 --- a/Telegram/SourceFiles/editor/photo_editor_layer_widget.cpp +++ b/Telegram/SourceFiles/editor/photo_editor_layer_widget.cpp @@ -53,12 +53,14 @@ LayerWidget::LayerWidget( not_null window, std::shared_ptr photo, PhotoModifications modifications, - Fn &&doneCallback) + Fn &&doneCallback, + EditorData data) : Ui::LayerWidget(parent) , _content(base::make_unique_q( this, photo, - std::move(modifications))) { + std::move(modifications), + std::move(data))) { paintRequest( ) | rpl::start_with_next([=](const QRect &clip) { diff --git a/Telegram/SourceFiles/editor/photo_editor_layer_widget.h b/Telegram/SourceFiles/editor/photo_editor_layer_widget.h index 8d6842791..8b8041c9f 100644 --- a/Telegram/SourceFiles/editor/photo_editor_layer_widget.h +++ b/Telegram/SourceFiles/editor/photo_editor_layer_widget.h @@ -40,7 +40,8 @@ public: not_null window, std::shared_ptr photo, PhotoModifications modifications, - Fn &&doneCallback); + Fn &&doneCallback, + EditorData data = EditorData()); void parentResized() override; bool closeByOutsideClick() const override;