1 /*
2  *  Copyright (C) 2009-2010 Parker Coates <coates@kde.org>
3  *
4  *  This program is free software; you can redistribute it and/or
5  *  modify it under the terms of the GNU General Public License as
6  *  published by the Free Software Foundation; either version 2 of
7  *  the License, or (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  *
17  */
18 
19 #ifndef KABSTRACTCARDDECK_P_H
20 #define KABSTRACTCARDDECK_P_H
21 
22 #include "kabstractcarddeck.h"
23 // own
24 #include "kcardtheme.h"
25 // KF
26 #include <KImageCache>
27 // Qt
28 #include <QHash>
29 #include <QMutex>
30 #include <QSet>
31 #include <QSizeF>
32 #include <QStringList>
33 #include <QThread>
34 #include <QPixmap>
35 
36 class QSvgRenderer;
37 class QImage;
38 
39 class RenderingThread : public QThread
40 {
41     Q_OBJECT
42 
43 public:
44     RenderingThread( KAbstractCardDeckPrivate * d, QSize size, const QStringList & elements );
45     void run() override;
46     void halt();
47 
48 Q_SIGNALS:
49     void renderingDone( const QString & elementId, const QImage & image );
50 
51 private:
52     KAbstractCardDeckPrivate * const d;
53     const QSize m_size;
54     const QStringList m_elementsToRender;
55     bool m_haltFlag;
56     QMutex m_haltMutex;
57 };
58 
59 
60 struct CardElementData
61 {
62     QPixmap cardPixmap;
63     QList<KCard*> cardUsers;
64 };
65 
66 
67 class KAbstractCardDeckPrivate : public QObject
68 {
69     Q_OBJECT
70 
71 public:
72     explicit KAbstractCardDeckPrivate( KAbstractCardDeck * q );
73     ~KAbstractCardDeckPrivate();
74 
75     QSvgRenderer * renderer();
76     QImage renderCard( const QString & element, const QSize & size );
77     QSizeF unscaledCardSize();
78     QPixmap requestPixmap( quint32 id, bool faceUp );
79     void updateCardSize( const QSize & size );
80     void deleteThread();
81 
82 public Q_SLOTS:
83     void submitRendering( const QString & elementId, const QImage & image );
84     void cardStartedAnimation( KCard * card );
85     void cardStoppedAnimation( KCard * card );
86     void checkIfAnimationIsDone();
87 
88 
89 public:
90     KAbstractCardDeck * q;
91 
92     QSizeF originalCardSize;
93     QSize currentCardSize;
94 
95     QList<KCard*> cards;
96     QSet<KCard*> cardsWaitedFor;
97     QTimer * animationCheckTimer;
98 
99     KCardTheme theme;
100     KImageCache * cache;
101     QSvgRenderer * svgRenderer;
102     QMutex rendererMutex;
103     RenderingThread * thread;
104 
105     QHash<QString,CardElementData> frontIndex;
106     QHash<QString,CardElementData> backIndex;
107 };
108 
109 #endif
110