+#include <QtGui>\r
+\r
+#include "mainwindow.h"\r
+#include "trace.h"\r
+#include "platform.h"\r
+\r
+MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), toolBar(0)\r
+{\r
+ TRACE;\r
+\r
+#ifdef Q_WS_MAEMO_5\r
+ setAttribute(Qt::WA_Maemo5StackedWindow, true);\r
+#endif\r
+\r
+ QFrame *frame = new QFrame(this);\r
+ 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
+ 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
+#else\r
+ // Tool bar\r
+ setUnifiedTitleAndToolBarOnMac(true);\r
+ toolBar = addToolBar("");\r
+ toolBar->setMovable(false);\r
+ toolBar->setFloatable(false);\r
+ toolBar->toggleViewAction()->setVisible(false);\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 *MainWindow::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
+ if (important) {\r
+ // Add tool bar action\r
+ QPushButton *button = new QPushButton(this);\r
+ button->setIconSize(QSize(60, 60));\r
+ button->setFixedSize(89, 60);\r
+ button->setIcon(QIcon(Platform::instance()->icon(iconName)));\r
+ button->setSizePolicy(QSizePolicy::MinimumExpanding,\r
+ QSizePolicy::Maximum);\r
+ connect(button, SIGNAL(clicked()), receiver, member);\r
+ toolBar->addWidget(button);\r
+ }\r
+ // Add menu action, too\r
+ action = new QAction(text, this);\r
+ menuBar()->addAction(action);\r
+ connect(action, SIGNAL(triggered()), receiver, member);\r
+#endif\r
+\r
+ action->setText("");\r
+ action->setToolTip("");\r
+\r
+ return action;\r
+}\r
+\r
+void MainWindow::addToolBarSpace()\r
+{\r
+#ifndef Q_OS_SYMBIAN\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
+{\r
+ QRect geometry = QApplication::desktop()->geometry();\r
+ return geometry.width() < geometry.height();\r
+}\r
+\r
+#endif // Q_OS_SYMBIAN\r
+\r
+void MainWindow::showEvent(QShowEvent *e)\r
+{\r
+ Trace t("MainWindow::showEvent");\r
+\r
+#ifdef Q_OS_SYMBIAN\r
+ updateToolBar();\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
+\r
+void MainWindow::hideToolBar()\r
+{\r
+ if (toolBar) {\r
+ toolBar->hide();\r
+ }\r
+}\r