2021-05-06 21:47:49 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "editor/scene/scene_item_image.h"
|
|
|
|
|
|
|
|
namespace Editor {
|
|
|
|
|
|
|
|
ItemImage::ItemImage(
|
|
|
|
const QPixmap &&pixmap,
|
2021-07-04 12:57:07 +00:00
|
|
|
ItemBase::Data data)
|
|
|
|
: ItemBase(std::move(data))
|
2021-05-06 21:47:49 +00:00
|
|
|
, _pixmap(std::move(pixmap)) {
|
|
|
|
setAspectRatio(_pixmap.isNull()
|
|
|
|
? 1.0
|
|
|
|
: (_pixmap.height() / float64(_pixmap.width())));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemImage::paint(
|
|
|
|
QPainter *p,
|
|
|
|
const QStyleOptionGraphicsItem *option,
|
|
|
|
QWidget *w) {
|
2023-11-05 15:10:27 +00:00
|
|
|
const auto rect = contentRect();
|
|
|
|
const auto pixmapSize = QSizeF(_pixmap.size() / style::DevicePixelRatio())
|
|
|
|
.scaled(rect.size(), Qt::KeepAspectRatio);
|
|
|
|
const auto resultRect = QRectF(rect.topLeft(), pixmapSize).translated(
|
|
|
|
(rect.width() - pixmapSize.width()) / 2.,
|
|
|
|
(rect.height() - pixmapSize.height()) / 2.);
|
|
|
|
p->drawPixmap(resultRect.toRect(), _pixmap);
|
2021-05-06 21:47:49 +00:00
|
|
|
ItemBase::paint(p, option, w);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemImage::performFlip() {
|
|
|
|
_pixmap = _pixmap.transformed(QTransform().scale(-1, 1));
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2021-07-04 12:57:07 +00:00
|
|
|
std::shared_ptr<ItemBase> ItemImage::duplicate(ItemBase::Data data) const {
|
2021-05-06 21:47:49 +00:00
|
|
|
auto pixmap = _pixmap;
|
2021-07-04 12:57:07 +00:00
|
|
|
return std::make_shared<ItemImage>(std::move(pixmap), std::move(data));
|
2021-05-06 21:47:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Editor
|