1 /*
2  * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB.  All rights reserved.
3  *
4  * This file is part of the KD Chart library.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (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 <https://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef NULL_PAINT_DEVICE_H
21 #define NULL_PAINT_DEVICE_H
22 
23 #include <QPaintDevice>
24 #include <QPaintEngine>
25 
26 namespace KChart
27 {
28     class NullPaintEngine : public QPaintEngine
29     {
30     public:
begin(QPaintDevice *)31         virtual bool begin(QPaintDevice * /*pdev*/) { return true; }
drawEllipse(const QRectF &)32         virtual void drawEllipse(const QRectF & /*rect*/) { }
drawEllipse(const QRect &)33         virtual void drawEllipse(const QRect & /*rect*/) { }
drawImage(const QRectF &,const QImage &,const QRectF &,Qt::ImageConversionFlags)34         virtual void drawImage(const QRectF & /*rectangle*/, const QImage & /*image*/, const QRectF & /*sr*/, Qt::ImageConversionFlags /*flags*/) { }
drawLines(const QLineF *,int)35         virtual void drawLines(const QLineF * /*lines*/, int /*lineCount*/) { }
drawLines(const QLine *,int)36         virtual void drawLines(const QLine * /*lines*/, int /*lineCount*/) { }
drawPath(const QPainterPath &)37         virtual void drawPath(const QPainterPath & /*path*/) { }
drawPixmap(const QRectF &,const QPixmap &,const QRectF &)38         virtual void drawPixmap(const QRectF & /*r*/, const QPixmap & /*pm*/, const QRectF & /*sr*/) { }
drawPoints(const QPointF *,int)39         virtual void drawPoints(const QPointF * /*points*/, int /*pointCount*/) { }
drawPoints(const QPoint *,int)40         virtual void drawPoints(const QPoint * /*points*/, int /*pointCount*/) { }
drawPolygon(const QPointF *,int,PolygonDrawMode)41         virtual void drawPolygon(const QPointF * /*points*/, int /*pointCount*/, PolygonDrawMode /*mode*/) { }
drawPolygon(const QPoint *,int,PolygonDrawMode)42         virtual void drawPolygon(const QPoint * /*points*/, int /*pointCount*/, PolygonDrawMode /*mode*/) { }
drawRects(const QRectF *,int)43         virtual void drawRects(const QRectF * /*rects*/, int /*rectCount*/) { }
drawRects(const QRect *,int)44         virtual void drawRects(const QRect * /*rects*/, int /*rectCount*/) { }
drawTextItem(const QPointF &,const QTextItem &)45         virtual void drawTextItem(const QPointF & /*p*/, const QTextItem & /*textItem*/) { }
drawTiledPixmap(const QRectF &,const QPixmap &,const QPointF &)46         virtual void drawTiledPixmap(const QRectF & /*rect*/, const QPixmap & /*pixmap*/, const QPointF & /*p*/) { }
end()47         virtual bool end()  { return true; }
48 
type()49         virtual Type type() const { return QPaintEngine::User; }
updateState(const QPaintEngineState &)50         virtual void updateState(const QPaintEngineState & /*state*/) { }
51     };
52 
53     class NullPaintDevice : public QPaintDevice
54     {
55     public:
NullPaintDevice(const QSize & size)56         NullPaintDevice(const QSize& size) : m_size(size) { }
~NullPaintDevice()57         ~NullPaintDevice() { }
58 
metric(PaintDeviceMetric metric)59         int metric(PaintDeviceMetric metric) const
60         {
61             switch (metric)
62             {
63             case QPaintDevice::PdmWidth:
64                 return m_size.width();
65             case QPaintDevice::PdmHeight:
66                 return m_size.height();
67             case QPaintDevice::PdmWidthMM:
68                 return 1;
69             case QPaintDevice::PdmHeightMM:
70                 return 1;
71             case QPaintDevice::PdmNumColors:
72                 return int((uint)(-1));
73             case QPaintDevice::PdmDepth:
74                 return 1;
75             case QPaintDevice::PdmDpiX:
76                 return 1;
77             case QPaintDevice::PdmDpiY:
78                 return 1;
79             case QPaintDevice::PdmPhysicalDpiX:
80                 return 1;
81             case QPaintDevice::PdmPhysicalDpiY:
82                 return 1;
83 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
84             case QPaintDevice::PdmDevicePixelRatio:
85                 return 1;
86 #endif
87             }
88             return 1;
89         }
90 
paintEngine()91         QPaintEngine* paintEngine() const
92         {
93             static NullPaintEngine nullPaintEngine;
94             return &nullPaintEngine;
95         }
96 
97     private:
98         QSize m_size;
99     };
100 
101 }
102 
103 #endif
104