File indexing completed on 2024-11-03 03:46:55
0001 /* 0002 SPDX-FileCopyrightText: 2010 Ni Hui <shuizhuyuanluo@126.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef PIECE_H 0008 #define PIECE_H 0009 0010 #include <KGameRenderedGraphicsObject> 0011 0012 class QGraphicsLineItem; 0013 class QGraphicsSceneMouseEvent; 0014 /** 0015 * This class represents a single piece on the game scene. 0016 * It emits signals when clicked. 0017 */ 0018 class Piece : public KGameRenderedGraphicsObject 0019 { 0020 Q_OBJECT 0021 public: 0022 /** Constructor */ 0023 explicit Piece( KGameGraphicsViewRenderer* renderer, int x, int y, int color, QGraphicsItem* parent = nullptr ); 0024 /** Destructor */ 0025 ~Piece() override; 0026 /** Reimplemented for using bounding rect for detecting hovering and mouse clicking */ 0027 QPainterPath shape() const override; 0028 /** The current column in the game scene, from left to right, starts from 0 */ 0029 int m_x; 0030 /** The current row in the game scene, from top to bottom, starts from 0 */ 0031 int m_y; 0032 /** The color of the piece */ 0033 const int m_color; 0034 /** The bound line graphics item on the right side */ 0035 QGraphicsLineItem* const m_rightLine; 0036 /** The bound line graphics item on the bottom side */ 0037 QGraphicsLineItem* const m_bottomLine; 0038 /** The highlight graphics item overlapped */ 0039 KGameRenderedGraphicsObject* const m_highlighter; 0040 Q_SIGNALS: 0041 /** Emitted when this piece is clicked */ 0042 void pieceClicked( int x, int y ); 0043 /** Emitted when this piece is hovered */ 0044 void pieceHovered( int x, int y ); 0045 /** Emitted when this piece is unhovered */ 0046 void pieceUnhovered( int x, int y ); 0047 protected: 0048 /** Reimplemented for emitting signals if this piece is hovered */ 0049 void hoverEnterEvent( QGraphicsSceneHoverEvent* event ) override; 0050 /** Reimplemented for emitting signals if this piece is unhovered */ 0051 void hoverLeaveEvent( QGraphicsSceneHoverEvent* event ) override; 0052 /** Reimplemented for emitting signals if any mouse click event */ 0053 void mousePressEvent( QGraphicsSceneMouseEvent* event ) override; 0054 }; 0055 0056 #endif // PIECE_H