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): QMainWindow(parent), bookView(0)
21 setAttribute(Qt::WA_Maemo5StackedWindow, true);
22 #endif // Q_WS_MAEMO_5
24 QFrame *frame = new QFrame(this);
25 QVBoxLayout *layout = new QVBoxLayout(frame);
27 frame->setLayout(layout);
28 setCentralWidget(frame);
31 QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this);
32 closeAction->setSoftKeyRole(QAction::NegativeSoftKey);
33 connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
34 QMainWindow::addAction(closeAction);
37 setUnifiedTitleAndToolBarOnMac(true);
38 toolBar = addToolBar("controls");
39 toolBar->setMovable(false);
40 toolBar->setFloatable(false);
41 toolBar->toggleViewAction()->setVisible(false);
42 #if defined(Q_WS_X11) && !defined(Q_WS_MAEMO_5)
43 toolBar->setIconSize(QSize(42, 42));
45 #endif // Q_OS_SYMBIAN
48 Settings *settings = Settings::instance();
49 connect(settings, SIGNAL(valueChanged(const QString &)),
50 this, SLOT(onSettingsChanged(const QString &)));
51 settings->setValue("usevolumekeys", settings->value("usevolumekeys"));
54 void AdopterWindow::takeChildren(BookView *view, const QList<QWidget *> &others)
60 bookView->setParent(centralWidget());
61 centralWidget()->layout()->addWidget(bookView);
64 foreach (QWidget *child, others) {
66 child->setParent(this);
71 void AdopterWindow::leaveChildren()
75 centralWidget()->layout()->removeWidget(bookView);
80 void AdopterWindow::show()
83 foreach (QWidget *w, QApplication::allWidgets()) {
84 w->setContextMenuPolicy(Qt::NoContextMenu);
93 QAction *AdopterWindow::addToolBarAction(QObject *receiver,
95 const QString &iconName,
99 qDebug() << "icon" << iconName << "text" << text;
101 return toolBar->addAction(QIcon(Platform::icon(iconName)),
102 text, receiver, member);
105 QAction *action = new QAction(text, this);
106 menuBar()->addAction(action);
107 connect(action, SIGNAL(triggered()), receiver, member);
112 void AdopterWindow::addToolBarSpace()
115 QFrame *frame = new QFrame(toolBar);
116 frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
117 toolBar->addWidget(frame);
121 void AdopterWindow::grabVolumeKeys(bool grab)
124 grabbingVolumeKeys = grab;
126 doGrabVolumeKeys(grab);
132 void AdopterWindow::doGrabVolumeKeys(bool grab)
136 qDebug() << "Not visible - skipping";
140 qDebug() << "Could not get window ID - skipping";
143 unsigned long val = grab? 1: 0;
144 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
146 qCritical() << "Unable to obtain _HILDON_ZOOM_KEY_ATOM";
149 XChangeProperty(QX11Info::display(),
155 reinterpret_cast<unsigned char *>(&val),
157 qDebug() << "Grabbed volume keys";
160 #endif // Q_WS_MAEMO_5
164 void AdopterWindow::showEvent(QShowEvent *e)
167 doGrabVolumeKeys(grabbingVolumeKeys);
168 QMainWindow::showEvent(e);
171 #endif // Q_WS_MAEMO_5
173 void AdopterWindow::keyPressEvent(QKeyEvent *event)
176 if (bookView && grabbingVolumeKeys) {
177 switch (event->key()) {
181 bookView->goNextPage();
186 bookView->goPreviousPage();
189 #endif // Q_WS_MAEMO_5
191 bookView->goPreviousPage();
194 case Qt::Key_PageDown:
195 bookView->goNextPage();
202 QMainWindow::keyPressEvent(event);
205 void AdopterWindow::onSettingsChanged(const QString &key)
208 if (key == "usevolumekeys") {
210 grabVolumeKeys(Settings::instance()->value(key).toBool());