File indexing completed on 2024-06-09 04:03:33
0001 /* 0002 * Copyright (C) 2009-2010 Parker Coates <coates@kde.org> 0003 * 0004 * This program is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU General Public License as 0006 * published by the Free Software Foundation; either version 2 of 0007 * the License, or (at your option) any later version. 0008 * 0009 * This program is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 * GNU General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU General Public License 0015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0016 * 0017 */ 0018 0019 #ifndef KABSTRACTCARDDECK_P_H 0020 #define KABSTRACTCARDDECK_P_H 0021 0022 #include "kabstractcarddeck.h" 0023 // own 0024 #include "kcardtheme.h" 0025 // KF 0026 #include <KImageCache> 0027 // Qt 0028 #include <QHash> 0029 #include <QMutex> 0030 #include <QPixmap> 0031 #include <QSet> 0032 #include <QSizeF> 0033 #include <QStringList> 0034 #include <QThread> 0035 0036 class QSvgRenderer; 0037 class QImage; 0038 0039 class RenderingThread : public QThread 0040 { 0041 Q_OBJECT 0042 0043 public: 0044 RenderingThread(KAbstractCardDeckPrivate *d, QSize size, const QStringList &elements); 0045 void run() override; 0046 void halt(); 0047 0048 Q_SIGNALS: 0049 void renderingDone(const QString &elementId, const QImage &image); 0050 0051 private: 0052 KAbstractCardDeckPrivate *const d; 0053 const QSize m_size; 0054 const QStringList m_elementsToRender; 0055 std::atomic_bool m_haltFlag; 0056 }; 0057 0058 struct CardElementData { 0059 QPixmap cardPixmap; 0060 QList<KCard *> cardUsers; 0061 }; 0062 0063 class KAbstractCardDeckPrivate : public QObject 0064 { 0065 Q_OBJECT 0066 0067 public: 0068 explicit KAbstractCardDeckPrivate(KAbstractCardDeck *q); 0069 ~KAbstractCardDeckPrivate(); 0070 0071 QSvgRenderer *renderer(); 0072 QImage renderCard(const QString &element, const QSize &size); 0073 QSizeF unscaledCardSize(); 0074 QPixmap requestPixmap(quint32 id, bool faceUp); 0075 void updateCardSize(const QSize &size); 0076 void deleteThread(); 0077 0078 public Q_SLOTS: 0079 void submitRendering(const QString &elementId, const QImage &image); 0080 void cardStartedAnimation(KCard *card); 0081 void cardStoppedAnimation(KCard *card); 0082 void checkIfAnimationIsDone(); 0083 0084 public: 0085 KAbstractCardDeck *q; 0086 0087 QSizeF originalCardSize; 0088 QSize currentCardSize; 0089 0090 QList<KCard *> cards; 0091 QSet<KCard *> cardsWaitedFor; 0092 QTimer *animationCheckTimer; 0093 0094 KCardTheme theme; 0095 KImageCache *cache; 0096 QSvgRenderer *svgRenderer; 0097 QMutex rendererMutex; 0098 RenderingThread *thread; 0099 0100 QHash<QString, CardElementData> frontIndex; 0101 QHash<QString, CardElementData> backIndex; 0102 }; 0103 0104 #endif