| 1 | /* |
| 2 | * LibrePCB - Professional EDA for everyone! |
| 3 | * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. |
| 4 | * https://librepcb.org/ |
| 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, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #ifndef UNITTESTS_CORE_GRAPHICSEXPORTTEST_H |
| 21 | #define UNITTESTS_CORE_GRAPHICSEXPORTTEST_H |
| 22 | |
| 23 | /******************************************************************************* |
| 24 | * Includes |
| 25 | ******************************************************************************/ |
| 26 | #include <librepcb/core/export/graphicsexport.h> |
| 27 | #include <librepcb/core/types/point.h> |
| 28 | |
| 29 | #include <QtCore> |
| 30 | |
| 31 | /******************************************************************************* |
| 32 | * Namespace / Forward Declarations |
| 33 | ******************************************************************************/ |
| 34 | namespace librepcb { |
| 35 | namespace tests { |
| 36 | |
| 37 | /******************************************************************************* |
| 38 | * GraphicsPagePainter |
| 39 | ******************************************************************************/ |
| 40 | |
| 41 | class GraphicsPagePainterMock : public GraphicsPagePainter { |
| 42 | Point mPos; |
| 43 | Length mWidth; |
| 44 | Length mHeight; |
| 45 | |
| 46 | public: |
| 47 | GraphicsPagePainterMock(const Length& x = Length(0), |
| 48 | const Length& y = Length(), |
| 49 | const Length& width = Length(200000000), |
| 50 | const Length& height = Length(100000000)) noexcept |
| 51 | : mPos(x, y), mWidth(width), mHeight(height) {} |
| 52 | |
| 53 | virtual ~GraphicsPagePainterMock() noexcept {} |
| 54 | |
| 55 | void paint(QPainter& painter, |
| 56 | const GraphicsExportSettings& settings) const noexcept override { |
| 57 | Q_UNUSED(settings); |
| 58 | |
| 59 | Point topLeft(mPos.getX() - mWidth / 2, mPos.getY() + mHeight / 2); |
| 60 | Point bottomRight(mPos.getX() + mWidth / 2, mPos.getY() - mHeight / 2); |
| 61 | QRectF rect(topLeft.toPxQPointF(), bottomRight.toPxQPointF()); |
| 62 | rect.adjust(0, 0, -1, -1); // Ensure content is *within* bounds. |
| 63 | |
| 64 | painter.setPen(QPen(Qt::red, 5)); |
| 65 | painter.drawEllipse(rect.adjusted(20, 20, -20, -20)); |
| 66 | painter.setPen(QPen(Qt::black, 0)); |
| 67 | painter.drawRect(rect); |
| 68 | } |
| 69 | }; |
| 70 | |
| 71 | /******************************************************************************* |
| 72 | * End of File |
| 73 | ******************************************************************************/ |
| 74 | |
| 75 | } // namespace tests |
| 76 | } // namespace librepcb |
| 77 | |
| 78 | #endif |