From: Shamus Hammons Date: Sun, 25 Aug 2013 01:31:23 +0000 (-0500) Subject: Fixed Container loading, informative display. X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=architektonas;a=commitdiff_plain;h=143b369c0308a8cd524cb0ed51c5d67d6be69603 Fixed Container loading, informative display. Informative text is now in Painter, and automagically adjusts its bounding rect to the size of the rendered text. --- diff --git a/TODO b/TODO index 92517e0..43ee39b 100644 --- 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] diff --git a/src/arc.cpp b/src/arc.cpp index 030e293..9848d38 100644 --- a/src/arc.cpp +++ b/src/arc.cpp @@ -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 } } diff --git a/src/circle.cpp b/src/circle.cpp index 9111c04..75e9d93 100644 --- a/src/circle.cpp +++ b/src/circle.cpp @@ -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 } } diff --git a/src/container.cpp b/src/container.cpp index ced7326..cd50d58 100644 --- a/src/container.cpp +++ b/src/container.cpp @@ -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; +} + diff --git a/src/container.h b/src/container.h index fd574da..905e757 100644 --- a/src/container.h +++ b/src/container.h @@ -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); diff --git a/src/drawingview.cpp b/src/drawingview.cpp index bdc3540..838d45a 100644 --- a/src/drawingview.cpp +++ b/src/drawingview.cpp @@ -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)) diff --git a/src/drawlineaction.cpp b/src/drawlineaction.cpp index 887e9c4..d4b35db 100644 --- a/src/drawlineaction.cpp +++ b/src/drawlineaction.cpp @@ -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); } } diff --git a/src/line.cpp b/src/line.cpp index 37b43c8..74c40b5 100644 --- a/src/line.cpp +++ b/src/line.cpp @@ -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 } } diff --git a/src/object.h b/src/object.h index 39dbb9e..b8fdd9d 100644 --- a/src/object.h +++ b/src/object.h @@ -74,7 +74,9 @@ class Object std::vector connected; // Class variables + public: static QFont * font; + protected: static bool fixedAngle; static bool fixedLength; static int viewportHeight; diff --git a/src/painter.cpp b/src/painter.cpp index a649306..6145638 100644 --- a/src/painter.cpp +++ b/src/painter.cpp @@ -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); +} + diff --git a/src/painter.h b/src/painter.h index bdc46e4..1bc261b 100644 --- a/src/painter.h +++ b/src/painter.h @@ -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);