X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdrawingview.cpp;h=95721178a70be35ee56600f4a492390b8f1ed44c;hb=428876081ee41d40e32f5b4f2bfcfdb7a835e6e1;hp=ab9f565fc2423bcb4f5a0c2b076eeaf63e64f500;hpb=86caae9cadd6e1877a4e6226533521ef0d1c6389;p=architektonas diff --git a/src/drawingview.cpp b/src/drawingview.cpp index ab9f565..9572117 100644 --- a/src/drawingview.cpp +++ b/src/drawingview.cpp @@ -47,7 +47,7 @@ DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent), gridBackground(BACKGROUND_MAX_SIZE, BACKGROUND_MAX_SIZE), scale(1.0), offsetX(-10), offsetY(-10), document(Vector(0, 0)), - gridSpacing(12.0), gridPixels(0), collided(false), rotateTool(false), + /*gridSpacing(12.0),*/ gridPixels(0), collided(false), rotateTool(false), rx(150.0), ry(150.0), scrollDrag(false), addLineTool(false), addCircleTool(false), addDimensionTool(false), @@ -57,6 +57,7 @@ DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent), setBackgroundRole(QPalette::Base); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + Object::gridSpacing = 12.0; // toolPalette = new ToolWindow(); // CreateCursors(); // setCursor(cur[TOOLSelect]); @@ -168,7 +169,8 @@ void DrawingView::SetGridSize(uint32_t size) pmp.end(); // Set up new BG brush & zoom level (pixels per base unit) - Painter::zoom = gridPixels / gridSpacing; +// Painter::zoom = gridPixels / gridSpacing; + Painter::zoom = gridPixels / Object::gridSpacing; UpdateGridBackground(); } @@ -282,6 +284,7 @@ QPoint DrawingView::GetAdjustedClientPosition(int x, int y) } +#if 0 // // 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 @@ -300,6 +303,7 @@ Vector DrawingView::SnapPointToGrid(Vector point) point *= gridSpacing; return point; } +#endif void DrawingView::paintEvent(QPaintEvent * /*event*/) @@ -369,9 +373,19 @@ void DrawingView::mousePressEvent(QMouseEvent * event) Vector point = Painter::QtToCartesianCoords(Vector(event->x(), event->y())); // Problem with this: Can't select stuff very well with the snap grid on. -// Completely screws things up. +// Completely screws things up, as sometimes things don't fall on the grid. +/* +So, how to fix this? Have the Object check itself? +Maybe we can fix this by having the initial point not be snapped, but when there's +a drag, we substitute the snapped point 'oldPoint' which the Object keeps track of +internally to know how far it was dragged... + +Now we do... :-/ +*/ +#if 0 if (Object::snapToGrid) - point = SnapPointToGrid(point); + point = Object::SnapPointToGrid(point); +#endif collided = document.Collided(point); @@ -379,7 +393,12 @@ void DrawingView::mousePressEvent(QMouseEvent * event) update(); // Do an update if collided with at least *one* object in the document if (toolAction) + { + if (Object::snapToGrid) + point = Object::SnapPointToGrid(point); + toolAction->MouseDown(point); + } // Didn't hit any object and not using a tool, so do a selection rectangle if (!(collided || toolAction)) @@ -421,25 +440,11 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event) } // Grid processing... -#if 1 if ((event->buttons() & Qt::LeftButton) && Object::snapToGrid) { -#if 0 - point += gridSpacing / 2.0; // *This* adds to Z!!! - point /= gridSpacing; -//200% is ok, gridSpacing = 6 in this case... -//won't run into problems until gridSpacing = 1.5 (zoom = 800%) -//run into problems with this approach: when zoom level is 200% this truncates to -//integers, which is *not* what's wanted here... - 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 *= gridSpacing; -#else - point = SnapPointToGrid(point); -#endif + point = Object::SnapPointToGrid(point); } -#endif + oldPoint = point; //we should keep track of the last point here and only pass this down *if* the point //changed... @@ -452,7 +457,7 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event) { if (Object::snapToGrid) { - point = SnapPointToGrid(point); + point = Object::SnapPointToGrid(point); oldPoint = point; } @@ -491,3 +496,27 @@ void DrawingView::mouseReleaseEvent(QMouseEvent * event) } } + +void DrawingView::keyPressEvent(QKeyEvent * event) +{ + if (toolAction) + { + bool needUpdate = toolAction->KeyDown(event->key()); + + if (needUpdate) + update(); + } +} + + +void DrawingView::keyReleaseEvent(QKeyEvent * event) +{ + if (toolAction) + { + bool needUpdate = toolAction->KeyReleased(event->key()); + + if (needUpdate) + update(); + } +} +