4 #include "../model/arena.h" 5 #include "../model/arenaelement.h" 6 #include "../model/arenaelementtype.h" 10 #include <QMouseEvent> 11 #include <QMessageBox> 16 : QGraphicsView(parent)
17 , m_controller(controller)
19 setDragMode(QGraphicsView::RubberBandDrag);
20 setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
25 void drawCross(QPainter *painter, QPoint p,
int lineLength)
27 painter->drawLine(p.x() - lineLength, p.y(), p.x() + lineLength, p.y());
28 painter->drawLine(p.x(), p.y() - lineLength, p.x(), p.y() + lineLength);
33 QMessageBox::warning(parentWidget(),
"Grid Painting Monkey",
34 "Aaargh. This is just too many grid points. Sorry. Falling back to white background.");
41 qreal scale = qMin(transform().m11(), transform().m22());
49 painter->setPen(0xE0E0E0);
52 QRectF scRect = scene()->sceneRect();
53 p0.rx() = qMax(p0.x(), scRect.left());
54 p0.ry() = qMax(p0.y(), scRect.top());
55 int visibleSceneWidth = qMin(rect.width(), scRect.width()) +
CELL_SIZE;
56 int visibleSceneHeight = qMin(rect.height(), scRect.height()) +
CELL_SIZE;
74 for (
int x = 0; x <= visibleSceneWidth; x +=
CELL_SIZE)
76 for (
int y = 0; y <= visibleSceneHeight; y +=
CELL_SIZE)
79 QPoint p = p0.toPoint() + QPoint(x, y)
104 bool forwardEvent =
true;
115 forwardEvent =
false;
123 setDragMode(QGraphicsView::RubberBandDrag);
125 setDragMode(QGraphicsView::NoDrag);
131 QGraphicsView::mousePressEvent(event);
139 bool forwardEvent =
true;
143 QPointF mousePos = mapToScene(event->pos());
154 if (selectedElements.count() == 1 &&
155 !selectedElements.first()->element()->isItem())
166 forwardEvent =
false;
168 else if (event->buttons() & Qt::RightButton)
172 int oldX = horizontalScrollBar()->value();
173 int oldY = verticalScrollBar()->value();
174 horizontalScrollBar()->setValue(oldX - diff.x());
175 verticalScrollBar()->setValue(oldY - diff.y());
182 QGraphicsView::mouseMoveEvent(event);
187 QGraphicsView::mouseReleaseEvent(event);
206 if (event->delta() > 0)
212 #define MIN_SCALE 0.1 213 #define MAX_SCALE 5.0 217 QTransform trans = transform().scale(2.0, 2.0);
224 QTransform trans = transform().scale(0.5, 0.5);
233 setSceneRect(scene()->sceneRect());
239 setSceneRect(QRectF());
247 QString elementTypeName =
event->mimeData()->data(
"type");
void mouseReleaseEvent(QMouseEvent *event)
ArenaController * m_controller
ArenaElementType const * type() const
void dropEvent(QDropEvent *event)
QList< ArenaSceneElement * > selectedElements()
bool operationInProgress() const
void drawCross(QPainter *painter, QPoint p, int lineLength)
void draw(QPainter *painter, const QRectF &rect)
void mouseMoveEvent(QMouseEvent *event)
void dragTo(const QPointF &to)
void slotGridPaintingDisabled()
void wheelEvent(QWheelEvent *event)
ArenaElement * element() const
void dragBy(const QPointF &by)
ArenaView(ArenaController *controller, QWidget *parent=0)
void drawBackground(QPainter *painter, const QRectF &rect)
QPointF m_lastMousePosScene
static QPointF nearestGridPoint(QPointF scenePos)
void dragLeaveEvent(QDragLeaveEvent *event)
void drawForeground(QPainter *painter, const QRectF &rect)
ArenaScene * arenaScene()
void mousePressEvent(QMouseEvent *event)
void startInsertion(const QString &elementType, const QPointF &pos)
void dragMoveEvent(QDragMoveEvent *event)
void dragEnterEvent(QDragEnterEvent *event)
void startDrag(ArenaSceneElement *sceneElement)