]> Shamusworld >> Repos - architektonas/commitdiff
Add Circle manipulation, fix Line movement bug.
authorShamus Hammons <jlhamm@acm.org>
Sat, 9 May 2015 13:17:25 +0000 (08:17 -0500)
committerShamus Hammons <jlhamm@acm.org>
Sat, 9 May 2015 13:17:25 +0000 (08:17 -0500)
src/action.cpp [deleted file]
src/action.h [deleted file]
src/drawingview.cpp
src/drawingview.h

diff --git a/src/action.cpp b/src/action.cpp
deleted file mode 100644 (file)
index 817e1a0..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-// action.cpp: Action base class
-//
-// Part of the Architektonas Project
-// (C) 2011 Underground Software
-// See the README and GPLv3 files for licensing and warranty information
-//
-// JLH = James Hammons <jlhamm@acm.org>
-//
-// WHO  WHEN        WHAT
-// ---  ----------  ------------------------------------------------------------
-// JLH  10/04/2011  Created this file
-//
-
-#include "action.h"
-
-Action::Action(): QObject()
-{
-}
-
-Action::~Action()
-{
-}
diff --git a/src/action.h b/src/action.h
deleted file mode 100644 (file)
index f456d8f..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-#ifndef __ACTION_H__
-#define __ACTION_H__
-
-#include <QtWidgets>
-#include "vector.h"
-
-class Object;
-class Painter;
-
-class Action: public QObject
-{
-       Q_OBJECT
-
-       public:
-               Action();
-               ~Action();
-
-               // These are all pure virtual functions: Derived classes must define
-               // ALL of them.
-               virtual void Draw(Painter *) = 0;
-               virtual void MouseDown(Vector) = 0;
-               virtual void MouseMoved(Vector) = 0;
-               virtual void MouseReleased(void) = 0;
-               virtual void KeyDown(int) = 0;
-               virtual void KeyReleased(int) = 0;
-
-       signals:
-               void ObjectReady(Object *);
-               void NeedRefresh(void);
-
-       // Class variables
-//     public:
-//             static unsigned int currentLayer;
-};
-
-#endif // __ACTION_H__
-
index 15579c9ab7dd5a8ef6790e408652fdc22b58dd00..f253bd9064ee17367a95b87b8e74991a7bbcf984 100644 (file)
@@ -308,6 +308,9 @@ void DrawingView::paintEvent(QPaintEvent * /*event*/)
        // Do object rendering...
        RenderObjects(&painter, document.objects);
 
+       if (!informativeText.isEmpty())
+               painter.DrawInformativeText(informativeText);
+
        // Do tool rendering, if any...
        if (Global::tool)
        {
@@ -717,7 +720,6 @@ void DrawingView::RotateHandler(int mode, Point p)
 
                                if (obj.type == OTArc)
                                {
-//printf("Obj2->angle[0] = %f, obj.angle[0] = %f, angle = %f\n", obj2->angle[0], obj.angle[0], angle);
                                        obj2->angle[0] = obj.angle[0] + angle;
 
                                        if (obj2->angle[0] > PI_TIMES_2)
@@ -814,6 +816,7 @@ void DrawingView::mousePressEvent(QMouseEvent * event)
                        GetHovered(hover);      // prolly needed
 
                        // Needed for grab & moving objects
+                       // We do it *after*... why? (doesn't seem to confer any advantage...)
                        if (Global::snapToGrid)
                                oldPoint = SnapPointToGrid(point);
 
@@ -871,6 +874,9 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
        // Handle object movement (left button down & over an object)
        if ((event->buttons() & Qt::LeftButton) && numHovered && !Global::tool)
        {
+               if (Global::snapToGrid)
+                       point = SnapPointToGrid(point);
+
                HandleObjectMovement(point);
                update();
                oldPoint = point;
@@ -919,7 +925,8 @@ void DrawingView::mouseReleaseEvent(QMouseEvent * event)
                if (Global::selectionInProgress)
                        Global::selectionInProgress = false;
 
-// Should be we do this automagically? Hmm...
+               informativeText.clear();
+// Should we be doing this automagically? Hmm...
                // Clear our vectors
                select.clear();
                hover.clear();
@@ -967,13 +974,11 @@ void DrawingView::wheelEvent(QWheelEvent * event)
                Global::zoom /= zoomFactor;
        }
 
-#if 1
 //     Global::gridSpacing = gridPixels / Painter::zoom;
 //     UpdateGridBackground();
        SetGridSize(Global::gridSpacing * Global::zoom);
        update();
 //     zoomIndicator->setText(QString("Grid: %1\", BU: Inch").arg(Global::gridSpacing));
-#endif
 }
 
 
@@ -1016,6 +1021,7 @@ void DrawingView::keyReleaseEvent(QKeyEvent * event)
        }
 }
 
+
 //
 // This looks strange, but it's really quite simple: We want a point that's
 // more than half-way to the next grid point to snap there while conversely we
@@ -1221,10 +1227,8 @@ bool DrawingView::HitTestObjects(Point point)
 
 void DrawingView::HandleObjectMovement(Point point)
 {
-       if (Global::snapToGrid)
-               point = SnapPointToGrid(point);
-
        Point delta = point - oldPoint;
+//printf("HOM: old = (%f,%f), new = (%f, %f), delta = (%f, %f)\n", oldPoint.x, oldPoint.y, point.x, point.y, delta.x, delta.y);
        Object * obj = (Object *)hover[0];
 //printf("Object type = %i (size=%i), ", obj->type, hover.size());
 //printf("Object (%X) move: hp1=%s, hp2=%s, hl=%s\n", obj, (obj->hitPoint[0] ? "true" : "false"), (obj->hitPoint[1] ? "true" : "false"), (obj->hitObject ? "true" : "false"));
@@ -1232,9 +1236,6 @@ void DrawingView::HandleObjectMovement(Point point)
        switch (obj->type)
        {
        case OTLine:
-       {
-//             Line * l = (Line *)obj;
-
                if (obj->hitPoint[0])
                        obj->p[0] = point;
                else if (obj->hitPoint[1])
@@ -1246,7 +1247,20 @@ void DrawingView::HandleObjectMovement(Point point)
                }
 
                break;
-       }
+       case OTCircle:
+               if (obj->hitPoint[0])
+                       obj->p[0] = point;
+               else if (obj->hitObject)
+               {
+//this doesn't work. we need to save this on mouse down for this to work correctly!
+//                     double oldRadius = obj->radius[0];
+                       obj->radius[0] = Vector::Magnitude(obj->p[0], point);
+
+                       QString text = QObject::tr("Radius: %1");//\nScale: %2%");
+                       informativeText = text.arg(obj->radius[0], 0, 'd', 4);//.arg(obj->radius[0] / oldRadius * 100.0, 0, 'd', 0);
+               }
+
+               break;
        default:
                break;
        }
index ba35affc022ecbde8c3a54f4c78ae8b4639cf573..162e9686b416d330eeaafe745b7043bb519c316b 100644 (file)
@@ -67,6 +67,7 @@ class DrawingView: public QWidget
                bool collided;
                bool scrollDrag;
                Vector oldPoint;
+               QString informativeText;
 
        public:
                std::vector<void *> select;