|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
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. |
|
8 * |
|
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 * |
|
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 * |
|
20 */ |
|
21 #include <QtGui> |
|
22 #include "ProgressBarItem.h" |
|
23 #include "GWebContentView.h" |
|
24 #include "ContentViewDelegate.h" |
|
25 #include "ChromeSnippet.h" |
|
26 #include "webpagecontroller.h" |
|
27 |
|
28 #include <QDebug> |
|
29 |
|
30 namespace GVA { |
|
31 |
|
32 ProgressBarItem::ProgressBarItem(ChromeSnippet * snippet, QGraphicsItem* parent) |
|
33 : NativeChromeItem(snippet, parent), |
|
34 m_progress(0) |
|
35 { |
|
36 //Set indicator color from element css |
|
37 QString cssColor = m_snippet->element().styleProperty("color", QWebElement::ComputedStyle); |
|
38 CSSToQColor(cssColor, m_color); |
|
39 |
|
40 connectAll(); |
|
41 } |
|
42 |
|
43 ProgressBarItem:: ~ProgressBarItem() |
|
44 { |
|
45 |
|
46 } |
|
47 |
|
48 void ProgressBarItem::onProgress(int progress) |
|
49 { |
|
50 setProgress(((qreal)progress)/100); |
|
51 } |
|
52 |
|
53 void ProgressBarItem::setProgress(qreal progress) |
|
54 { |
|
55 //QApplication::processEvents(QEventLoop::ExcludeSocketNotifiers); |
|
56 //qDebug() << "ProgressBarItem::onProgress: " << progress; |
|
57 if (m_progress != progress){ |
|
58 m_progress = progress; |
|
59 update(); |
|
60 } |
|
61 } |
|
62 |
|
63 void ProgressBarItem::onStart() { |
|
64 onProgress(0); |
|
65 } |
|
66 |
|
67 void ProgressBarItem::onFinished(bool ok) { |
|
68 Q_UNUSED(ok) |
|
69 onProgress(0); |
|
70 } |
|
71 |
|
72 void ProgressBarItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* opt, QWidget* widget) |
|
73 { |
|
74 Q_UNUSED(opt) |
|
75 Q_UNUSED(widget) |
|
76 |
|
77 //painter->fillRect(QRectF(0,0, geometry().width(), geometry().height()), Qt::blue); |
|
78 if (m_progress > 0) { |
|
79 QSizeF s = size(); |
|
80 qreal minWidth = s.width()/10; |
|
81 painter->fillRect(QRectF(0,0, minWidth + (s.width() - minWidth)*m_progress, s.height()), m_color); |
|
82 } |
|
83 NativeChromeItem::paint(painter, opt, widget); |
|
84 } |
|
85 |
|
86 void ProgressBarItem::connectAll() { |
|
87 WebPageController* pageController = WebPageController::getSingleton(); |
|
88 if (pageController){ |
|
89 connect(pageController, SIGNAL(loadStarted()), this, SLOT(onStart())); |
|
90 connect(pageController, SIGNAL(loadProgress(int)), this, SLOT(onProgress(int))); |
|
91 connect(pageController, SIGNAL(loadFinished(bool)), this, SLOT(onFinished(bool))); |
|
92 } |
|
93 } |
|
94 |
|
95 } // end of namespace GVA |
|
96 |
|
97 |