| 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 | // TODO: Rename this file to PathPaintDevice.h |
| 25 | |
| 26 | #include <QPaintDevice> |
| 27 | #include <QList> |
| 28 | #include <QPolygonF> |
| 29 | #include <QSet> |
| 30 | |
| 31 | class PathPaintEngine; |
| 32 | |
| 33 | // Needed for QSet<QPolygonF>. Simply concatenates all the coordinates in a QByteArray and hashes that. |
| 34 | uint qHash(const QPolygonF& key); |
| 35 | |
| 36 | class PathPaintDevice : public QPaintDevice |
| 37 | { |
| 38 | public: |
| 39 | PathPaintDevice(double widthInMm, double heightInMm, double pixelsPerMm = 90.0/25.4); |
| 40 | ~PathPaintDevice(); |
| 41 | |
| 42 | // Adds a path to the device. |
| 43 | // Also automatically ignores duplicate paths, which QSvgPainter creates (I guess for the fill and stroke). |
| 44 | // Paths are clipped (horribly) to the page. And if any are clipped, clipped() returns true. |
| 45 | void addPath(const QPolygonF& path); |
| 46 | |
| 47 | // Get a list of paths. |
| 48 | QList<QPolygonF> paths(); |
| 49 | |
| 50 | // Returns true if any paths had to be clipped. |
| 51 | bool clipped() const; |
| 52 | |
| 53 | QPaintEngine* paintEngine() const; |
| 54 | |
| 55 | |
| 56 | protected: |
| 57 | int metric(PaintDeviceMetric metric) const; |
| 58 | private: |
| 59 | mutable PathPaintEngine* engine; |
| 60 | |
| 61 | // The paths added. |
| 62 | QList<QPolygonF> pagePaths; |
| 63 | // Set of paths, so we can detect duplicates. |
| 64 | QSet<QPolygonF> pagePathSet; |
| 65 | |
| 66 | bool pathsClipped; |
| 67 | |
| 68 | double width; |
| 69 | double height; |
| 70 | |
| 71 | double ppm; |
| 72 | }; |