porymap/include/ui/graphicsview.h
2024-10-31 14:58:01 -04:00

56 lines
1.3 KiB
C++

#ifndef GRAPHICSVIEW_H
#define GRAPHICSVIEW_H
#include <QGraphicsView>
#include <QMouseEvent>
class NoScrollGraphicsView : public QGraphicsView
{
Q_OBJECT
public:
NoScrollGraphicsView(QWidget *parent = nullptr) : QGraphicsView(parent) {}
protected:
void wheelEvent(QWheelEvent *event) {
event->ignore();
}
};
class ClickableGraphicsView : public NoScrollGraphicsView
{
Q_OBJECT
public:
ClickableGraphicsView(QWidget *parent = nullptr) : NoScrollGraphicsView(parent) {}
public:
void mouseReleaseEvent(QMouseEvent *event) override {
QGraphicsView::mouseReleaseEvent(event);
emit this->clicked(event);
}
signals:
void clicked(QMouseEvent *event);
};
class Editor;
// TODO: This should just be MapView. It makes map-based assumptions, and no other class inherits GraphicsView.
class GraphicsView : public QGraphicsView
{
public:
GraphicsView() : QGraphicsView() {}
GraphicsView(QWidget *parent) : QGraphicsView(parent) {}
public:
// GraphicsView_Object object;
Editor *editor;
protected:
virtual void mousePressEvent(QMouseEvent *event) override;
virtual void mouseMoveEvent(QMouseEvent *event) override;
virtual void mouseReleaseEvent(QMouseEvent *event) override;
virtual void moveEvent(QMoveEvent *event) override;
};
//Q_DECLARE_METATYPE(GraphicsView)
#endif // GRAPHICSVIEW_H