File indexing completed on 2024-09-01 03:55:02
0001 /* 0002 This file is part of the KDE games lskat program 0003 SPDX-FileCopyrightText: 2006 Martin Heni <kde@heni-online.de> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef ABSTRACT_DISPLAY_H 0009 #define ABSTRACT_DISPLAY_H 0010 0011 // Qt includes 0012 #include <QGraphicsItem> 0013 #include <QGraphicsScene> 0014 #include <QGraphicsView> 0015 #include <QHash> 0016 #include <QList> 0017 0018 // KF includes 0019 #include "lskat_debug.h" 0020 0021 // local includes 0022 0023 // Forward declaration 0024 class Deck; 0025 class CardSprite; 0026 class ThemeManager; 0027 0028 /** 0029 * Abstract display engine. 0030 */ 0031 class AbstractDisplay : public QObject 0032 { 0033 Q_OBJECT 0034 0035 public: 0036 /** 0037 * Constructor for the engine 0038 * @param deck The card deck 0039 * @param scene The graphics scene to work with 0040 * @param theme The theme manager 0041 * @param advancePeriod The advance period [ms] 0042 * @param parent The parent object 0043 */ 0044 AbstractDisplay(Deck *deck, QGraphicsScene *scene, ThemeManager *theme, int advancePeriod, QGraphicsView *parent); 0045 0046 /** 0047 * Destructor. 0048 */ 0049 ~AbstractDisplay() override; 0050 0051 /** 0052 * Set a new deck object. 0053 * @param deck The deck 0054 */ 0055 void setDeck(Deck *deck); 0056 0057 /** 0058 * Reset the display. Clear all sprites etc. 0059 */ 0060 virtual void reset(); 0061 0062 /** 0063 * Start the display. 0064 */ 0065 virtual void start() = 0; 0066 0067 /** 0068 * Play a card on the display. The card is moved from its current position 0069 * to the card deposit. 0070 * @param cardNumber The card number [0-7 ] 0071 * @param playerNumber The player number [0-1] 0072 * @param phase Movement phase (1st part, 2nd part, etc) [optional] 0073 */ 0074 virtual void play(int cardNumber, int playerNumber, int phase) = 0; 0075 0076 /** 0077 * Turn a card on the display. The card is flipped backside 0078 * to frontside. 0079 * @param cardNumber The card number [0-7] 0080 */ 0081 virtual void turn(int cardNumber) = 0; 0082 0083 /** 0084 * Remove the given card from the display. 0085 * @param winnerPosition The position of the winner (0,1) 0086 * @param cardNumber The number of the card 0087 * @param delta Card offset from target position (0,1,2,...) 0088 */ 0089 virtual void remove(int winnerPosition, int cardNumber, int delta) = 0; 0090 0091 /** 0092 * Retrieve the graphics scene of this display. 0093 * @return The QGraphicsScene of this display. 0094 */ 0095 QGraphicsScene *scene() {return mScene;} 0096 0097 public Q_SLOTS: 0098 /** 0099 * Convert the mouse position to a card number for one of the players. 0100 * @param mouse The mouse coordinates [screen coordinates] 0101 * @param playerNumber The resulting player number [0-1] 0102 * @param cardNumber The resulting card number [0-7] 0103 */ 0104 virtual void convertMousePress(const QPoint &mouse, int &playerNumber, int &cardNumber) = 0; 0105 0106 /** 0107 * Load all card sprites. 0108 */ 0109 virtual void createCardSprites(); 0110 0111 protected: 0112 /** The card deck */ 0113 Deck *mDeck; 0114 /** The work canvas */ 0115 QGraphicsScene *mScene; 0116 /** The graphics view */ 0117 QGraphicsView *mView; 0118 /** Canvas advance period [ms]*/ 0119 int mAdvancePeriod; 0120 /** Text sprite list */ 0121 QList<QGraphicsItem *> mSprites; 0122 /** Store the card sprite indexed by the card value */ 0123 static QHash<int, CardSprite *> mCards; 0124 /** Theme manager */ 0125 ThemeManager *mTheme; 0126 }; 0127 0128 #endif