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);
74 centralWidget()->layout()->addWidget(bookView);
77 previousButton = previous;
79 progress->setParent(this);
80 previousButton->setParent(this);
81 nextButton->setParent(this);
84 void AdopterWindow::leaveBookView()
88 centralWidget()->layout()->removeWidget(bookView);
96 bool AdopterWindow::hasBookView()
101 void AdopterWindow::show()
104 foreach (QWidget *w, QApplication::allWidgets()) {
105 w->setContextMenuPolicy(Qt::NoContextMenu);
114 QAction *AdopterWindow::addToolBarAction(QObject *receiver,
116 const QString &iconName,
121 qDebug() << "icon" << iconName << "text" << text;
125 action = toolBar->addAction(QIcon(Platform::instance()->icon(iconName)),
126 text, receiver, member);
128 if (!toolBar && important) {
129 // Create tool bar if needed
130 toolBar = new QToolBar("", this);
131 // toolBar->setFixedWidth(QApplication::desktop()->
132 // availableGeometry().width());
133 toolBar->setFixedHeight(65);
134 toolBar->setStyleSheet("margin:0; border:0; padding:0");
135 toolBar->setSizePolicy(QSizePolicy::MinimumExpanding,
136 QSizePolicy::Maximum);
137 addToolBar(Qt::BottomToolBarArea, toolBar);
140 // Add tool bar action
141 QPushButton *button = new QPushButton(this);
142 button->setIconSize(QSize(60, 60));
143 button->setFixedSize(89, 60);
144 button->setIcon(QIcon(Platform::instance()->icon(iconName)));
145 button->setSizePolicy(QSizePolicy::MinimumExpanding,
146 QSizePolicy::Maximum);
147 connect(button, SIGNAL(clicked()), receiver, member);
148 toolBar->addWidget(button);
150 // Add menu action, too
151 action = new QAction(text, this);
152 menuBar()->addAction(action);
153 connect(action, SIGNAL(triggered()), receiver, member);
156 #if defined Q_WS_MAEMO_5
158 action->setToolTip("");
164 void AdopterWindow::addToolBarSpace()
167 QFrame *frame = new QFrame(toolBar);
168 frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
169 toolBar->addWidget(frame);
173 void AdopterWindow::grabVolumeKeys(bool grab)
176 grabbingVolumeKeys = grab;
178 doGrabVolumeKeys(grab);
184 void AdopterWindow::doGrabVolumeKeys(bool grab)
188 qDebug() << "Not visible - skipping";
192 qDebug() << "Could not get window ID - skipping";
195 unsigned long val = grab? 1: 0;
196 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
198 qCritical() << "Unable to obtain _HILDON_ZOOM_KEY_ATOM";
201 XChangeProperty(QX11Info::display(),
207 reinterpret_cast<unsigned char *>(&val),
209 qDebug() << "Grabbed volume keys";
212 #endif // Q_WS_MAEMO_5
214 void AdopterWindow::showEvent(QShowEvent *e)
216 Trace t("AdopterWindow::showEvent");
218 #if defined(Q_WS_MAEMO_5)
219 doGrabVolumeKeys(grabbingVolumeKeys);
220 #endif // Q_WS_MAEMO_5
221 QMainWindow::showEvent(e);
224 void AdopterWindow::resizeEvent(QResizeEvent *event)
226 Trace t("AdopterWindow::resizeEvent");
231 qDebug() << "Show tool bar";
232 toolBar->setVisible(true);
234 qDebug() << "Hide tool bar";
235 toolBar->setVisible(false);
238 #endif // Q_OS_SYMBIAN
241 QTimer::singleShot(100, this, SLOT(placeDecorations()));
243 QMainWindow::resizeEvent(event);
246 void AdopterWindow::keyPressEvent(QKeyEvent *event)
249 if (bookView && grabbingVolumeKeys) {
250 switch (event->key()) {
254 bookView->goNextPage();
259 bookView->goPreviousPage();
262 #endif // Q_WS_MAEMO_5
264 bookView->goPreviousPage();
267 case Qt::Key_PageDown:
268 bookView->goNextPage();
275 QMainWindow::keyPressEvent(event);
278 void AdopterWindow::onSettingsChanged(const QString &key)
280 if (key == "usevolumekeys") {
281 bool grab = Settings::instance()->value(key, false).toBool();
282 qDebug() << "AdopterWindow::onSettingsChanged: usevolumekeys" << grab;
283 grabVolumeKeys(grab);
287 bool AdopterWindow::portrait()
289 QRect geometry = QApplication::desktop()->geometry();
290 return geometry.width() < geometry.height();
293 void AdopterWindow::placeDecorations()
295 Trace t("AdopterWindow::placeDecorations");
297 if (!hasBookView()) {
301 int toolBarHeight = 0;
303 QRect geo = bookView->geometry();
304 qDebug() << "bookView:" << geo;
307 // Work around Symbian bug: If tool bar is hidden, increase bottom
308 // decorator widgets' Y coordinates by the tool bar's height
309 if (!portrait() && toolBar) {
310 toolBarHeight = toolBar->height();
313 // Work around another Symbian bug: When returning from full screen mode
314 // in landscape, the book view widget's height is miscalculated.
315 // My apologies for this kludge
316 if (geo.height() == 288) {
317 qDebug() << "Adjusting bottom Y";
318 toolBarHeight -= 288 - 223;
320 #endif // Q_OS_SYMBIAN
322 progress->setGeometry(geo.x(),
323 geo.y() + geo.height() - progress->thickness() + toolBarHeight,
324 geo.width(), progress->thickness());
325 previousButton->setGeometry(geo.x(),
326 geo.y() + geo.height() - TranslucentButton::pixels + toolBarHeight,
327 TranslucentButton::pixels, TranslucentButton::pixels);
328 nextButton->setGeometry(
329 geo.x() + geo.width() - TranslucentButton::pixels,
330 geo.y(), TranslucentButton::pixels, TranslucentButton::pixels);
332 previousButton->flash();
334 qDebug() << "progress:" << progress->geometry();