File indexing completed on 2025-01-12 03:46:26

0001 /*
0002  *  Copyright (C) 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 KCARD_H
0020 #define KCARD_H
0021 
0022 // own
0023 #include "libkcardgame_export.h"
0024 // Qt
0025 #include <QGraphicsPixmapItem>
0026 #include <QObject>
0027 
0028 class KAbstractCardDeck;
0029 class KCardPile;
0030 
0031 class LIBKCARDGAME_EXPORT KCard : public QObject, public QGraphicsPixmapItem
0032 {
0033     Q_OBJECT
0034 
0035 private:
0036     KCard(quint32 id, KAbstractCardDeck *deck);
0037     virtual ~KCard();
0038 
0039 public:
0040     enum { Type = QGraphicsItem::UserType + 1 };
0041     int type() const override;
0042 
0043     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
0044 
0045     quint32 id() const;
0046     int rank() const;
0047     int suit() const;
0048     int color() const;
0049 
0050     KCardPile *pile() const;
0051 
0052     void setFaceUp(bool faceUp);
0053     bool isFaceUp() const;
0054 
0055     void animate(QPointF pos, qreal z, qreal rotation, bool faceUp, bool raised, int duration);
0056     bool isAnimated() const;
0057 
0058     void raise();
0059 
0060     void setHighlighted(bool highlighted);
0061     bool isHighlighted() const;
0062 
0063     void setFrontPixmap(const QPixmap &pix);
0064     void setBackPixmap(const QPixmap &pix);
0065 
0066 Q_SIGNALS:
0067     void animationStarted(KCard *card);
0068     void animationStopped(KCard *card);
0069 
0070 public Q_SLOTS:
0071     void completeAnimation();
0072     void stopAnimation();
0073 
0074 private:
0075     void setPile(KCardPile *pile);
0076     void setPixmap(const QPixmap &pix);
0077 
0078     class KCardPrivate *const d;
0079 
0080     friend class KCardPrivate;
0081     friend class KAbstractCardDeck;
0082     friend class KCardPile;
0083 };
0084 
0085 #endif