#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);
#endif
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
QVBoxLayout *layout = new QVBoxLayout(contents);
contents->setLayout(layout);
- QLabel *zoomLabel = new QLabel(tr("Zoom level:"), contents);
+#if defined(Q_WS_MAEMO_5)
+ QCheckBox *backlight = new QCheckBox(tr("Keep backlight on"), contents);
+ layout->addWidget(backlight);
+ backlight->setChecked(settings->value("lightson", false).toBool());
+#endif
+
+#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
+ QCheckBox *grabVolume =
+ new QCheckBox(tr("Navigate with volume keys"), contents);
+ layout->addWidget(grabVolume);
+ grabVolume->setChecked(settings->value("usevolumekeys", false).toBool());
+#endif
+
+ 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);
- QSlider *zoomSlider = new QSlider(Qt::Horizontal, contents);
- zoomSlider->setMinimum(50);
- zoomSlider->setMaximum(300);
- zoomSlider->setValue(Settings::instance()->value("zoom").toInt());
+ zoomSlider = new QSlider(Qt::Horizontal, contents);
+ 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();
- QFontComboBox *fontButton = new QFontComboBox(contents);
+ QString family =
+ settings->value("font", platform->defaultFont()).toString();
+ fontButton = new QFontComboBox(contents);
fontButton->setCurrentFont(QFont(family));
fontButton->setEditable(false);
layout->addWidget(fontButton);
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(SchemeDay, tr("Day"),
+ Platform::instance()->icon("style-day"));
+ box->addButton(SchemeNight, tr("Night"),
+ Platform::instance()->icon("style-night"));
+ box->addButton(SchemeSand, tr("Sand"),
+ Platform::instance()->icon("style-sand"));
+ box->addStretch();
+ QString scheme = settings->value("scheme", "day").toString();
if (scheme == "night") {
- nightSchemeButton->toggle();
- }
- else if (scheme == "day") {
- daySchemeButton->toggle();
- }
- else if (scheme == "sand") {
- sandSchemeButton->toggle();
- }
- else {
- defaultSchemeButton->toggle();
- }
-
- QLabel *orientationLabel = new QLabel(tr("Orientation:"), contents);
- layout->addWidget(orientationLabel);
-
- QFrame *orientationBox = new QFrame(this);
- layout->addWidget(orientationBox);
- QHBoxLayout *orientationLayout = new QHBoxLayout(orientationBox);
- orientationLayout->setMargin(0);
- orientationBox->setLayout(orientationLayout);
- QButtonGroup *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();
-
- QString orientation =
- Settings::instance()->value("orientation", DEFAULT_ORIENTATION).toString();
- if (orientation == "portrait") {
- portraitButton->toggle();
- }
- else {
- landscapeButton->toggle();
+ box->toggle(SchemeNight);
+ } else if (scheme == "sand") {
+ box->toggle(SchemeSand);
+ } else {
+ box->toggle(SchemeDay);
}
- boxLayout->addStretch();
layout->addStretch();
scroller->setWidget(contents);
contents->show();
setCentralWidget(scroller);
+#if defined(Q_WS_MAEMO_5)
+ connect(backlight, SIGNAL(toggled(bool)),
+ this, SLOT(onLightsToggled(bool)));
+#endif
+#if defined(Q_WS_MAEMO_5) || defined(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 &)),
this, SLOT(onCurrentFontChanged(const QFont &)));
- connect(group, SIGNAL(buttonClicked(int)),
+ connect(box, SIGNAL(buttonClicked(int)),
this, SLOT(onSchemeButtonClicked(int)));
- connect(orientationGroup, 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)
{
- Settings::instance()->setValue("zoom", 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)
+ Settings::instance()->setValue("zoom", zoomSlider->value());
+#endif
}
void SettingsWindow::onCurrentFontChanged(const QFont &font)
{
+#if !defined(Q_WS_MAEMO_5) && !defined(Q_OS_SYMBIAN)
Settings::instance()->setValue("font", font.family());
+#else
+ Q_UNUSED(font);
+#endif
}
void SettingsWindow::onSchemeButtonClicked(int id)
{
QString scheme;
switch (id) {
- case SchemeDay: scheme = "day"; break;
case SchemeNight: scheme = "night"; break;
case SchemeSand: scheme = "sand"; break;
- default: scheme = "default"; break;
+ default: scheme = "day"; break;
}
Settings::instance()->setValue("scheme", scheme);
}
{
QString orientation;
switch (id) {
- case OrientationLandscape: orientation = "landscape"; break;
- default: orientation = "portrait"; break;
+ case OrientationLandscape:
+ orientation = "landscape";
+ break;
+ default:
+ orientation = "portrait";
+ break;
}
Settings::instance()->setValue("orientation", orientation);
}
+
+void SettingsWindow::closeEvent(QCloseEvent *e)
+{
+ TRACE;
+ Settings *settings = Settings::instance();
+ settings->setValue("zoom", zoomSlider->value());
+ settings->setValue("font", fontButton->currentFont().family());
+ e->accept();
+}
+
+void SettingsWindow::onLightsToggled(bool value)
+{
+ Settings::instance()->setValue("lightson", value);
+}
+
+void SettingsWindow::onGrabVolumeToggled(bool enable)
+{
+ Settings::instance()->setValue("usevolumekeys", enable);
+}