3 #include "mainwindow.h"
\r
5 #include "platform.h"
\r
7 MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), toolBar(0)
\r
12 setAttribute(Qt::WA_Maemo5StackedWindow, true);
\r
15 QFrame *frame = new QFrame(this);
\r
16 QVBoxLayout *layout = new QVBoxLayout(frame);
\r
17 layout->setMargin(0);
\r
18 frame->setLayout(layout);
\r
20 setCentralWidget(frame);
\r
23 QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this);
\r
24 closeAction->setSoftKeyRole(QAction::NegativeSoftKey);
\r
25 connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
\r
26 QMainWindow::addAction(closeAction);
\r
29 setUnifiedTitleAndToolBarOnMac(true);
\r
30 toolBar = addToolBar("");
\r
31 toolBar->setMovable(false);
\r
32 toolBar->setFloatable(false);
\r
33 toolBar->toggleViewAction()->setVisible(false);
\r
34 #if defined(Q_WS_X11) && !defined(Q_WS_MAEMO_5)
\r
35 toolBar->setIconSize(QSize(42, 42));
\r
37 #endif // Q_OS_SYMBIAN
\r
40 QAction *MainWindow::addToolBarAction(QObject *receiver,
\r
42 const QString &iconName,
\r
43 const QString &text,
\r
47 qDebug() << "icon" << iconName << "text" << text;
\r
49 #ifndef Q_OS_SYMBIAN
\r
50 Q_UNUSED(important);
\r
51 action = toolBar->addAction(QIcon(Platform::instance()->icon(iconName)),
\r
52 text, receiver, member);
\r
54 if (!toolBar && important) {
\r
55 // Create tool bar if needed
\r
56 toolBar = new QToolBar("", this);
\r
57 // toolBar->setFixedHeight(63);
\r
58 toolBar->setStyleSheet("margin:0; border:0; padding:0");
\r
59 toolBar->setSizePolicy(QSizePolicy::MinimumExpanding,
\r
60 QSizePolicy::Maximum);
\r
61 addToolBar(Qt::BottomToolBarArea, toolBar);
\r
64 // Add tool bar action
\r
65 QPushButton *button = new QPushButton(this);
\r
66 button->setIconSize(QSize(60, 60));
\r
67 button->setFixedSize(89, 60);
\r
68 button->setIcon(QIcon(Platform::instance()->icon(iconName)));
\r
69 button->setSizePolicy(QSizePolicy::MinimumExpanding,
\r
70 QSizePolicy::Maximum);
\r
71 connect(button, SIGNAL(clicked()), receiver, member);
\r
72 toolBar->addWidget(button);
\r
74 // Add menu action, too
\r
75 action = new QAction(text, this);
\r
76 menuBar()->addAction(action);
\r
77 connect(action, SIGNAL(triggered()), receiver, member);
\r
80 action->setText("");
\r
81 action->setToolTip("");
\r
86 void MainWindow::addToolBarSpace()
\r
88 #ifndef Q_OS_SYMBIAN
\r
89 QFrame *frame = new QFrame(toolBar);
\r
90 frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
\r
91 toolBar->addWidget(frame);
\r
97 void MainWindow::updateToolBar()
\r
101 QRect geometry = QApplication::desktop()->geometry();
\r
102 bool isPortrait = geometry.width() < geometry.height();
\r
103 bool isToolBarHidden = toolBar->isHidden();
\r
104 if (isPortrait && isToolBarHidden) {
\r
105 qDebug() << "Show tool bar";
\r
106 toolBar->setVisible(true);
\r
107 } else if (!isPortrait && !isToolBarHidden) {
\r
108 qDebug() << "Hide tool bar";
\r
109 toolBar->setVisible(false);
\r
114 bool MainWindow::portrait()
\r
116 QRect geometry = QApplication::desktop()->geometry();
\r
117 return geometry.width() < geometry.height();
\r
120 #endif // Q_OS_SYMBIAN
\r
122 void MainWindow::showEvent(QShowEvent *e)
\r
124 Trace t("MainWindow::showEvent");
\r
126 #ifdef Q_OS_SYMBIAN
\r
129 QMainWindow::showEvent(e);
\r
132 void MainWindow::resizeEvent(QResizeEvent *event)
\r
134 Trace t("MainWindow::resizeEvent");
\r
135 #ifdef Q_OS_SYMBIAN
\r
138 QMainWindow::resizeEvent(event);
\r
141 void MainWindow::hideToolBar()
\r