| 1 | /*************************************************************************** |
| 2 | * This file is part of Robocut. * |
| 3 | * Copyright (C) 2010 Tim Hutt <[email protected]> * |
| 4 | * Copyright (C) 2010 Markus Schulz <[email protected]> * |
| 5 | * * |
| 6 | * This program is free software; you can redistribute it and/or modify * |
| 7 | * it under the terms of the GNU General Public License as published by * |
| 8 | * the Free Software Foundation; either version 3 of the License, or * |
| 9 | * (at your option) any later version. * |
| 10 | * * |
| 11 | * This program is distributed in the hope that it will be useful, * |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 | * GNU General Public License for more details. * |
| 15 | * * |
| 16 | * You should have received a copy of the GNU General Public License * |
| 17 | * along with this program; if not, write to the * |
| 18 | * Free Software Foundation, Inc., * |
| 19 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * |
| 20 | ***************************************************************************/ |
| 21 | |
| 22 | #pragma once |
| 23 | |
| 24 | #include <QPaintEngine> |
| 25 | #include <QPaintDevice> |
| 26 | #include <QPainterPath> |
| 27 | #include "PathPaintPage.h" |
| 28 | |
| 29 | // This is a simple paint engine that records all the paths painted. |
| 30 | // It is used with QSvgPainter to record the paths in an SVG. |
| 31 | // The only device it can draw to is PathPaintDevice |
| 32 | class PathPaintEngine : public QPaintEngine |
| 33 | { |
| 34 | public: |
| 35 | PathPaintEngine(QPaintDevice* pdev); |
| 36 | bool begin(QPaintDevice* pdev); |
| 37 | |
| 38 | void drawPath(const QPainterPath& path); |
| 39 | |
| 40 | void drawPixmap(const QRectF& r, const QPixmap& pm, const QRectF& sr); |
| 41 | |
| 42 | void drawPolygon(const QPointF* points, int pointCount, PolygonDrawMode mode); |
| 43 | |
| 44 | bool end(); |
| 45 | |
| 46 | Type type() const; |
| 47 | void updateState(const QPaintEngineState& state); |
| 48 | private: |
| 49 | PathPaintDevice* dev; |
| 50 | QTransform transform; |
| 51 | QVector<qreal> dashPattern; |
| 52 | bool isCosmetic; |
| 53 | qreal getDistance(const QPointF &p1, const QPointF &p2); |
| 54 | QPointF getPointAtLenght(const QPointF &p1, const QPointF &p2, qreal &l1); |
| 55 | }; |
| 56 |