00001 /* 00002 This file is part of the KDE games lskat program 00003 Copyright (c) 2006 Martin Heni <kde@heni-online.de> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 00021 // Qt includes 00022 00023 // KDE includes 00024 #include <klocale.h> 00025 #include <kdebug.h> 00026 00027 // Local includes 00028 #include "abstractdisplay.h" 00029 #include "deck.h" 00030 #include "cardsprite.h" 00031 #include "textsprite.h" 00032 #include "thememanager.h" 00033 00034 // Define static attributes 00035 QHash<int,CardSprite*> AbstractDisplay::mCards; 00036 00037 // Constructor for the engine 00038 AbstractDisplay::AbstractDisplay(Deck* deck, QGraphicsScene* scene, ThemeManager* theme, 00039 int advancePeriod, QGraphicsView* parent) 00040 : QObject(parent) 00041 { 00042 // Store the scene 00043 mScene = scene; 00044 // Store the view 00045 mView = parent; 00046 // Store advance period 00047 mAdvancePeriod = advancePeriod; 00048 // Store theme manager 00049 mTheme = theme; 00050 00051 // Set up deck 00052 setDeck(deck); 00053 00054 // Initialize sprites 00055 createCardSprites(); 00056 mSprites.clear(); 00057 } 00058 00059 00060 // Destructor. 00061 AbstractDisplay::~AbstractDisplay() 00062 { 00063 while(!mSprites.isEmpty()) 00064 { 00065 QGraphicsItem* item = mSprites.takeFirst(); 00066 item->hide(); 00067 delete item; 00068 } 00069 // Do not delete static cards for performance reasons 00070 } 00071 00072 00073 // Store the deck object for accessing the card deck 00074 void AbstractDisplay::setDeck(Deck* deck) 00075 { 00076 mDeck = deck; 00077 } 00078 00079 00080 // Explicitely reset stored data, e.g. sprites. 00081 void AbstractDisplay::reset() 00082 { 00083 mCards.clear(); 00084 } 00085 00086 00087 // Create all sprites and store them for later access 00088 void AbstractDisplay::createCardSprites() 00089 { 00090 // Only create sprites once (unless explicitly reset) 00091 if (mCards.size() > 0) return; 00092 00093 // Loop all cards 00094 for (int cardNo=0; cardNo<mDeck->cardNumber(); cardNo++) 00095 { 00096 // Create sprite with card correct card image 00097 Suite suite = Suite(cardNo%4); 00098 CardType cardtype = CardType(cardNo/4); 00099 CardSprite* sprite = new CardSprite(suite, cardtype, mTheme, mAdvancePeriod, mScene); 00100 sprite->setBackside(); 00101 // Display sprite 00102 sprite->hide(); 00103 00104 // Store sprite 00105 mCards[cardNo] = sprite; 00106 }// next 00107 } 00108 00109 #include "abstractdisplay.moc"
1.4.6