Project Gutenberg downloads work end-to-end.
[dorian] / settingswindow.cpp
index 247cffc..4bece61 100644 (file)
@@ -5,11 +5,15 @@
 #include "toolbuttonbox.h"
 
 #ifdef Q_OS_SYMBIAN
-#define DEFAULT_ORIENTATION "portrait"
+const char *DEFAULT_ORIENTATION = "portrait";
 #else
-#define DEFAULT_ORIENTATION "landscape"
+const char *DEFAULT_ORIENTATION = "landscape";
 #endif
 
+const int ZOOM_MIN = 75;
+const int ZOOM_MAX = 250;
+const int ZOOM_STEP = 25;
+
 SettingsWindow::SettingsWindow(QWidget *parent):  QMainWindow(parent)
 {
 #ifdef Q_WS_MAEMO_5
@@ -37,23 +41,34 @@ SettingsWindow::SettingsWindow(QWidget *parent):  QMainWindow(parent)
     layout->addWidget(backlight);
     backlight->setChecked(settings->value("lightson", false).toBool());
 
+#ifndef Q_OS_SYMBIAN
     QCheckBox *grabVolume =
             new QCheckBox(tr("Navigate with volume keys"), contents);
     layout->addWidget(grabVolume);
     grabVolume->setChecked(settings->value("usevolumekeys", false).toBool());
+#endif
 
-    QLabel *zoomLabel = new QLabel(tr("Zoom level:"), contents);
+    int zoom = Settings::instance()->value("zoom").toInt();
+    if (zoom < ZOOM_MIN) {
+        zoom = ZOOM_MIN;
+    } else if (zoom > ZOOM_MAX) {
+        zoom = ZOOM_MAX;
+    }
+    zoomLabel = new QLabel(tr("Zoom level: %1%").arg(zoom), contents);
     layout->addWidget(zoomLabel);
     zoomSlider = new QSlider(Qt::Horizontal, contents);
-    zoomSlider->setMinimum(50);
-    zoomSlider->setMaximum(300);
-    zoomSlider->setValue(Settings::instance()->value("zoom").toInt());
+    zoomSlider->setMinimum(ZOOM_MIN);
+    zoomSlider->setMaximum(ZOOM_MAX);
+    zoomSlider->setSingleStep(ZOOM_STEP);
+    zoomSlider->setPageStep(ZOOM_STEP);
+    zoomSlider->setValue(zoom);
     layout->addWidget(zoomSlider);
 
     QLabel *fontLabel = new QLabel(tr("Font:"), contents);
     layout->addWidget(fontLabel);
     QString defaultFamily = fontLabel->fontInfo().family();
-    QString family = Settings::instance()->value("font", defaultFamily).toString();
+    QString family =
+            Settings::instance()->value("font", defaultFamily).toString();
     fontButton = new QFontComboBox(contents);
     fontButton->setCurrentFont(QFont(family));
     fontButton->setEditable(false);
@@ -103,9 +118,12 @@ SettingsWindow::SettingsWindow(QWidget *parent):  QMainWindow(parent)
 
     setCentralWidget(scroller);
 
-    connect(backlight, SIGNAL(toggled(bool)), this, SLOT(onLightsToggled(bool)));
+    connect(backlight, SIGNAL(toggled(bool)),
+            this, SLOT(onLightsToggled(bool)));
+#ifndef Q_OS_SYMBIAN
     connect(grabVolume, SIGNAL(toggled(bool)),
             this, SLOT(onGrabVolumeToggled(bool)));
+#endif
     connect(zoomSlider, SIGNAL(valueChanged(int)),
             this, SLOT(onSliderValueChanged(int)));
     connect(fontButton, SIGNAL(currentFontChanged(const QFont &)),
@@ -114,12 +132,25 @@ SettingsWindow::SettingsWindow(QWidget *parent):  QMainWindow(parent)
             this, SLOT(onSchemeButtonClicked(int)));
     connect(orientationBox, SIGNAL(buttonClicked(int)),
             this, SLOT(onOrientationButtonClicked(int)));
+
+#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);
+#endif
 }
 
 void SettingsWindow::onSliderValueChanged(int value)
 {
-#ifdef Q_WS_MAEMO_5 // Re-scaling the book view is too much for the N900
-    Q_UNUSED(value);
+    int step = zoomSlider->singleStep();
+    if (value % step) {
+        zoomSlider->setValue((value + step / 2) / step * step);
+        return;
+    }
+    zoomLabel->setText(tr("Zoom level: %1%").arg(value));
+#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
+    // Constant re-scaling of the book view is too much for mobiles
 #else
     Settings::instance()->setValue("zoom", value);
 #endif // Q_WS_MAEMO_5