setWindowTitle(tr("Bookmark Details"));
Book::Bookmark bookmark = book->bookmarks()[index];
- QString contentId = book->toc[bookmark.part];
+ QString contentId = book->parts[bookmark.part];
QString contentTitle = book->content[contentId].name;
QLabel *info = new QLabel(contentTitle + "\nAt " +
QString::number((int)(bookmark.pos*100)) + "%", this);
list = new QListWidget(this);
list->setSelectionMode(QAbstractItemView::SingleSelection);
foreach (Book::Bookmark bookmark, book_->bookmarks()) {
- QString contentId = book_->toc[bookmark.part];
+ QString contentId = book_->parts[bookmark.part];
QString contentTitle = book_->content[contentId].name;
(void)new QListWidgetItem(QIcon(":icons/bookmark.png"), contentTitle +
"\nAt " + QString::number((int)(bookmark.pos*100)) + "%", list);
#include "library.h"
#include "settings.h"
#include "trace.h"
+#include "progress.h"
#ifdef Q_WS_MAC
# define ICON_PREFIX ":/icons/mac/"
addNavigationBar();
onSettingsChanged("scheme");
emit partLoadEnd(contentIndex);
+ showProgress();
}
void BookView::onSettingsChanged(const QString &key)
e->ignore();
}
+void BookView::mouseReleaseEvent(QMouseEvent *e)
+{
+ QWebView::mouseReleaseEvent(e);
+ showProgress();
+}
+
+void BookView::wheelEvent(QWheelEvent *e)
+{
+ QWebView::wheelEvent(e);
+ showProgress();
+}
+
void BookView::addBookmark()
{
Trace t("BookView::addBookmark");
mousePressed = true;
break;
case QEvent::MouseButtonRelease:
+ showProgress();
mousePressed = false;
break;
case QEvent::MouseMove:
Trace::trace(QString("BookView::goToPosition: To %1 (%2%, height %3)").
arg(scrollPos).arg(position * 100).arg(contentsHeight));
}
+
+void BookView::showProgress()
+{
+ if (mBook) {
+ qreal pos = (qreal)(page()->mainFrame()->scrollPosition().y()) /
+ (qreal)contentsHeight;
+ emit progress(mBook->getProgress(contentIndex, pos));
+ }
+}
#include "book.h"
class QModelIndex;
+class Progress;
/** Visual representation of a book. */
class BookView: public QWebView
/** Signal button press when the real event has been suppressed. */
void suppressedMouseButtonPress();
+ /** Signal progress in reading the book. */
+ void progress(qreal p);
+
public slots:
void goPrevious();
void goNext();
void onContentsSizeChanged(const QSize &size);
protected:
- virtual void paintEvent(QPaintEvent *e);
- virtual void mousePressEvent(QMouseEvent *e);
+ void paintEvent(QPaintEvent *e);
+ void mousePressEvent(QMouseEvent *e);
+ void mouseReleaseEvent(QMouseEvent *e);
+ void wheelEvent(QWheelEvent *);
bool eventFilter(QObject *o, QEvent *e);
- virtual void leaveEvent(QEvent *);
- virtual void enterEvent(QEvent *);
+ void leaveEvent(QEvent *e);
+ void enterEvent(QEvent *e);
private:
/** Save navigation icons from resource to the file system. */
/** Go to a given (relative) position in current part. */
void goToPosition(qreal position);
+ /** Show progress. */
+ void showProgress();
+
int contentIndex; /**< Current part in book. */
Book *mBook; /**< Book to show. */
bool restorePositionAfterLoad;
widgets/toolbuttonbox.cpp \
model/bookfinder.cpp \
widgets/listwindow.cpp \
- foldersdialog.cpp
+ foldersdialog.cpp \
+ widgets/progress.cpp
HEADERS += \
mainwindow.h \
widgets/toolbuttonbox.h \
model/bookfinder.h \
widgets/listwindow.h \
- foldersdialog.h
+ foldersdialog.h \
+ widgets/progress.h
RESOURCES += \
dorian.qrc
#include "fullscreenwindow.h"
#include "trace.h"
#include "bookfinder.h"
+#include "progress.h"
#ifdef DORIAN_TEST_MODEL
#include "modeltest.h"
# define ICON_PREFIX ":/icons/"
#endif
+const int PROGRESS_HEIGHT = 17;
+
MainWindow::MainWindow(QWidget *parent):
QMainWindow(parent), view(0), preventBlankingTimer(-1)
{
view->show();
layout->addWidget(view);
+ // Progress
+ progress = new Progress(central);
+
// Tool bar
setUnifiedTitleAndToolBarOnMac(true);
settings = new QDialog(this);
connect(view, SIGNAL(chapterLoadEnd(int)),
this, SLOT(onChapterLoadEnd(int)));
+ // Handle progress
+ connect(view, SIGNAL(progress(qreal)), progress, SLOT(setProgress(qreal)));
+
// Shadow window for full screen
fullScreenWindow = new FullScreenWindow(this);
connect(fullScreenWindow, SIGNAL(restore()), this, SLOT(showRegular()));
bookFinder->moveToThread(&bookFinderThread);
bookFinderThread.start();
-#if 0
- bool ret = QMetaObject::invokeMethod(
- bookFinder,
- "find",
- Q_ARG(QStringList, QStringList(QString("/Users/polster/Books"))),
- Q_ARG(QStringList, library->bookPaths()));
- t.trace(QString("Invoking BookFinder::find ") + (ret?"succeeded":"failed"));
-#endif
-
#ifdef DORIAN_TEST_MODEL
(void)new ModelTest(Library::instance(), this);
#endif
fullScreenWindow->hide();
fullScreenWindow->leaveChild();
view->setParent(centralWidget());
+ progress->setParent(centralWidget());
+ progress->setGeometry(0, 0, geometry().width(), PROGRESS_HEIGHT);
centralWidget()->layout()->addWidget(view);
+ progress->flash();
}
void MainWindow::showBig()
{
Trace t("MainWindow::showBig");
centralWidget()->layout()->removeWidget(view);
+ progress->setParent(fullScreenWindow);
+ progress->setGeometry(0, 0, QApplication::desktop()->screenGeometry().width(),
+ PROGRESS_HEIGHT);
fullScreenWindow->takeChild(view);
fullScreenWindow->showFullScreen();
+ progress->flash();
}
void MainWindow::setCurrentBook(const QModelIndex ¤t)
Trace::trace("MainWindow::timerEvent: Prevent display blanking");
}
}
+
+void MainWindow::resizeEvent(QResizeEvent *e)
+{
+ progress->setGeometry(QRect(0, 0, e->size().width(), PROGRESS_HEIGHT));
+ QMainWindow::resizeEvent(e);
+}
class BookView;
class Book;
class FullScreenWindow;
+class Progress;
class MainWindow: public QMainWindow
{
void onGoToChapter(int index);
protected:
- virtual void closeEvent(QCloseEvent *event);
- virtual void timerEvent(QTimerEvent *event);
+ void closeEvent(QCloseEvent *event);
+ void timerEvent(QTimerEvent *event);
+ void resizeEvent(QResizeEvent *event);
private:
void setCurrentBook(const QModelIndex ¤t);
int preventBlankingTimer;
BookFinder *bookFinder;
BookFinderThread bookFinderThread;
+ Progress *progress;
};
#endif // MAINWINDOW_H
}
// Calculate book part sizes
+ size = 0;
foreach (QString part, parts) {
QFileInfo info(content[part].href);
content[part].size = info.size();
+ size += content[part].size;
t.trace(QString("Size of part %1: %2").arg(part).arg(content[part].size));
}
}
return partIndex;
}
+
+qreal Book::getProgress(int part, qreal position)
+{
+ Q_ASSERT(part < parts.size());
+ QString key;
+ qreal partSize = 0;
+ for (int i = 0; i < part; i++) {
+ key = parts[i];
+ partSize += content[key].size;
+ }
+ key = parts[part];
+ partSize += content[key].size * position;
+ return partSize / (qreal)size;
+}
/** Get part index from chapter index. */
int partFromChapter(int index);
+ /** Get progress (0..1) corresponding to part index and part position. */
+ qreal getProgress(int part, qreal position);
+
QString title; //< Book title from EPUB.
QStringList parts; //< EPUB part list.
QHash<QString, ContentItem> content; //< Content items from EPUB.
QString tocPath; //< Path to toc ncx.
QString coverPath; //< Path to cover html.
QStringList chapters; //< Main navigation items from EPUB.
+ qint64 size; //< Size of all parts.
signals:
/** Emitted if @see open() succeeds. */
* Improve cover image display
* Fix naming: book parts vs. chapters
+ * Show reading progress
-- Akos Polster <akos@pipacs.com> Sat, 7 Aug 2010 20:00:00 +0200
--- /dev/null
+#include <QtGui>
+
+#include "progress.h"
+#include "trace.h"
+
+Progress::Progress(QWidget *parent): QLabel(parent), progress(0), timer(-1)
+{
+ hide();
+}
+
+void Progress::setProgress(qreal p)
+{
+ if (progress != p) {
+ progress = p;
+ flash();
+ update();
+ }
+}
+
+void Progress::paintEvent(QPaintEvent *e)
+{
+ Q_UNUSED(e);
+ QPainter painter(this);
+ painter.setBrush(QBrush(QColor(100, 100, 100, 177)));
+ painter.setPen(Qt::NoPen);
+ int w = int(width() * progress);
+ int h = height();
+ painter.drawRect(0, 0, w, h);
+ painter.setBrush(QBrush(QColor(100, 100, 100, 50)));
+ painter.drawRect(w, 0, width(), h);
+}
+
+void Progress::flash()
+{
+ killTimer(timer);
+ show();
+ timer = startTimer(400);
+}
+
+void Progress::timerEvent(QTimerEvent *e)
+{
+ if (e->timerId() == timer) {
+ killTimer(timer);
+ hide();
+ }
+}
--- /dev/null
+#ifndef PROGRESS_H
+#define PROGRESS_H
+
+#include <QWidget>
+#include <QLabel>
+
+class Progress: public QLabel
+{
+ Q_OBJECT
+
+public:
+ explicit Progress(QWidget *parent = 0);
+
+signals:
+
+public slots:
+ void setProgress(qreal p);
+ void flash();
+
+protected:
+ void paintEvent(QPaintEvent *e);
+ void timerEvent(QTimerEvent *e);
+ qreal progress;
+ int timer;
+};
+
+#endif // PROGRESS_H
protected:
virtual void paintEvent(QPaintEvent *);
-
-private:
QString name;
qreal mOpacity;
};