From: Shamus Hammons Date: Mon, 6 Feb 2012 20:31:32 +0000 (+0000) Subject: First stabs at sizing dimension lines properly. X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d5d4488ba75c407709556a7ed56b8d16e21834e;p=architektonas First stabs at sizing dimension lines properly. --- diff --git a/src/applicationwindow.cpp b/src/applicationwindow.cpp index 36c256f..66f9edc 100644 --- a/src/applicationwindow.cpp +++ b/src/applicationwindow.cpp @@ -53,6 +53,8 @@ ApplicationWindow::ApplicationWindow(): settings("Underground Software", "Archit CreateToolbars(); // Create status bar + zoomIndicator = new QLabel("Zoom: 12.5%"); + statusBar()->addPermanentWidget(zoomIndicator); statusBar()->showMessage(tr("Ready")); ReadSettings(); @@ -120,6 +122,18 @@ void ApplicationWindow::AddCircleTool(void) SetInternalToolStates(); } +void ApplicationWindow::AddArcTool(void) +{ + ClearUIToolStatesExcept(addArcAct); + SetInternalToolStates(); +} + +void ApplicationWindow::AddPolygonTool(void) +{ + ClearUIToolStatesExcept(addPolygonAct); + SetInternalToolStates(); +} + void ApplicationWindow::ZoomInTool(void) { double zoomFactor = 2.0; @@ -148,6 +162,7 @@ when zooming in, new origin will be (xCenter - origin.x) / 2, (yCenter - origin. //printf("Zoom in... level going from %02f to ", Painter::zoom); // This just zooms leaving origin intact... should zoom in at the current center! [DONE] Painter::zoom *= zoomFactor; + zoomIndicator->setText(QString("Zoom: %1%").arg(Painter::zoom * 100.0 * SCREEN_ZOOM)); drawing->update(); } @@ -180,6 +195,7 @@ x 2 = (-426, -301) //printf("Zoom out...\n"); // This just zooms leaving origin intact... should zoom out at the current center! [DONE] Painter::zoom /= zoomFactor; + zoomIndicator->setText(QString("Zoom: %1%").arg(Painter::zoom * 100.0 * SCREEN_ZOOM)); drawing->update(); } @@ -261,8 +277,10 @@ void ApplicationWindow::CreateActions(void) connect(addCircleAct, SIGNAL(triggered()), this, SLOT(AddCircleTool())); addArcAct = CreateAction(tr("Add &Arc"), tr("Add Arc"), tr("Adds arcs to the drawing."), QIcon(":/res/add-arc-tool.png"), QKeySequence("A,A"), true); + connect(addArcAct, SIGNAL(triggered()), this, SLOT(AddArcTool())); addPolygonAct = CreateAction(tr("Add &Polygon"), tr("Add Polygon"), tr("Add polygons to the drawing."), QIcon(":/res/add-polygon-tool.png"), QKeySequence("A,P"), true); + connect(addPolygonAct, SIGNAL(triggered()), this, SLOT(AddPolygonTool())); aboutAct = CreateAction(tr("About &Architektonas"), tr("About Architektonas"), tr("Gives information about this program."), QIcon(":/res/generic-tool.png"), QKeySequence()); connect(aboutAct, SIGNAL(triggered()), this, SLOT(HelpAbout())); @@ -290,6 +308,7 @@ void ApplicationWindow::CreateActions(void) connect(settingsAct, SIGNAL(triggered()), this, SLOT(Settings())); //Hm. I think we'll have to have separate logic to do the "Radio Group Toolbar" thing... +// Yup, in order to turn them off, we'd have to have an "OFF" toolbar button. Ick. /* QActionGroup * group = new QActionGroup(this); group->addAction(deleteAct); group->addAction(addDimensionAct); diff --git a/src/applicationwindow.h b/src/applicationwindow.h index e75c5fe..c220548 100644 --- a/src/applicationwindow.h +++ b/src/applicationwindow.h @@ -9,6 +9,7 @@ //class CharWindow; class AboutWindow; class DrawingView; +class QLabel; class ApplicationWindow: public QMainWindow { @@ -30,6 +31,8 @@ class ApplicationWindow: public QMainWindow void RotateTool(void); void AddLineTool(void); void AddCircleTool(void); + void AddArcTool(void); + void AddPolygonTool(void); void ZoomInTool(void); void ZoomOutTool(void); void HelpAbout(void); @@ -50,6 +53,7 @@ class ApplicationWindow: public QMainWindow DrawingView * drawing; AboutWindow * aboutWin; + QLabel * zoomIndicator; QSettings settings; diff --git a/src/circle.cpp b/src/circle.cpp index 9233f3e..5750b1f 100644 --- a/src/circle.cpp +++ b/src/circle.cpp @@ -35,15 +35,15 @@ Circle::~Circle() else painter->SetPen(QPen(Qt::black, 1.0, Qt::SolidLine)); - // Draw handles (if needed) + // Draw the object... + painter->DrawEllipse(position, radius, radius); + + // & draw handles (if needed) if (state == OSSelected || hitCenter) painter->DrawHandle(position); if (state == OSSelected && draggingEdge && objectWasDragged) painter->DrawHandle(dragPoint); - - // & finally, draw the object! - painter->DrawEllipse(position, radius, radius); } /*virtual*/ Vector Circle::Center(void) diff --git a/src/dimension.cpp b/src/dimension.cpp index b433cac..5aa6a88 100644 --- a/src/dimension.cpp +++ b/src/dimension.cpp @@ -56,17 +56,19 @@ 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(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(p3, p5); @@ -75,28 +77,9 @@ Dimension::~Dimension() painter->SetBrush(QBrush(QColor(Qt::blue))); painter->DrawArrowhead(p1, p2); painter->DrawArrowhead(p2, p1); -#if 0 - // Draw arrowheads, dots, etc :-P - // NOTE: These need some kind of enum in the header so that they can - // be created with some kind of user control... - - Point p7 = position + (unit * 9.0); - Point p8 = endpoint - (unit * 9.0); - Point p9 = p7 + (orthogonal * 7.0); - Point p10 = p7 + (orthogonal * 13.0); - Point p11 = p8 + (orthogonal * 7.0); - Point p12 = p8 + (orthogonal * 13.0); - - painter->DrawLine(p1, p9); - painter->DrawLine(p9, p10); - painter->DrawLine(p10, p1); - painter->DrawLine(p2, p11); - painter->DrawLine(p11, p12); - painter->DrawLine(p12, p2); -#endif // Draw length of dimension line... - painter->SetFont(QFont("Arial", 10 * Painter::zoom)); + 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 !!! diff --git a/src/line.cpp b/src/line.cpp index 2ffb03f..2459636 100644 --- a/src/line.cpp +++ b/src/line.cpp @@ -65,16 +65,21 @@ Line::~Line() 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); +// painter->DrawLine((int)point1.x, (int)point1.y, (int)v2.x, (int)v2.y); + painter->DrawLine(point1, v2); 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); +// painter->DrawLine((int)v2.x, (int)v2.y, (int)point2.x, (int)point2.y); + painter->DrawLine(v2, point2); } } +// Problem: when drawing at large zoom levels, this throws away precision thus +// causing the line to rendered too short. !!! FIX !!! [DONE] else - painter->DrawLine((int)position.x, (int)position.y, (int)endpoint.x, (int)endpoint.y); +// painter->DrawLine((int)position.x, (int)position.y, (int)endpoint.x, (int)endpoint.y); + painter->DrawLine(position, endpoint); } /*virtual*/ Vector Line::Center(void) @@ -436,12 +441,13 @@ bool Line::HitTest(Point point) // simplifies the calculation of the determinant. //How do we determine distance here? Especially if zoomed in or out??? -#warning "!!! Distances tested for may not be valid if zoomed in or out !!!" - if (v1.Magnitude() < 8.0) +//#warning "!!! Distances tested for may not be valid if zoomed in or out !!!" +// [FIXED] + if ((v1.Magnitude() * Painter::zoom) < 8.0) hitPoint1 = true; - else if (v2.Magnitude() < 8.0) + else if ((v2.Magnitude() * Painter::zoom) < 8.0) hitPoint2 = true; - else if (distance < 5.0) + else if ((distance * Painter::zoom) < 5.0) hitLine = true; return StateChanged(); @@ -502,7 +508,7 @@ rearranging we get: t(d1x) - s(d2x) = p2x - p0x t(d1y) - s(d2y) = p2y - p0y -Determinant D is ad - bc where the matrix look like: +Determinant D is ad - bc where the matrix looks like: a b c d diff --git a/src/painter.cpp b/src/painter.cpp index 1bb2e6b..ba5e3f8 100644 --- a/src/painter.cpp +++ b/src/painter.cpp @@ -108,23 +108,24 @@ void Painter::DrawAngledText(Vector center, double angle, QString text) // then rotate the frame to the desired angle. center = CartesianToQtCoords(center); +// NOTE: 1/32 is a kludge to make things look right at screen resolution... // We may need this stuff... If dimension text is large enough. // int textWidth = QFontMetrics(painter->font()).width(text); // int textHeight = QFontMetrics(painter->font()).height(); - QRectF textBox(-100 * zoom, -100 * zoom, 200 * zoom, 200 * zoom); // x, y, w, h; x/y = upper left corner + QRectF textBox(-100 * zoom * SCREEN_ZOOM, -100 * zoom * SCREEN_ZOOM, 200 * zoom * SCREEN_ZOOM, 200 * zoom * SCREEN_ZOOM); // x, y, w, h; x/y = upper left corner // This is in pixels. Might not render correctly at all zoom levels. // Need to figure out if dimensions are always rendered at one size regardless of zoom, // or if they have a definite size, and are thus zoomable. // If zoomable, this is incorrect: // (Added zoom, so this is correct now :-) - int yOffset = -12 * zoom; + int yOffset = -12 * zoom * SCREEN_ZOOM; // Fix text so it isn't upside down... if ((angle > PI * 0.5) && (angle < PI * 1.5)) { angle += PI; - yOffset = 12 * zoom; + yOffset = 12 * zoom * SCREEN_ZOOM; } #if 0 @@ -224,9 +225,10 @@ void Painter::DrawArrowhead(Vector head, Vector tail) Vector orthogonal = Vector(cos(orthoAngle), sin(orthoAngle)); Vector unit = Vector(head - tail).Unit(); - Point p1 = head - (unit * 9.0); - Point p2 = p1 + (orthogonal * 3.0); - Point p3 = p1 - (orthogonal * 3.0); +// NOTE: 1/32 is a kludge to make things look right at scale... + Point p1 = head - (unit * 9.0 * SCREEN_ZOOM); + Point p2 = p1 + (orthogonal * 3.0 * SCREEN_ZOOM); + Point p3 = p1 - (orthogonal * 3.0 * SCREEN_ZOOM); Point p4 = CartesianToQtCoords(head); Point p5 = CartesianToQtCoords(p2); diff --git a/src/painter.h b/src/painter.h index ddd6a27..d82c000 100644 --- a/src/painter.h +++ b/src/painter.h @@ -4,6 +4,8 @@ #include #include "vector.h" +#define SCREEN_ZOOM (1.0 / 8.0) + // Forward declarations class Painter