X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;ds=sidebyside;f=settingswindow.cpp;h=1bf3b8d2acbdfbed4180b2d721fec8397a2275f4;hb=ab97a63843365b91ec659267d1738edeae7f8964;hp=3407a92f7428c2d6316f312113a0e80bed8fdce3;hpb=826aea4a3e3f4b4361b7592ad824963a529ffefd;p=dorian diff --git a/settingswindow.cpp b/settingswindow.cpp index 3407a92..1bf3b8d 100644 --- a/settingswindow.cpp +++ b/settingswindow.cpp @@ -2,14 +2,25 @@ #include "settingswindow.h" #include "settings.h" +#include "toolbuttonbox.h" +#include "platform.h" +#include "trace.h" #ifdef Q_OS_SYMBIAN -#define DEFAULT_ORIENTATION "portrait" +#include "flickcharm.h" +#endif + +#ifdef Q_OS_SYMBIAN +const char *DEFAULT_ORIENTATION = "portrait"; #else -#define DEFAULT_ORIENTATION "landscape" +const char *DEFAULT_ORIENTATION = "landscape"; #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); @@ -17,10 +28,14 @@ SettingsWindow::SettingsWindow(QWidget *parent): QMainWindow(parent) #endif setWindowTitle("Settings"); + Settings *settings = Settings::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 @@ -31,18 +46,38 @@ SettingsWindow::SettingsWindow(QWidget *parent): QMainWindow(parent) QVBoxLayout *layout = new QVBoxLayout(contents); contents->setLayout(layout); - QLabel *zoomLabel = new QLabel(tr("Zoom level:"), contents); +#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()); + + 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); @@ -50,109 +85,44 @@ 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"), + Platform::icon("style-default")); + box->addButton(SchemeNight, tr("Night"), Platform::icon("style-night")); + box->addButton(SchemeDay, tr("Day"), Platform::icon("style-day")); + box->addButton(SchemeSand, tr("Sand"), Platform::icon("style-sand")); + 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); } +#ifndef Q_OS_SYMBIAN 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); } +#endif // !Q_OS_SYMBIAN - boxLayout->addStretch(); layout->addStretch(); scroller->setWidget(contents); contents->show(); @@ -160,20 +130,41 @@ SettingsWindow::SettingsWindow(QWidget *parent): QMainWindow(parent) setCentralWidget(scroller); +#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)), 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)), +#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); + 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 @@ -218,17 +209,30 @@ void SettingsWindow::onOrientationButtonClicked(int id) #endif // Q_WS_MAEMO_5 } -#ifdef Q_WS_MAEMO_5 +#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN) 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", - (orientationGroup->checkedId() == OrientationLandscape)? + (orientationBox->checkedId() == OrientationLandscape)? "landscape": "portrait"); +#endif // Q_OS_SYMBIAN e->accept(); } -#endif // Q_WS_MAEMO_5 +#endif // Q_WS_MAEMO_5 || Q_OS_SYMBIAN + +void SettingsWindow::onLightsToggled(bool value) +{ + Settings::instance()->setValue("lightson", value); +} + +void SettingsWindow::onGrabVolumeToggled(bool enable) +{ + Settings::instance()->setValue("usevolumekeys", enable); +}