3 #if defined(Q_WS_MAEMO_5)
4 # include <QtGui/QX11Info>
6 # include <X11/Xatom.h>
7 # include <QAbstractKineticScroller>
10 #include "adopterwindow.h"
16 #include "translucentbutton.h"
18 AdopterWindow::AdopterWindow(QWidget *parent):
19 QMainWindow(parent), bookView(0), grabbingVolumeKeys(false), toolBar(0),
20 progress(0), previousButton(0), nextButton(0)
25 setAttribute(Qt::WA_Maemo5StackedWindow, true);
28 QFrame *frame = new QFrame(this);
29 QVBoxLayout *layout = new QVBoxLayout(frame);
31 frame->setLayout(layout);
33 setCentralWidget(frame);
36 QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this);
37 closeAction->setSoftKeyRole(QAction::NegativeSoftKey);
38 connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
39 QMainWindow::addAction(closeAction);
42 setUnifiedTitleAndToolBarOnMac(true);
43 toolBar = addToolBar("");
44 toolBar->setMovable(false);
45 toolBar->setFloatable(false);
46 toolBar->toggleViewAction()->setVisible(false);
47 #if defined(Q_WS_X11) && !defined(Q_WS_MAEMO_5)
48 toolBar->setIconSize(QSize(42, 42));
50 #endif // Q_OS_SYMBIAN
53 connect(Settings::instance(), SIGNAL(valueChanged(const QString &)),
54 this, SLOT(onSettingsChanged(const QString &)));
57 void AdopterWindow::takeBookView(BookView *view,
59 TranslucentButton *previous,
60 TranslucentButton *next)
72 bookView->setParent(this);
73 centralWidget()->layout()->addWidget(bookView);
77 previousButton = previous;
79 progress->setParent(this);
80 previousButton->setParent(this);
81 nextButton->setParent(this);
84 void AdopterWindow::leaveBookView()
89 centralWidget()->layout()->removeWidget(bookView);
97 bool AdopterWindow::hasBookView()
102 void AdopterWindow::show()
104 Trace t("AdopterWindow::show");
106 foreach (QWidget *w, QApplication::allWidgets()) {
107 w->setContextMenuPolicy(Qt::NoContextMenu);
115 QAction *AdopterWindow::addToolBarAction(QObject *receiver,
117 const QString &iconName,
122 qDebug() << "icon" << iconName << "text" << text;
126 action = toolBar->addAction(QIcon(Platform::instance()->icon(iconName)),
127 text, receiver, member);
129 if (!toolBar && important) {
130 // Create tool bar if needed
131 toolBar = new QToolBar("", this);
132 // toolBar->setFixedWidth(QApplication::desktop()->
133 // availableGeometry().width());
134 toolBar->setFixedHeight(65);
135 toolBar->setStyleSheet("margin:0; border:0; padding:0");
136 toolBar->setSizePolicy(QSizePolicy::MinimumExpanding,
137 QSizePolicy::Maximum);
138 addToolBar(Qt::BottomToolBarArea, toolBar);
141 // Add tool bar action
142 QPushButton *button = new QPushButton(this);
143 button->setIconSize(QSize(60, 60));
144 button->setFixedSize(89, 60);
145 button->setIcon(QIcon(Platform::instance()->icon(iconName)));
146 button->setSizePolicy(QSizePolicy::MinimumExpanding,
147 QSizePolicy::Maximum);
148 connect(button, SIGNAL(clicked()), receiver, member);
149 toolBar->addWidget(button);
151 // Add menu action, too
152 action = new QAction(text, this);
153 menuBar()->addAction(action);
154 connect(action, SIGNAL(triggered()), receiver, member);
157 #if defined Q_WS_MAEMO_5
159 action->setToolTip("");
165 void AdopterWindow::addToolBarSpace()
168 QFrame *frame = new QFrame(toolBar);
169 frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
170 toolBar->addWidget(frame);
174 void AdopterWindow::grabVolumeKeys(bool grab)
177 grabbingVolumeKeys = grab;
179 doGrabVolumeKeys(grab);
185 void AdopterWindow::doGrabVolumeKeys(bool grab)
189 qDebug() << "Not visible - skipping";
193 qDebug() << "Could not get window ID - skipping";
196 unsigned long val = grab? 1: 0;
197 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
199 qCritical() << "Unable to obtain _HILDON_ZOOM_KEY_ATOM";
202 XChangeProperty(QX11Info::display(),
208 reinterpret_cast<unsigned char *>(&val),
210 qDebug() << "Grabbed volume keys";
213 #endif // Q_WS_MAEMO_5
215 void AdopterWindow::showEvent(QShowEvent *e)
217 Trace t("AdopterWindow::showEvent");
222 qDebug() << "Show tool bar";
223 toolBar->setVisible(true);
225 qDebug() << "Hide tool bar";
226 toolBar->setVisible(false);
229 #endif // Q_OS_SYMBIAN
230 QMainWindow::showEvent(e);
231 #if defined(Q_WS_MAEMO_5)
232 doGrabVolumeKeys(grabbingVolumeKeys);
233 #endif // Q_WS_MAEMO_5
237 void AdopterWindow::resizeEvent(QResizeEvent *event)
239 Trace t("AdopterWindow::resizeEvent");
243 qDebug() << "Show tool bar";
244 toolBar->setVisible(true);
246 qDebug() << "Hide tool bar";
247 toolBar->setVisible(false);
250 #endif // Q_OS_SYMBIAN
252 QMainWindow::resizeEvent(event);
256 void AdopterWindow::keyPressEvent(QKeyEvent *event)
259 if (bookView && grabbingVolumeKeys) {
260 switch (event->key()) {
264 bookView->goNextPage();
269 bookView->goPreviousPage();
272 #endif // Q_WS_MAEMO_5
274 bookView->goPreviousPage();
277 case Qt::Key_PageDown:
278 bookView->goNextPage();
285 QMainWindow::keyPressEvent(event);
288 void AdopterWindow::onSettingsChanged(const QString &key)
290 if (key == "usevolumekeys") {
291 bool grab = Settings::instance()->value(key, false).toBool();
292 qDebug() << "AdopterWindow::onSettingsChanged: usevolumekeys" << grab;
293 grabVolumeKeys(grab);
297 bool AdopterWindow::portrait()
299 QRect geometry = QApplication::desktop()->geometry();
300 return geometry.width() < geometry.height();
303 void AdopterWindow::placeDecorations()
305 Trace t("AdopterWindow::placeDecorations");
307 if (!hasBookView()) {
311 int toolBarHeight = 0;
313 QRect geo = bookView->geometry();
314 qDebug() << "bookView:" << geo;
317 // Work around Symbian bug: If tool bar is hidden, increase bottom
318 // decorator widgets' Y coordinates by the tool bar's height
319 if (!portrait() && toolBar) {
320 toolBarHeight = toolBar->height();
323 // Work around another Symbian bug: When returning from full screen mode
324 // in landscape, the book view widget's height is miscalculated.
325 // My apologies for this kludge
326 if (geo.height() == 288) {
327 qDebug() << "Adjusting bottom Y";
328 toolBarHeight -= 288 - 223;
330 #endif // Q_OS_SYMBIAN
332 progress->setGeometry(geo.x(),
333 geo.y() + geo.height() - progress->thickness() + toolBarHeight,
334 geo.width(), progress->thickness());
335 previousButton->setGeometry(geo.x(),
336 geo.y() + geo.height() - TranslucentButton::pixels + toolBarHeight,
337 TranslucentButton::pixels, TranslucentButton::pixels);
338 nextButton->setGeometry(
339 geo.x() + geo.width() - TranslucentButton::pixels,
340 geo.y(), TranslucentButton::pixels, TranslucentButton::pixels);
342 previousButton->flash();
344 qDebug() << "progress:" << progress->geometry();