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), toolBar(0)
22 setAttribute(Qt::WA_Maemo5StackedWindow, true);
25 QFrame *frame = new QFrame(this);
26 QVBoxLayout *layout = new QVBoxLayout(frame);
28 frame->setLayout(layout);
30 setCentralWidget(frame);
33 QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this);
34 closeAction->setSoftKeyRole(QAction::NegativeSoftKey);
35 connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
36 QMainWindow::addAction(closeAction);
39 setUnifiedTitleAndToolBarOnMac(true);
40 toolBar = addToolBar("");
41 toolBar->setMovable(false);
42 toolBar->setFloatable(false);
43 toolBar->toggleViewAction()->setVisible(false);
44 #if defined(Q_WS_X11) && !defined(Q_WS_MAEMO_5)
45 toolBar->setIconSize(QSize(42, 42));
47 #endif // Q_OS_SYMBIAN
50 connect(Settings::instance(), SIGNAL(valueChanged(const QString &)),
51 this, SLOT(onSettingsChanged(const QString &)));
54 void AdopterWindow::takeChildren(BookView *view, const QList<QWidget *> &others)
60 bookView->setParent(this);
63 qobject_cast<QVBoxLayout *>(centralWidget()->layout());
64 layout->addWidget(bookView, 1);
66 foreach (QWidget *child, others) {
68 child->setParent(this);
73 void AdopterWindow::leaveChildren()
77 centralWidget()->layout()->removeWidget(bookView);
82 bool AdopterWindow::hasChild(QWidget *child)
84 if (child == bookView) {
87 return this == child->parent();
90 void AdopterWindow::show()
93 foreach (QWidget *w, QApplication::allWidgets()) {
94 w->setContextMenuPolicy(Qt::NoContextMenu);
103 QAction *AdopterWindow::addToolBarAction(QObject *receiver,
105 const QString &iconName,
110 qDebug() << "icon" << iconName << "text" << text;
114 action = toolBar->addAction(QIcon(Platform::instance()->icon(iconName)),
115 text, receiver, member);
117 if (toolBar && important) {
118 QPushButton *button = new QPushButton(this);
119 button->setIconSize(QSize(60, 60));
120 button->setFixedSize(89, 60);
121 button->setIcon(QIcon(Platform::instance()->icon(iconName)));
122 button->setSizePolicy(QSizePolicy::MinimumExpanding,
123 QSizePolicy::Maximum);
124 connect(button, SIGNAL(clicked()), receiver, member);
125 toolBar->addWidget(button);
127 action = new QAction(text, this);
128 menuBar()->addAction(action);
129 connect(action, SIGNAL(triggered()), receiver, member);
132 #if defined Q_WS_MAEMO_5
134 action->setToolTip("");
140 void AdopterWindow::addToolBarSpace()
143 QFrame *frame = new QFrame(toolBar);
144 frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
145 toolBar->addWidget(frame);
149 void AdopterWindow::grabVolumeKeys(bool grab)
152 grabbingVolumeKeys = grab;
154 doGrabVolumeKeys(grab);
160 void AdopterWindow::doGrabVolumeKeys(bool grab)
164 qDebug() << "Not visible - skipping";
168 qDebug() << "Could not get window ID - skipping";
171 unsigned long val = grab? 1: 0;
172 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
174 qCritical() << "Unable to obtain _HILDON_ZOOM_KEY_ATOM";
177 XChangeProperty(QX11Info::display(),
183 reinterpret_cast<unsigned char *>(&val),
185 qDebug() << "Grabbed volume keys";
188 #endif // Q_WS_MAEMO_5
192 void AdopterWindow::showEvent(QShowEvent *e)
195 doGrabVolumeKeys(grabbingVolumeKeys);
196 QMainWindow::showEvent(e);
199 #endif // Q_WS_MAEMO_5
201 void AdopterWindow::keyPressEvent(QKeyEvent *event)
204 if (bookView && grabbingVolumeKeys) {
205 switch (event->key()) {
209 bookView->goNextPage();
214 bookView->goPreviousPage();
217 #endif // Q_WS_MAEMO_5
219 bookView->goPreviousPage();
222 case Qt::Key_PageDown:
223 bookView->goNextPage();
230 QMainWindow::keyPressEvent(event);
233 void AdopterWindow::onSettingsChanged(const QString &key)
235 if (key == "usevolumekeys") {
236 bool grab = Settings::instance()->value(key, false).toBool();
237 qDebug() << "AdopterWindow::onSettingsChanged: usevolumekeys" << grab;
238 grabVolumeKeys(grab);