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: |
15 * |
19 * |
16 */ |
20 */ |
17 |
21 |
18 |
|
19 #include "ToolbarChromeItem.h" |
22 #include "ToolbarChromeItem.h" |
|
23 #include "NativeChromeItem.h" |
20 #include "GWebContentView.h" |
24 #include "GWebContentView.h" |
21 #include "WebChromeContainerSnippet.h" |
25 #include "WebChromeContainerSnippet.h" |
22 |
26 |
23 #include <QDebug> |
27 #include <QDebug> |
24 |
28 |
25 #define TOOLBAR_MARGIN 4 |
29 #define TOOLBAR_BG_OPACITY 0.75 |
26 #define TOOLBAR_BORDER_WIDTH 3 |
|
27 #define TOOLBAR_BORDER_COLOR "#2A3447" |
|
28 #define TOOLBAR_GRADIENT_START "#2E3B57" |
30 #define TOOLBAR_GRADIENT_START "#2E3B57" |
29 #define TOOLBAR_GRADIENT_END "#44587D" |
31 #define TOOLBAR_GRADIENT_END "#44587D" |
30 #define TOOLBAR_RIGHTCORNER_ITEM 2 |
|
31 #define TOOLBAR_LEFTCORNER_ITEM 0 |
32 #define TOOLBAR_LEFTCORNER_ITEM 0 |
32 |
33 |
33 namespace GVA { |
34 namespace GVA { |
34 |
35 |
35 ToolbarChromeItem::ToolbarChromeItem(QGraphicsItem* parent) |
36 ToolbarChromeItem::ToolbarChromeItem(QGraphicsItem* parent) |
36 : QGraphicsWidget(parent), |
37 : ChromeItem(NULL, parent), |
37 m_snippet(NULL), |
|
38 m_partialbg(NULL), |
38 m_partialbg(NULL), |
39 m_opacity(0.75) |
39 m_opacity(TOOLBAR_BG_OPACITY) |
40 { |
40 { |
41 |
|
42 setProperties(); |
|
43 |
|
44 |
41 |
45 } |
42 } |
46 |
43 |
47 ToolbarChromeItem::~ToolbarChromeItem() |
44 ToolbarChromeItem::~ToolbarChromeItem() |
48 { |
45 { |
63 { |
60 { |
64 Q_UNUSED(opt) |
61 Q_UNUSED(opt) |
65 Q_UNUSED(widget) |
62 Q_UNUSED(widget) |
66 |
63 |
67 painter->save(); |
64 painter->save(); |
68 |
65 |
69 painter->setRenderHint(QPainter::Antialiasing); |
66 painter->setRenderHint(QPainter::Antialiasing); |
70 |
67 |
71 painter->setPen(m_pen); |
68 painter->setPen(m_pen); |
72 painter->setOpacity(m_opacity); |
69 painter->setOpacity(m_opacity); |
73 |
70 |
74 |
71 |
75 // qDebug() << __PRETTY_FUNCTION__ << boundingRect(); |
72 // qDebug() << __PRETTY_FUNCTION__ << boundingRect(); |
76 painter->fillPath(*m_partialbg, QBrush(m_grad)); |
73 painter->fillPath(*m_partialbg, QBrush(m_grad)); |
77 painter->drawPath(*m_partialbg); |
74 painter->drawPath(*m_partialbg); |
78 |
75 |
79 // restore painter |
76 // restore painter |
80 painter->restore(); |
77 painter->restore(); |
81 |
|
82 } |
|
83 void ToolbarChromeItem::setSnippet(WebChromeContainerSnippet* snippet) { |
|
84 |
78 |
85 //qDebug() << __func__ << snippet; |
|
86 m_snippet = snippet; |
|
87 } |
79 } |
88 |
80 |
89 void ToolbarChromeItem::setProperties() { |
81 void ToolbarChromeItem::setProperties() { |
90 |
82 |
91 m_pen.setWidth(TOOLBAR_BORDER_WIDTH); |
83 m_pen.setWidth(m_borderWidth); |
92 m_pen.setBrush(QBrush(TOOLBAR_BORDER_COLOR)); |
84 m_pen.setBrush(QBrush(m_borderColor)); |
93 |
85 |
94 m_grad.setColorAt(0, TOOLBAR_GRADIENT_START); |
86 m_grad.setColorAt(0, TOOLBAR_GRADIENT_START); |
95 m_grad.setColorAt(1, TOOLBAR_GRADIENT_END); |
87 m_grad.setColorAt(1, TOOLBAR_GRADIENT_END); |
96 |
88 |
97 } |
89 } |
98 |
90 |
99 void ToolbarChromeItem::addPartialbg() { |
91 void ToolbarChromeItem::addPartialbg() { |
100 |
92 |
101 WebChromeContainerSnippet * s = static_cast<WebChromeContainerSnippet*>(m_snippet); |
93 WebChromeContainerSnippet * s = static_cast<WebChromeContainerSnippet*>(m_snippet); |
103 if (m_partialbg) { |
95 if (m_partialbg) { |
104 delete m_partialbg; |
96 delete m_partialbg; |
105 } |
97 } |
106 |
98 |
107 m_partialbg = new QPainterPath(); |
99 m_partialbg = new QPainterPath(); |
108 int width = rc.width()-TOOLBAR_MARGIN; |
100 qreal width = rc.width()-m_padding; |
109 |
101 |
110 // Add left corner bg |
102 // Add left corner bg |
111 m_partialbg->addEllipse(1, 1, width, width); |
103 m_partialbg->addEllipse(1, 1, width, width); |
112 |
104 |
113 // Right Corner background |
105 // Right Corner background |
114 int x = boundingRect().width()- rc.width() + 1; |
106 qreal x = boundingRect().width()- rc.width() + 1; |
115 QRectF r(x, 1, width, width); |
107 QRectF r(x, 1, width, width); |
116 |
108 |
117 m_partialbg->addEllipse(r); |
109 m_partialbg->addEllipse(r); |
118 } |
110 } |
119 |
111 |
|
112 void ToolbarChromeItem::setSnippet(ChromeSnippet* snippet) { |
|
113 |
|
114 ChromeItem::setSnippet(snippet); |
|
115 |
|
116 QString cssVal = m_snippet->element().styleProperty("border-top-color", QWebElement::ComputedStyle); |
|
117 NativeChromeItem::CSSToQColor(cssVal, m_borderColor); |
|
118 |
|
119 cssVal = m_snippet->element().styleProperty("padding-top", QWebElement::ComputedStyle); |
|
120 m_padding = cssVal.remove("px").toInt(); |
|
121 |
|
122 |
|
123 cssVal = m_snippet->element().styleProperty("border-top-width", QWebElement::ComputedStyle); |
|
124 m_borderWidth = cssVal.remove("px").toInt(); |
|
125 |
|
126 setProperties(); |
|
127 } |
120 |
128 |
121 } // end of namespace GVA |
129 } // end of namespace GVA |
122 |
130 |
123 |
131 |