class Book;
+/** Show bookmark info. */
class BookmarkInfoDialog: public Dyalog
{
Q_OBJECT
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);
}
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()
-{
- decorated = true;
-}
-
QString BookView::tmpPath()
{
return QDir::tempPath() + "/dorian";
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);
}
}
/** Load given part. */
void loadContent(int index);
- /** Decorate web page frame with navigation icons. */
- void addNavigationBar();
-
/** Get temporary directory for extracting book contents. */
QString tmpPath();
bool loaded; /**< True if content has been loaded. */
bool mousePressed;
int contentsHeight; /**< Last know height of the frame. */
- bool decorated; /**< True after adding the arrows to the frame contents. */
int scrollerMonitor;
#ifdef Q_WS_MAEMO_5
#include <QtGui>
+/** Display developer tools. */
class DevTools: public QDialog
{
Q_OBJECT
model/bookfinder.cpp \
widgets/listwindow.cpp \
widgets/progress.cpp \
- widgets/bookwindow.cpp
+ widgets/adopterwindow.cpp
HEADERS += \
mainwindow.h \
model/bookfinder.h \
widgets/listwindow.h \
widgets/progress.h \
- widgets/bookwindow.h \
+ widgets/adopterwindow.h \
widgets/listview.h
RESOURCES += \
class QWidget;
class Book;
+/** Display book information. */
class InfoDialog: public Dyalog
{
Q_OBJECT
class InfoWindow;
class SortedLibrary;
+/** Manage library. */
class LibraryDialog: public ListWindow
{
Q_OBJECT
;
MainWindow::MainWindow(QWidget *parent):
- BookWindow(parent), view(0), preventBlankingTimer(-1)
+ AdopterWindow(parent), view(0), preventBlankingTimer(-1)
{
Trace t("MainWindow::MainWindow");
#ifdef Q_WS_MAEMO_5
progress = new Progress(central);
// Tool bar
+
setUnifiedTitleAndToolBarOnMac(true);
settings = new QDialog(this);
toolBar = addToolBar("controls");
fullScreenAction = addToolBarAction(this, SLOT(showBig()),
"view-fullscreen");
- // Buttons for paging
+ // Buttons on top of the book view
previousButton = new TranslucentButton("back", this);
nextButton = new TranslucentButton("forward", this);
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()));
+ // Handle book view buttons
+ connect(nextButton, SIGNAL(triggered()), this, SLOT(goToNextPage()));
+ connect(previousButton, SIGNAL(triggered()), this, SLOT(goToPreviousPage()));
#ifdef DORIAN_TEST_MODEL
(void)new ModelTest(Library::instance(), this);
Trace t("MainWindow::showRegular");
fullScreenWindow->hide();
fullScreenWindow->leaveChildren();
+
+ QList<QWidget *> otherChildren;
+ otherChildren << progress << previousButton << nextButton;
+ takeChildren(view, otherChildren);
QRect geo = geometry();
- qDebug() << "Geometry:" << geo;
+ qDebug() << "Geometry" << geo << "toolbar" << toolBar->height();
progress->setGeometry(0, 0, geo.width(), PROGRESS_HEIGHT);
#ifdef Q_WS_MAEMO_5
- previousButton->setGeometry(0,geo.height() - toolBar->height() - 95,
- 95, 95);
- nextButton->setGeometry(geo.width() - 95, 0, 95, 95);
+ previousButton->setGeometry(0,
+ geo.height() - toolBar->height() - TranslucentButton::pixels,
+ TranslucentButton::pixels, TranslucentButton::pixels);
+ nextButton->setGeometry(geo.width() - TranslucentButton::pixels, 0,
+ TranslucentButton::pixels, TranslucentButton::pixels);
#else
- previousButton->setGeometry(0, geo.height() - 95, 95, 95);
- nextButton->setGeometry(geo.width() - 95, toolBar->height(), 95, 95);
+ previousButton->setGeometry(0, geo.height() - TranslucentButton::pixels,
+ TranslucentButton::pixels, TranslucentButton::pixels);
+ nextButton->setGeometry(geo.width() - TranslucentButton::pixels,
+ toolBar->height(), TranslucentButton::pixels, TranslucentButton::pixels);
#endif // Q_WS_MAEMO_5
-
- QList<QWidget *> otherChildren;
- otherChildren << progress << previousButton << nextButton;
- takeChildren(view, otherChildren);
+ qDebug() << "previousButton geometry" << previousButton->geometry();
progress->flash();
- nextButton->flash();
- previousButton->flash();
+ nextButton->show();
+ previousButton->show();
+ nextButton->flash(1500);
+ previousButton->flash(1500);
}
void MainWindow::showBig()
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);
+ nextButton->setGeometry(screen.width() - TranslucentButton::pixels, 0,
+ TranslucentButton::pixels, TranslucentButton::pixels);
+ previousButton->setGeometry(0, screen.height() - TranslucentButton::pixels,
+ TranslucentButton::pixels, TranslucentButton::pixels);
fullScreenWindow->takeChildren(view, otherChildren);
fullScreenWindow->showFullScreen();
progress->flash();
- nextButton->flash();
- previousButton->flash();
+ nextButton->flash(1500);
+ previousButton->flash(1500);
}
void MainWindow::setCurrentBook(const QModelIndex ¤t)
progress->setGeometry(QRect(0, 0, e->size().width(), PROGRESS_HEIGHT));
qDebug() << "Toolbar height" << toolBar->height();
#ifdef Q_WS_MAEMO_5
- previousButton->setGeometry(0, e->size().height() - toolBar->height() - 95,
- 95, 95);
- nextButton->setGeometry(e->size().width() - 95, 0, 95, 95);
+ previousButton->setGeometry(0,
+ e->size().height() - toolBar->height() - TranslucentButton::pixels,
+ TranslucentButton::pixels, TranslucentButton::pixels);
+ nextButton->setGeometry(e->size().width() - TranslucentButton::pixels, 0,
+ TranslucentButton::pixels, TranslucentButton::pixels);
#else
- previousButton->setGeometry(0, e->size().height() - 95, 95, 95);
- nextButton->setGeometry(e->size().width() - 95, toolBar->height(), 95, 95);
+ previousButton->setGeometry(0, e->size().height() - TranslucentButton::pixels,
+ TranslucentButton::pixels, TranslucentButton::pixels);
+ nextButton->setGeometry(e->size().width() - TranslucentButton::pixels,
+ toolBar->height(), TranslucentButton::pixels, TranslucentButton::pixels);
#endif // Q_WS_MAEMO_5
- previousButton->flash();
- nextButton->flash();
+ qDebug() << "previousButton geometry" << previousButton->geometry();
+ previousButton->flash(1500);
+ nextButton->flash(1500);
QMainWindow::resizeEvent(e);
}
aboutDialog->addWidget(label);
aboutDialog->show();
}
+
+
+void MainWindow::goToNextPage()
+{
+ nextButton->flash(1500);
+ previousButton->flash(1500);
+ view->goNextPage();
+}
+
+void MainWindow::goToPreviousPage()
+{
+ nextButton->flash(1500);
+ previousButton->flash(1500);
+ view->goPreviousPage();
+}
#include <QtGui>
-#include "bookwindow.h"
+#include "adopterwindow.h"
class QString;
class QModelIndex;
class Progress;
class TranslucentButton;
-class MainWindow: public BookWindow
+class MainWindow: public AdopterWindow
{
Q_OBJECT
void showChapters();
void onGoToChapter(int index);
void about();
+ void goToNextPage();
+ void goToPreviousPage();
protected:
void closeEvent(QCloseEvent *event);
class QLabel;
class ToolButtonBox;
+/** Display settings. */
class SettingsWindow: public QMainWindow
{
Q_OBJECT
#include <QTime>
#include <QEvent>
+/** Trace helper. */
class Trace
{
public:
--- /dev/null
+#include <QtGui>
+
+#ifdef Q_WS_MAEMO_5
+# include <QtGui/QX11Info>
+# include <X11/Xlib.h>
+# include <X11/Xatom.h>
+#endif // Q_WS_MAEMO_5
+
+#include "adopterwindow.h"
+#include "trace.h"
+
+AdopterWindow::AdopterWindow(QWidget *parent):
+ QMainWindow(parent), grabbingZoomKeys(false), mainChild(0)
+{
+#ifdef Q_WS_MAEMO_5
+ setAttribute(Qt::WA_Maemo5StackedWindow, true);
+#endif // Q_WS_MAEMO_5
+
+ QFrame *frame = new QFrame(this);
+ QVBoxLayout *layout = new QVBoxLayout(frame);
+ layout->setMargin(0);
+ frame->setLayout(layout);
+ setCentralWidget(frame);
+}
+
+void AdopterWindow::takeChildren(QWidget *main, const QList<QWidget *> &others)
+{
+ Trace t("AdopterWindow::takeChildren");
+ leaveChildren();
+ if (main) {
+ mainChild = main;
+ mainChild->setParent(centralWidget());
+ centralWidget()->layout()->addWidget(mainChild);
+ mainChild->show();
+ }
+ foreach (QWidget *child, others) {
+ if (child) {
+ child->setParent(this);
+ }
+ }
+}
+
+void AdopterWindow::leaveChildren()
+{
+ Trace t("AdopterWindow::leaveChildren");
+ if (mainChild) {
+ centralWidget()->layout()->removeWidget(mainChild);
+ mainChild = 0;
+ }
+}
+
+void AdopterWindow::grabZoomKeys(bool grab)
+{
+ Trace t("AdopterWindow::grabZoomKeys");
+ grabbingZoomKeys = grab;
+ doGrabZoomKeys(grab);
+}
+
+void AdopterWindow::showEvent(QShowEvent *e)
+{
+ Trace t("AdopterWindow::showEvent");
+ doGrabZoomKeys(grabbingZoomKeys);
+ QMainWindow::showEvent(e);
+}
+
+void AdopterWindow::doGrabZoomKeys(bool grab)
+{
+ Trace t("AdopterWindow::doGrabZoomKeys");
+#ifdef Q_WS_MAEMO_5
+ if (!isVisible()) {
+ qDebug() << "Not visible - skipping";
+ }
+ if (!winId()) {
+ qDebug() << "Could not get window ID - skipping";
+ return;
+ }
+ unsigned long val = grab? 1: 0;
+ Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
+ if (!atom) {
+ qCritical() << "Unable to obtain _HILDON_ZOOM_KEY_ATOM";
+ return;
+ }
+ XChangeProperty(QX11Info::display(),
+ winId(),
+ atom,
+ XA_INTEGER,
+ 32,
+ PropModeReplace,
+ reinterpret_cast<unsigned char *>(&val),
+ 1);
+#else
+ Q_UNUSED(grab);
+#endif // Q_WS_MAEMO_5
+}
--- /dev/null
+#ifndef ADOPTERWINDOW_H
+#define ADOPTERWINDOW_H
+
+#include <QMainWindow>
+#include <QList>
+
+class QWidget;
+
+/**
+ * A main window that can adopt other windows' children, and grabs the
+ * zoom (volume) keys on Maemo.
+ */
+class AdopterWindow: public QMainWindow
+{
+ Q_OBJECT
+public:
+ explicit AdopterWindow(QWidget *parent = 0);
+ void grabZoomKeys(bool grab);
+ void takeChildren(QWidget *main, const QList<QWidget *> &others);
+ void leaveChildren();
+
+signals:
+
+public slots:
+
+protected:
+ void showEvent(QShowEvent *e);
+ void doGrabZoomKeys(bool grab);
+ bool grabbingZoomKeys;
+ QWidget *mainChild;
+};
+
+#endif // ADOPTERWINDOW_H
+++ /dev/null
-#include <QtGui>
-
-#ifdef Q_WS_MAEMO_5
-# include <QtGui/QX11Info>
-# include <X11/Xlib.h>
-# include <X11/Xatom.h>
-#endif // Q_WS_MAEMO_5
-
-#include "bookwindow.h"
-#include "trace.h"
-
-BookWindow::BookWindow(QWidget *parent):
- QMainWindow(parent), grabbingZoomKeys(false), mainChild(0)
-{
-#ifdef Q_WS_MAEMO_5
- setAttribute(Qt::WA_Maemo5StackedWindow, true);
-#endif // Q_WS_MAEMO_5
-
- QFrame *frame = new QFrame(this);
- QVBoxLayout *layout = new QVBoxLayout(frame);
- layout->setMargin(0);
- frame->setLayout(layout);
- setCentralWidget(frame);
-}
-
-void BookWindow::takeChildren(QWidget *main, const QList<QWidget *> &others)
-{
- Trace t("BookWindow::takeChildren");
- leaveChildren();
- if (main) {
- mainChild = main;
- mainChild->setParent(centralWidget());
- centralWidget()->layout()->addWidget(mainChild);
- mainChild->show();
- }
- foreach (QWidget *child, others) {
- if (child) {
- child->setParent(this);
- }
- }
-}
-
-void BookWindow::leaveChildren()
-{
- Trace t("BookWindow::leaveChildren");
- if (mainChild) {
- centralWidget()->layout()->removeWidget(mainChild);
- mainChild = 0;
- }
-}
-
-void BookWindow::grabZoomKeys(bool grab)
-{
- Trace t("BookWindow::grabZoomKeys");
- grabbingZoomKeys = grab;
- doGrabZoomKeys(grab);
-}
-
-void BookWindow::showEvent(QShowEvent *e)
-{
- Trace t("BookWindow::showEvent");
- doGrabZoomKeys(grabbingZoomKeys);
- QMainWindow::showEvent(e);
-}
-
-void BookWindow::doGrabZoomKeys(bool grab)
-{
- Trace t("BookWindow::doGrabZoomKeys");
-#ifdef Q_WS_MAEMO_5
- if (!isVisible()) {
- qDebug() << "Not visible - skipping";
- }
- if (!winId()) {
- qDebug() << "Could not get window ID - skipping";
- return;
- }
- unsigned long val = grab? 1: 0;
- Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
- if (!atom) {
- qCritical() << "Unable to obtain _HILDON_ZOOM_KEY_ATOM";
- return;
- }
- XChangeProperty(QX11Info::display(),
- winId(),
- atom,
- XA_INTEGER,
- 32,
- PropModeReplace,
- reinterpret_cast<unsigned char *>(&val),
- 1);
-#else
- Q_UNUSED(grab);
-#endif // Q_WS_MAEMO_5
-}
+++ /dev/null
-#ifndef BOOKWINDOW_H
-#define BOOKWINDOW_H
-
-#include <QMainWindow>
-#include <QList>
-
-class QWidget;
-
-class BookWindow: public QMainWindow
-{
- Q_OBJECT
-public:
- explicit BookWindow(QWidget *parent = 0);
- void grabZoomKeys(bool grab);
- void takeChildren(QWidget *main, const QList<QWidget *> &others);
- void leaveChildren();
-
-signals:
-
-public slots:
-
-protected:
- void showEvent(QShowEvent *e);
- void doGrabZoomKeys(bool grab);
- bool grabbingZoomKeys;
- QWidget *mainChild;
-};
-
-#endif // BOOKWINDOW_H
#include "translucentbutton.h"
#include "trace.h"
-FullScreenWindow::FullScreenWindow(QWidget *parent): BookWindow(parent)
+FullScreenWindow::FullScreenWindow(QWidget *parent): AdopterWindow(parent)
{
Q_ASSERT(parent);
#ifdef Q_WS_MAEMO_5
frame->setLayout(layout);
setCentralWidget(frame);
restoreButton = new TranslucentButton("view-normal", this);
+ QRect screen = QApplication::desktop()->screenGeometry();
+ restoreButton->setGeometry((screen.width() - TranslucentButton::pixels) / 2,
+ screen.height() - TranslucentButton::pixels - 9,
+ TranslucentButton::pixels, TranslucentButton::pixels);
+ connect(restoreButton, SIGNAL(triggered()), this, SIGNAL(restore()));
}
void FullScreenWindow::showFullScreen()
restoreButton->flash();
}
-void FullScreenWindow::MOUSE_ACTIVATE_EVENT(QMouseEvent *event)
-{
- Trace t("FullScreenWindow::MOUSE_ACTIVATE_EVENT");
- if (fullScreenZone().contains(event->x(), event->y())) {
- emit restore();
- } else {
- restoreButton->flash(700);
- }
- QMainWindow::MOUSE_ACTIVATE_EVENT(event);
-}
-
-QRect FullScreenWindow::fullScreenZone() const
-{
- return QRect(width() / 2 - 45, height() - 104, 95, 95);
-}
-
void FullScreenWindow::resizeEvent(QResizeEvent *e)
{
- restoreButton->setGeometry(fullScreenZone());
- QMainWindow::resizeEvent(e);
+ Q_UNUSED(e);
+ QRect screen = QApplication::desktop()->screenGeometry();
+ restoreButton->setGeometry(screen.width() - TranslucentButton::pixels - 9,
+ screen.height() - TranslucentButton::pixels - 9,
+ TranslucentButton::pixels, TranslucentButton::pixels);
}
#include <QRect>
#include <QObject>
-#include "bookwindow.h"
+#include "adopterwindow.h"
class QWidget;
class QMouseEvent;
class QResizeEvent;
class TranslucentButton;
-/** A full screen window that can adopt a child widget from another window. */
-class FullScreenWindow: public BookWindow
+/** A full screen window with a restore button. */
+class FullScreenWindow: public AdopterWindow
{
Q_OBJECT
void showFullScreen();
signals:
+ /** Emitted when the restore button is pressed. */
void restore();
protected:
-#ifdef Q_WS_MAEMO_5
-# define MOUSE_ACTIVATE_EVENT mouseReleaseEvent
-#else
-# define MOUSE_ACTIVATE_EVENT mousePressEvent
-#endif
- virtual void MOUSE_ACTIVATE_EVENT(QMouseEvent *event);
- virtual void resizeEvent(QResizeEvent *event);
- QRect fullScreenZone() const;
+ void resizeEvent(QResizeEvent *e);
TranslucentButton *restoreButton;
};
#include <QListView>
+/** Same as QListView, except contentsHeight() is public. */
class ListView: public QListView
{
Q_OBJECT
+
public:
explicit ListView(QWidget *parent = 0): QListView(parent) {
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
#include <QWidget>
#include <QLabel>
+/** Subtle progress bar. */
class Progress: public QLabel
{
Q_OBJECT
+#include <QtGui>
+
#include "translucentbutton.h"
#include "trace.h"
# define ICON_PREFIX ":/icons/"
#endif
+const int TranslucentButton::pixels = 95;
+
TranslucentButton::TranslucentButton(const QString &name_, QWidget *parent):
- QWidget(parent), name(name_), opacity(1)
+ QLabel(parent), name(name_), transparent(true)
{
- setGeometry(0, 0, 95, 95);
+ setGeometry(0, 0, pixels, pixels);
timer = new QTimer(this);
timer->setSingleShot(true);
connect(timer, SIGNAL(timeout()), this, SLOT(stopFlash()));
void TranslucentButton::paintEvent(QPaintEvent *)
{
QPainter painter(this);
- if (opacity < 1) {
+ if (!transparent) {
painter.setRenderHint(QPainter::Antialiasing, true);
painter.drawPixmap(0, 0, QPixmap(ICON_PREFIX + name + ".png").scaled(
- QSize(95, 95), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
+ QSize(pixels, pixels), Qt::IgnoreAspectRatio,
+ Qt::SmoothTransformation));
} else {
- painter.fillRect(0, 0, 95, 95, Qt::NoBrush);
+ painter.fillRect(0, 0, pixels, pixels, Qt::NoBrush);
}
}
void TranslucentButton::flash(int duration)
{
- opacity = 0;
+ raise();
+ transparent = false;
update();
timer->start(duration);
}
void TranslucentButton::stopFlash()
{
- opacity = 1;
+ transparent = true;
update();
}
-void TranslucentButton::mousePressEvent(QMouseEvent *e)
+void TranslucentButton::mouseReleaseEvent(QMouseEvent *e)
{
Q_UNUSED(e);
- Trace t("TranslucentButton::mousePressEvent");
emit triggered();
e->accept();
}
#ifndef TRANSLUCENTBUTTON_H
#define TRANSLUCENTBUTTON_H
-#include <QtGui>
+#include <QLabel>
#include <QString>
-class TranslucentButton: public QWidget
+class QWidget;
+class QPaintEvent;
+class QMouseEvent;
+class QTimer;
+
+/**
+ * A button that is transparent, but can temporarily made opaque by flashing it.
+ */
+class TranslucentButton: public QLabel
{
Q_OBJECT
public:
- explicit TranslucentButton(const QString &name, QWidget *parent);
+ static const int pixels;
+ explicit TranslucentButton(const QString &iconName, QWidget *parent);
public slots:
void flash(int duration = 3000);
protected:
void paintEvent(QPaintEvent *);
- void mousePressEvent(QMouseEvent *);
+ void mouseReleaseEvent(QMouseEvent *);
QString name;
- int opacity;
+ bool transparent;
QTimer *timer;
};