//
// 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...
#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);
#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...
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.
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);
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
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
// 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);
+ }
}