LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CardGroup.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2010-2012 Hewlett-Packard Development Company, L.P.
4 * Copyright (c) 2013 LG Electronics
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * LICENSE@@@ */
19 
20 
21 
22 
23 #ifndef CARDGROUP_H_
24 #define CARDGROUP_H_
25 
26 #include "Common.h"
27 
28 #include <QVector>
29 #include <QList>
30 #include <QEasingCurve>
31 #include <QObject>
32 #include <QPointF>
33 
34 #include "CardWindow.h"
35 
36 QT_BEGIN_NAMESPACE
37 class QPropertyAnimation;
38 QT_END_NAMESPACE
39 
40 class CardGroup : public QObject
41 {
42  Q_OBJECT
43  Q_PROPERTY(QPointF pos READ pos WRITE setPos)
44  Q_PROPERTY(qreal x READ x WRITE setX)
45  Q_PROPERTY(qreal y READ y WRITE setY)
46 
47 public:
48 
49  CardGroup(qreal curScale, qreal nonCurScale);
50  ~CardGroup();
51 
52  // adds an ungrouped card to this group and makes it the active card
53  void addToGroup(CardWindow* c);
54  // removes the card from this group (if grouped) and sets the card
55  // to the left as the new active card
56  void removeFromGroup(CardWindow* c);
57  // adds an ungrouped card to the top of the groups stacking order
58  void addToFront(CardWindow* c);
59  // adds an ungrouped card to the bottom of the groups stacking order
60  void addToBack(CardWindow* c);
61 
62  // raises/lowers the current active card to the next/previous spot
63  // within the group. - direction lowers, + direction raises.
64  // returns whether the move was successful.
65  // NOTE: does not modify the GraphicsScene stacking order, you must
66  // explicitly call raiseCards().
67  bool moveActiveCard(int direction);
68 
69  // raises/lowers the current active card to the next/previous spot
70  // within the group. changes positions if the center point of the active
71  // card, passes the center of another card.
72  bool moveActiveCard();
73 
74  // moves the current position within the group to the next/previous whole
75  // increment. - direction lowers, + direction raises.
76  // returns whether the move was successful.
77  bool moveCurrentPosition(int direction);
78 
79  QList<QPropertyAnimation*> animateOpen(int duration,
80  QEasingCurve::Type curve,
81  bool includeActiveCard=true);
82  QList<QPropertyAnimation*> animateClose(int duration,
83  QEasingCurve::Type curve,
84  bool useGroupPosition=false);
85  // calculate a list of animations for fanning the group based on the
86  // group x offset passed instead of the groups current x offset
87  QList<QPropertyAnimation*> animateCloseWithOffset(int duration,
88  QEasingCurve::Type curve,
89  int groupXOffset);
90 
91  // Sets positions for the group and the cards based on groupXOffset
92  // without creating any animations.
93  void setCardPositions(int groupXOffset);
94 
95  QList<QPropertyAnimation*> maximizeActiveCard(qreal centerOffset);
96 
97  void layoutCards(bool open,bool includeActiveCard);
98 
99  void maximizeActiveCardNoAnimation(qreal centerOffset);
100 
101  // sets the active card that contains scenePt,
102  // returns false if scenePt doesn't fall within a card
103  bool setActiveCard(QPointF scenePt);
104  // sets the active card if card is contained in this group
105  // returns false if the card doesn't belong to this group
106  bool setActiveCard(CardWindow* card);
107 
108  // changes the active card to be the next in the group.
109  // returns false if the active card wasn't changed.
110  bool makeNextCardActive();
111  // changes the active card to be the last card in the group.
112  void makeFrontCardActive();
113 
114  // changes the active card to be the previous in the group.
115  // returns false if the active card wasn't changed.
116  bool makePreviousCardActive();
117  // changes the active card to be the first card in the group.
118  void makeBackCardActive();
119 
120  // move all cards in this group to the top within their parent
121  // preserving stacking order within the group
122  void raiseCards();
123 
124  CardWindow* activeCard() const { return m_activeCard; }
125 
126  int size() const { return m_cards.size(); }
127  bool empty() const { return m_cards.empty(); }
128 
129  // are there any cards to the left/right of the current active card?
130  bool atEdge(qreal direction) const;
131  // shift the current position within the group by some ratio
132  void adjustHorizontally(qreal xDelta);
133  // adjust the current position within the group based on some velocity
134  void flick(int xVelocity);
135 
136  void enableShadows();
137  void disableShadows();
138  void setCompositionMode(QPainter::CompositionMode mode);
139  void resize(int width, int height, QRect normalScreenBounds);
140 
141  // returns the width of the final transformed group
142  int width() const { return m_leftWidth + m_rightWidth; }
143  // returns the width to the left of the groups origin
144  int left() const { return m_leftWidth; }
145  // returns the width to the right of the groups origin
146  int right() const { return m_rightWidth; }
147  // returns true if the pt falls within the column of this group
148  bool withinColumn(const QPointF& pt) const;
149 
150  // updates the center position of the group in parent coordinates
151  QPointF pos() const { return m_pos; }
152  void setPos(const QPointF& pos);
153 
154  qreal x() const { return m_pos.x(); }
155  void setX(const qreal& x);
156 
157  qreal y() const { return m_pos.y(); }
158  void setY(const qreal& y);
159  bool shouldMaximizeOrScroll(QPointF scenePt);
160  bool testHit(QPointF scenePt);
161  void moveToActiveCard();
162 
163  QVector<CardWindow*> cards() const { return m_cards; }
164 private:
165 
166  QVector<CardWindow::Position> calculateOpenedPositions(qreal xOffset = 0.0);
167  QVector<CardWindow::Position> calculateClosedPositions();
168 
169  void clampCurrentPosition();
170 
171  QPointF m_pos;
172  qreal m_curScale;
173  qreal m_nonCurScale;
174  int m_leftWidth;
175  int m_rightWidth;
176  QVector<CardWindow*> m_cards;
177  CardWindow* m_activeCard;
178  int m_cardGroupRotFactor;
179  double m_cardGroupXDistanceFactor;
180  // currentPosition is the position within an open card group.
181  // 0: 1 card is in the center of the group
182  // .5: 2 cards are placed half way from the center of the group
183  // 1: 3-4 cards with the second card being the center of the group
184  // N: >4 cards where valid positions are between 1.0 and N - 4 + 1
185  qreal m_currentPosition;
186 };
187 
188 Q_DECLARE_METATYPE(CardWindow::Position)
189 
190 #endif
191