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);
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);
37 // toolBar = new QToolBar(this);
38 // toolBar->setFixedWidth(QApplication::desktop()->
39 // availableGeometry().width());
40 // toolBar->setFixedHeight(70);
41 // toolBar->setIconSize(QSize(90, 70));
42 // toolBar->setFloatable(false);
43 // toolBar->setMovable(false);
44 // addToolBar(Qt::BottomToolBarArea, toolBar);
47 setUnifiedTitleAndToolBarOnMac(true);
48 toolBar = addToolBar("");
49 toolBar->setMovable(false);
50 toolBar->setFloatable(false);
51 toolBar->toggleViewAction()->setVisible(false);
52 #if defined(Q_WS_X11) && !defined(Q_WS_MAEMO_5)
53 toolBar->setIconSize(QSize(42, 42));
55 #endif // Q_OS_SYMBIAN
58 connect(Settings::instance(), SIGNAL(valueChanged(const QString &)),
59 this, SLOT(onSettingsChanged(const QString &)));
62 void AdopterWindow::takeChildren(BookView *view, const QList<QWidget *> &others)
68 bookView->setParent(centralWidget());
70 centralWidget()->layout()->addWidget(bookView);
72 foreach (QWidget *child, others) {
74 child->setParent(this);
79 void AdopterWindow::leaveChildren()
83 centralWidget()->layout()->removeWidget(bookView);
88 bool AdopterWindow::hasChild(QWidget *child)
90 if (child == bookView) {
93 return this == child->parent();
96 void AdopterWindow::show()
99 foreach (QWidget *w, QApplication::allWidgets()) {
100 w->setContextMenuPolicy(Qt::NoContextMenu);
109 QAction *AdopterWindow::addToolBarAction(QObject *receiver,
111 const QString &iconName,
116 qDebug() << "icon" << iconName << "text" << text;
120 action = toolBar->addAction(QIcon(Platform::instance()->icon(iconName)),
121 text, receiver, member);
123 if (0) { // if (important) {
124 qDebug() << "Add Symbian tool bar action";
125 QAction *toolBarAction = toolBar->addAction(
126 QIcon(Platform::instance()->icon(iconName)),
127 text, receiver, member);
128 toolBarAction->setText("");
129 toolBarAction->setToolTip("");
130 connect(toolBarAction, SIGNAL(triggered()), receiver, member);
132 action = new QAction(text, this);
133 menuBar()->addAction(action);
134 connect(action, SIGNAL(triggered()), receiver, member);
137 #if defined Q_WS_MAEMO_5
139 action->setToolTip("");
145 void AdopterWindow::addToolBarSpace()
148 QFrame *frame = new QFrame(toolBar);
149 frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
150 toolBar->addWidget(frame);
154 void AdopterWindow::grabVolumeKeys(bool grab)
157 grabbingVolumeKeys = grab;
159 doGrabVolumeKeys(grab);
165 void AdopterWindow::doGrabVolumeKeys(bool grab)
169 qDebug() << "Not visible - skipping";
173 qDebug() << "Could not get window ID - skipping";
176 unsigned long val = grab? 1: 0;
177 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
179 qCritical() << "Unable to obtain _HILDON_ZOOM_KEY_ATOM";
182 XChangeProperty(QX11Info::display(),
188 reinterpret_cast<unsigned char *>(&val),
190 qDebug() << "Grabbed volume keys";
193 #endif // Q_WS_MAEMO_5
197 void AdopterWindow::showEvent(QShowEvent *e)
200 doGrabVolumeKeys(grabbingVolumeKeys);
201 QMainWindow::showEvent(e);
204 #endif // Q_WS_MAEMO_5
206 void AdopterWindow::keyPressEvent(QKeyEvent *event)
209 if (bookView && grabbingVolumeKeys) {
210 switch (event->key()) {
214 bookView->goNextPage();
219 bookView->goPreviousPage();
222 #endif // Q_WS_MAEMO_5
224 bookView->goPreviousPage();
227 case Qt::Key_PageDown:
228 bookView->goNextPage();
235 QMainWindow::keyPressEvent(event);
238 void AdopterWindow::onSettingsChanged(const QString &key)
240 if (key == "usevolumekeys") {
241 bool grab = Settings::instance()->value(key, false).toBool();
242 qDebug() << "AdopterWindow::onSettingsChanged: usevolumekeys" << grab;
243 grabVolumeKeys(grab);