X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdrawingview.cpp;h=a3a6eb13a67503dd56042600eea073349cedfdaf;hb=f19a3a172c425b7fcc5a648a94870f0247c6be89;hp=e904bdb7ef2a5240fa152392d33f121891a9ce91;hpb=d41ddd699001f6bbf6ac621f5c467bd13efb6087;p=architektonas diff --git a/src/drawingview.cpp b/src/drawingview.cpp index e904bdb..a3a6eb1 100644 --- a/src/drawingview.cpp +++ b/src/drawingview.cpp @@ -16,6 +16,8 @@ // // 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... @@ -32,17 +34,16 @@ #include "circle.h" #include "dimension.h" #include "line.h" +#include "painter.h" DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent), // The value in the settings file will override this. useAntialiasing(true), -// scale(1.0), offsetX(-10), offsetY(-10), tool(TOOLSelect), -// ptHighlight(-1), oldPtHighlight(-1), ptNextHighlight(-1), oldPtNextHighlight(-1), -// polyFirstPoint(true) scale(1.0), offsetX(-10), offsetY(-10), document(Vector(0, 0)), - gridSpacing(32.0), collided(false), rotateTool(false), rx(150.0), ry(150.0) + gridSpacing(32.0), collided(false), rotateTool(false), rx(150.0), ry(150.0), + scrollDrag(false) { setBackgroundRole(QPalette::Base); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -63,7 +64,6 @@ DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent), #if 1 Dimension * dimension = new Dimension(Vector(0, 0), Vector(0, 0), &document); line->SetDimensionOnLine(dimension); -// line->SetDimensionOnPoint2(dimension); document.Add(dimension); #else // Alternate way to do the above... @@ -77,6 +77,17 @@ void DrawingView::SetRotateToolActive(bool state/*= true*/) update(); } +//These are not needed... :-P +#if 0 +void DrawingView::ZoomIn(void) +{ +} + +void DrawingView::ZoomOut(void); +{ +} +#endif + QPoint DrawingView::GetAdjustedMousePosition(QMouseEvent * event) { // This is undoing the transform, e.g. going from client coords to local coords. @@ -95,11 +106,15 @@ QPoint DrawingView::GetAdjustedClientPosition(int x, int y) void DrawingView::paintEvent(QPaintEvent * /*event*/) { - QPainter painter(this); + QPainter qtPainter(this); + Painter painter(&qtPainter); if (useAntialiasing) - painter.setRenderHint(QPainter::Antialiasing); + 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); @@ -112,22 +127,23 @@ 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); + 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 @@ -138,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 @@ -213,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); + } }