mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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::ItemIsSelectable
|
||||||
| QGraphicsItem::ItemIsFocusable);
|
| QGraphicsItem::ItemIsFocusable);
|
||||||
setAcceptHoverEvents(true);
|
setAcceptHoverEvents(true);
|
||||||
setPos(data.x, data.y);
|
applyData(data);
|
||||||
setZValue((*_lastZ)++);
|
|
||||||
setFlip(data.flipped);
|
|
||||||
setRotation(data.rotation);
|
|
||||||
updateZoom(data.initialZoom);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF ItemBase::boundingRect() const {
|
QRectF ItemBase::boundingRect() const {
|
||||||
|
@ -212,17 +208,10 @@ void ItemBase::actionDelete() {
|
||||||
|
|
||||||
void ItemBase::actionDuplicate() {
|
void ItemBase::actionDuplicate() {
|
||||||
if (const auto s = static_cast<Scene*>(scene())) {
|
if (const auto s = static_cast<Scene*>(scene())) {
|
||||||
const auto zoom = st::photoEditorItemHandleSize / _scaledHandleSize;
|
auto data = generateData();
|
||||||
const auto newItem = duplicate(Data{
|
data.x += int(_horizontalSize / 3);
|
||||||
.initialZoom = zoom,
|
data.y += int(_verticalSize / 3);
|
||||||
.zPtr = _lastZ,
|
const auto newItem = duplicate(std::move(data));
|
||||||
.size = int(_horizontalSize),
|
|
||||||
.x = int(scenePos().x() + _horizontalSize / 3),
|
|
||||||
.y = int(scenePos().y() + _verticalSize / 3),
|
|
||||||
.flipped = flipped(),
|
|
||||||
.rotation = int(rotation()),
|
|
||||||
.imageSize = _imageSize,
|
|
||||||
});
|
|
||||||
if (hasFocus()) {
|
if (hasFocus()) {
|
||||||
newItem->setFocus();
|
newItem->setFocus();
|
||||||
}
|
}
|
||||||
|
@ -369,4 +358,29 @@ void ItemBase::updatePens(QPen pen) {
|
||||||
_pens.handleInactive.setStyle(Qt::SolidLine);
|
_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
|
} // namespace Editor
|
||||||
|
|
|
@ -97,6 +97,9 @@ private:
|
||||||
void updatePens(QPen pen);
|
void updatePens(QPen pen);
|
||||||
void handleActionKey(not_null<QKeyEvent*> e);
|
void handleActionKey(not_null<QKeyEvent*> e);
|
||||||
|
|
||||||
|
Data generateData() const;
|
||||||
|
void applyData(const Data &data);
|
||||||
|
|
||||||
const std::shared_ptr<float64> _lastZ;
|
const std::shared_ptr<float64> _lastZ;
|
||||||
const QSize _imageSize;
|
const QSize _imageSize;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue