|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Customized scroll area which handles dynamic slide loading in |
|
15 * unifiedviewer |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "uniscrollarea.h" |
|
20 |
|
21 #include <HbScrollBar> |
|
22 |
|
23 //--------------------------------------------------------------- |
|
24 //UniScrollArea :: UniScrollArea |
|
25 // @see header file |
|
26 //--------------------------------------------------------------- |
|
27 UniScrollArea::UniScrollArea(QGraphicsItem * parent) : |
|
28 HbScrollArea(parent), mCurrentSlide(0), mTotalSlides(0) |
|
29 { |
|
30 bool flag = connect(this, SIGNAL(scrollingEnded()), |
|
31 this, SLOT(handleScrollingEnded())); |
|
32 bool flag1 = connect(this, SIGNAL(scrollingStarted()), |
|
33 this, SLOT(handleScrollingStarted())); |
|
34 |
|
35 } |
|
36 |
|
37 //--------------------------------------------------------------- |
|
38 //UniScrollArea :: ~UniScrollArea |
|
39 // @see header file |
|
40 //--------------------------------------------------------------- |
|
41 UniScrollArea::~UniScrollArea() |
|
42 { |
|
43 |
|
44 } |
|
45 |
|
46 //--------------------------------------------------------------- |
|
47 //UniScrollArea :: setTotalSlides |
|
48 // @see header file |
|
49 //--------------------------------------------------------------- |
|
50 void UniScrollArea::setTotalSlides(int totalSlides) |
|
51 { |
|
52 mTotalSlides = totalSlides; |
|
53 } |
|
54 |
|
55 //--------------------------------------------------------------- |
|
56 //UniScrollArea :: resetCurrentSlide |
|
57 // @see header file |
|
58 //--------------------------------------------------------------- |
|
59 void UniScrollArea::resetCurrentSlide() |
|
60 { |
|
61 mCurrentSlide = 0; |
|
62 } |
|
63 |
|
64 //--------------------------------------------------------------- |
|
65 //UniScrollArea :: handleScrollingEnded |
|
66 // @see header file |
|
67 //--------------------------------------------------------------- |
|
68 void UniScrollArea::handleScrollingEnded() |
|
69 { |
|
70 // TODO : reduce the complexity , code readability |
|
71 // TODO : avoid calculating the heights every time |
|
72 int currentSlide = -1; |
|
73 QList<qreal> heights; |
|
74 heights.clear(); |
|
75 // contents() is not available so replaced with contentWidget() |
|
76 // mScrollEndPoint = this->contents()->pos(); |
|
77 mScrollEndPoint = this->contentWidget()->pos(); |
|
78 // contents() is not available so replaced with contentWidget() |
|
79 QList<QGraphicsItem *> list = this->contentWidget()->childItems(); |
|
80 for (int i = 0; i < list.size(); i++) |
|
81 { |
|
82 QRectF rect = list[i]->boundingRect(); |
|
83 heights.append(- (rect.height())); |
|
84 } |
|
85 |
|
86 qreal h = 0.0; |
|
87 for (int i = 0; i < heights.size(); i++) |
|
88 { |
|
89 h += heights.at(i); |
|
90 if (mScrollEndPoint.y() > h) |
|
91 { |
|
92 currentSlide = i; |
|
93 break; |
|
94 } |
|
95 } |
|
96 |
|
97 if (mScrollEndPoint.y() < mScrollStartPoint.y()) |
|
98 { |
|
99 //Identify if we are in last slide / last but one slide as we always |
|
100 // assume the slide next to current slide is always loaded |
|
101 //(Assumtion is based on slide initial load count of 2) |
|
102 if (currentSlide >= mTotalSlides - 1) |
|
103 { |
|
104 return; |
|
105 } |
|
106 //(This can be removed and emit signal if we cross 50% of last slide) |
|
107 if (currentSlide >= mTotalSlides - 2) |
|
108 { |
|
109 return; |
|
110 } |
|
111 |
|
112 //Determine how much we have scrolled & if we have scrolled beyond 50% |
|
113 //of current slide load the slide next to next slide |
|
114 qreal delta = heights.at(currentSlide) / 2; |
|
115 qreal fh = h - delta; |
|
116 if (mScrollEndPoint.y() < fh) |
|
117 { |
|
118 emit scrolledToNextSlide(); |
|
119 } |
|
120 } |
|
121 |
|
122 } |
|
123 |
|
124 //--------------------------------------------------------------- |
|
125 //UniScrollArea :: handleScrollingStarted |
|
126 // @see header file |
|
127 //--------------------------------------------------------------- |
|
128 void UniScrollArea::handleScrollingStarted() |
|
129 { |
|
130 // contents() is not available so replaced with contentWidget() |
|
131 // mScrollStartPoint = this->contents()->pos(); |
|
132 mScrollStartPoint = this->contentWidget()->pos(); |
|
133 } |
|
134 |
|
135 //--------------------------------------------------------------- |
|
136 //UniScrollArea :: setPosToStart |
|
137 // @see header file |
|
138 //--------------------------------------------------------------- |
|
139 void UniScrollArea::setPosToStart() |
|
140 { |
|
141 // contents() is not available so replaced with contentWidget() |
|
142 QGraphicsItem* widgetItem = this->contentWidget(); |
|
143 widgetItem->setPos(0, 0); |
|
144 } |
|
145 |
|
146 |
|
147 // EOF |