//
// 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"
#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);
// setCursor(cur[TOOLSelect]);
// setMouseTracking(true);
- document.Add(new Line(Vector(5, 5), Vector(50, 40), &document));
+ Line * line = new Line(Vector(5, 5), Vector(50, 40), &document);
+ document.Add(line);
document.Add(new Line(Vector(50, 40), Vector(10, 83), &document));
document.Add(new Line(Vector(10, 83), Vector(17, 2), &document));
document.Add(new Circle(Vector(100, 100), 36, &document));
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));
- document.Add(new Dimension(Vector(5, 5), Vector(50, 40), &document));
+#if 1
+ Dimension * dimension = new Dimension(Vector(0, 0), Vector(0, 0), &document);
+ 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)
{
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);
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???
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; x<size().width(); x+=gridSpacing*10.0)
- p.drawLine((int)x, -16384, (int)x, 16384);
+ painter.drawLine((int)x, -16384, (int)x, 16384);
for(double y=0; y<size().height(); y+=gridSpacing*10.0)
- p.drawLine(-16384, (int)y, 16384, (int)y);
+ painter.drawLine(-16384, (int)y, 16384, (int)y);
#endif
- painter.setPen(QPen(Qt::black, 1.0, Qt::SolidLine));
+ painter.SetPen(QPen(Qt::black, 1.0, Qt::SolidLine));
for(double x=0; x<size().width(); x+=gridSpacing)
for(double y=0; y<size().height(); y+=gridSpacing)
- painter.drawPoint((int)x, (int)y);
+ painter.DrawPoint((int)x, (int)y);
// The top level document takes care of rendering for us...
document.Draw(&painter);
{
if (event->button() == 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
// 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...
// 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);
+ }
}