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);
141 #if defined(Q_WS_MAEMO_5)
142 // Restore previous reading position
146 QTimer::singleShot(110, bookView, SLOT(restoreLastBookmark()));
147 #endif // Q_WS_MAEMO_5
149 #if defined(Q_OS_SYMBIAN)
150 // Adjust reading position after orientation change
154 if (event->oldSize().width() == -1) {
157 bool oldPortrait = event->oldSize().width() < event->oldSize().height();
158 bool portrait = event->size().width() < event->size().height();
159 if (oldPortrait == portrait) {
162 QTimer::singleShot(990, bookView, SLOT(adjustPosition()));
163 #endif // Q_OS_SYMBIAN
166 void AdopterWindow::closeEvent(QCloseEvent *event)
168 Trace t("AdopterWindow::closeEvent");
170 bookView->setLastBookmark();
172 MainBase::closeEvent(event);
175 void AdopterWindow::leaveEvent(QEvent *event)
177 Trace t("AdopterWindow::leaveEvent");
179 bookView->setLastBookmark();
181 MainBase::leaveEvent(event);
184 void AdopterWindow::keyPressEvent(QKeyEvent *event)
187 switch (event->key()) {
188 case Qt::Key_PageDown:
205 MainBase::keyPressEvent(event);
208 void AdopterWindow::onSettingsChanged(const QString &key)
210 if (key == "usevolumekeys") {
211 bool grab = Settings::instance()->value(key, false).toBool();
212 qDebug() << "AdopterWindow::onSettingsChanged: usevolumekeys" << grab;
213 grabVolumeKeys(grab);
217 void AdopterWindow::placeDecorations()
219 Trace t("AdopterWindow::placeDecorations");
221 if (!hasBookView()) {
227 QRect geo = bookView->geometry();
228 qDebug() << "bookView:" << geo;
231 // Work around Symbian bug: If tool bar is hidden, increase bottom
232 // decorator widgets' Y coordinates by the tool bar's height
233 if (isToolBarHidden()) {
234 extraHeight = toolBarHeight();
237 // Work around another Symbian bug: When returning from full screen mode
238 // in landscape, the book view widget's height is miscalculated.
239 // My apologies for this kludge
240 if (geo.height() == 288) {
241 qDebug() << "Adjusting bottom Y";
242 extraHeight -= 288 - 223;
244 #endif // Q_OS_SYMBIAN
246 progress->setGeometry(geo.x(),
247 geo.y() + geo.height() - progress->thickness() + extraHeight,
248 geo.width(), progress->thickness());
249 previousButton->setGeometry(geo.x(),
250 geo.y() + geo.height() - TranslucentButton::pixels + extraHeight,
251 TranslucentButton::pixels, TranslucentButton::pixels);
252 nextButton->setGeometry(geo.x() + geo.width() - TranslucentButton::pixels,
253 geo.y(), TranslucentButton::pixels, TranslucentButton::pixels);
255 previousButton->flash();
257 qDebug() << "progress:" << progress->geometry();
260 void AdopterWindow::onPageUp()
262 if (bookView && grabbingVolumeKeys) {
264 bookView->goPreviousPage();
269 void AdopterWindow::onPageDown()
271 if (bookView && grabbingVolumeKeys) {
273 bookView->goNextPage();