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