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): MainBase(parent), bookView(0),
19 grabbingVolumeKeys(false), progress(0), previousButton(0), nextButton(0)
24 connect(Settings::instance(), SIGNAL(valueChanged(const QString &)),
25 this, SLOT(onSettingsChanged(const QString &)));
29 void AdopterWindow::takeBookView(BookView *view,
31 TranslucentButton *previous,
32 TranslucentButton *next)
44 bookView->setParent(this);
45 centralWidget()->layout()->addWidget(bookView);
49 previousButton = previous;
51 progress->setParent(this);
52 previousButton->setParent(this);
53 nextButton->setParent(this);
55 // Handle page and/or volume keys
56 connect(this, SIGNAL(pageUp()), this, SLOT(onPageUp()),
57 Qt::QueuedConnection);
58 connect(this, SIGNAL(pageDown()), this, SLOT(onPageDown()),
59 Qt::QueuedConnection);
62 void AdopterWindow::leaveBookView()
67 centralWidget()->layout()->removeWidget(bookView);
73 disconnect(this, SLOT(onPageUp()));
74 disconnect(this, SLOT(onPageDown()));
77 bool AdopterWindow::hasBookView()
82 void AdopterWindow::grabVolumeKeys(bool grab)
85 grabbingVolumeKeys = grab;
87 doGrabVolumeKeys(grab);
93 void AdopterWindow::doGrabVolumeKeys(bool grab)
97 qDebug() << "Not visible - skipping";
101 qDebug() << "Could not get window ID - skipping";
104 unsigned long val = grab? 1: 0;
106 XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
108 qCritical() << "Unable to obtain _HILDON_ZOOM_KEY_ATOM";
111 XChangeProperty(QX11Info::display(),
117 reinterpret_cast<unsigned char *>(&val),
119 qDebug() << "Grabbed volume keys";
122 #endif // Q_WS_MAEMO_5
124 void AdopterWindow::showEvent(QShowEvent *e)
126 Trace t("AdopterWindow::showEvent");
128 MainBase::showEvent(e);
129 #if defined(Q_WS_MAEMO_5)
130 doGrabVolumeKeys(grabbingVolumeKeys);
135 void AdopterWindow::resizeEvent(QResizeEvent *event)
137 Trace t("AdopterWindow::resizeEvent");
138 MainBase::resizeEvent(event);
140 #if defined(Q_WS_MAEMO_5)
142 QTimer::singleShot(110, bookView, SLOT(restoreLastBookmark()));
144 #elif defined(Q_OS_SYMBIAN)
146 QTimer::singleShot(110, bookView, SLOT(adjustPosition()));
151 void AdopterWindow::closeEvent(QCloseEvent *event)
153 Trace t("AdopterWindow::closeEvent");
155 bookView->setLastBookmark();
157 MainBase::closeEvent(event);
160 void AdopterWindow::leaveEvent(QEvent *event)
162 Trace t("AdopterWindow::leaveEvent");
164 bookView->setLastBookmark();
166 MainBase::leaveEvent(event);
169 void AdopterWindow::keyPressEvent(QKeyEvent *event)
172 switch (event->key()) {
173 case Qt::Key_PageDown:
190 MainBase::keyPressEvent(event);
193 void AdopterWindow::onSettingsChanged(const QString &key)
195 if (key == "usevolumekeys") {
196 bool grab = Settings::instance()->value(key, false).toBool();
197 qDebug() << "AdopterWindow::onSettingsChanged: usevolumekeys" << grab;
198 grabVolumeKeys(grab);
202 void AdopterWindow::placeDecorations()
204 Trace t("AdopterWindow::placeDecorations");
206 if (!hasBookView()) {
212 QRect geo = bookView->geometry();
213 qDebug() << "bookView:" << geo;
216 // Work around Symbian bug: If tool bar is hidden, increase bottom
217 // decorator widgets' Y coordinates by the tool bar's height
218 if (isToolBarHidden()) {
219 extraHeight = toolBarHeight();
222 // Work around another Symbian bug: When returning from full screen mode
223 // in landscape, the book view widget's height is miscalculated.
224 // My apologies for this kludge
225 if (geo.height() == 288) {
226 qDebug() << "Adjusting bottom Y";
227 extraHeight -= 288 - 223;
229 #endif // Q_OS_SYMBIAN
231 progress->setGeometry(geo.x(),
232 geo.y() + geo.height() - progress->thickness() + extraHeight,
233 geo.width(), progress->thickness());
234 previousButton->setGeometry(geo.x(),
235 geo.y() + geo.height() - TranslucentButton::pixels + extraHeight,
236 TranslucentButton::pixels, TranslucentButton::pixels);
237 nextButton->setGeometry(geo.x() + geo.width() - TranslucentButton::pixels,
238 geo.y(), TranslucentButton::pixels, TranslucentButton::pixels);
240 previousButton->flash();
242 qDebug() << "progress:" << progress->geometry();
245 void AdopterWindow::onPageUp()
247 if (bookView && grabbingVolumeKeys) {
249 bookView->goPreviousPage();
254 void AdopterWindow::onPageDown()
256 if (bookView && grabbingVolumeKeys) {
258 bookView->goNextPage();