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);
46 QCheckBox *backlight = new QCheckBox(tr("Keep backlight on"), contents);
47 layout->addWidget(backlight);
48 backlight->setChecked(settings->value("lightson", false).toBool());
51 QCheckBox *grabVolume =
52 new QCheckBox(tr("Navigate with volume keys"), contents);
53 layout->addWidget(grabVolume);
54 grabVolume->setChecked(settings->value("usevolumekeys", false).toBool());
56 int zoom = settings->value("zoom", platform->defaultZoom()).toInt();
57 if (zoom < ZOOM_MIN) {
59 } else if (zoom > ZOOM_MAX) {
62 zoomLabel = new QLabel(tr("Zoom level: %1%").arg(zoom), contents);
63 layout->addWidget(zoomLabel);
64 zoomSlider = new QSlider(Qt::Horizontal, contents);
65 zoomSlider->setMinimum(ZOOM_MIN);
66 zoomSlider->setMaximum(ZOOM_MAX);
67 zoomSlider->setSingleStep(ZOOM_STEP);
68 zoomSlider->setPageStep(ZOOM_STEP);
69 zoomSlider->setValue(zoom);
70 layout->addWidget(zoomSlider);
72 QLabel *fontLabel = new QLabel(tr("Font:"), contents);
73 layout->addWidget(fontLabel);
75 settings->value("font", platform->defaultFont()).toString();
76 fontButton = new QFontComboBox(contents);
77 fontButton->setCurrentFont(QFont(family));
78 fontButton->setEditable(false);
79 layout->addWidget(fontButton);
81 QLabel *colorLabel = new QLabel(tr("Color scheme:"), contents);
82 layout->addWidget(colorLabel);
83 ToolButtonBox *box = new ToolButtonBox(this);
84 layout->addWidget(box);
85 box->addButton(SchemeDefault, tr("Default"),
86 Platform::instance()->icon("style-default"));
87 box->addButton(SchemeNight, tr("Night"),
88 Platform::instance()->icon("style-night"));
89 box->addButton(SchemeDay, tr("Day"),
90 Platform::instance()->icon("style-day"));
91 box->addButton(SchemeSand, tr("Sand"),
92 Platform::instance()->icon("style-sand"));
94 QString scheme = settings->value("scheme", "default").toString();
95 if (scheme == "night") {
96 box->toggle(SchemeNight);
97 } else if (scheme == "day") {
98 box->toggle(SchemeDay);
99 } else if (scheme == "sand") {
100 box->toggle(SchemeSand);
102 box->toggle(SchemeDefault);
105 layout->addStretch();
106 scroller->setWidget(contents);
108 scroller->setWidgetResizable(true);
110 setCentralWidget(scroller);
113 connect(backlight, SIGNAL(toggled(bool)),
114 this, SLOT(onLightsToggled(bool)));
116 connect(grabVolume, SIGNAL(toggled(bool)),
117 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));
143 void SettingsWindow::onCurrentFontChanged(const QFont &font)
148 void SettingsWindow::onSchemeButtonClicked(int id)
152 case SchemeDay: scheme = "day"; break;
153 case SchemeNight: scheme = "night"; break;
154 case SchemeSand: scheme = "sand"; break;
155 default: scheme = "default"; break;
157 Settings::instance()->setValue("scheme", scheme);
160 void SettingsWindow::onOrientationButtonClicked(int id)
164 case OrientationLandscape:
165 orientation = "landscape";
168 orientation = "portrait";
171 Settings::instance()->setValue("orientation", orientation);
174 void SettingsWindow::closeEvent(QCloseEvent *e)
177 Settings *settings = Settings::instance();
178 settings->setValue("zoom", zoomSlider->value());
179 settings->setValue("font", fontButton->currentFont().family());
183 void SettingsWindow::onLightsToggled(bool value)
185 Settings::instance()->setValue("lightson", value);
188 void SettingsWindow::onGrabVolumeToggled(bool enable)
190 Settings::instance()->setValue("usevolumekeys", enable);