1 /***************************************************************************
2 								  BoardTheme - graphics theme for BoardView
3 									  -------------------
4 	 begin                : Sun 21 Aug 2005
5 	 copyright            : (C) 2005 Michal Rudolf <mrudolf@kdewebdev.org>
6  ***************************************************************************/
7 
8 /***************************************************************************
9  *                                                                         *
10  *   This program is free software; you can redistribute it and/or modify  *
11  *   it under the terms of the GNU General Public License as published by  *
12  *   the Free Software Foundation; either version 2 of the License, or     *
13  *   (at your option) any later version.                                   *
14  *                                                                         *
15  ***************************************************************************/
16 
17 #ifndef BOARDTHEME_H_INCLUDED
18 #define BOARDTHEME_H_INCLUDED
19 
20 #include <QtGui>
21 
22 #include "piece.h"
23 
24 /** @ingroup GUI
25 	The BoardTheme class contains set of pixmaps and options to
26 	define current board theme. Themes are read from INI files pointing
27 	to set of external pixmaps.
28 
29 	Pixmaps are automatically scaled to given size.
30 */
31 
32 
33 class BoardTheme : public QObject
34 {
35     Q_OBJECT
36 public:
37     enum ColorRole {LightSquare, DarkSquare, Highlight, Frame, CurrentMove, StoredMove, VariationMove, Threat, Target, Check, Wall, UnderProtected, Engine, ColorRoleEndEntry};
38     enum LoadTheme {LoadBoard = 1, LoadPieces = 2, LoadAll = LoadBoard | LoadPieces};
39     enum Effects {Plain, Outline = 1, Shadow = 2};
40     BoardTheme();
41     ~BoardTheme();
42     /** Reset piece and board selections based on config values */
43     void configure();
44     /** Load piece graphics named by string + effect flag */
45     bool loadPieces(const QString& pieces, int effect);
46     /** Load board graphics named by string */
47     bool loadBoard(const QString& board);
48     /** Sets one of the board colors. */
49     void setColor(ColorRole role, const QColor& value);
50     /** @return one of the board colors. */
51     QColor color(ColorRole role) const;
52     /** @return pixmap for given piece scaled to current size(). */
53     const QPixmap& piece(Piece p) const;
54     /** @return unscaled pixmap for given piece. */
55     const QPixmap& originalPiece(Piece p) const;
56     /** @return pixmap for square. */
57     const QPixmap& square(bool dark) const;
58     /** @return unscaled pixmap for square. */
59     const QPixmap& originalSquare(bool dark) const;
60     /** Checkes whether themes is valid (pixmaps loaded). */
61     bool isValid() const;
62     /** Returns name of board theme. It is just file without a path and extension. */
63     QString boardThemeName() const;
64     /** Returns name of piece theme. It is just file without a path and extension. */
65     QString pieceThemeName() const;
66     /** Sets current size for pixmaps. Resizes all pixmaps. */
67     void setSize(const QSize& size);
68     /** Returns current size of pixmaps. */
69     QSize size() const;
70     /** Returns center point of piece pixmap. Useful for centering piece when dragging. */
71     QPoint pieceCenter() const;
72     /** Returns current rectangle of pixmaps. */
73     QRect rect() const;
74     /** Updates board square. */
75     void updateSquares();
76     /** Set the theme according to the parents state */
77     void setEnabled(bool enabled);
78 private:
79     bool isBoardPlain() const;
80     QPixmap m_originalPiece[ConstPieceTypes];
81     QPixmap m_piece[ConstPieceTypes];
82     QPixmap m_originalSquare[2];
83     QPixmap m_square[2];
84     QSize m_size;
85     QColor m_colors[ColorRoleEndEntry];
86     QString m_pieceFilename;
87     QString m_boardFilename;
88 };
89 
90 #endif
91 
92