3 #if defined(Q_WS_MAEMO_5)
4 # include <QtGui/QX11Info>
6 # include <X11/Xatom.h>
7 # include <QAbstractKineticScroller>
10 #include "adopterwindow.h"
16 AdopterWindow::AdopterWindow(QWidget *parent):
17 QMainWindow(parent), bookView(0), grabbingVolumeKeys(false)
22 setAttribute(Qt::WA_Maemo5StackedWindow, true);
23 #endif // Q_WS_MAEMO_5
25 QFrame *frame = new QFrame(this);
26 QVBoxLayout *layout = new QVBoxLayout(frame);
28 frame->setLayout(layout);
29 setCentralWidget(frame);
32 QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this);
33 closeAction->setSoftKeyRole(QAction::NegativeSoftKey);
34 connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
35 QMainWindow::addAction(closeAction);
38 setUnifiedTitleAndToolBarOnMac(true);
39 toolBar = addToolBar("controls");
40 toolBar->setMovable(false);
41 toolBar->setFloatable(false);
42 toolBar->toggleViewAction()->setVisible(false);
43 #if defined(Q_WS_X11) && !defined(Q_WS_MAEMO_5)
44 toolBar->setIconSize(QSize(42, 42));
46 #endif // Q_OS_SYMBIAN
49 connect(Settings::instance(), SIGNAL(valueChanged(const QString &)),
50 this, SLOT(onSettingsChanged(const QString &)));
53 void AdopterWindow::takeChildren(BookView *view, const QList<QWidget *> &others)
59 bookView->setParent(centralWidget());
60 centralWidget()->layout()->addWidget(bookView);
63 foreach (QWidget *child, others) {
65 child->setParent(this);
70 void AdopterWindow::leaveChildren()
74 centralWidget()->layout()->removeWidget(bookView);
79 bool AdopterWindow::hasChild(QWidget *child)
81 if (child == bookView) {
84 return this == child->parent();
87 void AdopterWindow::show()
90 foreach (QWidget *w, QApplication::allWidgets()) {
91 w->setContextMenuPolicy(Qt::NoContextMenu);
100 QAction *AdopterWindow::addToolBarAction(QObject *receiver,
102 const QString &iconName,
106 qDebug() << "icon" << iconName << "text" << text;
109 action = toolBar->addAction(QIcon(Platform::instance()->icon(iconName)),
110 text, receiver, member);
113 action = new QAction(text, this);
114 menuBar()->addAction(action);
115 connect(action, SIGNAL(triggered()), receiver, member);
118 #if defined Q_WS_MAEMO_5
120 action->setToolTip("");
125 void AdopterWindow::addToolBarSpace()
128 QFrame *frame = new QFrame(toolBar);
129 frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
130 toolBar->addWidget(frame);
134 void AdopterWindow::grabVolumeKeys(bool grab)
137 grabbingVolumeKeys = grab;
139 doGrabVolumeKeys(grab);
145 void AdopterWindow::doGrabVolumeKeys(bool grab)
149 qDebug() << "Not visible - skipping";
153 qDebug() << "Could not get window ID - skipping";
156 unsigned long val = grab? 1: 0;
157 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
159 qCritical() << "Unable to obtain _HILDON_ZOOM_KEY_ATOM";
162 XChangeProperty(QX11Info::display(),
168 reinterpret_cast<unsigned char *>(&val),
170 qDebug() << "Grabbed volume keys";
173 #endif // Q_WS_MAEMO_5
177 void AdopterWindow::showEvent(QShowEvent *e)
180 doGrabVolumeKeys(grabbingVolumeKeys);
181 QMainWindow::showEvent(e);
184 #endif // Q_WS_MAEMO_5
186 void AdopterWindow::keyPressEvent(QKeyEvent *event)
189 if (bookView && grabbingVolumeKeys) {
190 switch (event->key()) {
194 bookView->goNextPage();
199 bookView->goPreviousPage();
202 #endif // Q_WS_MAEMO_5
204 bookView->goPreviousPage();
207 case Qt::Key_PageDown:
208 bookView->goNextPage();
215 QMainWindow::keyPressEvent(event);
218 void AdopterWindow::onSettingsChanged(const QString &key)
220 if (key == "usevolumekeys") {
221 bool grab = Settings::instance()->value(key, false).toBool();
222 qDebug() << "AdopterWindow::onSettingsChanged: usevolumekeys" << grab;
223 grabVolumeKeys(grab);