X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=settingswindow.cpp;h=524dc7dfb10be509a8a129f044187e9ab34d53a0;hb=3c911546d4367fa1da0a21c70872159a1044a170;hp=247cffcc7f90471fa7c9f6bc802aa818c91e2739;hpb=67043ec8b79ebd87b72d82d27397097371ec38b5;p=dorian diff --git a/settingswindow.cpp b/settingswindow.cpp index 247cffc..524dc7d 100644 --- a/settingswindow.cpp +++ b/settingswindow.cpp @@ -3,14 +3,18 @@ #include "settingswindow.h" #include "settings.h" #include "toolbuttonbox.h" +#include "platform.h" +#include "trace.h" #ifdef Q_OS_SYMBIAN -#define DEFAULT_ORIENTATION "portrait" -#else -#define DEFAULT_ORIENTATION "landscape" +# include "flickcharm.h" #endif -SettingsWindow::SettingsWindow(QWidget *parent): QMainWindow(parent) +const int ZOOM_MIN = 75; +const int ZOOM_MAX = 250; +const int ZOOM_STEP = 25; + +SettingsWindow::SettingsWindow(QWidget *parent): AdopterWindow(parent) { #ifdef Q_WS_MAEMO_5 setAttribute(Qt::WA_Maemo5StackedWindow, true); @@ -19,10 +23,15 @@ SettingsWindow::SettingsWindow(QWidget *parent): QMainWindow(parent) setWindowTitle("Settings"); Settings *settings = Settings::instance(); + Platform *platform = Platform::instance(); + QScrollArea *scroller = new QScrollArea(this); -#ifdef Q_WS_MAEMO_5 +#if defined(Q_WS_MAEMO_5) scroller->setProperty("FingerScrollable", true); scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); +#elif defined(Q_OS_SYMBIAN) + FlickCharm *charm = new FlickCharm(this); + charm->activateOn(scroller); #else scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); #endif @@ -33,27 +42,36 @@ SettingsWindow::SettingsWindow(QWidget *parent): QMainWindow(parent) QVBoxLayout *layout = new QVBoxLayout(contents); contents->setLayout(layout); +#ifndef Q_OS_SYMBIAN QCheckBox *backlight = new QCheckBox(tr("Keep backlight on"), contents); layout->addWidget(backlight); backlight->setChecked(settings->value("lightson", false).toBool()); +#endif 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); + int zoom = settings->value("zoom", platform->defaultZoom()).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->value("font", platform->defaultFont()).toString(); fontButton = new QFontComboBox(contents); fontButton->setCurrentFont(QFont(family)); fontButton->setEditable(false); @@ -63,10 +81,13 @@ SettingsWindow::SettingsWindow(QWidget *parent): QMainWindow(parent) layout->addWidget(colorLabel); ToolButtonBox *box = new ToolButtonBox(this); layout->addWidget(box); - 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->addButton(SchemeDefault, tr("Default"), + Platform::instance()->icon("style-default")); + box->addButton(SchemeNight, tr("Night"), + Platform::instance()->icon("style-night")); + box->addButton(SchemeDay, tr("Day"), Platform::instance()->icon("style-day")); + box->addButton(SchemeSand, tr("Sand"), + Platform::instance()->icon("style-sand")); box->addStretch(); QString scheme = settings->value("scheme", "default").toString(); if (scheme == "night") { @@ -79,6 +100,7 @@ SettingsWindow::SettingsWindow(QWidget *parent): QMainWindow(parent) box->toggle(SchemeDefault); } +#ifndef Q_OS_SYMBIAN QLabel *orientationLabel = new QLabel(tr("Orientation:"), contents); layout->addWidget(orientationLabel); orientationBox = new ToolButtonBox(this); @@ -89,12 +111,13 @@ SettingsWindow::SettingsWindow(QWidget *parent): QMainWindow(parent) ":/icons/settings-landscape.png"); orientationBox->addStretch(); QString orientation = - settings->value("orientation", DEFAULT_ORIENTATION).toString(); + settings->value("orientation", platform->defaultOrientation()).toString(); if (orientation == "portrait") { orientationBox->toggle(OrientationPortrait); } else { orientationBox->toggle(OrientationLandscape); } +#endif // !Q_OS_SYMBIAN layout->addStretch(); scroller->setWidget(contents); @@ -103,7 +126,10 @@ SettingsWindow::SettingsWindow(QWidget *parent): QMainWindow(parent) setCentralWidget(scroller); - connect(backlight, SIGNAL(toggled(bool)), this, SLOT(onLightsToggled(bool))); +#ifndef Q_OS_SYMBIAN + connect(backlight, SIGNAL(toggled(bool)), + this, SLOT(onLightsToggled(bool))); +#endif connect(grabVolume, SIGNAL(toggled(bool)), this, SLOT(onGrabVolumeToggled(bool))); connect(zoomSlider, SIGNAL(valueChanged(int)), @@ -112,26 +138,32 @@ SettingsWindow::SettingsWindow(QWidget *parent): QMainWindow(parent) this, SLOT(onCurrentFontChanged(const QFont &))); connect(box, SIGNAL(buttonClicked(int)), this, SLOT(onSchemeButtonClicked(int))); +#ifndef Q_OS_SYMBIAN connect(orientationBox, SIGNAL(buttonClicked(int)), this, SLOT(onOrientationButtonClicked(int))); +#endif + +#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); -#else - Settings::instance()->setValue("zoom", value); -#endif // Q_WS_MAEMO_5 + int step = zoomSlider->singleStep(); + if (value % step) { + zoomSlider->setValue((value + step / 2) / step * step); + return; + } + zoomLabel->setText(tr("Zoom level: %1%").arg(value)); } void SettingsWindow::onCurrentFontChanged(const QFont &font) { -#ifdef Q_WS_MAEMO_5 Q_UNUSED(font); -#else - Settings::instance()->setValue("font", font.family()); -#endif // Q_WS_MAEMO_5 } void SettingsWindow::onSchemeButtonClicked(int id) @@ -164,21 +196,20 @@ void SettingsWindow::onOrientationButtonClicked(int id) #endif // Q_WS_MAEMO_5 } -#ifdef Q_WS_MAEMO_5 - void SettingsWindow::closeEvent(QCloseEvent *e) { + TRACE; Settings *settings = Settings::instance(); settings->setValue("zoom", zoomSlider->value()); settings->setValue("font", fontButton->currentFont().family()); +#ifndef Q_OS_SYMBIAN settings->setValue("orientation", (orientationBox->checkedId() == OrientationLandscape)? "landscape": "portrait"); +#endif // Q_OS_SYMBIAN e->accept(); } -#endif // Q_WS_MAEMO_5 - void SettingsWindow::onLightsToggled(bool value) { Settings::instance()->setValue("lightson", value);