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);
+ }
}