]> Shamusworld >> Repos - architektonas/commitdiff
Fixed Container loading, informative display.
authorShamus Hammons <jlhamm@acm.org>
Sun, 25 Aug 2013 01:31:23 +0000 (20:31 -0500)
committerShamus Hammons <jlhamm@acm.org>
Sun, 25 Aug 2013 01:31:23 +0000 (20:31 -0500)
Informative text is now in Painter, and automagically adjusts its
bounding rect to the size of the rendered text.

TODO
src/arc.cpp
src/circle.cpp
src/container.cpp
src/container.h
src/drawingview.cpp
src/drawlineaction.cpp
src/line.cpp
src/object.h
src/painter.cpp
src/painter.h

diff --git a/TODO b/TODO
index 92517e09079fd88bb9b018d06bfbede067cb02a7..43ee39b51d1f9836be78f9a8a1f6ae099fab71e5 100644 (file)
--- a/TODO
+++ b/TODO
@@ -8,7 +8,8 @@ Stuff To Be Implemented/Fixed
  - Manipulate Dimension
  - Object connections
  - Group selection (kind done, needs more work though)
- - Take movement code out of Objects and put it into top level Container
+ - Take movement code out of Objects and put it into top level Container (actually
+   I think this should be more of the state code handling. Have to see.)
  - Add OSD routines so they don't have to be implemented in Objects
  - Add OSD to Object creation
  - Add layers
@@ -25,8 +26,6 @@ Stuff To Be Implemented/Fixed
    arc sizing, outer half controls rotation. That way you can grab either handle
    and know what it's supposed to do.
  - Fix loading and saving code
- - Fix snap to grid to allow picking up of handles when they are not on a grid
-   point.
  - Add Drawing Properties dialog (separate from Application Settings)
 
 
@@ -36,5 +35,7 @@ Stuff That's Done
  - Fix snap to grid to honor both states (right now, it's a weird mix of states)
    [Shamus 2013-08-11]
  - Add Arc [Shamus 2013-08-14]
+ - Fix snap to grid to allow picking up of handles when they are not on a grid
+   point. [Shamus 2013-08-18]
 
 
index 030e293a70a20697f9575d893585894a71643e72..9848d38a80e5272dc45ceb52c2963e80a08e4a6f 100644 (file)
@@ -110,6 +110,7 @@ Arc::~Arc()
                        text = text.arg(radius, 0, 'd', 4).arg(radius / oldRadius * 100.0, 0, 'd', 0);
                }
 
+#if 0
                pen = QPen(QColor(0x00, 0xFF, 0x00), 1.0, Qt::SolidLine);
                painter->SetPen(pen);
                painter->SetBrush(QBrush(QColor(0x40, 0xFF, 0x40, 0x9F)));
@@ -121,6 +122,9 @@ Arc::~Arc()
                pen = QPen(QColor(0x00, 0x5F, 0xDF));
                painter->SetPen(pen);
                painter->DrawText(textRect, Qt::AlignVCenter, text);
+#else
+               painter->DrawInformativeText(text);
+#endif
        }
 }
 
index 9111c04ec1e8c36289703979a9848d0797664707..75e9d9352e2749ccea3defaca75452bddb8d5aa9 100644 (file)
@@ -59,7 +59,7 @@ Circle::~Circle()
        {
                QString text = QObject::tr("Radius: %1\nScale: %2%");
                text = text.arg(radius, 0, 'd', 4).arg(radius / oldRadius * 100.0, 0, 'd', 0);
-
+#if 0
                QPen pen = QPen(QColor(0x00, 0xFF, 0x00), 1.0, Qt::SolidLine);
                painter->SetPen(pen);
                painter->SetBrush(QBrush(QColor(0x40, 0xFF, 0x40, 0x9F)));
@@ -71,6 +71,9 @@ Circle::~Circle()
                pen = QPen(QColor(0x00, 0x5F, 0xDF));
                painter->SetPen(pen);
                painter->DrawText(textRect, Qt::AlignVCenter, text);
+#else
+               painter->DrawInformativeText(text);
+#endif
        }
 }
 
index ced7326de4979b91e67d4d16dfe97694101d4837..cd50d587381c4a62002d2211cad3c8436e9ecb87 100644 (file)
@@ -162,6 +162,9 @@ printf("Container::Collided: Deleting object ($%X)\n", *i);
                }
        }
 
+       if (snapToGrid)
+               point = SnapPointToGrid(point);
+
        // We check to see if the container we're trying to access is the
        // DrawingView's document. If so, we ignore the state of the container.
        // Otherwise, we care about the state of the container. :-)
@@ -499,3 +502,21 @@ void Container::ResizeAllDimensions(double newSize)
                fprintf(file, "ENDCONTAINER\n");
 }
 
+
+/*virtual*/ Object * Container::Copy(void)
+{
+#warning "!!! This doesn't take care of attached Dimensions !!!"
+/*
+This is a real problem. While having a pointer in the Dimension to this line's points
+is fast & easy, it creates a huge problem when trying to replicate an object like this.
+
+Maybe a way to fix that then, is to have reference numbers instead of pointers. That
+way, if you copy them, ... you might still have problems. Because you can't be sure if
+a copy will be persistant or not, you then *definitely* do not want them to have the
+same reference number.
+*/
+       Container * c = new Container(position, parent);
+       *c = *this;
+       return c;
+}
+
index fd574daa4fbadd68836961471476f4c575aa58c3..905e7572fab7ca8c31ab5688ecd48544dd2ef985 100644 (file)
@@ -22,6 +22,7 @@ class Container: public Object
                virtual void Add(Object *);
                virtual QRectF Extents(void);
                virtual void Enumerate(FILE *);
+               virtual Object * Copy(void);
                void Delete(Object *);
                void DeleteSelectedItems(void);
                void Clear(void);
index bdc3540b0442fc51b243e6096da6a94b362d2632..838d45aae4f62e59827d082a9c6b34eb8c6eca18 100644 (file)
@@ -393,7 +393,12 @@ Now we do... :-/
                        update();       // Do an update if collided with at least *one* object in the document
 
                if (toolAction)
+               {
+                       if (Object::snapToGrid)
+                               point = Object::SnapPointToGrid(point);
+
                        toolAction->MouseDown(point);
+               }
 
                // Didn't hit any object and not using a tool, so do a selection rectangle
                if (!(collided || toolAction))
index 887e9c4c3795f33d1eeb9af34b26acfba283739e..d4b35db336ae70c35bc8f7c6e69ca199d7e7426f 100644 (file)
@@ -45,6 +45,10 @@ DrawLineAction::~DrawLineAction()
        {
                painter->DrawLine(p1, p2);
                painter->DrawHandle(p2);
+
+               QString text = tr("Length: %1 in.");
+               text = text.arg(Vector::Magnitude(p1, p2));
+               painter->DrawInformativeText(text);
        }
 }
 
index 37b43c8865cb86740da00abda5767ad562a512d7..74c40b5a3b6a027f409bf574ada59b9e475e6b5a 100644 (file)
@@ -93,11 +93,9 @@ Line::~Line()
                double absAngle = (Vector(endpoint - position).Angle()) * RADIANS_TO_DEGREES;
                double absLength = Vector(position - endpoint).Magnitude();
 
-               QString text;
-
-               text = QObject::tr("Length: %1 in.\n") + QChar(0x2221) + QObject::tr(": %2");
+               QString text = QObject::tr("Length: %1 in.\n") + QChar(0x2221) + QObject::tr(": %2");
                text = text.arg(absLength).arg(absAngle);
-
+#if 0
                QPen pen = QPen(QColor(0x00, 0xFF, 0x00), 1.0, Qt::SolidLine);
                painter->SetPen(pen);
                painter->SetBrush(QBrush(QColor(0x40, 0xFF, 0x40, 0x9F)));
@@ -109,6 +107,9 @@ Line::~Line()
                pen = QPen(QColor(0x00, 0x5F, 0xDF));
                painter->SetPen(pen);
                painter->DrawText(textRect, Qt::AlignVCenter, text);
+#else
+               painter->DrawInformativeText(text);
+#endif
        }
 }
 
index 39dbb9e4137633bf0483e7711ecb6df8fc3d8d81..b8fdd9db76f70b0a2cf8fbd5e797951c278183e3 100644 (file)
@@ -74,7 +74,9 @@ class Object
                std::vector<Connection> connected;
 
                // Class variables
+       public:
                static QFont * font;
+       protected:
                static bool fixedAngle;
                static bool fixedLength;
                static int viewportHeight;
index a649306c74ecd96be81cbba047c8cba253be5d99..6145638c8a022080a30aab44122498ff0fcd9eb1 100644 (file)
@@ -15,6 +15,7 @@
 #include "painter.h"
 
 #include "mathconstants.h"
+#include "object.h"
 
 
 // Set class variable defaults
@@ -292,3 +293,22 @@ void Painter::DrawCrosshair(Vector point)
        painter->drawLine(screenPoint.x, 0, screenPoint.x, screenSize.y);
 }
 
+
+void Painter::DrawInformativeText(QString text)
+{
+       painter->setFont(*Object::font);
+       QRectF bounds = painter->boundingRect(QRectF(), Qt::AlignVCenter, text);
+       bounds.moveTo(17.0, 17.0);
+       QRectF textRect = bounds;
+       textRect.adjust(-7.0, -7.0, 7.0, 7.0);
+
+       QPen pen = QPen(QColor(0x00, 0xFF, 0x00), 1.0, Qt::SolidLine);
+       painter->setPen(pen);
+       painter->setBrush(QBrush(QColor(0x40, 0xFF, 0x40, 0x9F)));
+       painter->drawRoundedRect(textRect, 7.0, 7.0);
+
+       pen = QPen(QColor(0x00, 0x5F, 0xDF));
+       painter->setPen(pen);
+       painter->drawText(bounds, Qt::AlignVCenter, text);
+}
+
index bdc46e413bfa88caeb284b96b98d31d14bdf40ed..1bc261b0eab5cbd198467e5d8e38688db3939a09 100644 (file)
@@ -31,6 +31,7 @@ class Painter
                void DrawText(QRectF, int, QString);
                void DrawArrowhead(Vector, Vector, double);
                void DrawCrosshair(Vector);
+               void DrawInformativeText(QString);
 
        public:
                static Vector CartesianToQtCoords(Vector);