File: colorproxy_p.h

package info (click to toggle)
libkdegames-kde4 4:14.12.3-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 36,372 kB
  • ctags: 2,337
  • sloc: cpp: 16,003; perl: 5,276; sh: 58; makefile: 3
file content (98 lines) | stat: -rw-r--r-- 4,334 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/***************************************************************************
 *   Copyright 2010 Stefan Majewsky <majewsky@gmx.net>                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License          *
 *   version 2 as published by the Free Software Foundation                *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU Library General Public License for more details.                  *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 ***************************************************************************/

#ifndef LIBKDEGAMES_COLORPROXY_P_H
#define LIBKDEGAMES_COLORPROXY_P_H

#include <QtCore/QHash>
#include <QtGui/QPaintDevice>
#include <QtGui/QPaintEngine>

class QPaintEngineColorProxy;

#ifndef KDEGAMES_QCOLOR_QHASH
#	define KDEGAMES_QCOLOR_QHASH
	inline uint qHash(const QColor& color)
	{
		return color.rgba();
	}
#endif // KDEGAMES_QCOLOR_QHASH

/**
 * This QPaintDevice forwards all painting operations performed on it to the
 * contained QPaintDevice. The only modification is that certain colors are
 * replaced by others in all painting operations (except for drawImage and
 * drawPixmap).
 *
 * @note Using this class results in a non-negligible performance penalty
 * (~10-20% longer runtime), so use it only if the set of color replacements is
 * non-empty.
 */
class QPaintDeviceColorProxy : public QPaintDevice
{
	public:
		///@warning Replacement loops (e.g. color1 -> color2 -> color3 -> color1) lead to infinite loops.
		///@warning You should not interact with the @a proxiedDevice during the lifetime of this instance.
		QPaintDeviceColorProxy(QPaintDevice* proxiedDevice, const QHash<QColor, QColor>& replacements);
		~QPaintDeviceColorProxy();

		QPaintDevice* proxiedDevice() const;
		virtual QPaintEngine* paintEngine() const;

		QBrush map(const QBrush& brush) const;
		inline QColor map(const QColor& color) const;
		QPen map(const QPen& pen) const;
	protected:
		virtual int metric(PaintDeviceMetric metric) const;
	private:
		QPaintDevice* m_proxiedDevice;
		QPaintEngine* m_engine;
		QHash<QColor, QColor> m_replacements;
};

class QPaintEngineColorProxy : public QPaintEngine
{
	public:
		QPaintEngineColorProxy();
		~QPaintEngineColorProxy();

		virtual bool begin(QPaintDevice* device);
		virtual bool end();
		virtual void drawEllipse(const QRectF& rect);
		virtual void drawEllipse(const QRect& rect);
		virtual void drawImage(const QRectF& rectangle, const QImage& image, const QRectF& sr, Qt::ImageConversionFlags flags = Qt::AutoColor);
		virtual void drawLines(const QLineF* lines, int lineCount);
		virtual void drawLines(const QLine* lines, int lineCount);
		virtual void drawPath(const QPainterPath& path);
		virtual void drawPixmap(const QRectF& r, const QPixmap& pm, const QRectF& sr);
		virtual void drawPoints(const QPointF* points, int pointCount);
		virtual void drawPoints(const QPoint* points, int pointCount);
		virtual void drawPolygon(const QPointF* points, int pointCount, PolygonDrawMode mode);
		virtual void drawPolygon(const QPoint* points, int pointCount, PolygonDrawMode mode);
		virtual void drawRects(const QRectF* rects, int rectCount);
		virtual void drawRects(const QRect* rects, int rectCount);
		virtual void drawTextItem(const QPointF& p, const QTextItem& textItem);
		virtual void drawTiledPixmap(const QRectF& rect, const QPixmap& pixmap, const QPointF& p);
		virtual Type type() const;
		virtual void updateState(const QPaintEngineState& state);
	private:
		QPaintDeviceColorProxy* m_proxy;
		QPainter* m_painter;
};

#endif // LIBKDEGAMES_COLORPROXY_P_H