Add new widget ToolButtonBox. Add setting to prevent display blanking.
authorAkos Polster <polster@marzipan.pipacs.com>
Mon, 2 Aug 2010 17:03:50 +0000 (19:03 +0200)
committerAkos Polster <polster@marzipan.pipacs.com>
Mon, 2 Aug 2010 17:03:50 +0000 (19:03 +0200)
12 files changed:
bookview.cpp
devtools.cpp
dorian.pro
mainwindow.cpp
mainwindow.h
pkg/changelog
pkg/version.txt
settingswindow.cpp
settingswindow.h
toolbuttonbox.cpp [new file with mode: 0644]
toolbuttonbox.h [new file with mode: 0644]
trace.h

index ae1cfe7..fe43e02 100644 (file)
@@ -328,10 +328,10 @@ bool BookView::eventFilter(QObject *o, QEvent *e)
 #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())));
         }
     }
@@ -369,7 +369,7 @@ void BookView::onContentsSizeChanged(const QSize &size)
     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);
         }
@@ -398,6 +398,6 @@ void BookView::goToPosition(qreal position)
     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));
 }
index 110a003..84fa2ca 100644 (file)
@@ -4,6 +4,7 @@
 #include "devtools.h"
 #include "trace.h"
 #include "settings.h"
+#include "toolbuttonbox.h"
 
 DevTools::DevTools(QWidget *parent):
         QDialog(parent, Qt::Dialog | Qt::WindowTitleHint |
@@ -31,55 +32,15 @@ DevTools::DevTools(QWidget *parent):
     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);
index 5e71141..0d8d62f 100644 (file)
@@ -21,7 +21,8 @@ SOURCES += \
     dialog.cpp \
     chaptersdialog.cpp \
     fullscreenwindow.cpp \
-    trace.cpp
+    trace.cpp \
+    toolbuttonbox.cpp
 
 HEADERS += \
     mainwindow.h \
@@ -47,7 +48,8 @@ HEADERS += \
     dialog.h \
     chaptersdialog.h \
     fullscreenwindow.h \
-    trace.h
+    trace.h \
+    toolbuttonbox.h
 
 RESOURCES += \
     dorian.qrc
@@ -85,7 +87,7 @@ windows {
     # FIXME: Build zlib, too
 }
 maemo5 {
-    QT += maemo5
+    QT += maemo5 dbus
     isEmpty(PREFIX) {
         PREFIX = /usr
     }
index df4729d..5f4dab2 100755 (executable)
@@ -3,9 +3,13 @@
 #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"
@@ -31,7 +35,8 @@
 #   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);
@@ -118,10 +123,11 @@ MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), view(0)
     }
 
     // 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)),
@@ -225,10 +231,11 @@ void MainWindow::closeEvent(QCloseEvent *event)
 
 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);
@@ -237,25 +244,14 @@ void MainWindow::onSettingsChanged(const QString &key)
             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);
@@ -324,3 +320,15 @@ void MainWindow::onGoToChapter(int index)
 {
     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");
+    }
+}
index a8a2928..eef5444 100755 (executable)
@@ -37,6 +37,7 @@ public slots:
 
 protected:
     virtual void closeEvent(QCloseEvent *event);
+    virtual void timerEvent(QTimerEvent *event);
 
 private:
     void setCurrentBook(const QModelIndex &current);
@@ -59,6 +60,7 @@ private:
     DevTools *devTools;
     QModelIndex mCurrent;
     FullScreenWindow *fullScreenWindow;
+    int preventBlankingTimer;
 };
 
 #endif // MAINWINDOW_H
index 3af2d06..ef4b733 100644 (file)
@@ -1,3 +1,9 @@
+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
index ceddfb2..6e8bf73 100644 (file)
@@ -1 +1 @@
-0.0.15
+0.1.0
index 3407a92..2da1cd5 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "settingswindow.h"
 #include "settings.h"
+#include "toolbuttonbox.h"
 
 #ifdef Q_OS_SYMBIAN
 #define DEFAULT_ORIENTATION "portrait"
@@ -17,6 +18,7 @@ SettingsWindow::SettingsWindow(QWidget *parent):  QMainWindow(parent)
 #endif
     setWindowTitle("Settings");
 
+    Settings *settings = Settings::instance();
     QScrollArea *scroller = new QScrollArea(this);
 #ifdef Q_WS_MAEMO_5
     scroller->setProperty("FingerScrollable", true);
@@ -31,6 +33,10 @@ SettingsWindow::SettingsWindow(QWidget *parent):  QMainWindow(parent)
     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);
@@ -50,109 +56,41 @@ SettingsWindow::SettingsWindow(QWidget *parent):  QMainWindow(parent)
 
     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();
@@ -160,13 +98,14 @@ SettingsWindow::SettingsWindow(QWidget *parent):  QMainWindow(parent)
 
     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)));
 }
 
@@ -226,9 +165,14 @@ void SettingsWindow::closeEvent(QCloseEvent *e)
     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);
+}
index f120701..55e40b7 100644 (file)
@@ -8,7 +8,7 @@ class QFontComboBox;
 class QFont;
 class QSlider;
 class QFontComboBox;
-class QButtonGroup;
+class ToolButtonBox;
 
 class SettingsWindow: public QMainWindow
 {
@@ -26,6 +26,7 @@ public slots:
     void onCurrentFontChanged(const QFont &);
     void onSchemeButtonClicked(int id);
     void onOrientationButtonClicked(int id);
+    void onLightsToggled(bool enable);
 
 protected:
 #ifdef Q_WS_MAEMO_5
@@ -35,7 +36,7 @@ protected:
 private:
     QSlider *zoomSlider;
     QFontComboBox *fontButton;
-    QButtonGroup *orientationGroup;
+    ToolButtonBox *orientationBox;
 };
 
 #endif // SETTINGSWINDOW_H
diff --git a/toolbuttonbox.cpp b/toolbuttonbox.cpp
new file mode 100644 (file)
index 0000000..7884187
--- /dev/null
@@ -0,0 +1,44 @@
+#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();
+}
diff --git a/toolbuttonbox.h b/toolbuttonbox.h
new file mode 100644 (file)
index 0000000..17ff60a
--- /dev/null
@@ -0,0 +1,29 @@
+#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
diff --git a/trace.h b/trace.h
index ea41852..9c2fd2e 100644 (file)
--- a/trace.h
+++ b/trace.h
@@ -13,18 +13,16 @@ public:
         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) {