2021-02-23 06:58:25 +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
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2021-03-10 12:07:04 +00:00
|
|
|
#include "base/unique_qptr.h"
|
2021-07-07 18:14:50 +00:00
|
|
|
#include "editor/photo_editor_inner_common.h"
|
2021-03-10 12:07:04 +00:00
|
|
|
|
2021-02-23 06:58:25 +00:00
|
|
|
#include <QGraphicsItem>
|
|
|
|
|
|
|
|
class QGraphicsSceneHoverEvent;
|
|
|
|
class QGraphicsSceneMouseEvent;
|
|
|
|
class QStyleOptionGraphicsItem;
|
|
|
|
|
2021-03-10 12:07:04 +00:00
|
|
|
namespace Ui {
|
|
|
|
class PopupMenu;
|
|
|
|
} // namespace Ui
|
|
|
|
|
2021-02-23 06:58:25 +00:00
|
|
|
namespace Editor {
|
|
|
|
|
2021-03-14 09:44:49 +00:00
|
|
|
class NumberedItem : public QGraphicsItem {
|
|
|
|
public:
|
2021-07-07 21:51:58 +00:00
|
|
|
enum class Status {
|
|
|
|
Normal,
|
|
|
|
Undid,
|
2021-07-08 12:29:04 +00:00
|
|
|
Removed,
|
2021-07-07 21:51:58 +00:00
|
|
|
};
|
|
|
|
|
2021-04-10 13:17:18 +00:00
|
|
|
enum { Type = UserType + 1 };
|
2021-03-14 09:44:49 +00:00
|
|
|
using QGraphicsItem::QGraphicsItem;
|
|
|
|
|
2021-04-10 13:17:18 +00:00
|
|
|
int type() const override;
|
2021-03-14 09:44:49 +00:00
|
|
|
void setNumber(int number);
|
|
|
|
[[nodiscard]] int number() const;
|
2021-07-07 21:51:58 +00:00
|
|
|
|
|
|
|
[[nodiscard]] Status status() const;
|
|
|
|
void setStatus(Status status);
|
|
|
|
[[nodiscard]] bool isNormalStatus() const;
|
|
|
|
[[nodiscard]] bool isUndidStatus() const;
|
2021-07-08 12:29:04 +00:00
|
|
|
[[nodiscard]] bool isRemovedStatus() const;
|
2021-07-07 22:25:04 +00:00
|
|
|
|
|
|
|
virtual void save(SaveState state);
|
|
|
|
virtual void restore(SaveState state);
|
|
|
|
virtual bool hasState(SaveState state) const;
|
2021-03-14 09:44:49 +00:00
|
|
|
private:
|
|
|
|
int _number = 0;
|
2021-07-07 21:51:58 +00:00
|
|
|
Status _status = Status::Normal;
|
2021-03-14 09:44:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ItemBase : public NumberedItem {
|
2021-02-23 06:58:25 +00:00
|
|
|
public:
|
2021-07-06 23:10:13 +00:00
|
|
|
enum { Type = UserType + 2 };
|
2021-02-23 06:58:25 +00:00
|
|
|
|
2021-07-04 12:57:07 +00:00
|
|
|
struct Data {
|
2021-07-06 23:10:13 +00:00
|
|
|
float64 initialZoom = 0.;
|
2021-07-04 12:57:07 +00:00
|
|
|
std::shared_ptr<float64> zPtr;
|
|
|
|
int size = 0;
|
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
2021-07-04 13:13:54 +00:00
|
|
|
bool flipped = false;
|
|
|
|
int rotation = 0;
|
2021-07-06 21:13:40 +00:00
|
|
|
QSize imageSize;
|
2021-07-04 12:57:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ItemBase(Data data);
|
2021-02-23 06:58:25 +00:00
|
|
|
QRectF boundingRect() const override;
|
|
|
|
void paint(
|
|
|
|
QPainter *p,
|
|
|
|
const QStyleOptionGraphicsItem *option,
|
|
|
|
QWidget *widget) override;
|
2021-07-06 23:10:13 +00:00
|
|
|
int type() const override;
|
2021-03-10 17:50:35 +00:00
|
|
|
|
|
|
|
bool flipped() const;
|
|
|
|
void setFlip(bool value);
|
2021-07-06 23:10:13 +00:00
|
|
|
|
|
|
|
void updateZoom(float64 zoom);
|
2021-07-07 18:14:50 +00:00
|
|
|
|
2021-07-07 22:25:04 +00:00
|
|
|
bool hasState(SaveState state) const override;
|
|
|
|
void save(SaveState state) override;
|
|
|
|
void restore(SaveState state) override;
|
2021-02-23 06:58:25 +00:00
|
|
|
protected:
|
|
|
|
enum HandleType {
|
|
|
|
None,
|
|
|
|
Left,
|
|
|
|
Right,
|
|
|
|
};
|
|
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
|
|
|
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
|
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
2021-03-10 12:07:04 +00:00
|
|
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
2021-05-06 18:23:04 +00:00
|
|
|
void keyPressEvent(QKeyEvent *e) override;
|
2021-04-10 14:16:37 +00:00
|
|
|
|
|
|
|
using Action = void(ItemBase::*)();
|
|
|
|
void performForSelectedItems(Action action);
|
|
|
|
void actionFlip();
|
|
|
|
void actionDelete();
|
|
|
|
void actionDuplicate();
|
2021-02-23 06:58:25 +00:00
|
|
|
|
2021-03-10 07:45:42 +00:00
|
|
|
QRectF contentRect() const;
|
2021-02-23 06:58:25 +00:00
|
|
|
QRectF innerRect() const;
|
2021-03-09 15:12:23 +00:00
|
|
|
float64 size() const;
|
|
|
|
float64 horizontalSize() const;
|
|
|
|
float64 verticalSize() const;
|
|
|
|
void setAspectRatio(float64 aspectRatio);
|
2021-02-23 06:58:25 +00:00
|
|
|
|
2021-03-10 17:50:35 +00:00
|
|
|
virtual void performFlip();
|
2021-07-04 12:57:07 +00:00
|
|
|
virtual std::shared_ptr<ItemBase> duplicate(Data data) const = 0;
|
2021-02-23 06:58:25 +00:00
|
|
|
private:
|
|
|
|
HandleType handleType(const QPointF &pos) const;
|
|
|
|
QRectF rightHandleRect() const;
|
|
|
|
QRectF leftHandleRect() const;
|
|
|
|
bool isHandling() const;
|
2021-03-09 15:12:23 +00:00
|
|
|
void updateVerticalSize();
|
2021-03-21 17:37:45 +00:00
|
|
|
void updatePens(QPen pen);
|
2021-04-10 14:16:37 +00:00
|
|
|
void handleActionKey(not_null<QKeyEvent*> e);
|
2021-02-23 06:58:25 +00:00
|
|
|
|
2021-07-07 14:13:40 +00:00
|
|
|
Data generateData() const;
|
|
|
|
void applyData(const Data &data);
|
|
|
|
|
2021-02-23 06:58:25 +00:00
|
|
|
const std::shared_ptr<float64> _lastZ;
|
2021-07-06 21:13:40 +00:00
|
|
|
const QSize _imageSize;
|
2021-03-21 17:37:45 +00:00
|
|
|
|
|
|
|
struct {
|
|
|
|
QPen select;
|
|
|
|
QPen selectInactive;
|
|
|
|
QPen handle;
|
|
|
|
QPen handleInactive;
|
|
|
|
} _pens;
|
2021-02-23 06:58:25 +00:00
|
|
|
|
2021-03-10 12:07:04 +00:00
|
|
|
base::unique_qptr<Ui::PopupMenu> _menu;
|
|
|
|
|
2021-03-21 17:22:22 +00:00
|
|
|
struct {
|
2021-07-07 18:14:50 +00:00
|
|
|
Data data;
|
|
|
|
float64 zValue = 0.;
|
2021-07-08 12:29:04 +00:00
|
|
|
NumberedItem::Status status;
|
2021-07-07 18:14:50 +00:00
|
|
|
} _saved, _keeped;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
int min = 0;
|
|
|
|
int max = 0;
|
2021-03-21 17:22:22 +00:00
|
|
|
} _sizeLimits;
|
2021-03-10 07:45:42 +00:00
|
|
|
float64 _scaledHandleSize = 1.0;
|
|
|
|
QMarginsF _scaledInnerMargins;
|
|
|
|
|
2021-03-09 15:12:23 +00:00
|
|
|
float64 _horizontalSize = 0;
|
|
|
|
float64 _verticalSize = 0;
|
|
|
|
float64 _aspectRatio = 1.0;
|
2021-02-23 06:58:25 +00:00
|
|
|
HandleType _handle = HandleType::None;
|
|
|
|
|
2021-03-10 17:50:35 +00:00
|
|
|
bool _flipped = false;
|
|
|
|
|
2021-02-23 06:58:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Editor
|