- 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
- 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
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]
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),
RotateHandler(mode, p);
else if (Global::tool == TTMirror)
MirrorHandler(mode, p);
+ else if (Global::tool == TTDimension)
+ DimensionHandler(mode, p);
}
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);
+ }
+ }
}
}
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];
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];
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;
}
+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)
// 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
{
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))
{
update();
}
+ if (oldAlt != altDown)
+ {
+ scrollDrag = true;
+ setCursor(Qt::SizeAllCursor);
+// oldPoint = Vector();
+ oldPoint = oldScrollPoint;
+ }
+
if (select.size() > 0)
{
if (event->key() == Qt::Key_Up)
{
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))
{
update();
}
+
+ if (oldAlt != altDown)
+ {
+ scrollDrag = false;
+ setCursor(Qt::ArrowCursor);
+ }
}
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);
uint32_t numHovered;
bool shiftDown;
bool ctrlDown;
+ bool altDown;
private:
QPixmap gridBackground;
bool collided;
bool scrollDrag;
Vector oldPoint;
+ Vector oldScrollPoint;
QString informativeText;
public:
/*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;
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;
{
objectFileType = OTFEndOfFile;
}
+ else
+ printf("Unknown object type '%s'...\n", buffer);
if (obj != NULL)
{
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;
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;
break;
case OTArc:
- s += QString("Center: <%1, %2><br>Radius: %3<br>Start: %4°<br>End: %5°<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: <%1, %2><br>Radius: %3<br>Start: %4°<br>Span: %5°<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;
// --- ---------- -----------------------------------------------------------
// 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");
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;
}
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);
}
return;
r = value;
- emit ColorSelected((r << 16) | (g << 8) | b);
+ Global::penColor = (r << 16) | (g << 8) | b;
+ emit ColorSelected(Global::penColor);
}
return;
g = value;
- emit ColorSelected((r << 16) | (g << 8) | b);
+ Global::penColor = (r << 16) | (g << 8) | b;
+ emit ColorSelected(Global::penColor);
}
return;
b = value;
- emit ColorSelected((r << 16) | (g << 8) | b);
+ Global::penColor = (r << 16) | (g << 8) | b;
+ emit ColorSelected(Global::penColor);
}
QLineEdit * blue;
QComboBox * style;
int r, g, b;
+ bool programChange;
};
#endif // __PENWIDGET_H__