2021-02-08 07:01:15 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ui/rp_widget.h"
|
|
|
|
|
|
|
|
#include "base/flat_map.h"
|
|
|
|
#include "editor/photo_editor_common.h"
|
|
|
|
|
|
|
|
namespace Editor {
|
|
|
|
|
|
|
|
// Crop control.
|
|
|
|
class Crop final : public Ui::RpWidget {
|
|
|
|
public:
|
|
|
|
Crop(
|
|
|
|
not_null<Ui::RpWidget*> parent,
|
|
|
|
const PhotoModifications &modifications,
|
2021-02-21 07:28:37 +00:00
|
|
|
const QSize &imageSize,
|
|
|
|
EditorData type);
|
2021-02-08 07:01:15 +00:00
|
|
|
|
2021-02-18 06:37:12 +00:00
|
|
|
void applyTransform(
|
|
|
|
const QRect &geometry,
|
|
|
|
int angle,
|
|
|
|
bool flipped,
|
|
|
|
const QSizeF &scaledImageSize);
|
|
|
|
[[nodiscard]] QRect saveCropRect();
|
2021-02-08 07:01:15 +00:00
|
|
|
[[nodiscard]] style::margins cropMargins() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct InfoAtDown {
|
2021-02-18 06:37:12 +00:00
|
|
|
QRectF rect;
|
2021-07-06 21:54:56 +00:00
|
|
|
Qt::Edges edge;
|
2021-02-08 07:01:15 +00:00
|
|
|
QPoint point;
|
2021-02-21 11:51:32 +00:00
|
|
|
float64 cropRatio = 0.;
|
2021-02-08 07:01:15 +00:00
|
|
|
|
|
|
|
struct Borders {
|
|
|
|
int left = 0;
|
|
|
|
int right = 0;
|
|
|
|
int top = 0;
|
|
|
|
int bottom = 0;
|
|
|
|
} borders;
|
|
|
|
};
|
|
|
|
|
|
|
|
void paintPoints(Painter &p);
|
|
|
|
|
|
|
|
void updateEdges();
|
|
|
|
[[nodiscard]] QPoint pointOfEdge(Qt::Edges e) const;
|
2021-02-18 06:37:12 +00:00
|
|
|
void setCropPaint(QRectF &&rect);
|
|
|
|
void convertCropPaintToOriginal();
|
2021-02-08 07:01:15 +00:00
|
|
|
|
|
|
|
void computeDownState(const QPoint &p);
|
|
|
|
void clearDownState();
|
|
|
|
[[nodiscard]] Qt::Edges mouseState(const QPoint &p);
|
|
|
|
void performCrop(const QPoint &pos);
|
|
|
|
void performMove(const QPoint &pos);
|
|
|
|
|
|
|
|
const int _pointSize;
|
|
|
|
const float _pointSizeH;
|
|
|
|
const style::margins _innerMargins;
|
|
|
|
const QPoint _offset;
|
|
|
|
const QMarginsF _edgePointMargins;
|
2021-02-18 06:37:12 +00:00
|
|
|
const QSize _imageSize;
|
2021-02-21 07:28:37 +00:00
|
|
|
const EditorData _data;
|
2021-02-08 07:01:15 +00:00
|
|
|
|
|
|
|
base::flat_map<Qt::Edges, QRectF> _edges;
|
|
|
|
|
2021-02-18 06:37:12 +00:00
|
|
|
struct {
|
|
|
|
float64 w = 0.;
|
|
|
|
float64 h = 0.;
|
|
|
|
} _ratio;
|
2021-02-08 07:01:15 +00:00
|
|
|
|
2021-02-18 06:37:12 +00:00
|
|
|
QRectF _cropPaint;
|
|
|
|
QRectF _cropOriginal;
|
|
|
|
QRectF _innerRect;
|
2021-02-08 07:01:15 +00:00
|
|
|
|
|
|
|
QPainterPath _painterPath;
|
|
|
|
|
|
|
|
InfoAtDown _down;
|
|
|
|
|
|
|
|
int _angle = 0;
|
|
|
|
bool _flipped = false;
|
|
|
|
|
|
|
|
bool _keepAspectRatio = false;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Editor
|