File indexing completed on 2024-05-26 04:08:27

0001 /*
0002  * Copyright (C) 1995 Paul Olav Tvete <paul@troll.no>
0003  * Copyright (C) 2000-2009 Stephan Kulow <coolo@kde.org>
0004  * Copyright (C) 2010 Parker Coates <coates@kde.org>
0005  *
0006  * License of original code:
0007  * -------------------------------------------------------------------------
0008  *   Permission to use, copy, modify, and distribute this software and its
0009  *   documentation for any purpose and without fee is hereby granted,
0010  *   provided that the above copyright notice appear in all copies and that
0011  *   both that copyright notice and this permission notice appear in
0012  *   supporting documentation.
0013  *
0014  *   This file is provided AS IS with no warranties of any kind.  The author
0015  *   shall have no liability with respect to the infringement of copyrights,
0016  *   trade secrets or any patents by this file or any part thereof.  In no
0017  *   event will the author be liable for any lost revenue or profits or
0018  *   other special, indirect and consequential damages.
0019  * -------------------------------------------------------------------------
0020  *
0021  * License of modifications/additions made after 2009-01-01:
0022  * -------------------------------------------------------------------------
0023  *   This program is free software; you can redistribute it and/or
0024  *   modify it under the terms of the GNU General Public License as
0025  *   published by the Free Software Foundation; either version 2 of
0026  *   the License, or (at your option) any later version.
0027  *
0028  *   This program is distributed in the hope that it will be useful,
0029  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0030  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0031  *   GNU General Public License for more details.
0032  *
0033  *   You should have received a copy of the GNU General Public License
0034  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
0035  * -------------------------------------------------------------------------
0036  */
0037 
0038 #ifndef KCARDPILE_H
0039 #define KCARDPILE_H
0040 
0041 // own
0042 #include "kcard.h"
0043 #include "libkcardgame_export.h"
0044 // Qt
0045 #include <QGraphicsPixmapItem>
0046 
0047 class KCardScene;
0048 
0049 class LIBKCARDGAME_EXPORT KCardPile : public QGraphicsObject
0050 {
0051     Q_OBJECT
0052 
0053 public:
0054     explicit KCardPile(KCardScene *cardScene);
0055     virtual ~KCardPile();
0056 
0057     enum { Type = QGraphicsItem::UserType + 2 };
0058     int type() const override;
0059 
0060     QRectF boundingRect() const override;
0061     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
0062 
0063     QList<KCard *> cards() const;
0064     int count() const;
0065     bool isEmpty() const;
0066     int indexOf(const KCard *card) const;
0067     KCard *at(int index) const;
0068     KCard *topCard() const;
0069     QList<KCard *> topCards(int depth) const;
0070     QList<KCard *> topCardsDownTo(const KCard *card) const;
0071 
0072     void setLayoutPos(QPointF pos);
0073     void setLayoutPos(qreal x, qreal y);
0074     QPointF layoutPos() const;
0075 
0076     enum WidthPolicy { FixedWidth, GrowLeft, GrowRight };
0077     void setWidthPolicy(WidthPolicy policy);
0078     WidthPolicy widthPolicy() const;
0079 
0080     enum HeightPolicy { FixedHeight, GrowUp, GrowDown };
0081     void setHeightPolicy(HeightPolicy policy);
0082     HeightPolicy heightPolicy() const;
0083 
0084     void setPadding(qreal topPadding, qreal rightPadding, qreal bottomPadding, qreal leftPadding);
0085     void setTopPadding(qreal padding);
0086     qreal topPadding() const;
0087     void setRightPadding(qreal padding);
0088     qreal rightPadding() const;
0089     void setBottomPadding(qreal padding);
0090     qreal bottomPadding() const;
0091     void setLeftPadding(qreal padding);
0092     qreal leftPadding() const;
0093 
0094     void setSpread(QPointF spread);
0095     void setSpread(qreal width, qreal height);
0096     QPointF spread() const;
0097 
0098     void setAutoTurnTop(bool autoTurnTop);
0099     bool autoTurnTop() const;
0100 
0101     enum KeyboardFocusHint { FreeFocus, AutoFocusTop, AutoFocusDeepestRemovable, AutoFocusDeepestFaceUp, AutoFocusBottom, ForceFocusTop, NeverFocus };
0102 
0103     void setKeyboardSelectHint(KeyboardFocusHint hint);
0104     KeyboardFocusHint keyboardSelectHint() const;
0105     void setKeyboardDropHint(KeyboardFocusHint hint);
0106     KeyboardFocusHint keyboardDropHint() const;
0107 
0108     virtual void setVisible(bool vis);
0109 
0110     void setHighlighted(bool highlighted);
0111     bool isHighlighted() const;
0112 
0113     void add(KCard *card);
0114     virtual void insert(int index, KCard *card);
0115     virtual void remove(KCard *card);
0116     void clear();
0117     void swapCards(int index1, int index2);
0118 
0119     virtual QList<QPointF> cardPositions() const;
0120 
0121 Q_SIGNALS:
0122     void clicked(KCard *card);
0123     void doubleClicked(KCard *card);
0124     void rightClicked(KCard *card);
0125 
0126 protected:
0127     virtual void paintGraphic(QPainter *painter, qreal highlightedness);
0128 
0129 private:
0130     void setGraphicSize(QSize size);
0131 
0132     class KCardPilePrivate *const d;
0133     friend class KCardPilePrivate;
0134     friend class KCardScene;
0135 };
0136 
0137 #endif