bool BookView::eventFilter(QObject *o, QEvent *e)
{
+#if 0
if (e->type() != QEvent::Paint && e->type() != QEvent::MouseMove) {
if (e->type() == QEvent::Resize) {
Trace::trace(QString("BookView::eventFilter QEvent::Resize to %1").
arg(Trace::event(e->type())));
}
}
-
+#endif
switch (e->type()) {
case QEvent::MouseButtonPress:
emit suppressedMouseButtonPress();
model/bookfinder.cpp \
widgets/listwindow.cpp \
foldersdialog.cpp \
- widgets/progress.cpp
+ widgets/progress.cpp \
+ widgets/bookwindow.cpp
HEADERS += \
mainwindow.h \
model/bookfinder.h \
widgets/listwindow.h \
foldersdialog.h \
- widgets/progress.h
+ widgets/progress.h \
+ widgets/bookwindow.h
RESOURCES += \
dorian.qrc
const int PROGRESS_HEIGHT = 17;
MainWindow::MainWindow(QWidget *parent):
- QMainWindow(parent), view(0), preventBlankingTimer(-1)
+ BookWindow(parent), view(0), preventBlankingTimer(-1)
{
Trace t("MainWindow::MainWindow");
#ifdef Q_WS_MAEMO_5
setAttribute(Qt::WA_Maemo5StackedWindow, true);
- grabZoomKeys();
#endif
setWindowTitle("Dorian");
}
}
- // Handle settings changes
- Settings *settings = Settings::instance();
- connect(settings, SIGNAL(valueChanged(const QString &)),
- this, SLOT(onSettingsChanged(const QString &)));
- settings->setValue("orientation", settings->value("orientation"));
- settings->setValue("lightson", settings->value("lightson"));
-
- // Handle loading chapters
- connect(view, SIGNAL(chapterLoadStart(int)),
- this, SLOT(onChapterLoadStart()));
- connect(view, SIGNAL(chapterLoadEnd(int)),
- this, SLOT(onChapterLoadEnd(int)));
+ // Handle loading book parts
+ connect(view, SIGNAL(partLoadStart(int)), this, SLOT(onPartLoadStart()));
+ connect(view, SIGNAL(partLoadEnd(int)), this, SLOT(onPartLoadEnd(int)));
// Handle progress
connect(view, SIGNAL(progress(qreal)), progress, SLOT(setProgress(qreal)));
bookFinder->moveToThread(&bookFinderThread);
bookFinderThread.start();
+ // Handle settings changes
+ Settings *settings = Settings::instance();
+ connect(settings, SIGNAL(valueChanged(const QString &)),
+ this, SLOT(onSettingsChanged(const QString &)));
+ settings->setValue("orientation", settings->value("orientation"));
+ settings->setValue("lightson", settings->value("lightson"));
+ settings->setValue("usevolumekeys", settings->value("usevolumekeys"));
+
#ifdef DORIAN_TEST_MODEL
(void)new ModelTest(Library::instance(), this);
#endif
{
Trace t("MainWindow::showRegular");
fullScreenWindow->hide();
- fullScreenWindow->leaveChild();
- view->setParent(centralWidget());
- progress->setParent(centralWidget());
+ fullScreenWindow->leaveChildren();
progress->setGeometry(0, 0, geometry().width(), PROGRESS_HEIGHT);
- centralWidget()->layout()->addWidget(view);
+ QList<QWidget *> otherChildren;
+ otherChildren.append(progress);
+ takeChildren(view, otherChildren);
progress->flash();
}
void MainWindow::showBig()
{
Trace t("MainWindow::showBig");
- centralWidget()->layout()->removeWidget(view);
- progress->setParent(fullScreenWindow);
+ leaveChildren();
+ QList<QWidget *> otherChildren;
+ otherChildren.append(progress);
progress->setGeometry(0, 0, QApplication::desktop()->screenGeometry().width(),
PROGRESS_HEIGHT);
- fullScreenWindow->takeChild(view);
+ fullScreenWindow->takeChildren(view, otherChildren);
fullScreenWindow->showFullScreen();
progress->flash();
}
if (enable) {
preventBlankingTimer = startTimer(29 * 1000);
}
+ } else if (key == "usevolumekeys") {
+ bool value = Settings::instance()->value(key).toBool();
+ Trace::trace(QString("MainWindow::onSettingsChanged: usevolumekeys %1").
+ arg(value));
+ grabZoomKeys(value);
+ fullScreenWindow->grabZoomKeys(value);
}
#else
Q_UNUSED(key);
progress->setGeometry(QRect(0, 0, e->size().width(), PROGRESS_HEIGHT));
QMainWindow::resizeEvent(e);
}
-
-void MainWindow::grabZoomKeys()
-{
-#ifdef Q_WS_MAEMO_5
- if (!winId()) {
- qCritical() << "Can't grab keys unless we have a window id";
- return;
- }
- unsigned long val = 1;
- 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);
-#endif // Q_WS_MAEMO_5
-}
#define MAINWINDOW_H
#include <QtGui>
+
+#include "bookwindow.h"
#include "bookfinder.h"
class QString;
class FullScreenWindow;
class Progress;
-class MainWindow: public QMainWindow
+class MainWindow: public BookWindow
{
Q_OBJECT
void setCurrentBook(const QModelIndex ¤t);
QAction *addToolBarAction(const QObject *receiver, const char *member,
const QString &name);
- void grabZoomKeys();
BookView *view;
QAction *settingsAction;
QAction *libraryAction;
layout->addWidget(backlight);
backlight->setChecked(settings->value("lightson", false).toBool());
+ QCheckBox *grabVolume =
+ new QCheckBox(tr("Navigate with volume keys"), contents);
+ layout->addWidget(grabVolume);
+ grabVolume->setChecked(settings->value("usevolumekeys", false).toBool());
+
QLabel *zoomLabel = new QLabel(tr("Zoom level:"), contents);
layout->addWidget(zoomLabel);
zoomSlider = new QSlider(Qt::Horizontal, contents);
setCentralWidget(scroller);
connect(backlight, SIGNAL(toggled(bool)), this, SLOT(onLightsToggled(bool)));
+ connect(grabVolume, SIGNAL(toggled(bool)),
+ this, SLOT(onGrabVolumeToggled(bool)));
connect(zoomSlider, SIGNAL(valueChanged(int)),
this, SLOT(onSliderValueChanged(int)));
connect(fontButton, SIGNAL(currentFontChanged(const QFont &)),
{
Settings::instance()->setValue("lightson", value);
}
+
+void SettingsWindow::onGrabVolumeToggled(bool enable)
+{
+ Settings::instance()->setValue("usevolumekeys", enable);
+}
void onSchemeButtonClicked(int id);
void onOrientationButtonClicked(int id);
void onLightsToggled(bool enable);
+ void onGrabVolumeToggled(bool enable);
protected:
#ifdef Q_WS_MAEMO_5
--- /dev/null
+#include <QtGui>
+
+#ifdef Q_WS_MAEMO_5
+# include <QtGui/QX11Info>
+# include <X11/Xlib.h>
+# include <X11/Xatom.h>
+#endif // Q_WS_MAEMO_5
+
+#include "bookwindow.h"
+#include "trace.h"
+
+BookWindow::BookWindow(QWidget *parent):
+ QMainWindow(parent), grabbingZoomKeys(false), mainChild(0)
+{
+#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);
+}
+
+void BookWindow::takeChildren(QWidget *main, const QList<QWidget *> &others)
+{
+ Trace t("BookWindow::takeChildren");
+ leaveChildren();
+ if (main) {
+ mainChild = main;
+ mainChild->setParent(centralWidget());
+ centralWidget()->layout()->addWidget(mainChild);
+ mainChild->show();
+ }
+ foreach (QWidget *child, others) {
+ if (child) {
+ child->setParent(this);
+ }
+ }
+}
+
+void BookWindow::leaveChildren()
+{
+ Trace t("BookWindow::leaveChildren");
+ if (mainChild) {
+ centralWidget()->layout()->removeWidget(mainChild);
+ mainChild = 0;
+ }
+}
+
+void BookWindow::grabZoomKeys(bool grab)
+{
+ Trace t("BookWindow::grabZoomKeys");
+ grabbingZoomKeys = grab;
+ doGrabZoomKeys(grab);
+}
+
+void BookWindow::showEvent(QShowEvent *e)
+{
+ Trace t("BookWindow::showEvent");
+ doGrabZoomKeys(grabbingZoomKeys);
+ QMainWindow::showEvent(e);
+}
+
+void BookWindow::doGrabZoomKeys(bool grab)
+{
+ Trace t("BookWindow::doGrabZoomKeys");
+#ifdef Q_WS_MAEMO_5
+ if (!isVisible()) {
+ t.trace("Not visible - skipping");
+ }
+ if (!winId()) {
+ t.trace("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
+}
--- /dev/null
+#ifndef BOOKWINDOW_H
+#define BOOKWINDOW_H
+
+#include <QMainWindow>
+#include <QList>
+
+class QWidget;
+
+class BookWindow: public QMainWindow
+{
+ Q_OBJECT
+public:
+ explicit BookWindow(QWidget *parent = 0);
+ void grabZoomKeys(bool grab);
+ void takeChildren(QWidget *main, const QList<QWidget *> &others);
+ void leaveChildren();
+
+signals:
+
+public slots:
+
+protected:
+ void showEvent(QShowEvent *e);
+ void doGrabZoomKeys(bool grab);
+ bool grabbingZoomKeys;
+ QWidget *mainChild;
+};
+
+#endif // BOOKWINDOW_H
#include "translucentbutton.h"
#include "trace.h"
-FullScreenWindow::FullScreenWindow(QWidget *parent): QMainWindow(parent), child(0)
+FullScreenWindow::FullScreenWindow(QWidget *parent): BookWindow(parent)
{
Q_ASSERT(parent);
#ifdef Q_WS_MAEMO_5
restoreButton->setGeometry(fullScreenZone());
QMainWindow::resizeEvent(e);
}
-
-void FullScreenWindow::takeChild(QWidget *c)
-{
- leaveChild();
- if (c) {
- child = c;
- child->setParent(centralWidget());
- centralWidget()->layout()->addWidget(child);
- connect(child, SIGNAL(suppressedMouseButtonPress()),
- restoreButton, SLOT(flash()));
- }
-}
-
-void FullScreenWindow::leaveChild()
-{
- if (child) {
- centralWidget()->layout()->removeWidget(child);
- child = 0;
- }
-}
#ifndef FULLSCREENWINDOW_H
#define FULLSCREENWINDOW_H
-#include <QMainWindow>
+#include <QRect>
+#include <QObject>
+#include "bookwindow.h"
+
+class QWidget;
+class QMouseEvent;
+class QResizeEvent;
class TranslucentButton;
/** A full screen window that can adopt a child widget from another window. */
-class FullScreenWindow: public QMainWindow
+class FullScreenWindow: public BookWindow
{
Q_OBJECT
public:
explicit FullScreenWindow(QWidget *parent);
void showFullScreen();
- void takeChild(QWidget *child);
- void leaveChild();
signals:
void restore();
virtual void resizeEvent(QResizeEvent *event);
QRect fullScreenZone() const;
TranslucentButton *restoreButton;
- QWidget *child;
};
#endif // FULLSCREENWINDOW_H