3 #include "settingswindow.h"
5 #include "toolbuttonbox.h"
10 # include "flickcharm.h"
13 const int ZOOM_MIN = 75;
14 const int ZOOM_MAX = 250;
15 const int ZOOM_STEP = 25;
17 SettingsWindow::SettingsWindow(QWidget *parent): AdopterWindow(parent)
20 setAttribute(Qt::WA_Maemo5StackedWindow, true);
21 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
23 setWindowTitle("Settings");
25 Settings *settings = Settings::instance();
26 Platform *platform = Platform::instance();
28 QScrollArea *scroller = new QScrollArea(this);
29 #if defined(Q_WS_MAEMO_5)
30 scroller->setProperty("FingerScrollable", true);
31 scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
32 #elif defined(Q_OS_SYMBIAN)
33 FlickCharm *charm = new FlickCharm(this);
34 charm->activateOn(scroller);
36 scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
38 scroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
39 scroller->setFrameStyle(QFrame::NoFrame);
41 QWidget *contents = new QWidget(scroller);
42 QVBoxLayout *layout = new QVBoxLayout(contents);
43 contents->setLayout(layout);
45 #if defined(Q_WS_MAEMO_5)
46 QCheckBox *backlight = new QCheckBox(tr("Keep backlight on"), contents);
47 layout->addWidget(backlight);
48 backlight->setChecked(settings->value("lightson", false).toBool());
51 #if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
52 QCheckBox *grabVolume =
53 new QCheckBox(tr("Navigate with volume keys"), contents);
54 layout->addWidget(grabVolume);
55 grabVolume->setChecked(settings->value("usevolumekeys", false).toBool());
58 int zoom = settings->value("zoom", platform->defaultZoom()).toInt();
59 if (zoom < ZOOM_MIN) {
61 } else if (zoom > ZOOM_MAX) {
64 zoomLabel = new QLabel(tr("Zoom level: %1%").arg(zoom), contents);
65 layout->addWidget(zoomLabel);
66 zoomSlider = new QSlider(Qt::Horizontal, contents);
67 zoomSlider->setMinimum(ZOOM_MIN);
68 zoomSlider->setMaximum(ZOOM_MAX);
69 zoomSlider->setSingleStep(ZOOM_STEP);
70 zoomSlider->setPageStep(ZOOM_STEP);
71 zoomSlider->setValue(zoom);
72 layout->addWidget(zoomSlider);
74 QLabel *fontLabel = new QLabel(tr("Font:"), contents);
75 layout->addWidget(fontLabel);
77 settings->value("font", platform->defaultFont()).toString();
78 fontButton = new QFontComboBox(contents);
79 fontButton->setCurrentFont(QFont(family));
80 fontButton->setEditable(false);
81 layout->addWidget(fontButton);
83 QLabel *colorLabel = new QLabel(tr("Color scheme:"), contents);
84 layout->addWidget(colorLabel);
85 ToolButtonBox *box = new ToolButtonBox(this);
86 layout->addWidget(box);
87 box->addButton(SchemeDay, tr("Day"),
88 Platform::instance()->icon("style-day"));
89 box->addButton(SchemeNight, tr("Night"),
90 Platform::instance()->icon("style-night"));
91 box->addButton(SchemeSand, tr("Sand"),
92 Platform::instance()->icon("style-sand"));
94 QString scheme = settings->value("scheme", "day").toString();
95 if (scheme == "night") {
96 box->toggle(SchemeNight);
97 } else if (scheme == "sand") {
98 box->toggle(SchemeSand);
100 box->toggle(SchemeDay);
103 layout->addStretch();
104 scroller->setWidget(contents);
106 scroller->setWidgetResizable(true);
108 setCentralWidget(scroller);
110 #if defined(Q_WS_MAEMO_5)
111 connect(backlight, SIGNAL(toggled(bool)),
112 this, SLOT(onLightsToggled(bool)));
114 #if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
115 connect(grabVolume, SIGNAL(toggled(bool)),
116 this, SLOT(onGrabVolumeToggled(bool)));
118 connect(zoomSlider, SIGNAL(valueChanged(int)),
119 this, SLOT(onSliderValueChanged(int)));
120 connect(fontButton, SIGNAL(currentFontChanged(const QFont &)),
121 this, SLOT(onCurrentFontChanged(const QFont &)));
122 connect(box, SIGNAL(buttonClicked(int)),
123 this, SLOT(onSchemeButtonClicked(int)));
126 QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this);
127 closeAction->setSoftKeyRole(QAction::NegativeSoftKey);
128 connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
129 QMainWindow::addAction(closeAction);
133 void SettingsWindow::onSliderValueChanged(int value)
135 int step = zoomSlider->singleStep();
137 zoomSlider->setValue((value + step / 2) / step * step);
140 zoomLabel->setText(tr("Zoom level: %1%").arg(value));
141 #if !defined(Q_WS_MAEMO_5) && !defined(Q_OS_SYMBIAN)
142 Settings::instance()->setValue("zoom", zoomSlider->value());
146 void SettingsWindow::onCurrentFontChanged(const QFont &font)
148 #if !defined(Q_WS_MAEMO_5) && !defined(Q_OS_SYMBIAN)
149 Settings::instance()->setValue("font", font.family());
155 void SettingsWindow::onSchemeButtonClicked(int id)
159 case SchemeNight: scheme = "night"; break;
160 case SchemeSand: scheme = "sand"; break;
161 default: scheme = "day"; break;
163 Settings::instance()->setValue("scheme", scheme);
166 void SettingsWindow::onOrientationButtonClicked(int id)
170 case OrientationLandscape:
171 orientation = "landscape";
174 orientation = "portrait";
177 Settings::instance()->setValue("orientation", orientation);
180 void SettingsWindow::closeEvent(QCloseEvent *e)
183 Settings *settings = Settings::instance();
184 settings->setValue("zoom", zoomSlider->value());
185 settings->setValue("font", fontButton->currentFont().family());
189 void SettingsWindow::onLightsToggled(bool value)
191 Settings::instance()->setValue("lightson", value);
194 void SettingsWindow::onGrabVolumeToggled(bool enable)
196 Settings::instance()->setValue("usevolumekeys", enable);