From: Shamus Hammons Date: Thu, 21 Jun 2018 02:22:46 +0000 (-0500) Subject: Added miscellaneous features. X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=architektonas;a=commitdiff_plain;h=acd27aa62a4c78b6aeee523e3145a8aa53f4bcde Added miscellaneous features. - Added ability to add Dimensions to drawing - Added ability to scroll viewport by holding down - Fixed drawing load to handle OTText objects correctly - Fixed Pen widget to allow setting attributes on objects correctly --- diff --git a/TODO b/TODO index 608c081..b783d7e 100644 --- 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] diff --git a/src/drawingview.cpp b/src/drawingview.cpp index 30b1591..f50fca5 100644 --- a/src/drawingview.cpp +++ b/src/drawingview.cpp @@ -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); + } } diff --git a/src/drawingview.h b/src/drawingview.h index 29a47a7..08f347f 100644 --- a/src/drawingview.h +++ b/src/drawingview.h @@ -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: diff --git a/src/fileio.cpp b/src/fileio.cpp index 7f1a90a..02ab2f5 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -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) { diff --git a/src/global.cpp b/src/global.cpp index 8dc2f98..e408a5d 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -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; diff --git a/src/global.h b/src/global.h index c0f019a..4f4d46a 100644 --- a/src/global.h +++ b/src/global.h @@ -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; diff --git a/src/objectwidget.cpp b/src/objectwidget.cpp index 554ce34..b4f2cda 100644 --- a/src/objectwidget.cpp +++ b/src/objectwidget.cpp @@ -102,7 +102,7 @@ void ObjectWidget::ShowInfo(Object * obj) break; case OTArc: - s += QString("Center: <%1, %2>
Radius: %3
Start: %4°
End: %5°
").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: <%1, %2>
Radius: %3
Start: %4°
Span: %5°
").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; diff --git a/src/penwidget.cpp b/src/penwidget.cpp index 50d90c6..2a557e3 100644 --- a/src/penwidget.cpp +++ b/src/penwidget.cpp @@ -10,11 +10,15 @@ // --- ---------- ----------------------------------------------------------- // 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); } diff --git a/src/penwidget.h b/src/penwidget.h index 7f096d9..11dcdcf 100644 --- a/src/penwidget.h +++ b/src/penwidget.h @@ -35,6 +35,7 @@ class PenWidget: public QWidget QLineEdit * blue; QComboBox * style; int r, g, b; + bool programChange; }; #endif // __PENWIDGET_H__