LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
pagetab.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2010-2013 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
18 
19 
20 
21 
22 #ifndef PAGETAB_H_
23 #define PAGETAB_H_
24 
25 #include <QUuid>
26 #include <QRectF>
27 #include <QSize>
28 #include <QSizeF>
29 #include <QFont>
30 #include <QFontMetrics>
31 #include <QPointer>
32 #include <QString>
33 #include <QTimer>
34 #include <QTextLayout>
35 #include <QStaticText>
36 #include <QPointer>
37 #include <QMap>
38 #include <QList>
39 
40 #include "thingpaintable.h"
41 
42 class PageTabBar;
43 class QGraphicsSceneMouseEvent;
44 class QGesture;
45 class QGestureEvent;
46 class QTouchEvent;
47 class QPanGesture;
48 class QSwipeGesture;
49 class QPinchGesture;
50 class QTapAndHoldGesture;
51 class QTapGesture;
52 class FlickGesture;
53 class Page;
54 
55 namespace PageTabDisplayMode
56 {
57  enum Enum
58  {
63  };
64 }
65 
66 class PixmapObject;
67 class PageTab : public ThingPaintable
68 {
69  Q_OBJECT
70  Q_INTERFACES(QGraphicsItem)
71 
72 public:
73 
74  static const char * PropertyNameIndex;
75 
76  friend class PageTabBar;
77 
78  PageTab(const QRectF& pageTabGeometry,const QString& label,PageTabBar * p_belongsTo,Page * p_refersToPage=0);
79  virtual ~PageTab();
80 
81  Page * relatedPage() const;
82 
83  virtual bool testForIntersect(const QPointF& tabBarPositionICS,bool highlight=false);
84  virtual void syntheticTap();
85 
86  virtual quint32 tabIndex() const;
87 
88 public Q_SLOTS:
89 
90  virtual void slotHighlight();
91  virtual void slotUnHighlight();
92 
93 Q_SIGNALS:
94 
95  void signalActivatedTap();
97 
98  void signalSlotHighlighted();
99 
100 protected Q_SLOTS:
101 
102  virtual void slotSetDisplayMode(PageTabDisplayMode::Enum mode);
103 
104  virtual void slotRelatedPageActive();
105  virtual void slotRelatedPageDeactivated();
106 
107  virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
108  virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
109  virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
110 
111  virtual void slotAnimationFinished() {}
112 
113  virtual void slotInteractionsBlocked();
114  virtual void slotInteractionsAllowed();
115 
116 protected:
117 
118  virtual void setTabIndex(quint32 i);
119 
120  virtual void initObjects();
121  virtual void initSignalSlotConnections();
122 
123  virtual PixmapObject * setBackground(PixmapObject * p_new,PageTabDisplayMode::Enum mode, bool makeCurrent=false);
124  virtual QList<PixmapObject *> setBackgrounds(PixmapObject * p_newNormal,
125  PixmapObject * p_newSelected,
126  PixmapObject * p_newHighlighted);
129  virtual void setLeftVerticalDividerVisible(bool visible);
130  virtual void setRightVerticalDividerVisible(bool visible);
131 
132  virtual PixmapObject * setBackgroundShadow(PixmapObject * p_new);
133 
134  virtual bool resize(const QSize& s);
135  virtual bool resize(quint32 newWidth,quint32 newHeight);
136 
137  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option=0,QWidget *widget=0);
138  virtual void paintOffscreen(QPainter *painter);
139 
140  virtual bool touchEvent(QTouchEvent * event) { return true; }
141  virtual bool touchStartEvent(QTouchEvent *event) { return true; }
142  virtual bool touchUpdateEvent(QTouchEvent *event) { return true; }
143  virtual bool touchEndEvent(QTouchEvent *event) { return true; }
144 
145  virtual bool sceneEvent(QEvent * event);
146  virtual bool gestureEvent(QGestureEvent *gestureEvent) { return true; }
147 
148  virtual bool flickGesture(FlickGesture *flickEvent,QGestureEvent * baseGestureEvent);
149  virtual bool tapAndHoldGesture(QTapAndHoldGesture *tapHoldEvent,QGestureEvent * baseGestureEvent);
150  virtual bool tapGesture(QTapGesture *tapEvent,QGestureEvent * baseGestureEvent);
151 
152  // PREREQUISITE: m_geom is valid
153  // RESULT: m_labelMaxGeom is set
155 
156  // PREREQUISITE: m_labelMaxGeom must be valid, at least its size()
157  // RESULT: m_textLayoutObject will have the correct layout, m_labelGeom will be set correctly for the current label,
158  virtual void redoLabelTextLayout(); //run this after the geometry changes. This is absolutely necessary
159  // ALSO run this after the label changes. don't ask, just do it. Not necessary now, but it most likely will be later
160 
161  // PREREQUISITE: m_geom , m_labelMaxGeom and m_labelGeom are set
162  // RESULT: m_labelPosICS and m_labelPosPntCS are set
163  virtual void recalculateLabelPosition();
164 
165 private:
166 
167  QPointer<PageTabBar> m_qp_currentTabBarOwner;
168  QPointer<Page> m_qp_relatedToPage;
169 
170  QRectF m_backgroundGeom;
171  QRectF m_backgroundShadowGeom;
172 
173  QMap<qint32,QPointer<PixmapObject> > m_modeBackgrounds;
174  QPointer<PixmapObject> m_qp_backgroundShadow;
175 
176  PageTabDisplayMode::Enum m_currentMode;
177  PageTabDisplayMode::Enum m_savedMode;
178 
179  bool m_interactionsBlocked;
180  QPointer<PixmapObject> m_currentBackgroundPmo; //keep 'em in sync; it's to avoid a map lookup in paint()
181  bool m_showLeftDivider;
182  bool m_showRightDivider;
183  QPointer<PixmapObject> m_leftDividerPmo;
184  QPointer<PixmapObject> m_rightDividerPmo;
185 
186  QPointF m_leftDividerPosPntCS;
187  QPointF m_rightDividerPosPntCS;
188 
189  QString m_tabLabel;
190  QFont m_textFont;
191  QColor m_selectedColor;
192  QColor m_unselectedColor;
193  QTextLayout m_textLayoutObject;
194  QPointF m_labelPosICS; // position in ICS, and corresponds to m_labelGeom
195  QPoint m_labelPosPntCS; // same, but precomputed to offscreen painter coords relative to 0,0 at top left
196  QRect m_labelMaxGeom; // precomputed by recalculateLabelBoundsForCurrentGeom()
197  QRect m_labelGeom; //precomputed by redoLabelTextLayout(); this one is the CURRENT label's box (always <= m_labelMaxGeom)
198 
199 #if defined TARGET_DESKTOP && (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
200  QPixmap m_textPixmap;
201 #endif
202 };
203 
204 
205 
206 #endif /* PAGETAB_H_ */