Add icon to about box.
[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 #if defined(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     setCentralWidget(frame);\r
20 \r
21 #if defined(Q_OS_SYMBIAN)\r
22     QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this);\r
23     closeAction->setSoftKeyRole(QAction::NegativeSoftKey);\r
24     connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));\r
25     QMainWindow::addAction(closeAction);\r
26 #endif // Q_OS_SYMBIAN\r
27 }\r
28 \r
29 void MainBase::addToolBar()\r
30 {\r
31     TRACE;\r
32 \r
33     if (toolBar) {\r
34         return;\r
35     }\r
36 \r
37 #if defined(Q_OS_SYMBIAN)\r
38     toolBar = new QToolBar("", this);\r
39     toolBar->setFixedHeight(Platform::softKeyHeight());\r
40     toolBar->show();\r
41     QMainWindow::addToolBar(Qt::BottomToolBarArea, toolBar);\r
42 #else\r
43     toolBar = QMainWindow::addToolBar("");\r
44 #endif\r
45 \r
46     setUnifiedTitleAndToolBarOnMac(true);\r
47     toolBar->setMovable(false);\r
48     toolBar->setFloatable(false);\r
49     toolBar->toggleViewAction()->setVisible(false);\r
50 \r
51 #if defined(Q_WS_X11) && !defined(Q_WS_MAEMO_5)\r
52     toolBar->setIconSize(QSize(Platform::toolBarIconHeight(),\r
53                                Platform::toolBarIconHeight()));\r
54 #endif\r
55 }\r
56 \r
57 QAction *MainBase::addToolBarAction(QObject *receiver,\r
58                                     const char *member,\r
59                                     const QString &iconName,\r
60                                     const QString &text,\r
61                                     bool important)\r
62 {\r
63     TRACE;\r
64     qDebug() << "icon" << iconName << "text" << text;\r
65     QAction *action;\r
66 #ifdef Q_OS_SYMBIAN\r
67     if (important) {\r
68         // Add tool bar action\r
69         addToolBar();\r
70         QPushButton *button = new QPushButton(this);\r
71         button->setIconSize(QSize(60, 60));\r
72         button->setFixedHeight(60);\r
73         button->setIcon(QIcon(Platform::instance()->icon(iconName)));\r
74         button->setSizePolicy(QSizePolicy::MinimumExpanding,\r
75                               QSizePolicy::Maximum);\r
76         connect(button, SIGNAL(clicked()), receiver, member);\r
77         toolBar->addWidget(button);\r
78     }\r
79     // Add menu action, too\r
80     action = menuBar()->addAction(text);\r
81     connect(action, SIGNAL(triggered()), receiver, member);\r
82 #else\r
83     Q_UNUSED(important);\r
84     addToolBar();\r
85     action = toolBar->addAction(QIcon(Platform::instance()->icon(iconName)),\r
86                                 text, receiver, member);\r
87 #endif\r
88 \r
89     action->setToolTip("");\r
90     return action;\r
91 }\r
92 \r
93 void MainBase::addToolBarSpace()\r
94 {\r
95 #ifndef Q_OS_SYMBIAN\r
96     addToolBar();\r
97     QFrame *frame = new QFrame(toolBar);\r
98     frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);\r
99     toolBar->addWidget(frame);\r
100 #endif\r
101 }\r
102 \r
103 int MainBase::toolBarHeight()\r
104 {\r
105     return toolBar? toolBar->height(): 0;\r
106 }\r
107 \r
108 void MainBase::show()\r
109 {\r
110     Trace t("MainBase::show");\r
111 #ifdef Q_OS_SYMBIAN\r
112     foreach (QWidget *w, QApplication::allWidgets()) {\r
113         w->setContextMenuPolicy(Qt::NoContextMenu);\r
114     }\r
115     showMaximized();\r
116 #else\r
117     QMainWindow::show();\r
118 #endif\r
119 }\r
120 \r
121 #if 0 // ifdef Q_OS_SYMBIAN\r
122 \r
123 void MainBase::resizeEvent(QResizeEvent *e)\r
124 {\r
125     Trace t("MainBase::resizeEvent");\r
126 \r
127     QMainWindow::resizeEvent(e);\r
128     if (!toolBar) {\r
129         return;\r
130     }\r
131     QSize available = Platform::availableSize();\r
132     toolBar->setGeometry(0, available.height() - Platform::softKeyHeight(),\r
133                          available.width(), Platform::softKeyHeight());\r
134 }\r
135 \r
136 #endif // Q_OS_SYMBIAN\r