2020-07-30 21:35:48 +01:00
|
|
|
#ifndef DRAGGABLEPIXMAPITEM_H
|
|
|
|
#define DRAGGABLEPIXMAPITEM_H
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
#include <QGraphicsItemGroup>
|
|
|
|
#include <QGraphicsPixmapItem>
|
|
|
|
#include <QGraphicsItemAnimation>
|
|
|
|
|
|
|
|
#include <QtWidgets>
|
|
|
|
|
2022-07-19 22:56:12 +01:00
|
|
|
#include "events.h"
|
2020-07-30 21:35:48 +01:00
|
|
|
|
|
|
|
class Editor;
|
|
|
|
|
|
|
|
class DraggablePixmapItem : public QObject, public QGraphicsPixmapItem {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
DraggablePixmapItem(QPixmap pixmap): QGraphicsPixmapItem(pixmap) {}
|
|
|
|
|
2022-07-19 22:56:12 +01:00
|
|
|
DraggablePixmapItem(Event *event, Editor *editor) : QGraphicsPixmapItem(event->getPixmap()) {
|
|
|
|
this->event = event;
|
2020-07-30 21:35:48 +01:00
|
|
|
event->setPixmapItem(this);
|
2022-07-19 22:56:12 +01:00
|
|
|
this->editor = editor;
|
2020-07-30 21:35:48 +01:00
|
|
|
updatePosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
Editor *editor = nullptr;
|
|
|
|
Event *event = nullptr;
|
|
|
|
QGraphicsItemAnimation *pos_anim = nullptr;
|
|
|
|
|
|
|
|
bool active;
|
|
|
|
int last_x;
|
|
|
|
int last_y;
|
|
|
|
|
|
|
|
void updatePosition();
|
2021-03-23 01:57:34 +00:00
|
|
|
void move(int dx, int dy);
|
|
|
|
void moveTo(const QPoint &pos);
|
2020-07-30 21:35:48 +01:00
|
|
|
void emitPositionChanged();
|
|
|
|
void updatePixmap();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void positionChanged(Event *event);
|
|
|
|
void xChanged(int);
|
|
|
|
void yChanged(int);
|
|
|
|
void elevationChanged(int);
|
|
|
|
void spriteChanged(QPixmap pixmap);
|
|
|
|
void onPropertyChanged(QString key, QString value);
|
|
|
|
|
|
|
|
public slots:
|
2022-07-19 22:56:12 +01:00
|
|
|
void set_x(int x) {
|
|
|
|
event->setX(x);
|
2020-07-30 21:35:48 +01:00
|
|
|
updatePosition();
|
|
|
|
}
|
2022-07-19 22:56:12 +01:00
|
|
|
void set_y(int y) {
|
|
|
|
event->setY(y);
|
2020-07-30 21:35:48 +01:00
|
|
|
updatePosition();
|
|
|
|
}
|
2022-07-19 22:56:12 +01:00
|
|
|
void set_elevation(int z) {
|
|
|
|
event->setElevation(z);
|
2020-07-30 21:35:48 +01:00
|
|
|
updatePosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
|
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
|
|
|
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DRAGGABLEPIXMAPITEM_H
|