painter.DrawCrosshair(oldPoint);
toolAction->Draw(&painter);
}
+#else
+ if (Global::tool)
+ {
+ painter.SetPen(QPen(QColor(200, 100, 0, 255), 1.0, Qt::DashLine));
+ painter.DrawCrosshair(oldPoint);
+ ToolDraw(&painter);
+ }
#endif
#if 1
}
+void DrawingView::ToolMouseDown(Point p)
+{
+ if (Global::tool == TTLine)
+ {
+ if (Global::toolState == TSNone)
+ {
+ toolPoint[0] = p;
+// toolState = TSPoint1;
+// toolObject = (Object *)(new Line(p, Vector(0, 0)));
+ }
+ else //if (Global::toolState == TSPoint1)
+ {
+ toolPoint[1] = p;
+ }
+ }
+}
+
+
+void DrawingView::ToolMouseMove(Point p)
+{
+ if (Global::tool == TTLine)
+ {
+ if (Global::toolState == TSNone)
+ toolPoint[0] = p;
+ else
+ toolPoint[1] = p;
+ }
+}
+
+
+void DrawingView::ToolMouseUp(Point p)
+{
+ if (Global::tool == TTLine)
+ {
+ if (Global::toolState == TSNone)
+ {
+ Global::toolState = TSPoint2;
+ // Prevent spurious line from drawing...
+ toolPoint[1] = toolPoint[0];
+ }
+ else
+ {
+ Line * l = new Line(toolPoint[0], toolPoint[1]);
+ document.objects.push_back(l);
+ toolPoint[0] = toolPoint[1];
+ }
+ }
+}
+
+
+void DrawingView::ToolDraw(Painter * painter)
+{
+ if (Global::tool == TTLine)
+ {
+ if (Global::toolState == TSNone)
+ {
+ painter->DrawHandle(toolPoint[0]);
+ }
+ else
+ {
+ painter->DrawLine(toolPoint[0], toolPoint[1]);
+ painter->DrawHandle(toolPoint[1]);
+ }
+ }
+}
+
+
void DrawingView::mousePressEvent(QMouseEvent * event)
{
if (event->button() == Qt::LeftButton)
#else
if (Global::tool)
{
+ if (Global::snapToGrid)
+ point = SnapPointToGrid(point);
+
+ // Snap to object point if valid...
+
+
+ ToolMouseDown(point);
+ //Also, may want to figure out if hovering over a snap point on an object,
+ //snap to grid if not.
return;
}
#endif
#if 1
// Grid processing... (only snap here is left button is down)
- if ((event->buttons() & Qt::LeftButton) && Global::snapToGrid)
+ // Umm, WHY??
+ if (/*(event->buttons() & Qt::LeftButton) &&*/ Global::snapToGrid)
{
point = SnapPointToGrid(point);
}
toolAction->MouseMoved(point);
}
+#else
#endif
+
bool needUpdate = false;
// Don't do this kind of checking unless we're not doing a selection rectangle!
}
//printf("MouseMove: numHovered = %i\n", numHovered);
+ // Tool handling...
+ if (Global::tool)
+ {
+ // Need to do snapping, etc. as well
+ ToolMouseMove(point);
+ }
+
// This is used to draw the tool crosshair...
oldPoint = point;
#if 0
if (toolAction)
toolAction->MouseReleased();
+#else
+ if (Global::tool)
+ {
+ Vector point = Painter::QtToCartesianCoords(Vector(event->x(), event->y()));
+ ToolMouseUp(point);
+ return;
+ }
#endif
if (Global::selectionInProgress)
DrawingView(QWidget * parent = NULL);
public:
-// void SetToolActive(Action * action);
void SetGridSize(uint32_t);
void UpdateGridBackground(void);
Point SnapPointToGrid(Point);
void AddHoveredToSelection(void);
void GetSelection(std::vector<void *> &);
void GetHovered(std::vector<void *> &);
+ void ToolMouseDown(Point);
+ void ToolMouseMove(Point);
+ void ToolMouseUp(Point);
+ void ToolDraw(Painter *);
public slots:
void AddNewObjectToDocument(Object *);
public:
std::vector<void *> select;
std::vector<void *> hover;
-// Action * toolAction;
+// int toolState;
+ Point toolPoint[32];
+// Object * toolObject;
+ // Tool methods (static)
+ public:
+// static void foo();
// public:
// static Container document;
};