Changed max and min sizes of scene items from pixels to ratio.

This commit is contained in:
23rd 2021-07-07 00:13:40 +03:00
parent d69090bf34
commit 8ddbf08a97
4 changed files with 17 additions and 6 deletions

View file

@ -92,5 +92,3 @@ photoEditorCropPointSize: 10px;
photoEditorCropMinSize: 20px; photoEditorCropMinSize: 20px;
photoEditorItemHandleSize: 10px; photoEditorItemHandleSize: 10px;
photoEditorItemMinSize: 32px;
photoEditorItemMaxSize: 512px;

View file

@ -299,6 +299,7 @@ ItemBase::Data Paint::itemBaseData() const {
.y = y, .y = y,
.flipped = _transform.flipped, .flipped = _transform.flipped,
.rotation = -_transform.angle, .rotation = -_transform.angle,
.imageSize = _imageSize,
}; };
} }

View file

@ -26,6 +26,9 @@ const auto kDuplicateSequence = QKeySequence("ctrl+d");
const auto kFlipSequence = QKeySequence("ctrl+s"); const auto kFlipSequence = QKeySequence("ctrl+s");
const auto kDeleteSequence = QKeySequence("delete"); const auto kDeleteSequence = QKeySequence("delete");
constexpr auto kMinSizeRatio = 0.05;
constexpr auto kMaxSizeRatio = 1.00;
auto Normalized(float64 angle) { auto Normalized(float64 angle) {
return angle return angle
+ ((std::abs(angle) < 360) ? 0 : (-360 * (angle < 0 ? -1 : 1))); + ((std::abs(angle) < 360) ? 0 : (-360 * (angle < 0 ? -1 : 1)));
@ -47,6 +50,7 @@ void NumberedItem::setNumber(int number) {
ItemBase::ItemBase(Data data) ItemBase::ItemBase(Data data)
: _lastZ(data.zPtr) : _lastZ(data.zPtr)
, _imageSize(data.imageSize)
, _horizontalSize(data.size) , _horizontalSize(data.size)
, _zoom(std::move(data.zoomValue)) { , _zoom(std::move(data.zoomValue)) {
setFlags(QGraphicsItem::ItemIsMovable setFlags(QGraphicsItem::ItemIsMovable
@ -67,14 +71,19 @@ ItemBase::ItemBase(Data data)
_scaledHandleSize, _scaledHandleSize,
_scaledHandleSize, _scaledHandleSize,
_scaledHandleSize) * 0.5; _scaledHandleSize) * 0.5;
const auto maxSide = std::max(
_imageSize.width(),
_imageSize.height());
_sizeLimits = { _sizeLimits = {
.min = int(st::photoEditorItemMinSize / zoom), .min = int(maxSide * kMinSizeRatio),
.max = int(st::photoEditorItemMaxSize / zoom), .max = int(maxSide * kMaxSizeRatio),
}; };
_horizontalSize = std::clamp( _horizontalSize = std::clamp(
_horizontalSize, _horizontalSize,
float64(_sizeLimits.min), float64(_sizeLimits.min),
float64(_sizeLimits.max)); float64(_sizeLimits.max));
updateVerticalSize();
updatePens(QPen( updatePens(QPen(
QBrush(), QBrush(),
@ -242,6 +251,7 @@ void ItemBase::actionDuplicate() {
.y = int(scenePos().y() + _verticalSize / 3), .y = int(scenePos().y() + _verticalSize / 3),
.flipped = flipped(), .flipped = flipped(),
.rotation = int(rotation()), .rotation = int(rotation()),
.imageSize = _imageSize,
}); });
if (hasFocus()) { if (hasFocus()) {
newItem->setFocus(); newItem->setFocus();
@ -308,8 +318,8 @@ void ItemBase::updateVerticalSize() {
const auto verticalSize = _horizontalSize * _aspectRatio; const auto verticalSize = _horizontalSize * _aspectRatio;
_verticalSize = std::max( _verticalSize = std::max(
verticalSize, verticalSize,
float64(st::photoEditorItemMinSize)); float64(_sizeLimits.min));
if (verticalSize < st::photoEditorItemMinSize) { if (verticalSize < _sizeLimits.min) {
_horizontalSize = _verticalSize / _aspectRatio; _horizontalSize = _verticalSize / _aspectRatio;
} }
} }

View file

@ -44,6 +44,7 @@ public:
int y = 0; int y = 0;
bool flipped = false; bool flipped = false;
int rotation = 0; int rotation = 0;
QSize imageSize;
}; };
ItemBase(Data data); ItemBase(Data data);
@ -93,6 +94,7 @@ private:
void handleActionKey(not_null<QKeyEvent*> e); void handleActionKey(not_null<QKeyEvent*> e);
const std::shared_ptr<float64> _lastZ; const std::shared_ptr<float64> _lastZ;
const QSize _imageSize;
struct { struct {
QPen select; QPen select;