--- /dev/null
+#include <QtGui>
+
+#if defined(Q_WS_MAEMO_5)
+# include <QtGui/QX11Info>
+# include <X11/Xlib.h>
+# include <X11/Xatom.h>
+# include <QAbstractKineticScroller>
+#endif
+
+#include "adopterwindow.h"
+#include "trace.h"
+#include "bookview.h"
+#include "platform.h"
+#include "settings.h"
+
+AdopterWindow::AdopterWindow(QWidget *parent): QMainWindow(parent), bookView(0)
+{
+ TRACE;
+
+#ifdef Q_WS_MAEMO_5
+ setAttribute(Qt::WA_Maemo5StackedWindow, true);
+#endif // Q_WS_MAEMO_5
+
+ QFrame *frame = new QFrame(this);
+ QVBoxLayout *layout = new QVBoxLayout(frame);
+ layout->setMargin(0);
+ frame->setLayout(layout);
+ setCentralWidget(frame);
+
+#ifdef Q_OS_SYMBIAN
+ QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this);
+ closeAction->setSoftKeyRole(QAction::NegativeSoftKey);
+ connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
+ QMainWindow::addAction(closeAction);
+#else
+ // Tool bar
+ setUnifiedTitleAndToolBarOnMac(true);
+ toolBar = addToolBar("controls");
+ toolBar->setMovable(false);
+ toolBar->setFloatable(false);
+ toolBar->toggleViewAction()->setVisible(false);
+#if defined(Q_WS_X11) && !defined(Q_WS_MAEMO_5)
+ toolBar->setIconSize(QSize(42, 42));
+#endif
+#endif // Q_OS_SYMBIAN
+
+ // Monitor settings
+ Settings *settings = Settings::instance();
+ connect(settings, SIGNAL(valueChanged(const QString &)),
+ this, SLOT(onSettingsChanged(const QString &)));
+ settings->setValue("usevolumekeys", settings->value("usevolumekeys"));
+}
+
+void AdopterWindow::takeChildren(BookView *view, const QList<QWidget *> &others)
+{
+ TRACE;
+ leaveChildren();
+ if (view) {
+ bookView = view;
+ bookView->setParent(centralWidget());
+ centralWidget()->layout()->addWidget(bookView);
+ bookView->show();
+ }
+ foreach (QWidget *child, others) {
+ if (child) {
+ child->setParent(this);
+ }
+ }
+}
+
+void AdopterWindow::leaveChildren()
+{
+ TRACE;
+ if (bookView) {
+ centralWidget()->layout()->removeWidget(bookView);
+ bookView = 0;
+ }
+}
+
+void AdopterWindow::show()
+{
+#ifdef Q_OS_SYMBIAN
+ foreach (QWidget *w, QApplication::allWidgets()) {
+ w->setContextMenuPolicy(Qt::NoContextMenu);
+ }
+ showMaximized();
+ raise();
+#else
+ QMainWindow::show();
+#endif
+}
+
+QAction *AdopterWindow::addToolBarAction(QObject *receiver,
+ const char *member,
+ const QString &iconName,
+ const QString &text)
+{
+ TRACE;
+ qDebug() << "icon" << iconName << "text" << text;
+#ifndef Q_OS_SYMBIAN
+ return toolBar->addAction(QIcon(Platform::icon(iconName)),
+ text, receiver, member);
+#else
+ Q_UNUSED(iconName);
+ QAction *action = new QAction(text, this);
+ menuBar()->addAction(action);
+ connect(action, SIGNAL(triggered()), receiver, member);
+ return action;
+#endif
+}
+
+void AdopterWindow::addToolBarSpace()
+{
+#ifndef Q_OS_SYMBIAN
+ QFrame *frame = new QFrame(toolBar);
+ frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+ toolBar->addWidget(frame);
+#endif
+}
+
+void AdopterWindow::grabVolumeKeys(bool grab)
+{
+ TRACE;
+ grabbingVolumeKeys = grab;
+#ifdef Q_WS_MAEMO_5
+ doGrabVolumeKeys(grab);
+#endif
+}
+
+#ifdef Q_WS_MAEMO_5
+
+void AdopterWindow::doGrabVolumeKeys(bool grab)
+{
+ TRACE;
+ if (!isVisible()) {
+ qDebug() << "Not visible - skipping";
+ return;
+ }
+ if (!winId()) {
+ qDebug() << "Could not get window ID - skipping";
+ return;
+ }
+ unsigned long val = grab? 1: 0;
+ Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
+ if (!atom) {
+ qCritical() << "Unable to obtain _HILDON_ZOOM_KEY_ATOM";
+ return;
+ }
+ XChangeProperty(QX11Info::display(),
+ winId(),
+ atom,
+ XA_INTEGER,
+ 32,
+ PropModeReplace,
+ reinterpret_cast<unsigned char *>(&val),
+ 1);
+ qDebug() << "Grabbed volume keys";
+}
+
+#endif // Q_WS_MAEMO_5
+
+#ifdef Q_WS_MAEMO_5
+
+void AdopterWindow::showEvent(QShowEvent *e)
+{
+ TRACE;
+ doGrabVolumeKeys(grabbingVolumeKeys);
+ QMainWindow::showEvent(e);
+}
+
+#endif // Q_WS_MAEMO_5
+
+void AdopterWindow::keyPressEvent(QKeyEvent *event)
+{
+ TRACE;
+ if (bookView && grabbingVolumeKeys) {
+ switch (event->key()) {
+#ifdef Q_WS_MAEMO_5
+ case Qt::Key_F7:
+ qDebug() << "F7";
+ bookView->goNextPage();
+ event->accept();
+ break;
+ case Qt::Key_F8:
+ qDebug() << "F8";
+ bookView->goPreviousPage();
+ event->accept();
+ break;
+#endif // Q_WS_MAEMO_5
+ case Qt::Key_PageUp:
+ bookView->goPreviousPage();
+ event->accept();
+ break;
+ case Qt::Key_PageDown:
+ bookView->goNextPage();
+ event->accept();
+ break;
+ default:
+ ;
+ }
+ }
+ QMainWindow::keyPressEvent(event);
+}
+
+void AdopterWindow::onSettingsChanged(const QString &key)
+{
+ TRACE;
+ if (key == "usevolumekeys") {
+ qDebug() << key;
+ grabVolumeKeys(Settings::instance()->value(key).toBool());
+ }
+}
+
--- /dev/null
+#ifndef ADOPTERWINDOW_H
+#define ADOPTERWINDOW_H
+
+#include <QMainWindow>
+#include <QList>
+
+class QWidget;
+class QToolBar;
+class QAction;
+class BookView;
+
+/**
+ * A toplevel window that can adopt a BookView and other children.
+ * On Maemo, it can also grab the volume keys.
+ */
+class AdopterWindow: public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ explicit AdopterWindow(QWidget *parent = 0);
+
+ /** Adopt children "bookView" and "others". */
+ void takeChildren(BookView *bookView, const QList<QWidget *> &others);
+
+ /** Release current children (adopted in @see takeChildren). */
+ void leaveChildren();
+
+ /**
+ * Add action that is visible on the tool bar (except on Symbian, where
+ * it is visible on the Options menu).
+ */
+ QAction *addToolBarAction(QObject *receiver, const char *slot,
+ const QString &iconName, const QString &text);
+
+ /** Add spacing to tool bar. */
+ void addToolBarSpace();
+
+ /** Show window. */
+ void show();
+
+ /** If grab is true, volume keys will generate pageUp/Down keys. */
+ void grabVolumeKeys(bool grab);
+
+public slots:
+ /** Handle settings changes. */
+ void onSettingsChanged(const QString &key);
+
+protected:
+ void keyPressEvent(QKeyEvent *event);
+#ifdef Q_WS_MAEMO_5
+ void showEvent(QShowEvent *event);
+ void doGrabVolumeKeys(bool grab);
+#endif
+ BookView *bookView;
+ bool grabbingVolumeKeys;/**< True, if volume keys should be grabbed. */
+#ifndef Q_OS_SYMBIAN
+ QToolBar *toolBar;
+#endif
+};
+
+#endif // ADOPTERWINDOW_H
#include <QtGui>
#include <QWebFrame>
-#if defined(Q_WS_MAEMO_5)
-# include <QAbstractKineticScroller>
-#elif defined(Q_OS_SYMBIAN)
+#if defined(Q_OS_SYMBIAN)
+# include "mediakeysobserver.h"
# include "flickcharm.h"
#endif
#include "progressdialog.h"
#include "platform.h"
-BookView::BookView(QWidget *parent):
- QWebView(parent), contentIndex(-1), mBook(0),
+BookView::BookView(QWidget *parent): QWebView(parent), contentIndex(-1), mBook(0),
restorePositionAfterLoad(false), positionAfterLoad(0), loaded(false),
- contentsHeight(0)
+ contentsHeight(0), grabbingVolumeKeys(false)
{
TRACE;
+
+ // Set up web view defaults
settings()->setAttribute(QWebSettings::AutoLoadImages, true);
settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
settings()->setAttribute(QWebSettings::JavaEnabled, false);
false);
settings()->setDefaultTextEncoding("utf-8");
page()->setContentEditable(false);
-
-#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
- // Suppress unwanted text selections on Maemo and Symbian
- installEventFilter(this);
-#endif
QWebFrame *frame = page()->mainFrame();
#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
frame->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
#endif
frame->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
-
- bookmarkImage = QImage(":/icons/bookmark.png");
-
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool)));
connect(frame, SIGNAL(javaScriptWindowObjectCleared()),
this, SLOT(addJavaScriptObjects()));
connect(frame, SIGNAL(contentsSizeChanged(const QSize &)),
this, SLOT(onContentsSizeChanged(const QSize &)));
- connect(Settings::instance(), SIGNAL(valueChanged(const QString &)),
- this, SLOT(onSettingsChanged(const QString &)));
+
+ // Suppress unwanted text selections on Maemo and Symbian
+#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
+ installEventFilter(this);
+#endif
+
+ // Pre-load bookmark icon
+ bookmarkImage = QImage(":/icons/bookmark.png");
+
+ // Handle settings changes, force handling initial settings
Settings *s = Settings::instance();
+ connect(s, SIGNAL(valueChanged(const QString &)),
+ this, SLOT(onSettingsChanged(const QString &)));
s->setValue("zoom", s->value("zoom", 160));
s->setValue("font", s->value("font", Platform::defaultFont()));
s->setValue("scheme", s->value("scheme", "default"));
+ s->setValue("usevolumekeys", s->value("usevolumekeys", false));
setBook(0);
+ // Enable kinetic scrolling
#if defined(Q_WS_MAEMO_5)
scrollerMonitor = 0;
scroller = property("kineticScroller").value<QAbstractKineticScroller *>();
charm = new FlickCharm(this);
charm->activateOn(this);
#endif
-}
-BookView::~BookView()
-{
- TRACE;
+ // Observe media keys on Symbian
+#ifdef Q_OS_SYMBIAN
+ MediaKeysObserver *observer = MediaKeysObserver::instance();
+ connect(observer, SIGNAL(mediaKeyPressed(MediaKeysObserver::MediaKeys)),
+ this, SLOT(onMediaKeysPressed(MediaKeysObserver::MediaKeys)));
+#endif
}
void BookView::loadContent(int index)
{
TRACE;
+
if (!mBook) {
return;
}
script.close();
QVariant ret = frame->evaluateJavaScript(scriptText);
}
+ else if (key == "usevolumekeys") {
+ grabVolumeKeys(Settings::instance()->value(key).toBool());
+ }
}
void BookView::paintEvent(QPaintEvent *e)
QWebView::timerEvent(e);
}
-void BookView::keyPressEvent(QKeyEvent *event)
-{
- switch (event->key()) {
- case Qt::Key_F7:
- goNextPage();
- event->accept();
- break;
- case Qt::Key_F8:
- goPreviousPage();
- event->accept();
- break;
- default:
- ;
- }
- QWebView::keyPressEvent(event);
-}
-
void BookView::goPreviousPage()
{
QWebFrame *frame = page()->mainFrame();
showProgress();
}
}
+
+void BookView::grabVolumeKeys(bool grab)
+{
+ TRACE;
+ grabbingVolumeKeys = grab;
+}
+
+#ifdef Q_OS_SYMBIAN
+
+void BookView::onMediaKeysPressed(MediaKeysObserver::MediaKeys key)
+{
+ TRACE;
+ qDebug() << "Key" << (int)key;
+ if (grabbingVolumeKeys) {
+ if (key == MediaKeysObserver::EVolIncKey) {
+ qDebug() << "Volume up";
+ goNextPage();
+ } else if (key == MediaKeysObserver::EVolDecKey){
+ qDebug() << "Volume down";
+ goPreviousPage();
+ }
+ }
+}
+
+#endif // Q_OS_SYMBIAN
#include "book.h"
+#ifdef Q_OS_SYMBIAN
+# include "mediakeysobserver.h"
+#endif
+
class QModelIndex;
class Progress;
class QAbstractKineticScroller;
public:
explicit BookView(QWidget *parent = 0);
- virtual ~BookView();
void setBook(Book *book);
Book *book();
void goToBookmark(const Book::Bookmark &bookmark);
void goToPart(int part, const QString &fragment);
void goToFragment(const QString &fragment);
+ /** If grab is true, volume keys will generate act as page up/down. */
+ void grabVolumeKeys(bool grab);
+
signals:
void partLoadStart(int index);
void partLoadEnd(int index);
/** Go to next page. */
void goNextPage();
+protected slots:
+#ifdef Q_OS_SYMBIAN
+ /** Observe media keys. */
+ void onMediaKeysPressed(MediaKeysObserver::MediaKeys key);
+#endif
+
protected:
void paintEvent(QPaintEvent *e);
void mousePressEvent(QMouseEvent *e);
void wheelEvent(QWheelEvent *);
bool eventFilter(QObject *o, QEvent *e);
+ void timerEvent(QTimerEvent *e);
#ifdef Q_WS_MAEMO_5
void leaveEvent(QEvent *e);
void enterEvent(QEvent *e);
#endif // Q_WS_MAEMO_5
- void timerEvent(QTimerEvent *e);
- void keyPressEvent(QKeyEvent *e);
-private:
/** Load given part. */
void loadContent(int index);
/** Show reading progress. */
void showProgress();
- int contentIndex; /**< Current part in book. */
- Book *mBook; /**< Book to show. */
+ int contentIndex; /**< Current part in book. */
+ Book *mBook; /**< Book to show. */
bool restorePositionAfterLoad;
- /**< If true, restore current position after load. */
- qreal positionAfterLoad;
- /**< Position to be restored after load. */
+ /**< If true, restore current position after load. */
+ qreal positionAfterLoad;/**< Position to be restored after load. */
bool restoreFragmentAfterLoad;
- /**< If true, restore fragment location after load. */
+ /**< If true, restore fragment location after load. */
QString fragmentAfterLoad;
- /**< Fragment location to be restored after load. */
- QImage bookmarkImage;
- /**< Bookmark icon pre-loaded. */
- bool loaded; /**< True if content has been loaded. */
- bool mousePressed;
- int contentsHeight; /**< Last know height of the frame. */
+ /**< Fragment location to be restored after load. */
+ QImage bookmarkImage; /**< Bookmark icon pre-loaded. */
+ bool loaded; /**< True, if content has been loaded. */
+ bool mousePressed; /**< Event filter's mouse button state. */
+ int contentsHeight; /**< Last know height of the frame. */
+ bool grabbingVolumeKeys;/**< True, if volume keys should be grabbed. */
#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
- int scrollerMonitor;
+ int scrollerMonitor; /**< ID of timer monitoring kinetic scroll. */
#endif
#if defined(Q_WS_MAEMO_5)
QAbstractKineticScroller *scroller;
bookmarkinfodialog.cpp \\r
widgets/dyalog.cpp \\r
chaptersdialog.cpp \\r
- widgets/fullscreenwindow.cpp \\r
+ fullscreenwindow.cpp \\r
trace.cpp \\r
widgets/toolbuttonbox.cpp \\r
model/bookfinder.cpp \\r
widgets/listwindow.cpp \\r
widgets/progress.cpp \\r
- widgets/adopterwindow.cpp \\r
+ adopterwindow.cpp \\r
platform.cpp \\r
model/bookdb.cpp \\r
searchdialog.cpp \\r
bookmarkinfodialog.h \\r
widgets/dyalog.h \\r
chaptersdialog.h \\r
- widgets/fullscreenwindow.h \\r
+ fullscreenwindow.h \\r
trace.h \\r
widgets/toolbuttonbox.h \\r
model/bookfinder.h \\r
widgets/listwindow.h \\r
widgets/progress.h \\r
- widgets/adopterwindow.h \\r
+ adopterwindow.h \\r
widgets/listview.h \\r
model/xmlhandler.h \\r
platform.h \\r
--- /dev/null
+#include <QtGui>
+
+#include "fullscreenwindow.h"
+#include "translucentbutton.h"
+#include "trace.h"
+
+FullScreenWindow::FullScreenWindow(QWidget *parent): AdopterWindow(parent)
+{
+ Q_ASSERT(parent);
+#ifdef Q_WS_MAEMO_5
+ setAttribute(Qt::WA_Maemo5StackedWindow, true);
+ setAttribute(Qt::WA_Maemo5NonComposited, true);
+#endif // Q_WS_MAEMO_5
+#ifndef Q_OS_SYMBIAN
+ toolBar->hide();
+#endif
+ QFrame *frame = new QFrame(this);
+ QVBoxLayout *layout = new QVBoxLayout(frame);
+ layout->setMargin(0);
+ frame->setLayout(layout);
+ setCentralWidget(frame);
+ restoreButton = new TranslucentButton("view-normal", this);
+ QRect screen = QApplication::desktop()->screenGeometry();
+ restoreButton->setGeometry((screen.width() - TranslucentButton::pixels) / 2,
+ screen.height() - TranslucentButton::pixels - 9,
+ TranslucentButton::pixels, TranslucentButton::pixels);
+ connect(restoreButton, SIGNAL(triggered()), this, SIGNAL(restore()));
+}
+
+void FullScreenWindow::showFullScreen()
+{
+#ifdef Q_WS_MAEMO_5
+ setAttribute(Qt::WA_Maemo5PortraitOrientation, parentWidget()->
+ testAttribute(Qt::WA_Maemo5PortraitOrientation));
+ setAttribute(Qt::WA_Maemo5LandscapeOrientation, parentWidget()->
+ testAttribute(Qt::WA_Maemo5LandscapeOrientation));
+#endif // Q_WS_MAEMO_5
+ QWidget::showFullScreen();
+ restoreButton->flash(3000);
+}
+
+void FullScreenWindow::resizeEvent(QResizeEvent *e)
+{
+ Q_UNUSED(e);
+ QRect screen = QApplication::desktop()->screenGeometry();
+ restoreButton->setGeometry(screen.width() - TranslucentButton::pixels - 9,
+ screen.height() - TranslucentButton::pixels - 9,
+ TranslucentButton::pixels, TranslucentButton::pixels);
+}
--- /dev/null
+#ifndef FULLSCREENWINDOW_H
+#define FULLSCREENWINDOW_H
+
+#include <QRect>
+#include <QObject>
+
+#include "adopterwindow.h"
+
+class QWidget;
+class QMouseEvent;
+class QResizeEvent;
+class TranslucentButton;
+
+/** A full screen window with a restore button. */
+class FullScreenWindow: public AdopterWindow
+{
+ Q_OBJECT
+
+public:
+ explicit FullScreenWindow(QWidget *parent);
+ void showFullScreen();
+
+signals:
+ /** Emitted when the restore button is pressed. */
+ void restore();
+
+protected:
+ void resizeEvent(QResizeEvent *e);
+
+private:
+ TranslucentButton *restoreButton;
+};
+
+#endif // FULLSCREENWINDOW_H
#include <QtGui>
+#include <QEvent>
#ifdef Q_WS_MAEMO_5
# include <QtDBus>
this, SLOT(onSettingsChanged(const QString &)));
settings->setValue("orientation", settings->value("orientation"));
settings->setValue("lightson", settings->value("lightson"));
- settings->setValue("usevolumekeys", settings->value("usevolumekeys"));
// Handle book view buttons
connect(nextButton, SIGNAL(triggered()), this, SLOT(goToNextPage()));
connect(previousButton, SIGNAL(triggered()), this, SLOT(goToPreviousPage()));
+ // Adopt view, show window
+ showRegular();
+
#ifdef DORIAN_TEST_MODEL
(void)new ModelTest(Library::instance(), this);
#endif
}
-MainWindow::~MainWindow()
-{
-}
-
void MainWindow::onCurrentBookChanged()
{
setCurrentBook(Library::instance()->nowReading());
void MainWindow::onSettingsChanged(const QString &key)
{
+ TRACE;
+ qDebug() << key;
#if defined(Q_WS_MAEMO_5)
if (key == "orientation") {
QString value = Settings::instance()->value(key).toString();
- qDebug() << "MainWindow::onSettingsChanged: orientation" << value;
if (value == "portrait") {
setAttribute(Qt::WA_Maemo5LandscapeOrientation, false);
setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
}
} else if (key == "lightson") {
bool enable = Settings::instance()->value(key, false).toBool();
- qDebug() << "MainWindow::onSettingsChanged: lightson:" << enable;
killTimer(preventBlankingTimer);
if (enable) {
preventBlankingTimer = startTimer(29 * 1000);
}
- } else if (key == "usevolumekeys") {
- bool value = Settings::instance()->value(key).toBool();
- qDebug() << "MainWindow::onSettingsChanged: usevolumekeys" << value;
- grabZoomKeys(value);
- fullScreenWindow->grabZoomKeys(value);
- }
-#elif defined Q_OS_SYMBIAN
- if (key == "usevolumekeys") {
- bool value = Settings::instance()->value(key).toBool();
- qDebug() << "MainWindow::onSettingsChanged: usevolumekeys" << value;
- grabZoomKeys(value);
- fullScreenWindow->grabZoomKeys(value);
}
-#else
- Q_UNUSED(key);
#endif // Q_WS_MAEMO_5
}
void MainWindow::onPartLoadStart()
{
TRACE;
-#ifdef Q_WS_MAEMO_5
- setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
-#endif
+ Platform::showBusy(this, true);
}
void MainWindow::onPartLoadEnd(int index)
enableNext = true;
}
}
-#ifdef Q_WS_MAEMO_5
- setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
-#endif // Q_WS_MAEMO_5
+ Platform::showBusy(this, false);
}
void MainWindow::onAddBookmark(const QString ¬e)
aboutDialog->show();
}
-
void MainWindow::goToNextPage()
{
nextButton->flash();
libraryProgress->reset();
}
-
void MainWindow::onBeginLoad(int total)
{
libraryProgress->setVisible(total > 0);
libraryProgress->hide();
libraryProgress->reset();
}
-
#define MAINWINDOW_H
#include <QModelIndex>
+#include <QEvent>
#include "adopterwindow.h"
public:
MainWindow(QWidget *parent = 0);
- ~MainWindow();
public slots:
void showLibrary();
QMessageBox::Ok);
#endif
}
+
+void Platform::showBusy(QWidget *w, bool isBusy)
+{
+#ifdef Q_WS_MAEMO_5
+ w->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, isBusy);
+#else
+ Q_UNUSED(w);
+ Q_UNUSED(isBusy);
+#endif
+}
static QString downloadDir();
static QString defaultFont();
static void information(const QString &label, QWidget *parent = 0);
+ static void showBusy(QWidget *w, bool isBusy);
};
#endif // PLATFORM_H
+++ /dev/null
-#include <QtGui>
-
-#if defined(Q_WS_MAEMO_5)
-# include <QtGui/QX11Info>
-# include <X11/Xlib.h>
-# include <X11/Xatom.h>
-#elif defined(Q_OS_SYMBIAN)
-# include "mediakeysobserver.h"
-#endif
-
-#include "trace.h"
-#include "adopterwindow.h"
-#include "platform.h"
-
-AdopterWindow::AdopterWindow(QWidget *parent):
- QMainWindow(parent), grabbingZoomKeys(false), mainChild(0)
-{
- TRACE;
-
-#ifdef Q_WS_MAEMO_5
- setAttribute(Qt::WA_Maemo5StackedWindow, true);
-#endif // Q_WS_MAEMO_5
-
- QFrame *frame = new QFrame(this);
- QVBoxLayout *layout = new QVBoxLayout(frame);
- layout->setMargin(0);
- frame->setLayout(layout);
- setCentralWidget(frame);
-
-#ifdef Q_OS_SYMBIAN
- QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this);
- closeAction->setSoftKeyRole(QAction::NegativeSoftKey);
- connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
- QMainWindow::addAction(closeAction);
- MediaKeysObserver *observer = MediaKeysObserver::instance();
- connect(observer, SIGNAL(mediaKeyPressed(MediaKeysObserver::MediaKeys)),
- this, SLOT(onMediaKeysPressed(MediaKeysObserver::MediaKeys)));
-#else
- // Tool bar
- setUnifiedTitleAndToolBarOnMac(true);
- toolBar = addToolBar("controls");
- toolBar->setMovable(false);
- toolBar->setFloatable(false);
- toolBar->toggleViewAction()->setVisible(false);
-#if defined(Q_WS_X11) && !defined(Q_WS_MAEMO_5)
- toolBar->setIconSize(QSize(42, 42));
-#endif
-#endif // Q_OS_SYMBIAN
-}
-
-void AdopterWindow::takeChildren(QWidget *main, const QList<QWidget *> &others)
-{
- TRACE;
- leaveChildren();
- if (main) {
- mainChild = main;
- mainChild->setParent(centralWidget());
- centralWidget()->layout()->addWidget(mainChild);
- mainChild->show();
- }
- foreach (QWidget *child, others) {
- if (child) {
- child->setParent(this);
- }
- }
-}
-
-void AdopterWindow::leaveChildren()
-{
- TRACE;
- if (mainChild) {
- centralWidget()->layout()->removeWidget(mainChild);
- mainChild = 0;
- }
-}
-
-void AdopterWindow::grabZoomKeys(bool grab)
-{
- TRACE;
- grabbingZoomKeys = grab;
- doGrabZoomKeys(grab);
-}
-
-void AdopterWindow::showEvent(QShowEvent *e)
-{
- TRACE;
- doGrabZoomKeys(grabbingZoomKeys);
- QMainWindow::showEvent(e);
-}
-
-void AdopterWindow::doGrabZoomKeys(bool grab)
-{
- TRACE;
-#ifdef Q_WS_MAEMO_5
- if (!isVisible()) {
- qDebug() << "Not visible - skipping";
- }
- if (!winId()) {
- qDebug() << "Could not get window ID - skipping";
- return;
- }
- unsigned long val = grab? 1: 0;
- Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
- if (!atom) {
- qCritical() << "Unable to obtain _HILDON_ZOOM_KEY_ATOM";
- return;
- }
- XChangeProperty(QX11Info::display(),
- winId(),
- atom,
- XA_INTEGER,
- 32,
- PropModeReplace,
- reinterpret_cast<unsigned char *>(&val),
- 1);
-#else
- Q_UNUSED(grab);
-#endif // Q_WS_MAEMO_5
-}
-
-void AdopterWindow::show()
-{
-#ifdef Q_OS_SYMBIAN
- foreach (QWidget *w, QApplication::allWidgets()) {
- w->setContextMenuPolicy(Qt::NoContextMenu);
- }
- showMaximized();
- raise();
-#else
- QMainWindow::show();
-#endif
-}
-
-QAction *AdopterWindow::addToolBarAction(QObject *receiver,
- const char *member,
- const QString &iconName,
- const QString &text)
-{
- TRACE;
- qDebug() << "icon" << iconName << "text" << text;
-#ifndef Q_OS_SYMBIAN
- return toolBar->addAction(QIcon(Platform::icon(iconName)),
- text, receiver, member);
-#else
- Q_UNUSED(iconName);
- QAction *action = new QAction(text, this);
- menuBar()->addAction(action);
- connect(action, SIGNAL(triggered()), receiver, member);
- return action;
-#endif
-}
-
-void AdopterWindow::addToolBarSpace()
-{
-#ifndef Q_OS_SYMBIAN
- QFrame *frame = new QFrame(toolBar);
- frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
- toolBar->addWidget(frame);
-#endif
-}
-
-#ifdef Q_OS_SYMBIAN
-
-void AdopterWindow::onMediaKeysPressed(MediaKeysObserver::MediaKeys key)
-{
- qDebug() << "AdopterWindow::onMediaKeysPressed:" << (int)key;
-
- if ((key != MediaKeysObserver::EVolIncKey) &&
- (key != MediaKeysObserver::EVolDecKey)) {
- return;
- }
-
- if (grabbingZoomKeys) {
- qDebug() << "Posting"
- << ((key == MediaKeysObserver::EVolIncKey)? "Key_F7": "Key_F8");
- QKeyEvent *event = new QKeyEvent(QEvent::KeyPress,
- (key == MediaKeysObserver::EVolIncKey)? Qt::Key_F7: Qt::Key_F8, 0);
- QCoreApplication::sendEvent(this, event);
- }
-}
-
-#endif // Q_OS_SYMBIAN
+++ /dev/null
-#ifndef ADOPTERWINDOW_H
-#define ADOPTERWINDOW_H
-
-#include <QMainWindow>
-#include <QList>
-
-#ifdef Q_OS_SYMBIAN
-# include "mediakeysobserver.h"
-#endif
-
-class QWidget;
-class QToolBar;
-class QAction;
-
-/**
- * A main window that can adopt other windows' children, and grabs the
- * zoom (volume) keys on Maemo.
- */
-class AdopterWindow: public QMainWindow
-{
- Q_OBJECT
-public:
- explicit AdopterWindow(QWidget *parent = 0);
-
- /* If true, zoom (volume) keys will generate Key_F7 and Key_F8 events. */
- void grabZoomKeys(bool grab);
-
- /** Adopt children "main" and "others". */
- void takeChildren(QWidget *main, const QList<QWidget *> &others);
-
- /** Release current children (adopted in @see takeChildren). */
- void leaveChildren();
-
- /**
- * Add action that is visible on the tool bar (except on Symbian, where
- * it is visible on the Options menu).
- */
- QAction *addToolBarAction(QObject *receiver, const char *slot,
- const QString &iconName, const QString &text);
-
- /** Add space. */
- void addToolBarSpace();
-
- /** Show window. */
- void show();
-
-signals:
-
-protected slots:
-#ifdef Q_OS_SYMBIAN
- void onMediaKeysPressed(MediaKeysObserver::MediaKeys key);
-#endif
-
-protected:
- void showEvent(QShowEvent *e);
- void doGrabZoomKeys(bool grab);
- bool grabbingZoomKeys;
- QWidget *mainChild;
-#ifndef Q_OS_SYMBIAN
- QToolBar *toolBar;
-#endif
-};
-
-#endif // ADOPTERWINDOW_H
+++ /dev/null
-#include <QtGui>
-
-#include "fullscreenwindow.h"
-#include "translucentbutton.h"
-#include "trace.h"
-
-FullScreenWindow::FullScreenWindow(QWidget *parent): AdopterWindow(parent)
-{
- Q_ASSERT(parent);
-#ifdef Q_WS_MAEMO_5
- setAttribute(Qt::WA_Maemo5StackedWindow, true);
- setAttribute(Qt::WA_Maemo5NonComposited, true);
-#endif // Q_WS_MAEMO_5
-#ifndef Q_OS_SYMBIAN
- toolBar->hide();
-#endif
- QFrame *frame = new QFrame(this);
- QVBoxLayout *layout = new QVBoxLayout(frame);
- layout->setMargin(0);
- frame->setLayout(layout);
- setCentralWidget(frame);
- restoreButton = new TranslucentButton("view-normal", this);
- QRect screen = QApplication::desktop()->screenGeometry();
- restoreButton->setGeometry((screen.width() - TranslucentButton::pixels) / 2,
- screen.height() - TranslucentButton::pixels - 9,
- TranslucentButton::pixels, TranslucentButton::pixels);
- connect(restoreButton, SIGNAL(triggered()), this, SIGNAL(restore()));
-}
-
-void FullScreenWindow::showFullScreen()
-{
-#ifdef Q_WS_MAEMO_5
- setAttribute(Qt::WA_Maemo5PortraitOrientation, parentWidget()->
- testAttribute(Qt::WA_Maemo5PortraitOrientation));
- setAttribute(Qt::WA_Maemo5LandscapeOrientation, parentWidget()->
- testAttribute(Qt::WA_Maemo5LandscapeOrientation));
-#endif // Q_WS_MAEMO_5
- QWidget::showFullScreen();
- restoreButton->flash(3000);
-}
-
-void FullScreenWindow::resizeEvent(QResizeEvent *e)
-{
- Q_UNUSED(e);
- QRect screen = QApplication::desktop()->screenGeometry();
- restoreButton->setGeometry(screen.width() - TranslucentButton::pixels - 9,
- screen.height() - TranslucentButton::pixels - 9,
- TranslucentButton::pixels, TranslucentButton::pixels);
-}
+++ /dev/null
-#ifndef FULLSCREENWINDOW_H
-#define FULLSCREENWINDOW_H
-
-#include <QRect>
-#include <QObject>
-
-#include "adopterwindow.h"
-
-class QWidget;
-class QMouseEvent;
-class QResizeEvent;
-class TranslucentButton;
-
-/** A full screen window with a restore button. */
-class FullScreenWindow: public AdopterWindow
-{
- Q_OBJECT
-
-public:
- explicit FullScreenWindow(QWidget *parent);
- void showFullScreen();
-
-signals:
- /** Emitted when the restore button is pressed. */
- void restore();
-
-protected:
- void resizeEvent(QResizeEvent *e);
-
-private:
- TranslucentButton *restoreButton;
-};
-
-#endif // FULLSCREENWINDOW_H