16
|
1 |
#include "MostVisitedView.h"
|
|
2 |
#include "GridView.h"
|
|
3 |
#include "webpagecontroller.h"
|
|
4 |
#include "mostvisitedpagestore.h"
|
|
5 |
#include "wrtbrowsercontainer.h"
|
|
6 |
#include "ScaleThreePainter.h"
|
|
7 |
#include "qstmgestureevent.h"
|
|
8 |
|
|
9 |
#include <QGraphicsPixmapItem>
|
|
10 |
#include <QGraphicsScene>
|
|
11 |
#include <QGraphicsSceneResizeEvent>
|
|
12 |
#include <QPainter>
|
|
13 |
#include <QStyleOptionGraphicsItem>
|
|
14 |
#include <QGraphicsLinearLayout>
|
|
15 |
#include <QGraphicsSimpleTextItem>
|
|
16 |
|
|
17 |
namespace GVA {
|
|
18 |
|
|
19 |
|
|
20 |
// -----------------------------------------------------------
|
|
21 |
// MostVisitedViewItem
|
|
22 |
// -----------------------------------------------------------
|
|
23 |
|
|
24 |
MostVisitedViewItem::MostVisitedViewItem(::MostVisitedPage *mostVisitedPage, QGraphicsItem *parent)
|
|
25 |
: QGraphicsWidget(parent),
|
|
26 |
m_mostVisitedPage(mostVisitedPage)
|
|
27 |
{
|
|
28 |
grabGesture(QStm_Gesture::assignedType());
|
|
29 |
installEventFilter(this);
|
|
30 |
}
|
|
31 |
|
|
32 |
void MostVisitedViewItem::activate() {
|
|
33 |
WRT::WrtBrowserContainer * activePage = WebPageController::getSingleton()->currentPage();
|
|
34 |
|
|
35 |
if (activePage) {
|
|
36 |
activePage->mainFrame()->load(m_mostVisitedPage->m_url);
|
|
37 |
}
|
|
38 |
close();
|
|
39 |
emit activated();
|
|
40 |
}
|
|
41 |
|
|
42 |
void MostVisitedViewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
|
|
43 |
if(m_mostVisitedPage->m_pageThumbnail) {
|
|
44 |
QPixmap pixmap(QPixmap::fromImage(*m_mostVisitedPage->m_pageThumbnail).scaled(size().toSize()));
|
|
45 |
painter->drawPixmap(option->exposedRect, pixmap, option->exposedRect);
|
|
46 |
|
|
47 |
QPen pen;
|
|
48 |
int x, y, w, h;
|
|
49 |
const int itemBorderWidth = 2;
|
|
50 |
const QColor itemBorderColor = QColor("black");
|
|
51 |
|
|
52 |
pen.setWidth(itemBorderWidth);
|
|
53 |
pen.setBrush(itemBorderColor);
|
|
54 |
pen.setJoinStyle(Qt::MiterJoin);
|
|
55 |
|
|
56 |
painter->setPen(pen);
|
|
57 |
option->exposedRect.toRect().getRect(&x, &y, &w, &h);
|
|
58 |
painter->drawRect(x + itemBorderWidth / 2, y + itemBorderWidth / 2, w - itemBorderWidth, h - itemBorderWidth);
|
|
59 |
}
|
|
60 |
}
|
|
61 |
|
|
62 |
bool MostVisitedViewItem::eventFilter(QObject* o, QEvent* e)
|
|
63 |
{
|
|
64 |
if (o != this)
|
|
65 |
return false;
|
|
66 |
return QStm_GestureEventFilter::instance()->eventFilter(o, e);
|
|
67 |
}
|
|
68 |
|
|
69 |
bool MostVisitedViewItem::event(QEvent* event)
|
|
70 |
{
|
|
71 |
if (event->type() == QEvent::Gesture) {
|
|
72 |
QStm_Gesture* gesture = getQStmGesture(event);
|
|
73 |
if (gesture) {
|
|
74 |
handleQStmGesture(gesture);
|
|
75 |
event->accept();
|
|
76 |
return true;
|
|
77 |
}
|
|
78 |
}
|
|
79 |
return false;
|
|
80 |
}
|
|
81 |
|
|
82 |
bool MostVisitedViewItem::handleQStmGesture(QStm_Gesture* gesture)
|
|
83 |
{
|
|
84 |
QStm_GestureType type = gesture->getGestureStmType();
|
|
85 |
|
|
86 |
if (type == QStmTapGestureType) {
|
|
87 |
activate();
|
|
88 |
}
|
|
89 |
return true;
|
|
90 |
}
|
|
91 |
|
|
92 |
|
|
93 |
// -----------------------------------------------------------
|
|
94 |
// MostVisitedView
|
|
95 |
// -----------------------------------------------------------
|
|
96 |
|
|
97 |
MostVisitedView::MostVisitedView(const QString &title, QGraphicsItem *parent)
|
|
98 |
: QGraphicsWidget(parent),
|
|
99 |
m_layout(new QGraphicsLinearLayout(Qt::Vertical, this)),
|
|
100 |
m_title(0),
|
|
101 |
m_gridView(new GridView(this)),
|
|
102 |
m_backgroundPixmap(0),
|
|
103 |
m_backgroundDirty(true),
|
|
104 |
m_titleWrapper(new QGraphicsWidget(this))
|
|
105 |
|
|
106 |
{
|
|
107 |
m_titleWrapper->resize(50, 10);
|
|
108 |
m_title = new QGraphicsSimpleTextItem(" " + title, m_titleWrapper);
|
|
109 |
m_title->setBrush(QColor(Qt::white));
|
|
110 |
QFont textFont = m_title->font();
|
|
111 |
#ifdef Q_WS_MAEMO_5
|
|
112 |
textFont.setPointSize(16);
|
|
113 |
#else
|
|
114 |
textFont.setPointSize(6);
|
|
115 |
#endif
|
|
116 |
textFont.setWeight(QFont::Bold);
|
|
117 |
m_title->setFont(textFont);
|
|
118 |
#ifdef Q_WS_MAEMO_5
|
|
119 |
m_titleWrapper->setContentsMargins(16, 0, 0, 0);
|
|
120 |
#endif
|
|
121 |
|
|
122 |
setLayout(m_layout);
|
|
123 |
m_layout->setSpacing(0);
|
|
124 |
|
|
125 |
#ifdef Q_WS_MAEMO_5
|
|
126 |
m_layout->setContentsMargins(16, 4, 16, 16);
|
|
127 |
m_layout->addItem(m_titleWrapper);
|
|
128 |
#else
|
|
129 |
|
|
130 |
m_layout->addItem(m_titleWrapper);
|
|
131 |
#endif
|
|
132 |
m_layout->addItem(m_gridView);
|
|
133 |
|
|
134 |
#ifdef Q_WS_MAEMO_5
|
|
135 |
m_gridView->setColumnRowCounts(3, 2);
|
|
136 |
#endif
|
|
137 |
|
|
138 |
m_backgroundPainter = new ScaleThreePainter(
|
|
139 |
":/mostvisited/most_visited_bac_left.png",
|
|
140 |
":/mostvisited/most_visited_bac_middle.png",
|
|
141 |
":/mostvisited/most_visited_bac_right.png"
|
|
142 |
);
|
|
143 |
}
|
|
144 |
|
|
145 |
MostVisitedView::~MostVisitedView() {
|
|
146 |
delete m_backgroundPainter;
|
|
147 |
delete m_backgroundPixmap;
|
|
148 |
}
|
|
149 |
|
|
150 |
void MostVisitedView::update(QString mode) {
|
|
151 |
|
|
152 |
MostVisitedPageList pageList = MostVisitedPageStoreSingleton::Instance().pageList();
|
|
153 |
m_gridView->clear();
|
|
154 |
foreach(MostVisitedPage *page, pageList) {
|
|
155 |
MostVisitedViewItem *item = new MostVisitedViewItem(page, this);
|
|
156 |
//qDebug() << __PRETTY_FUNCTION__ << " url=" << page->m_url << page->m_pageThumbnail;
|
|
157 |
m_gridView->addItem(item);
|
|
158 |
safe_connect(item, SIGNAL(activated()), this, SLOT(onItemActivated()));
|
|
159 |
}
|
|
160 |
|
|
161 |
m_displayMode = mode;
|
|
162 |
m_gridView->rebuildLayout();
|
|
163 |
}
|
|
164 |
|
|
165 |
void MostVisitedView::resizeEvent(QGraphicsSceneResizeEvent * event) {
|
|
166 |
|
|
167 |
m_gridView->resize(event->newSize());
|
|
168 |
// Force background update on next paint().
|
|
169 |
m_backgroundDirty = true;
|
|
170 |
}
|
|
171 |
|
|
172 |
void MostVisitedView::closeEvent(QCloseEvent *event) {
|
|
173 |
Q_UNUSED(event)
|
|
174 |
emit closeComplete();
|
|
175 |
}
|
|
176 |
|
|
177 |
void MostVisitedView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
|
|
178 |
// Update the background pixmap if needed.
|
|
179 |
|
|
180 |
#ifndef Q_WS_MAEMO_5
|
|
181 |
if (m_displayMode == "portrait")
|
|
182 |
{
|
|
183 |
m_gridView->setColumnRowCounts(2, 3);
|
|
184 |
m_titleWrapper->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
185 |
m_layout->setContentsMargins(16, 4, 16, 16);
|
|
186 |
setMinimumSize(346, 523);
|
|
187 |
setMaximumSize(346, 523);
|
|
188 |
}
|
|
189 |
else
|
|
190 |
{
|
|
191 |
m_gridView->setColumnRowCounts(3, 2);
|
|
192 |
m_titleWrapper->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
|
193 |
m_layout->setContentsMargins(36, 4, 0, 0);
|
|
194 |
setMinimumSize(610, 260);
|
|
195 |
setMaximumSize(610, 260);
|
|
196 |
}
|
|
197 |
m_gridView->rebuildLayout();
|
|
198 |
#endif
|
|
199 |
|
|
200 |
#ifndef Q_WS_MAEMO_5
|
|
201 |
updateBackgroundPixmap(geometry().size().toSize(), widget);
|
|
202 |
m_backgroundPainter->unloadPixmaps();
|
|
203 |
#else
|
|
204 |
if(m_backgroundDirty) {
|
|
205 |
updateBackgroundPixmap(geometry().size().toSize(), widget);
|
|
206 |
m_backgroundPainter->unloadPixmaps();
|
|
207 |
}
|
|
208 |
#endif
|
|
209 |
|
|
210 |
// Paint the background.
|
|
211 |
painter->drawPixmap(option->exposedRect, *m_backgroundPixmap, option->exposedRect);
|
|
212 |
}
|
|
213 |
|
|
214 |
void MostVisitedView::updateBackgroundPixmap(const QSize &size, QWidget* widget) {
|
|
215 |
delete m_backgroundPixmap;
|
|
216 |
m_backgroundPixmap = new QPixmap(size);
|
|
217 |
m_backgroundPixmap->fill(QColor(0xff, 0xff, 0xff, 0));
|
|
218 |
QPainter painter(m_backgroundPixmap);
|
|
219 |
m_backgroundPainter->paint(&painter, QRect(0, 0, size.width(), size.height()), widget);
|
|
220 |
m_backgroundDirty = false;
|
|
221 |
}
|
|
222 |
|
|
223 |
void MostVisitedView::onItemActivated() {
|
|
224 |
close();
|
|
225 |
emit activated();
|
|
226 |
}
|
|
227 |
|
|
228 |
} // namespace
|
|
229 |
|