X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdimension.cpp;h=26a39f5d29d9b4c001a47e5d79c4b793336ed203;hb=5446001bd9adfd9f4787f5de5a2a7afd8d7cdb5a;hp=b9fc97620d8708afa2cbdd08b1fc1fd38d98dc81;hpb=746443089f76c115245d1500b780d7d189b9b2af;p=architektonas diff --git a/src/dimension.cpp b/src/dimension.cpp index b9fc976..26a39f5 100644 --- a/src/dimension.cpp +++ b/src/dimension.cpp @@ -4,7 +4,7 @@ // (C) 2011 Underground Software // See the README and GPLv3 files for licensing and warranty information // -// JLH = James L. Hammons +// JLH = James Hammons // // WHO WHEN WHAT // --- ---------- ------------------------------------------------------------ @@ -15,6 +15,7 @@ #include #include "mathconstants.h" +#include "painter.h" Dimension::Dimension(Vector p1, Vector p2, Object * p/*= NULL*/): Object(p1, p), endpoint(p2), @@ -34,7 +35,7 @@ Dimension::~Dimension() { } -/*virtual*/ void Dimension::Draw(QPainter * painter) +/*virtual*/ void Dimension::Draw(Painter * 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. @@ -45,9 +46,9 @@ Dimension::~Dimension() endpoint = *point2; if (state == OSSelected) - painter->setPen(QPen(Qt::red, 2.0, Qt::DotLine)); + painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine)); else - painter->setPen(QPen(Qt::blue, 1.0, Qt::SolidLine)); + painter->SetPen(QPen(Qt::blue, 1.0, Qt::SolidLine)); // Draw an aligned dimension line double angle = Vector(endpoint - position).Angle(); @@ -55,29 +56,37 @@ Dimension::~Dimension() Vector orthogonal = Vector(cos(orthoAngle), sin(orthoAngle)); Vector unit = Vector(endpoint - position).Unit(); +//NOTE: SCREEN_ZOOM is our kludge factor... We need to figure out a better +// way of doing this... // Get our line parallel to our points - Point p1 = position + (orthogonal * 10.0); - Point p2 = endpoint + (orthogonal * 10.0); + Point p1 = position + (orthogonal * 10.0 * SCREEN_ZOOM); + Point p2 = endpoint + (orthogonal * 10.0 * SCREEN_ZOOM); // Draw main dimension line - painter->drawLine(QPointF(p1.x, p1.y), QPointF(p2.x, p2.y)); + painter->DrawLine(p1, p2); - Point p3 = position + (orthogonal * 16.0); - Point p4 = endpoint + (orthogonal * 16.0); - Point p5 = position + (orthogonal * 4.0); - Point p6 = endpoint + (orthogonal * 4.0); + Point p3 = position + (orthogonal * 16.0 * SCREEN_ZOOM); + Point p4 = endpoint + (orthogonal * 16.0 * SCREEN_ZOOM); + Point p5 = position + (orthogonal * 4.0 * SCREEN_ZOOM); + Point p6 = endpoint + (orthogonal * 4.0 * SCREEN_ZOOM); // Draw extension lines - painter->drawLine(QPointF(p3.x, p3.y), QPointF(p5.x, p5.y)); - painter->drawLine(QPointF(p4.x, p4.y), QPointF(p6.x, p6.y)); + painter->DrawLine(p3, p5); + painter->DrawLine(p4, p6); + + painter->SetBrush(QBrush(QColor(Qt::blue))); + painter->DrawArrowhead(p1, p2); + painter->DrawArrowhead(p2, p1); // Draw length of dimension line... - painter->setFont(QFont("Arial", 10)); + painter->SetFont(QFont("Arial", 10.0 * Painter::zoom * SCREEN_ZOOM)); Vector v1((p1.x - p2.x) / 2.0, (p1.y - p2.y) / 2.0); Point ctr = p2 + v1; + // This is in pixels, which isn't even remotely correct... !!! FIX !!! QString dimText = QString("%1\"").arg(Vector(endpoint - position).Magnitude()); - int textWidth = QFontMetrics(painter->font()).width(dimText); - int textHeight = QFontMetrics(painter->font()).height(); +// int textWidth = QFontMetrics(painter->font()).width(dimText); +// int textHeight = QFontMetrics(painter->font()).height(); +#if 0 //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. @@ -98,11 +107,17 @@ 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, yOffset, 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(); +#else +// painter->DrawText(QRectF(QPointF(ctr.x, ctr.y), QPointF(ctr.x + textWidth, ctr.y + textHeight)), Qt::AlignVCenter, dimText); +// Now that we've taken our own good advice, maybe we should have the painter class +// do a nice abstracted text draw routine? :-) + painter->DrawAngledText(ctr, angle, dimText); +#endif /* All of the preceeding makes me think that rather than try to compensate for Qt's unbelieveably @@ -314,6 +329,16 @@ void Dimension::SetPoint2(Vector * v) needUpdate = true; } +Vector Dimension::GetPoint1(void) +{ + return position; +} + +Vector Dimension::GetPoint2(void) +{ + return endpoint; +} + void Dimension::FlipSides(void) { #if 0 @@ -327,3 +352,4 @@ void Dimension::FlipSides(void) #endif needUpdate = true; } +