#if 0
if (e->type() != QEvent::Paint && e->type() != QEvent::MouseMove) {
if (e->type() == QEvent::Resize) {
- Trace::debug(QString("BookView::eventFilter QEvent::Resize to %1").
+ Trace::trace(QString("BookView::eventFilter QEvent::Resize to %1").
arg(page()->mainFrame()->contentsSize().height()));
} else {
- Trace::debug(QString("BookView::eventFilter %1").
+ Trace::trace(QString("BookView::eventFilter %1").
arg(Trace::event(e->type())));
}
}
contentsHeight = size.height();
if (decorated) {
if (restorePositionAfterLoad) {
- Trace::debug("BookView::onContentSizeChanged: Time to restore");
+ Trace::trace("BookView::onContentSizeChanged: Time to restore");
restorePositionAfterLoad = false;
goToPosition(positionAfterLoad);
}
int scrollPos = (qreal)contentsHeight * position;
page()->mainFrame()->setScrollPosition(QPoint(0, scrollPos));
// FIXME: update();
- Trace::debug(QString("BookView::goToPosition: To %1 (%2%, height %3)").
+ Trace::trace(QString("BookView::goToPosition: To %1 (%2%, height %3)").
arg(scrollPos).arg(position * 100).arg(contentsHeight));
}
#include "devtools.h"
#include "trace.h"
#include "settings.h"
+#include "toolbuttonbox.h"
DevTools::DevTools(QWidget *parent):
QDialog(parent, Qt::Dialog | Qt::WindowTitleHint |
QLabel *level = new QLabel(tr("Trace level:"), contents);
layout->addWidget(level);
- QFrame *box = new QFrame(this);
+ ToolButtonBox *box = new ToolButtonBox(this);
layout->addWidget(box);
- QHBoxLayout *boxLayout = new QHBoxLayout(box);
- boxLayout->setMargin(0);
- box->setLayout(boxLayout);
- QButtonGroup *group = new QButtonGroup(this);
- group->setExclusive(true);
-
- QToolButton *levelDebug = new QToolButton(box);
- levelDebug->setToolButtonStyle(Qt::ToolButtonTextOnly);
- levelDebug->setText(tr("Debug"));
- levelDebug->setCheckable(true);
- boxLayout->addWidget(levelDebug);
- group->addButton(levelDebug, QtDebugMsg);
-
- QToolButton *levelWarning = new QToolButton(box);
- levelWarning->setToolButtonStyle(Qt::ToolButtonTextOnly);
- levelWarning->setText(tr("Warning"));
- levelWarning->setCheckable(true);
- boxLayout->addWidget(levelWarning);
- group->addButton(levelWarning, QtWarningMsg);
-
- QToolButton *levelCritical = new QToolButton(box);
- levelCritical->setToolButtonStyle(Qt::ToolButtonTextOnly);
- levelCritical->setText(tr("Critical"));
- levelCritical->setCheckable(true);
- boxLayout->addWidget(levelCritical);
- group->addButton(levelCritical, QtCriticalMsg);
-
- QToolButton *levelFatal = new QToolButton(box);
- levelFatal->setToolButtonStyle(Qt::ToolButtonTextOnly);
- levelFatal->setText(tr("Fatal"));
- levelFatal->setCheckable(true);
- boxLayout->addWidget(levelFatal);
- group->addButton(levelFatal, QtFatalMsg);
-
- if (Trace::level == QtFatalMsg) {
- levelFatal->toggle();
- } else if (Trace::level == QtCriticalMsg) {
- levelCritical->toggle();
- } else if (Trace::level == QtWarningMsg) {
- levelWarning->toggle();
- } else {
- levelDebug->toggle();
- }
-
- connect(group, SIGNAL(buttonClicked(int)),
+ box->addButton(QtDebugMsg, tr("Debug"));
+ box->addButton(QtWarningMsg, tr("Warning"));
+ box->addButton(QtCriticalMsg, tr("Critical"));
+ box->addButton(QtFatalMsg, tr("Fatal"));
+ box->toggle(Trace::level);
+ connect(box, SIGNAL(buttonClicked(int)),
this, SLOT(onLevelButtonClicked(int)));
- layout->addWidget(box);
contents->setLayout(layout);
scroller->setWidget(contents);
dialog.cpp \
chaptersdialog.cpp \
fullscreenwindow.cpp \
- trace.cpp
+ trace.cpp \
+ toolbuttonbox.cpp
HEADERS += \
mainwindow.h \
dialog.h \
chaptersdialog.h \
fullscreenwindow.h \
- trace.h
+ trace.h \
+ toolbuttonbox.h
RESOURCES += \
dorian.qrc
# FIXME: Build zlib, too
}
maemo5 {
- QT += maemo5
+ QT += maemo5 dbus
isEmpty(PREFIX) {
PREFIX = /usr
}
#include <QDir>
#include <QApplication>
#include <QFileInfo>
+
#ifdef Q_WS_MAEMO_5
# include <QtMaemo5/QMaemo5InformationBox>
-#endif
+# include <QtDBus>
+# include <mce/mode-names.h>
+# include <mce/dbus-names.h>
+#endif // Q_WS_MAEMO_5
#include "bookview.h"
#include "book.h"
# define ICON_PREFIX ":/icons/"
#endif
-MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), view(0)
+MainWindow::MainWindow(QWidget *parent):
+ QMainWindow(parent), view(0), preventBlankingTimer(-1)
{
#ifdef Q_WS_MAEMO_5
setAttribute(Qt::WA_Maemo5StackedWindow, true);
}
// Handle settings changes
- connect(Settings::instance(), SIGNAL(valueChanged(const QString &)),
+ Settings *settings = Settings::instance();
+ connect(settings, SIGNAL(valueChanged(const QString &)),
this, SLOT(onSettingsChanged(const QString &)));
- Settings::instance()->setValue("orientation",
- Settings::instance()->value("orientation"));
+ settings->setValue("orientation", settings->value("orientation"));
+ settings->setValue("lightson", settings->value("lightson"));
// Handle loading chapters
connect(view, SIGNAL(chapterLoadStart(int)),
void MainWindow::onSettingsChanged(const QString &key)
{
- Trace t("MainWindow::onSettingsChanged");
#ifdef Q_WS_MAEMO_5
if (key == "orientation") {
QString value = Settings::instance()->value(key).toString();
+ Trace::trace(QString("MainWindow::onSettingsChanged: orientation %1").
+ arg(value));
if (value == "portrait") {
setAttribute(Qt::WA_Maemo5LandscapeOrientation, false);
setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
setAttribute(Qt::WA_Maemo5PortraitOrientation, false);
setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
}
-
- // FIXME: Orientation change should re-activate the window but it doesn't.
- // And I have no idea how to force it
-
- // view->restoreLastBookmark();
- // view->setFocus();
- // raise();
-
- // QApplication::setActiveWindow(this);
- // activateWindow();
- // QEvent *enter = new QEvent(QEvent::Enter);
- // QApplication::postEvent(view, enter);
-
- // view->grabKeyboard();
- // showNormal();
-
- // QTestEventList events;
- // events.addMouseClick(Qt::LeftButton);
- // events.simulate(view);
+ } else if (key == "lightson") {
+ bool enable = Settings::instance()->value(key, false).toBool();
+ Trace::trace(QString("MainWindow::onSettingsChanged: lightson: %1").
+ arg(enable));
+ killTimer(preventBlankingTimer);
+ if (enable) {
+ preventBlankingTimer = startTimer(29 * 1000);
+ }
}
#else
Q_UNUSED(key);
{
view->goToBookmark(Book::Bookmark(index, 0));
}
+
+void MainWindow::timerEvent(QTimerEvent *event)
+{
+ if (event->timerId() == preventBlankingTimer) {
+#ifdef Q_WS_MAEMO_5
+ QDBusInterface mce(MCE_SERVICE, MCE_REQUEST_PATH,
+ MCE_REQUEST_IF, QDBusConnection::systemBus());
+ mce.call(MCE_PREVENT_BLANK_REQ);
+#endif // Q_WS_MAEMO_5
+ Trace::trace("MainWindow::timerEvent: Prevent display blanking");
+ }
+}
protected:
virtual void closeEvent(QCloseEvent *event);
+ virtual void timerEvent(QTimerEvent *event);
private:
void setCurrentBook(const QModelIndex ¤t);
DevTools *devTools;
QModelIndex mCurrent;
FullScreenWindow *fullScreenWindow;
+ int preventBlankingTimer;
};
#endif // MAINWINDOW_H
+dorian (0.1.0-1) unstable; urgency=low
+
+ * Add setting to have prevent display blanking
+
+ -- Akos Polster <akos@pipacs.com> Tue, 2 Aug 2010 20:00:00 +0200
+
dorian (0.0.15-1) unstable; urgency=low
* Fix jumping to new chapter
#include "settingswindow.h"
#include "settings.h"
+#include "toolbuttonbox.h"
#ifdef Q_OS_SYMBIAN
#define DEFAULT_ORIENTATION "portrait"
#endif
setWindowTitle("Settings");
+ Settings *settings = Settings::instance();
QScrollArea *scroller = new QScrollArea(this);
#ifdef Q_WS_MAEMO_5
scroller->setProperty("FingerScrollable", true);
QVBoxLayout *layout = new QVBoxLayout(contents);
contents->setLayout(layout);
+ QCheckBox *backlight = new QCheckBox(tr("Keep backlight on"), contents);
+ layout->addWidget(backlight);
+ backlight->setChecked(settings->value("lightson", false).toBool());
+
QLabel *zoomLabel = new QLabel(tr("Zoom level:"), contents);
layout->addWidget(zoomLabel);
zoomSlider = new QSlider(Qt::Horizontal, contents);
QLabel *colorLabel = new QLabel(tr("Color scheme:"), contents);
layout->addWidget(colorLabel);
- QFrame *box = new QFrame(this);
+ ToolButtonBox *box = new ToolButtonBox(this);
layout->addWidget(box);
- QHBoxLayout *boxLayout = new QHBoxLayout(box);
- boxLayout->setMargin(0);
- box->setLayout(boxLayout);
- QButtonGroup *group = new QButtonGroup(this);
-
- QToolButton *defaultSchemeButton = new QToolButton(box);
- defaultSchemeButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
- defaultSchemeButton->setText(tr("Default"));
- defaultSchemeButton->setIconSize(QSize(81, 81));
- defaultSchemeButton->setIcon(QIcon(":/icons/style-default.png"));
- defaultSchemeButton->setCheckable(true);
- boxLayout->addWidget(defaultSchemeButton);
- group->addButton(defaultSchemeButton);
- group->setId(defaultSchemeButton, SchemeDefault);
-
- QToolButton *nightSchemeButton = new QToolButton(box);
- nightSchemeButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
- nightSchemeButton->setText(tr("Night"));
- nightSchemeButton->setCheckable(true);
- nightSchemeButton->setIconSize(QSize(81, 81));
- nightSchemeButton->setIcon(QIcon(":/icons/style-night.png"));
- boxLayout->addWidget(nightSchemeButton);
- group->addButton(nightSchemeButton);
- group->setId(nightSchemeButton, SchemeNight);
-
- QToolButton *daySchemeButton = new QToolButton(box);
- daySchemeButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
- daySchemeButton->setText(tr("Day"));
- daySchemeButton->setCheckable(true);
- daySchemeButton->setIconSize(QSize(81, 81));
- daySchemeButton->setIcon(QIcon(":/icons/style-day.png"));
- boxLayout->addWidget(daySchemeButton);
- group->addButton(daySchemeButton);
- group->setId(daySchemeButton, SchemeDay);
-
- QToolButton *sandSchemeButton = new QToolButton(box);
- sandSchemeButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
- sandSchemeButton->setText(tr("Sand"));
- sandSchemeButton->setCheckable(true);
- sandSchemeButton->setIconSize(QSize(81, 81));
- sandSchemeButton->setIcon(QIcon(":/icons/style-sand.png"));
- boxLayout->addWidget(sandSchemeButton);
- group->addButton(sandSchemeButton);
- group->setId(sandSchemeButton, SchemeSand);
-
- QString scheme = Settings::instance()->value("scheme", "default").toString();
+ box->addButton(SchemeDefault, tr("Default"), ":/icons/style-default.png");
+ box->addButton(SchemeNight, tr("Night"), ":/icons/style-night.png");
+ box->addButton(SchemeDay, tr("Day"), ":/icons/style-day.png");
+ box->addButton(SchemeSand, tr("Sand"), ":/icons/style-sand.png");
+ box->addStretch();
+ QString scheme = settings->value("scheme", "default").toString();
if (scheme == "night") {
- nightSchemeButton->toggle();
- }
- else if (scheme == "day") {
- daySchemeButton->toggle();
- }
- else if (scheme == "sand") {
- sandSchemeButton->toggle();
- }
- else {
- defaultSchemeButton->toggle();
+ box->toggle(SchemeNight);
+ } else if (scheme == "day") {
+ box->toggle(SchemeDay);
+ } else if (scheme == "sand") {
+ box->toggle(SchemeSand);
+ } else {
+ box->toggle(SchemeDefault);
}
QLabel *orientationLabel = new QLabel(tr("Orientation:"), contents);
layout->addWidget(orientationLabel);
-
- QFrame *orientationBox = new QFrame(this);
+ orientationBox = new ToolButtonBox(this);
layout->addWidget(orientationBox);
- QHBoxLayout *orientationLayout = new QHBoxLayout(orientationBox);
- orientationLayout->setMargin(0);
- orientationBox->setLayout(orientationLayout);
- orientationGroup = new QButtonGroup(this);
-
- QToolButton *portraitButton = new QToolButton(box);
- portraitButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
- portraitButton->setText(tr("Portrait"));
- portraitButton->setIconSize(QSize(81, 81));
- portraitButton->setIcon(QIcon(":/icons/settings-portrait.png"));
- portraitButton->setCheckable(true);
- orientationLayout->addWidget(portraitButton);
- orientationGroup->addButton(portraitButton);
- orientationGroup->setId(portraitButton, OrientationPortrait);
-
- QToolButton *landscapeButton = new QToolButton(box);
- landscapeButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
- landscapeButton->setText(tr("Landscape"));
- landscapeButton->setIconSize(QSize(81, 81));
- landscapeButton->setIcon(QIcon(":/icons/settings-landscape.png"));
- landscapeButton->setCheckable(true);
- orientationLayout->addWidget(landscapeButton);
- orientationGroup->addButton(landscapeButton);
- orientationGroup->setId(landscapeButton, OrientationLandscape);
-
- orientationLayout->addStretch();
-
+ orientationBox->addButton(OrientationPortrait, tr("Portrait"),
+ ":/icons/settings-portrait.png");
+ orientationBox->addButton(OrientationLandscape, tr("Landscape"),
+ ":/icons/settings-landscape.png");
+ orientationBox->addStretch();
QString orientation =
- Settings::instance()->value("orientation", DEFAULT_ORIENTATION).toString();
+ settings->value("orientation", DEFAULT_ORIENTATION).toString();
if (orientation == "portrait") {
- portraitButton->toggle();
- }
- else {
- landscapeButton->toggle();
+ orientationBox->toggle(OrientationPortrait);
+ } else {
+ orientationBox->toggle(OrientationLandscape);
}
- boxLayout->addStretch();
layout->addStretch();
scroller->setWidget(contents);
contents->show();
setCentralWidget(scroller);
+ connect(backlight, SIGNAL(toggled(bool)), this, SLOT(onLightsToggled(bool)));
connect(zoomSlider, SIGNAL(valueChanged(int)),
this, SLOT(onSliderValueChanged(int)));
connect(fontButton, SIGNAL(currentFontChanged(const QFont &)),
this, SLOT(onCurrentFontChanged(const QFont &)));
- connect(group, SIGNAL(buttonClicked(int)),
+ connect(box, SIGNAL(buttonClicked(int)),
this, SLOT(onSchemeButtonClicked(int)));
- connect(orientationGroup, SIGNAL(buttonClicked(int)),
+ connect(orientationBox, SIGNAL(buttonClicked(int)),
this, SLOT(onOrientationButtonClicked(int)));
}
settings->setValue("zoom", zoomSlider->value());
settings->setValue("font", fontButton->currentFont().family());
settings->setValue("orientation",
- (orientationGroup->checkedId() == OrientationLandscape)?
+ (orientationBox->checkedId() == OrientationLandscape)?
"landscape": "portrait");
e->accept();
}
#endif // Q_WS_MAEMO_5
+
+void SettingsWindow::onLightsToggled(bool value)
+{
+ Settings::instance()->setValue("lightson", value);
+}
class QFont;
class QSlider;
class QFontComboBox;
-class QButtonGroup;
+class ToolButtonBox;
class SettingsWindow: public QMainWindow
{
void onCurrentFontChanged(const QFont &);
void onSchemeButtonClicked(int id);
void onOrientationButtonClicked(int id);
+ void onLightsToggled(bool enable);
protected:
#ifdef Q_WS_MAEMO_5
private:
QSlider *zoomSlider;
QFontComboBox *fontButton;
- QButtonGroup *orientationGroup;
+ ToolButtonBox *orientationBox;
};
#endif // SETTINGSWINDOW_H
--- /dev/null
+#include <QtGui>
+
+#include "toolbuttonbox.h"
+
+ToolButtonBox::ToolButtonBox(QWidget *parent): QFrame(parent)
+{
+ QHBoxLayout *layout = new QHBoxLayout(this);
+ layout->setMargin(0);
+ setLayout(layout);
+ group = new QButtonGroup(this);
+ group->setExclusive(true);
+ connect(group, SIGNAL(buttonClicked(int)), this, SIGNAL(buttonClicked(int)));
+}
+
+void ToolButtonBox::addButton(int id, const QString &title, const QString &icon)
+{
+ QToolButton *button = new QToolButton(this);
+ if (icon == "") {
+ button->setToolButtonStyle(Qt::ToolButtonTextOnly);
+ } else {
+ button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
+ button->setIconSize(QSize(81, 81));
+ button->setIcon(QIcon(icon));
+ }
+ button->setText(title);
+ button->setCheckable(true);
+ layout()->addWidget(button);
+ group->addButton(button, id);
+}
+
+void ToolButtonBox::addStretch()
+{
+ qobject_cast<QHBoxLayout *>(layout())->addStretch();
+}
+
+void ToolButtonBox::toggle(int id)
+{
+ group->button(id)->toggle();
+}
+
+int ToolButtonBox::checkedId() const
+{
+ return group->checkedId();
+}
--- /dev/null
+#ifndef TOOLBUTTONBOX_H
+#define TOOLBUTTONBOX_H
+
+#include <QFrame>
+
+class QString;
+class QButtonGroup;
+
+class ToolButtonBox: public QFrame
+{
+ Q_OBJECT
+
+public:
+ explicit ToolButtonBox(QWidget *parent = 0);
+ void addButton(int id, const QString &title, const QString &icon = "");
+ void addStretch();
+ void toggle(int id);
+ int checkedId() const;
+
+signals:
+ void buttonClicked(int id);
+
+public slots:
+
+protected:
+ QButtonGroup *group;
+};
+
+#endif // TOOLBUTTONBOX_H
qDebug() << prefix() + ">" + name;
indent++;
}
+
~Trace() {
if (--indent < 0) {
indent = 0;
}
qDebug() << prefix() + "<" + name;
}
- void trace(const QString &s) const {
- qDebug() << prefix() + name + ": " + s;
- }
- static void debug(const QString &s) {
- qDebug() << prefix() + s;
+ static void trace(const QString &s) {
+ qDebug() << prefix() + s;
}
static QString event(QEvent::Type t) {