mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +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(
|
||||
not_null<Ui::RpWidget*> 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() {
|
||||
|
|
|
@ -20,7 +20,8 @@ public:
|
|||
Crop(
|
||||
not_null<Ui::RpWidget*> 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<Qt::Edges, QRectF> _edges;
|
||||
|
||||
|
|
|
@ -46,7 +46,8 @@ constexpr auto kPrecision = 100000;
|
|||
PhotoEditor::PhotoEditor(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
std::shared_ptr<Image> photo,
|
||||
PhotoModifications modifications)
|
||||
PhotoModifications modifications,
|
||||
EditorData data)
|
||||
: RpWidget(parent)
|
||||
, _modifications(std::move(modifications))
|
||||
, _undoController(std::make_shared<UndoController>())
|
||||
|
@ -54,7 +55,8 @@ PhotoEditor::PhotoEditor(
|
|||
this,
|
||||
photo,
|
||||
_modifications,
|
||||
_undoController))
|
||||
_undoController,
|
||||
std::move(data)))
|
||||
, _controls(base::make_unique_q<PhotoEditorControls>(this, _undoController))
|
||||
, _colorPicker(std::make_unique<ColorPicker>(
|
||||
this,
|
||||
|
|
|
@ -25,7 +25,8 @@ public:
|
|||
PhotoEditor(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
std::shared_ptr<Image> photo,
|
||||
PhotoModifications modifications);
|
||||
PhotoModifications modifications,
|
||||
EditorData data = EditorData());
|
||||
|
||||
void save();
|
||||
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 {
|
||||
float sizeRatio = 0.;
|
||||
QColor color;
|
||||
|
|
|
@ -20,7 +20,8 @@ PhotoEditorContent::PhotoEditorContent(
|
|||
not_null<Ui::RpWidget*> parent,
|
||||
std::shared_ptr<Image> photo,
|
||||
PhotoModifications modifications,
|
||||
std::shared_ptr<UndoController> undoController)
|
||||
std::shared_ptr<UndoController> undoController,
|
||||
EditorData data)
|
||||
: RpWidget(parent)
|
||||
, _photoSize(photo->size())
|
||||
, _paint(base::make_unique_q<Paint>(
|
||||
|
@ -28,7 +29,11 @@ PhotoEditorContent::PhotoEditorContent(
|
|||
modifications,
|
||||
_photoSize,
|
||||
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))
|
||||
, _modifications(modifications) {
|
||||
|
||||
|
|
|
@ -24,7 +24,8 @@ public:
|
|||
not_null<Ui::RpWidget*> parent,
|
||||
std::shared_ptr<Image> photo,
|
||||
PhotoModifications modifications,
|
||||
std::shared_ptr<UndoController> undoController);
|
||||
std::shared_ptr<UndoController> undoController,
|
||||
EditorData data);
|
||||
|
||||
void applyModifications(PhotoModifications modifications);
|
||||
void applyMode(const PhotoEditorMode &mode);
|
||||
|
|
|
@ -53,12 +53,14 @@ LayerWidget::LayerWidget(
|
|||
not_null<Window::Controller*> window,
|
||||
std::shared_ptr<Image> photo,
|
||||
PhotoModifications modifications,
|
||||
Fn<void(PhotoModifications)> &&doneCallback)
|
||||
Fn<void(PhotoModifications)> &&doneCallback,
|
||||
EditorData data)
|
||||
: Ui::LayerWidget(parent)
|
||||
, _content(base::make_unique_q<PhotoEditor>(
|
||||
this,
|
||||
photo,
|
||||
std::move(modifications))) {
|
||||
std::move(modifications),
|
||||
std::move(data))) {
|
||||
|
||||
paintRequest(
|
||||
) | rpl::start_with_next([=](const QRect &clip) {
|
||||
|
|
|
@ -40,7 +40,8 @@ public:
|
|||
not_null<Window::Controller*> window,
|
||||
std::shared_ptr<Image> photo,
|
||||
PhotoModifications modifications,
|
||||
Fn<void(PhotoModifications)> &&doneCallback);
|
||||
Fn<void(PhotoModifications)> &&doneCallback,
|
||||
EditorData data = EditorData());
|
||||
|
||||
void parentResized() override;
|
||||
bool closeByOutsideClick() const override;
|
||||
|
|
Loading…
Add table
Reference in a new issue