Handle nested TOC items.
[dorian] / mainwindow.cpp
index 73d1661..f99ada6 100755 (executable)
@@ -1,11 +1,4 @@
 #include <QtGui>
-#include <QtDebug>
-#include <QDir>
-#include <QApplication>
-#include <QFileInfo>
-#include <QStringList>
-#include <QWebView>
-#include <QWebFrame>
 
 #ifdef Q_WS_MAEMO_5
 #   include <QtMaemo5/QMaemo5InformationBox>
@@ -46,7 +39,7 @@ const int DORIAN_PROGRESS_HEIGHT = 17;
 MainWindow::MainWindow(QWidget *parent):
     AdopterWindow(parent), view(0), preventBlankingTimer(-1)
 {
-    Trace t("MainWindow::MainWindow");
+    TRACE;
 #ifdef Q_WS_MAEMO_5
     setAttribute(Qt::WA_Maemo5StackedWindow, true);
 #endif
@@ -106,6 +99,8 @@ MainWindow::MainWindow(QWidget *parent):
     addToolBarSpace();
     fullScreenAction = addToolBarAction(this, SLOT(showBig()),
                                         "view-fullscreen", tr("Full screen"));
+#else
+    (void)addToolBarAction(this, SLOT(close()), "", tr("Exit"));
 #endif
 
     // Buttons on top of the book view
@@ -189,13 +184,15 @@ void MainWindow::onCurrentBookChanged()
 
 void MainWindow::showRegular()
 {
-    Trace t("MainWindow::showRegular");
-    fullScreenWindow->hide();
-    fullScreenWindow->leaveChildren();
+    TRACE;
 
+    // Re-parent children
+    fullScreenWindow->leaveChildren();
     QList<QWidget *> otherChildren;
     otherChildren << progress << previousButton << nextButton;
     takeChildren(view, otherChildren);
+
+    // Adjust geometry of decorations
     QRect geo = geometry();
     progress->setGeometry(0, 0, geo.width(), DORIAN_PROGRESS_HEIGHT);
 #if defined(Q_WS_MAEMO_5)
@@ -213,22 +210,35 @@ void MainWindow::showRegular()
     previousButton->setGeometry(0, geo.height() - TranslucentButton::pixels,
         TranslucentButton::pixels, TranslucentButton::pixels);
     nextButton->setGeometry(geo.width() - TranslucentButton::pixels - 25,
-        toolBar->height(), TranslucentButton::pixels, TranslucentButton::pixels);
+        toolBar->height(), TranslucentButton::pixels,
+        TranslucentButton::pixels);
 #endif // Q_WS_MAEMO_5
     qDebug() << "previousButton geometry" << previousButton->geometry();
+
+    fullScreenWindow->hide();
+    show();
+#if defined(Q_OS_SYMBIAN)
+    activateWindow();
+#elif defined(Q_WS_MAEMO_5)
+    // FIXME: This is ugly.
+    view->restoreLastBookmark();
+#endif
     progress->flash();
-    nextButton->show();
-    previousButton->show();
     nextButton->flash(1500);
     previousButton->flash(1500);
 }
 
 void MainWindow::showBig()
 {
-    Trace t("MainWindow::showBig");
+    TRACE;
+
+    // Re-parent children
     leaveChildren();
     QList<QWidget *> otherChildren;
     otherChildren << progress << nextButton << previousButton;
+    fullScreenWindow->takeChildren(view, otherChildren);
+
+    // Adjust geometry of decorations
     QRect screen = QApplication::desktop()->screenGeometry();
     progress->setGeometry(0, 0, screen.width(), DORIAN_PROGRESS_HEIGHT);
 #if defined(Q_WS_MAEMO_5)
@@ -236,13 +246,18 @@ void MainWindow::showBig()
         TranslucentButton::pixels, TranslucentButton::pixels);
 #else
     nextButton->setGeometry(screen.width() - TranslucentButton::pixels - 25, 0,
-                            TranslucentButton::pixels, TranslucentButton::pixels);
+        TranslucentButton::pixels, TranslucentButton::pixels);
 #endif // Q_WS_MAEMO_5
     previousButton->setGeometry(0, screen.height() - TranslucentButton::pixels,
         TranslucentButton::pixels, TranslucentButton::pixels);
 
-    fullScreenWindow->takeChildren(view, otherChildren);
+#ifdef Q_OS_SYMBIAN
+    hide();
+#endif
     fullScreenWindow->showFullScreen();
+#ifdef Q_OS_SYMBIAN
+    fullScreenWindow->activateWindow();
+#endif
     progress->flash();
     nextButton->flash(1500);
     previousButton->flash(1500);
@@ -295,7 +310,7 @@ void MainWindow::showBookmarks()
 
 void MainWindow::closeEvent(QCloseEvent *event)
 {
-    Trace t("MainWindow::closeEvent");
+    TRACE;
     view->setLastBookmark();
     event->accept();
 }
@@ -333,7 +348,7 @@ void MainWindow::onSettingsChanged(const QString &key)
 
 void MainWindow::onPartLoadStart()
 {
-    Trace t("MainWindow::onPartLoadStart");
+    TRACE;
 #ifdef Q_WS_MAEMO_5
     setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
 #endif
@@ -341,7 +356,7 @@ void MainWindow::onPartLoadStart()
 
 void MainWindow::onPartLoadEnd(int index)
 {
-    Trace t("MainWindow::onPartLoadEnd");
+    TRACE;
     bool enablePrevious = false;
     bool enableNext = false;
     Book *book = Library::instance()->book(mCurrent);
@@ -360,13 +375,13 @@ void MainWindow::onPartLoadEnd(int index)
 
 void MainWindow::onAddBookmark(const QString &note)
 {
-    Trace t("MainWindow:onAddBookmark");
+    TRACE;
     view->addBookmark(note);
 }
 
 void MainWindow::onGoToBookmark(int index)
 {
-    Trace t("MainWindow::onGoToBookmark");
+    TRACE;
     Book *book = Library::instance()->book(mCurrent);
     view->goToBookmark(book->bookmarks()[index]);
 }
@@ -385,7 +400,7 @@ void MainWindow::showChapters()
 
 void MainWindow::onGoToChapter(int index)
 {
-    Trace t("MainWindow::onGoToChapter");
+    TRACE;
 
     Book *book = Library::instance()->book(mCurrent);
     if (book) {
@@ -411,7 +426,7 @@ void MainWindow::timerEvent(QTimerEvent *event)
 
 void MainWindow::resizeEvent(QResizeEvent *e)
 {
-    Trace t("MainWindow::resizeEvent");
+    TRACE;
     progress->setGeometry(QRect(0, 0, e->size().width(), DORIAN_PROGRESS_HEIGHT));
 #if defined(Q_WS_MAEMO_5)
     previousButton->setGeometry(0,