Changeset View
Changeset View
Standalone View
Standalone View
src/gameremovedtiles.h
- This file was added.
1 | /* Copyright (C) 2019 Christian Krippendorf <Coding@Christian-Krippendorf.de> | ||||
---|---|---|---|---|---|
2 | * | ||||
3 | * Kmahjongg is free software; you can redistribute it and/or modify it under | ||||
4 | * the terms of the GNU General Public License as published by the Free | ||||
5 | * Software Foundation; either version 2 of the License, or (at your option) | ||||
6 | * any later version. | ||||
7 | * | ||||
8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||||
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||||
10 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||||
11 | * details. | ||||
12 | * | ||||
13 | * You should have received a copy of the GNU General Public License along with | ||||
14 | * this program; if not, write to the Free Software Foundation, Inc., 51 | ||||
15 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||||
16 | | ||||
17 | #ifndef GAMEREMOVEDTILES_H | ||||
18 | #define GAMEREMOVEDTILES_H | ||||
19 | | ||||
20 | // Qt | ||||
21 | #include <QGraphicsObject> | ||||
22 | #include <QObject> | ||||
23 | #include <QList> | ||||
24 | | ||||
25 | // KMahjongg | ||||
26 | #include "kmtypes.h" | ||||
27 | | ||||
28 | // Forward declarations | ||||
29 | class KMahjonggTileset; | ||||
30 | class GameData; | ||||
31 | | ||||
32 | | ||||
33 | /** | ||||
34 | * A QGraphicsObject for representing the removed tiles of the current game. | ||||
35 | * @author Christian Krippendorf | ||||
36 | */ | ||||
37 | class GameRemovedTiles : public QGraphicsObject | ||||
38 | { | ||||
39 | Q_OBJECT | ||||
40 | | ||||
41 | public: | ||||
42 | /** | ||||
43 | * Constructor | ||||
44 | * @param item The parent item | ||||
45 | */ | ||||
46 | explicit GameRemovedTiles(QGraphicsObject *item = nullptr); | ||||
47 | ~GameRemovedTiles() override; | ||||
48 | | ||||
49 | /** | ||||
50 | * Overrides the paint method of QGraphicsItem | ||||
51 | */ | ||||
52 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, | ||||
53 | QWidget *widget) override; | ||||
54 | | ||||
55 | /** | ||||
56 | * Set size of element | ||||
57 | * @param width Width of element in pixels | ||||
58 | * @param height Height of element in pixels | ||||
59 | */ | ||||
60 | void setSize(qreal width, qreal height); | ||||
61 | | ||||
62 | /** | ||||
63 | * Overrides the boundingRect method of QGraphicsItem | ||||
64 | */ | ||||
65 | QRectF boundingRect() const override; | ||||
66 | | ||||
67 | /** | ||||
68 | * Returns the rect of the item | ||||
69 | * @return The rect of the item | ||||
70 | */ | ||||
71 | QRectF rect() const; | ||||
72 | | ||||
73 | /** | ||||
74 | * Called in GameView::resizeTileset() before reloading the tiles | ||||
75 | */ | ||||
76 | void prepareForGeometryChange(); | ||||
77 | | ||||
78 | /** | ||||
79 | * Add an removed tile. | ||||
80 | * @param itemPos POSITION object of the item. | ||||
81 | */ | ||||
82 | void addItem(const POSITION & itemPos); | ||||
83 | | ||||
84 | /** | ||||
85 | * Set the game data object. | ||||
86 | * @param gameData the game data object. | ||||
87 | */ | ||||
88 | void setGameData(GameData * gameData); | ||||
89 | | ||||
90 | /** | ||||
91 | * Remove a tile. | ||||
92 | */ | ||||
93 | void removeLastItem(); | ||||
94 | | ||||
95 | /** | ||||
96 | * Set the tileset for the tile pixmaps. | ||||
97 | * @param tiles KMahjonggTileset object. | ||||
98 | */ | ||||
99 | void setTileset(KMahjonggTileset * tiles); | ||||
100 | | ||||
101 | /** | ||||
102 | * Calculate all values that neccessary to paint all tiles. | ||||
103 | */ | ||||
104 | void updateTileCalculations(); | ||||
105 | | ||||
106 | /** | ||||
107 | * Reset system for empty game. | ||||
108 | */ | ||||
109 | void reset(); | ||||
110 | | ||||
111 | /** | ||||
112 | * Remove the last two added tiles. | ||||
113 | */ | ||||
114 | void undo(); | ||||
115 | | ||||
116 | private: | ||||
117 | qreal m_width; | ||||
118 | qreal m_height; | ||||
119 | qreal m_borderWidthFrac; | ||||
120 | qreal m_tileScale; | ||||
121 | qreal m_titleHeightFrac; | ||||
122 | qreal m_borderWidthPixel; | ||||
123 | qreal m_titleHeightPixel; | ||||
124 | qreal m_tileSpaceRow; | ||||
125 | qreal m_tileSpaceCol; | ||||
126 | qreal m_tileFaceWidth; | ||||
127 | qreal m_tileFaceHeight; | ||||
128 | qreal m_faceScale; | ||||
129 | qreal m_tileFaceWidthScaled; | ||||
130 | qreal m_tileFaceHeightScaled; | ||||
131 | unsigned int m_maxTilesRow; | ||||
132 | unsigned int m_maxTilesCol; | ||||
133 | | ||||
134 | QList<USHORT> * m_itemFaces; | ||||
135 | KMahjonggTileset * m_tiles; | ||||
136 | GameData * m_gameData; | ||||
137 | }; | ||||
138 | | ||||
139 | #endif // GAMEREMOVEDTILES_H |