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);
48 centralWidget()->layout()->addWidget(bookView);
53 previousButton = previous;
55 progress->setParent(this);
56 previousButton->setParent(this);
57 nextButton->setParent(this);
59 // Handle page and/or volume keys
60 connect(this, SIGNAL(pageUp()), this, SLOT(onPageUp()),
61 Qt::QueuedConnection);
62 connect(this, SIGNAL(pageDown()), this, SLOT(onPageDown()),
63 Qt::QueuedConnection);
66 void AdopterWindow::leaveBookView()
76 centralWidget()->layout()->removeWidget(bookView);
82 disconnect(this, SLOT(onPageUp()));
83 disconnect(this, SLOT(onPageDown()));
86 bool AdopterWindow::hasBookView()
91 void AdopterWindow::grabVolumeKeys(bool grab)
94 grabbingVolumeKeys = grab;
96 doGrabVolumeKeys(grab);
102 void AdopterWindow::doGrabVolumeKeys(bool grab)
106 qDebug() << "Not visible - skipping";
110 qDebug() << "Could not get window ID - skipping";
113 unsigned long val = grab? 1: 0;
115 XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
117 qCritical() << "Unable to obtain _HILDON_ZOOM_KEY_ATOM";
120 XChangeProperty(QX11Info::display(),
126 reinterpret_cast<unsigned char *>(&val),
128 qDebug() << "Grabbed volume keys";
131 #endif // Q_WS_MAEMO_5
133 void AdopterWindow::showEvent(QShowEvent *event)
135 Trace t("AdopterWindow::showEvent");
137 MainBase::showEvent(event);
138 #if defined(Q_WS_MAEMO_5)
139 doGrabVolumeKeys(grabbingVolumeKeys);
144 void AdopterWindow::resizeEvent(QResizeEvent *event)
146 Trace t("AdopterWindow::resizeEvent");
148 MainBase::resizeEvent(event);
150 #if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
151 // Restore previous reading position
153 QTimer::singleShot(110, bookView, SLOT(restoreLastBookmark()));
155 #endif // defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
158 void AdopterWindow::closeEvent(QCloseEvent *event)
160 Trace t("AdopterWindow::closeEvent");
162 bookView->setLastBookmark();
164 MainBase::closeEvent(event);
167 void AdopterWindow::leaveEvent(QEvent *event)
169 Trace t("AdopterWindow::leaveEvent");
171 bookView->setLastBookmark();
173 MainBase::leaveEvent(event);
176 void AdopterWindow::keyPressEvent(QKeyEvent *event)
179 switch (event->key()) {
180 case Qt::Key_PageDown:
197 MainBase::keyPressEvent(event);
200 void AdopterWindow::onSettingsChanged(const QString &key)
202 if (key == "usevolumekeys") {
203 bool grab = Settings::instance()->value(key, false).toBool();
204 qDebug() << "AdopterWindow::onSettingsChanged: usevolumekeys" << grab;
205 grabVolumeKeys(grab);
209 void AdopterWindow::placeDecorations()
211 Trace t("AdopterWindow::placeDecorations");
213 if (!hasBookView()) {
214 qDebug() << "Doesn't have the book view";
218 qDebug() << "Has the book view";
221 QRect geo = bookView->geometry();
222 qDebug() << "bookView:" << geo;
224 progress->setGeometry(geo.x(),
225 geo.y() + geo.height() - progress->thickness() + extraHeight,
226 geo.width(), progress->thickness());
227 previousButton->setGeometry(geo.x(),
228 geo.y() + geo.height() - TranslucentButton::pixels + extraHeight,
229 TranslucentButton::pixels, TranslucentButton::pixels);
230 nextButton->setGeometry(geo.x() + geo.width() - TranslucentButton::pixels,
231 geo.y(), TranslucentButton::pixels, TranslucentButton::pixels);
233 previousButton->flash();
235 qDebug() << "progress:" << progress->geometry();
238 void AdopterWindow::onPageUp()
240 if (bookView && grabbingVolumeKeys) {
242 bookView->goPreviousPage();
247 void AdopterWindow::onPageDown()
249 if (bookView && grabbingVolumeKeys) {
251 bookView->goNextPage();