QPainter qtPainter(printer);
Painter painter(&qtPainter);
+ // Save vars for screen
+ Point originSave = Global::origin;
+ double zoomSave = Global::zoom;
+ Vector screenSizeSave = Global::screenSize;
+
+ // Adjust zoom + origin to fit the paper (or NxM pages if we have 'em)
+ Rect r = drawing->GetObjectExtents((Object *)(&(drawing->document)));
+
+ QPageLayout pageLayout = printer->pageLayout();
+ QRect pageRect = pageLayout.paintRectPixels(printer->resolution());
+
+ Global::origin = r.BottomLeft();
+ Global::screenSize.x = pageRect.width();
+ Global::screenSize.y = pageRect.height();
+
+ double xScale = (double)pageRect.width() / r.Width();
+ double yScale = (double)pageRect.height() / r.Height();
+ Global::zoom = qMin(xScale, yScale);
+
+ if (xScale < yScale)
+ Global::origin.y -= (((double)pageRect.height() / Global::zoom) - r.Height()) / 2.0;
+ else
+ Global::origin.x -= (((double)pageRect.width() / Global::zoom) - r.Width()) / 2.0;
+
// Do object rendering...
for(int i=0; i<Global::numLayers; i++)
- {
-// if (Global::layerHidden[i] == false)
drawing->RenderObjects(&painter, drawing->document.objects, i);
- }
+
+ // Restore vars
+ Global::origin = originSave;
+ Global::zoom = zoomSave;
+ Global::screenSize = screenSizeSave;
}
void ApplicationWindow::contextMenuEvent(QContextMenuEvent * event)
Need a way to scale line widths as well. :-/ Shouldn't be too difficult, just
need a thickness parameter similar to the "size" param for dimensions. (And now
we do! :-)
-
*/
-// gridPixels = 12; //tmp???
-// SetGridSize(12.0); // This is in pixels
}
void DrawingView::DrawBackground(Painter * painter)
painter->DrawHLine(start.y + i);
}
-#if 0
-void DrawingView::SetGridSize(uint32_t size)
-{
-#if 0
- // Sanity check
- if (size == gridPixels)
- return;
-
- // tmp...
- if (size <= 1)
- return;
-
- // Recreate the background bitmap
- gridPixels = size;
- QPainter pmp(&gridBackground);
- pmp.fillRect(0, 0, BACKGROUND_MAX_SIZE, BACKGROUND_MAX_SIZE, QColor(240, 240, 240));
- pmp.setPen(QPen(QColor(210, 210, 255), 2.0, Qt::SolidLine));
-
- for(int i=0; i<(BACKGROUND_MAX_SIZE-1); i+=gridPixels)
- {
- pmp.drawLine(i, 0, i, BACKGROUND_MAX_SIZE - 1);
- pmp.drawLine(0, i, BACKGROUND_MAX_SIZE - 1, i);
- }
-
- pmp.end();
-
- // Set up new BG brush & zoom level (pixels per base unit)
-// This shouldn't be done here, because it fucks up the scrollwheel zooming...
-// Global::zoom = gridPixels / Global::gridSpacing;
- UpdateGridBackground();
-#endif
-}
-
-void DrawingView::UpdateGridBackground(void)
-{
-#if 0
- // Transform the origin to Qt coordinates
- Vector pixmapOrigin = Painter::CartesianToQtCoords(Vector());
- int x = (int)pixmapOrigin.x;
- int y = (int)pixmapOrigin.y;
- // Use mod arithmetic to grab the correct swatch of background
-/*
-Negative numbers still screw it up... Need to think about what we're
-trying to do here. The fact that it worked with 72 seems to have been pure luck.
-It seems the problem is negative numbers: We can't let that happen.
-When taking away the zero, it pops over 1 px at zero, then goes about 1/2 a
-grid at x<0.
-
-The bitmap looks like this:
-
-+---+---+---+---+---
-| | | | |
-| | | | |
-+---+---+---+---+---
-| | | | |
-| | | | |
-| | | | |
-
-@ x = 1, we want it to look like:
-
--+---+---+---+---+---
- | | | | |
- | | | | |
--+---+---+---+---+---
- | | | | |
- | | | | |
- | | | | |
-
-Which means we need to grab the sample from x = 3. @ x = -1:
-
----+---+---+---+---
- | | | |
- | | | |
----+---+---+---+---
- | | | |
- | | | |
- | | | |
-
-Which means we need to grab the sample from x = 1. Which means we have to take
-the mirror of the modulus of gridPixels.
-
-Doing a mod of a negative number is problematic: 1st, the compiler converts the
-negative number to an unsigned int, then it does the mod. Gets you wrong answers
-most of the time, unless you use a power of 2. :-P So what we do here is just
-take the modulus of the negation, which means we don't have to worry about
-mirroring it later.
-
-The positive case looks gruesome (and it is) but it boils down to this: We take
-the modulus of the X coordinate, then mirror it by subtraction from the
-maximum (in this case, gridPixels). This gives us a number in the range of 1 to
-gridPixels. But we need the case where the result equalling gridPixels to be
-zero; so we do another modulus operation on the result to achieve this.
-*/
- if (x < 0)
- x = -x % gridPixels;
- else
- x = (gridPixels - (x % gridPixels)) % gridPixels;
-
- if (y < 0)
- y = -y % gridPixels;
- else
- y = (gridPixels - (y % gridPixels)) % gridPixels;
-
- // Here we grab a section of the bigger pixmap, so that the background
- // *looks* like it's scrolling...
- QPixmap pm = gridBackground.copy(x, y, gridPixels, gridPixels);
- QPalette pal = palette();
- pal.setBrush(backgroundRole(), QBrush(pm));
- setAutoFillBackground(true);
- setPalette(pal);
-#endif
-}
-
-void DrawingView::SetGridSize(double size)
-{
-#if 0
- // Sanity check
- if (size == gridPixelsF)
- return;
-
- // tmp...
- if (size <= 1)
- return;
-
- // Recreate the background bitmap
- gridPixelsF = size;
- QPainter pmp(&gridBackground);
- pmp.fillRect(0, 0, BACKGROUND_MAX_SIZE, BACKGROUND_MAX_SIZE, QColor(240, 240, 240));
- pmp.setPen(QPen(QColor(210, 210, 255), 2.0, Qt::SolidLine));
-
- for(double i=0; i<(BACKGROUND_MAX_SIZE-1); i+=gridPixelsF)
- {
- pmp.drawLine(i, 0, i, (double)(BACKGROUND_MAX_SIZE - 1));
- pmp.drawLine(0, i, (double)(BACKGROUND_MAX_SIZE - 1), i);
- }
-
- pmp.end();
-
- // Set up new BG brush & zoom level (pixels per base unit)
-// This shouldn't be done here, because it fucks up the scrollwheel zooming...
-// Global::zoom = gridPixels / Global::gridSpacing;
- UpdateGridBackgroundF();
-#endif
-}
-
-
-void DrawingView::UpdateGridBackgroundF(void)
-{
-#if 0
- // Transform the origin to Qt coordinates
- Vector pixmapOrigin = Painter::CartesianToQtCoords(Vector());
- int x = 0;// (int)pixmapOrigin.x;
- int y = 0;// (int)pixmapOrigin.y;
- // Use mod arithmetic to grab the correct swatch of background
-
-/* if (x < 0)
- x = -x % gridPixels;
- else
- x = (gridPixels - (x % gridPixels)) % gridPixels;
-
- if (y < 0)
- y = -y % gridPixels;
- else
- y = (gridPixels - (y % gridPixels)) % gridPixels;*/
-
- // Here we grab a section of the bigger pixmap, so that the background
- // *looks* like it's scrolling...
- QPixmap pm = gridBackground.copy(x, y, gridPixelsF, gridPixelsF);
- QPalette pal = palette();
- pal.setBrush(backgroundRole(), QBrush(pm));
- setAutoFillBackground(true);
- setPalette(pal);
-#endif
-}
-#endif
-
//
// Basically, we just make a single pass through the Container. If the layer #
// is less than the layer # being deleted, then do nothing. If the layer # is
void DrawingView::resizeEvent(QResizeEvent * /*event*/)
{
Global::screenSize = Vector(size().width(), size().height());
-// UpdateGridBackground();
}
void DrawingView::ToolHandler(int mode, Point p)
public:
void DrawBackground(Painter *);
-// void SetGridSize(uint32_t);
-// void SetGridSize(double);
-// void UpdateGridBackground(void);
-// void UpdateGridBackgroundF(void);
Point SnapPointToGrid(Point);
Point SnapPointToAngle(Point);
void RenderObjects(Painter *, VPVector &, int, bool ignoreLayer = false);
void DeleteCurrentLayer(int);
void HandleLayerToggle(void);
void HandleLayerSwap(int, int);
+ void HandleLayerSwap(int, int, VPVector &);
void HandlePenWidth(float);
void HandlePenStyle(int);
void HandlePenColor(uint32_t);
void keyReleaseEvent(QKeyEvent * event);
private:
- void HandleLayerSwap(int, int, VPVector &);
void DrawSubGrid(Painter *, uint32_t, double, Vector, Vector);
QPoint GetAdjustedMousePosition(QMouseEvent * event);
QPoint GetAdjustedClientPosition(int x, int y);
#include "rect.h"
//#include <stdio.h>
-
Rect::Rect(): l(0), r(0), t(0), b(0)
{
}
-
Rect::Rect(double ll, double rr, double tt, double bb):
l(ll), r(rr), t(tt), b(bb)
{
Normalize();
}
-
Rect::Rect(Point tl, Point br): l(tl.x), r(br.x), t(tl.y), b(br.y)
{
Normalize();
}
-
Rect & Rect::operator*=(double scale)
{
l *= scale;
r *= scale;
t *= scale;
b *= scale;
+
return *this;
}
-
Rect & Rect::operator|=(Rect r2)
{
//printf("operatore|=\nthis = (%lf, %lf, %lf, %lf), r = (%lf, %lf, %lf, %lf)\n", l, t, r, b, r2.l, r2.t, r2.r, r2.b);
return *this;
}
-
void Rect::Normalize(void)
{
if (l > r)
}
}
-
void Rect::Translate(Point p)
{
l += p.x;
b += p.y;
}
-
void Rect::Expand(double amt)
{
l -= amt;
b -= amt;
}
-
double Rect::Width(void)
{
return r - l;
}
-
double Rect::Height(void)
{
return t - b;
}
-
bool Rect::Contains(Point p)
{
return ((p.x >= l) && (p.x <= r) && (p.y >= b) && (p.y <= t) ? true : false);
}
-
Point Rect::TopLeft(void)
{
return Point(l, t);
}
+Point Rect::TopRight(void)
+{
+ return Point(r, t);
+}
+
+Point Rect::BottomLeft(void)
+{
+ return Point(l, b);
+}
Point Rect::BottomRight(void)
{
return Point(r, b);
}
-