// FIXED:
//
+// - 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. [DONE]
//
// 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...
DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent),
// The value in the settings file will override this.
useAntialiasing(true),
+ gridBackground(256, 256),
scale(1.0), offsetX(-10), offsetY(-10),
document(Vector(0, 0)),
gridSpacing(32.0), collided(false), rotateTool(false), rx(150.0), ry(150.0),
#endif
// connect(toolAction, SIGNAL(ObjectReady(Object *)), this,
// SLOT(AddNewObjectToDocument(Object *)));
+//This works, now how to scroll it???
+// QPixmap pm(256, 256);
+ QPainter pmp(&gridBackground);
+#if 0
+ pmp.fillRect(0, 0, 256, 256, Qt::lightGray);
+
+ pmp.fillRect(0, 64, 64, 64, Qt::darkGray);
+ pmp.fillRect(0, 192, 64, 64, Qt::darkGray);
+ pmp.fillRect(64, 0, 64, 64, Qt::darkGray);
+ pmp.fillRect(64, 128, 64, 64, Qt::darkGray);
+ pmp.fillRect(128, 64, 64, 64, Qt::darkGray);
+ pmp.fillRect(128, 192, 64, 64, Qt::darkGray);
+ pmp.fillRect(192, 0, 64, 64, Qt::darkGray);
+ pmp.fillRect(192, 128, 64, 64, Qt::darkGray);
+#else
+ pmp.fillRect(0, 0, 256, 256, QColor(240, 240, 240));
+ pmp.setPen(QPen(QColor(190, 190, 255), 2.0, Qt::SolidLine));
+ for(int i=0; i<255; i+=12)
+ pmp.drawLine(i, 0, i, 255);
+ for(int i=0; i<255; i+=12)
+ pmp.drawLine(0, i, 255, i);
+#endif
+ pmp.end();
+ UpdateGridBackground();
}
void DrawingView::SetRotateToolActive(bool state/*= true*/)
void DrawingView::SetAddLineToolActive(bool state/*= true*/)
{
- if (state && toolAction == NULL)
+ if (state)// && toolAction == NULL)
{
+ if (toolAction)
+ delete toolAction;
+
+ addCircleTool = false;
toolAction = new DrawLineAction();
connect(toolAction, SIGNAL(ObjectReady(Object *)), this,
SLOT(AddNewObjectToDocument(Object *)));
}
- else if (!state && toolAction)
+ else if (!state && addLineTool && toolAction)
{
delete toolAction;
toolAction = NULL;
void DrawingView::SetAddCircleToolActive(bool state/*= true*/)
{
- if (state && toolAction == NULL)
+ if (state)// && toolAction == NULL)
{
+ if (toolAction)
+ delete toolAction;
+
+ addLineTool = false;
toolAction = new DrawCircleAction();
connect(toolAction, SIGNAL(ObjectReady(Object *)), this,
SLOT(AddNewObjectToDocument(Object *)));
}
- else if (!state && toolAction)
+ else if (!state && addCircleTool && toolAction)
{
delete toolAction;
toolAction = NULL;
addCircleTool = state;
update();
-//printf("DrawingView::SetAddLineToolActive(). toolAction=%08X\n", toolAction);
+//printf("DrawingView::SetAddCircleToolActive(). toolAction=%08X\n", toolAction);
+}
+
+void DrawingView::UpdateGridBackground(void)
+{
+#if 0
+// Shift the background to match our scrolling...
+QBrush newBrush = *backgroundBrush;
+//QMatrix brushMatrix = backgroundBrush->matrix();
+QTransform brushMatrix = backgroundBrush->transform();
+brushMatrix.translate(Painter::origin.x, Painter::origin.y);
+//brushMatrix.translate(15.0, 15.0);
+//backgroundBrush->setMatrix(brushMatrix);
+//backgroundBrush->setTransform(brushMatrix);
+newBrush.setTransform(brushMatrix);
+QPalette pal = palette();
+//pal.setBrush(backgroundRole(), *backgroundBrush);
+pal.setBrush(backgroundRole(), newBrush);
+setPalette(pal);
+//Background painting does not honor the transformation matrix (either one)...
+// So...
+#else
+//was: 128
+#define BG_BRUSH_SPAN 72
+ // Transform the origin to Qt coordinates
+ Vector pixmapOrigin = Painter::CartesianToQtCoords(Vector());
+ int x = (int)pixmapOrigin.x;
+ int y = (int)pixmapOrigin.y;
+ // Problem with mod 128: Negative numbers screw it up... [FIXED]
+ x = (x < 0 ? 0 : BG_BRUSH_SPAN - 1) - (x % BG_BRUSH_SPAN);
+ y = (y < 0 ? 0 : BG_BRUSH_SPAN - 1) - (y % BG_BRUSH_SPAN);
+
+ // Here we grab a section of the bigger pixmap, so that the background
+ // *looks* like it's scrolling...
+ QPixmap pm = gridBackground.copy(x, y, BG_BRUSH_SPAN, BG_BRUSH_SPAN);
+ QPalette pal = palette();
+ pal.setBrush(backgroundRole(), QBrush(pm));
+ setAutoFillBackground(true);
+ setPalette(pal);
+#endif
}
void DrawingView::AddNewObjectToDocument(Object * object)
QPainter qtPainter(this);
Painter painter(&qtPainter);
+// qtPainter.setBackground(QBrush(Qt::DiagCrossPattern));
+// qtPainter.setBackgroundMode(Qt::OpaqueMode);
+
if (useAntialiasing)
qtPainter.setRenderHint(QPainter::Antialiasing);
delta /= Painter::zoom;
delta.y = -delta.y;
Painter::origin -= delta;
+
+ UpdateGridBackground();
update();
oldPoint = point;
return;