#define BACKGROUND_MAX_SIZE 512
+// Class variable
+//Container DrawingView::document(Vector(0, 0));
+
DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent),
// The value in the settings file will override this.
toolAction = action;
connect(toolAction, SIGNAL(ObjectReady(Object *)), this,
SLOT(AddNewObjectToDocument(Object *)));
+ connect(toolAction, SIGNAL(NeedRefresh()), this, SLOT(HandleActionUpdate()));
}
}
}
+void DrawingView::HandleActionUpdate(void)
+{
+ update();
+}
+
+
void DrawingView::SetCurrentLayer(int layer)
{
Object::currentLayer = layer;
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 Cartesian. :-)
- Vector delta(point, oldPoint);
+// Vector delta(point, oldPoint);
+ Vector delta(oldPoint, point);
delta /= Painter::zoom;
delta.y = -delta.y;
Painter::origin -= delta;
}
-void DrawingView::keyPressEvent(QKeyEvent * event)
+void DrawingView::wheelEvent(QWheelEvent * event)
{
- if (toolAction)
- {
- bool needUpdate = toolAction->KeyDown(event->key());
+ double zoomFactor = 1.25;
+ QSize sizeWin = size();
+ Vector center(sizeWin.width() / 2.0, sizeWin.height() / 2.0);
+ center = Painter::QtToCartesianCoords(center);
- if (needUpdate)
- update();
+ // This is not centering for some reason. Need to figure out why. :-/
+ if (event->delta() > 0)
+ {
+ Vector newOrigin = center - ((center - Painter::origin) / zoomFactor);
+ Painter::origin = newOrigin;
+ Painter::zoom *= zoomFactor;
+ }
+ else
+ {
+ Vector newOrigin = center + ((-center + Painter::origin) * zoomFactor);
+ Painter::origin = newOrigin;
+ Painter::zoom /= zoomFactor;
}
+
+// Object::gridSpacing = gridPixels / Painter::zoom;
+// UpdateGridBackground();
+ SetGridSize(Object::gridSpacing * Painter::zoom);
+ update();
+// zoomIndicator->setText(QString("Grid: %1\", BU: Inch").arg(Object::gridSpacing));
}
-void DrawingView::keyReleaseEvent(QKeyEvent * event)
+void DrawingView::keyPressEvent(QKeyEvent * event)
{
if (toolAction)
- {
- bool needUpdate = toolAction->KeyReleased(event->key());
+ toolAction->KeyDown(event->key());
+}
- if (needUpdate)
- update();
- }
+
+void DrawingView::keyReleaseEvent(QKeyEvent * event)
+{
+ if (toolAction)
+ toolAction->KeyReleased(event->key());
}