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");
219 QMainWindow::showEvent(e);
220 #if defined(Q_WS_MAEMO_5)
221 doGrabVolumeKeys(grabbingVolumeKeys);
222 #endif // Q_WS_MAEMO_5
226 void AdopterWindow::resizeEvent(QResizeEvent *event)
228 Trace t("AdopterWindow::resizeEvent");
229 QMainWindow::resizeEvent(event);
233 void AdopterWindow::keyPressEvent(QKeyEvent *event)
236 if (bookView && grabbingVolumeKeys) {
237 switch (event->key()) {
241 bookView->goNextPage();
246 bookView->goPreviousPage();
249 #endif // Q_WS_MAEMO_5
251 bookView->goPreviousPage();
254 case Qt::Key_PageDown:
255 bookView->goNextPage();
262 QMainWindow::keyPressEvent(event);
265 void AdopterWindow::onSettingsChanged(const QString &key)
267 if (key == "usevolumekeys") {
268 bool grab = Settings::instance()->value(key, false).toBool();
269 qDebug() << "AdopterWindow::onSettingsChanged: usevolumekeys" << grab;
270 grabVolumeKeys(grab);
274 bool AdopterWindow::portrait()
276 QRect geometry = QApplication::desktop()->geometry();
277 return geometry.width() < geometry.height();
280 void AdopterWindow::placeDecorations()
282 Trace t("AdopterWindow::placeDecorations");
287 qDebug() << "Show tool bar";
288 toolBar->setVisible(true);
290 qDebug() << "Hide tool bar";
291 toolBar->setVisible(false);
294 #endif // Q_OS_SYMBIAN
296 if (!hasBookView()) {
300 int toolBarHeight = 0;
302 QRect geo = bookView->geometry();
303 qDebug() << "bookView:" << geo;
306 // Work around Symbian bug: If tool bar is hidden, increase bottom
307 // decorator widgets' Y coordinates by the tool bar's height
308 if (!portrait() && toolBar) {
309 toolBarHeight = toolBar->height();
312 // Work around another Symbian bug: When returning from full screen mode
313 // in landscape, the book view widget's height is miscalculated.
314 // My apologies for this kludge
315 if (geo.height() == 288) {
316 qDebug() << "Adjusting bottom Y";
317 toolBarHeight -= 288 - 223;
319 #endif // Q_OS_SYMBIAN
321 progress->setGeometry(geo.x(),
322 geo.y() + geo.height() - progress->thickness() + toolBarHeight,
323 geo.width(), progress->thickness());
324 previousButton->setGeometry(geo.x(),
325 geo.y() + geo.height() - TranslucentButton::pixels + toolBarHeight,
326 TranslucentButton::pixels, TranslucentButton::pixels);
327 nextButton->setGeometry(
328 geo.x() + geo.width() - TranslucentButton::pixels,
329 geo.y(), TranslucentButton::pixels, TranslucentButton::pixels);
331 previousButton->flash();
333 qDebug() << "progress:" << progress->geometry();