diff --git a/Telegram/SourceFiles/editor/editor.style b/Telegram/SourceFiles/editor/editor.style index d4b362de4..cb74ac3cc 100644 --- a/Telegram/SourceFiles/editor/editor.style +++ b/Telegram/SourceFiles/editor/editor.style @@ -64,5 +64,3 @@ photoEditorCropMinSize: 20px; photoEditorItemHandleSize: 10px; photoEditorItemMinSize: 32px; photoEditorItemMaxSize: 512px; - -photoEditorItemStickerPadding: margins(5px, 5px, 5px, 5px); diff --git a/Telegram/SourceFiles/editor/editor_paint.cpp b/Telegram/SourceFiles/editor/editor_paint.cpp index 14b054095..9c0fb6854 100644 --- a/Telegram/SourceFiles/editor/editor_paint.cpp +++ b/Telegram/SourceFiles/editor/editor_paint.cpp @@ -114,7 +114,13 @@ Paint::Paint( const auto size = std::min(s.width(), s.height()) / 2; const auto x = s.width() / 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)++); _scene->addItem(item); _scene->clearSelection(); @@ -139,6 +145,8 @@ void Paint::applyTransform(QRect geometry, int angle, bool flipped) { _view->setTransform(QTransform().scale(ratioW, ratioH).rotate(angle)); _view->setGeometry(QRect(QPoint(), size)); + + _zoom = size.width() / float64(_scene->sceneRect().width()); } std::shared_ptr Paint::saveScene() const { diff --git a/Telegram/SourceFiles/editor/editor_paint.h b/Telegram/SourceFiles/editor/editor_paint.h index bee9c3ae7..7d3b48a23 100644 --- a/Telegram/SourceFiles/editor/editor_paint.h +++ b/Telegram/SourceFiles/editor/editor_paint.h @@ -61,6 +61,8 @@ private: rpl::variable _hasUndo = true; rpl::variable _hasRedo = true; + rpl::variable _zoom = 0.; + }; } // namespace Editor diff --git a/Telegram/SourceFiles/editor/scene_item_base.cpp b/Telegram/SourceFiles/editor/scene_item_base.cpp index ca19bc93f..3bcc1cebe 100644 --- a/Telegram/SourceFiles/editor/scene_item_base.cpp +++ b/Telegram/SourceFiles/editor/scene_item_base.cpp @@ -36,14 +36,13 @@ void NumberedItem::setNumber(int number) { _number = number; } -ItemBase::ItemBase(std::shared_ptr zPtr, int size, int x, int y) +ItemBase::ItemBase( + rpl::producer zoomValue, + std::shared_ptr zPtr, + int size, + int x, + int y) : _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) , _selectPenInactive( QBrush(Qt::gray), @@ -57,10 +56,26 @@ ItemBase::ItemBase(std::shared_ptr zPtr, int size, int x, int y) | QGraphicsItem::ItemIsFocusable); setAcceptHoverEvents(true); 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 { - return innerRect() + _innerMargins; + return innerRect() + _scaledInnerMargins; +} + +QRectF ItemBase::contentRect() const { + return innerRect() - _scaledInnerMargins; } QRectF ItemBase::innerRect() const { @@ -152,18 +167,18 @@ int ItemBase::type() const { QRectF ItemBase::rightHandleRect() const { return QRectF( - (_horizontalSize / 2) - (_handleSize / 2), - 0 - (_handleSize / 2), - _handleSize, - _handleSize); + (_horizontalSize / 2) - (_scaledHandleSize / 2), + 0 - (_scaledHandleSize / 2), + _scaledHandleSize, + _scaledHandleSize); } QRectF ItemBase::leftHandleRect() const { return QRectF( - (-_horizontalSize / 2) - (_handleSize / 2), - 0 - (_handleSize / 2), - _handleSize, - _handleSize); + (-_horizontalSize / 2) - (_scaledHandleSize / 2), + 0 - (_scaledHandleSize / 2), + _scaledHandleSize, + _scaledHandleSize); } bool ItemBase::isHandling() const { diff --git a/Telegram/SourceFiles/editor/scene_item_base.h b/Telegram/SourceFiles/editor/scene_item_base.h index cd835012f..49b5c849a 100644 --- a/Telegram/SourceFiles/editor/scene_item_base.h +++ b/Telegram/SourceFiles/editor/scene_item_base.h @@ -29,7 +29,12 @@ class ItemBase : public NumberedItem { public: enum { Type = UserType + 1 }; - ItemBase(std::shared_ptr zPtr, int size, int x, int y); + ItemBase( + rpl::producer zoomValue, + std::shared_ptr zPtr, + int size, + int x, + int y); QRectF boundingRect() const override; void paint( QPainter *p, @@ -47,6 +52,7 @@ protected: void mousePressEvent(QGraphicsSceneMouseEvent *event) override; void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; + QRectF contentRect() const; QRectF innerRect() const; float64 size() const; float64 horizontalSize() const; @@ -61,17 +67,20 @@ private: void updateVerticalSize(); const std::shared_ptr _lastZ; - const int _handleSize; - const QMargins _innerMargins; const QPen _selectPen; const QPen _selectPenInactive; const QPen _handlePen; + float64 _scaledHandleSize = 1.0; + QMarginsF _scaledInnerMargins; + float64 _horizontalSize = 0; float64 _verticalSize = 0; float64 _aspectRatio = 1.0; HandleType _handle = HandleType::None; + rpl::lifetime _lifetime; + }; } // namespace Editor diff --git a/Telegram/SourceFiles/editor/scene_item_sticker.cpp b/Telegram/SourceFiles/editor/scene_item_sticker.cpp index 66c1b8d2c..c7af5512e 100644 --- a/Telegram/SourceFiles/editor/scene_item_sticker.cpp +++ b/Telegram/SourceFiles/editor/scene_item_sticker.cpp @@ -24,14 +24,14 @@ namespace { ItemSticker::ItemSticker( not_null document, + rpl::producer zoomValue, std::shared_ptr zPtr, int size, int x, int y) -: ItemBase(std::move(zPtr), size, x, y) +: ItemBase(std::move(zoomValue), std::move(zPtr), size, x, y) , _document(document) -, _mediaView(_document->createMediaView()) -, _thumbnailMargins(st::photoEditorItemStickerPadding) { +, _mediaView(_document->createMediaView()) { const auto stickerData = document->sticker(); if (!stickerData) { return; @@ -85,7 +85,7 @@ void ItemSticker::paint( QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *w) { - p->drawPixmap((innerRect() - _thumbnailMargins).toRect(), _pixmap); + p->drawPixmap(contentRect().toRect(), _pixmap); ItemBase::paint(p, option, w); } diff --git a/Telegram/SourceFiles/editor/scene_item_sticker.h b/Telegram/SourceFiles/editor/scene_item_sticker.h index 1cd1a805e..68c4d18a8 100644 --- a/Telegram/SourceFiles/editor/scene_item_sticker.h +++ b/Telegram/SourceFiles/editor/scene_item_sticker.h @@ -25,6 +25,7 @@ public: ItemSticker( not_null document, + rpl::producer zoomValue, std::shared_ptr zPtr, int size, int x, @@ -38,7 +39,6 @@ public: private: const not_null _document; const std::shared_ptr _mediaView; - const QMarginsF _thumbnailMargins; struct { std::unique_ptr player;