Some basic functionality
authorunc0rr
Sat, 27 Nov 2010 23:55:39 +0300
changeset 4424 3225ea34e415
parent 4423 4391526e436e
child 4425 2314bb0c433d
Some basic functionality
tools/drawMapTest/drawmapscene.cpp
tools/drawMapTest/drawmapscene.h
--- a/tools/drawMapTest/drawmapscene.cpp	Sat Nov 27 22:40:29 2010 +0300
+++ b/tools/drawMapTest/drawmapscene.cpp	Sat Nov 27 23:55:39 2010 +0300
@@ -4,23 +4,49 @@
 #include "drawmapscene.h"
 
 DrawMapScene::DrawMapScene(QObject *parent) :
-    QGraphicsScene(parent)
+    QGraphicsScene(parent),
+    m_pen(Qt::black),
+    m_brush(Qt::black)
 {
     setSceneRect(0, 0, 4096, 2048);
+
+    QLinearGradient gradient(0, 0, 0, 2048);
+    gradient.setColorAt(0, QColor(160, 160, 255));
+    gradient.setColorAt(1, QColor(255, 255, 160));
+    setBackgroundBrush(QBrush(gradient));
+
+    m_halfWidth = 67;
 }
 
 void DrawMapScene::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent)
 {
 
     qDebug() << "move" << mouseEvent->scenePos();
+
+    if(mouseEvent->buttons() && Qt::LeftButton)
+        drawFigure(mouseEvent->scenePos());
 }
 
 void DrawMapScene::mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent)
 {
     qDebug() << "press" << mouseEvent->scenePos();
+
+    drawFigure(mouseEvent->scenePos());
 }
 
 void DrawMapScene::mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent)
 {
     qDebug() << "release" << mouseEvent->scenePos();
 }
+
+void DrawMapScene::drawFigure(const QPointF & point)
+{
+    addEllipse(
+            point.x() - m_halfWidth,
+            point.y() - m_halfWidth,
+            m_halfWidth * 2,
+            m_halfWidth * 2,
+            m_pen,
+            m_brush
+        );
+}
--- a/tools/drawMapTest/drawmapscene.h	Sat Nov 27 22:40:29 2010 +0300
+++ b/tools/drawMapTest/drawmapscene.h	Sat Nov 27 23:55:39 2010 +0300
@@ -14,9 +14,15 @@
 public slots:
 
 private:
+    qreal m_halfWidth;
+    QPen m_pen;
+    QBrush m_brush;
+
     virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent);
     virtual void mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent);
     virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent);
+
+    void drawFigure(const QPointF & point);
 };
 
 #endif // DRAWMAPSCENE_H