X-Git-Url: http://git.maemo.org/git/?p=dorian;a=blobdiff_plain;f=adopterwindow.cpp;h=b60b61a16dbb54a88e12c8aec986aa7334e5cca5;hp=27d5dbf944154bca9096150a35d97e0d9dc398a4;hb=HEAD;hpb=156e40ef8337b8c0d668fb33a9c8bf2b6b34ba79 diff --git a/adopterwindow.cpp b/adopterwindow.cpp index 27d5dbf..b60b61a 100644 --- a/adopterwindow.cpp +++ b/adopterwindow.cpp @@ -12,110 +12,76 @@ #include "bookview.h" #include "platform.h" #include "settings.h" +#include "progress.h" +#include "translucentbutton.h" -AdopterWindow::AdopterWindow(QWidget *parent): QMainWindow(parent), bookView(0) +AdopterWindow::AdopterWindow(QWidget *parent): MainBase(parent), bookView(0), + grabbingVolumeKeys(false), progress(0), previousButton(0), nextButton(0) { TRACE; -#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); - -#ifdef Q_OS_SYMBIAN - QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this); - closeAction->setSoftKeyRole(QAction::NegativeSoftKey); - connect(closeAction, SIGNAL(triggered()), this, SLOT(close())); - QMainWindow::addAction(closeAction); -#else - // Tool bar - setUnifiedTitleAndToolBarOnMac(true); - toolBar = addToolBar("controls"); - toolBar->setMovable(false); - toolBar->setFloatable(false); - toolBar->toggleViewAction()->setVisible(false); -#if defined(Q_WS_X11) && !defined(Q_WS_MAEMO_5) - toolBar->setIconSize(QSize(42, 42)); -#endif -#endif // Q_OS_SYMBIAN - - // Monitor settings - Settings *settings = Settings::instance(); - connect(settings, SIGNAL(valueChanged(const QString &)), + // Monitor settings changes + connect(Settings::instance(), SIGNAL(valueChanged(const QString &)), this, SLOT(onSettingsChanged(const QString &))); - settings->setValue("usevolumekeys", settings->value("usevolumekeys")); -} -void AdopterWindow::takeChildren(BookView *view, const QList &others) -{ - TRACE; - leaveChildren(); - if (view) { - bookView = view; - bookView->setParent(centralWidget()); - centralWidget()->layout()->addWidget(bookView); - bookView->show(); - } - foreach (QWidget *child, others) { - if (child) { - child->setParent(this); - } - } } -void AdopterWindow::leaveChildren() +void AdopterWindow::takeBookView(BookView *view, + Progress *prog, + TranslucentButton *previous, + TranslucentButton *next) { TRACE; + + Q_ASSERT(view); + Q_ASSERT(prog); + Q_ASSERT(previous); + Q_ASSERT(next); + if (bookView) { - centralWidget()->layout()->removeWidget(bookView); - bookView = 0; + return; } -} -void AdopterWindow::show() -{ -#ifdef Q_OS_SYMBIAN - foreach (QWidget *w, QApplication::allWidgets()) { - w->setContextMenuPolicy(Qt::NoContextMenu); - } - showMaximized(); - raise(); -#else - QMainWindow::show(); -#endif + bookView = view; + bookView->setParent(this); + centralWidget()->layout()->addWidget(bookView); + // bookView->show(); + + progress = prog; + previousButton = previous; + nextButton = next; + progress->setParent(this); + previousButton->setParent(this); + nextButton->setParent(this); + + // Handle page and/or volume keys + connect(this, SIGNAL(pageUp()), this, SLOT(onPageUp()), + Qt::QueuedConnection); + connect(this, SIGNAL(pageDown()), this, SLOT(onPageDown()), + Qt::QueuedConnection); } -QAction *AdopterWindow::addToolBarAction(QObject *receiver, - const char *member, - const QString &iconName, - const QString &text) +void AdopterWindow::leaveBookView() { TRACE; - qDebug() << "icon" << iconName << "text" << text; -#ifndef Q_OS_SYMBIAN - return toolBar->addAction(QIcon(Platform::instance()->icon(iconName)), - text, receiver, member); -#else - Q_UNUSED(iconName); - QAction *action = new QAction(text, this); - menuBar()->addAction(action); - connect(action, SIGNAL(triggered()), receiver, member); - return action; -#endif + + if (!bookView) { + return; + } + + // bookView->hide(); + centralWidget()->layout()->removeWidget(bookView); + bookView = 0; + progress = 0; + nextButton = 0; + previousButton = 0; + disconnect(this, SLOT(onPageUp())); + disconnect(this, SLOT(onPageDown())); } -void AdopterWindow::addToolBarSpace() +bool AdopterWindow::hasBookView() { -#ifndef Q_OS_SYMBIAN - QFrame *frame = new QFrame(toolBar); - frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - toolBar->addWidget(frame); -#endif + return bookView != 0; } void AdopterWindow::grabVolumeKeys(bool grab) @@ -141,7 +107,8 @@ void AdopterWindow::doGrabVolumeKeys(bool grab) return; } unsigned long val = grab? 1: 0; - Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False); + Atom atom = + XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False); if (!atom) { qCritical() << "Unable to obtain _HILDON_ZOOM_KEY_ATOM"; return; @@ -159,55 +126,133 @@ void AdopterWindow::doGrabVolumeKeys(bool grab) #endif // Q_WS_MAEMO_5 -#ifdef Q_WS_MAEMO_5 - -void AdopterWindow::showEvent(QShowEvent *e) +void AdopterWindow::showEvent(QShowEvent *event) { - TRACE; + Trace t("AdopterWindow::showEvent"); + + MainBase::showEvent(event); +#if defined(Q_WS_MAEMO_5) doGrabVolumeKeys(grabbingVolumeKeys); - QMainWindow::showEvent(e); +#endif + placeDecorations(); } -#endif // Q_WS_MAEMO_5 +void AdopterWindow::resizeEvent(QResizeEvent *event) +{ + Trace t("AdopterWindow::resizeEvent"); + + MainBase::resizeEvent(event); + placeDecorations(); +#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN) + // Restore previous reading position + if (bookView) { + bookView->scheduleRestoreLastBookmark(); + } +#endif // defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN) +} + +void AdopterWindow::closeEvent(QCloseEvent *event) +{ + Trace t("AdopterWindow::closeEvent"); + if (bookView) { + bookView->setLastBookmark(); + } + hide(); + MainBase::closeEvent(event); +} + +void AdopterWindow::leaveEvent(QEvent *event) +{ + Trace t("AdopterWindow::leaveEvent"); + if (bookView) { + bookView->setLastBookmark(); + } + MainBase::leaveEvent(event); +} void AdopterWindow::keyPressEvent(QKeyEvent *event) { - TRACE; - if (bookView && grabbingVolumeKeys) { - switch (event->key()) { + Trace t("AdopterWindow::keyPressEvent"); + + switch (event->key()) { + case Qt::Key_PageDown: #ifdef Q_WS_MAEMO_5 - case Qt::Key_F7: - qDebug() << "F7"; - bookView->goNextPage(); - event->accept(); - break; - case Qt::Key_F8: - qDebug() << "F8"; - bookView->goPreviousPage(); - event->accept(); - break; -#endif // Q_WS_MAEMO_5 - case Qt::Key_PageUp: - bookView->goPreviousPage(); - event->accept(); - break; - case Qt::Key_PageDown: - bookView->goNextPage(); - event->accept(); - break; - default: - ; - } + case Qt::Key_F7: +#endif + emit pageDown(); + event->accept(); + break; + case Qt::Key_PageUp: +#ifdef Q_WS_MAEMO_5 + case Qt::Key_F8: +#endif + emit pageUp(); + event->accept(); + break; + default: + ; } - QMainWindow::keyPressEvent(event); + MainBase::keyPressEvent(event); } void AdopterWindow::onSettingsChanged(const QString &key) { - TRACE; if (key == "usevolumekeys") { - qDebug() << key; - grabVolumeKeys(Settings::instance()->value(key).toBool()); + bool grab = Settings::instance()->value(key, false).toBool(); + qDebug() << "AdopterWindow::onSettingsChanged: usevolumekeys" << grab; + grabVolumeKeys(grab); + } +} + +void AdopterWindow::placeDecorations() +{ + Trace t("AdopterWindow::placeDecorations"); + + if (!hasBookView()) { + qDebug() << "Doesn't have the book view"; + return; } + + qDebug() << "Has the book view"; + int extraHeight = 0; + +#if defined(Q_WS_X11) && !defined(Q_WS_MAEMO_5) + extraHeight += toolBarHeight(); +#endif + + QRect geo = bookView->geometry(); + qDebug() << "bookView:" << geo; + + progress->setGeometry(geo.x(), + geo.y() + geo.height() - progress->thickness() + extraHeight, + geo.width(), progress->thickness()); + previousButton->setGeometry(geo.x(), + geo.y() + geo.height() - TranslucentButton::pixels + extraHeight, + TranslucentButton::pixels, TranslucentButton::pixels); + nextButton->setGeometry( + geo.x() + geo.width() - TranslucentButton::pixels, + geo.y() + extraHeight, TranslucentButton::pixels, + TranslucentButton::pixels); + progress->flash(); + previousButton->flash(); + nextButton->flash(); + qDebug() << "progress:" << progress->geometry(); } +void AdopterWindow::onPageUp() +{ + if (bookView && grabbingVolumeKeys) { + setEnabled(false); + bookView->goPreviousPage(); + setEnabled(true); + } +} + +void AdopterWindow::onPageDown() +{ + if (bookView && grabbingVolumeKeys) { + setEnabled(false); + bookView->goNextPage(); + setEnabled(true); + } +}