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)
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;
}
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) {
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();
}
}
void progress(qreal p);
public slots:
+ /** Go to next part. */
void goPrevious();
+
+ /** Go to previous part. */
void goNext();
+
void onLoadFinished(bool ok);
void onSettingsChanged(const QString &key);
/** Handle main frame contents size changes. */
void onContentsSizeChanged(const QSize &size);
+ /** Go to previous page. */
+ void goPreviousPage();
+
+ /** Go to next page. */
+ void goNextPage();
+
protected:
void paintEvent(QPaintEvent *e);
void mousePressEvent(QMouseEvent *e);
void keyPressEvent(QKeyEvent *e);
private:
- /** Save navigation icons from resource to the file system. */
- void extractIcons();
-
- /** Remove extracted icons. */
- void removeIcons();
-
/** Load given part. */
void loadContent(int index);
/** Show progress. */
void showProgress();
- /** Go to previous page. */
- void goPreviousPage();
-
- /** Go to next page. */
- void goNextPage();
-
int contentIndex; /**< Current part in book. */
Book *mBook; /**< Book to show. */
bool restorePositionAfterLoad;
#include "bookfinder.h"
#include "progress.h"
#include "dyalog.h"
+#include "translucentbutton.h"
#ifdef DORIAN_TEST_MODEL
#include "modeltest.h"
frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
toolBar->addWidget(frame);
- fullScreenAction = addToolBarAction(this, SLOT(showBig()), "view-fullscreen");
+ fullScreenAction = addToolBarAction(this, SLOT(showBig()),
+ "view-fullscreen");
+
+ // Buttons for paging
+ previousButton = new TranslucentButton("back", this);
+ nextButton = new TranslucentButton("forward", this);
// Handle model changes
connect(Library::instance(), SIGNAL(nowReadingChanged()),
settings->setValue("lightson", settings->value("lightson"));
settings->setValue("usevolumekeys", settings->value("usevolumekeys"));
+ // Handle next/previous buttons
+ connect(nextButton, SIGNAL(triggered()), view, SLOT(goNextPage()));
+ connect(previousButton, SIGNAL(triggered()), view, SLOT(goPreviousPage()));
+
#ifdef DORIAN_TEST_MODEL
(void)new ModelTest(Library::instance(), this);
#endif
Trace t("MainWindow::showRegular");
fullScreenWindow->hide();
fullScreenWindow->leaveChildren();
- progress->setGeometry(0, 0, geometry().width(), PROGRESS_HEIGHT);
+ QRect geo = geometry();
+ progress->setGeometry(0, 0, geo.width(), PROGRESS_HEIGHT);
+ nextButton->setGeometry(geo.width() - 95, 0, 95, 95);
+ previousButton->setGeometry(0, geo.height() - 95, 95, 95);
QList<QWidget *> otherChildren;
- otherChildren.append(progress);
+ otherChildren << progress << previousButton << nextButton;
takeChildren(view, otherChildren);
progress->flash();
+ nextButton->flash();
+ previousButton->flash();
}
void MainWindow::showBig()
Trace t("MainWindow::showBig");
leaveChildren();
QList<QWidget *> otherChildren;
- otherChildren.append(progress);
- progress->setGeometry(0, 0, QApplication::desktop()->screenGeometry().width(),
- PROGRESS_HEIGHT);
+ otherChildren << progress << nextButton << previousButton;
+ QRect screen = QApplication::desktop()->screenGeometry();
+ progress->setGeometry(0, 0, screen.width(), PROGRESS_HEIGHT);
+ nextButton->setGeometry(screen.width() - 95, 0, 95, 95);
+ previousButton->setGeometry(0, screen.height() - 95, 95, 95);
+
fullScreenWindow->takeChildren(view, otherChildren);
fullScreenWindow->showFullScreen();
progress->flash();
+ nextButton->flash();
+ previousButton->flash();
}
void MainWindow::setCurrentBook(const QModelIndex ¤t)
void MainWindow::resizeEvent(QResizeEvent *e)
{
+ Trace t("MainWindow::resizeEvent");
progress->setGeometry(QRect(0, 0, e->size().width(), PROGRESS_HEIGHT));
+ qDebug() << "Toolbar height" << toolBar->height();
+ previousButton->setGeometry(0, e->size().height() - 95, 95, 95);
+ nextButton->setGeometry(e->size().width() - 95, toolBar->height(), 95, 95);
+ previousButton->flash();
+ nextButton->flash();
QMainWindow::resizeEvent(e);
}
class Book;
class FullScreenWindow;
class Progress;
+class TranslucentButton;
class MainWindow: public BookWindow
{
FullScreenWindow *fullScreenWindow;
int preventBlankingTimer;
Progress *progress;
+ TranslucentButton *previousButton;
+ TranslucentButton *nextButton;
};
#endif // MAINWINDOW_H
#include "translucentbutton.h"
+#include "trace.h"
#ifdef Q_WS_MAC
# define ICON_PREFIX ":/icons/mac/"
TranslucentButton::TranslucentButton(const QString &name_, QWidget *parent):
QWidget(parent), name(name_), opacity(1)
{
- setGeometry(0, 0, 50, 50);
+ setGeometry(0, 0, 95, 95);
timer = new QTimer(this);
timer->setSingleShot(true);
connect(timer, SIGNAL(timeout()), this, SLOT(stopFlash()));
opacity = 1;
update();
}
+
+void TranslucentButton::mousePressEvent(QMouseEvent *e)
+{
+ Q_UNUSED(e);
+ Trace t("TranslucentButton::mousePressEvent");
+ emit triggered();
+}
void flash(int duration = 3000);
void stopFlash();
+signals:
+ void triggered();
+
protected:
- virtual void paintEvent(QPaintEvent *);
+ void paintEvent(QPaintEvent *);
+ void mousePressEvent(QMouseEvent *);
QString name;
int opacity;
QTimer *timer;