File indexing completed on 2024-12-15 03:50:13

0001 /***************************************************************************
0002  *   Copyright 2008      Johannes Bergmeier <johannes.bergmeier@gmx.net>   *
0003  *   Copyright 2015      Ian Wadham <iandw.au@gmail.com>                   *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
0019  ***************************************************************************/
0020 
0021 #ifndef _KSUDOKU_RENDERER_H_
0022 #define _KSUDOKU_RENDERER_H_
0023 
0024 #include <KImageCache>
0025 
0026 #include <QList>
0027 #include <QString>
0028 
0029 class KGameTheme;
0030 class KGameThemeProvider;
0031 
0032 class QPixmap;
0033 class QSize;
0034 class QSvgRenderer;
0035 
0036 namespace ksudoku {
0037 
0038 enum GroupType {
0039     GroupNone              = 0x00,
0040     GroupRow               = 0x01,
0041     GroupColumn            = 0x02,
0042     GroupBlock             = 0x03,
0043     GroupSpecial           = 0x04,
0044     GroupCage              = 0x05, // For Mathdoku and Killer Sudoku only.
0045     GroupUnhighlightedMask = 0x07,
0046     GroupHighlight         = 0x08
0047 };
0048 
0049 enum SpecialType {
0050     SpecialCell        = 0x00,
0051     SpecialCellPreset  = 0x01,
0052     SpecialCellMarkers = 0x02,
0053     SpecialCellMistake = 0x03,
0054     SpecialCursor      = 0x04,
0055     SpecialListItem    = 0x05,
0056     SpecialListCursor  = 0x06
0057 };
0058 
0059 enum SymbolType {
0060     SymbolPreset    = 0x00,
0061     SymbolEdited    = 0x01
0062 };
0063 
0064 Q_DECLARE_FLAGS(GroupTypes, GroupType)
0065 
0066 class Renderer {
0067 
0068 enum SupportFlag {
0069     HasRow               = 0x0001,
0070     HasColumn            = 0x0002,
0071     HasBlock             = 0x0004,
0072     HasSpecial           = 0x0008,
0073     HasRowHighlight      = 0x0010,
0074     HasColumnHighlight   = 0x0020,
0075     HasBlockHighlight    = 0x0040,
0076     HasSpecialHighlight  = 0x0080,
0077     HasBlockCenter       = 0x0100,
0078     HasSpecialCenter     = 0x0200,
0079     ContoursInBackground = 0x1000
0080 };
0081 
0082 public:
0083     static Renderer* instance();
0084 
0085     bool loadTheme(const KGameTheme* theme);
0086 
0087     // In Mathdoku style, symbols and markers are drawn smaller than usual
0088     // and re-positioned, to allow space at the top left of a cell for a
0089     // cage label. The label contains the value and operator clues.
0090     void setMathdokuStyle(bool onOff) { m_mathdokuStyle = onOff; }
0091 
0092     QPixmap renderBackground(const QSize& size) const;
0093     QPixmap renderSpecial(SpecialType type, int size) const;
0094 
0095     QPixmap renderBorder(int border, GroupTypes type, int size) const;
0096 
0097     QPixmap renderSymbol(int symbol, int size, int max, SymbolType type) const;
0098     QPixmap renderSymbolOn(QPixmap pixmap, int symbol, int color, int max, SymbolType type) const;
0099 
0100     QPixmap renderMarker(int symbol, int range, int size) const;
0101     QPixmap renderMarkerOn(QPixmap pixmap, int symbol, int range, int color) const;
0102 
0103     QPixmap renderCageLabelOn(QPixmap pixmap, const QString & cageLabel);
0104 
0105     QPixmap renderSpecial3D(SpecialType type, int size) const;
0106 
0107     KGameThemeProvider *themeProvider() const;
0108 
0109 private:
0110     Renderer();
0111     ~Renderer();
0112 private:
0113     void fillNameHashes();
0114 private:
0115     // TODO - The next 6 data items are unused.
0116 /*
0117     bool m_hasRowAndColumn : 1;
0118     bool m_hasRowAndColumnHighlight : 1;
0119     bool m_hasBlock : 1;
0120     bool m_hasBlockHighlight : 1;
0121     bool m_hasSpecial : 1;
0122     bool m_hasSpecialHighlight : 1;
0123 */
0124     QList<QString> m_borderNames;
0125     QList<QString> m_borderTypes;
0126     QList<QString> m_specialNames;
0127     QList<QString> m_special3dNames;
0128     QList<QString> m_markerNames;
0129     KGameThemeProvider *m_themeProvider;
0130     QSvgRenderer* m_renderer;
0131     KImageCache* m_cache;
0132     bool m_mathdokuStyle;
0133 };
0134 
0135 }
0136 
0137 Q_DECLARE_OPERATORS_FOR_FLAGS(ksudoku::GroupTypes)
0138 
0139 #endif