Undo bad fix on Symbian.
[dorian] / widgets / mainbase.cpp
index f3d176d..c9a4d54 100755 (executable)
@@ -1,14 +1,14 @@
 #include <QtGui>\r
 \r
-#include "mainwindow.h"\r
+#include "mainbase.h"\r
 #include "trace.h"\r
 #include "platform.h"\r
 \r
-MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), toolBar(0)\r
+MainBase::MainBase(QWidget *parent): QMainWindow(parent), toolBar(0)\r
 {\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,55 +16,60 @@ MainWindow::MainWindow(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
+    toolBar->setFixedHeight(Platform::softKeyHeight());\r
+    toolBar->show();\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
+    toolBar->setIconSize(QSize(Platform::toolBarIconHeight(),\r
+                               Platform::toolBarIconHeight()));\r
 #endif\r
-#endif // Q_OS_SYMBIAN\r
 }\r
 \r
-QAction *MainWindow::addToolBarAction(QObject *receiver,\r
-                                      const char *member,\r
-                                      const QString &iconName,\r
-                                      const QString &text,\r
-                                      bool important)\r
+QAction *MainBase::addToolBarAction(QObject *receiver,\r
+                                    const char *member,\r
+                                    const QString &iconName,\r
+                                    const QString &text,\r
+                                    bool important)\r
 {\r
     TRACE;\r
     qDebug() << "icon" << iconName << "text" << text;\r
     QAction *action;\r
-#ifndef Q_OS_SYMBIAN\r
-    Q_UNUSED(important);\r
-    action = toolBar->addAction(QIcon(Platform::instance()->icon(iconName)),\r
-                                text, receiver, member);\r
-#else\r
-    if (!toolBar && important) {\r
-        // Create tool bar if needed\r
-        toolBar = new QToolBar("", this);\r
-        // toolBar->setFixedHeight(63);\r
-        toolBar->setStyleSheet("margin:0; border:0; padding:0");\r
-        toolBar->setSizePolicy(QSizePolicy::MinimumExpanding,\r
-                               QSizePolicy::Maximum);\r
-        addToolBar(Qt::BottomToolBarArea, toolBar);\r
-    }\r
+#ifdef Q_OS_SYMBIAN\r
     if (important) {\r
         // Add tool bar action\r
+        addToolBar();\r
         QPushButton *button = new QPushButton(this);\r
         button->setIconSize(QSize(60, 60));\r
-        button->setFixedSize(89, 60);\r
+        button->setFixedHeight(60);\r
         button->setIcon(QIcon(Platform::instance()->icon(iconName)));\r
         button->setSizePolicy(QSizePolicy::MinimumExpanding,\r
                               QSizePolicy::Maximum);\r
@@ -72,75 +77,58 @@ QAction *MainWindow::addToolBarAction(QObject *receiver,
         toolBar->addWidget(button);\r
     }\r
     // Add menu action, too\r
-    action = new QAction(text, this);\r
-    menuBar()->addAction(action);\r
+    action = menuBar()->addAction(text);\r
     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
 \r
-    action->setText("");\r
     action->setToolTip("");\r
-\r
     return action;\r
 }\r
 \r
-void MainWindow::addToolBarSpace()\r
+void MainBase::addToolBarSpace()\r
 {\r
-#ifndef Q_OS_SYMBIAN\r
+    addToolBar();\r
     QFrame *frame = new QFrame(toolBar);\r
     frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);\r
     toolBar->addWidget(frame);\r
-#endif\r
-}\r
-\r
-#ifdef Q_OS_SYMBIAN\r
-\r
-void MainWindow::updateToolBar()\r
-{\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
 }\r
 \r
-bool MainWindow::portrait()\r
+int MainBase::toolBarHeight()\r
 {\r
-    QRect geometry = QApplication::desktop()->geometry();\r
-    return geometry.width() < geometry.height();\r
+    return toolBar? toolBar->height(): 0;\r
 }\r
 \r
-#endif // Q_OS_SYMBIAN\r
-\r
-void MainWindow::showEvent(QShowEvent *e)\r
+void MainBase::show()\r
 {\r
-    Trace t("MainWindow::showEvent");\r
-\r
+    Trace t("MainBase::show");\r
 #ifdef Q_OS_SYMBIAN\r
-    updateToolBar();\r
+    foreach (QWidget *w, QApplication::allWidgets()) {\r
+        w->setContextMenuPolicy(Qt::NoContextMenu);\r
+    }\r
+    showMaximized();\r
+#else\r
+    QMainWindow::show();\r
 #endif\r
-    QMainWindow::showEvent(e);\r
 }\r
 \r
-void MainWindow::resizeEvent(QResizeEvent *event)\r
-{\r
-    Trace t("MainWindow::resizeEvent");\r
-#ifdef Q_OS_SYMBIAN\r
-    updateToolBar();\r
-#endif\r
-    QMainWindow::resizeEvent(event);\r
-}\r
+#if 0 // ifdef Q_OS_SYMBIAN\r
 \r
-void MainWindow::hideToolBar()\r
+void MainBase::resizeEvent(QResizeEvent *e)\r
 {\r
-    if (toolBar) {\r
-        toolBar->hide();\r
+    Trace t("MainBase::resizeEvent");\r
+\r
+    QMainWindow::resizeEvent(e);\r
+    if (!toolBar) {\r
+        return;\r
     }\r
+    QSize available = Platform::availableSize();\r
+    toolBar->setGeometry(0, available.height() - Platform::softKeyHeight(),\r
+                         available.width(), Platform::softKeyHeight());\r
 }\r
+\r
+#endif // Q_OS_SYMBIAN\r