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)
176 switch (event->key()) {
177 case Qt::Key_PageDown:
194 MainBase::keyPressEvent(event);
197 void AdopterWindow::onSettingsChanged(const QString &key)
199 if (key == "usevolumekeys") {
200 bool grab = Settings::instance()->value(key, false).toBool();
201 qDebug() << "AdopterWindow::onSettingsChanged: usevolumekeys" << grab;
202 grabVolumeKeys(grab);
206 void AdopterWindow::placeDecorations()
208 Trace t("AdopterWindow::placeDecorations");
210 if (!hasBookView()) {
211 qDebug() << "Doesn't have the book view";
215 qDebug() << "Has the book view";
218 QRect geo = bookView->geometry();
219 qDebug() << "bookView:" << geo;
221 progress->setGeometry(geo.x(),
222 geo.y() + geo.height() - progress->thickness() + extraHeight,
223 geo.width(), progress->thickness());
224 previousButton->setGeometry(geo.x(),
225 geo.y() + geo.height() - TranslucentButton::pixels + extraHeight,
226 TranslucentButton::pixels, TranslucentButton::pixels);
227 nextButton->setGeometry(geo.x() + geo.width() - TranslucentButton::pixels,
228 geo.y(), TranslucentButton::pixels, TranslucentButton::pixels);
230 previousButton->flash();
232 qDebug() << "progress:" << progress->geometry();
235 void AdopterWindow::onPageUp()
237 if (bookView && grabbingVolumeKeys) {
239 bookView->goPreviousPage();
244 void AdopterWindow::onPageDown()
246 if (bookView && grabbingVolumeKeys) {
248 bookView->goNextPage();