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 &)));
58 void AdopterWindow::takeBookView(BookView *view,
60 TranslucentButton *previous,
61 TranslucentButton *next)
73 bookView->setParent(this);
74 centralWidget()->layout()->addWidget(bookView);
78 previousButton = previous;
80 progress->setParent(this);
81 previousButton->setParent(this);
82 nextButton->setParent(this);
84 // Handle page and/or volume keys
85 connect(this, SIGNAL(pageUp()), this, SLOT(onPageUp()),
86 Qt::QueuedConnection);
87 connect(this, SIGNAL(pageDown()), this, SLOT(onPageDown()),
88 Qt::QueuedConnection);
91 void AdopterWindow::leaveBookView()
96 centralWidget()->layout()->removeWidget(bookView);
102 disconnect(this, SLOT(onPageUp()));
103 disconnect(this, SLOT(onPageDown()));
106 bool AdopterWindow::hasBookView()
108 return bookView != 0;
111 void AdopterWindow::show()
113 Trace t("AdopterWindow::show");
115 foreach (QWidget *w, QApplication::allWidgets()) {
116 w->setContextMenuPolicy(Qt::NoContextMenu);
124 QAction *AdopterWindow::addToolBarAction(QObject *receiver,
126 const QString &iconName,
131 qDebug() << "icon" << iconName << "text" << text;
135 action = toolBar->addAction(QIcon(Platform::instance()->icon(iconName)),
136 text, receiver, member);
138 if (!toolBar && important) {
139 // Create tool bar if needed
140 toolBar = new QToolBar("", this);
141 // toolBar->setFixedHeight(63);
142 toolBar->setStyleSheet("margin:0; border:0; padding:0");
143 toolBar->setSizePolicy(QSizePolicy::MinimumExpanding,
144 QSizePolicy::Maximum);
145 addToolBar(Qt::BottomToolBarArea, toolBar);
148 // Add tool bar action
149 QPushButton *button = new QPushButton(this);
150 button->setIconSize(QSize(60, 60));
151 button->setFixedSize(89, 60);
152 button->setIcon(QIcon(Platform::instance()->icon(iconName)));
153 button->setSizePolicy(QSizePolicy::MinimumExpanding,
154 QSizePolicy::Maximum);
155 connect(button, SIGNAL(clicked()), receiver, member);
156 toolBar->addWidget(button);
158 // Add menu action, too
159 action = new QAction(text, this);
160 menuBar()->addAction(action);
161 connect(action, SIGNAL(triggered()), receiver, member);
164 #if defined Q_WS_MAEMO_5
166 action->setToolTip("");
172 void AdopterWindow::addToolBarSpace()
175 QFrame *frame = new QFrame(toolBar);
176 frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
177 toolBar->addWidget(frame);
181 void AdopterWindow::grabVolumeKeys(bool grab)
184 grabbingVolumeKeys = grab;
186 doGrabVolumeKeys(grab);
192 void AdopterWindow::doGrabVolumeKeys(bool grab)
196 qDebug() << "Not visible - skipping";
200 qDebug() << "Could not get window ID - skipping";
203 unsigned long val = grab? 1: 0;
205 XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
207 qCritical() << "Unable to obtain _HILDON_ZOOM_KEY_ATOM";
210 XChangeProperty(QX11Info::display(),
216 reinterpret_cast<unsigned char *>(&val),
218 qDebug() << "Grabbed volume keys";
221 #endif // Q_WS_MAEMO_5
225 void AdopterWindow::updateToolBar()
229 QRect geometry = QApplication::desktop()->geometry();
230 bool isPortrait = geometry.width() < geometry.height();
231 bool isToolBarHidden = toolBar->isHidden();
232 if (isPortrait && isToolBarHidden) {
233 qDebug() << "Show tool bar";
234 toolBar->setVisible(true);
235 } else if (!isPortrait && !isToolBarHidden) {
236 qDebug() << "Hide tool bar";
237 toolBar->setVisible(false);
242 bool AdopterWindow::portrait()
244 QRect geometry = QApplication::desktop()->geometry();
245 return geometry.width() < geometry.height();
248 #endif // Q_OS_SYMBIAN
250 void AdopterWindow::showEvent(QShowEvent *e)
252 Trace t("AdopterWindow::showEvent");
257 QMainWindow::showEvent(e);
258 #if defined(Q_WS_MAEMO_5)
259 doGrabVolumeKeys(grabbingVolumeKeys);
264 void AdopterWindow::resizeEvent(QResizeEvent *event)
266 Trace t("AdopterWindow::resizeEvent");
270 QMainWindow::resizeEvent(event);
273 QTimer::singleShot(110, bookView, SLOT(restoreLastBookmark()));
277 void AdopterWindow::closeEvent(QCloseEvent *event)
279 Trace t("AdopterWindow::closeEvent");
281 bookView->setLastBookmark();
283 QMainWindow::closeEvent(event);
286 void AdopterWindow::leaveEvent(QEvent *event)
288 Trace t("AdopterWindow::leaveEvent");
290 bookView->setLastBookmark();
292 QMainWindow::leaveEvent(event);
295 void AdopterWindow::keyPressEvent(QKeyEvent *event)
298 switch (event->key()) {
299 case Qt::Key_PageDown:
316 QMainWindow::keyPressEvent(event);
319 void AdopterWindow::onSettingsChanged(const QString &key)
321 if (key == "usevolumekeys") {
322 bool grab = Settings::instance()->value(key, false).toBool();
323 qDebug() << "AdopterWindow::onSettingsChanged: usevolumekeys" << grab;
324 grabVolumeKeys(grab);
328 void AdopterWindow::placeDecorations()
330 Trace t("AdopterWindow::placeDecorations");
332 if (!hasBookView()) {
336 int toolBarHeight = 0;
338 QRect geo = bookView->geometry();
339 qDebug() << "bookView:" << geo;
342 // Work around Symbian bug: If tool bar is hidden, increase bottom
343 // decorator widgets' Y coordinates by the tool bar's height
344 if (toolBar && toolBar->isHidden()) {
345 toolBarHeight = toolBar->height();
348 // Work around another Symbian bug: When returning from full screen mode
349 // in landscape, the book view widget's height is miscalculated.
350 // My apologies for this kludge
351 if (geo.height() == 288) {
352 qDebug() << "Adjusting bottom Y";
353 toolBarHeight -= 288 - 223;
355 #endif // Q_OS_SYMBIAN
357 progress->setGeometry(geo.x(),
358 geo.y() + geo.height() - progress->thickness() + toolBarHeight,
359 geo.width(), progress->thickness());
360 previousButton->setGeometry(geo.x(),
361 geo.y() + geo.height() - TranslucentButton::pixels + toolBarHeight,
362 TranslucentButton::pixels, TranslucentButton::pixels);
363 nextButton->setGeometry(
364 geo.x() + geo.width() - TranslucentButton::pixels,
365 geo.y(), TranslucentButton::pixels, TranslucentButton::pixels);
367 previousButton->flash();
369 qDebug() << "progress:" << progress->geometry();
372 void AdopterWindow::onPageUp()
374 if (bookView && grabbingVolumeKeys) {
376 bookView->goPreviousPage();
381 void AdopterWindow::onPageDown()
383 if (bookView && grabbingVolumeKeys) {
385 bookView->goNextPage();
390 void AdopterWindow::hideToolBar()