]> Shamusworld >> Repos - architektonas/commitdiff
First stabs at sizing dimension lines properly.
authorShamus Hammons <jlhamm@acm.org>
Mon, 6 Feb 2012 20:31:32 +0000 (20:31 +0000)
committerShamus Hammons <jlhamm@acm.org>
Mon, 6 Feb 2012 20:31:32 +0000 (20:31 +0000)
src/applicationwindow.cpp
src/applicationwindow.h
src/circle.cpp
src/dimension.cpp
src/line.cpp
src/painter.cpp
src/painter.h

index 36c256fb588fb789a7d968f39c84da871c34d8f0..66f9edc3b9a2a1845063b770d588c378c5ed8b5f 100644 (file)
@@ -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);
index e75c5fef364a83ef39ae333613308e7e47b932b8..c220548c7d8f98baed78394f2b98ff41ed5cd668 100644 (file)
@@ -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;
 
index 9233f3e1c281dfb46470d12ba31070a808a6db14..5750b1f0ecabb66ac2929f68cb4b6543ea035bbf 100644 (file)
@@ -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)
index b433cac32fa47ad7a6486cca1ac0f3d3c6651392..5aa6a8829a815634a96135411c5c4bda46370580 100644 (file)
@@ -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 !!!
index 2ffb03ff0addf1cda99dfbd343914c24b8b125ad..2459636024e8be411f17f6d8994c037b27ae7d68 100644 (file)
@@ -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
index 1bb2e6bb33845aa3a000d385fb811efedeb366d1..ba5e3f8aa2866ede59b6cc675757721f83cee050 100644 (file)
@@ -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);
index ddd6a27ad7b73f616ff39f91455d0eed9ff59e23..d82c00078fba42e294b877ffb5791f843343ae18 100644 (file)
@@ -4,6 +4,8 @@
 #include <QtGui>
 #include "vector.h"
 
+#define SCREEN_ZOOM  (1.0 / 8.0)
+
 // Forward declarations
 
 class Painter