mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Fixed size of handles of base item in photo editor.
This commit is contained in:
parent
274b66f74b
commit
0b5044f064
7 changed files with 59 additions and 27 deletions
|
@ -64,5 +64,3 @@ photoEditorCropMinSize: 20px;
|
||||||
photoEditorItemHandleSize: 10px;
|
photoEditorItemHandleSize: 10px;
|
||||||
photoEditorItemMinSize: 32px;
|
photoEditorItemMinSize: 32px;
|
||||||
photoEditorItemMaxSize: 512px;
|
photoEditorItemMaxSize: 512px;
|
||||||
|
|
||||||
photoEditorItemStickerPadding: margins(5px, 5px, 5px, 5px);
|
|
||||||
|
|
|
@ -114,7 +114,13 @@ Paint::Paint(
|
||||||
const auto size = std::min(s.width(), s.height()) / 2;
|
const auto size = std::min(s.width(), s.height()) / 2;
|
||||||
const auto x = s.width() / 2;
|
const auto x = s.width() / 2;
|
||||||
const auto y = s.height() / 2;
|
const auto y = s.height() / 2;
|
||||||
const auto item = new ItemSticker(document, _lastZ, size, x, y);
|
const auto item = new ItemSticker(
|
||||||
|
document,
|
||||||
|
_zoom.value(),
|
||||||
|
_lastZ,
|
||||||
|
size,
|
||||||
|
x,
|
||||||
|
y);
|
||||||
item->setZValue((*_lastZ)++);
|
item->setZValue((*_lastZ)++);
|
||||||
_scene->addItem(item);
|
_scene->addItem(item);
|
||||||
_scene->clearSelection();
|
_scene->clearSelection();
|
||||||
|
@ -139,6 +145,8 @@ void Paint::applyTransform(QRect geometry, int angle, bool flipped) {
|
||||||
|
|
||||||
_view->setTransform(QTransform().scale(ratioW, ratioH).rotate(angle));
|
_view->setTransform(QTransform().scale(ratioW, ratioH).rotate(angle));
|
||||||
_view->setGeometry(QRect(QPoint(), size));
|
_view->setGeometry(QRect(QPoint(), size));
|
||||||
|
|
||||||
|
_zoom = size.width() / float64(_scene->sceneRect().width());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Scene> Paint::saveScene() const {
|
std::shared_ptr<Scene> Paint::saveScene() const {
|
||||||
|
|
|
@ -61,6 +61,8 @@ private:
|
||||||
rpl::variable<bool> _hasUndo = true;
|
rpl::variable<bool> _hasUndo = true;
|
||||||
rpl::variable<bool> _hasRedo = true;
|
rpl::variable<bool> _hasRedo = true;
|
||||||
|
|
||||||
|
rpl::variable<float64> _zoom = 0.;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Editor
|
} // namespace Editor
|
||||||
|
|
|
@ -36,14 +36,13 @@ void NumberedItem::setNumber(int number) {
|
||||||
_number = number;
|
_number = number;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemBase::ItemBase(std::shared_ptr<float64> zPtr, int size, int x, int y)
|
ItemBase::ItemBase(
|
||||||
|
rpl::producer<float64> zoomValue,
|
||||||
|
std::shared_ptr<float64> zPtr,
|
||||||
|
int size,
|
||||||
|
int x,
|
||||||
|
int y)
|
||||||
: _lastZ(zPtr)
|
: _lastZ(zPtr)
|
||||||
, _handleSize(st::photoEditorItemHandleSize)
|
|
||||||
, _innerMargins(
|
|
||||||
_handleSize / 2,
|
|
||||||
_handleSize / 2,
|
|
||||||
_handleSize / 2,
|
|
||||||
_handleSize / 2)
|
|
||||||
, _selectPen(QBrush(Qt::white), 1, Qt::DashLine, Qt::SquareCap, Qt::RoundJoin)
|
, _selectPen(QBrush(Qt::white), 1, Qt::DashLine, Qt::SquareCap, Qt::RoundJoin)
|
||||||
, _selectPenInactive(
|
, _selectPenInactive(
|
||||||
QBrush(Qt::gray),
|
QBrush(Qt::gray),
|
||||||
|
@ -57,10 +56,26 @@ ItemBase::ItemBase(std::shared_ptr<float64> zPtr, int size, int x, int y)
|
||||||
| QGraphicsItem::ItemIsFocusable);
|
| QGraphicsItem::ItemIsFocusable);
|
||||||
setAcceptHoverEvents(true);
|
setAcceptHoverEvents(true);
|
||||||
setPos(x, y);
|
setPos(x, y);
|
||||||
|
|
||||||
|
const auto &handleSize = st::photoEditorItemHandleSize;
|
||||||
|
std::move(
|
||||||
|
zoomValue
|
||||||
|
) | rpl::start_with_next([=](float64 zoom) {
|
||||||
|
_scaledHandleSize = handleSize / zoom;
|
||||||
|
_scaledInnerMargins = QMarginsF(
|
||||||
|
_scaledHandleSize,
|
||||||
|
_scaledHandleSize,
|
||||||
|
_scaledHandleSize,
|
||||||
|
_scaledHandleSize) * 0.5;
|
||||||
|
}, _lifetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF ItemBase::boundingRect() const {
|
QRectF ItemBase::boundingRect() const {
|
||||||
return innerRect() + _innerMargins;
|
return innerRect() + _scaledInnerMargins;
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF ItemBase::contentRect() const {
|
||||||
|
return innerRect() - _scaledInnerMargins;
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF ItemBase::innerRect() const {
|
QRectF ItemBase::innerRect() const {
|
||||||
|
@ -152,18 +167,18 @@ int ItemBase::type() const {
|
||||||
|
|
||||||
QRectF ItemBase::rightHandleRect() const {
|
QRectF ItemBase::rightHandleRect() const {
|
||||||
return QRectF(
|
return QRectF(
|
||||||
(_horizontalSize / 2) - (_handleSize / 2),
|
(_horizontalSize / 2) - (_scaledHandleSize / 2),
|
||||||
0 - (_handleSize / 2),
|
0 - (_scaledHandleSize / 2),
|
||||||
_handleSize,
|
_scaledHandleSize,
|
||||||
_handleSize);
|
_scaledHandleSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF ItemBase::leftHandleRect() const {
|
QRectF ItemBase::leftHandleRect() const {
|
||||||
return QRectF(
|
return QRectF(
|
||||||
(-_horizontalSize / 2) - (_handleSize / 2),
|
(-_horizontalSize / 2) - (_scaledHandleSize / 2),
|
||||||
0 - (_handleSize / 2),
|
0 - (_scaledHandleSize / 2),
|
||||||
_handleSize,
|
_scaledHandleSize,
|
||||||
_handleSize);
|
_scaledHandleSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ItemBase::isHandling() const {
|
bool ItemBase::isHandling() const {
|
||||||
|
|
|
@ -29,7 +29,12 @@ class ItemBase : public NumberedItem {
|
||||||
public:
|
public:
|
||||||
enum { Type = UserType + 1 };
|
enum { Type = UserType + 1 };
|
||||||
|
|
||||||
ItemBase(std::shared_ptr<float64> zPtr, int size, int x, int y);
|
ItemBase(
|
||||||
|
rpl::producer<float64> zoomValue,
|
||||||
|
std::shared_ptr<float64> zPtr,
|
||||||
|
int size,
|
||||||
|
int x,
|
||||||
|
int y);
|
||||||
QRectF boundingRect() const override;
|
QRectF boundingRect() const override;
|
||||||
void paint(
|
void paint(
|
||||||
QPainter *p,
|
QPainter *p,
|
||||||
|
@ -47,6 +52,7 @@ protected:
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
|
|
||||||
|
QRectF contentRect() const;
|
||||||
QRectF innerRect() const;
|
QRectF innerRect() const;
|
||||||
float64 size() const;
|
float64 size() const;
|
||||||
float64 horizontalSize() const;
|
float64 horizontalSize() const;
|
||||||
|
@ -61,17 +67,20 @@ private:
|
||||||
void updateVerticalSize();
|
void updateVerticalSize();
|
||||||
|
|
||||||
const std::shared_ptr<float64> _lastZ;
|
const std::shared_ptr<float64> _lastZ;
|
||||||
const int _handleSize;
|
|
||||||
const QMargins _innerMargins;
|
|
||||||
const QPen _selectPen;
|
const QPen _selectPen;
|
||||||
const QPen _selectPenInactive;
|
const QPen _selectPenInactive;
|
||||||
const QPen _handlePen;
|
const QPen _handlePen;
|
||||||
|
|
||||||
|
float64 _scaledHandleSize = 1.0;
|
||||||
|
QMarginsF _scaledInnerMargins;
|
||||||
|
|
||||||
float64 _horizontalSize = 0;
|
float64 _horizontalSize = 0;
|
||||||
float64 _verticalSize = 0;
|
float64 _verticalSize = 0;
|
||||||
float64 _aspectRatio = 1.0;
|
float64 _aspectRatio = 1.0;
|
||||||
HandleType _handle = HandleType::None;
|
HandleType _handle = HandleType::None;
|
||||||
|
|
||||||
|
rpl::lifetime _lifetime;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Editor
|
} // namespace Editor
|
||||||
|
|
|
@ -24,14 +24,14 @@ namespace {
|
||||||
|
|
||||||
ItemSticker::ItemSticker(
|
ItemSticker::ItemSticker(
|
||||||
not_null<DocumentData*> document,
|
not_null<DocumentData*> document,
|
||||||
|
rpl::producer<float64> zoomValue,
|
||||||
std::shared_ptr<float64> zPtr,
|
std::shared_ptr<float64> zPtr,
|
||||||
int size,
|
int size,
|
||||||
int x,
|
int x,
|
||||||
int y)
|
int y)
|
||||||
: ItemBase(std::move(zPtr), size, x, y)
|
: ItemBase(std::move(zoomValue), std::move(zPtr), size, x, y)
|
||||||
, _document(document)
|
, _document(document)
|
||||||
, _mediaView(_document->createMediaView())
|
, _mediaView(_document->createMediaView()) {
|
||||||
, _thumbnailMargins(st::photoEditorItemStickerPadding) {
|
|
||||||
const auto stickerData = document->sticker();
|
const auto stickerData = document->sticker();
|
||||||
if (!stickerData) {
|
if (!stickerData) {
|
||||||
return;
|
return;
|
||||||
|
@ -85,7 +85,7 @@ void ItemSticker::paint(
|
||||||
QPainter *p,
|
QPainter *p,
|
||||||
const QStyleOptionGraphicsItem *option,
|
const QStyleOptionGraphicsItem *option,
|
||||||
QWidget *w) {
|
QWidget *w) {
|
||||||
p->drawPixmap((innerRect() - _thumbnailMargins).toRect(), _pixmap);
|
p->drawPixmap(contentRect().toRect(), _pixmap);
|
||||||
ItemBase::paint(p, option, w);
|
ItemBase::paint(p, option, w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ public:
|
||||||
|
|
||||||
ItemSticker(
|
ItemSticker(
|
||||||
not_null<DocumentData*> document,
|
not_null<DocumentData*> document,
|
||||||
|
rpl::producer<float64> zoomValue,
|
||||||
std::shared_ptr<float64> zPtr,
|
std::shared_ptr<float64> zPtr,
|
||||||
int size,
|
int size,
|
||||||
int x,
|
int x,
|
||||||
|
@ -38,7 +39,6 @@ public:
|
||||||
private:
|
private:
|
||||||
const not_null<DocumentData*> _document;
|
const not_null<DocumentData*> _document;
|
||||||
const std::shared_ptr<Data::DocumentMedia> _mediaView;
|
const std::shared_ptr<Data::DocumentMedia> _mediaView;
|
||||||
const QMarginsF _thumbnailMargins;
|
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
std::unique_ptr<Lottie::SinglePlayer> player;
|
std::unique_ptr<Lottie::SinglePlayer> player;
|
||||||
|
|
Loading…
Add table
Reference in a new issue