Show button for full screen mode on Symbian, too.
[dorian] / widgets / mainbase.cpp
1 #include <QtGui>\r
2 \r
3 #include "mainbase.h"\r
4 #include "trace.h"\r
5 #include "platform.h"\r
6 \r
7 MainBase::MainBase(QWidget *parent): QMainWindow(parent), toolBar(0)\r
8 {\r
9     TRACE;\r
10 \r
11 #ifdef Q_WS_MAEMO_5\r
12     setAttribute(Qt::WA_Maemo5StackedWindow, true);\r
13 #endif\r
14 \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
19     //frame->show();\r
20     setCentralWidget(frame);\r
21 \r
22 #ifdef Q_OS_SYMBIAN\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
27 #else\r
28     // Tool bar\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
36 #endif\r
37 #endif // Q_OS_SYMBIAN\r
38 }\r
39 \r
40 QAction *MainBase::addToolBarAction(QObject *receiver,\r
41                                     const char *member,\r
42                                     const QString &iconName,\r
43                                     const QString &text,\r
44                                     bool important)\r
45 {\r
46     TRACE;\r
47     qDebug() << "icon" << iconName << "text" << text;\r
48     QAction *action;\r
49 #ifdef Q_OS_SYMBIAN\r
50     if (important) {\r
51         if (!toolBar) {\r
52             // Create tool bar if needed\r
53             toolBar = new QToolBar("", this);\r
54             addToolBar(Qt::BottomToolBarArea, toolBar);\r
55         }\r
56         // Add tool bar action\r
57         QPushButton *button = new QPushButton(this);\r
58         button->setIconSize(QSize(60, 60));\r
59         button->setFixedHeight(60);\r
60         button->setIcon(QIcon(Platform::instance()->icon(iconName)));\r
61         button->setSizePolicy(QSizePolicy::MinimumExpanding,\r
62                               QSizePolicy::Maximum);\r
63         connect(button, SIGNAL(clicked()), receiver, member);\r
64         toolBar->addWidget(button);\r
65     }\r
66     // Add menu action, too\r
67     action = menuBar()->addAction(text);\r
68     connect(action, SIGNAL(triggered()), receiver, member);\r
69 #else\r
70     Q_UNUSED(important);\r
71     action = toolBar->addAction(QIcon(Platform::instance()->icon(iconName)),\r
72                                 text, receiver, member);\r
73 #endif\r
74 \r
75     action->setToolTip("");\r
76     return action;\r
77 }\r
78 \r
79 void MainBase::addToolBarSpace()\r
80 {\r
81     QFrame *frame = new QFrame(toolBar);\r
82     frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);\r
83     toolBar->addWidget(frame);\r
84 }\r
85 \r
86 void MainBase::updateToolBar()\r
87 {\r
88 #if 0 // ifdef Q_OS_SYMBIAN\r
89     TRACE;\r
90     if (toolBar) {\r
91         QRect geometry = QApplication::desktop()->geometry();\r
92         bool isPortrait = geometry.width() < geometry.height();\r
93         bool isToolBarHidden = toolBar->isHidden();\r
94         if (isPortrait && isToolBarHidden) {\r
95             qDebug() << "Show tool bar";\r
96             toolBar->setVisible(true);\r
97         } else if (!isPortrait && !isToolBarHidden) {\r
98             qDebug() << "Hide tool bar";\r
99             toolBar->setVisible(false);\r
100         }\r
101     }\r
102 #endif // Q_OS_SYMBIAN\r
103 }\r
104 \r
105 void MainBase::showEvent(QShowEvent *event)\r
106 {\r
107     Trace t("MainBase::showEvent");\r
108     updateToolBar();\r
109     QMainWindow::showEvent(event);\r
110 }\r
111 \r
112 void MainBase::resizeEvent(QResizeEvent *event)\r
113 {\r
114     Trace t("MainBase::resizeEvent");\r
115     updateToolBar();\r
116     QMainWindow::resizeEvent(event);\r
117 }\r
118 \r
119 void MainBase::hideToolBar()\r
120 {\r
121     if (toolBar) {\r
122         toolBar->hide();\r
123     }\r
124 }\r
125 \r
126 bool MainBase::isToolBarHidden()\r
127 {\r
128     return toolBar && toolBar->isHidden();\r
129 }\r
130 \r
131 int MainBase::toolBarHeight()\r
132 {\r
133     return toolBar? toolBar->height(): 0;\r
134 }\r
135 \r
136 void MainBase::show()\r
137 {\r
138     Trace t("MainBase::show");\r
139 #ifdef Q_OS_SYMBIAN\r
140     foreach (QWidget *w, QApplication::allWidgets()) {\r
141         w->setContextMenuPolicy(Qt::NoContextMenu);\r
142     }\r
143     showMaximized();\r
144 #else\r
145     QMainWindow::show();\r
146 #endif\r
147 }\r