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)
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 QTimer::singleShot(110, bookView, SLOT(restoreLastBookmark()));
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();
160 MainBase::closeEvent(event);
163 void AdopterWindow::leaveEvent(QEvent *event)
165 Trace t("AdopterWindow::leaveEvent");
167 bookView->setLastBookmark();
169 MainBase::leaveEvent(event);
172 void AdopterWindow::keyPressEvent(QKeyEvent *event)
175 switch (event->key()) {
176 case Qt::Key_PageDown:
193 MainBase::keyPressEvent(event);
196 void AdopterWindow::onSettingsChanged(const QString &key)
198 if (key == "usevolumekeys") {
199 bool grab = Settings::instance()->value(key, false).toBool();
200 qDebug() << "AdopterWindow::onSettingsChanged: usevolumekeys" << grab;
201 grabVolumeKeys(grab);
205 void AdopterWindow::placeDecorations()
207 Trace t("AdopterWindow::placeDecorations");
209 if (!hasBookView()) {
210 qDebug() << "Doesn't have the book view";
214 qDebug() << "Has the book view";
217 QRect geo = bookView->geometry();
218 qDebug() << "bookView:" << geo;
220 progress->setGeometry(geo.x(),
221 geo.y() + geo.height() - progress->thickness() + extraHeight,
222 geo.width(), progress->thickness());
223 previousButton->setGeometry(geo.x(),
224 geo.y() + geo.height() - TranslucentButton::pixels + extraHeight,
225 TranslucentButton::pixels, TranslucentButton::pixels);
226 nextButton->setGeometry(geo.x() + geo.width() - TranslucentButton::pixels,
227 geo.y(), TranslucentButton::pixels, TranslucentButton::pixels);
229 previousButton->flash();
231 qDebug() << "progress:" << progress->geometry();
234 void AdopterWindow::onPageUp()
236 if (bookView && grabbingVolumeKeys) {
238 bookView->goPreviousPage();
243 void AdopterWindow::onPageDown()
245 if (bookView && grabbingVolumeKeys) {
247 bookView->goNextPage();