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):
19 QMainWindow(parent), bookView(0), grabbingVolumeKeys(false), toolBar(0),
20 progress(0), previousButton(0), nextButton(0)
25 setAttribute(Qt::WA_Maemo5StackedWindow, true);
28 QFrame *frame = new QFrame(this);
29 QVBoxLayout *layout = new QVBoxLayout(frame);
31 frame->setLayout(layout);
33 setCentralWidget(frame);
36 QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this);
37 closeAction->setSoftKeyRole(QAction::NegativeSoftKey);
38 connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
39 QMainWindow::addAction(closeAction);
42 setUnifiedTitleAndToolBarOnMac(true);
43 toolBar = addToolBar("");
44 toolBar->setMovable(false);
45 toolBar->setFloatable(false);
46 toolBar->toggleViewAction()->setVisible(false);
47 #if defined(Q_WS_X11) && !defined(Q_WS_MAEMO_5)
48 toolBar->setIconSize(QSize(42, 42));
50 #endif // Q_OS_SYMBIAN
53 connect(Settings::instance(), SIGNAL(valueChanged(const QString &)),
54 this, SLOT(onSettingsChanged(const QString &)));
57 void AdopterWindow::takeBookView(BookView *view,
59 TranslucentButton *previous,
60 TranslucentButton *next)
72 bookView->setParent(this);
73 centralWidget()->layout()->addWidget(bookView);
77 previousButton = previous;
79 progress->setParent(this);
80 previousButton->setParent(this);
81 nextButton->setParent(this);
84 void AdopterWindow::leaveBookView()
89 centralWidget()->layout()->removeWidget(bookView);
97 bool AdopterWindow::hasBookView()
102 void AdopterWindow::show()
104 Trace t("AdopterWindow::show");
106 foreach (QWidget *w, QApplication::allWidgets()) {
107 w->setContextMenuPolicy(Qt::NoContextMenu);
115 QAction *AdopterWindow::addToolBarAction(QObject *receiver,
117 const QString &iconName,
122 qDebug() << "icon" << iconName << "text" << text;
126 action = toolBar->addAction(QIcon(Platform::instance()->icon(iconName)),
127 text, receiver, member);
129 if (!toolBar && important) {
130 // Create tool bar if needed
131 toolBar = new QToolBar("", this);
132 // toolBar->setFixedHeight(63);
133 toolBar->setStyleSheet("margin:0; border:0; padding:0");
134 toolBar->setSizePolicy(QSizePolicy::MinimumExpanding,
135 QSizePolicy::Maximum);
136 addToolBar(Qt::BottomToolBarArea, toolBar);
139 // Add tool bar action
140 QPushButton *button = new QPushButton(this);
141 button->setIconSize(QSize(60, 60));
142 button->setFixedSize(89, 60);
143 button->setIcon(QIcon(Platform::instance()->icon(iconName)));
144 button->setSizePolicy(QSizePolicy::MinimumExpanding,
145 QSizePolicy::Maximum);
146 connect(button, SIGNAL(clicked()), receiver, member);
147 toolBar->addWidget(button);
149 // Add menu action, too
150 action = new QAction(text, this);
151 menuBar()->addAction(action);
152 connect(action, SIGNAL(triggered()), receiver, member);
155 #if defined Q_WS_MAEMO_5
157 action->setToolTip("");
163 void AdopterWindow::addToolBarSpace()
166 QFrame *frame = new QFrame(toolBar);
167 frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
168 toolBar->addWidget(frame);
172 void AdopterWindow::grabVolumeKeys(bool grab)
175 grabbingVolumeKeys = grab;
177 doGrabVolumeKeys(grab);
183 void AdopterWindow::doGrabVolumeKeys(bool grab)
187 qDebug() << "Not visible - skipping";
191 qDebug() << "Could not get window ID - skipping";
194 unsigned long val = grab? 1: 0;
196 XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
198 qCritical() << "Unable to obtain _HILDON_ZOOM_KEY_ATOM";
201 XChangeProperty(QX11Info::display(),
207 reinterpret_cast<unsigned char *>(&val),
209 qDebug() << "Grabbed volume keys";
212 #endif // Q_WS_MAEMO_5
216 void AdopterWindow::updateToolBar()
220 QRect geometry = QApplication::desktop()->geometry();
221 bool isPortrait = geometry.width() < geometry.height();
222 bool isToolBarHidden = toolBar->isHidden();
223 if (isPortrait && isToolBarHidden) {
224 qDebug() << "Show tool bar";
225 toolBar->setVisible(true);
226 } else if (!isPortrait && !isToolBarHidden) {
227 qDebug() << "Hide tool bar";
228 toolBar->setVisible(false);
233 bool AdopterWindow::portrait()
235 QRect geometry = QApplication::desktop()->geometry();
236 return geometry.width() < geometry.height();
239 #endif // Q_OS_SYMBIAN
241 void AdopterWindow::showEvent(QShowEvent *e)
243 Trace t("AdopterWindow::showEvent");
248 QMainWindow::showEvent(e);
249 #if defined(Q_WS_MAEMO_5)
250 doGrabVolumeKeys(grabbingVolumeKeys);
255 void AdopterWindow::resizeEvent(QResizeEvent *event)
257 Trace t("AdopterWindow::resizeEvent");
261 QMainWindow::resizeEvent(event);
265 void AdopterWindow::keyPressEvent(QKeyEvent *event)
268 if (bookView && grabbingVolumeKeys) {
269 switch (event->key()) {
273 bookView->goNextPage();
278 bookView->goPreviousPage();
281 #endif // Q_WS_MAEMO_5
283 bookView->goPreviousPage();
286 case Qt::Key_PageDown:
287 bookView->goNextPage();
294 QMainWindow::keyPressEvent(event);
297 void AdopterWindow::onSettingsChanged(const QString &key)
299 if (key == "usevolumekeys") {
300 bool grab = Settings::instance()->value(key, false).toBool();
301 qDebug() << "AdopterWindow::onSettingsChanged: usevolumekeys" << grab;
302 grabVolumeKeys(grab);
306 void AdopterWindow::placeDecorations()
308 Trace t("AdopterWindow::placeDecorations");
310 if (!hasBookView()) {
314 int toolBarHeight = 0;
316 QRect geo = bookView->geometry();
317 qDebug() << "bookView:" << geo;
320 // Work around Symbian bug: If tool bar is hidden, increase bottom
321 // decorator widgets' Y coordinates by the tool bar's height
322 if (toolBar && toolBar->isHidden()) {
323 toolBarHeight = toolBar->height();
326 // Work around another Symbian bug: When returning from full screen mode
327 // in landscape, the book view widget's height is miscalculated.
328 // My apologies for this kludge
329 if (geo.height() == 288) {
330 qDebug() << "Adjusting bottom Y";
331 toolBarHeight -= 288 - 223;
333 #endif // Q_OS_SYMBIAN
335 progress->setGeometry(geo.x(),
336 geo.y() + geo.height() - progress->thickness() + toolBarHeight,
337 geo.width(), progress->thickness());
338 previousButton->setGeometry(geo.x(),
339 geo.y() + geo.height() - TranslucentButton::pixels + toolBarHeight,
340 TranslucentButton::pixels, TranslucentButton::pixels);
341 nextButton->setGeometry(
342 geo.x() + geo.width() - TranslucentButton::pixels,
343 geo.y(), TranslucentButton::pixels, TranslucentButton::pixels);
345 previousButton->flash();
347 qDebug() << "progress:" << progress->geometry();