1 /* |
1 /* |
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
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 * |
4 * |
9 * Initial Contributors: |
5 * This program is free software: you can redistribute it and/or modify |
10 * Nokia Corporation - initial contribution. |
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, version 2.1 of the License. |
11 * |
8 * |
12 * Contributors: |
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU Lesser General Public License for more details. |
13 * |
13 * |
14 * Description: |
14 * You should have received a copy of the GNU Lesser General Public License |
|
15 * along with this program. If not, |
|
16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
|
17 * |
|
18 * Description: |
|
19 * This class extends ToolbarChromeItem. It paints the toolbar background |
|
20 * and controls toolbar visibility in the content view. |
15 * |
21 * |
16 */ |
22 */ |
17 |
23 |
18 |
|
19 #include "ContentToolbarChromeItem.h" |
24 #include "ContentToolbarChromeItem.h" |
|
25 #include "ChromeItem.h" |
|
26 #include "WebChromeContainerSnippet.h" |
|
27 #include "ContentToolbarSnippet.h" |
20 #include "GWebContentView.h" |
28 #include "GWebContentView.h" |
21 #include "mostvisitedsnippet.h" |
29 #include "mostvisitedsnippet.h" |
|
30 #include "webpagecontroller.h" |
|
31 #include "ViewController.h" |
|
32 #include "ChromeEffect.h" |
|
33 |
22 |
34 |
23 #include <QTimeLine> |
35 #include <QTimeLine> |
24 #include <QDebug> |
36 #include <QDebug> |
25 |
37 |
26 #define TOOLBAR_MARGIN 4 |
38 #define TOOLBAR_MARGIN 4 |
27 #define TOOBAR_ANIMATION_DURATION 200 |
39 #define TOOLBAR_ANIMATION_DURATION 200 |
28 #define TOOBAR_INACTIVITY_DURATION 5000 |
40 #define TOOLBAR_INACTIVITY_DURATION 5000 |
29 |
41 |
30 namespace GVA { |
42 namespace GVA { |
31 |
43 |
32 ToolbarFadeAnimator::ToolbarFadeAnimator(): m_timeLine(NULL) |
44 ToolbarFadeAnimator::ToolbarFadeAnimator(): m_timeLine(NULL) |
33 { |
45 { |
34 } |
46 } |
35 |
47 |
36 |
48 |
37 ToolbarFadeAnimator::~ToolbarFadeAnimator() { |
49 ToolbarFadeAnimator::~ToolbarFadeAnimator() { |
67 //qDebug() << __PRETTY_FUNCTION__ ; |
79 //qDebug() << __PRETTY_FUNCTION__ ; |
68 m_timeLine->stop(); |
80 m_timeLine->stop(); |
69 } |
81 } |
70 |
82 |
71 void ToolbarFadeAnimator::valueChange(qreal step) { |
83 void ToolbarFadeAnimator::valueChange(qreal step) { |
72 qreal value = step - 0.25; |
84 emit updateVisibility(step); |
73 value = (value > 0)? value: 0.0; |
85 } |
74 emit updateVisibility(value); |
86 |
75 } |
87 ContentToolbarChromeItem::ContentToolbarChromeItem(ChromeSnippet* snippet, QGraphicsItem* parent) |
76 |
88 : ToolbarChromeItem(snippet, parent), |
77 ContentToolbarChromeItem::ContentToolbarChromeItem(QGraphicsItem* parent) |
|
78 : ToolbarChromeItem(parent), |
|
79 m_background(NULL), |
89 m_background(NULL), |
80 m_middleSnippet(NULL), |
|
81 m_bgopacity(0.75), |
|
82 m_state(CONTENT_TOOLBAR_STATE_FULL), |
90 m_state(CONTENT_TOOLBAR_STATE_FULL), |
83 m_inactiveTimerState(CONTENT_TOOLBAR_INACTIVITY_TIMER_NONE) |
91 m_autoHideToolbar(true), |
|
92 m_timerState(CONTENT_TOOLBAR_TIMER_STATE_ALLOW) |
84 { |
93 { |
85 |
94 |
86 m_inactivityTimer = new QTimer(this); |
95 m_inactivityTimer = new QTimer(this); |
87 connect(m_inactivityTimer, SIGNAL(timeout()), this, SLOT(onInactivityTimer())); |
96 connect(m_inactivityTimer, SIGNAL(timeout()), this, SLOT(onInactivityTimer())); |
88 |
97 |
89 m_animator = new ToolbarFadeAnimator(); |
98 m_animator = new ToolbarFadeAnimator(); |
90 connect(m_animator, SIGNAL(updateVisibility(qreal)), this, SLOT(onUpdateVisibility(qreal))); |
99 connect(m_animator, SIGNAL(updateVisibility(qreal)), this, SLOT(onUpdateVisibility(qreal))); |
91 connect(m_animator, SIGNAL(finished()), this, SLOT(onAnimFinished())); |
100 connect(m_animator, SIGNAL(finished()), this, SLOT(onAnimFinished())); |
92 |
101 |
|
102 m_maxOpacity = m_bgopacity = opacity(); |
|
103 if (m_autoHideToolbar ) { |
|
104 connect(m_snippet->chrome(), SIGNAL(chromeComplete()), this, SLOT(onChromeComplete())); |
|
105 } |
|
106 |
93 setFlags(QGraphicsItem::ItemDoesntPropagateOpacityToChildren); |
107 setFlags(QGraphicsItem::ItemDoesntPropagateOpacityToChildren); |
94 |
108 |
95 } |
109 } |
96 |
110 |
97 ContentToolbarChromeItem::~ContentToolbarChromeItem() |
111 ContentToolbarChromeItem::~ContentToolbarChromeItem() |
98 { |
112 { |
99 if (m_background ) |
113 if (m_background ) |
100 delete m_background; |
114 delete m_background; |
101 delete m_inactivityTimer; |
115 delete m_inactivityTimer; |
|
116 |
102 delete m_animator; |
117 delete m_animator; |
103 |
118 |
104 } |
119 } |
105 |
120 |
106 void ContentToolbarChromeItem::resizeEvent(QGraphicsSceneResizeEvent * ev) |
121 void ContentToolbarChromeItem::resizeEvent(QGraphicsSceneResizeEvent * ev) |
107 { |
122 { |
108 //qDebug() << __PRETTY_FUNCTION__ << boundingRect(); |
123 //qDebug() << __PRETTY_FUNCTION__ << boundingRect(); |
109 ToolbarChromeItem::resizeEvent(ev); |
124 ToolbarChromeItem::resizeEvent(ev); |
110 addFullBackground(); |
125 addFullBackground(); |
111 |
126 |
|
127 } |
|
128 |
|
129 void ContentToolbarChromeItem::mousePressEvent(QGraphicsSceneMouseEvent * ev) |
|
130 { |
|
131 // If we are not in full state, ignore the event. Once igonre, none of the |
|
132 // other mouse events are received until the next mouse press |
|
133 if (m_state == CONTENT_TOOLBAR_STATE_PARTIAL ) { |
|
134 ev->ignore(); |
|
135 } |
|
136 else { |
|
137 ChromeSnippet * mv = m_snippet->chrome()->getSnippet("MostVisitedViewId"); |
|
138 // Let mostvisited snippet handle the key press if it is visible |
|
139 if (mv && mv->isVisible() ){ |
|
140 ev->ignore(); |
|
141 } |
|
142 } |
|
143 } |
|
144 |
|
145 void ContentToolbarChromeItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * ev) |
|
146 { |
|
147 Q_UNUSED(ev); |
|
148 // Do nothing - prevent the event from trickling down |
|
149 |
112 } |
150 } |
113 |
151 |
114 void ContentToolbarChromeItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* opt, QWidget* widget) |
152 void ContentToolbarChromeItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* opt, QWidget* widget) |
115 { |
153 { |
116 Q_UNUSED(opt) |
154 Q_UNUSED(opt) |
117 Q_UNUSED(widget) |
155 Q_UNUSED(widget) |
118 |
156 |
119 // qDebug() << __PRETTY_FUNCTION__ << m_state; |
157 // qDebug() << __PRETTY_FUNCTION__ << m_state; |
120 painter->save(); |
158 painter->save(); |
121 |
159 |
122 painter->setRenderHint(QPainter::Antialiasing); |
160 painter->setRenderHint(QPainter::Antialiasing); |
123 |
161 |
124 painter->setPen(pen()); |
162 painter->setPen(pen()); |
125 painter->setOpacity(m_bgopacity); |
163 painter->setOpacity(m_bgopacity); |
126 |
164 |
127 switch (m_state) { |
165 switch (m_state) { |
128 case CONTENT_TOOLBAR_STATE_PARTIAL: |
166 case CONTENT_TOOLBAR_STATE_PARTIAL: |
129 ToolbarChromeItem::paint(painter, opt, widget); |
167 ToolbarChromeItem::paint(painter, opt, widget); |
130 break; |
168 break; |
131 case CONTENT_TOOLBAR_STATE_ANIM_TO_FULL: |
169 case CONTENT_TOOLBAR_STATE_ANIM_TO_FULL: |
133 ToolbarChromeItem::paint(painter, opt, widget); |
171 ToolbarChromeItem::paint(painter, opt, widget); |
134 case CONTENT_TOOLBAR_STATE_FULL: |
172 case CONTENT_TOOLBAR_STATE_FULL: |
135 // fill path with color |
173 // fill path with color |
136 painter->fillPath(*m_background,QBrush(grad())); |
174 painter->fillPath(*m_background,QBrush(grad())); |
137 painter->drawPath(*m_background); |
175 painter->drawPath(*m_background); |
|
176 if(m_state == CONTENT_TOOLBAR_STATE_FULL && !isEnabled()) { |
|
177 // Disabled, apply whitewash. |
|
178 ChromeEffect::paintDisabledRect(painter, opt->exposedRect); |
|
179 } |
138 break; |
180 break; |
139 default: |
181 default: |
140 qDebug() << "ContentToolbarChromeItem::paint invalid state" ; |
182 qDebug() << "ContentToolbarChromeItem::paint invalid state" ; |
141 break; |
183 break; |
142 } |
184 } |
143 // restore painter |
185 // restore painter |
144 painter->restore(); |
186 painter->restore(); |
145 |
187 |
146 } |
188 } |
147 |
189 |
148 |
190 |
149 void ContentToolbarChromeItem::setSnippet(WebChromeContainerSnippet* snippet) { |
191 void ContentToolbarChromeItem::setSnippet(ChromeSnippet* snippet) { |
150 |
|
151 //qDebug() << __func__ << snippet; |
|
152 ToolbarChromeItem::setSnippet(snippet); |
192 ToolbarChromeItem::setSnippet(snippet); |
153 |
193 m_maxOpacity = m_bgopacity = opacity(); |
154 connect(snippet->chrome(), SIGNAL(chromeComplete()), this, SLOT(onChromeComplete())); |
|
155 connect(snippet, SIGNAL(snippetMouseEvent(QEvent::Type)), this, SLOT(onSnippetMouseEvent(QEvent::Type))); |
|
156 |
194 |
157 } |
195 if (m_autoHideToolbar ) { |
158 |
196 connect(snippet->chrome(), SIGNAL(chromeComplete()), this, SLOT(onChromeComplete())); |
159 void ContentToolbarChromeItem::onWebViewMouseEvents(QEvent::Type type) { |
197 } |
160 |
198 |
161 // qDebug() << __PRETTY_FUNCTION__ << type; |
199 } |
162 switch (type ) { |
200 |
163 case QEvent::GraphicsSceneMousePress: |
201 void ContentToolbarChromeItem::onChromeComplete() { |
164 case QEvent::GraphicsSceneMouseDoubleClick: |
202 |
165 handleMousePress(); |
203 GWebContentView* webView = static_cast<GWebContentView*> (m_snippet->chrome()->getView("WebView")); |
166 break; |
204 //qDebug() << __PRETTY_FUNCTION__ << webView; |
167 case QEvent::GraphicsSceneMouseRelease: |
205 if (webView ) { |
168 handleMouseRelease(); |
206 connect(webView, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); |
169 break; |
207 connect(webView, SIGNAL(loadStarted()), this, SLOT(onLoadStarted())); |
170 default: |
208 #ifdef BEDROCK_TILED_BACKING_STORE |
171 break; |
209 connect(webView, SIGNAL(contextEvent(::WebViewEventContext *)), this, SLOT(resetTimer())); |
172 |
210 #else |
173 } |
211 connect(webView->widget(), SIGNAL(contextEvent(::WebViewEventContext *)), this, SLOT(resetTimer())); |
174 |
212 #endif |
|
213 } |
|
214 |
|
215 } |
|
216 |
|
217 void ContentToolbarChromeItem::onLoadStarted() { |
|
218 |
|
219 m_timerState = CONTENT_TOOLBAR_TIMER_STATE_ALLOW; |
|
220 stopInactivityTimer(); |
|
221 } |
|
222 |
|
223 |
|
224 void ContentToolbarChromeItem::onLoadFinished(bool ok) { |
|
225 |
|
226 Q_UNUSED(ok); |
|
227 //qDebug() << __PRETTY_FUNCTION__ << m_state << "Timer Allowed" << m_timerState; |
|
228 |
|
229 if (m_autoHideToolbar && m_timerState == CONTENT_TOOLBAR_TIMER_STATE_ALLOW) { |
|
230 ControllableViewBase* curView = m_snippet->chrome()->viewController()->currentView(); |
|
231 if (curView && curView->type() == "webView") { |
|
232 GWebContentView * gView = qobject_cast<GWebContentView*> (curView); |
|
233 bool isSuperPage = gView ? gView->currentPageIsSuperPage() : false; |
|
234 |
|
235 // Start inactivity timer if full toolbar is visible |
|
236 if (!isSuperPage && m_state == CONTENT_TOOLBAR_STATE_FULL ) |
|
237 m_inactivityTimer->start(TOOLBAR_INACTIVITY_DURATION); |
|
238 } |
|
239 } |
|
240 |
|
241 } |
|
242 void ContentToolbarChromeItem::resetTimer() { |
|
243 |
|
244 m_timerState = CONTENT_TOOLBAR_TIMER_STATE_NONE; |
|
245 stopInactivityTimer(); |
|
246 } |
|
247 |
|
248 void ContentToolbarChromeItem::stopInactivityTimer() { |
|
249 |
|
250 //qDebug() << __PRETTY_FUNCTION__<< m_state << " Timer Active: " << m_inactivityTimer->isActive(); |
|
251 // Stop inactivity timer |
|
252 if (m_inactivityTimer->isActive() ) |
|
253 m_inactivityTimer->stop(); |
|
254 |
|
255 } |
|
256 |
|
257 void ContentToolbarChromeItem::onInactivityTimer() { |
|
258 |
|
259 //qDebug() << __PRETTY_FUNCTION__ << m_state; |
|
260 |
|
261 //We are here because inactivity timer timed out. So we have to be in full toolbar state with no |
|
262 // popups. So change fade to Partial state after stopping inactivity timer |
|
263 m_inactivityTimer->stop(); |
|
264 changeState(CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL, true); |
175 } |
265 } |
176 |
266 |
177 void ContentToolbarChromeItem::onSnippetMouseEvent( QEvent::Type type) { |
267 void ContentToolbarChromeItem::onSnippetMouseEvent( QEvent::Type type) { |
178 |
268 |
179 |
269 //qDebug() << __PRETTY_FUNCTION__ << type ; |
180 // qDebug() << __PRETTY_FUNCTION__ << type; |
270 |
181 // Handle the snippet mouse events when we are in webview |
271 if (type == QEvent::MouseButtonPress || type == QEvent::GraphicsSceneMousePress) { |
182 if ( getSnippet()->chrome()->currentView() == "webView") { |
272 resetTimer(); |
183 |
273 } |
184 if (type == QEvent::MouseButtonPress || type == QEvent::GraphicsSceneMousePress) { |
274 } |
185 |
275 |
186 m_inactiveTimerState = CONTENT_TOOLBAR_INACTIVITY_TIMER_NONE; |
276 void ContentToolbarChromeItem::addLinkedChild(ChromeSnippet * s) { |
187 switch (m_state) { |
277 m_linkedChildren.append(s); |
188 case CONTENT_TOOLBAR_STATE_PARTIAL: |
278 } |
|
279 |
|
280 void ContentToolbarChromeItem::toggleMiddleSnippet() { |
|
281 //qDebug() << "TOGGLE MIDDLE : " << m_state; |
|
282 switch (m_state) { |
|
283 case CONTENT_TOOLBAR_STATE_PARTIAL: |
189 changeState(CONTENT_TOOLBAR_STATE_ANIM_TO_FULL); |
284 changeState(CONTENT_TOOLBAR_STATE_ANIM_TO_FULL); |
190 break; |
285 break; |
191 case CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL: |
286 case CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL: |
192 // Stop animation and change to full immediately |
287 // Stop animation and change to full immediately |
193 m_animator->stop(); |
288 m_animator->stop(); |
196 case CONTENT_TOOLBAR_STATE_ANIM_TO_FULL: |
291 case CONTENT_TOOLBAR_STATE_ANIM_TO_FULL: |
197 // Do nothing here - will reset inactivity timer when |
292 // Do nothing here - will reset inactivity timer when |
198 // animation completes |
293 // animation completes |
199 break; |
294 break; |
200 case CONTENT_TOOLBAR_STATE_FULL: |
295 case CONTENT_TOOLBAR_STATE_FULL: |
201 resetInactivityTimer(); |
296 // if MV is active then wait for it to hide before changing the toolbar state |
|
297 if (mvSnippetVisible()) { |
|
298 changeState(CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL, false); |
|
299 } |
|
300 else { |
|
301 changeState(CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL, true); |
|
302 } |
202 break; |
303 break; |
203 default: |
304 default: |
204 break; |
305 break; |
205 |
|
206 } |
306 } |
207 } |
|
208 else if ( type == QEvent::MouseButtonRelease || type == QEvent::GraphicsSceneMouseRelease){ |
|
209 m_inactiveTimerState = CONTENT_TOOLBAR_INACTIVITY_TIMER_ALLOWED; |
|
210 if (m_state == CONTENT_TOOLBAR_STATE_FULL ){ |
|
211 resetInactivityTimer(); |
|
212 } |
|
213 } |
|
214 } |
|
215 } |
|
216 |
|
217 void ContentToolbarChromeItem::onChromeComplete() { |
|
218 |
|
219 GWebContentView* webView = static_cast<GWebContentView*> (getSnippet()->chrome()->getView("WebView")); |
|
220 //qDebug() << __PRETTY_FUNCTION__ << webView; |
|
221 if(webView){ |
|
222 connect(webView, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); |
|
223 connect(webView, SIGNAL(loadStarted()), this, SLOT(onLoadStarted())); |
|
224 connect(webView, SIGNAL(contentViewMouseEvent(QEvent::Type)) , this, SLOT(onWebViewMouseEvents(QEvent::Type)) ); |
|
225 } |
|
226 // Get the middle snippet here for now |
|
227 m_middleSnippet = getSnippet()->chrome()->getSnippet("ButtonContainer"); |
|
228 connect(m_middleSnippet, SIGNAL(snippetMouseEvent(QEvent::Type)), this, SLOT(onSnippetMouseEvent(QEvent::Type))); |
|
229 QList <ChromeSnippet *> links = getSnippet()->links(); |
|
230 for (int i=0; i < links.count() ; i++) { |
|
231 |
|
232 connect(links.at(i), SIGNAL(snippetMouseEvent(QEvent::Type)), this, SLOT(onSnippetMouseEvent(QEvent::Type))); |
|
233 |
|
234 } |
|
235 |
|
236 // Connect to shown and hidden signals to reset the inactivity timer |
|
237 connect(getSnippet() , SIGNAL(shown()), this, SLOT(onSnippetHide())); |
|
238 connect(getSnippet() , SIGNAL(hidden()), this, SLOT(onSnippetShow())); |
|
239 } |
|
240 |
|
241 void ContentToolbarChromeItem::onSnippetShow() { |
|
242 |
|
243 // This is signal is received when the snippet is about to be hidden. So stop the timer |
|
244 //qDebug() << __PRETTY_FUNCTION__; |
|
245 if (m_inactivityTimer->isActive() ) |
|
246 m_inactivityTimer->stop(); |
|
247 } |
|
248 |
|
249 void ContentToolbarChromeItem::onSnippetHide() { |
|
250 |
|
251 //qDebug() << __PRETTY_FUNCTION__; |
|
252 changeState(CONTENT_TOOLBAR_STATE_FULL, false); |
|
253 } |
307 } |
254 |
308 |
255 void ContentToolbarChromeItem::onMVCloseComplete() { |
309 void ContentToolbarChromeItem::onMVCloseComplete() { |
256 |
310 |
257 // qDebug() << __PRETTY_FUNCTION__; |
311 // qDebug() << __PRETTY_FUNCTION__; |
258 ChromeSnippet * mv = getSnippet()->chrome()->getSnippet("MostVisitedViewId"); |
312 ChromeSnippet * mv = m_snippet->chrome()->getSnippet("MostVisitedViewId"); |
259 disconnect(mv, SIGNAL(mostVisitedSnippetCloseComplete()) , this, SLOT(onMVCloseComplete())); |
313 disconnect(mv, SIGNAL(mostVisitedSnippetCloseComplete()) , this, SLOT(onMVCloseComplete())); |
260 // MostVisitedSnippet animation complete, so let's do toolbar animation |
314 // MostVisitedSnippet animation complete, so let's do toolbar animation |
261 if (m_state == CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL) |
315 if (m_state == CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL) |
262 changeState(CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL, true); |
316 changeState(CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL, true); |
263 |
317 |
264 } |
318 } |
265 |
319 |
266 void ContentToolbarChromeItem::onLoadFinished(bool ok) { |
320 void ContentToolbarChromeItem::onUpdateVisibility(qreal step) { |
267 |
321 |
268 Q_UNUSED(ok); |
322 //qDebug() << __PRETTY_FUNCTION__ << step << m_bgopacity << opacity(); |
|
323 // Value we get is 1.0 based, adjust it based on our max opacity |
|
324 qreal value = step - (1.0 - m_maxOpacity); |
|
325 value = (value > 0)? value: 0.0; |
|
326 |
|
327 if (m_bgopacity != value ) { |
|
328 m_bgopacity = value; |
|
329 setOpacity(m_maxOpacity - value); |
|
330 ContentToolbarSnippet * s = static_cast<ContentToolbarSnippet*>(m_snippet); |
|
331 s->middleSnippet()->widget()->setOpacity(value); |
|
332 update(); |
|
333 } |
|
334 } |
|
335 |
|
336 void ContentToolbarChromeItem::onAnimFinished() { |
|
337 |
|
338 ContentToolbarState state = CONTENT_TOOLBAR_STATE_INVALID; |
|
339 bool animate = false; |
269 //qDebug() << __PRETTY_FUNCTION__ << m_state; |
340 //qDebug() << __PRETTY_FUNCTION__ << m_state; |
270 |
|
271 // We should be in STATE_FULL when load completes as we would have |
|
272 // changed to that state on starting a load |
|
273 //assert(m_state == CONTENT_TOOLBAR_STATE_FULL) |
|
274 m_inactiveTimerState = CONTENT_TOOLBAR_INACTIVITY_TIMER_ALLOWED; |
|
275 resetInactivityTimer(); |
|
276 |
|
277 } |
|
278 |
|
279 void ContentToolbarChromeItem::onLoadStarted() { |
|
280 |
|
281 //qDebug() << __PRETTY_FUNCTION__<< m_state; ; |
|
282 m_inactiveTimerState = CONTENT_TOOLBAR_INACTIVITY_TIMER_NONE; |
|
283 |
|
284 switch (m_state) { |
|
285 case CONTENT_TOOLBAR_STATE_PARTIAL: |
|
286 changeState(CONTENT_TOOLBAR_STATE_FULL, false); |
|
287 break; |
|
288 case CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL: |
|
289 case CONTENT_TOOLBAR_STATE_ANIM_TO_FULL: |
|
290 // Stop animation and change to full immediately |
|
291 m_animator->stop(); |
|
292 changeState(CONTENT_TOOLBAR_STATE_FULL, false); |
|
293 break; |
|
294 case CONTENT_TOOLBAR_STATE_FULL: |
|
295 resetInactivityTimer(); |
|
296 break; |
|
297 default: |
|
298 break; |
|
299 |
|
300 } |
|
301 //qDebug() << __PRETTY_FUNCTION__<< m_state; ; |
|
302 |
|
303 } |
|
304 |
|
305 void ContentToolbarChromeItem::onInactivityTimer() { |
|
306 |
|
307 //assert(m_state == CONTENT_TOOLBAR_STATE_PARTIAL); |
|
308 //qDebug() << __PRETTY_FUNCTION__ << m_state; |
|
309 if (mvSnippetVisible()) { |
|
310 changeState(CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL); |
|
311 |
|
312 } |
|
313 else { |
|
314 changeState(CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL, true); |
|
315 } |
|
316 } |
|
317 |
|
318 void ContentToolbarChromeItem::onUpdateVisibility(qreal step) { |
|
319 |
|
320 qreal value = 0.76 - step; |
|
321 //qDebug() << __PRETTY_FUNCTION__ << step << value << m_bgopacity << opacity(); |
|
322 if (m_bgopacity != step ) { |
|
323 m_bgopacity = step; |
|
324 getSnippet()->setOpacity(value); |
|
325 m_middleSnippet->widget()->setOpacity(step); |
|
326 update(); |
|
327 } |
|
328 } |
|
329 |
|
330 void ContentToolbarChromeItem::onAnimFinished() { |
|
331 |
|
332 //qDebug() << __PRETTY_FUNCTION__ << m_state; |
|
333 switch (m_state) { |
341 switch (m_state) { |
334 case CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL: |
342 case CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL: |
335 changeState(CONTENT_TOOLBAR_STATE_PARTIAL); |
343 state = CONTENT_TOOLBAR_STATE_PARTIAL; |
336 break; |
344 break; |
337 case CONTENT_TOOLBAR_STATE_ANIM_TO_FULL: |
345 case CONTENT_TOOLBAR_STATE_ANIM_TO_FULL: |
338 changeState(CONTENT_TOOLBAR_STATE_FULL, true); |
346 state = CONTENT_TOOLBAR_STATE_FULL; |
|
347 animate = true; |
339 break; |
348 break; |
340 default: |
349 default: |
341 break; |
350 break; |
|
351 |
|
352 } |
342 |
353 |
343 } |
354 ContentToolbarSnippet * s = static_cast<ContentToolbarSnippet*>(m_snippet); |
344 //qDebug() << __PRETTY_FUNCTION__ << m_state; |
355 s->handleToolbarStateChange(state); |
345 |
356 changeState(state, animate); |
|
357 //qDebug() << __PRETTY_FUNCTION__ << m_state; |
|
358 |
346 } |
359 } |
347 void ContentToolbarChromeItem::addFullBackground() { |
360 void ContentToolbarChromeItem::addFullBackground() { |
348 |
361 |
349 //qDebug() << __PRETTY_FUNCTION__ ; |
362 //qDebug() << __PRETTY_FUNCTION__ ; |
350 qreal roundness((boundingRect().height() -TOOLBAR_MARGIN)/2); |
363 qreal roundness((boundingRect().height() -TOOLBAR_MARGIN)/2); |
356 } |
369 } |
357 m_background = new QPainterPath(); |
370 m_background = new QPainterPath(); |
358 m_background->addRoundedRect(r, roundness, roundness); |
371 m_background->addRoundedRect(r, roundness, roundness); |
359 } |
372 } |
360 |
373 |
361 void ContentToolbarChromeItem::resetInactivityTimer() { |
|
362 |
|
363 // qDebug() << __PRETTY_FUNCTION__ << m_inactiveTimerState; |
|
364 if (m_inactivityTimer->isActive() ) |
|
365 m_inactivityTimer->stop(); |
|
366 if (m_inactiveTimerState == CONTENT_TOOLBAR_INACTIVITY_TIMER_ALLOWED ) { |
|
367 m_inactivityTimer->start(TOOBAR_INACTIVITY_DURATION); |
|
368 } |
|
369 } |
|
370 |
|
371 void ContentToolbarChromeItem::stateEnterFull(bool animate) { |
374 void ContentToolbarChromeItem::stateEnterFull(bool animate) { |
372 |
375 |
373 //qDebug() <<__PRETTY_FUNCTION__ ; |
376 //qDebug() <<__PRETTY_FUNCTION__ ; |
374 |
377 ContentToolbarSnippet * s = static_cast<ContentToolbarSnippet*>(m_snippet); |
375 resetInactivityTimer(); |
378 |
376 // Show the middle snippet and reset the opacity if we are here directly with no aniamtion |
379 // Show the middle snippet and reset the opacity if we are here directly with no aniamtion |
377 if (!animate) { |
380 if (!animate) { |
378 m_bgopacity = 0.75; |
381 m_bgopacity = 0.75; |
379 m_middleSnippet->show(); |
382 s->middleSnippet()->show(); |
380 } |
383 } |
381 |
384 |
382 m_state = CONTENT_TOOLBAR_STATE_FULL; |
385 m_state = CONTENT_TOOLBAR_STATE_FULL; |
383 m_middleSnippet->widget()->setOpacity(1.0); |
386 s->middleSnippet()->widget()->setOpacity(1.0); |
384 // TODO: specify the rect to be updated to avoid full repaint |
387 // TODO: specify the rect to be updated to avoid full repaint |
385 update(); |
388 update(); |
386 } |
389 } |
387 |
390 |
388 void ContentToolbarChromeItem::stateEnterPartial(bool animate) { |
391 void ContentToolbarChromeItem::stateEnterPartial(bool animate) { |
389 |
392 |
390 //qDebug() <<__PRETTY_FUNCTION__ ; |
393 //qDebug() <<__PRETTY_FUNCTION__ ; |
391 Q_UNUSED(animate); |
394 Q_UNUSED(animate); |
|
395 ContentToolbarSnippet * s = static_cast<ContentToolbarSnippet*>(m_snippet); |
392 |
396 |
393 // Explicity hide the linked snippets so that toggle button javascript gets the right |
397 // Explicity hide the linked snippets so that toggle button javascript gets the right |
394 // signals that it is expecting |
398 // signals that it is expecting |
395 QList <ChromeSnippet *> links = getSnippet()->links(); |
399 hideLinkedChildren(); |
396 for (int i=0; i < links.count() ; i++) { |
400 |
397 //qDebug() << __PRETTY_FUNCTION__ << links.at(i)->elementId(); |
401 s->middleSnippet()->hide(); |
398 links.at(i)->hide(); |
|
399 } |
|
400 |
|
401 m_middleSnippet->hide(); |
|
402 m_state = CONTENT_TOOLBAR_STATE_PARTIAL; |
402 m_state = CONTENT_TOOLBAR_STATE_PARTIAL; |
403 |
403 |
404 } |
404 } |
405 |
405 |
406 void ContentToolbarChromeItem::stateEnterAnimToFull(bool animate) { |
406 void ContentToolbarChromeItem::stateEnterAnimToFull(bool animate) { |
407 |
407 |
408 //qDebug() <<__PRETTY_FUNCTION__ ; |
408 //qDebug() <<__PRETTY_FUNCTION__ ; |
409 Q_UNUSED(animate); |
409 Q_UNUSED(animate); |
|
410 ContentToolbarSnippet * s = static_cast<ContentToolbarSnippet*>(m_snippet); |
|
411 |
410 m_state = CONTENT_TOOLBAR_STATE_ANIM_TO_FULL; |
412 m_state = CONTENT_TOOLBAR_STATE_ANIM_TO_FULL; |
411 m_inactivityTimer->stop(); |
413 s->middleSnippet()->show(); |
412 m_middleSnippet->show(); |
|
413 m_animator->start(false); |
414 m_animator->start(false); |
414 |
415 |
415 } |
416 } |
416 |
417 |
417 void ContentToolbarChromeItem::stateEnterAnimToPartial(bool animate) { |
418 void ContentToolbarChromeItem::stateEnterAnimToPartial(bool animate) { |
418 |
|
419 //qDebug() <<__PRETTY_FUNCTION__ << animate ; |
|
420 m_inactivityTimer->stop(); |
|
421 m_state = CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL; |
419 m_state = CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL; |
422 |
420 |
423 if (animate ) { |
421 if (animate ) { |
424 m_animator->start(true); |
422 m_animator->start(true); |
425 } |
423 } |
426 else { |
424 else { |
427 |
425 |
428 MostVisitedSnippet * mv = static_cast<MostVisitedSnippet *>(getSnippet()->chrome()->getSnippet("MostVisitedViewId")); |
426 MostVisitedSnippet * mv = static_cast<MostVisitedSnippet *>(m_snippet->chrome()->getSnippet("MostVisitedViewId")); |
429 connect(mv, SIGNAL(mostVisitedSnippetCloseComplete()) , this, SLOT(onMVCloseComplete())); |
427 connect(mv, SIGNAL(mostVisitedSnippetCloseComplete()) , this, SLOT(onMVCloseComplete())); |
430 mv->close(); |
428 mv->close(); |
431 } |
429 } |
432 |
430 |
433 } |
431 } |
434 |
432 |
435 void ContentToolbarChromeItem::changeState( ContentToolbarState state, bool animate){ |
433 void ContentToolbarChromeItem::changeState( ContentToolbarState state, bool animate){ |
436 |
434 |
437 onStateEntry(state, animate); |
435 onStateEntry(state, animate); |
457 qDebug() << "ContentToolbarChromeItem::onStateEntry - invalid state" ; |
455 qDebug() << "ContentToolbarChromeItem::onStateEntry - invalid state" ; |
458 break; |
456 break; |
459 } |
457 } |
460 } |
458 } |
461 |
459 |
462 void ContentToolbarChromeItem::onStateExit(ContentToolbarState state){ |
|
463 |
|
464 //qDebug() << __PRETTY_FUNCTION__ ; |
|
465 switch (state) { |
|
466 case CONTENT_TOOLBAR_STATE_PARTIAL: |
|
467 break; |
|
468 case CONTENT_TOOLBAR_STATE_ANIM_TO_FULL: |
|
469 break; |
|
470 case CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL: |
|
471 break; |
|
472 case CONTENT_TOOLBAR_STATE_FULL: |
|
473 break; |
|
474 default: |
|
475 qDebug() << "ContentToolbarChromeItem::onStateExit - invalid state" ; |
|
476 break; |
|
477 } |
|
478 } |
|
479 |
|
480 void ContentToolbarChromeItem::handleMousePress() { |
|
481 |
|
482 // qDebug() << __PRETTY_FUNCTION__ << m_state; |
|
483 m_inactiveTimerState = CONTENT_TOOLBAR_INACTIVITY_TIMER_NONE; |
|
484 switch (m_state) { |
|
485 case CONTENT_TOOLBAR_STATE_PARTIAL: |
|
486 changeState(CONTENT_TOOLBAR_STATE_ANIM_TO_FULL); |
|
487 break; |
|
488 case CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL: |
|
489 // Stop animation and change to full immediately |
|
490 m_animator->stop(); |
|
491 changeState(CONTENT_TOOLBAR_STATE_FULL, false); |
|
492 break; |
|
493 case CONTENT_TOOLBAR_STATE_ANIM_TO_FULL: |
|
494 // Do nothing here - will reset inactivity timer when |
|
495 // animation completes based on timer state then |
|
496 break; |
|
497 case CONTENT_TOOLBAR_STATE_FULL: |
|
498 resetInactivityTimer(); |
|
499 break; |
|
500 default: |
|
501 qDebug() << "ContentToolbarChromeItem::handleMousePress invalid state" ; |
|
502 break; |
|
503 |
|
504 } |
|
505 |
|
506 |
|
507 } |
|
508 |
|
509 void ContentToolbarChromeItem::handleMouseRelease() { |
|
510 |
|
511 // qDebug() << __PRETTY_FUNCTION__ << m_state; |
|
512 /* If in STATE_FULL, restart inactivity timer. In other states: |
|
513 * STATE_PARTIAL, STATE_ANIM_TO_PARTIAL - not possible |
|
514 * STATE_ANIM_TO_FULL - timer will be restarted on animation completion |
|
515 */ |
|
516 |
|
517 m_inactiveTimerState = CONTENT_TOOLBAR_INACTIVITY_TIMER_ALLOWED; |
|
518 if (m_state == CONTENT_TOOLBAR_STATE_FULL ){ |
|
519 resetInactivityTimer(); |
|
520 } |
|
521 } |
|
522 |
|
523 bool ContentToolbarChromeItem::mvSnippetVisible() { |
460 bool ContentToolbarChromeItem::mvSnippetVisible() { |
524 |
461 |
525 ChromeSnippet * mv = getSnippet()->chrome()->getSnippet("MostVisitedViewId"); |
462 ChromeSnippet * mv = m_snippet->chrome()->getSnippet("MostVisitedViewId"); |
526 bool result = false; |
463 bool result = false; |
527 |
464 |
528 if (mv && mv->isVisible() ) { |
465 if (mv && mv->isVisible() ) { |
529 result = true; |
466 result = true; |
530 } |
467 } |
531 return result; |
468 return result; |
532 } |
469 } |
533 |
470 |
534 /* |
471 void ContentToolbarChromeItem::hideLinkedChildren() { |
535 //Not using this method now - potential performance hit |
472 |
536 void ContentToolbarChromeItem::changeState( ContentToolbarState state, bool animate){ |
473 for (int i=0; i < m_linkedChildren.count() ; i++) { |
537 |
474 |
538 if ( m_states[m_state].exitFunc ) { |
475 m_linkedChildren.at(i)->hide(); |
539 |
476 } |
540 (*this.*(m_states[m_state].exitFunc))(); |
477 } |
541 } |
|
542 if ( m_states[state].enterFunc ) { |
|
543 (*this.*(m_states[state].enterFunc))(animate); |
|
544 |
|
545 } |
|
546 |
|
547 } |
|
548 |
|
549 void ContentToolbarChromeItem::initStates() { |
|
550 |
|
551 |
|
552 m_states[CONTENT_TOOLBAR_STATE_FULL].enterFunc = &ContentToolbarChromeItem::stateEnterFull; |
|
553 m_states[CONTENT_TOOLBAR_STATE_FULL].exitFunc = NULL; |
|
554 |
|
555 m_states[CONTENT_TOOLBAR_STATE_PARTIAL].enterFunc = &ContentToolbarChromeItem::stateEnterpartial; |
|
556 m_states[CONTENT_TOOLBAR_STATE_PARTIAL].exitFunc = NULL; |
|
557 |
|
558 m_states[CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL].enterFunc = &ContentToolbarChromeItem::stateEnterAnimToPartial; |
|
559 m_states[CONTENT_TOOLBAR_STATE_ANIM_TO_PARTIAL].exitFunc = NULL; |
|
560 |
|
561 m_states[CONTENT_TOOLBAR_STATE_ANIM_TO_FULL].enterFunc = &ContentToolbarChromeItem::stateEnterAnimToFull; |
|
562 m_states[CONTENT_TOOLBAR_STATE_ANIM_TO_FULL].exitFunc = NULL; |
|
563 } |
|
564 */ |
|
565 } // end of namespace GVA |
478 } // end of namespace GVA |
566 |
479 |
567 |
480 |