]> Shamusworld >> Repos - architektonas/blobdiff - src/drawingview.cpp
Beginning to make the Layer widget functional.
[architektonas] / src / drawingview.cpp
index bdc3540b0442fc51b243e6096da6a94b362d2632..3020368913cfa3b4358df95669b1b65649523d15 100644 (file)
@@ -49,8 +49,8 @@ DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent),
        document(Vector(0, 0)),
        /*gridSpacing(12.0),*/ gridPixels(0), collided(false), rotateTool(false),
        rx(150.0), ry(150.0),
-       scrollDrag(false), addLineTool(false), addCircleTool(false),
-       addDimensionTool(false),
+//     scrollDrag(false), addLineTool(false), addCircleTool(false),
+//     addDimensionTool(false),
        toolAction(NULL)
 {
        document.isTopLevelContainer = true;
@@ -266,6 +266,13 @@ void DrawingView::AddNewObjectToDocument(Object * object)
 }
 
 
+void DrawingView::SetCurrentLayer(int layer)
+{
+       Object::currentLayer = layer;
+//printf("DrawingView::CurrentLayer = %i\n", layer);
+}
+
+
 QPoint DrawingView::GetAdjustedMousePosition(QMouseEvent * event)
 {
        // This is undoing the transform, e.g. going from client coords to local coords.
@@ -393,7 +400,12 @@ Now we do... :-/
                        update();       // Do an update if collided with at least *one* object in the document
 
                if (toolAction)
+               {
+                       if (Object::snapToGrid)
+                               point = Object::SnapPointToGrid(point);
+
                        toolAction->MouseDown(point);
+               }
 
                // Didn't hit any object and not using a tool, so do a selection rectangle
                if (!(collided || toolAction))
@@ -491,3 +503,27 @@ void DrawingView::mouseReleaseEvent(QMouseEvent * event)
        }
 }
 
+
+void DrawingView::keyPressEvent(QKeyEvent * event)
+{
+       if (toolAction)
+       {
+               bool needUpdate = toolAction->KeyDown(event->key());
+
+               if (needUpdate)
+                       update();
+       }
+}
+
+
+void DrawingView::keyReleaseEvent(QKeyEvent * event)
+{
+       if (toolAction)
+       {
+               bool needUpdate = toolAction->KeyReleased(event->key());
+
+               if (needUpdate)
+                       update();
+       }
+}
+