mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Simplified work with Editor::ItemBase::Data.
This commit is contained in:
parent
fe8eae09c4
commit
bf8f3e42f4
2 changed files with 33 additions and 16 deletions
|
@ -56,11 +56,7 @@ ItemBase::ItemBase(Data data)
|
|||
| QGraphicsItem::ItemIsSelectable
|
||||
| QGraphicsItem::ItemIsFocusable);
|
||||
setAcceptHoverEvents(true);
|
||||
setPos(data.x, data.y);
|
||||
setZValue((*_lastZ)++);
|
||||
setFlip(data.flipped);
|
||||
setRotation(data.rotation);
|
||||
updateZoom(data.initialZoom);
|
||||
applyData(data);
|
||||
}
|
||||
|
||||
QRectF ItemBase::boundingRect() const {
|
||||
|
@ -212,17 +208,10 @@ void ItemBase::actionDelete() {
|
|||
|
||||
void ItemBase::actionDuplicate() {
|
||||
if (const auto s = static_cast<Scene*>(scene())) {
|
||||
const auto zoom = st::photoEditorItemHandleSize / _scaledHandleSize;
|
||||
const auto newItem = duplicate(Data{
|
||||
.initialZoom = zoom,
|
||||
.zPtr = _lastZ,
|
||||
.size = int(_horizontalSize),
|
||||
.x = int(scenePos().x() + _horizontalSize / 3),
|
||||
.y = int(scenePos().y() + _verticalSize / 3),
|
||||
.flipped = flipped(),
|
||||
.rotation = int(rotation()),
|
||||
.imageSize = _imageSize,
|
||||
});
|
||||
auto data = generateData();
|
||||
data.x += int(_horizontalSize / 3);
|
||||
data.y += int(_verticalSize / 3);
|
||||
const auto newItem = duplicate(std::move(data));
|
||||
if (hasFocus()) {
|
||||
newItem->setFocus();
|
||||
}
|
||||
|
@ -369,4 +358,29 @@ void ItemBase::updatePens(QPen pen) {
|
|||
_pens.handleInactive.setStyle(Qt::SolidLine);
|
||||
}
|
||||
|
||||
ItemBase::Data ItemBase::generateData() const {
|
||||
return {
|
||||
.initialZoom = (st::photoEditorItemHandleSize / _scaledHandleSize),
|
||||
.zPtr = _lastZ,
|
||||
.size = int(_horizontalSize),
|
||||
.x = int(scenePos().x()),
|
||||
.y = int(scenePos().y()),
|
||||
.flipped = flipped(),
|
||||
.rotation = int(rotation()),
|
||||
.imageSize = _imageSize,
|
||||
};
|
||||
}
|
||||
|
||||
void ItemBase::applyData(const Data &data) {
|
||||
// _lastZ is const.
|
||||
// _imageSize is const.
|
||||
_horizontalSize = data.size;
|
||||
setPos(data.x, data.y);
|
||||
setZValue((*_lastZ)++);
|
||||
setFlip(data.flipped);
|
||||
setRotation(data.rotation);
|
||||
updateZoom(data.initialZoom);
|
||||
update();
|
||||
}
|
||||
|
||||
} // namespace Editor
|
||||
|
|
|
@ -97,6 +97,9 @@ private:
|
|||
void updatePens(QPen pen);
|
||||
void handleActionKey(not_null<QKeyEvent*> e);
|
||||
|
||||
Data generateData() const;
|
||||
void applyData(const Data &data);
|
||||
|
||||
const std::shared_ptr<float64> _lastZ;
|
||||
const QSize _imageSize;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue