X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdimension.cpp;h=b9fc97620d8708afa2cbdd08b1fc1fd38d98dc81;hb=7ac2021bfe0d3032e161520e3fa790ef621e39b3;hp=d049fc32da0316336c4ba0414bce1cd2e8de5e9a;hpb=9f6ad3fe0b9cb30115a5d38e8af3aebed0d70c08;p=architektonas diff --git a/src/dimension.cpp b/src/dimension.cpp index d049fc3..b9fc976 100644 --- a/src/dimension.cpp +++ b/src/dimension.cpp @@ -19,7 +19,14 @@ Dimension::Dimension(Vector p1, Vector p2, Object * p/*= NULL*/): Object(p1, p), endpoint(p2), dragging(false), draggingHandle1(false), draggingHandle2(false), - length(p2.Magnitude()) + length(p2.Magnitude()), point1(NULL), point2(NULL) +{ +} + +// This is bad, p1 & p2 could be NULL, causing much consternation... +Dimension::Dimension(Vector * p1, Vector * p2, Object * p/*= NULL*/): Object(*p1, p), endpoint(*p2), + dragging(false), draggingHandle1(false), draggingHandle2(false), + length(p2->Magnitude()), point1(p1), point2(p2) { } @@ -29,39 +36,19 @@ Dimension::~Dimension() /*virtual*/ void Dimension::Draw(QPainter * painter) { + // If there are valid Vector pointers in here, use them to update the internal + // positions. Otherwise, we just use the internal positions by default. + if (point1) + position = *point1; + + if (point2) + endpoint = *point2; + if (state == OSSelected) painter->setPen(QPen(Qt::red, 2.0, Qt::DotLine)); else painter->setPen(QPen(Qt::blue, 1.0, Qt::SolidLine)); -#if 0 -// if (draggingHandle1) - if (state == OSSelected) - painter->drawEllipse(QPointF(position.x, position.y), 4.0, 4.0); - -// if (draggingHandle2) - if (state == OSSelected) - painter->drawEllipse(QPointF(endpoint.x, endpoint.y), 4.0, 4.0); - - if (Object::fixedLength && (draggingHandle1 || draggingHandle2)) - { - Vector point1 = (draggingHandle1 ? endpoint : position); - Vector point2 = (draggingHandle1 ? position : endpoint); - - Vector current(point2 - point1); - Vector v = current.Unit() * length; - Vector v2 = point1 + v; - painter->drawLine((int)point1.x, (int)point1.y, (int)v2.x, (int)v2.y); - - if (current.Magnitude() > length) - { - painter->setPen(QPen(QColor(128, 0, 0), 1.0, Qt::DashLine)); - painter->drawLine((int)v2.x, (int)v2.y, (int)point2.x, (int)point2.y); - } - } - else - painter->drawLine((int)position.x, (int)position.y, (int)endpoint.x, (int)endpoint.y); -#endif // Draw an aligned dimension line double angle = Vector(endpoint - position).Angle(); double orthoAngle = angle + (PI / 2.0); @@ -90,21 +77,40 @@ Dimension::~Dimension() Point ctr = p2 + v1; QString dimText = QString("%1\"").arg(Vector(endpoint - position).Magnitude()); int textWidth = QFontMetrics(painter->font()).width(dimText); + int textHeight = QFontMetrics(painter->font()).height(); //We have to do transformation voodoo to make the text come out readable and in correct orientation... //Some things to note here: if angle > 90 degrees, then we need to take the negative of the angle //for our text. painter->save(); painter->translate(ctr.x, ctr.y); +int yOffset = -8; +//16 : printf("textHeight: %d\n", textHeight); + +//Fix text so it isn't upside down... +if ((angle > PI * 0.5) && (angle < PI * 1.5)) +{ + angle += PI; + yOffset = 18; +} + painter->rotate(angle * RADIANS_TO_DEGREES); painter->scale(1.0, -1.0); //painter->translate(-textWidth / 2, -24); // painter->drawText(0, 0, textWidth, 20, Qt::AlignCenter, dimText); // This version draws the y-coord from the baseline of the font - painter->drawText(-textWidth / 2, -8, dimText); + painter->drawText(-textWidth / 2, yOffset, dimText); //painter->setPen(QPen(QColor(0xFF, 0x20, 0x20), 1.0, Qt::SolidLine)); //painter->drawLine(20, 0, -20, 0); //painter->drawLine(0, 20, 0, -20); painter->restore(); + +/* +All of the preceeding makes me think that rather than try to compensate for Qt's unbelieveably +AWFUL decision to go with a wrong-handed graphics subsystem, it may be better to just stuff +all of that crap into some kind of subclass that handles all the nastiness behind the scenes. +I mean, really, all this crap just to get some proplerly rendered text on the screen? How +retarded is that? :-/ +*/ } /*virtual*/ Vector Dimension::Center(void) @@ -295,3 +301,29 @@ about keeping track of old states... if (objectWasDragged) state = oldState; } + +void Dimension::SetPoint1(Vector * v) +{ + point1 = v; + needUpdate = true; +} + +void Dimension::SetPoint2(Vector * v) +{ + point2 = v; + needUpdate = true; +} + +void Dimension::FlipSides(void) +{ +#if 0 + Vector tmp = position; + position = endpoint; + endpoint = tmp; +#else + Vector * tmp = point1; + point1 = point2; + point2 = tmp; +#endif + needUpdate = true; +}