#include "bookview.h"
#include "platform.h"
#include "settings.h"
+#include "progress.h"
+#include "translucentbutton.h"
AdopterWindow::AdopterWindow(QWidget *parent):
- QMainWindow(parent), bookView(0), grabbingVolumeKeys(false), toolBar(0)
+ QMainWindow(parent), bookView(0), grabbingVolumeKeys(false), toolBar(0),
+ progress(0), previousButton(0), nextButton(0)
{
TRACE;
this, SLOT(onSettingsChanged(const QString &)));
}
-void AdopterWindow::takeChildren(BookView *view, const QList<QWidget *> &others)
+void AdopterWindow::takeBookView(BookView *view,
+ Progress *prog,
+ TranslucentButton *previous,
+ TranslucentButton *next)
{
TRACE;
- leaveChildren();
- if (view) {
- bookView = view;
- bookView->setParent(this);
- bookView->show();
- QVBoxLayout *layout =
- qobject_cast<QVBoxLayout *>(centralWidget()->layout());
- layout->addWidget(bookView, 1);
- }
- foreach (QWidget *child, others) {
- if (child) {
- child->setParent(this);
- }
- }
+
+ Q_ASSERT(view);
+ Q_ASSERT(prog);
+ Q_ASSERT(previous);
+ Q_ASSERT(next);
+
+ leaveBookView();
+
+ bookView = view;
+ bookView->setParent(this);
+ bookView->show();
+ centralWidget()->layout()->addWidget(bookView);
+
+ progress = prog;
+ previousButton = previous;
+ nextButton = next;
+ progress->setParent(this);
+ previousButton->setParent(this);
+ nextButton->setParent(this);
}
-void AdopterWindow::leaveChildren()
+void AdopterWindow::leaveBookView()
{
TRACE;
if (bookView) {
centralWidget()->layout()->removeWidget(bookView);
- bookView = 0;
}
+ bookView = 0;
+ progress = 0;
+ nextButton = 0;
+ previousButton = 0;
}
-bool AdopterWindow::hasChild(QWidget *child)
+bool AdopterWindow::hasBookView()
{
- if (child == bookView) {
- return true;
- }
- return this == child->parent();
+ return bookView != 0;
}
void AdopterWindow::show()
action = toolBar->addAction(QIcon(Platform::instance()->icon(iconName)),
text, receiver, member);
#else
- if (toolBar && important) {
+ if (!toolBar && important) {
+ // Create tool bar if needed
+ toolBar = new QToolBar("", this);
+ // toolBar->setFixedWidth(QApplication::desktop()->
+ // availableGeometry().width());
+ toolBar->setFixedHeight(65);
+ toolBar->setStyleSheet("margin:0; border:0; padding:0");
+ toolBar->setSizePolicy(QSizePolicy::MinimumExpanding,
+ QSizePolicy::Maximum);
+ addToolBar(Qt::BottomToolBarArea, toolBar);
+ }
+ if (important) {
+ // Add tool bar action
QPushButton *button = new QPushButton(this);
button->setIconSize(QSize(60, 60));
button->setFixedSize(89, 60);
connect(button, SIGNAL(clicked()), receiver, member);
toolBar->addWidget(button);
}
+ // Add menu action, too
action = new QAction(text, this);
menuBar()->addAction(action);
connect(action, SIGNAL(triggered()), receiver, member);
#endif // Q_WS_MAEMO_5
-#ifdef Q_WS_MAEMO_5
-
void AdopterWindow::showEvent(QShowEvent *e)
{
- TRACE;
+ Trace t("AdopterWindow::showEvent");
+
+#if defined(Q_WS_MAEMO_5)
doGrabVolumeKeys(grabbingVolumeKeys);
+#endif // Q_WS_MAEMO_5
QMainWindow::showEvent(e);
}
-#endif // Q_WS_MAEMO_5
+void AdopterWindow::resizeEvent(QResizeEvent *event)
+{
+ Trace t("AdopterWindow::resizeEvent");
+
+#ifdef Q_OS_SYMBIAN
+ if (toolBar) {
+ if (portrait()) {
+ qDebug() << "Show tool bar";
+ toolBar->setVisible(true);
+ } else {
+ qDebug() << "Hide tool bar";
+ toolBar->setVisible(false);
+ }
+ }
+#endif // Q_OS_SYMBIAN
+
+ if (hasBookView()) {
+ QTimer::singleShot(100, this, SLOT(placeDecorations()));
+ }
+ QMainWindow::resizeEvent(event);
+}
void AdopterWindow::keyPressEvent(QKeyEvent *event)
{
}
}
+bool AdopterWindow::portrait()
+{
+ QRect geometry = QApplication::desktop()->geometry();
+ return geometry.width() < geometry.height();
+}
+
+void AdopterWindow::placeDecorations()
+{
+ Trace t("AdopterWindow::placeDecorations");
+
+ if (!hasBookView()) {
+ return;
+ }
+
+ int toolBarHeight = 0;
+
+ QRect geo = bookView->geometry();
+ qDebug() << "bookView:" << geo;
+
+#ifdef Q_OS_SYMBIAN
+ // Work around Symbian bug: If tool bar is hidden, increase bottom
+ // decorator widgets' Y coordinates by the tool bar's height
+ if (!portrait() && toolBar) {
+ toolBarHeight = toolBar->height();
+ }
+
+ // Work around another Symbian bug: When returning from full screen mode
+ // in landscape, the book view widget's height is miscalculated.
+ // My apologies for this kludge
+ if (geo.height() == 288) {
+ qDebug() << "Adjusting bottom Y";
+ toolBarHeight -= 288 - 223;
+ }
+#endif // Q_OS_SYMBIAN
+
+ progress->setGeometry(geo.x(),
+ geo.y() + geo.height() - progress->thickness() + toolBarHeight,
+ geo.width(), progress->thickness());
+ previousButton->setGeometry(geo.x(),
+ geo.y() + geo.height() - TranslucentButton::pixels + toolBarHeight,
+ TranslucentButton::pixels, TranslucentButton::pixels);
+ nextButton->setGeometry(
+ geo.x() + geo.width() - TranslucentButton::pixels,
+ geo.y(), TranslucentButton::pixels, TranslucentButton::pixels);
+ progress->flash();
+ previousButton->flash();
+ nextButton->flash();
+ qDebug() << "progress:" << progress->geometry();
+}
class QAction;
class BookView;
class QVBoxLayout;
+class Progress;
+class TranslucentButton;
/**
* A toplevel window that can adopt a BookView and other children.
public:
explicit AdopterWindow(QWidget *parent = 0);
- /** Adopt children "bookView" and "others". */
- void takeChildren(BookView *bookView, const QList<QWidget *> &others);
+ /** Adopt book view and decorations. */
+ void takeBookView(BookView *bookView, Progress *prog,
+ TranslucentButton *prev, TranslucentButton *next);
- /** Release current children (adopted in @see takeChildren). */
- void leaveChildren();
+ /** Release book view and decorations. */
+ void leaveBookView();
- /** Return true if a child is currently adopted. */
- bool hasChild(QWidget *child);
+ /** Return true if the book view is currently adopted. */
+ bool hasBookView();
/**
* Add action that is visible on the tool bar.
/** Show window. */
void show();
- /** If grab is true, volume keys will generate pageUp/Down key events. */
+ /** If grab is true, volume keys will navigate the book view. */
void grabVolumeKeys(bool grab);
public slots:
void onSettingsChanged(const QString &key);
protected:
+ /** Return true, if we are in portrait mode. */
+ bool portrait();
+
+ /** Handle key press events. */
void keyPressEvent(QKeyEvent *event);
-#ifdef Q_WS_MAEMO_5
+
+ /**
+ * Handle show events.
+ * On Symbian, volume keys can only be grabbed, if the window is shown.
+ */
void showEvent(QShowEvent *event);
+
+ /** Handle resize events. */
+ void resizeEvent(QResizeEvent *event);
+
+#ifdef Q_WS_MAEMO_5
+ /** Actually grab the volume keys. */
void doGrabVolumeKeys(bool grab);
#endif
- BookView *bookView;
+
+protected slots:
+ void placeDecorations();
+
+private:
+ BookView *bookView; /**< Book view widget. */
bool grabbingVolumeKeys;/**< True, if volume keys should be grabbed. */
- QToolBar *toolBar;
+ QToolBar *toolBar; /**< Tool bar. */
+ Progress *progress; /**< Reading progress indicator. */
+ TranslucentButton *previousButton; /**< Previous page indicator. */
+ TranslucentButton *nextButton; /**< Next page indicator. */
};
#endif // ADOPTERWINDOW_H
static const int MARGIN = 9;
-FullScreenWindow::FullScreenWindow(QWidget *parent):
- AdopterWindow(parent), progress(0), previousButton(0), nextButton(0)
+FullScreenWindow::FullScreenWindow(QWidget *parent): AdopterWindow(parent)
{
TRACE;
Q_ASSERT(parent);
AdopterWindow::resizeEvent(e);
}
-void FullScreenWindow::takeChildren(BookView *view,
- Progress *prog,
- TranslucentButton *previous,
- TranslucentButton *next)
-{
- TRACE;
- progress = prog;
- previousButton = previous;
- nextButton = next;
- QList<QWidget *> otherChildren;
- otherChildren << progress << previousButton << nextButton;
- AdopterWindow::takeChildren(view, otherChildren);
-}
-
void FullScreenWindow::placeChildren()
{
Trace t("FullScreenWindow::placeChildren");
h - TranslucentButton::pixels - MARGIN,
TranslucentButton::pixels,
TranslucentButton::pixels);
-
- if (hasChild(progress)) {
- progress->setGeometry(0, h - progress->thickness(),
- w, progress->thickness());
- qDebug() << "Screen (FullScreenWindow::resizeEvent)" << w << "x" << h;
- qDebug() << "Progress (FullScreenWindow::resizeEvent)"
- << progress->geometry();
- }
- if (hasChild(previousButton)) {
- previousButton->setGeometry(
- MARGIN,
- h - TranslucentButton::pixels - MARGIN,
- TranslucentButton::pixels,
- TranslucentButton::pixels);
- }
- if (hasChild(nextButton)) {
- nextButton->setGeometry(
- w - TranslucentButton::pixels - MARGIN,
- MARGIN,
- TranslucentButton::pixels,
- TranslucentButton::pixels);
- }
-
restoreButton->flash(3000);
}
private:
TranslucentButton *restoreButton;
- Progress *progress;
- TranslucentButton *previousButton;
- TranslucentButton *nextButton;
};
#endif // FULLSCREENWINDOW_H
#endif
setWindowTitle("Dorian");
-#ifdef Q_OS_SYMBIAN
- // Tool bar
- toolBar = new QToolBar("", this /*frame*/);
- toolBar->setFixedWidth(QApplication::desktop()->
- availableGeometry().width());
- toolBar->setFixedHeight(65);
- toolBar->setStyleSheet("margin:0;border:0;padding:0");
- toolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
- addToolBar(Qt::BottomToolBarArea, toolBar);
-#endif
-
// Central widget. Must be an intermediate, because the book view widget
// can be re-parented later
QFrame *central = new QFrame(this);
// Book view
view = new BookView(this);
view->show();
- layout->addWidget(view);
-
- // Dialogs
- progress = new Progress(this);
// Tool bar actions
(void)addToolBarAction(this, SLOT(close()), "", tr("Exit"));
#endif
- // Buttons on top of the book view
- previousButton = new TranslucentButton("back", this);
- nextButton = new TranslucentButton("forward", this);
+ // Decorations
+ prev = new TranslucentButton("back", this);
+ next = new TranslucentButton("forward", this);
+ prog = new Progress(this);
// Handle model changes
connect(Library::instance(), SIGNAL(nowReadingChanged()),
connect(view, SIGNAL(partLoadEnd(int)), this, SLOT(onPartLoadEnd(int)));
// Handle progress
- connect(view, SIGNAL(progress(qreal)), progress, SLOT(setProgress(qreal)));
+ connect(view, SIGNAL(progress(qreal)), prog, SLOT(setProgress(qreal)));
// Shadow window for full screen reading
fullScreenWindow = new FullScreenWindow(this);
this, SLOT(onSettingsChanged(const QString &)));
// Handle book view buttons
- connect(nextButton, SIGNAL(triggered()), this, SLOT(goToNextPage()));
- connect(previousButton, SIGNAL(triggered()), this, SLOT(goToPreviousPage()));
+ connect(next, SIGNAL(triggered()), this, SLOT(goToNextPage()));
+ connect(prev, SIGNAL(triggered()), this, SLOT(goToPreviousPage()));
// Adopt view, show window
showRegular();
TRACE;
// Re-parent children
- fullScreenWindow->leaveChildren();
- QList<QWidget *> otherChildren;
- otherChildren << progress << previousButton << nextButton;
- takeChildren(view, otherChildren);
-
-#if 0
-
- // Adjust geometry of decorations
-
- QRect geo = geometry();
- qDebug() << "MainWindow (MainWindow::showRegular)" << geo;
- qDebug() << "BookView (MainWindow::showRegular)" << view->geometry();
- int y = geo.height() - progress->thickness();
-#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
- bool hasToolBar = false;
-# if defined(Q_OS_SYMBIAN)
- hasToolBar =
- (QApplication::desktop()->width() < QApplication::desktop()->height());
- qDebug() << (hasToolBar? "Portrait": "Landscape");
-# endif
- if (!hasToolBar) {
- y -= toolBar->height();
- }
-#endif
- progress->setGeometry(0, y, geo.width(), y + progress->thickness());
-
-#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
- y = geo.height() - TranslucentButton::pixels;
- if (!hasToolBar) {
- y -= toolBar->height();
- }
- previousButton->setGeometry(0, y, TranslucentButton::pixels,
- TranslucentButton::pixels);
- nextButton->setGeometry(geo.width() - TranslucentButton::pixels, 0,
- TranslucentButton::pixels, TranslucentButton::pixels);
-#else
- previousButton->setGeometry(0, geo.height() - TranslucentButton::pixels,
- TranslucentButton::pixels, TranslucentButton::pixels);
- nextButton->setGeometry(geo.width() - TranslucentButton::pixels - 25,
- toolBar->height(), TranslucentButton::pixels,
- TranslucentButton::pixels);
-#endif // Q_WS_MAEMO_5
- qDebug() << "previousButton geometry" << previousButton->geometry();
-
-#endif
+ fullScreenWindow->leaveBookView();
+ takeBookView(view, prog, prev, next);
fullScreenWindow->hide();
show();
TRACE;
// Re-parent children
- leaveChildren();
- fullScreenWindow->takeChildren(view, progress, previousButton, nextButton);
-
-#if 0
-
- // Adjust geometry of decorations
- QRect screen = QApplication::desktop()->screenGeometry();
- int y = screen.height() - progress->thickness();
- progress->setGeometry(0, y, screen.width(), y + progress->thickness());
-#if defined(Q_WS_MAEMO_5)
- nextButton->setGeometry(screen.width() - TranslucentButton::pixels, 0,
- TranslucentButton::pixels, TranslucentButton::pixels);
-#else
- nextButton->setGeometry(screen.width() - TranslucentButton::pixels - 25, 0,
- TranslucentButton::pixels, TranslucentButton::pixels);
-#endif // Q_WS_MAEMO_5
- previousButton->setGeometry(0, screen.height() - TranslucentButton::pixels,
- TranslucentButton::pixels, TranslucentButton::pixels);
-
-#endif
+ leaveBookView();
+ fullScreenWindow->takeBookView(view, prog, prev, next);
// #ifdef Q_OS_SYMBIAN
hide();
AdopterWindow::timerEvent(event);
}
-void MainWindow::resizeEvent(QResizeEvent *e)
-{
- Trace t("MainWindow::resizeEvent");
-#ifdef Q_OS_SYMBIAN
- // Tool bar is only useful in portrait mode
- bool isPortrait =
- (QApplication::desktop()->width() < QApplication::desktop()->height());
- toolBar->setVisible(isPortrait);
-#endif
- QTimer::singleShot(100, this, SLOT(placeChildren()));
- AdopterWindow::resizeEvent(e);
-}
-
-void MainWindow::placeChildren()
-{
- Trace t("MainWindow::placeChildren");
-
- int toolBarHeight = 0;
-
-#ifdef Q_OS_SYMBIAN
- // Tool bar is only useful in portrait mode
- bool isPortrait =
- (QApplication::desktop()->width() < QApplication::desktop()->height());
- // toolBar->setVisible(isPortrait);
-
- // Work around Symbian bug: If there is no tool bar, increase decorator
- // widgets' Y coordinates
- if (!isPortrait) {
- toolBarHeight = toolBar->height();
- }
-#endif // Q_OS_SYMBIAN
-
- if (hasChild(view)) {
- QRect geo = centralWidget()->geometry();
- qDebug() << "centralWidget (MainWindow::resizeEvent)" << geo;
-#ifdef Q_OS_SYMBIAN
- // FIXME: When returning from full screen in landscape mode,
- // the central widget's height is miscalculated on Symbian.
- // My apologies for this kludge
- if (geo.height() == 288) {
- geo.setHeight(223);
- }
-#endif // Q_OS_SYMBIAN
- progress->setGeometry(geo.x(),
- geo.y() + geo.height() - progress->thickness() + toolBarHeight,
- geo.width(), progress->thickness());
- previousButton->setGeometry(geo.x(),
- geo.y() + geo.height() - TranslucentButton::pixels + toolBarHeight,
- TranslucentButton::pixels, TranslucentButton::pixels);
- nextButton->setGeometry(
- geo.x() + geo.width() - TranslucentButton::pixels,
- geo.y(), TranslucentButton::pixels, TranslucentButton::pixels);
- progress->flash();
- previousButton->flash();
- nextButton->flash();
- qDebug() << "Progress (MainWindow::resizeEvent)"
- << progress->geometry();
- }
-
-}
-
void MainWindow::about()
{
Dyalog *aboutDialog = new Dyalog(this, false);
void MainWindow::goToNextPage()
{
- nextButton->flash();
- previousButton->flash();
+ next->flash();
+ prev->flash();
view->goNextPage();
}
void MainWindow::goToPreviousPage()
{
- nextButton->flash();
- previousButton->flash();
+ next->flash();
+ prev->flash();
view->goPreviousPage();
}
protected:
void closeEvent(QCloseEvent *event);
void timerEvent(QTimerEvent *event);
- void resizeEvent(QResizeEvent *event);
-
-protected slots:
- void placeChildren();
private:
void setCurrentBook(const QModelIndex ¤t);
QModelIndex mCurrent;
FullScreenWindow *fullScreenWindow;
int preventBlankingTimer;
- Progress *progress;
- TranslucentButton *previousButton;
- TranslucentButton *nextButton;
+ Progress *prog;
+ TranslucentButton *prev;
+ TranslucentButton *next;
ProgressDialog *libraryProgress;
};
#include <QtGlobal>
#include <QDir>
+#include <QtGui>
#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
# include <unistd.h>