renderer.h 4.21 KB
Newer Older
1 2
/***************************************************************************
 *   Copyright 2008      Johannes Bergmeier <johannes.bergmeier@gmx.net>   *
3
 *   Copyright 2015      Ian Wadham <iandw.au@gmail.com>                   *
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   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 General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU 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.         *
 ***************************************************************************/

21 22 23
#ifndef _KSUDOKU_RENDERER_H_
#define _KSUDOKU_RENDERER_H_

24 25
#include <KImageCache>

26
#include <QString>
27
#include <QVector>
28 29 30

class QPixmap;
class QSize;
31
class QSvgRenderer;
32 33 34 35 36 37 38 39 40

namespace ksudoku {

enum GroupType {
	GroupNone              = 0x00,
	GroupRow               = 0x01,
	GroupColumn            = 0x02,
	GroupBlock             = 0x03,
	GroupSpecial           = 0x04,
41
	GroupCage              = 0x05, // For Mathdoku and Killer Sudoku only.
42 43 44 45 46 47 48 49 50
	GroupUnhighlightedMask = 0x07,
	GroupHighlight         = 0x08
};

enum SpecialType {
	SpecialCell        = 0x00,
	SpecialCellPreset  = 0x01,
	SpecialCellMarkers = 0x02,
	SpecialCellMistake = 0x03,
51 52 53
	SpecialCursor      = 0x04,
	SpecialListItem    = 0x05,
	SpecialListCursor  = 0x06
54 55
};

56 57 58 59 60
enum SymbolType {
	SymbolPreset	= 0x00,
	SymbolEdited	= 0x01
};

61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
Q_DECLARE_FLAGS(GroupTypes, GroupType)

class Renderer {

enum SupportFlag {
	HasRow               = 0x0001,
	HasColumn            = 0x0002,
	HasBlock             = 0x0004,
	HasSpecial           = 0x0008,
	HasRowHighlight      = 0x0010,
	HasColumnHighlight   = 0x0020,
	HasBlockHighlight    = 0x0040,
	HasSpecialHighlight  = 0x0080,
	HasBlockCenter       = 0x0100,
	HasSpecialCenter     = 0x0200,
	ContoursInBackground = 0x1000
};

public:
	static Renderer* instance();

82 83
	bool loadTheme(const QString& themeName);

84 85 86 87 88
	// In Mathdoku style, symbols and markers are drawn smaller than usual
	// and re-positioned, to allow space at the top left of a cell for a
	// cage label. The label contains the value and operator clues.
	void setMathdokuStyle(bool onOff) { m_mathdokuStyle = onOff; }

89 90 91 92 93
	QPixmap renderBackground(const QSize& size) const;
	QPixmap renderSpecial(SpecialType type, int size) const;

	QPixmap renderBorder(int border, GroupTypes type, int size) const;

94 95
	QPixmap renderSymbol(int symbol, int size, int max, SymbolType type) const;
	QPixmap renderSymbolOn(QPixmap pixmap, int symbol, int color, int max, SymbolType type) const;
96 97 98

	QPixmap renderMarker(int symbol, int range, int size) const;
	QPixmap renderMarkerOn(QPixmap pixmap, int symbol, int range, int color) const;
99

100 101
	QPixmap renderCageLabelOn(QPixmap pixmap, const QString & cageLabel);

102
	QPixmap renderSpecial3D(SpecialType type, int size) const;
103 104 105 106 107 108
private:
	Renderer();
	~Renderer();
private:
	void fillNameHashes();
private:
109 110
	// TODO - The next 6 data items are unused.
/*
111 112 113 114 115 116
	bool m_hasRowAndColumn : 1;
	bool m_hasRowAndColumnHighlight : 1;
	bool m_hasBlock : 1;
	bool m_hasBlockHighlight : 1;
	bool m_hasSpecial : 1;
	bool m_hasSpecialHighlight : 1;
117
*/
118 119 120
	QVector<QString> m_borderNames;
	QVector<QString> m_borderTypes;
	QVector<QString> m_specialNames;
121
	QVector<QString> m_special3dNames;
122
	QVector<QString> m_markerNames;
123
	QString m_currentTheme;
124
	QSvgRenderer* m_renderer;
125
	KImageCache* m_cache;
126
	bool m_mathdokuStyle;
127 128 129 130
};

}

131 132
Q_DECLARE_OPERATORS_FOR_FLAGS(ksudoku::GroupTypes)

133
#endif