X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdrawingview.cpp;h=07d7d9fa0265a67073769ab880e0af5712bd388a;hb=2549a213bacfb2f6993ec143083d72b716854345;hp=89c63ed429d9a95f71aa245160d09d95c6ca7e4b;hpb=921bf050ffe5fc81a9ab377e634180e659ee5d5d;p=architektonas diff --git a/src/drawingview.cpp b/src/drawingview.cpp index 89c63ed..07d7d9f 100644 --- a/src/drawingview.cpp +++ b/src/drawingview.cpp @@ -41,6 +41,9 @@ #define BACKGROUND_MAX_SIZE 512 +// Class variable +//Container DrawingView::document(Vector(0, 0)); + DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent), // The value in the settings file will override this. @@ -138,6 +141,7 @@ void DrawingView::SetToolActive(Action * action) toolAction = action; connect(toolAction, SIGNAL(ObjectReady(Object *)), this, SLOT(AddNewObjectToDocument(Object *))); + connect(toolAction, SIGNAL(NeedRefresh()), this, SLOT(HandleActionUpdate())); } } @@ -260,6 +264,12 @@ void DrawingView::AddNewObjectToDocument(Object * object) } +void DrawingView::HandleActionUpdate(void) +{ + update(); +} + + void DrawingView::SetCurrentLayer(int layer) { Object::currentLayer = layer; @@ -388,7 +398,8 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event) point = Vector(event->x(), event->y()); // Since we're using Qt coords for scrolling, we have to adjust them here to // conform to Cartesian coords, since the origin is using Cartesian. :-) - Vector delta(point, oldPoint); +// Vector delta(point, oldPoint); + Vector delta(oldPoint, point); delta /= Painter::zoom; delta.y = -delta.y; Painter::origin -= delta; @@ -457,26 +468,45 @@ void DrawingView::mouseReleaseEvent(QMouseEvent * event) } -void DrawingView::keyPressEvent(QKeyEvent * event) +void DrawingView::wheelEvent(QWheelEvent * event) { - if (toolAction) - { - bool needUpdate = toolAction->KeyDown(event->key()); + double zoomFactor = 1.25; + QSize sizeWin = size(); + Vector center(sizeWin.width() / 2.0, sizeWin.height() / 2.0); + center = Painter::QtToCartesianCoords(center); - if (needUpdate) - update(); + // This is not centering for some reason. Need to figure out why. :-/ + if (event->delta() > 0) + { + Vector newOrigin = center - ((center - Painter::origin) / zoomFactor); + Painter::origin = newOrigin; + Painter::zoom *= zoomFactor; + } + else + { + Vector newOrigin = center + ((-center + Painter::origin) * zoomFactor); + Painter::origin = newOrigin; + Painter::zoom /= zoomFactor; } + +// Object::gridSpacing = gridPixels / Painter::zoom; +// UpdateGridBackground(); + SetGridSize(Object::gridSpacing * Painter::zoom); + update(); +// zoomIndicator->setText(QString("Grid: %1\", BU: Inch").arg(Object::gridSpacing)); } -void DrawingView::keyReleaseEvent(QKeyEvent * event) +void DrawingView::keyPressEvent(QKeyEvent * event) { if (toolAction) - { - bool needUpdate = toolAction->KeyReleased(event->key()); + toolAction->KeyDown(event->key()); +} - if (needUpdate) - update(); - } + +void DrawingView::keyReleaseEvent(QKeyEvent * event) +{ + if (toolAction) + toolAction->KeyReleased(event->key()); }