mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Added ability to create items in photo editor with different ratios.
This commit is contained in:
parent
e05343d721
commit
274b66f74b
3 changed files with 32 additions and 10 deletions
|
@ -51,7 +51,7 @@ ItemBase::ItemBase(std::shared_ptr<float64> zPtr, int size, int x, int y)
|
|||
Qt::DashLine,
|
||||
Qt::SquareCap,
|
||||
Qt::RoundJoin)
|
||||
, _size(size) {
|
||||
, _horizontalSize(size) {
|
||||
setFlags(QGraphicsItem::ItemIsMovable
|
||||
| QGraphicsItem::ItemIsSelectable
|
||||
| QGraphicsItem::ItemIsFocusable);
|
||||
|
@ -64,7 +64,9 @@ QRectF ItemBase::boundingRect() const {
|
|||
}
|
||||
|
||||
QRectF ItemBase::innerRect() const {
|
||||
return QRectF(-_size / 2, -_size / 2, _size, _size);
|
||||
const auto &hSize = _horizontalSize;
|
||||
const auto &vSize = _verticalSize;
|
||||
return QRectF(-hSize / 2, -vSize / 2, hSize, vSize);
|
||||
}
|
||||
|
||||
void ItemBase::paint(
|
||||
|
@ -96,10 +98,11 @@ void ItemBase::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
|||
const auto dx = int(2.0 * p.x());
|
||||
const auto dy = int(2.0 * p.y());
|
||||
prepareGeometryChange();
|
||||
_size = std::clamp(
|
||||
_horizontalSize = std::clamp(
|
||||
(dx > dy ? dx : dy),
|
||||
st::photoEditorItemMinSize,
|
||||
st::photoEditorItemMaxSize);
|
||||
updateVerticalSize();
|
||||
|
||||
// Rotate.
|
||||
const auto origin = mapToScene(boundingRect().center());
|
||||
|
@ -149,7 +152,7 @@ int ItemBase::type() const {
|
|||
|
||||
QRectF ItemBase::rightHandleRect() const {
|
||||
return QRectF(
|
||||
(_size / 2) - (_handleSize / 2),
|
||||
(_horizontalSize / 2) - (_handleSize / 2),
|
||||
0 - (_handleSize / 2),
|
||||
_handleSize,
|
||||
_handleSize);
|
||||
|
@ -157,7 +160,7 @@ QRectF ItemBase::rightHandleRect() const {
|
|||
|
||||
QRectF ItemBase::leftHandleRect() const {
|
||||
return QRectF(
|
||||
(-_size / 2) - (_handleSize / 2),
|
||||
(-_horizontalSize / 2) - (_handleSize / 2),
|
||||
0 - (_handleSize / 2),
|
||||
_handleSize,
|
||||
_handleSize);
|
||||
|
@ -167,8 +170,17 @@ bool ItemBase::isHandling() const {
|
|||
return _handle != HandleType::None;
|
||||
}
|
||||
|
||||
int ItemBase::size() const {
|
||||
return _size;
|
||||
float64 ItemBase::size() const {
|
||||
return _horizontalSize;
|
||||
}
|
||||
|
||||
void ItemBase::updateVerticalSize() {
|
||||
_verticalSize = _horizontalSize * _aspectRatio;
|
||||
}
|
||||
|
||||
void ItemBase::setAspectRatio(float64 aspectRatio) {
|
||||
_aspectRatio = aspectRatio;
|
||||
updateVerticalSize();
|
||||
}
|
||||
|
||||
ItemBase::HandleType ItemBase::handleType(const QPointF &pos) const {
|
||||
|
|
|
@ -48,13 +48,17 @@ protected:
|
|||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
|
||||
QRectF innerRect() const;
|
||||
int size() const;
|
||||
float64 size() const;
|
||||
float64 horizontalSize() const;
|
||||
float64 verticalSize() const;
|
||||
void setAspectRatio(float64 aspectRatio);
|
||||
|
||||
private:
|
||||
HandleType handleType(const QPointF &pos) const;
|
||||
QRectF rightHandleRect() const;
|
||||
QRectF leftHandleRect() const;
|
||||
bool isHandling() const;
|
||||
void updateVerticalSize();
|
||||
|
||||
const std::shared_ptr<float64> _lastZ;
|
||||
const int _handleSize;
|
||||
|
@ -63,7 +67,9 @@ private:
|
|||
const QPen _selectPenInactive;
|
||||
const QPen _handlePen;
|
||||
|
||||
int _size;
|
||||
float64 _horizontalSize = 0;
|
||||
float64 _verticalSize = 0;
|
||||
float64 _aspectRatio = 1.0;
|
||||
HandleType _handle = HandleType::None;
|
||||
|
||||
};
|
||||
|
|
|
@ -37,6 +37,11 @@ ItemSticker::ItemSticker(
|
|||
return;
|
||||
}
|
||||
const auto updateThumbnail = [=] {
|
||||
const auto guard = gsl::finally([&] {
|
||||
setAspectRatio(_pixmap.isNull()
|
||||
? 1.0
|
||||
: (_pixmap.height() / float64(_pixmap.width())));
|
||||
});
|
||||
if (stickerData->animated) {
|
||||
_lottie.player = ChatHelpers::LottiePlayerFromDocument(
|
||||
_mediaView.get(),
|
||||
|
@ -73,7 +78,6 @@ ItemSticker::ItemSticker(
|
|||
update();
|
||||
}
|
||||
}, _loadingLifetime);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue