1 /*
2  * Copyright (C) 1995 Paul Olav Tvete <paul@troll.no>
3  * Copyright (C) 2000-2009 Stephan Kulow <coolo@kde.org>
4  * Copyright (C) 2010 Parker Coates <coates@kde.org>
5  *
6  * License of original code:
7  * -------------------------------------------------------------------------
8  *   Permission to use, copy, modify, and distribute this software and its
9  *   documentation for any purpose and without fee is hereby granted,
10  *   provided that the above copyright notice appear in all copies and that
11  *   both that copyright notice and this permission notice appear in
12  *   supporting documentation.
13  *
14  *   This file is provided AS IS with no warranties of any kind.  The author
15  *   shall have no liability with respect to the infringement of copyrights,
16  *   trade secrets or any patents by this file or any part thereof.  In no
17  *   event will the author be liable for any lost revenue or profits or
18  *   other special, indirect and consequential damages.
19  * -------------------------------------------------------------------------
20  *
21  * License of modifications/additions made after 2009-01-01:
22  * -------------------------------------------------------------------------
23  *   This program is free software; you can redistribute it and/or
24  *   modify it under the terms of the GNU General Public License as
25  *   published by the Free Software Foundation; either version 2 of
26  *   the License, or (at your option) any later version.
27  *
28  *   This program is distributed in the hope that it will be useful,
29  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
30  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31  *   GNU General Public License for more details.
32  *
33  *   You should have received a copy of the GNU General Public License
34  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
35  * -------------------------------------------------------------------------
36  */
37 
38 #ifndef KCARDPILE_H
39 #define KCARDPILE_H
40 
41 // own
42 #include "kcard.h"
43 #include "libkcardgame_export.h"
44 // Qt
45 #include <QGraphicsPixmapItem>
46 
47 class KCardScene;
48 
49 class LIBKCARDGAME_EXPORT KCardPile : public QGraphicsObject
50 {
51     Q_OBJECT
52 
53 public:
54     explicit KCardPile( KCardScene * cardScene );
55     virtual ~KCardPile();
56 
57     enum { Type = QGraphicsItem::UserType + 2 };
58     int type() const override;
59 
60     QRectF boundingRect() const override;
61     void paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = nullptr ) override;
62 
63     QList<KCard*> cards() const;
64     int count() const;
65     bool isEmpty() const;
66     int indexOf( const KCard * card ) const;
67     KCard * at( int index ) const;
68     KCard * topCard() const;
69     QList<KCard*> topCards( int depth ) const;
70     QList<KCard*> topCardsDownTo( const KCard * card ) const;
71 
72     void setLayoutPos( QPointF pos );
73     void setLayoutPos( qreal x, qreal y );
74     QPointF layoutPos() const;
75 
76     enum WidthPolicy
77     {
78         FixedWidth,
79         GrowLeft,
80         GrowRight
81     };
82     void setWidthPolicy( WidthPolicy policy );
83     WidthPolicy widthPolicy() const;
84 
85     enum HeightPolicy
86     {
87         FixedHeight,
88         GrowUp,
89         GrowDown
90     };
91     void setHeightPolicy( HeightPolicy policy );
92     HeightPolicy heightPolicy() const;
93 
94     void setPadding( qreal topPadding, qreal rightPadding, qreal bottomPadding, qreal leftPadding );
95     void setTopPadding( qreal padding );
96     qreal topPadding() const;
97     void setRightPadding( qreal padding );
98     qreal rightPadding() const;
99     void setBottomPadding( qreal padding );
100     qreal bottomPadding() const;
101     void setLeftPadding( qreal padding );
102     qreal leftPadding() const;
103 
104     void setSpread( QPointF spread );
105     void setSpread( qreal width, qreal height );
106     QPointF spread() const;
107 
108     void setAutoTurnTop( bool autoTurnTop );
109     bool autoTurnTop() const;
110 
111     enum KeyboardFocusHint
112     {
113         FreeFocus,
114         AutoFocusTop,
115         AutoFocusDeepestRemovable,
116         AutoFocusDeepestFaceUp,
117         AutoFocusBottom,
118         ForceFocusTop,
119         NeverFocus
120     };
121 
122     void setKeyboardSelectHint( KeyboardFocusHint hint );
123     KeyboardFocusHint keyboardSelectHint() const;
124     void setKeyboardDropHint( KeyboardFocusHint hint );
125     KeyboardFocusHint keyboardDropHint() const;
126 
127     virtual void setVisible(bool vis);
128 
129     void setHighlighted( bool highlighted );
130     bool isHighlighted() const;
131 
132     void add( KCard * card );
133     virtual void insert( int index, KCard * card );
134     virtual void remove( KCard * card );
135     void clear();
136     void swapCards( int index1, int index2 );
137 
138     virtual QList<QPointF> cardPositions() const;
139 
140 Q_SIGNALS:
141     void clicked( KCard * card );
142     void doubleClicked( KCard * card );
143     void rightClicked( KCard * card );
144 
145 protected:
146     virtual void paintGraphic( QPainter * painter, qreal highlightedness );
147 
148 private:
149     void setGraphicSize( QSize size );
150 
151     class KCardPilePrivate * const d;
152     friend class KCardPilePrivate;
153     friend class KCardScene;
154 };
155 
156 #endif
157