Clean up event handling.
authorAkos Polster <akos@pipacs.com>
Sun, 9 Jan 2011 23:19:01 +0000 (00:19 +0100)
committerAkos Polster <akos@pipacs.com>
Sun, 9 Jan 2011 23:19:01 +0000 (00:19 +0100)
adopterwindow.cpp
fullscreenwindow.cpp
mainwindow.cpp
widgets/mainbase.cpp
widgets/mainbase.h

index d5f5337..daafa29 100644 (file)
@@ -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());
index c63f003..a80eed7 100644 (file)
@@ -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);
index 4860d41..583928e 100755 (executable)
@@ -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 &current)
index 88c623c..f2707c8 100755 (executable)
@@ -8,7 +8,7 @@ MainBase::MainBase(QWidget *parent): QMainWindow(parent), toolBar(0)
 {\r
     TRACE;\r
 \r
-#ifdef Q_WS_MAEMO_5\r
+#if defined(Q_WS_MAEMO_5)\r
     setAttribute(Qt::WA_Maemo5StackedWindow, true);\r
 #endif\r
 \r
@@ -16,25 +16,39 @@ MainBase::MainBase(QWidget *parent): QMainWindow(parent), toolBar(0)
     QVBoxLayout *layout = new QVBoxLayout(frame);\r
     layout->setMargin(0);\r
     frame->setLayout(layout);\r
-    //frame->show();\r
     setCentralWidget(frame);\r
 \r
-#ifdef Q_OS_SYMBIAN\r
+#if defined(Q_OS_SYMBIAN)\r
     QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this);\r
     closeAction->setSoftKeyRole(QAction::NegativeSoftKey);\r
     connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));\r
     QMainWindow::addAction(closeAction);\r
+#endif // Q_OS_SYMBIAN\r
+}\r
+\r
+void MainBase::addToolBar()\r
+{\r
+    TRACE;\r
+\r
+    if (toolBar) {\r
+        return;\r
+    }\r
+\r
+#if defined(Q_OS_SYMBIAN)\r
+    toolBar = new QToolBar("", this);\r
+    QMainWindow::addToolBar(Qt::BottomToolBarArea, toolBar);\r
 #else\r
-    // Tool bar\r
+    toolBar = QMainWindow::addToolBar("");\r
+#endif\r
+\r
     setUnifiedTitleAndToolBarOnMac(true);\r
-    toolBar = addToolBar("");\r
     toolBar->setMovable(false);\r
     toolBar->setFloatable(false);\r
     toolBar->toggleViewAction()->setVisible(false);\r
+\r
 #if defined(Q_WS_X11) && !defined(Q_WS_MAEMO_5)\r
     toolBar->setIconSize(QSize(42, 42));\r
 #endif\r
-#endif // Q_OS_SYMBIAN\r
 }\r
 \r
 QAction *MainBase::addToolBarAction(QObject *receiver,\r
@@ -48,12 +62,8 @@ QAction *MainBase::addToolBarAction(QObject *receiver,
     QAction *action;\r
 #ifdef Q_OS_SYMBIAN\r
     if (important) {\r
-        if (!toolBar) {\r
-            // Create tool bar if needed\r
-            toolBar = new QToolBar("", this);\r
-            addToolBar(Qt::BottomToolBarArea, toolBar);\r
-        }\r
         // Add tool bar action\r
+        addToolBar();\r
         QPushButton *button = new QPushButton(this);\r
         button->setIconSize(QSize(60, 60));\r
         button->setFixedHeight(60);\r
@@ -68,6 +78,7 @@ QAction *MainBase::addToolBarAction(QObject *receiver,
     connect(action, SIGNAL(triggered()), receiver, member);\r
 #else\r
     Q_UNUSED(important);\r
+    addToolBar();\r
     action = toolBar->addAction(QIcon(Platform::instance()->icon(iconName)),\r
                                 text, receiver, member);\r
 #endif\r
@@ -78,56 +89,12 @@ QAction *MainBase::addToolBarAction(QObject *receiver,
 \r
 void MainBase::addToolBarSpace()\r
 {\r
+    addToolBar();\r
     QFrame *frame = new QFrame(toolBar);\r
     frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);\r
     toolBar->addWidget(frame);\r
 }\r
 \r
-void MainBase::updateToolBar()\r
-{\r
-#if 0 // ifdef Q_OS_SYMBIAN\r
-    TRACE;\r
-    if (toolBar) {\r
-        QRect geometry = QApplication::desktop()->geometry();\r
-        bool isPortrait = geometry.width() < geometry.height();\r
-        bool isToolBarHidden = toolBar->isHidden();\r
-        if (isPortrait && isToolBarHidden) {\r
-            qDebug() << "Show tool bar";\r
-            toolBar->setVisible(true);\r
-        } else if (!isPortrait && !isToolBarHidden) {\r
-            qDebug() << "Hide tool bar";\r
-            toolBar->setVisible(false);\r
-        }\r
-    }\r
-#endif // Q_OS_SYMBIAN\r
-}\r
-\r
-void MainBase::showEvent(QShowEvent *event)\r
-{\r
-    Trace t("MainBase::showEvent");\r
-    updateToolBar();\r
-    QMainWindow::showEvent(event);\r
-}\r
-\r
-void MainBase::resizeEvent(QResizeEvent *event)\r
-{\r
-    Trace t("MainBase::resizeEvent");\r
-    updateToolBar();\r
-    QMainWindow::resizeEvent(event);\r
-}\r
-\r
-void MainBase::hideToolBar()\r
-{\r
-    if (toolBar) {\r
-        toolBar->hide();\r
-    }\r
-}\r
-\r
-bool MainBase::isToolBarHidden()\r
-{\r
-    return toolBar && toolBar->isHidden();\r
-}\r
-\r
 int MainBase::toolBarHeight()\r
 {\r
     return toolBar? toolBar->height(): 0;\r
index 3c72999..bf2e83b 100755 (executable)
@@ -29,6 +29,9 @@ public:
                               const QString &iconName, const QString &text,\r
                               bool important = false);\r
 \r
+    /** Add tool bar. */\r
+    void addToolBar();\r
+\r
     /** Add spacing to tool bar. */\r
     void addToolBarSpace();\r
 \r
@@ -36,24 +39,6 @@ public slots:
     void show();\r
 \r
 protected:\r
-    /** Handle resize event: Manage tool bar visibility. */\r
-    void resizeEvent(QResizeEvent *event);\r
-\r
-    /** Handle show event: Manage tool bar visibility. */\r
-    void showEvent(QShowEvent *event);\r
-\r
-    /**\r
-     * Update toolb ar visibility.\r
-     * On Symbian, the tool bar is not visible in landscape mode.\r
-     */\r
-    void updateToolBar();\r
-\r
-    /** Hide tool bar if visible. */\r
-    void hideToolBar();\r
-\r
-    /** Return true if the tool bar is present and hidden. */\r
-    bool isToolBarHidden();\r
-\r
     /** Return the height of the tool bar (or 0 if there is no tool bar). */\r
     int toolBarHeight();\r
 \r