X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdrawingview.cpp;h=aeb764cc5781ff38364f7a99eb154c4898c360bd;hb=06456047e6476969e45be5b1f31b8336ea74c45f;hp=f3cac0db04a00f44aa71934bfac4e6b21f122165;hpb=deb5512a6b35e73dc2c19ac4d2800cff87dd2e71;p=architektonas diff --git a/src/drawingview.cpp b/src/drawingview.cpp index f3cac0d..aeb764c 100644 --- a/src/drawingview.cpp +++ b/src/drawingview.cpp @@ -40,8 +40,6 @@ #define BACKGROUND_MAX_SIZE 512 -enum { ToolMouseDown, ToolMouseMove, ToolMouseUp }; - // Class variable //Container DrawingView::document(Vector(0, 0)); @@ -49,7 +47,7 @@ enum { ToolMouseDown, ToolMouseMove, ToolMouseUp }; 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), overrideColor(false), + ctrlDown(false), gridBackground(BACKGROUND_MAX_SIZE, BACKGROUND_MAX_SIZE), scale(1.0), offsetX(-10), offsetY(-10),// document(Vector(0, 0)), gridPixels(0), collided(false)//, toolAction(NULL) @@ -267,24 +265,6 @@ zero; so we do another modulus operation on the result to achieve this. } -void DrawingView::AddNewObjectToDocument(Object * object) -{ - if (object) - { -// object->Reparent(&document); -// document.Add(object); - update(); - } -//printf("DrawingView::AddNewObjectToDocument(). object=%08X\n", object); -} - - -void DrawingView::HandleActionUpdate(void) -{ - update(); -} - - void DrawingView::SetCurrentLayer(int layer) { Global::currentLayer = layer; @@ -358,7 +338,11 @@ void DrawingView::RenderObjects(Painter * painter, std::vector & v) Object * obj = (Object *)(*i); float scaledThickness = Global::scale * obj->thickness; - if (!overrideColor) + if ((Global::tool == TTRotate) && ctrlDown && obj->selected) + { + painter->SetPen(0x00FF00, 2.0, LSSolid); + } + else { painter->SetPen(obj->color, Global::zoom * scaledThickness, obj->style); painter->SetBrush(obj->color); @@ -475,8 +459,8 @@ void DrawingView::RenderObjects(Painter * painter, std::vector & v) double t = Geometry::ParameterOfLineAndPoint(linePt1, linePt2, linePt2 - (unit * 9.0 * scaledThickness)); //printf("Dimension::Draw(): t = %lf\n", t); - // On the screen, it's acting like this is actually 58%... - // This is correct, we want it to happen at > 50% + // On the screen, it's acting like this is actually 58%... + // This is correct, we want it to happen at > 50% if (t > 0.58) { // Draw main dimension line + arrowheads @@ -535,34 +519,6 @@ void DrawingView::RenderObjects(Painter * painter, std::vector & v) } -void DrawingView::DeleteSelectedItems(void) -{ - std::vector::iterator i = document.objects.begin(); - - while (i != document.objects.end()) - { - Object * obj = (Object *)(*i); - - if (obj->selected) - { - delete obj; - document.objects.erase(i); - } - else - i++; - } -} - - -void DrawingView::ClearSelection(void) -{ - std::vector::iterator i; - - for(i=document.objects.begin(); i!=document.objects.end(); i++) - ((Object *)(*i))->selected = false; -} - - void DrawingView::AddHoveredToSelection(void) { std::vector::iterator i; @@ -611,7 +567,7 @@ void DrawingView::resizeEvent(QResizeEvent * /*event*/) } -void DrawingView::ToolMouse(int mode, Point p) +void DrawingView::ToolHandler(int mode, Point p) { if (Global::tool == TTLine) LineHandler(mode, p); @@ -732,9 +688,7 @@ void DrawingView::RotateHandler(int mode, Point p) if (Global::toolState == TSNone) { toolPoint[0] = p; - toolObjects.clear(); - CopyObjects(select, toolObjects); -// ClearSelected(toolObjects); + SavePointsFrom(select, toolScratch); Global::toolState = TSPoint1; } else if (Global::toolState == TSPoint1) @@ -744,36 +698,24 @@ void DrawingView::RotateHandler(int mode, Point p) break; case ToolMouseMove: -/* -There's two approaches to this that we can do: - - -- Keep a copy of selected objects & rotate those (drawing rotated + selected) - -- Rotate the selected (drawing selected only) - -Either way, we need to have a copy of the points before we change them; we also need -to know whether or not to discard any changes made--maybe with a ToolCleanup() -function. -*/ if ((Global::toolState == TSPoint1) || (Global::toolState == TSNone)) toolPoint[0] = p; else if (Global::toolState == TSPoint2) { -// need to reset the selected points to their non-rotated state in this case... + toolPoint[1] = p; + if (shiftDown) return; - toolPoint[1] = p; - double angle = Vector(toolPoint[1], toolPoint[0]).Angle(); std::vector::iterator j = select.begin(); - std::vector::iterator i = toolObjects.begin(); + std::vector::iterator i = toolScratch.begin(); -// for(; i!=select.end(); i++, j++) - for(; i!=toolObjects.end(); i++, j++) + for(; i!=toolScratch.end(); i++, j++) { - Object * obj = (Object *)(*i); - Point p1 = Geometry::RotatePointAroundPoint(obj->p[0], toolPoint[0], angle); - Point p2 = Geometry::RotatePointAroundPoint(obj->p[1], toolPoint[0], angle); + 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; @@ -796,12 +738,38 @@ function. } else { -#if 0 - Line * l = new Line(toolPoint[0], toolPoint[1]); - document.objects.push_back(l); - toolPoint[0] = toolPoint[1]; -#endif + // 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 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); } } @@ -824,13 +792,14 @@ void DrawingView::mousePressEvent(QMouseEvent * event) // if (Global::snapPointIsValid) // point = Global::snapPoint; - ToolMouse(ToolMouseDown, point); + ToolHandler(ToolMouseDown, point); return; } // Clear the selection only if CTRL isn't being held on click if (!ctrlDown) - ClearSelection(); + ClearSelected(document.objects); +// ClearSelection(); // If any objects are being hovered on click, add them to the selection // & return @@ -913,7 +882,7 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event) if (Global::snapToGrid) point = SnapPointToGrid(point); - ToolMouse(ToolMouseMove, point); + ToolHandler(ToolMouseMove, point); } // This is used to draw the tool crosshair... @@ -939,7 +908,7 @@ void DrawingView::mouseReleaseEvent(QMouseEvent * event) if (Global::tool) { Vector point = Painter::QtToCartesianCoords(Vector(event->x(), event->y())); - ToolMouse(ToolMouseUp, point); + ToolHandler(ToolMouseUp, point); return; } @@ -1007,10 +976,6 @@ void DrawingView::wheelEvent(QWheelEvent * event) void DrawingView::keyPressEvent(QKeyEvent * event) { -#if 0 - if (toolAction) - toolAction->KeyDown(event->key()); -#endif bool oldShift = shiftDown; bool oldCtrl = ctrlDown; @@ -1020,16 +985,17 @@ void DrawingView::keyPressEvent(QKeyEvent * event) ctrlDown = true; if ((oldShift != shiftDown) || (oldCtrl != ctrlDown)) + { + if (Global::tool) + ToolHandler(ToolKeyDown, Point(0, 0)); + update(); + } } void DrawingView::keyReleaseEvent(QKeyEvent * event) { -#if 0 - if (toolAction) - toolAction->KeyReleased(event->key()); -#endif bool oldShift = shiftDown; bool oldCtrl = ctrlDown; @@ -1039,7 +1005,12 @@ void DrawingView::keyReleaseEvent(QKeyEvent * event) ctrlDown = false; if ((oldShift != shiftDown) || (oldCtrl != ctrlDown)) + { + if (Global::tool) + ToolHandler(ToolKeyUp, Point(0, 0)); + update(); + } } //