// (C) 2011 Underground Software
// See the README and GPLv3 files for licensing and warranty information
//
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
//
// WHO WHEN WHAT
// --- ---------- ------------------------------------------------------------
#include <QtGui>
#include "mathconstants.h"
+#include "painter.h"
Dimension::Dimension(Vector p1, Vector p2, Object * p/*= NULL*/): Object(p1, p), endpoint(p2),
{
}
-/*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.
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();
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.
//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
needUpdate = true;
}
+Vector Dimension::GetPoint1(void)
+{
+ return position;
+}
+
+Vector Dimension::GetPoint2(void)
+{
+ return endpoint;
+}
+
void Dimension::FlipSides(void)
{
#if 0
#endif
needUpdate = true;
}
+