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)
23 // Monitor settings changes
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)
46 bookView->setParent(this);
47 centralWidget()->layout()->addWidget(bookView);
51 previousButton = previous;
53 progress->setParent(this);
54 previousButton->setParent(this);
55 nextButton->setParent(this);
57 // Handle page and/or volume keys
58 connect(this, SIGNAL(pageUp()), this, SLOT(onPageUp()),
59 Qt::QueuedConnection);
60 connect(this, SIGNAL(pageDown()), this, SLOT(onPageDown()),
61 Qt::QueuedConnection);
64 void AdopterWindow::leaveBookView()
73 centralWidget()->layout()->removeWidget(bookView);
78 disconnect(this, SLOT(onPageUp()));
79 disconnect(this, SLOT(onPageDown()));
82 bool AdopterWindow::hasBookView()
87 void AdopterWindow::grabVolumeKeys(bool grab)
90 grabbingVolumeKeys = grab;
92 doGrabVolumeKeys(grab);
98 void AdopterWindow::doGrabVolumeKeys(bool grab)
102 qDebug() << "Not visible - skipping";
106 qDebug() << "Could not get window ID - skipping";
109 unsigned long val = grab? 1: 0;
111 XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
113 qCritical() << "Unable to obtain _HILDON_ZOOM_KEY_ATOM";
116 XChangeProperty(QX11Info::display(),
122 reinterpret_cast<unsigned char *>(&val),
124 qDebug() << "Grabbed volume keys";
127 #endif // Q_WS_MAEMO_5
129 void AdopterWindow::showEvent(QShowEvent *event)
131 Trace t("AdopterWindow::showEvent");
133 MainBase::showEvent(event);
134 #if defined(Q_WS_MAEMO_5)
135 doGrabVolumeKeys(grabbingVolumeKeys);
140 void AdopterWindow::resizeEvent(QResizeEvent *event)
142 Trace t("AdopterWindow::resizeEvent");
144 MainBase::resizeEvent(event);
146 #if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
147 // Restore previous reading position
149 bookView->scheduleRestoreLastBookmark();
151 #endif // defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
154 void AdopterWindow::closeEvent(QCloseEvent *event)
156 Trace t("AdopterWindow::closeEvent");
158 bookView->setLastBookmark();
161 MainBase::closeEvent(event);
164 void AdopterWindow::leaveEvent(QEvent *event)
166 Trace t("AdopterWindow::leaveEvent");
168 bookView->setLastBookmark();
170 MainBase::leaveEvent(event);
173 void AdopterWindow::keyPressEvent(QKeyEvent *event)
175 Trace t("AdopterWindow::keyPressEvent");
177 switch (event->key()) {
178 case Qt::Key_PageDown:
195 MainBase::keyPressEvent(event);
198 void AdopterWindow::onSettingsChanged(const QString &key)
200 if (key == "usevolumekeys") {
201 bool grab = Settings::instance()->value(key, false).toBool();
202 qDebug() << "AdopterWindow::onSettingsChanged: usevolumekeys" << grab;
203 grabVolumeKeys(grab);
207 void AdopterWindow::placeDecorations()
209 Trace t("AdopterWindow::placeDecorations");
211 if (!hasBookView()) {
212 qDebug() << "Doesn't have the book view";
216 qDebug() << "Has the book view";
219 #if defined(Q_WS_X11) && !defined(Q_WS_MAEMO_5)
220 extraHeight += toolBarHeight();
223 QRect geo = bookView->geometry();
224 qDebug() << "bookView:" << geo;
226 progress->setGeometry(geo.x(),
227 geo.y() + geo.height() - progress->thickness() + extraHeight,
228 geo.width(), progress->thickness());
229 previousButton->setGeometry(geo.x(),
230 geo.y() + geo.height() - TranslucentButton::pixels + extraHeight,
231 TranslucentButton::pixels, TranslucentButton::pixels);
232 nextButton->setGeometry(
233 geo.x() + geo.width() - TranslucentButton::pixels,
234 geo.y() + extraHeight, TranslucentButton::pixels,
235 TranslucentButton::pixels);
237 previousButton->flash();
239 qDebug() << "progress:" << progress->geometry();
242 void AdopterWindow::onPageUp()
244 if (bookView && grabbingVolumeKeys) {
246 bookView->goPreviousPage();
251 void AdopterWindow::onPageDown()
253 if (bookView && grabbingVolumeKeys) {
255 bookView->goNextPage();