1 /* |
|
2 * Copyright (c) 2010 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 |
|
18 |
|
19 #include "iconwidget.h" |
|
20 #include "webpagecontroller.h" |
|
21 #include <QWebSettings> |
|
22 |
|
23 namespace GVA { |
|
24 |
|
25 IconWidget::IconWidget(ChromeSnippet * snippet, QGraphicsItem* parent) |
|
26 : NativeChromeItem(snippet, parent) |
|
27 { |
|
28 m_drawingDefault = false; |
|
29 m_icon = QIcon(); |
|
30 m_defaultImage = QImage(":/chrome/demochrome/Scroll.png"); |
|
31 } |
|
32 |
|
33 void IconWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* opt, QWidget* widget) |
|
34 { |
|
35 painter->save(); |
|
36 if (m_drawingDefault) { |
|
37 painter->drawImage(QRectF(0,0, geometry().width(), geometry().height()), m_defaultImage); |
|
38 } |
|
39 else { |
|
40 if (!m_icon.isNull()) { |
|
41 m_icon.paint(painter, 0, 0, geometry().width(), geometry().height()); |
|
42 } |
|
43 } |
|
44 painter->restore(); |
|
45 } |
|
46 |
|
47 void IconWidget::onLoadStarted() |
|
48 { |
|
49 m_drawingDefault = true; |
|
50 update(); |
|
51 } |
|
52 |
|
53 void IconWidget::onIconChanged() |
|
54 { |
|
55 m_drawingDefault = false; |
|
56 WebPageController* pageController = WebPageController::getSingleton(); |
|
57 m_icon = pageController->pageIcon(); |
|
58 if (!m_icon.isNull()) { |
|
59 update(); |
|
60 } |
|
61 } |
|
62 void IconWidget::onUrlChanged(const QUrl& url) |
|
63 { |
|
64 m_icon = QWebSettings::iconForUrl(url); |
|
65 if (!m_icon.isNull()) { |
|
66 m_drawingDefault = false; |
|
67 update(); |
|
68 } |
|
69 } |
|
70 |
|
71 void IconWidget::connectToWebpageController() |
|
72 { |
|
73 WebPageController* pageController = WebPageController::getSingleton(); |
|
74 connect(pageController, SIGNAL(loadStarted()), this, SLOT(onLoadStarted())); |
|
75 connect(pageController, SIGNAL(currentPageUrlChanged(const QUrl&)), this, SLOT(onUrlChanged(const QUrl&))); |
|
76 connect(pageController, SIGNAL(currentPageIconChanged()), this, SLOT(onIconChanged())); |
|
77 } |
|
78 |
|
79 void IconWidget::setIconForUrl(const QUrl& url) { |
|
80 m_drawingDefault = false; |
|
81 m_icon = QWebSettings::iconForUrl(url); |
|
82 update(); |
|
83 } |
|
84 void IconWidget::setDefaultImage(const QImage& image) { |
|
85 m_drawingDefault = true; |
|
86 m_defaultImage = image; |
|
87 update(); |
|
88 } |
|
89 }//end of name space |
|