X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdrawingview.cpp;h=015431c88e3fece1f53954e22d489a460bd5e1bf;hb=a398911ea125eb6b25320e96599e0ae39b720cf8;hp=957aaf87a56d27b70fb622fccfb45ad07b990d3d;hpb=4bc000ba003a53fb11428a2eb71e3b4471a15c7a;p=architektonas diff --git a/src/drawingview.cpp b/src/drawingview.cpp index 957aaf8..015431c 100644 --- a/src/drawingview.cpp +++ b/src/drawingview.cpp @@ -334,6 +334,13 @@ void DrawingView::paintEvent(QPaintEvent * /*event*/) painter.DrawCrosshair(oldPoint); toolAction->Draw(&painter); } +#else + if (Global::tool) + { + painter.SetPen(QPen(QColor(200, 100, 0, 255), 1.0, Qt::DashLine)); + painter.DrawCrosshair(oldPoint); + ToolDraw(&painter); + } #endif #if 1 @@ -595,6 +602,73 @@ void DrawingView::resizeEvent(QResizeEvent * /*event*/) } +void DrawingView::ToolMouseDown(Point p) +{ + if (Global::tool == TTLine) + { + if (Global::toolState == TSNone) + { + toolPoint[0] = p; +// toolState = TSPoint1; +// toolObject = (Object *)(new Line(p, Vector(0, 0))); + } + else //if (Global::toolState == TSPoint1) + { + toolPoint[1] = p; + } + } +} + + +void DrawingView::ToolMouseMove(Point p) +{ + if (Global::tool == TTLine) + { + if (Global::toolState == TSNone) + toolPoint[0] = p; + else + toolPoint[1] = p; + } +} + + +void DrawingView::ToolMouseUp(Point p) +{ + if (Global::tool == TTLine) + { + if (Global::toolState == TSNone) + { + Global::toolState = TSPoint2; + // Prevent spurious line from drawing... + toolPoint[1] = toolPoint[0]; + } + else + { + Line * l = new Line(toolPoint[0], toolPoint[1]); + document.objects.push_back(l); + toolPoint[0] = toolPoint[1]; + } + } +} + + +void DrawingView::ToolDraw(Painter * painter) +{ + if (Global::tool == TTLine) + { + if (Global::toolState == TSNone) + { + painter->DrawHandle(toolPoint[0]); + } + else + { + painter->DrawLine(toolPoint[0], toolPoint[1]); + painter->DrawHandle(toolPoint[1]); + } + } +} + + void DrawingView::mousePressEvent(QMouseEvent * event) { if (event->button() == Qt::LeftButton) @@ -626,6 +700,15 @@ void DrawingView::mousePressEvent(QMouseEvent * event) #else if (Global::tool) { + if (Global::snapToGrid) + point = SnapPointToGrid(point); + + // Snap to object point if valid... + + + ToolMouseDown(point); + //Also, may want to figure out if hovering over a snap point on an object, + //snap to grid if not. return; } #endif @@ -682,7 +765,8 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event) #if 1 // Grid processing... (only snap here is left button is down) - if ((event->buttons() & Qt::LeftButton) && Global::snapToGrid) + // Umm, WHY?? + if (/*(event->buttons() & Qt::LeftButton) &&*/ Global::snapToGrid) { point = SnapPointToGrid(point); } @@ -885,7 +969,9 @@ selected object last and thus fucks up the algorithm. Need to fix this... toolAction->MouseMoved(point); } +#else #endif + bool needUpdate = false; // Don't do this kind of checking unless we're not doing a selection rectangle! @@ -967,6 +1053,13 @@ selected object last and thus fucks up the algorithm. Need to fix this... } //printf("MouseMove: numHovered = %i\n", numHovered); + // Tool handling... + if (Global::tool) + { + // Need to do snapping, etc. as well + ToolMouseMove(point); + } + // This is used to draw the tool crosshair... oldPoint = point; @@ -994,6 +1087,13 @@ void DrawingView::mouseReleaseEvent(QMouseEvent * event) #if 0 if (toolAction) toolAction->MouseReleased(); +#else + if (Global::tool) + { + Vector point = Painter::QtToCartesianCoords(Vector(event->x(), event->y())); + ToolMouseUp(point); + return; + } #endif if (Global::selectionInProgress)