From 966f44ba3692d5f32191e860f2ee795c5b939bc3 Mon Sep 17 00:00:00 2001 From: Akos Polster Date: Wed, 1 Sep 2010 14:26:59 +0200 Subject: [PATCH] Navigate by pages instead of book parts. --- bookview.cpp | 58 +++-------------------------------------- bookview.h | 22 +++++++--------- mainwindow.cpp | 38 ++++++++++++++++++++++----- mainwindow.h | 3 +++ widgets/translucentbutton.cpp | 10 ++++++- widgets/translucentbutton.h | 6 ++++- 6 files changed, 63 insertions(+), 74 deletions(-) diff --git a/bookview.cpp b/bookview.cpp index 3003165..0acbdb3 100644 --- a/bookview.cpp +++ b/bookview.cpp @@ -78,7 +78,6 @@ BookView::BookView(QWidget *parent): s->setValue("scheme", s->value("scheme", "default")); setBook(0); - extractIcons(); #ifdef Q_WS_MAEMO_5 scroller = property("kineticScroller").value(); #endif @@ -87,7 +86,6 @@ BookView::BookView(QWidget *parent): BookView::~BookView() { Trace t("BookView::~BookView"); - removeIcons(); } void BookView::loadContent(int index) @@ -299,40 +297,6 @@ void BookView::addBookmark() void BookView::addNavigationBar() { - Trace t("BookView::addNavigationBar"); - if (!mBook) { - return; - } - - QString naviPrev = - "" - "" - ""; - QString naviNext = - "" - "" - ""; - if (contentIndex == 0) { - naviPrev = ""; - } - if (contentIndex >= mBook->parts.size() - 1) { - naviNext = ""; - } - - QWebFrame *frame = page()->currentFrame(); - QString headerScript = "document.body.innerHTML = '" + - naviPrev + naviNext + "
" + "' + document.body.innerHTML;"; - QString trailerScript = "document.body.innerHTML += '

" + - naviPrev + naviNext + "';"; - - frame->evaluateJavaScript(headerScript); - frame->evaluateJavaScript(trailerScript); decorated = true; } @@ -341,23 +305,6 @@ 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) { @@ -484,7 +431,9 @@ void BookView::goPreviousPage() 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(); @@ -500,6 +449,7 @@ void BookView::goNextPage() if (pos == frame->scrollPosition().y()) { goNext(); } else { + setLastBookmark(); showProgress(); } } diff --git a/bookview.h b/bookview.h index 54c13ad..4202ac1 100644 --- a/bookview.h +++ b/bookview.h @@ -39,8 +39,12 @@ signals: 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); @@ -50,6 +54,12 @@ public slots: /** 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); @@ -61,12 +71,6 @@ protected: 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); @@ -82,12 +86,6 @@ private: /** 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; diff --git a/mainwindow.cpp b/mainwindow.cpp index 46da063..aad12c5 100755 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -31,6 +31,7 @@ #include "bookfinder.h" #include "progress.h" #include "dyalog.h" +#include "translucentbutton.h" #ifdef DORIAN_TEST_MODEL #include "modeltest.h" @@ -113,7 +114,12 @@ MainWindow::MainWindow(QWidget *parent): 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()), @@ -161,6 +167,10 @@ MainWindow::MainWindow(QWidget *parent): 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 @@ -180,11 +190,16 @@ void MainWindow::showRegular() 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 otherChildren; - otherChildren.append(progress); + otherChildren << progress << previousButton << nextButton; takeChildren(view, otherChildren); progress->flash(); + nextButton->flash(); + previousButton->flash(); } void MainWindow::showBig() @@ -192,12 +207,17 @@ void MainWindow::showBig() Trace t("MainWindow::showBig"); leaveChildren(); QList 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) @@ -375,7 +395,13 @@ void MainWindow::timerEvent(QTimerEvent *event) 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); } diff --git a/mainwindow.h b/mainwindow.h index 4c4af45..c380a26 100755 --- a/mainwindow.h +++ b/mainwindow.h @@ -12,6 +12,7 @@ class BookView; class Book; class FullScreenWindow; class Progress; +class TranslucentButton; class MainWindow: public BookWindow { @@ -67,6 +68,8 @@ private: FullScreenWindow *fullScreenWindow; int preventBlankingTimer; Progress *progress; + TranslucentButton *previousButton; + TranslucentButton *nextButton; }; #endif // MAINWINDOW_H diff --git a/widgets/translucentbutton.cpp b/widgets/translucentbutton.cpp index 7a6d6fe..fdd9d46 100644 --- a/widgets/translucentbutton.cpp +++ b/widgets/translucentbutton.cpp @@ -1,4 +1,5 @@ #include "translucentbutton.h" +#include "trace.h" #ifdef Q_WS_MAC # define ICON_PREFIX ":/icons/mac/" @@ -9,7 +10,7 @@ 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())); @@ -40,3 +41,10 @@ void TranslucentButton::stopFlash() opacity = 1; update(); } + +void TranslucentButton::mousePressEvent(QMouseEvent *e) +{ + Q_UNUSED(e); + Trace t("TranslucentButton::mousePressEvent"); + emit triggered(); +} diff --git a/widgets/translucentbutton.h b/widgets/translucentbutton.h index 44b56c2..00035c1 100644 --- a/widgets/translucentbutton.h +++ b/widgets/translucentbutton.h @@ -15,8 +15,12 @@ public slots: 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; -- 1.7.9.5