mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +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;
|
||||
photoEditorItemMinSize: 32px;
|
||||
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 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<Scene> Paint::saveScene() const {
|
||||
|
|
|
@ -61,6 +61,8 @@ private:
|
|||
rpl::variable<bool> _hasUndo = true;
|
||||
rpl::variable<bool> _hasRedo = true;
|
||||
|
||||
rpl::variable<float64> _zoom = 0.;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Editor
|
||||
|
|
|
@ -36,14 +36,13 @@ void NumberedItem::setNumber(int 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)
|
||||
, _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<float64> 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 {
|
||||
|
|
|
@ -29,7 +29,12 @@ class ItemBase : public NumberedItem {
|
|||
public:
|
||||
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;
|
||||
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<float64> _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
|
||||
|
|
|
@ -24,14 +24,14 @@ namespace {
|
|||
|
||||
ItemSticker::ItemSticker(
|
||||
not_null<DocumentData*> document,
|
||||
rpl::producer<float64> zoomValue,
|
||||
std::shared_ptr<float64> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ public:
|
|||
|
||||
ItemSticker(
|
||||
not_null<DocumentData*> document,
|
||||
rpl::producer<float64> zoomValue,
|
||||
std::shared_ptr<float64> zPtr,
|
||||
int size,
|
||||
int x,
|
||||
|
@ -38,7 +39,6 @@ public:
|
|||
private:
|
||||
const not_null<DocumentData*> _document;
|
||||
const std::shared_ptr<Data::DocumentMedia> _mediaView;
|
||||
const QMarginsF _thumbnailMargins;
|
||||
|
||||
struct {
|
||||
std::unique_ptr<Lottie::SinglePlayer> player;
|
||||
|
|
Loading…
Add table
Reference in a new issue