]> Shamusworld >> Repos - architektonas/commitdiff
Added miscellaneous features.
authorShamus Hammons <jlhamm@acm.org>
Thu, 21 Jun 2018 02:22:46 +0000 (21:22 -0500)
committerShamus Hammons <jlhamm@acm.org>
Thu, 21 Jun 2018 02:22:46 +0000 (21:22 -0500)
- Added ability to add Dimensions to drawing
- Added ability to scroll viewport by holding down <ALT>
- Fixed drawing load to handle OTText objects correctly
- Fixed Pen widget to allow setting attributes on objects correctly

TODO
src/drawingview.cpp
src/drawingview.h
src/fileio.cpp
src/global.cpp
src/global.h
src/objectwidget.cpp
src/penwidget.cpp
src/penwidget.h

diff --git a/TODO b/TODO
index 608c08117c7d3f71ddae4d594858b1cc2668a20c..b783d7e6538673a0a964a398b929618106cc2de6 100644 (file)
--- a/TODO
+++ b/TODO
@@ -14,7 +14,6 @@ Stuff To Be Implemented/Fixed
  - Add layers
  - Add blocks
  - Add page layout
- - Add pen color/style/width to Objects
  - Add fill/hatch to Objects
  - Fix zooming to be more intuitive
  - Add other Dimension types, like radial, diametric, leader
@@ -22,7 +21,6 @@ Stuff To Be Implemented/Fixed
  - Fix Arc manipulator. Idea: split edge handles so that the inner half controls
    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
  - Add Drawing Properties dialog (separate from Application Settings)
  - Trim tool
  - Trim/Slice tool (to be able to click on a line segment crossing another, and
@@ -33,6 +31,8 @@ Stuff To Be Implemented/Fixed
 Stuff That's Done
 -----------------
 
+ - Add pen color/style/width to Objects [Shamus 2017ish]
+ - Fix loading and saving code [Shamus 2016ish]
  - Manipulate Dimension [Shamus 2014-03-20]
  - Fix snap to grid to honor both states (right now, it's a weird mix of states)
    [Shamus 2013-08-11]
index 30b159172248d04c0e87e75d6396f1f629bca807..f50fca562d11ce438a51c61d70ef16e689ba92e1 100644 (file)
@@ -45,7 +45,7 @@
 DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent),
        // The value in the settings file will override this.
        useAntialiasing(true), /*numSelected(0),*/ numHovered(0), shiftDown(false),
-       ctrlDown(false),
+       ctrlDown(false), altDown(false),
        gridBackground(BACKGROUND_MAX_SIZE, BACKGROUND_MAX_SIZE),
        scale(1.0), offsetX(-10), offsetY(-10), document(true),
        gridPixels(0), collided(false), hoveringIntersection(false),
@@ -747,6 +747,8 @@ void DrawingView::ToolHandler(int mode, Point p)
                RotateHandler(mode, p);
        else if (Global::tool == TTMirror)
                MirrorHandler(mode, p);
+       else if (Global::tool == TTDimension)
+               DimensionHandler(mode, p);
 }
 
 
@@ -885,6 +887,28 @@ void DrawingView::ToolDraw(Painter * painter)
                                informativeText += " (Copy)";
                }
        }
+       if (Global::tool == TTDimension)
+       {
+               if (Global::toolState == TSNone)
+               {
+                       painter->DrawHandle(toolPoint[0]);
+               }
+               else if ((Global::toolState == TSPoint2) && shiftDown)
+               {
+                       painter->DrawHandle(toolPoint[1]);
+               }
+               else
+               {
+                       painter->DrawLine(toolPoint[0], toolPoint[1]);
+                       painter->DrawHandle(toolPoint[1]);
+
+                       Vector v(toolPoint[0], toolPoint[1]);
+                       double absAngle = v.Angle() * RADIANS_TO_DEGREES;
+                       double absLength = v.Magnitude();
+                       QString text = tr("Length: %1 in.\n") + QChar(0x2221) + tr(": %2");
+                       informativeText = text.arg(absLength).arg(absAngle);
+               }
+       }
 }
 
 
@@ -921,7 +945,7 @@ void DrawingView::LineHandler(int mode, Point p)
                }
                else
                {
-                       Line * l = new Line(toolPoint[0], toolPoint[1]);
+                       Line * l = new Line(toolPoint[0], toolPoint[1], Global::penWidth, Global::penColor, Global::penStyle);
                        l->layer = Global::activeLayer;
                        document.objects.push_back(l);
                        toolPoint[0] = toolPoint[1];
@@ -964,7 +988,7 @@ void DrawingView::CircleHandler(int mode, Point p)
                else
                {
                        double length = Vector::Magnitude(toolPoint[0], toolPoint[1]);
-                       Circle * c = new Circle(toolPoint[0], length);
+                       Circle * c = new Circle(toolPoint[0], length, Global::penWidth, Global::penColor, Global::penStyle);
                        c->layer = Global::activeLayer;
                        document.objects.push_back(c);
                        toolPoint[0] = toolPoint[1];
@@ -1041,7 +1065,7 @@ void DrawingView::ArcHandler(int mode, Point p)
                        if (span < 0)
                                span += TAU;
 
-                       Arc * arc = new Arc(toolPoint[0], toolPoint[1].x, toolPoint[2].x, span);
+                       Arc * arc = new Arc(toolPoint[0], toolPoint[1].x, toolPoint[2].x, span, Global::penWidth, Global::penColor, Global::penStyle);
                        arc->layer = Global::activeLayer;
                        document.objects.push_back(arc);
                        Global::toolState = TSNone;
@@ -1257,6 +1281,48 @@ void DrawingView::MirrorHandler(int mode, Point p)
 }
 
 
+void DrawingView::DimensionHandler(int mode, Point p)
+{
+       switch (mode)
+       {
+       case ToolMouseDown:
+               if (Global::toolState == TSNone)
+                       toolPoint[0] = p;
+               else
+                       toolPoint[1] = p;
+
+               break;
+       case ToolMouseMove:
+               if (Global::toolState == TSNone)
+                       toolPoint[0] = p;
+               else
+                       toolPoint[1] = p;
+
+               break;
+       case ToolMouseUp:
+               if (Global::toolState == TSNone)
+               {
+                       Global::toolState = TSPoint2;
+                       // Prevent spurious line from drawing...
+                       toolPoint[1] = toolPoint[0];
+               }
+               else if ((Global::toolState == TSPoint2) && shiftDown)
+               {
+                       // Key override is telling us to make a new line, not continue the
+                       // previous one.
+                       toolPoint[0] = toolPoint[1];
+               }
+               else
+               {
+                       Dimension * d = new Dimension(toolPoint[0], toolPoint[1], DTLinear);
+                       d->layer = Global::activeLayer;
+                       document.objects.push_back(d);
+                       Global::toolState = TSNone;
+               }
+       }
+}
+
+
 void DrawingView::mousePressEvent(QMouseEvent * event)
 {
        if (event->button() == Qt::LeftButton)
@@ -1339,9 +1405,10 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
        // Only needs to be done here, as mouse down is always preceded by movement
        Global::snapPointIsValid = false;
        hoveringIntersection = false;
+       oldScrollPoint = Vector(event->x(), event->y());
 
        // Scrolling...
-       if (event->buttons() & Qt::MiddleButton)
+       if ((event->buttons() & Qt::MiddleButton) || scrollDrag)
        {
                point = Vector(event->x(), event->y());
                // Since we're using Qt coords for scrolling, we have to adjust them
@@ -1536,11 +1603,14 @@ void DrawingView::keyPressEvent(QKeyEvent * event)
 {
        bool oldShift = shiftDown;
        bool oldCtrl = ctrlDown;
+       bool oldAlt = altDown;
 
        if (event->key() == Qt::Key_Shift)
                shiftDown = true;
        else if (event->key() == Qt::Key_Control)
                ctrlDown = true;
+       else if (event->key() == Qt::Key_Alt)
+               altDown = true;
 
        if ((oldShift != shiftDown) || (oldCtrl != ctrlDown))
        {
@@ -1550,6 +1620,14 @@ void DrawingView::keyPressEvent(QKeyEvent * event)
                update();
        }
 
+       if (oldAlt != altDown)
+       {
+               scrollDrag = true;
+               setCursor(Qt::SizeAllCursor);
+//             oldPoint = Vector();
+               oldPoint = oldScrollPoint;
+       }
+
        if (select.size() > 0)
        {
                if (event->key() == Qt::Key_Up)
@@ -1580,11 +1658,14 @@ void DrawingView::keyReleaseEvent(QKeyEvent * event)
 {
        bool oldShift = shiftDown;
        bool oldCtrl = ctrlDown;
+       bool oldAlt = altDown;
 
        if (event->key() == Qt::Key_Shift)
                shiftDown = false;
        else if (event->key() == Qt::Key_Control)
                ctrlDown = false;
+       else if (event->key() == Qt::Key_Alt)
+               altDown = false;
 
        if ((oldShift != shiftDown) || (oldCtrl != ctrlDown))
        {
@@ -1593,6 +1674,12 @@ void DrawingView::keyReleaseEvent(QKeyEvent * event)
 
                update();
        }
+
+       if (oldAlt != altDown)
+       {
+               scrollDrag = false;
+               setCursor(Qt::ArrowCursor);
+       }
 }
 
 
index 29a47a7083e7c2f801d5deda81e6c1f3d543fd03..08f347f6cac05e26193f9df07e9114f30a86296c 100644 (file)
@@ -33,6 +33,7 @@ class DrawingView: public QWidget
                void ArcHandler(int, Point);
                void RotateHandler(int, Point);
                void MirrorHandler(int, Point);
+               void DimensionHandler(int, Point);
                Rect GetObjectExtents(Object *);
                void CheckObjectBounds(void);
                bool HitTestObjects(Point);
@@ -72,6 +73,7 @@ class DrawingView: public QWidget
                uint32_t numHovered;
                bool shiftDown;
                bool ctrlDown;
+               bool altDown;
 
        private:
                QPixmap gridBackground;
@@ -84,6 +86,7 @@ class DrawingView: public QWidget
                bool collided;
                bool scrollDrag;
                Vector oldPoint;
+               Vector oldScrollPoint;
                QString informativeText;
 
        public:
index 7f1a90a8d08b7e7c634545c0fb78b34dbc1b94c8..02ab2f577dc60af0a95f392a60e069b32b57b631 100644 (file)
@@ -245,6 +245,7 @@ enum ObjectTypeFile { OTFContainer, OTFContainerEnd, OTFObject, OTFEndOfFile };
 /*static*/ Object * FileIO::GetObjectFromFile(FILE * file, bool extended/*= false*/)
 {
        char buffer[256];
+       char textBuffer[65536];
        int foundLayer = 0;
        /*int num =*/ fscanf(file, "%s", buffer);
        Object * obj = NULL;
@@ -299,6 +300,12 @@ if (errno)
                fscanf(file, "(%lf,%lf) %lf, %lf, %lf", &p.x, &p.y, &r, &a1, &a2);
                obj = (Object *)new Arc(p, r, a1, a2);
        }
+       else if (strcmp(buffer, "TEXT") == 0)
+       {
+               Point p;
+               fscanf(file, "(%lf,%lf) \"%[^\"]\"", &p.x, &p.y, textBuffer);
+               obj = (Object *)new Text(p, textBuffer);
+       }
        else if (strcmp(buffer, "DIMENSION") == 0)
        {
                Point p1, p2;
@@ -319,6 +326,8 @@ if (errno)
        {
                objectFileType = OTFEndOfFile;
        }
+       else
+               printf("Unknown object type '%s'...\n", buffer);
 
        if (obj != NULL)
        {
index 8dc2f98d76693b99c3470746288355119590e3de..e408a5deb2eb7ac53e9a469c3ee39fc0ee095535 100644 (file)
@@ -38,6 +38,11 @@ Vector Global::screenSize(200.0, 200.0);
 
 float Global::scale = 0.5;
 
+float Global::penWidth = 1.0;
+int Global::penStyle = 1;
+uint32_t Global::penColor = 0x000000;
+bool Global::penStamp = false;
+
 Point Global::intersectPoint[16]; // Overkill, yes
 double Global::intersectParam[16]; // Ditto
 int Global::numIntersectPoints = 0;
index c0f019aa839ab9cba999ad0b72e3911785af9a80..4f4d46a118cded8012d3506283fc217ea7987848 100644 (file)
@@ -44,6 +44,11 @@ class Global
 
                static float scale;
 
+               static float penWidth;
+               static int penStyle;
+               static uint32_t penColor;
+               static bool penStamp;
+
                static Point intersectPoint[16]; // Overkill, yes
                static double intersectParam[16]; // Ditto
                static int numIntersectPoints;
index 554ce34bcf291f8b45d423fb303374f3cd27f309..b4f2cda442077b293bc04d9e5c1b965b2b83198e 100644 (file)
@@ -102,7 +102,7 @@ void ObjectWidget::ShowInfo(Object * obj)
                break;
 
        case OTArc:
-               s += QString("Center: &lt;%1, %2&gt;<br>Radius: %3<br>Start: %4&#x00B0;<br>End: %5&#x00B0;<br>").arg(obj->p[0].x).arg(obj->p[0].y).arg(obj->radius[0]).arg(obj->angle[0] * RADIANS_TO_DEGREES).arg(obj->angle[1] * RADIANS_TO_DEGREES);
+               s += QString("Center: &lt;%1, %2&gt;<br>Radius: %3<br>Start: %4&#x00B0;<br>Span: %5&#x00B0;<br>").arg(obj->p[0].x).arg(obj->p[0].y).arg(obj->radius[0]).arg(obj->angle[0] * RADIANS_TO_DEGREES).arg(obj->angle[1] * RADIANS_TO_DEGREES);
                break;
                break;
 
index 50d90c6d52484ffecc7f7b532bce0834dfb69246..2a557e39d150f54ab48e080eace9d234d0425aee 100644 (file)
 // ---  ----------  -----------------------------------------------------------
 // JLH  05/07/2017  Created this file
 //
+//maybe add a button to have it stamp attributes on all objects clicked on? [added Global::penStamp to facilitate this.]
+//need to add to drawingview the ability to use attributes on new objects [DONE]
+//need to override the selection so you can see the attributes effects immediately when they are changed instead of having to deselect them to see
+
 
 #include "penwidget.h"
 
 
-PenWidget::PenWidget(void): QWidget(), r(0), g(0), b(0)
+PenWidget::PenWidget(void): QWidget(), r(0), g(0), b(0), programChange(false)
 {
        width = new QLineEdit("1.0");
        red = new QLineEdit("00");
@@ -82,15 +86,21 @@ void PenWidget::SetFields(Object * obj)
        if (obj == NULL)
                return;
 
-       int r = (obj->color >> 16) & 0xFF;
-       int g = (obj->color >> 8) & 0xFF;
-       int b = (obj->color >> 0) & 0xFF;
+       // We don't handle groups properly--yet--so punt:
+       if (obj->type == OTContainer)
+               return;
+
+       r = (obj->color >> 16) & 0xFF;
+       g = (obj->color >> 8) & 0xFF;
+       b = (obj->color >> 0) & 0xFF;
        width->setText(QString("%1").arg(obj->thickness));
        red->setText(QString("%1").arg(r, 2, 16, QChar('0')));
        green->setText(QString("%1").arg(g, 2, 16, QChar('0')));
        blue->setText(QString("%1").arg(b, 2, 16, QChar('0')));
        // Styles are 1-indexed while the combobox is 0-indexed
+       programChange = true;
        style->setCurrentIndex(obj->style - 1);
+       programChange = false;
 }
 
 
@@ -103,15 +113,21 @@ void PenWidget::HandleWidthSelected(QString text)
        if (!ok)
                return;
 
-       emit WidthSelected(value);
+       Global::penWidth = value;
+       emit WidthSelected(Global::penWidth);
 }
 
 
 void PenWidget::HandleStyleSelected(int selected)
 {
+       // Change was programmatic, don't do anything
+       if (programChange)
+               return;
+
        // Styles are 1-based, but the combobox is 0-based, so we compensate for
        // that here
-       emit StyleSelected(selected + 1);
+       Global::penStyle = selected + 1;
+       emit StyleSelected(Global::penStyle);
 }
 
 
@@ -125,7 +141,8 @@ void PenWidget::HandleRedSelected(QString text)
                return;
 
        r = value;
-       emit ColorSelected((r << 16) | (g << 8) | b);
+       Global::penColor = (r << 16) | (g << 8) | b;
+       emit ColorSelected(Global::penColor);
 }
 
 
@@ -139,7 +156,8 @@ void PenWidget::HandleGreenSelected(QString text)
                return;
 
        g = value;
-       emit ColorSelected((r << 16) | (g << 8) | b);
+       Global::penColor = (r << 16) | (g << 8) | b;
+       emit ColorSelected(Global::penColor);
 }
 
 
@@ -153,6 +171,7 @@ void PenWidget::HandleBlueSelected(QString text)
                return;
 
        b = value;
-       emit ColorSelected((r << 16) | (g << 8) | b);
+       Global::penColor = (r << 16) | (g << 8) | b;
+       emit ColorSelected(Global::penColor);
 }
 
index 7f096d94ab750a0a753675ab49ceaedf27f7b9c9..11dcdcf44b67097a3f5436c8ba1e14ab5f08cdb2 100644 (file)
@@ -35,6 +35,7 @@ class PenWidget: public QWidget
                QLineEdit * blue;
                QComboBox * style;
                int r, g, b;
+               bool programChange;
 };
 
 #endif // __PENWIDGET_H__