+void DrawingView::ToolHandler(int mode, Point p)
+{
+ if (Global::tool == TTLine)
+ LineHandler(mode, p);
+ else if (Global::tool == TTCircle)
+ CircleHandler(mode, p);
+ else if (Global::tool == TTRotate)
+ RotateHandler(mode, p);
+}
+
+
+void DrawingView::ToolDraw(Painter * painter)
+{
+ if (Global::tool == TTLine)
+ {
+ 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 if (Global::tool == TTCircle)
+ {
+ if (Global::toolState == TSNone)
+ {
+ painter->DrawHandle(toolPoint[0]);
+ }
+ else if ((Global::toolState == TSPoint2) && shiftDown)
+ {
+ painter->DrawHandle(toolPoint[1]);
+ }
+ else
+ {
+ double length = Vector::Magnitude(toolPoint[0], toolPoint[1]);
+// painter->DrawLine(toolPoint[0], toolPoint[1]);
+// painter->DrawHandle(toolPoint[1]);
+ painter->SetBrush(QBrush(Qt::NoBrush));
+ painter->DrawEllipse(toolPoint[0], length, length);
+ QString text = tr("Radius: %1 in.");//\n") + QChar(0x2221) + tr(": %2");
+ informativeText = text.arg(length);//.arg(absAngle);
+ }
+ }
+ else if (Global::tool == TTRotate)
+ {
+ if ((Global::toolState == TSNone) || (Global::toolState == TSPoint1))
+ painter->DrawHandle(toolPoint[0]);
+ else if ((Global::toolState == TSPoint2) && shiftDown)
+ painter->DrawHandle(toolPoint[1]);
+ else
+ {
+ if (toolPoint[0] == toolPoint[1])
+ return;
+
+ painter->DrawLine(toolPoint[0], toolPoint[1]);
+ // Likely we need a tool container for this... (now we do!)
+#if 0
+ if (ctrlDown)
+ {
+ painter->SetPen(0x00FF00, 2.0, LSSolid);
+ overrideColor = true;
+ }
+
+ RenderObjects(painter, toolObjects);
+ overrideColor = false;
+#endif
+
+ double absAngle = (Vector(toolPoint[1] - toolPoint[0]).Angle()) * RADIANS_TO_DEGREES;
+
+ QString text = QChar(0x2221) + QObject::tr(": %1");
+ informativeText = text.arg(absAngle);
+
+ if (ctrlDown)
+ informativeText += " (Copy)";
+
+// painter->DrawInformativeText(text);
+ }
+ }
+}
+
+
+void DrawingView::LineHandler(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
+ {
+ Line * l = new Line(toolPoint[0], toolPoint[1]);
+ document.objects.push_back(l);
+ toolPoint[0] = toolPoint[1];
+ }
+ }
+}
+
+
+void DrawingView::CircleHandler(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
+ {
+ double length = Vector::Magnitude(toolPoint[0], toolPoint[1]);
+ Circle * c = new Circle(toolPoint[0], length);
+ document.objects.push_back(c);
+ toolPoint[0] = toolPoint[1];
+ Global::toolState = TSNone;
+ }
+ }
+}
+
+
+void DrawingView::RotateHandler(int mode, Point p)
+{
+ switch (mode)
+ {
+ case ToolMouseDown:
+ if (Global::toolState == TSNone)
+ {
+ toolPoint[0] = p;
+ SavePointsFrom(select, toolScratch);
+ Global::toolState = TSPoint1;
+ }
+ else if (Global::toolState == TSPoint1)
+ toolPoint[0] = p;
+ else
+ toolPoint[1] = p;
+
+ break;
+ case ToolMouseMove:
+ if ((Global::toolState == TSPoint1) || (Global::toolState == TSNone))
+ toolPoint[0] = p;
+ else if (Global::toolState == TSPoint2)
+ {
+ toolPoint[1] = p;
+
+ if (shiftDown)
+ return;
+
+ double angle = Vector(toolPoint[0], toolPoint[1]).Angle();
+ std::vector<void *>::iterator j = select.begin();
+ std::vector<Object>::iterator i = toolScratch.begin();
+
+ for(; i!=toolScratch.end(); i++, j++)
+ {
+ Object obj = *i;
+ Point p1 = Geometry::RotatePointAroundPoint(obj.p[0], toolPoint[0], angle);
+ Point p2 = Geometry::RotatePointAroundPoint(obj.p[1], toolPoint[0], angle);
+ Object * obj2 = (Object *)(*j);
+ obj2->p[0] = p1;
+ obj2->p[1] = p2;
+
+ if (obj.type == OTArc)
+ {
+ obj2->angle[0] = obj.angle[0] + angle;
+
+ if (obj2->angle[0] > PI_TIMES_2)
+ obj2->angle[0] -= PI_TIMES_2;
+ }
+ }
+ }
+
+ break;
+ case ToolMouseUp:
+ if (Global::toolState == TSPoint1)
+ {
+ 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
+ {
+ // Either we're finished with our rotate, or we're stamping a copy.
+ if (ctrlDown)
+ {
+ // Stamp a copy of the selection at the current rotation & bail
+ std::vector<void *> temp;
+ CopyObjects(select, temp);
+ ClearSelected(temp);
+ AddObjectsTo(document.objects, temp);
+ RestorePointsTo(select, toolScratch);
+ return;
+ }
+
+ toolPoint[0] = p;
+ Global::toolState = TSPoint1;
+ SavePointsFrom(select, toolScratch);
+ }
+
+ break;
+ case ToolKeyDown:
+ // Reset the selection if shift held down...
+ if (shiftDown)
+ RestorePointsTo(select, toolScratch);
+
+ break;
+ case ToolKeyUp:
+ // Reset selection when key is let up
+ if (!shiftDown)
+ RotateHandler(ToolMouseMove, toolPoint[1]);
+
+ break;
+ case ToolCleanup:
+ RestorePointsTo(select, toolScratch);
+ }
+}
+
+