File indexing completed on 2024-05-12 15:54:18
0001 /* 0002 * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 0003 * 0004 * This file is part of the KD Chart library. 0005 * 0006 * This program is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU General Public License as 0008 * published by the Free Software Foundation; either version 2 of 0009 * the License, or (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program. If not, see <https://www.gnu.org/licenses/>. 0018 */ 0019 0020 #ifndef NULL_PAINT_DEVICE_H 0021 #define NULL_PAINT_DEVICE_H 0022 0023 #include <QPaintDevice> 0024 #include <QPaintEngine> 0025 0026 namespace KChart 0027 { 0028 class NullPaintEngine : public QPaintEngine 0029 { 0030 public: 0031 virtual bool begin(QPaintDevice * /*pdev*/) { return true; } 0032 virtual void drawEllipse(const QRectF & /*rect*/) { } 0033 virtual void drawEllipse(const QRect & /*rect*/) { } 0034 virtual void drawImage(const QRectF & /*rectangle*/, const QImage & /*image*/, const QRectF & /*sr*/, Qt::ImageConversionFlags /*flags*/) { } 0035 virtual void drawLines(const QLineF * /*lines*/, int /*lineCount*/) { } 0036 virtual void drawLines(const QLine * /*lines*/, int /*lineCount*/) { } 0037 virtual void drawPath(const QPainterPath & /*path*/) { } 0038 virtual void drawPixmap(const QRectF & /*r*/, const QPixmap & /*pm*/, const QRectF & /*sr*/) { } 0039 virtual void drawPoints(const QPointF * /*points*/, int /*pointCount*/) { } 0040 virtual void drawPoints(const QPoint * /*points*/, int /*pointCount*/) { } 0041 virtual void drawPolygon(const QPointF * /*points*/, int /*pointCount*/, PolygonDrawMode /*mode*/) { } 0042 virtual void drawPolygon(const QPoint * /*points*/, int /*pointCount*/, PolygonDrawMode /*mode*/) { } 0043 virtual void drawRects(const QRectF * /*rects*/, int /*rectCount*/) { } 0044 virtual void drawRects(const QRect * /*rects*/, int /*rectCount*/) { } 0045 virtual void drawTextItem(const QPointF & /*p*/, const QTextItem & /*textItem*/) { } 0046 virtual void drawTiledPixmap(const QRectF & /*rect*/, const QPixmap & /*pixmap*/, const QPointF & /*p*/) { } 0047 virtual bool end() { return true; } 0048 0049 virtual Type type() const { return QPaintEngine::User; } 0050 virtual void updateState(const QPaintEngineState & /*state*/) { } 0051 }; 0052 0053 class NullPaintDevice : public QPaintDevice 0054 { 0055 public: 0056 NullPaintDevice(const QSize& size) : m_size(size) { } 0057 ~NullPaintDevice() { } 0058 0059 int metric(PaintDeviceMetric metric) const 0060 { 0061 switch (metric) 0062 { 0063 case QPaintDevice::PdmWidth: 0064 return m_size.width(); 0065 case QPaintDevice::PdmHeight: 0066 return m_size.height(); 0067 case QPaintDevice::PdmWidthMM: 0068 return 1; 0069 case QPaintDevice::PdmHeightMM: 0070 return 1; 0071 case QPaintDevice::PdmNumColors: 0072 return int((uint)(-1)); 0073 case QPaintDevice::PdmDepth: 0074 return 1; 0075 case QPaintDevice::PdmDpiX: 0076 return 1; 0077 case QPaintDevice::PdmDpiY: 0078 return 1; 0079 case QPaintDevice::PdmPhysicalDpiX: 0080 return 1; 0081 case QPaintDevice::PdmPhysicalDpiY: 0082 return 1; 0083 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) 0084 case QPaintDevice::PdmDevicePixelRatio: 0085 return 1; 0086 #endif 0087 } 0088 return 1; 0089 } 0090 0091 QPaintEngine* paintEngine() const 0092 { 0093 static NullPaintEngine nullPaintEngine; 0094 return &nullPaintEngine; 0095 } 0096 0097 private: 0098 QSize m_size; 0099 }; 0100 0101 } 0102 0103 #endif