X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdrawingview.cpp;h=a3a6eb13a67503dd56042600eea073349cedfdaf;hb=f19a3a172c425b7fcc5a648a94870f0247c6be89;hp=55b56e7d87e02ae0aa5cbd1b1e4c428ffca9ebb2;hpb=c51c02d23ddd4423882da2c54b76f8f2c90c1c99;p=architektonas diff --git a/src/drawingview.cpp b/src/drawingview.cpp index 55b56e7..a3a6eb1 100644 --- a/src/drawingview.cpp +++ b/src/drawingview.cpp @@ -16,11 +16,13 @@ // // STILL TO BE DONE: // +// - Redo rendering code to *not* use Qt's transform functions, as they are tied +// to a left-handed system and we need a right-handed one. // // Uncomment this for debugging... //#define DEBUG -//#define DEBUGFOO // Various tool debugging... +//#define DEBUGFOO // Various tool debugging... //#define DEBUGTP // Toolpalette debugging... #include "drawingview.h" @@ -32,15 +34,16 @@ #include "circle.h" #include "dimension.h" #include "line.h" +#include "painter.h" DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent), -// scale(1.0), offsetX(-10), offsetY(-10), tool(TOOLSelect), -// ptHighlight(-1), oldPtHighlight(-1), ptNextHighlight(-1), oldPtNextHighlight(-1), -// polyFirstPoint(true) + // The value in the settings file will override this. + useAntialiasing(true), scale(1.0), offsetX(-10), offsetY(-10), document(Vector(0, 0)), - gridSpacing(32.0), collided(false) + gridSpacing(32.0), collided(false), rotateTool(false), rx(150.0), ry(150.0), + scrollDrag(false) { setBackgroundRole(QPalette::Base); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -58,11 +61,32 @@ DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent), document.Add(new Circle(Vector(50, 150), 49, &document)); document.Add(new Arc(Vector(300, 300), 32, PI / 4.0, PI * 1.3, &document)), document.Add(new Arc(Vector(200, 200), 60, PI / 2.0, PI * 1.5, &document)); +#if 1 Dimension * dimension = new Dimension(Vector(0, 0), Vector(0, 0), &document); - line->SetDimensionOnPoint1(dimension); - line->SetDimensionOnPoint2(dimension); + line->SetDimensionOnLine(dimension); document.Add(dimension); +#else + // Alternate way to do the above... + line->SetDimensionOnLine(); +#endif +} + +void DrawingView::SetRotateToolActive(bool state/*= true*/) +{ + rotateTool = state; + update(); +} + +//These are not needed... :-P +#if 0 +void DrawingView::ZoomIn(void) +{ +} + +void DrawingView::ZoomOut(void); +{ } +#endif QPoint DrawingView::GetAdjustedMousePosition(QMouseEvent * event) { @@ -82,9 +106,15 @@ QPoint DrawingView::GetAdjustedClientPosition(int x, int y) void DrawingView::paintEvent(QPaintEvent * /*event*/) { - QPainter painter(this); - painter.setRenderHint(QPainter::Antialiasing); + QPainter qtPainter(this); + Painter painter(&qtPainter); + if (useAntialiasing) + qtPainter.setRenderHint(QPainter::Antialiasing); + + Painter::screenSize = Vector(size().width(), size().height()); +// Painter::zoom = 2.0; // 200% zoom +#if 0 #if 0 painter.translate(QPoint(-offsetX, size.height() - (-offsetY))); painter.scale(1.0, -1.0); @@ -97,14 +127,24 @@ void DrawingView::paintEvent(QPaintEvent * /*event*/) transform.translate(-offsetX, -size().height() - offsetY); // transform.scale(0.25, 0.25); painter.setTransform(transform); +#endif #endif Object::SetViewportHeight(size().height()); // Draw coordinate axes - painter.setPen(QPen(Qt::blue, 1.0, Qt::DotLine)); - painter.drawLine(0, -16384, 0, 16384); - painter.drawLine(-16384, 0, 16384, 0); + painter.SetPen(QPen(Qt::blue, 1.0, Qt::DotLine)); + painter.DrawLine(0, -16384, 0, 16384); + painter.DrawLine(-16384, 0, 16384, 0); + + // Draw supplemental (tool related) points + + if (rotateTool) + { + painter.SetPen(QPen(QColor(0, 200, 0), 2.0, Qt::SolidLine)); + painter.DrawLine(rx - 10, ry, rx + 10, ry); + painter.DrawLine(rx, ry - 10, rx, ry + 10); + } // Maybe we can make the grid into a background brush instead, and let Qt deal // with it??? @@ -114,18 +154,19 @@ void DrawingView::paintEvent(QPaintEvent * /*event*/) painter.setPen(QPen(QColor(90, 90, 90), 1.0, Qt::DotLine)); //these two loops kill performance! + // Also, these overwrite our coordinate axes for(double x=0; xbutton() == Qt::LeftButton) { - QPoint pt = GetAdjustedMousePosition(event); - Vector point(pt.x(), pt.y()); - + Vector point = Painter::QtToCartesianCoords(Vector(event->x(), event->y())); collided = document.Collided(point); if (collided) update(); // Do an update if collided with at least *one* object in the document } + else if (event->button() == Qt::MiddleButton) + { + scrollDrag = true; + oldPoint = Vector(event->x(), event->y()); + // Should also change the mouse pointer as well... + setCursor(Qt::SizeAllCursor); + } } void DrawingView::mouseMoveEvent(QMouseEvent * event) { - QPoint pt = GetAdjustedMousePosition(event); - Vector point(pt.x(), pt.y()); + Vector point = Painter::QtToCartesianCoords(Vector(event->x(), event->y())); + + if (event->buttons() & Qt::MiddleButton) + { + 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 them. :-) + Vector delta(point, oldPoint); + delta /= Painter::zoom; + delta.y = -delta.y; + Painter::origin -= delta; + update(); + oldPoint = point; + return; + } // Grid processing... #if 1 @@ -158,12 +217,15 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event) // 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 += gridSpacing / 2.0; // *This* adds to Z!!! - point /= 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 *= gridSpacing; + if (event->buttons() & Qt::LeftButton) + { + point += gridSpacing / 2.0; // *This* adds to Z!!! + point /= 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 *= gridSpacing; + } #endif //we should keep track of the last point here and only pass this down *if* the point //changed... @@ -186,6 +248,11 @@ void DrawingView::mouseReleaseEvent(QMouseEvent * event) // if (collided) update(); // Do an update if collided with at least *one* object in the document } + else if (event->button() == Qt::MiddleButton) + { + scrollDrag = false; + setCursor(Qt::ArrowCursor); + } }