12
|
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 |
* This class extends WebChromeContainerSnippet class
|
|
20 |
*
|
|
21 |
*/
|
|
22 |
|
|
23 |
#include "ActionButton.h"
|
|
24 |
#include "ActionButtonSnippet.h"
|
|
25 |
#include "ChromeRenderer.h"
|
|
26 |
#include "ChromeWidget.h"
|
|
27 |
#include "NativeChromeItem.h"
|
|
28 |
#include "TitleUrlContainerSnippet.h"
|
|
29 |
#include "UrlSearchSnippet.h"
|
|
30 |
#include "WebChromeSnippet.h"
|
|
31 |
#include "Utilities.h"
|
|
32 |
|
|
33 |
#include "QGraphicsPixmapItem"
|
|
34 |
|
|
35 |
#include "ChromeEffect.h"
|
|
36 |
|
|
37 |
#define BACKGROUND_GRADIENT_START "#232323"
|
|
38 |
#define BACKGROUND_GRADIENT_END "#000000"
|
|
39 |
|
|
40 |
#include <QDebug>
|
|
41 |
|
|
42 |
namespace GVA {
|
|
43 |
|
|
44 |
// Need to read this from the platform later
|
|
45 |
#define ICONWIDTH 65
|
|
46 |
#define ICONHEIGHT 44
|
|
47 |
|
|
48 |
TitleUrlContainerItem::TitleUrlContainerItem(ChromeSnippet * snippet, ChromeWidget * chrome, QGraphicsItem * parent)
|
|
49 |
: NativeChromeItem(snippet, parent)
|
|
50 |
, m_chrome(chrome)
|
|
51 |
{
|
|
52 |
setProperties();
|
|
53 |
// Create the view port widget
|
|
54 |
m_viewPort = new QGraphicsWidget(this);
|
|
55 |
m_viewPort->setFlags(QGraphicsItem::ItemClipsChildrenToShape);
|
|
56 |
|
|
57 |
// Create title-url widget(still by the name UrlSearchItem)
|
|
58 |
m_urlTileWidget = new GUrlSearchItem(snippet, chrome, m_viewPort);
|
|
59 |
|
|
60 |
QPixmap dividerPixmap;
|
|
61 |
dividerPixmap.load(":/chrome/bedrockchrome/urlsearch.snippet/icons/URL_search_divider.png", "PNG");
|
|
62 |
m_dividerImage = new QGraphicsPixmapItem(dividerPixmap, m_viewPort);
|
|
63 |
|
|
64 |
QAction * backAction = new QAction(this);
|
|
65 |
connect(backAction, SIGNAL(triggered()), m_chrome, SIGNAL(goToBackground()));
|
|
66 |
|
|
67 |
m_backStepButton = new ActionButton(snippet, m_viewPort);
|
|
68 |
m_backStepButton->setAction(backAction);
|
|
69 |
m_backStepButton->setActiveOnPress(true);
|
|
70 |
m_backStepButton->addIcon(":/chrome/bedrockchrome/urlsearch.snippet/icons/backstep.png", QIcon::Normal);
|
|
71 |
m_backStepButton->addIcon(":/chrome/bedrockchrome/urlsearch.snippet/icons/backstep_pressed.png", QIcon::Active);
|
|
72 |
|
|
73 |
// Monitor resize events.
|
|
74 |
safe_connect(m_chrome->renderer(), SIGNAL(chromeResized()), this, SLOT(onChromeResize()));
|
|
75 |
safe_connect(m_urlTileWidget, SIGNAL(changeEditMode(bool)), this, SLOT(changeLayout(bool)));
|
|
76 |
}
|
|
77 |
|
|
78 |
TitleUrlContainerItem::~TitleUrlContainerItem()
|
|
79 |
{
|
|
80 |
|
|
81 |
}
|
|
82 |
|
|
83 |
void TitleUrlContainerItem::setProperties() {
|
|
84 |
|
|
85 |
m_pen.setWidth(1);
|
|
86 |
m_pen.setBrush(QBrush(QColor(Qt::black)));
|
|
87 |
|
|
88 |
m_grad.setColorAt(0, BACKGROUND_GRADIENT_START);
|
|
89 |
m_grad.setColorAt(1, BACKGROUND_GRADIENT_END);
|
|
90 |
}
|
|
91 |
|
|
92 |
void TitleUrlContainerItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
|
93 |
{
|
|
94 |
Q_UNUSED(option)
|
|
95 |
Q_UNUSED(widget)
|
|
96 |
|
|
97 |
painter->save();
|
|
98 |
|
|
99 |
painter->setRenderHint(QPainter::Antialiasing);
|
|
100 |
painter->setPen(m_pen);
|
|
101 |
if (snippet()->enabled()) {
|
|
102 |
painter->fillRect(boundingRect(), QBrush(m_grad));
|
|
103 |
}
|
|
104 |
else {
|
|
105 |
painter->fillRect(boundingRect(), QColor(Qt::gray));
|
|
106 |
painter->setOpacity(ChromeEffect::disabledOpacity);
|
|
107 |
painter->fillRect(boundingRect(), ChromeEffect::disabledColor);
|
|
108 |
}
|
|
109 |
|
|
110 |
// top border
|
|
111 |
painter->setPen(QPen(QColor(53,53,53)));
|
|
112 |
painter->drawLine(boundingRect().x(), boundingRect().y(), boundingRect().x() + boundingRect().width(), boundingRect().y());
|
|
113 |
// bottom border
|
|
114 |
painter->setPen(QPen(QColor(76,76,78)));
|
|
115 |
painter->drawLine(boundingRect().x(), boundingRect().y() + boundingRect().height(), boundingRect().x() + boundingRect().width(), boundingRect().y() + boundingRect().height());
|
|
116 |
// right border
|
|
117 |
painter->setPen(QPen(QColor(0,0,0)));
|
|
118 |
painter->drawLine(boundingRect().x() + boundingRect().width(), boundingRect().y(), boundingRect().x() + boundingRect().width(), boundingRect().y() + boundingRect().height());
|
|
119 |
// left border
|
|
120 |
painter->setPen(m_pen);
|
|
121 |
QLinearGradient grad = QLinearGradient();
|
|
122 |
grad.setColorAt(0, QColor(41,41,41));
|
|
123 |
grad.setColorAt(0.5, QColor(83,83,84));
|
|
124 |
grad.setColorAt(1, QColor(2,2,2));
|
|
125 |
painter->fillRect(QRect(boundingRect().x(), boundingRect().y(), 1, boundingRect().height()), QBrush(grad));
|
|
126 |
|
|
127 |
painter->restore();
|
|
128 |
|
|
129 |
NativeChromeItem::paint(painter, option, widget);
|
|
130 |
}
|
|
131 |
|
|
132 |
void TitleUrlContainerItem::onChromeResize() {
|
|
133 |
|
|
134 |
QWebElement we = m_snippet->element();
|
|
135 |
QRectF g = we.geometry();
|
|
136 |
QGraphicsWidget::resize(g.width(), g.height());
|
|
137 |
}
|
|
138 |
|
|
139 |
void TitleUrlContainerItem::resizeEvent(QGraphicsSceneResizeEvent * event)
|
|
140 |
{
|
|
141 |
QSizeF size = event->newSize();
|
|
142 |
|
|
143 |
qreal width = size.width();
|
|
144 |
qreal height = size.height();
|
|
145 |
|
|
146 |
m_viewPort->setGeometry(
|
|
147 |
0,
|
|
148 |
0,
|
|
149 |
width,
|
|
150 |
height);
|
|
151 |
|
|
152 |
m_backStepButton->setGeometry(
|
|
153 |
width - ICONWIDTH,
|
|
154 |
(height - ICONHEIGHT)/2,
|
|
155 |
ICONWIDTH,
|
|
156 |
ICONHEIGHT);
|
|
157 |
|
|
158 |
// When we first get resize event, the widget is not yet set to visible by
|
|
159 |
// Ginebra. If the widget is not visible and for later resize events, if back-step
|
|
160 |
// button is visible, set the width of url-title widget taking into account
|
|
161 |
// the width of back-step button
|
|
162 |
if ((!this->isVisible()) || m_backStepButton->isVisible()) {
|
|
163 |
|
|
164 |
width = width - ICONWIDTH - m_dividerImage->boundingRect().width();
|
|
165 |
}
|
|
166 |
m_urlTileWidget->setGeometry(0,
|
|
167 |
0,
|
|
168 |
width,
|
|
169 |
height);
|
|
170 |
|
|
171 |
m_dividerImage->setPos(m_urlTileWidget->rect().width() + 1, (height - m_dividerImage->boundingRect().height())/2);
|
|
172 |
}
|
|
173 |
|
|
174 |
|
|
175 |
void TitleUrlContainerItem::changeLayout(bool editMode){
|
|
176 |
|
|
177 |
qreal width = m_viewPort->geometry().width();
|
|
178 |
qreal height = m_viewPort->geometry().height();
|
|
179 |
|
|
180 |
// If we are changing to edit mode, we need to hide the back-step button
|
|
181 |
if (editMode) {
|
|
182 |
|
|
183 |
m_backStepButton->hide();
|
|
184 |
m_dividerImage->hide();
|
|
185 |
}
|
|
186 |
else {
|
|
187 |
|
|
188 |
// show back-step button and re-layout the widgets
|
|
189 |
m_backStepButton->show();
|
|
190 |
m_dividerImage->show();
|
|
191 |
width = width - ICONWIDTH - m_dividerImage->boundingRect().width();
|
|
192 |
}
|
|
193 |
m_urlTileWidget->setGeometry(0,
|
|
194 |
0,
|
|
195 |
width,
|
|
196 |
height);
|
|
197 |
}
|
|
198 |
|
|
199 |
QString TitleUrlContainerItem::url() const
|
|
200 |
{
|
|
201 |
return m_urlTileWidget->url();
|
|
202 |
}
|
|
203 |
|
|
204 |
// TitleUrlContainerSnippet class
|
|
205 |
TitleUrlContainerSnippet::TitleUrlContainerSnippet(const QString & elementId, ChromeWidget * chrome,
|
|
206 |
QGraphicsWidget * widget, const QWebElement & element)
|
|
207 |
: ChromeSnippet(elementId, chrome, widget, element)
|
|
208 |
{
|
|
209 |
}
|
|
210 |
|
|
211 |
TitleUrlContainerSnippet::~TitleUrlContainerSnippet()
|
|
212 |
{
|
|
213 |
}
|
|
214 |
|
|
215 |
TitleUrlContainerSnippet * TitleUrlContainerSnippet::instance(const QString& elementId, ChromeWidget * chrome, const QWebElement & element)
|
|
216 |
{
|
|
217 |
TitleUrlContainerSnippet * that = new TitleUrlContainerSnippet( elementId, chrome, 0, element );
|
|
218 |
that->setChromeWidget( new TitleUrlContainerItem(that, chrome));
|
|
219 |
|
|
220 |
return that;
|
|
221 |
}
|
|
222 |
|
|
223 |
QString TitleUrlContainerSnippet::url() const
|
|
224 |
{
|
|
225 |
TitleUrlContainerItem const *urlContainer;
|
|
226 |
|
|
227 |
urlContainer = dynamic_cast<TitleUrlContainerItem const *> (constWidget());
|
|
228 |
return urlContainer->url();
|
|
229 |
}
|
|
230 |
|
|
231 |
} // end of namespace GVA
|
|
232 |
|
|
233 |
|
|
234 |
|