1/*
2 * Copyright (c) 2010 Ni Hui <shuizhuyuanluo@126.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19#ifndef PIECE_H
20#define PIECE_H
21
22#include <KGameRenderedObjectItem>
23
24class QGraphicsLineItem;
25class QGraphicsSceneMouseEvent;
26/**
27 * This class represents a single piece on the game scene.
28 * It emits signals when clicked.
29 */
30class Piece : public KGameRenderedObjectItem
31{
32 Q_OBJECT
33 public:
34 /** Constructor */
35 explicit Piece( KGameRenderer* renderer, int x, int y, int color, QGraphicsItem* parent = 0 );
36 /** Destructor */
37 ~Piece();
38 /** Reimplemented for using bounding rect for detecting hovering and mouse clicking */
39 virtual QPainterPath shape() const;
40 /** The current column in the game scene, from left to right, starts from 0 */
41 int m_x;
42 /** The current row in the game scene, from top to bottom, starts from 0 */
43 int m_y;
44 /** The color of the piece */
45 const int m_color;
46 /** The bound line graphics item on the right side */
47 QGraphicsLineItem* const m_rightLine;
48 /** The bound line graphics item on the bottom side */
49 QGraphicsLineItem* const m_bottomLine;
50 /** The highlight graphics item overlapped */
51 KGameRenderedObjectItem* const m_highlighter;
52 Q_SIGNALS:
53 /** Emitted when this piece is clicked */
54 void pieceClicked( int x, int y );
55 /** Emitted when this piece is hovered */
56 void pieceHovered( int x, int y );
57 /** Emitted when this piece is unhovered */
58 void pieceUnhovered( int x, int y );
59 protected:
60 /** Reimplemented for emitting signals if this piece is hovered */
61 virtual void hoverEnterEvent( QGraphicsSceneHoverEvent* event );
62 /** Reimplemented for emitting signals if this piece is unhovered */
63 virtual void hoverLeaveEvent( QGraphicsSceneHoverEvent* event );
64 /** Reimplemented for emitting signals if any mouse click event */
65 virtual void mousePressEvent( QGraphicsSceneMouseEvent* event );
66};
67
68#endif // PIECE_H
69