mirror of
https://github.com/huderlem/porymap.git
synced 2026-08-19 23:25:09 -05:00
Map connection edit history
This commit is contained in:
@@ -9,36 +9,37 @@
|
||||
class ConnectionPixmapItem : public QObject, public QGraphicsPixmapItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ConnectionPixmapItem(QPixmap pixmap, MapConnection* connection, int x, int y)
|
||||
: QGraphicsPixmapItem(pixmap)
|
||||
{
|
||||
this->basePixmap = pixmap;
|
||||
this->connection = connection;
|
||||
setFlag(ItemIsMovable);
|
||||
setFlag(ItemSendsGeometryChanges);
|
||||
this->initialX = x;
|
||||
this->initialY = y;
|
||||
this->initialOffset = connection->offset();
|
||||
this->setPos(x, y);
|
||||
}
|
||||
QPixmap basePixmap;
|
||||
QPointer<MapConnection> connection;
|
||||
int initialX;
|
||||
int initialY;
|
||||
int initialOffset;
|
||||
ConnectionPixmapItem(MapConnection* connection, int originX, int originY);
|
||||
ConnectionPixmapItem(MapConnection* connection, QPoint origin);
|
||||
|
||||
const QPointer<MapConnection> connection;
|
||||
|
||||
void setOrigin(int x, int y);
|
||||
void setOrigin(QPoint pos);
|
||||
|
||||
void setEditable(bool editable);
|
||||
bool getEditable();
|
||||
|
||||
void setSelected(bool selected);
|
||||
void render();
|
||||
|
||||
void updatePos();
|
||||
void render(bool ignoreCache = false);
|
||||
|
||||
private:
|
||||
QPixmap basePixmap;
|
||||
qreal originX;
|
||||
qreal originY;
|
||||
bool selected = false;
|
||||
unsigned actionId = 0;
|
||||
|
||||
static const int mWidth = 16;
|
||||
static const int mHeight = 16;
|
||||
|
||||
protected:
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*);
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent*) override;
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent*) override;
|
||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*) override;
|
||||
|
||||
signals:
|
||||
void connectionItemDoubleClicked(MapConnection*);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define CONNECTIONSLISTITEM_H
|
||||
|
||||
#include "mapconnection.h"
|
||||
#include "map.h"
|
||||
|
||||
#include <QFrame>
|
||||
#include <QMouseEvent>
|
||||
@@ -30,11 +31,13 @@ public:
|
||||
|
||||
private:
|
||||
Ui::ConnectionsListItem *ui;
|
||||
Map *map;
|
||||
bool isSelected = false;
|
||||
unsigned actionId = 0;
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *);
|
||||
void mouseDoubleClickEvent(QMouseEvent *);
|
||||
void mousePressEvent(QMouseEvent*) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent*) override;
|
||||
|
||||
signals:
|
||||
void removed(MapConnection*);
|
||||
|
||||
@@ -5,30 +5,26 @@
|
||||
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QPointer>
|
||||
#include <QComboBox>
|
||||
|
||||
class DivingMapPixmapItem : public QObject, public QGraphicsPixmapItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DivingMapPixmapItem(MapConnection* connection)
|
||||
: QGraphicsPixmapItem(getBasePixmap(connection))
|
||||
{
|
||||
m_connection = connection;
|
||||
DivingMapPixmapItem(MapConnection *connection, QComboBox *combo);
|
||||
~DivingMapPixmapItem();
|
||||
|
||||
// Update pixmap if the connected map is swapped.
|
||||
connect(m_connection, &MapConnection::targetMapNameChanged, this, &DivingMapPixmapItem::updatePixmap);
|
||||
}
|
||||
MapConnection* connection() const { return m_connection; }
|
||||
void updatePixmap();
|
||||
|
||||
private:
|
||||
QPointer<MapConnection> m_connection;
|
||||
QPointer<QComboBox> m_combo;
|
||||
|
||||
static QPixmap getBasePixmap(MapConnection* connection) {
|
||||
// If the map is connected to itself then rendering is pointless.
|
||||
if (!connection || connection->targetMapName() == connection->parentMapName())
|
||||
return QPixmap();
|
||||
return connection->getPixmap();
|
||||
}
|
||||
void updatePixmap() { setPixmap(getBasePixmap(m_connection)); }
|
||||
void setComboText(const QString &text);
|
||||
static QPixmap getBasePixmap(MapConnection* connection);
|
||||
|
||||
private slots:
|
||||
void onTargetMapChanged();
|
||||
};
|
||||
|
||||
#endif // DIVINGMAPPIXMAPITEM_H
|
||||
|
||||
@@ -17,10 +17,11 @@ public:
|
||||
explicit NewMapConnectionDialog(QWidget *parent, Map* map, const QStringList &mapNames);
|
||||
~NewMapConnectionDialog();
|
||||
|
||||
MapConnection *result;
|
||||
|
||||
virtual void accept() override;
|
||||
|
||||
signals:
|
||||
void accepted(MapConnection *result);
|
||||
|
||||
private:
|
||||
Ui::NewMapConnectionDialog *ui;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user