- bool needUpdate = false;
-
- // Don't do this kind of checking unless we're not doing a selection rectangle!
- // Hmm, lines don't stay selected if globally selected... !!! FIX !!! [DONE]
- // it's because there were extra state variables, the hit* vars...
- if (!Global::selectionInProgress)
- {
- std::vector<void *>::iterator i;
- numHovered = 0;
-
- for(i=document.objects.begin(); i!=document.objects.end(); i++)
- {
- Object * obj = (Object *)(*i);
-// obj->selected = false;
-
- switch (obj->type)
- {
- case OTLine:
- {
- Line * l = (Line *)obj;
-
-// bool hitPoint1, hitPoint2, hitLine;
- l->hitPoint[0] = l->hitPoint[1] = l->hitObject = false;
- Vector lineSegment = l->p2 - l->p1;
- Vector v1 = point - l->p1;
- Vector v2 = point - l->p2;
- double t = Geometry::ParameterOfLineAndPoint(l->p1, l->p2, point);
- double distance;
-
- if (t < 0.0)
- distance = v1.Magnitude();
- else if (t > 1.0)
- distance = v2.Magnitude();
- else
- // distance = ?Det?(ls, v1) / |ls|
- distance = fabs((lineSegment.x * v1.y - v1.x * lineSegment.y)
- / lineSegment.Magnitude());
-
- if ((v1.Magnitude() * Global::zoom) < 8.0)
- {
- l->hitPoint[0] = true;
-// snapPoint = l->p1;
-// snapPointIsValid = true;
- }
- else if ((v2.Magnitude() * Global::zoom) < 8.0)
- {
- l->hitPoint[1] = true;
-// snapPoint = l->p2;
-// snapPointIsValid = true;
- }
- else if ((distance * Global::zoom) < 5.0)
- l->hitObject = true;
-
- bool oldHovered = l->hovered;
- l->hovered = (l->hitPoint[0] || l->hitPoint[1] || l->hitObject ? true : false);
-
- if (oldHovered != l->hovered)
- needUpdate = true;
-
- break;
- }
- case OTCircle:
- {
- Circle * c = (Circle *)obj;
-
-
- break;
- }
- default:
- break;
- }
-
- if (obj->hovered)
- {
- numHovered++;
-//printf("MouseMove: OBJECT HOVERED (numHovered = %i)\n", numHovered);
- }
- }
- }
-//printf("MouseMove: numHovered = %i\n", numHovered);
-
- // This is used to draw the tool crosshair...
- oldPoint = point;
-
-// if (/*document.NeedsUpdate() ||*/ Global::selectionInProgress /*|| toolAction*/)
- if (needUpdate || Global::selectionInProgress || Global::tool)
- update();
-}
-
-
-void DrawingView::mouseReleaseEvent(QMouseEvent * event)
-{
- if (event->button() == Qt::LeftButton)
- {
-#if 0
- document.PointerReleased();
-#endif
-
-//We need to update especially if nothing collided and the state needs to change. !!! FIX !!!
-//could set it up to use the document's update function (assumes that all object updates
-//are being reported correctly:
-// if (document.NeedsUpdate())
-// if (collided)
- update(); // Do an update if collided with at least *one* object in the document
-
-#if 0
- if (toolAction)
- toolAction->MouseReleased();
-#endif
-
- if (Global::selectionInProgress)
- {
- // Select all the stuff inside of selection
- Global::selectionInProgress = false;
-
- // Clear our vectors
- select.empty();
- hover.empty();
-
- // Scoop 'em up
- std::vector<void *>::iterator i;
-
- for(i=document.objects.begin(); i!=document.objects.end(); i++)
- {
- if (((Object *)(*i))->selected)
- select.push_back(*i);
-
-//hmm, this is no good, too late to do any good :-P
-// if ((*i)->hovered)
-// hover.push_back(*i);
- }
- }
- }
- else if (event->button() == Qt::MiddleButton)
- {
- scrollDrag = false;
- setCursor(Qt::ArrowCursor);
- }
-}
-
-
-void DrawingView::wheelEvent(QWheelEvent * event)
-{
- double zoomFactor = 1.25;
- QSize sizeWin = size();
- Vector center(sizeWin.width() / 2.0, sizeWin.height() / 2.0);
- center = Painter::QtToCartesianCoords(center);
-
- // This is not centering for some reason. Need to figure out why. :-/
- if (event->delta() > 0)
- {
- Vector newOrigin = center - ((center - Global::origin) / zoomFactor);
- Global::origin = newOrigin;
- Global::zoom *= zoomFactor;
- }
- else
- {
- Vector newOrigin = center + ((-center + Global::origin) * zoomFactor);
- Global::origin = newOrigin;
- Global::zoom /= zoomFactor;
- }
-
-#if 1
-// Global::gridSpacing = gridPixels / Painter::zoom;
-// UpdateGridBackground();
- SetGridSize(Global::gridSpacing * Global::zoom);
- update();
-// zoomIndicator->setText(QString("Grid: %1\", BU: Inch").arg(Global::gridSpacing));
-#endif
-}
-
-
-void DrawingView::keyPressEvent(QKeyEvent * event)
-{
-#if 0
- if (toolAction)
- toolAction->KeyDown(event->key());
-#endif
- if (event->key() == Qt::Key_Shift)
- shiftDown = true;
- else if (event->key() == Qt::Key_Control)
- ctrlDown = true;
-}
-
-
-void DrawingView::keyReleaseEvent(QKeyEvent * event)
-{
-#if 0
- if (toolAction)
- toolAction->KeyReleased(event->key());
-#endif
- if (event->key() == Qt::Key_Shift)
- shiftDown = false;
- else if (event->key() == Qt::Key_Control)
- ctrlDown = false;
-}
-
-//
-// This looks strange, but it's really quite simple: We want a point that's
-// more than half-way to the next grid point to snap there while conversely we
-// want a point that's less than half-way to to the next grid point then snap
-// to the one before it. So we add half of the grid spacing to the point, then
-// divide by it so that we can remove the fractional part, then multiply it
-// back to get back to the correct answer.
-//
-Point DrawingView::SnapPointToGrid(Point point)
-{
- point += Global::gridSpacing / 2.0; // *This* adds to Z!!!
- point /= Global::gridSpacing;
- point.x = floor(point.x);//need to fix this for negative numbers...
- point.y = floor(point.y);
- point.z = 0; // Make *sure* Z doesn't go anywhere!!!
- point *= Global::gridSpacing;
- return point;
-}