Fix popup widgets' positions. Add tool bar on Symbian.
authorAkos Polster <akos@pipacs.com>
Mon, 22 Nov 2010 23:35:02 +0000 (00:35 +0100)
committerAkos Polster <akos@pipacs.com>
Mon, 22 Nov 2010 23:35:02 +0000 (00:35 +0100)
adopterwindow.cpp
fullscreenwindow.cpp
fullscreenwindow.h
mainwindow.cpp
mainwindow.h
pkg/changelog

index a819594..d5bc82b 100644 (file)
@@ -57,7 +57,7 @@ void AdopterWindow::takeChildren(BookView *view, const QList<QWidget *> &others)
     leaveChildren();
     if (view) {
         bookView = view;
-        bookView->setParent(centralWidget());
+        bookView->setParent(this);
         bookView->show();
         QVBoxLayout *layout =
                 qobject_cast<QVBoxLayout *>(centralWidget()->layout());
index ca8baba..07bf291 100644 (file)
@@ -38,14 +38,35 @@ FullScreenWindow::FullScreenWindow(QWidget *parent):
 
 void FullScreenWindow::showFullScreen()
 {
-    TRACE;
+    Trace t("FullScreenWindow::showFullScreen");
     AdopterWindow::showFullScreen();
-    restoreButton->flash(3000);
+    placeChildren();
 }
 
 void FullScreenWindow::resizeEvent(QResizeEvent *e)
 {
+    Trace t("FullScreenWindow::resizeEvent");
+    QTimer::singleShot(100, this, SLOT(placeChildren()));
+    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");
 
     QRect screen = QApplication::desktop()->screenGeometry();
     int w = screen.width();
@@ -72,6 +93,9 @@ void FullScreenWindow::resizeEvent(QResizeEvent *e)
     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(
@@ -89,19 +113,4 @@ void FullScreenWindow::resizeEvent(QResizeEvent *e)
     }
 
     restoreButton->flash(3000);
-    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);
 }
index c30c309..df2496c 100644 (file)
@@ -39,6 +39,10 @@ protected:
     /** Handle size (and orientation) change. */
     void resizeEvent(QResizeEvent *e);
 
+protected slots:
+    /** Re-align adopted child windows. */
+    void placeChildren();
+
 private:
     TranslucentButton *restoreButton;
     Progress *progress;
index 8f6e2ef..6486ec5 100755 (executable)
@@ -64,7 +64,7 @@ MainWindow::MainWindow(QWidget *parent):
     setCentralWidget(central);
 
     // Book view
-    view = new BookView(central);
+    view = new BookView(this);
     view->show();
     layout->addWidget(view);
 
@@ -200,10 +200,13 @@ void MainWindow::showRegular()
     otherChildren << progress << previousButton << nextButton;
     takeChildren(view, otherChildren);
 
+#if 0
+
     // Adjust geometry of decorations
 
     QRect geo = geometry();
-    qDebug() << geo;
+    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;
@@ -236,14 +239,13 @@ void MainWindow::showRegular()
 #endif // Q_WS_MAEMO_5
     qDebug() << "previousButton geometry" << previousButton->geometry();
 
+#endif
+
     fullScreenWindow->hide();
     show();
 #if defined(Q_OS_SYMBIAN)
     activateWindow();
 #endif
-    progress->flash();
-    nextButton->flash();
-    previousButton->flash();
 }
 
 void MainWindow::showBig()
@@ -254,6 +256,8 @@ void MainWindow::showBig()
     leaveChildren();
     fullScreenWindow->takeChildren(view, progress, previousButton, nextButton);
 
+#if 0
+
     // Adjust geometry of decorations
     QRect screen = QApplication::desktop()->screenGeometry();
     int y = screen.height() - progress->thickness();
@@ -268,16 +272,16 @@ void MainWindow::showBig()
     previousButton->setGeometry(0, screen.height() - TranslucentButton::pixels,
         TranslucentButton::pixels, TranslucentButton::pixels);
 
-#ifdef Q_OS_SYMBIAN
-    hide();
 #endif
+
+// #ifdef Q_OS_SYMBIAN
+    hide();
+// #endif
+
     fullScreenWindow->showFullScreen();
 #ifdef Q_OS_SYMBIAN
     fullScreenWindow->activateWindow();
 #endif
-    progress->flash();
-    nextButton->flash();
-    previousButton->flash();
 }
 
 void MainWindow::setCurrentBook(const QModelIndex &current)
@@ -442,22 +446,47 @@ void MainWindow::timerEvent(QTimerEvent *event)
 
 void MainWindow::resizeEvent(QResizeEvent *e)
 {
-    TRACE;
+    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 = (e->size().width() < e->size().height());
-    toolBar->setVisible(isPortrait);
+    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 (bookView) {
-        qDebug() << "BookView geometry" << bookView->geometry();
-        QRect geo = bookView->geometry();
+    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());
@@ -467,8 +496,13 @@ void MainWindow::resizeEvent(QResizeEvent *e)
         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();
     }
-    QMainWindow::resizeEvent(e);
+
 }
 
 void MainWindow::about()
index 5de2120..4f499d2 100755 (executable)
@@ -55,6 +55,9 @@ protected:
     void timerEvent(QTimerEvent *event);
     void resizeEvent(QResizeEvent *event);
 
+protected slots:
+    void placeChildren();
+
 private:
     void setCurrentBook(const QModelIndex &current);
     BookView *view;
index d4bb2f4..800013b 100644 (file)
@@ -1,6 +1,7 @@
 dorian (0.4.0-1) unstable; urgency=low
 
   * Fix popup button positions
+  * Add tool bar on Symbian
 
  -- Akos Polster <akos@pipacs.com>  Sun, 21 Nov 2010 02:00:00 +0100