mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Moved Editor::ItemBase arguments to struct.
This commit is contained in:
parent
4206ff0483
commit
0c50fbf1b9
8 changed files with 53 additions and 112 deletions
|
@ -10,7 +10,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "boxes/confirm_box.h"
|
||||
#include "editor/controllers/controllers.h"
|
||||
#include "editor/scene/scene.h"
|
||||
#include "editor/scene/scene_item_base.h"
|
||||
#include "editor/scene/scene_item_canvas.h"
|
||||
#include "editor/scene/scene_item_image.h"
|
||||
#include "editor/scene/scene_item_sticker.h"
|
||||
|
@ -110,17 +109,9 @@ Paint::Paint(
|
|||
|
||||
controllers->stickersPanelController->stickerChosen(
|
||||
) | rpl::start_with_next([=](not_null<DocumentData*> document) {
|
||||
const auto s = _scene->sceneRect().size();
|
||||
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 = std::make_shared<ItemSticker>(
|
||||
document,
|
||||
_transform.zoom.value(),
|
||||
_lastZ,
|
||||
size,
|
||||
x,
|
||||
y);
|
||||
itemBaseData());
|
||||
item->setFlip(_transform.flipped);
|
||||
item->setRotation(-_transform.angle);
|
||||
_scene->addItem(item);
|
||||
|
@ -271,10 +262,6 @@ void Paint::handleMimeData(const QMimeData *data) {
|
|||
if (image.isNull()) {
|
||||
return;
|
||||
}
|
||||
const auto s = _scene->sceneRect().size();
|
||||
const auto size = std::min(s.width(), s.height()) / 2;
|
||||
const auto x = s.width() / 2;
|
||||
const auto y = s.height() / 2;
|
||||
if (!Ui::ValidateThumbDimensions(image.width(), image.height())) {
|
||||
_controllers->showBox(
|
||||
Box<InformBox>(tr::lng_edit_media_invalid_file(tr::now)));
|
||||
|
@ -283,11 +270,7 @@ void Paint::handleMimeData(const QMimeData *data) {
|
|||
|
||||
const auto item = std::make_shared<ItemImage>(
|
||||
Ui::PixmapFromImage(std::move(image)),
|
||||
_transform.zoom.value(),
|
||||
_lastZ,
|
||||
size,
|
||||
x,
|
||||
y);
|
||||
itemBaseData());
|
||||
item->setFlip(_transform.flipped);
|
||||
item->setRotation(-_transform.angle);
|
||||
_scene->addItem(item);
|
||||
|
@ -307,4 +290,18 @@ void Paint::handleMimeData(const QMimeData *data) {
|
|||
}
|
||||
}
|
||||
|
||||
ItemBase::Data Paint::itemBaseData() const {
|
||||
const auto s = _scene->sceneRect().toRect().size();
|
||||
const auto size = std::min(s.width(), s.height()) / 2;
|
||||
const auto x = s.width() / 2;
|
||||
const auto y = s.height() / 2;
|
||||
return ItemBase::Data{
|
||||
.zoomValue = _transform.zoom.value(),
|
||||
.zPtr = _lastZ,
|
||||
.size = size,
|
||||
.x = x,
|
||||
.y = y,
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace Editor
|
||||
|
|
|
@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/rp_widget.h"
|
||||
|
||||
#include "editor/photo_editor_common.h"
|
||||
#include "editor/scene/scene_item_base.h"
|
||||
|
||||
class QGraphicsItem;
|
||||
class QGraphicsView;
|
||||
|
@ -17,7 +18,6 @@ class QGraphicsView;
|
|||
namespace Editor {
|
||||
|
||||
struct Controllers;
|
||||
class ItemBase;
|
||||
class Scene;
|
||||
|
||||
// Paint control.
|
||||
|
@ -45,6 +45,8 @@ private:
|
|||
bool undid = false;
|
||||
};
|
||||
|
||||
ItemBase::Data itemBaseData() const;
|
||||
|
||||
bool hasUndo() const;
|
||||
bool hasRedo() const;
|
||||
void clearRedoList();
|
||||
|
|
|
@ -45,20 +45,15 @@ void NumberedItem::setNumber(int number) {
|
|||
_number = number;
|
||||
}
|
||||
|
||||
ItemBase::ItemBase(
|
||||
rpl::producer<float64> zoomValue,
|
||||
std::shared_ptr<float64> zPtr,
|
||||
int size,
|
||||
int x,
|
||||
int y)
|
||||
: _lastZ(zPtr)
|
||||
, _horizontalSize(size)
|
||||
, _zoom(std::move(zoomValue)) {
|
||||
ItemBase::ItemBase(Data data)
|
||||
: _lastZ(data.zPtr)
|
||||
, _horizontalSize(data.size)
|
||||
, _zoom(std::move(data.zoomValue)) {
|
||||
setFlags(QGraphicsItem::ItemIsMovable
|
||||
| QGraphicsItem::ItemIsSelectable
|
||||
| QGraphicsItem::ItemIsFocusable);
|
||||
setAcceptHoverEvents(true);
|
||||
setPos(x, y);
|
||||
setPos(data.x, data.y);
|
||||
setZValue((*_lastZ)++);
|
||||
|
||||
const auto &handleSize = st::photoEditorItemHandleSize;
|
||||
|
@ -237,12 +232,12 @@ void ItemBase::actionDelete() {
|
|||
|
||||
void ItemBase::actionDuplicate() {
|
||||
if (const auto s = static_cast<Scene*>(scene())) {
|
||||
const auto newItem = duplicate(
|
||||
_zoom.value(),
|
||||
_lastZ,
|
||||
_horizontalSize,
|
||||
scenePos().x() + _horizontalSize / 3,
|
||||
scenePos().y() + _verticalSize / 3);
|
||||
const auto newItem = duplicate(Data{
|
||||
.zoomValue = _zoom.value(),
|
||||
.zPtr = _lastZ,
|
||||
.size = int(_horizontalSize),
|
||||
.x = int(scenePos().x() + _horizontalSize / 3),
|
||||
.y = int(scenePos().y() + _verticalSize / 3) });
|
||||
newItem->setFlip(flipped());
|
||||
newItem->setRotation(rotation());
|
||||
if (hasFocus()) {
|
||||
|
|
|
@ -36,12 +36,15 @@ private:
|
|||
class ItemBase : public NumberedItem {
|
||||
public:
|
||||
|
||||
ItemBase(
|
||||
rpl::producer<float64> zoomValue,
|
||||
std::shared_ptr<float64> zPtr,
|
||||
int size,
|
||||
int x,
|
||||
int y);
|
||||
struct Data {
|
||||
rpl::producer<float64> zoomValue;
|
||||
std::shared_ptr<float64> zPtr;
|
||||
int size = 0;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
};
|
||||
|
||||
ItemBase(Data data);
|
||||
QRectF boundingRect() const override;
|
||||
void paint(
|
||||
QPainter *p,
|
||||
|
@ -77,12 +80,7 @@ protected:
|
|||
void setAspectRatio(float64 aspectRatio);
|
||||
|
||||
virtual void performFlip();
|
||||
virtual std::shared_ptr<ItemBase> duplicate(
|
||||
rpl::producer<float64> zoomValue,
|
||||
std::shared_ptr<float64> zPtr,
|
||||
int size,
|
||||
int x,
|
||||
int y) const = 0;
|
||||
virtual std::shared_ptr<ItemBase> duplicate(Data data) const = 0;
|
||||
private:
|
||||
HandleType handleType(const QPointF &pos) const;
|
||||
QRectF rightHandleRect() const;
|
||||
|
|
|
@ -8,18 +8,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "editor/scene/scene_item_image.h"
|
||||
|
||||
namespace Editor {
|
||||
namespace {
|
||||
|
||||
} // namespace
|
||||
|
||||
ItemImage::ItemImage(
|
||||
const QPixmap &&pixmap,
|
||||
rpl::producer<float64> zoomValue,
|
||||
std::shared_ptr<float64> zPtr,
|
||||
int size,
|
||||
int x,
|
||||
int y)
|
||||
: ItemBase(std::move(zoomValue), std::move(zPtr), size, x, y)
|
||||
ItemBase::Data data)
|
||||
: ItemBase(std::move(data))
|
||||
, _pixmap(std::move(pixmap)) {
|
||||
setAspectRatio(_pixmap.isNull()
|
||||
? 1.0
|
||||
|
@ -39,20 +32,9 @@ void ItemImage::performFlip() {
|
|||
update();
|
||||
}
|
||||
|
||||
std::shared_ptr<ItemBase> ItemImage::duplicate(
|
||||
rpl::producer<float64> zoomValue,
|
||||
std::shared_ptr<float64> zPtr,
|
||||
int size,
|
||||
int x,
|
||||
int y) const {
|
||||
std::shared_ptr<ItemBase> ItemImage::duplicate(ItemBase::Data data) const {
|
||||
auto pixmap = _pixmap;
|
||||
return std::make_shared<ItemImage>(
|
||||
std::move(pixmap),
|
||||
std::move(zoomValue),
|
||||
std::move(zPtr),
|
||||
size,
|
||||
x,
|
||||
y);
|
||||
return std::make_shared<ItemImage>(std::move(pixmap), std::move(data));
|
||||
}
|
||||
|
||||
} // namespace Editor
|
||||
|
|
|
@ -15,23 +15,14 @@ class ItemImage : public ItemBase {
|
|||
public:
|
||||
ItemImage(
|
||||
const QPixmap &&pixmap,
|
||||
rpl::producer<float64> zoomValue,
|
||||
std::shared_ptr<float64> zPtr,
|
||||
int size,
|
||||
int x,
|
||||
int y);
|
||||
ItemBase::Data data);
|
||||
void paint(
|
||||
QPainter *p,
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget) override;
|
||||
protected:
|
||||
void performFlip() override;
|
||||
std::shared_ptr<ItemBase> duplicate(
|
||||
rpl::producer<float64> zoomValue,
|
||||
std::shared_ptr<float64> zPtr,
|
||||
int size,
|
||||
int x,
|
||||
int y) const override;
|
||||
std::shared_ptr<ItemBase> duplicate(ItemBase::Data data) const override;
|
||||
private:
|
||||
QPixmap _pixmap;
|
||||
|
||||
|
|
|
@ -24,12 +24,8 @@ 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(zoomValue), std::move(zPtr), size, x, y)
|
||||
ItemBase::Data data)
|
||||
: ItemBase(std::move(data))
|
||||
, _document(document)
|
||||
, _mediaView(_document->createMediaView()) {
|
||||
const auto stickerData = document->sticker();
|
||||
|
@ -112,19 +108,8 @@ void ItemSticker::performFlip() {
|
|||
update();
|
||||
}
|
||||
|
||||
std::shared_ptr<ItemBase> ItemSticker::duplicate(
|
||||
rpl::producer<float64> zoomValue,
|
||||
std::shared_ptr<float64> zPtr,
|
||||
int size,
|
||||
int x,
|
||||
int y) const {
|
||||
return std::make_shared<ItemSticker>(
|
||||
_document,
|
||||
std::move(zoomValue),
|
||||
std::move(zPtr),
|
||||
size,
|
||||
x,
|
||||
y);
|
||||
std::shared_ptr<ItemBase> ItemSticker::duplicate(ItemBase::Data data) const {
|
||||
return std::make_shared<ItemSticker>(_document, std::move(data));
|
||||
}
|
||||
|
||||
} // namespace Editor
|
||||
|
|
|
@ -25,11 +25,7 @@ public:
|
|||
|
||||
ItemSticker(
|
||||
not_null<DocumentData*> document,
|
||||
rpl::producer<float64> zoomValue,
|
||||
std::shared_ptr<float64> zPtr,
|
||||
int size,
|
||||
int x,
|
||||
int y);
|
||||
ItemBase::Data data);
|
||||
void paint(
|
||||
QPainter *p,
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
|
@ -38,15 +34,10 @@ public:
|
|||
int type() const override;
|
||||
protected:
|
||||
void performFlip() override;
|
||||
std::shared_ptr<ItemBase> duplicate(
|
||||
rpl::producer<float64> zoomValue,
|
||||
std::shared_ptr<float64> zPtr,
|
||||
int size,
|
||||
int x,
|
||||
int y) const override;
|
||||
std::shared_ptr<ItemBase> duplicate(ItemBase::Data data) const override;
|
||||
private:
|
||||
const not_null<DocumentData*> _document;
|
||||
const std::shared_ptr<Data::DocumentMedia> _mediaView;
|
||||
const std::shared_ptr<::Data::DocumentMedia> _mediaView;
|
||||
|
||||
void updatePixmap(QPixmap &&pixmap);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue