3 #include "mainbase.h"
\r
5 #include "platform.h"
\r
7 MainBase::MainBase(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 *MainBase::addToolBarAction(QObject *receiver,
\r
42 const QString &iconName,
\r
43 const QString &text,
\r
47 qDebug() << "icon" << iconName << "text" << text;
\r
52 // Create tool bar if needed
\r
53 toolBar = new QToolBar("", this);
\r
54 toolBar->setStyleSheet("margin:0; border:0; padding:0");
\r
55 addToolBar(Qt::BottomToolBarArea, toolBar);
\r
57 // Add tool bar action
\r
58 QPushButton *button = new QPushButton(this);
\r
59 button->setIconSize(QSize(60, 60));
\r
60 button->setFixedHeight(60);
\r
61 button->setIcon(QIcon(Platform::instance()->icon(iconName)));
\r
62 button->setSizePolicy(QSizePolicy::MinimumExpanding,
\r
63 QSizePolicy::Maximum);
\r
64 connect(button, SIGNAL(clicked()), receiver, member);
\r
65 toolBar->addWidget(button);
\r
67 // Add menu action, too
\r
68 action = menuBar()->addAction(text);
\r
69 connect(action, SIGNAL(triggered()), receiver, member);
\r
71 Q_UNUSED(important);
\r
72 action = toolBar->addAction(QIcon(Platform::instance()->icon(iconName)),
\r
73 text, receiver, member);
\r
76 action->setToolTip("");
\r
80 void MainBase::addToolBarSpace()
\r
82 #ifndef Q_OS_SYMBIAN
\r
83 QFrame *frame = new QFrame(toolBar);
\r
84 frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
\r
85 toolBar->addWidget(frame);
\r
89 void MainBase::updateToolBar()
\r
91 #if 0 // ifdef Q_OS_SYMBIAN
\r
94 QRect geometry = QApplication::desktop()->geometry();
\r
95 bool isPortrait = geometry.width() < geometry.height();
\r
96 bool isToolBarHidden = toolBar->isHidden();
\r
97 if (isPortrait && isToolBarHidden) {
\r
98 qDebug() << "Show tool bar";
\r
99 toolBar->setVisible(true);
\r
100 } else if (!isPortrait && !isToolBarHidden) {
\r
101 qDebug() << "Hide tool bar";
\r
102 toolBar->setVisible(false);
\r
105 #endif // Q_OS_SYMBIAN
\r
108 void MainBase::showEvent(QShowEvent *event)
\r
110 Trace t("MainBase::showEvent");
\r
112 QMainWindow::showEvent(event);
\r
115 void MainBase::resizeEvent(QResizeEvent *event)
\r
117 Trace t("MainBase::resizeEvent");
\r
119 QMainWindow::resizeEvent(event);
\r
122 void MainBase::hideToolBar()
\r
129 bool MainBase::isToolBarHidden()
\r
131 return toolBar && toolBar->isHidden();
\r
134 int MainBase::toolBarHeight()
\r
136 return toolBar? toolBar->height(): 0;
\r
139 void MainBase::show()
\r
141 Trace t("MainBase::show");
\r
142 #ifdef Q_OS_SYMBIAN
\r
143 foreach (QWidget *w, QApplication::allWidgets()) {
\r
144 w->setContextMenuPolicy(Qt::NoContextMenu);
\r
148 QMainWindow::show();
\r