File indexing completed on 2024-03-24 04:05:16
0001 /* 0002 SPDX-FileCopyrightText: 2012 Christian Krippendorf <Coding@Christian-Krippendorf.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef GAMEITEM_H 0008 #define GAMEITEM_H 0009 0010 // Qt 0011 #include <QGraphicsObject> 0012 0013 // KMahjongg 0014 #include "kmtypes.h" 0015 0016 /** 0017 * The tile of a mahjongg board. 0018 * 0019 * @author Christian Krippendorf */ 0020 class GameItem : public QGraphicsObject 0021 { 0022 Q_OBJECT 0023 0024 public: 0025 /** 0026 * Constructor 0027 * 0028 * @param selected Should the item be selected 0029 * @param item The parent item */ 0030 explicit GameItem(bool selected, QGraphicsObject * item = nullptr); 0031 ~GameItem() override; 0032 0033 /** 0034 * Get the actual angle. 0035 * 0036 * @return The angle that is actually set. */ 0037 TileViewAngle getAngle() const; 0038 0039 /** 0040 * Set the items grid position. 0041 * 0042 * @param x The x position. 0043 * @param y The y position. 0044 * @param z The z position. */ 0045 void setGridPos(USHORT x, USHORT y, USHORT z); 0046 0047 /** 0048 * Set the item grid position with the POSITION struct. 0049 * 0050 * @param stPos The POSITION type. */ 0051 void setGridPos(POSITION & stPos); 0052 0053 /** 0054 * Set the face id of the pixmap. 0055 * 0056 * @param faceId The face id to set up. */ 0057 void setFaceId(USHORT faceId); 0058 0059 /** 0060 * Get the face id. 0061 * 0062 * @return The face id.*/ 0063 USHORT getFaceId() const; 0064 0065 /** 0066 * Get the POSITION struct that is actually set. 0067 * 0068 * @return The POSITION struct. */ 0069 POSITION getGridPos() const; 0070 0071 /** 0072 * Get the grid positions. 0073 * 0074 * @return The position value. */ 0075 USHORT getGridPosX() const; 0076 USHORT getGridPosY() const; 0077 USHORT getGridPosZ() const; 0078 0079 /** 0080 * Set the actual angle and therefore all pixmaps related to the angle. 0081 * 0082 * @param angle The angle of the item 0083 * @param unselPix The pixmap for a unselected item 0084 * @param selPix The pixmap for a selected item 0085 * @param shadowWidth The width of the shadow 0086 * @param shadowHeight The height of the shadow */ 0087 void setAngle(TileViewAngle angle, QPixmap * selPix, QPixmap * unselPix, int shadowWidth, 0088 int shadowHeight); 0089 0090 /** 0091 * Set the face of the stone. 0092 * 0093 * @param facePix The pixmap of the face. */ 0094 void setFace(QPixmap * facePix); 0095 0096 /** 0097 * Overrides the paint method of QGraphicsItem. */ 0098 void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, 0099 QWidget * widget) override; 0100 0101 /** 0102 * Overrides the boundingRect method of QGraphicsItem. */ 0103 QRectF boundingRect() const override; 0104 0105 /** 0106 * Returns the rect of the item. 0107 * 0108 * @return The rect of the item. */ 0109 QRectF rect() const; 0110 0111 /** 0112 * Test whether the point is on the shadow or not. 0113 * 0114 * @param position The position where the point is. */ 0115 bool isShadow(QPointF const position) const; 0116 0117 /** 0118 * */ 0119 int getShadowDeltaX() const; 0120 0121 /** 0122 * */ 0123 int getShadowDeltaY() const; 0124 0125 /** 0126 * Called in GameView::resizeTileset() before reloading the tiles. 0127 */ 0128 void prepareForGeometryChange(); 0129 0130 public Q_SLOTS: 0131 /** 0132 * Fade in the item. */ 0133 void fadeIn(); 0134 0135 /** 0136 * Fade out the item. */ 0137 void fadeOut(); 0138 0139 private: 0140 /** 0141 * Updates the angle offset. Cause of 3D items, a shift related to the angle exist. */ 0142 void updateFaceOffset(); 0143 0144 bool m_dying; 0145 int m_shadowWidth; 0146 int m_shadowHeight; 0147 0148 POSITION m_stPos; 0149 0150 TileViewAngle m_angle; 0151 0152 QPixmap * m_selPix; 0153 QPixmap * m_unselPix; 0154 QPixmap * m_facePix; 0155 0156 QPointF m_faceOffset; 0157 }; 0158 0159 #endif // GAMEITEM_H