#include <QDir>
#include <QTimer>
-#ifdef Q_WS_MAEMO_5
+#if defined(Q_WS_MAEMO_5)
# include <QAbstractKineticScroller>
+#elif defined(Q_OS_SYMBIAN)
+# include "flickcharm.h"
#endif
#include "book.h"
#include "trace.h"
#include "progress.h"
-#ifdef Q_WS_MAC
-# define ICON_PREFIX ":/icons/mac/"
-#else
-# define ICON_PREFIX ":/icons/"
-#endif
-
BookView::BookView(QWidget *parent):
QWebView(parent), contentIndex(-1), mBook(0),
restorePositionAfterLoad(false), positionAfterLoad(0), loaded(false),
- contentsHeight(0), decorated(false), scrollerMonitor(-1)
+ contentsHeight(0)
{
Trace t("BookView::BookView");
settings()->setAttribute(QWebSettings::AutoLoadImages, true);
settings()->setDefaultTextEncoding("utf-8");
page()->setContentEditable(false);
-#if defined(Q_WS_MAEMO_5)
- // Suppress unwanted text selections on Maemo
+#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
+ // Suppress unwanted text selections on Maemo and Symbian
installEventFilter(this);
#endif
QWebFrame *frame = page()->mainFrame();
-#if defined(Q_WS_MAEMO_5)
+#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
frame->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
#endif
frame->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
s->setValue("scheme", s->value("scheme", "default"));
setBook(0);
- extractIcons();
-#ifdef Q_WS_MAEMO_5
+#if defined(Q_WS_MAEMO_5)
+ scrollerMonitor = 0;
scroller = property("kineticScroller").value<QAbstractKineticScroller *>();
+#elif defined(Q_OS_SYMBIAN)
+ FlickCharm *charm = new FlickCharm(this);
+ charm->activateOn(this);
#endif
}
BookView::~BookView()
{
Trace t("BookView::~BookView");
- removeIcons();
}
void BookView::loadContent(int index)
}
else {
loaded = false;
- decorated = false;
emit partLoadStart(index);
- load(QUrl(contentFile));
+ QUrl u = QUrl::fromLocalFile(QDir(mBook->rootPath()).
+ absoluteFilePath(contentFile));
+ qDebug() << "Loading" << u;
+ load(u);
}
contentIndex = index;
}
return;
}
loaded = true;
- addNavigationBar();
onSettingsChanged("scheme");
emit partLoadEnd(contentIndex);
showProgress();
continue;
}
int height = contentsHeight;
- int bookmarkPos = (qreal)height * (qreal)b.pos;
+ int bookmarkPos = (int)((qreal)height * (qreal)b.pos);
painter.drawPixmap(2, bookmarkPos - scrollPos.y(), bookmarkPixmap);
}
}
QWebView::mousePressEvent(e);
#ifdef Q_WS_MAEMO_5
// Start monitoring kinetic scroll
+ if (scrollerMonitor) {
+ killTimer(scrollerMonitor);
+ scrollerMonitor = 0;
+ }
if (scroller) {
- scrollerMonitor = startTimer(250);
+ scrollerMonitor = startTimer(500);
}
#else
// Handle mouse presses on the scroll bar
showProgress();
}
-void BookView::addBookmark()
+void BookView::addBookmark(const QString ¬e)
{
Trace t("BookView::addBookmark");
if (!mBook) {
int y = page()->mainFrame()->scrollPosition().y();
int height = page()->mainFrame()->contentsSize().height();
qDebug() << ((qreal)y / (qreal)height);
- mBook->addBookmark(contentIndex, (qreal)y / (qreal)height);
+ mBook->addBookmark(contentIndex, (qreal)y / (qreal)height, note);
update();
}
-void BookView::addNavigationBar()
-{
- Trace t("BookView::addNavigationBar");
- if (!mBook) {
- return;
- }
-
- QString naviPrev =
- "<a href=\"javascript:bv.goPrevious();\">"
- "<img width=\"95\" height=\"95\" style=\"float:left;clear:none;\" "
- "src=\"file://"
- + tmpPath() +
- "/previous.png\" />"
- "</a>";
- QString naviNext =
- "<a href=\"javascript:bv.goNext();\">"
- "<img width=\"95\" height=\"95\" style=\"float:right;clear:none;\" "
- "src=\"file://"
- + tmpPath() +
- "/next.png\" />"
- "</a>";
- if (contentIndex == 0) {
- naviPrev = "";
- }
- if (contentIndex >= mBook->parts.size() - 1) {
- naviNext = "";
- }
-
- QWebFrame *frame = page()->currentFrame();
- QString headerScript = "document.body.innerHTML = '" +
- naviPrev + naviNext + "<br />" + "' + document.body.innerHTML;";
- QString trailerScript = "document.body.innerHTML += '<br /><br />" +
- naviPrev + naviNext + "';";
-
- frame->evaluateJavaScript(headerScript);
- frame->evaluateJavaScript(trailerScript);
- decorated = true;
-}
-
QString BookView::tmpPath()
{
return QDir::tempPath() + "/dorian";
}
-void BookView::extractIcons()
-{
- QFile next(ICON_PREFIX + QString("/next.png"));
- QFile prev(ICON_PREFIX + QString("/previous.png"));
-
- QDir().mkpath(tmpPath());
- next.copy(tmpPath() + "/next.png");
- prev.copy(tmpPath() + "/previous.png");
-}
-
-void BookView::removeIcons()
-{
- QFile(ICON_PREFIX + QString("/next.png")).remove();
- QFile(ICON_PREFIX + QString("/previous.png")).remove();
- QDir().rmpath(tmpPath());
-}
-
bool BookView::eventFilter(QObject *o, QEvent *e)
{
if (e->type() != QEvent::Paint && e->type() != QEvent::MouseMove) {
if (e->type() == QEvent::Resize) {
qDebug() << "BookView::eventFilter QEvent::Resize to"
<< page()->mainFrame()->contentsSize().height();
+ } else if (e->type() == QEvent::Timer) {
+ qDebug() << "BookView::eventFilter" << "QEvent::Timer"
+ << ((QTimerEvent *)e)->timerId();
} else {
qDebug() << "BookView::eventFilter" << Trace::event(e->type());
}
void BookView::onContentsSizeChanged(const QSize &size)
{
contentsHeight = size.height();
- if (decorated) {
- if (restorePositionAfterLoad) {
- qDebug() << "BookView::onContentSizeChanged: Time to restore";
- restorePositionAfterLoad = false;
- goToPosition(positionAfterLoad);
- }
+ if (restorePositionAfterLoad) {
+ qDebug() << "BookView::onContentSizeChanged: Time to restore";
+ restorePositionAfterLoad = false;
+ goToPosition(positionAfterLoad);
}
}
void BookView::goToPosition(qreal position)
{
- int scrollPos = (qreal)contentsHeight * position;
+ int scrollPos = (int)((qreal)contentsHeight * position);
page()->mainFrame()->setScrollPosition(QPoint(0, scrollPos));
// FIXME: update();
qDebug() << "BookView::goToPosition: To" << scrollPos << "("
void BookView::timerEvent(QTimerEvent *e)
{
- if (e->timerId() == scrollerMonitor) {
#ifdef Q_WS_MAEMO_5
+ if (e->timerId() == scrollerMonitor) {
if (scroller &&
((scroller->state() == QAbstractKineticScroller::AutoScrolling) ||
(scroller->state() == QAbstractKineticScroller::Pushing))) {
} else {
killTimer(scrollerMonitor);
}
-#endif // Q_WS_MAEMO_5
}
+#endif
+ QWebView::timerEvent(e);
}
void BookView::keyPressEvent(QKeyEvent* event)
frame->scroll(0, -height());
if (pos == frame->scrollPosition().y()) {
if (contentIndex > 0) {
- goToBookmark(Book::Bookmark(contentIndex - 1, 1.0));
+ Book::Bookmark bookmark(contentIndex - 1, 1.0);
+ mBook->setLastBookmark(contentIndex - 1, 1.0);
+ goToBookmark(bookmark);
}
} else {
showProgress();
if (pos == frame->scrollPosition().y()) {
goNext();
} else {
+ setLastBookmark();
showProgress();
}
}