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 void AdopterWindow::show()
82 foreach (QWidget *w, QApplication::allWidgets()) {
83 w->setContextMenuPolicy(Qt::NoContextMenu);
92 QAction *AdopterWindow::addToolBarAction(QObject *receiver,
94 const QString &iconName,
98 qDebug() << "icon" << iconName << "text" << text;
100 return toolBar->addAction(QIcon(Platform::instance()->icon(iconName)),
101 text, receiver, member);
104 QAction *action = new QAction(text, this);
105 menuBar()->addAction(action);
106 connect(action, SIGNAL(triggered()), receiver, member);
111 void AdopterWindow::addToolBarSpace()
114 QFrame *frame = new QFrame(toolBar);
115 frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
116 toolBar->addWidget(frame);
120 void AdopterWindow::grabVolumeKeys(bool grab)
123 grabbingVolumeKeys = grab;
125 doGrabVolumeKeys(grab);
131 void AdopterWindow::doGrabVolumeKeys(bool grab)
135 qDebug() << "Not visible - skipping";
139 qDebug() << "Could not get window ID - skipping";
142 unsigned long val = grab? 1: 0;
143 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
145 qCritical() << "Unable to obtain _HILDON_ZOOM_KEY_ATOM";
148 XChangeProperty(QX11Info::display(),
154 reinterpret_cast<unsigned char *>(&val),
156 qDebug() << "Grabbed volume keys";
159 #endif // Q_WS_MAEMO_5
163 void AdopterWindow::showEvent(QShowEvent *e)
166 doGrabVolumeKeys(grabbingVolumeKeys);
167 QMainWindow::showEvent(e);
170 #endif // Q_WS_MAEMO_5
172 void AdopterWindow::keyPressEvent(QKeyEvent *event)
175 if (bookView && grabbingVolumeKeys) {
176 switch (event->key()) {
180 bookView->goNextPage();
185 bookView->goPreviousPage();
188 #endif // Q_WS_MAEMO_5
190 bookView->goPreviousPage();
193 case Qt::Key_PageDown:
194 bookView->goNextPage();
201 QMainWindow::keyPressEvent(event);
204 void AdopterWindow::onSettingsChanged(const QString &key)
206 if (key == "usevolumekeys") {
207 bool grab = Settings::instance()->value(key, false).toBool();
208 qDebug() << "AdopterWindow::onSettingsChanged: usevolumekeys" << grab;
209 grabVolumeKeys(grab);