ginebra2/ProgressSnippet.cpp
branchGCC_SURGE
changeset 8 2e16851ffecd
parent 2 bf4420e9fa4d
parent 6 1c3b8676e58c
equal deleted inserted replaced
2:bf4420e9fa4d 8:2e16851ffecd
     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: 
       
    15 *
       
    16 */
       
    17 #include <QtGui>
       
    18 #include "ProgressSnippet.h"
       
    19 #include "GWebContentView.h"
       
    20 #include "ContentViewDelegate.h"
       
    21 #include "ChromeSnippet.h"
       
    22 
       
    23 #include <QDebug>
       
    24 
       
    25 namespace GVA {
       
    26 
       
    27   ProgressSnippet::ProgressSnippet(ChromeSnippet * snippet, QGraphicsItem* parent)
       
    28     : NativeChromeItem(snippet, parent),
       
    29       m_progress(0),
       
    30       m_webView(0)
       
    31   {
       
    32     //Set indicator color from element css
       
    33     QString cssColor = m_snippet->element().styleProperty("color", QWebElement::ComputedStyle);
       
    34     CSSToQColor(cssColor, m_color);
       
    35   }
       
    36 
       
    37   ProgressSnippet:: ~ProgressSnippet()
       
    38   {
       
    39 
       
    40   }
       
    41 
       
    42   void ProgressSnippet::onProgress(int progress)
       
    43   {
       
    44     //QApplication::processEvents(QEventLoop::ExcludeSocketNotifiers);
       
    45     qreal p = ((qreal)progress)/100;
       
    46     qDebug() << "ProgressSnippet::onProgress: " << p;
       
    47     if(m_progress != p){
       
    48       m_progress = p;
       
    49       update();
       
    50     }
       
    51   }
       
    52 
       
    53   void ProgressSnippet::onStart() {
       
    54     onProgress(0);
       
    55   }
       
    56 
       
    57   void ProgressSnippet::onFinished(bool ok) {
       
    58     Q_UNUSED(ok)
       
    59     onProgress(0);
       
    60   }
       
    61 
       
    62   void ProgressSnippet::paint(QPainter* painter, const QStyleOptionGraphicsItem* opt, QWidget* widget)
       
    63   {
       
    64     Q_UNUSED(opt)
       
    65     //NB: Would be nice to do this a bit sooner. How about adding viewAdded signal to ChromeWidget? 
       
    66     if(!m_webView){
       
    67       m_webView  = dynamic_cast<GWebContentView*> (m_snippet->chrome()->getView("WebView"));
       
    68       if(m_webView){
       
    69         connect(m_webView, SIGNAL(loadStarted()), this, SLOT(onStart()));
       
    70 	    connect(m_webView, SIGNAL(loadProgress(int)), this, SLOT(onProgress(int)));
       
    71 	    connect(m_webView, SIGNAL(loadFinished(bool)), this, SLOT(onFinished(bool)));
       
    72       }
       
    73       else
       
    74 	qDebug() << "No web view found";
       
    75     }
       
    76     
       
    77     //painter->fillRect(QRectF(0,0, geometry().width(), geometry().height()), Qt::blue);
       
    78     qreal minWidth = geometry().width()/10;
       
    79     painter->fillRect(QRectF(0,0, minWidth + (geometry().width() - minWidth)*m_progress, geometry().height()), m_color);
       
    80   }
       
    81 
       
    82 } // end of namespace GVA
       
    83 
       
    84