Add tool bar on Symbian. Fix some orientation change bugs.
[dorian] / adopterwindow.cpp
index 27d5dbf..a819594 100644 (file)
 #include "platform.h"
 #include "settings.h"
 
-AdopterWindow::AdopterWindow(QWidget *parent): QMainWindow(parent), bookView(0)
+AdopterWindow::AdopterWindow(QWidget *parent):
+    QMainWindow(parent), bookView(0), grabbingVolumeKeys(false), toolBar(0)
 {
     TRACE;
 
 #ifdef Q_WS_MAEMO_5
     setAttribute(Qt::WA_Maemo5StackedWindow, true);
-#endif // Q_WS_MAEMO_5
+#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
@@ -35,7 +37,7 @@ AdopterWindow::AdopterWindow(QWidget *parent): QMainWindow(parent), bookView(0)
 #else
     // Tool bar
     setUnifiedTitleAndToolBarOnMac(true);
-    toolBar = addToolBar("controls");
+    toolBar = addToolBar("");
     toolBar->setMovable(false);
     toolBar->setFloatable(false);
     toolBar->toggleViewAction()->setVisible(false);
@@ -45,10 +47,8 @@ AdopterWindow::AdopterWindow(QWidget *parent): QMainWindow(parent), bookView(0)
 #endif // Q_OS_SYMBIAN
 
     // Monitor settings
-    Settings *settings = Settings::instance();
-    connect(settings, SIGNAL(valueChanged(const QString &)),
+    connect(Settings::instance(), SIGNAL(valueChanged(const QString &)),
             this, SLOT(onSettingsChanged(const QString &)));
-    settings->setValue("usevolumekeys", settings->value("usevolumekeys"));
 }
 
 void AdopterWindow::takeChildren(BookView *view, const QList<QWidget *> &others)
@@ -58,8 +58,10 @@ void AdopterWindow::takeChildren(BookView *view, const QList<QWidget *> &others)
     if (view) {
         bookView = view;
         bookView->setParent(centralWidget());
-        centralWidget()->layout()->addWidget(bookView);
         bookView->show();
+        QVBoxLayout *layout =
+                qobject_cast<QVBoxLayout *>(centralWidget()->layout());
+        layout->addWidget(bookView, 1);
     }
     foreach (QWidget *child, others) {
         if (child) {
@@ -77,6 +79,14 @@ void AdopterWindow::leaveChildren()
     }
 }
 
+bool AdopterWindow::hasChild(QWidget *child)
+{
+    if (child == bookView) {
+        return true;
+    }
+    return this == child->parent();
+}
+
 void AdopterWindow::show()
 {
 #ifdef Q_OS_SYMBIAN
@@ -93,20 +103,38 @@ void AdopterWindow::show()
 QAction *AdopterWindow::addToolBarAction(QObject *receiver,
                                          const char *member,
                                          const QString &iconName,
-                                         const QString &text)
+                                         const QString &text,
+                                         bool important)
 {
     TRACE;
     qDebug() << "icon" << iconName << "text" << text;
+    QAction *action;
 #ifndef Q_OS_SYMBIAN
-    return toolBar->addAction(QIcon(Platform::instance()->icon(iconName)),
-                              text, receiver, member);
+    Q_UNUSED(important);
+    action = toolBar->addAction(QIcon(Platform::instance()->icon(iconName)),
+                                text, receiver, member);
 #else
-    Q_UNUSED(iconName);
-    QAction *action = new QAction(text, this);
+    if (toolBar && important) {
+        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);
+    }
+    action = new QAction(text, this);
     menuBar()->addAction(action);
     connect(action, SIGNAL(triggered()), receiver, member);
-    return action;
 #endif
+
+#if defined Q_WS_MAEMO_5
+    action->setText("");
+    action->setToolTip("");
+#endif
+
+    return action;
 }
 
 void AdopterWindow::addToolBarSpace()
@@ -204,10 +232,10 @@ void AdopterWindow::keyPressEvent(QKeyEvent *event)
 
 void AdopterWindow::onSettingsChanged(const QString &key)
 {
-    TRACE;
     if (key == "usevolumekeys") {
-        qDebug() << key;
-        grabVolumeKeys(Settings::instance()->value(key).toBool());
+        bool grab = Settings::instance()->value(key, false).toBool();
+        qDebug() << "AdopterWindow::onSettingsChanged: usevolumekeys" << grab;
+        grabVolumeKeys(grab);
     }
 }