From ac72b9ea7af92a9936a8e023a1923cdf94558d54 Mon Sep 17 00:00:00 2001 From: Akos Polster Date: Mon, 10 Jan 2011 00:19:01 +0100 Subject: [PATCH] Clean up event handling. --- adopterwindow.cpp | 39 ++++++++++--------------- fullscreenwindow.cpp | 1 - mainwindow.cpp | 10 +------ widgets/mainbase.cpp | 79 +++++++++++++++----------------------------------- widgets/mainbase.h | 21 ++------------ 5 files changed, 42 insertions(+), 108 deletions(-) diff --git a/adopterwindow.cpp b/adopterwindow.cpp index d5f5337..daafa29 100644 --- a/adopterwindow.cpp +++ b/adopterwindow.cpp @@ -38,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; @@ -62,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; @@ -121,11 +126,11 @@ void AdopterWindow::doGrabVolumeKeys(bool grab) #endif // Q_WS_MAEMO_5 -void AdopterWindow::showEvent(QShowEvent *e) +void AdopterWindow::showEvent(QShowEvent *event) { Trace t("AdopterWindow::showEvent"); - MainBase::showEvent(e); + MainBase::showEvent(event); #if defined(Q_WS_MAEMO_5) doGrabVolumeKeys(grabbingVolumeKeys); #endif @@ -135,9 +140,9 @@ void AdopterWindow::showEvent(QShowEvent *e) 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) { @@ -202,30 +207,16 @@ 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; 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 (isToolBarHidden()) { - // extraHeight = toolBarHeight(); - // } - - // 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"; - extraHeight -= 288 - 223; - } -#endif // Q_OS_SYMBIAN - progress->setGeometry(geo.x(), geo.y() + geo.height() - progress->thickness() + extraHeight, geo.width(), progress->thickness()); diff --git a/fullscreenwindow.cpp b/fullscreenwindow.cpp index c63f003..a80eed7 100644 --- a/fullscreenwindow.cpp +++ b/fullscreenwindow.cpp @@ -17,7 +17,6 @@ FullScreenWindow::FullScreenWindow(QWidget *parent): AdopterWindow(parent) setAttribute(Qt::WA_Maemo5StackedWindow, true); setAttribute(Qt::WA_Maemo5NonComposited, true); #endif // Q_WS_MAEMO_5 - hideToolBar(); QFrame *frame = new QFrame(this); QVBoxLayout *layout = new QVBoxLayout(frame); layout->setMargin(0); diff --git a/mainwindow.cpp b/mainwindow.cpp index 4860d41..583928e 100755 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -188,10 +188,6 @@ void MainWindow::showRegular() fullScreenWindow->hide(); show(); - -#if defined(Q_OS_SYMBIAN) - activateWindow(); -#endif } void MainWindow::showBig() @@ -202,12 +198,8 @@ void MainWindow::showBig() leaveBookView(); fullScreenWindow->takeBookView(view, prog, prev, next); - fullScreenWindow->showFullScreen(); hide(); - -#ifdef Q_OS_SYMBIAN - fullScreenWindow->activateWindow(); -#endif + fullScreenWindow->showFullScreen(); } void MainWindow::setCurrentBook(const QModelIndex ¤t) diff --git a/widgets/mainbase.cpp b/widgets/mainbase.cpp index 88c623c..f2707c8 100755 --- a/widgets/mainbase.cpp +++ b/widgets/mainbase.cpp @@ -8,7 +8,7 @@ MainBase::MainBase(QWidget *parent): QMainWindow(parent), toolBar(0) { TRACE; -#ifdef Q_WS_MAEMO_5 +#if defined(Q_WS_MAEMO_5) setAttribute(Qt::WA_Maemo5StackedWindow, true); #endif @@ -16,25 +16,39 @@ MainBase::MainBase(QWidget *parent): QMainWindow(parent), toolBar(0) QVBoxLayout *layout = new QVBoxLayout(frame); layout->setMargin(0); frame->setLayout(layout); - //frame->show(); setCentralWidget(frame); -#ifdef Q_OS_SYMBIAN +#if defined(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); +#endif // Q_OS_SYMBIAN +} + +void MainBase::addToolBar() +{ + TRACE; + + if (toolBar) { + return; + } + +#if defined(Q_OS_SYMBIAN) + toolBar = new QToolBar("", this); + QMainWindow::addToolBar(Qt::BottomToolBarArea, toolBar); #else - // Tool bar + toolBar = QMainWindow::addToolBar(""); +#endif + 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 } QAction *MainBase::addToolBarAction(QObject *receiver, @@ -48,12 +62,8 @@ QAction *MainBase::addToolBarAction(QObject *receiver, QAction *action; #ifdef Q_OS_SYMBIAN if (important) { - if (!toolBar) { - // Create tool bar if needed - toolBar = new QToolBar("", this); - addToolBar(Qt::BottomToolBarArea, toolBar); - } // Add tool bar action + addToolBar(); QPushButton *button = new QPushButton(this); button->setIconSize(QSize(60, 60)); button->setFixedHeight(60); @@ -68,6 +78,7 @@ QAction *MainBase::addToolBarAction(QObject *receiver, connect(action, SIGNAL(triggered()), receiver, member); #else Q_UNUSED(important); + addToolBar(); action = toolBar->addAction(QIcon(Platform::instance()->icon(iconName)), text, receiver, member); #endif @@ -78,56 +89,12 @@ QAction *MainBase::addToolBarAction(QObject *receiver, void MainBase::addToolBarSpace() { + addToolBar(); QFrame *frame = new QFrame(toolBar); frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); toolBar->addWidget(frame); } -void MainBase::updateToolBar() -{ -#if 0 // ifdef Q_OS_SYMBIAN - 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); - } - } -#endif // Q_OS_SYMBIAN -} - -void MainBase::showEvent(QShowEvent *event) -{ - Trace t("MainBase::showEvent"); - updateToolBar(); - QMainWindow::showEvent(event); -} - -void MainBase::resizeEvent(QResizeEvent *event) -{ - Trace t("MainBase::resizeEvent"); - updateToolBar(); - QMainWindow::resizeEvent(event); -} - -void MainBase::hideToolBar() -{ - if (toolBar) { - toolBar->hide(); - } -} - -bool MainBase::isToolBarHidden() -{ - return toolBar && toolBar->isHidden(); -} - int MainBase::toolBarHeight() { return toolBar? toolBar->height(): 0; diff --git a/widgets/mainbase.h b/widgets/mainbase.h index 3c72999..bf2e83b 100755 --- a/widgets/mainbase.h +++ b/widgets/mainbase.h @@ -29,6 +29,9 @@ public: const QString &iconName, const QString &text, bool important = false); + /** Add tool bar. */ + void addToolBar(); + /** Add spacing to tool bar. */ void addToolBarSpace(); @@ -36,24 +39,6 @@ public slots: void show(); protected: - /** Handle resize event: Manage tool bar visibility. */ - void resizeEvent(QResizeEvent *event); - - /** Handle show event: Manage tool bar visibility. */ - void showEvent(QShowEvent *event); - - /** - * Update toolb ar visibility. - * On Symbian, the tool bar is not visible in landscape mode. - */ - void updateToolBar(); - - /** Hide tool bar if visible. */ - void hideToolBar(); - - /** Return true if the tool bar is present and hidden. */ - bool isToolBarHidden(); - /** Return the height of the tool bar (or 0 if there is no tool bar). */ int toolBarHeight(); -- 1.7.9.5