BookView::BookView(QWidget *parent):
QWebView(parent), contentIndex(-1), mBook(0),
restorePositionAfterLoad(false), positionAfterLoad(0), loaded(false),
- contentsHeight(0), decorated(false), scrollerMonitor(-1)
+ contentsHeight(0), scrollerMonitor(-1)
{
Trace t("BookView::BookView");
settings()->setAttribute(QWebSettings::AutoLoadImages, true);
s->setValue("scheme", s->value("scheme", "default"));
setBook(0);
- extractIcons();
#ifdef Q_WS_MAEMO_5
scroller = property("kineticScroller").value<QAbstractKineticScroller *>();
#endif
BookView::~BookView()
{
Trace t("BookView::~BookView");
- removeIcons();
}
void BookView::loadContent(int index)
}
else {
loaded = false;
- decorated = false;
emit partLoadStart(index);
load(QUrl(contentFile));
}
return;
}
loaded = true;
- addNavigationBar();
onSettingsChanged("scheme");
emit partLoadEnd(contentIndex);
showProgress();
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) {
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);
}
}
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();
}
}