X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdrawingview.cpp;h=31aeaf028193e6fe9c43cb530a9a166d7c6befce;hb=bb8d0671717bac2c5350e34024273381be1d8175;hp=8f689a80bd0e33cd2ef3000ba7bff14fea6d5c59;hpb=70297ac8ec7453e4196f4b58056bcfe4b04f2aca;p=architektonas diff --git a/src/drawingview.cpp b/src/drawingview.cpp index 8f689a8..31aeaf0 100644 --- a/src/drawingview.cpp +++ b/src/drawingview.cpp @@ -34,6 +34,7 @@ #include "arc.h" #include "circle.h" #include "dimension.h" +#include "drawarcaction.h" #include "drawcircleaction.h" #include "drawdimensionaction.h" #include "drawlineaction.h" @@ -124,7 +125,8 @@ Painter::zoom *and* size. Same with the dimension text; it's drawn at 10pt and scaled the same way as the arrowheads. Need a way to scale line widths as well. :-/ Shouldn't be too difficult, just -need a thickness parameter similar to the "size" param for dimensions. +need a thickness parameter similar to the "size" param for dimensions. (And now +we do! :-) */ #if 0 @@ -180,6 +182,19 @@ void DrawingView::SetAddCircleToolActive(bool state/*= true*/) } +void DrawingView::SetAddArcToolActive(bool state/*= true*/) +{ + if (state) + { + toolAction = new DrawArcAction(); + connect(toolAction, SIGNAL(ObjectReady(Object *)), this, + SLOT(AddNewObjectToDocument(Object *))); + } + + update(); +} + + void DrawingView::SetAddDimensionToolActive(bool state/*= true*/) { if (state) @@ -328,6 +343,26 @@ QPoint DrawingView::GetAdjustedClientPosition(int x, int y) } +// +// This looks strange, but it's really quite simple: We want a point that's +// more than half-way to the next grid point to snap there while conversely we +// want a point that's less than half-way to to the next grid point then snap +// to the one before it. So we add half of the grid spacing to the point, then +// divide by it so that we can remove the fractional part, then multiply it +// back to get back to the correct answer. +// +Vector DrawingView::SnapPointToGrid(Vector point) +{ + point += gridSpacing / 2.0; // *This* adds to Z!!! + point /= gridSpacing; + point.x = floor(point.x);//need to fix this for negative numbers... + point.y = floor(point.y); + point.z = 0; // Make *sure* Z doesn't go anywhere!!! + point *= gridSpacing; + return point; +} + + void DrawingView::paintEvent(QPaintEvent * /*event*/) { QPainter qtPainter(this); @@ -388,6 +423,10 @@ void DrawingView::mousePressEvent(QMouseEvent * event) if (event->button() == Qt::LeftButton) { Vector point = Painter::QtToCartesianCoords(Vector(event->x(), event->y())); + + if (Object::snapToGrid) + point = SnapPointToGrid(point); + collided = document.Collided(point); if (collided) @@ -437,14 +476,9 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event) // Grid processing... #if 1 - // This looks strange, but it's really quite simple: We want a point that's - // more than half-way to the next grid point to snap there while conversely - // we want a point that's less than half-way to to the next grid point then - // snap to the one before it. So we add half of the grid spacing to the - // point, then divide by it so that we can remove the fractional part, then - // multiply it back to get back to the correct answer. - if (event->buttons() & Qt::LeftButton) + if ((event->buttons() & Qt::LeftButton) && Object::snapToGrid) { +#if 0 point += gridSpacing / 2.0; // *This* adds to Z!!! point /= gridSpacing; //200% is ok, gridSpacing = 6 in this case... @@ -455,6 +489,9 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event) point.y = floor(point.y); point.z = 0; // Make *sure* Z doesn't go anywhere!!! point *= gridSpacing; +#else + point = SnapPointToGrid(point); +#endif } #endif //we should keep track of the last point here and only pass this down *if* the point