X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=adopterwindow.cpp;h=b60b61a16dbb54a88e12c8aec986aa7334e5cca5;hb=HEAD;hp=8d8e6d0daf71d3f8673497ab4171e10a2a3f570d;hpb=604e67a105161b6c303d00a6a55e04af14aebfd8;p=dorian diff --git a/adopterwindow.cpp b/adopterwindow.cpp index 8d8e6d0..b60b61a 100644 --- a/adopterwindow.cpp +++ b/adopterwindow.cpp @@ -15,41 +15,12 @@ #include "progress.h" #include "translucentbutton.h" -AdopterWindow::AdopterWindow(QWidget *parent): - QMainWindow(parent), bookView(0), grabbingVolumeKeys(false), toolBar(0), - progress(0), previousButton(0), nextButton(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 - - QFrame *frame = new QFrame(this); - QVBoxLayout *layout = new QVBoxLayout(frame); - layout->setMargin(0); - frame->setLayout(layout); - //frame->show(); - 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(""); - 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 + // Monitor settings changes connect(Settings::instance(), SIGNAL(valueChanged(const QString &)), this, SLOT(onSettingsChanged(const QString &))); @@ -67,12 +38,14 @@ void AdopterWindow::takeBookView(BookView *view, Q_ASSERT(previous); Q_ASSERT(next); - leaveBookView(); + if (bookView) { + return; + } bookView = view; bookView->setParent(this); centralWidget()->layout()->addWidget(bookView); - bookView->show(); + // bookView->show(); progress = prog; previousButton = previous; @@ -91,10 +64,13 @@ void AdopterWindow::takeBookView(BookView *view, void AdopterWindow::leaveBookView() { TRACE; - if (bookView) { - bookView->hide(); - centralWidget()->layout()->removeWidget(bookView); + + if (!bookView) { + return; } + + // bookView->hide(); + centralWidget()->layout()->removeWidget(bookView); bookView = 0; progress = 0; nextButton = 0; @@ -108,76 +84,6 @@ bool AdopterWindow::hasBookView() return bookView != 0; } -void AdopterWindow::show() -{ - Trace t("AdopterWindow::show"); -#ifdef Q_OS_SYMBIAN - foreach (QWidget *w, QApplication::allWidgets()) { - w->setContextMenuPolicy(Qt::NoContextMenu); - } - showMaximized(); -#else - QMainWindow::show(); -#endif -} - -QAction *AdopterWindow::addToolBarAction(QObject *receiver, - const char *member, - const QString &iconName, - const QString &text, - bool important) -{ - TRACE; - qDebug() << "icon" << iconName << "text" << text; - QAction *action; -#ifndef Q_OS_SYMBIAN - Q_UNUSED(important); - action = toolBar->addAction(QIcon(Platform::instance()->icon(iconName)), - text, receiver, member); -#else - if (!toolBar && important) { - // Create tool bar if needed - toolBar = new QToolBar("", this); - // toolBar->setFixedHeight(63); - 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); - button->setIcon(QIcon(Platform::instance()->icon(iconName))); - button->setSizePolicy(QSizePolicy::MinimumExpanding, - QSizePolicy::Maximum); - 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 - -#if defined Q_WS_MAEMO_5 - action->setText(""); - action->setToolTip(""); -#endif - - return action; -} - -void AdopterWindow::addToolBarSpace() -{ -#ifndef Q_OS_SYMBIAN - QFrame *frame = new QFrame(toolBar); - frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - toolBar->addWidget(frame); -#endif -} - void AdopterWindow::grabVolumeKeys(bool grab) { TRACE; @@ -220,41 +126,11 @@ void AdopterWindow::doGrabVolumeKeys(bool grab) #endif // Q_WS_MAEMO_5 -#ifdef Q_OS_SYMBIAN - -void AdopterWindow::updateToolBar() -{ - TRACE; - if (toolBar) { - QRect geometry = QApplication::desktop()->geometry(); - bool isPortrait = geometry.width() < geometry.height(); - bool isToolBarHidden = toolBar->isHidden(); - if (isPortrait && isToolBarHidden) { - qDebug() << "Show tool bar"; - toolBar->setVisible(true); - } else if (!isPortrait && !isToolBarHidden) { - qDebug() << "Hide tool bar"; - toolBar->setVisible(false); - } - } -} - -bool AdopterWindow::portrait() -{ - QRect geometry = QApplication::desktop()->geometry(); - return geometry.width() < geometry.height(); -} - -#endif // Q_OS_SYMBIAN - -void AdopterWindow::showEvent(QShowEvent *e) +void AdopterWindow::showEvent(QShowEvent *event) { Trace t("AdopterWindow::showEvent"); -#ifdef Q_OS_SYMBIAN - updateToolBar(); -#endif - QMainWindow::showEvent(e); + MainBase::showEvent(event); #if defined(Q_WS_MAEMO_5) doGrabVolumeKeys(grabbingVolumeKeys); #endif @@ -264,14 +140,15 @@ void AdopterWindow::showEvent(QShowEvent *e) void AdopterWindow::resizeEvent(QResizeEvent *event) { Trace t("AdopterWindow::resizeEvent"); -#ifdef Q_OS_SYMBIAN - updateToolBar(); -#endif - QMainWindow::resizeEvent(event); + + MainBase::resizeEvent(event); placeDecorations(); +#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN) + // Restore previous reading position if (bookView) { - QTimer::singleShot(110, bookView, SLOT(restoreLastBookmark())); + bookView->scheduleRestoreLastBookmark(); } +#endif // defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN) } void AdopterWindow::closeEvent(QCloseEvent *event) @@ -280,7 +157,8 @@ void AdopterWindow::closeEvent(QCloseEvent *event) if (bookView) { bookView->setLastBookmark(); } - QMainWindow::closeEvent(event); + hide(); + MainBase::closeEvent(event); } void AdopterWindow::leaveEvent(QEvent *event) @@ -289,12 +167,13 @@ void AdopterWindow::leaveEvent(QEvent *event) if (bookView) { bookView->setLastBookmark(); } - QMainWindow::leaveEvent(event); + MainBase::leaveEvent(event); } void AdopterWindow::keyPressEvent(QKeyEvent *event) { - TRACE; + Trace t("AdopterWindow::keyPressEvent"); + switch (event->key()) { case Qt::Key_PageDown: #ifdef Q_WS_MAEMO_5 @@ -313,7 +192,7 @@ void AdopterWindow::keyPressEvent(QKeyEvent *event) default: ; } - QMainWindow::keyPressEvent(event); + MainBase::keyPressEvent(event); } void AdopterWindow::onSettingsChanged(const QString &key) @@ -330,39 +209,30 @@ void AdopterWindow::placeDecorations() Trace t("AdopterWindow::placeDecorations"); if (!hasBookView()) { + qDebug() << "Doesn't have the book view"; return; } - int toolBarHeight = 0; + 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; -#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 (toolBar && toolBar->isHidden()) { - 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.y() + geo.height() - progress->thickness() + extraHeight, geo.width(), progress->thickness()); previousButton->setGeometry(geo.x(), - geo.y() + geo.height() - TranslucentButton::pixels + toolBarHeight, + geo.y() + geo.height() - TranslucentButton::pixels + extraHeight, TranslucentButton::pixels, TranslucentButton::pixels); nextButton->setGeometry( geo.x() + geo.width() - TranslucentButton::pixels, - geo.y(), TranslucentButton::pixels, TranslucentButton::pixels); + geo.y() + extraHeight, TranslucentButton::pixels, + TranslucentButton::pixels); progress->flash(); previousButton->flash(); nextButton->flash(); @@ -386,4 +256,3 @@ void AdopterWindow::onPageDown() setEnabled(true); } } -