//{
//}
+void ApplicationWindow::SnapToGridTool(void)
+{
+ Object::SetSnapMode(snapToGridAct->isChecked());
+}
+
void ApplicationWindow::FixAngle(void)
{
Object::SetFixedAngle(fixAngleAct->isChecked());
// This just zooms leaving origin intact... should zoom in at the current center! [DONE]
Painter::zoom *= zoomFactor;
zoomIndicator->setText(QString("Zoom: %1%").arg(Painter::zoom * 100.0 * SCREEN_ZOOM));
+ drawing->UpdateGridBackground();
drawing->update();
}
// This just zooms leaving origin intact... should zoom out at the current center! [DONE]
Painter::zoom /= zoomFactor;
zoomIndicator->setText(QString("Zoom: %1%").arg(Painter::zoom * 100.0 * SCREEN_ZOOM));
+ drawing->UpdateGridBackground();
drawing->update();
}
QIcon(":/res/quit.png"), QKeySequence(tr("Ctrl+q")));
connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
+ snapToGridAct = CreateAction(tr("&Snap To Grid"), tr("Snap To Grid"), tr("Snaps mouse cursor to the visible grid when moving/creating objects."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("S,G")), true);
+ connect(snapToGridAct, SIGNAL(triggered()), this, SLOT(SnapToGridTool()));
+
fixAngleAct = CreateAction(tr("Fix &Angle"), tr("Fix Angle"), tr("Fixes the angle of an object."),
QIcon(":/res/fix-angle.png"), QKeySequence(tr("F,A")), true);
connect(fixAngleAct, SIGNAL(triggered()), this, SLOT(FixAngle()));
menu->addAction(zoomOutAct);
menu = menuBar()->addMenu(tr("&Edit"));
+ menu->addAction(snapToGridAct);
menu->addAction(fixAngleAct);
menu->addAction(fixLengthAct);
menu->addAction(rotateAct);
toolbar->addAction(zoomOutAct);
toolbar = addToolBar(tr("Edit"));
+ toolbar->addAction(snapToGridAct);
toolbar->addAction(fixAngleAct);
toolbar->addAction(fixLengthAct);
toolbar->addAction(rotateAct);
toolbar->addAction(deleteAct);
+ toolbar->addSeparator();
toolbar->addAction(addLineAct);
toolbar->addAction(addCircleAct);
toolbar->addAction(addArcAct);
QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
QSize size = settings.value("size", QSize(400, 400)).toSize();
drawing->useAntialiasing = settings.value("useAntialiasing", true).toBool();
+ snapToGridAct->setChecked(settings.value("snapToGrid", true).toBool());
resize(size);
move(pos);
// pos = settings.value("charWndPos", QPoint(0, 0)).toPoint();
settings.setValue("pos", pos());
settings.setValue("size", size());
settings.setValue("useAntialiasing", drawing->useAntialiasing);
+ settings.setValue("snapToGrid", snapToGridAct->isChecked());
// settings.setValue("charWndPos", ((TTEdit *)qApp)->charWnd->pos());
// settings.setValue("charWndSize", ((TTEdit *)qApp)->charWnd->size());
}
private slots:
// void FileOpen();
+ void SnapToGridTool(void);
void FixAngle(void);
void FixLength(void);
void DeleteTool(void);
QAction * rotateAct;
QAction * zoomInAct;
QAction * zoomOutAct;
+ QAction * snapToGridAct;
};
#endif // __APPLICATIONWINDOW_H__
else
painter->SetPen(QPen(Qt::black, 1.0, Qt::SolidLine));
+ // Hatch/Fill...
+// QBrush brush(Qt::DiagCrossPattern);
+// brush.setColor(QColor(255, 255, 0));
+// painter->SetBrush(brush);
+ painter->SetBrush(QBrush(Qt::NoBrush));
+
// Draw the object...
painter->DrawEllipse(position, radius, radius);
// 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*/)
//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)
{
if (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;
void SetRotateToolActive(bool state = true);
void SetAddLineToolActive(bool state = true);
void SetAddCircleToolActive(bool state = true);
+ void UpdateGridBackground(void);
public slots:
void AddNewObjectToDocument(Object *);
bool useAntialiasing;
private:
+// QBrush * backgroundBrush;
+ QPixmap gridBackground;
double scale; // Window scaling factor
int32_t offsetX, offsetY; // Window offsets
Container document;
int Object::viewportHeight = 0;
bool Object::deleteActive = false;
bool Object::dimensionActive = false;
+bool Object::snapToGrid = true;
Object::Object(): position(Vector(0, 0)), parent(0), state(OSInactive), oldState(OSInactive),
{
dimensionActive = state;
}
+
+void Object::SetSnapMode(bool state/*= true*/)
+{
+ snapToGrid = state;
+}
static void SetViewportHeight(int);
static void SetDeleteActive(bool state = true);
static void SetDimensionActive(bool state = true);
+ static void SetSnapMode(bool state = true);
protected:
Vector position; // All objects have a position (doubles as reference point)
static int viewportHeight;
static bool deleteActive;
static bool dimensionActive;
+ static bool snapToGrid;
};
#endif // __OBJECT_H__
// then rotate the frame to the desired angle.
center = CartesianToQtCoords(center);
-// NOTE: 1/32 is a kludge to make things look right at screen resolution...
// We may need this stuff... If dimension text is large enough.
// int textWidth = QFontMetrics(painter->font()).width(text);
// int textHeight = QFontMetrics(painter->font()).height();
- QRectF textBox(-100 * zoom * SCREEN_ZOOM, -100 * zoom * SCREEN_ZOOM, 200 * zoom * SCREEN_ZOOM, 200 * zoom * SCREEN_ZOOM); // x, y, w, h; x/y = upper left corner
+// NOTE: SCREEN_ZOOM is a kludge to make things look right at screen resolution...
+ QRectF textBox(-100.0 * zoom * SCREEN_ZOOM, -100.0 * zoom * SCREEN_ZOOM, 200.0 * zoom * SCREEN_ZOOM, 200.0 * zoom * SCREEN_ZOOM); // x, y, w, h; x/y = upper left corner
// This is in pixels. Might not render correctly at all zoom levels.
// Need to figure out if dimensions are always rendered at one size regardless of zoom,
// or if they have a definite size, and are thus zoomable.
// If zoomable, this is incorrect:
// (Added zoom, so this is correct now :-)
- int yOffset = -12 * zoom * SCREEN_ZOOM;
+ float yOffset = -12.0 * zoom * SCREEN_ZOOM;
// Fix text so it isn't upside down...
if ((angle > PI * 0.5) && (angle < PI * 1.5))
{
angle += PI;
- yOffset = 12 * zoom * SCREEN_ZOOM;
+ yOffset = 12.0 * zoom * SCREEN_ZOOM;
}
#if 0
void Painter::DrawHandle(Vector center)
{
center = CartesianToQtCoords(center);
+ painter->setBrush(Qt::NoBrush);
painter->drawEllipse(QPointF(center.x, center.y), 4.0, 4.0);
}
Vector orthogonal = Vector(cos(orthoAngle), sin(orthoAngle));
Vector unit = Vector(head - tail).Unit();
-// NOTE: 1/32 is a kludge to make things look right at scale...
+// NOTE: SCREEN_ZOOM is a kludge to make things look right at scale...
Point p1 = head - (unit * 9.0 * SCREEN_ZOOM);
Point p2 = p1 + (orthogonal * 3.0 * SCREEN_ZOOM);
Point p3 = p1 - (orthogonal * 3.0 * SCREEN_ZOOM);
#include <QtGui>
#include "vector.h"
-#define SCREEN_ZOOM (1.0 / 8.0)
+#define SCREEN_ZOOM (1.0 / 4.0)
// Forward declarations