3 #include "settingswindow.h"
5 #include "toolbuttonbox.h"
8 const char *DEFAULT_ORIENTATION = "portrait";
10 const char *DEFAULT_ORIENTATION = "landscape";
13 const int ZOOM_MIN = 75;
14 const int ZOOM_MAX = 250;
15 const int ZOOM_STEP = 25;
17 SettingsWindow::SettingsWindow(QWidget *parent): QMainWindow(parent)
20 setAttribute(Qt::WA_Maemo5StackedWindow, true);
21 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
23 setWindowTitle("Settings");
25 Settings *settings = Settings::instance();
26 QScrollArea *scroller = new QScrollArea(this);
28 scroller->setProperty("FingerScrollable", true);
29 scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
31 scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
33 scroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
34 scroller->setFrameStyle(QFrame::NoFrame);
36 QWidget *contents = new QWidget(scroller);
37 QVBoxLayout *layout = new QVBoxLayout(contents);
38 contents->setLayout(layout);
40 QCheckBox *backlight = new QCheckBox(tr("Keep backlight on"), contents);
41 layout->addWidget(backlight);
42 backlight->setChecked(settings->value("lightson", false).toBool());
44 QCheckBox *grabVolume =
45 new QCheckBox(tr("Navigate with volume keys"), contents);
46 layout->addWidget(grabVolume);
47 grabVolume->setChecked(settings->value("usevolumekeys", false).toBool());
49 int zoom = Settings::instance()->value("zoom").toInt();
50 if (zoom < ZOOM_MIN) {
52 } else if (zoom > ZOOM_MAX) {
55 zoomLabel = new QLabel(tr("Zoom level: %1%").arg(zoom), contents);
56 layout->addWidget(zoomLabel);
57 zoomSlider = new QSlider(Qt::Horizontal, contents);
58 zoomSlider->setMinimum(ZOOM_MIN);
59 zoomSlider->setMaximum(ZOOM_MAX);
60 zoomSlider->setSingleStep(ZOOM_STEP);
61 zoomSlider->setPageStep(ZOOM_STEP);
62 zoomSlider->setValue(zoom);
63 layout->addWidget(zoomSlider);
65 QLabel *fontLabel = new QLabel(tr("Font:"), contents);
66 layout->addWidget(fontLabel);
67 QString defaultFamily = fontLabel->fontInfo().family();
68 QString family = Settings::instance()->value("font", defaultFamily).toString();
69 fontButton = new QFontComboBox(contents);
70 fontButton->setCurrentFont(QFont(family));
71 fontButton->setEditable(false);
72 layout->addWidget(fontButton);
74 QLabel *colorLabel = new QLabel(tr("Color scheme:"), contents);
75 layout->addWidget(colorLabel);
76 ToolButtonBox *box = new ToolButtonBox(this);
77 layout->addWidget(box);
78 box->addButton(SchemeDefault, tr("Default"), ":/icons/style-default.png");
79 box->addButton(SchemeNight, tr("Night"), ":/icons/style-night.png");
80 box->addButton(SchemeDay, tr("Day"), ":/icons/style-day.png");
81 box->addButton(SchemeSand, tr("Sand"), ":/icons/style-sand.png");
83 QString scheme = settings->value("scheme", "default").toString();
84 if (scheme == "night") {
85 box->toggle(SchemeNight);
86 } else if (scheme == "day") {
87 box->toggle(SchemeDay);
88 } else if (scheme == "sand") {
89 box->toggle(SchemeSand);
91 box->toggle(SchemeDefault);
94 QLabel *orientationLabel = new QLabel(tr("Orientation:"), contents);
95 layout->addWidget(orientationLabel);
96 orientationBox = new ToolButtonBox(this);
97 layout->addWidget(orientationBox);
98 orientationBox->addButton(OrientationPortrait, tr("Portrait"),
99 ":/icons/settings-portrait.png");
100 orientationBox->addButton(OrientationLandscape, tr("Landscape"),
101 ":/icons/settings-landscape.png");
102 orientationBox->addStretch();
103 QString orientation =
104 settings->value("orientation", DEFAULT_ORIENTATION).toString();
105 if (orientation == "portrait") {
106 orientationBox->toggle(OrientationPortrait);
108 orientationBox->toggle(OrientationLandscape);
111 layout->addStretch();
112 scroller->setWidget(contents);
114 scroller->setWidgetResizable(true);
116 setCentralWidget(scroller);
118 connect(backlight, SIGNAL(toggled(bool)), this, SLOT(onLightsToggled(bool)));
119 connect(grabVolume, SIGNAL(toggled(bool)),
120 this, SLOT(onGrabVolumeToggled(bool)));
121 connect(zoomSlider, SIGNAL(valueChanged(int)),
122 this, SLOT(onSliderValueChanged(int)));
123 connect(fontButton, SIGNAL(currentFontChanged(const QFont &)),
124 this, SLOT(onCurrentFontChanged(const QFont &)));
125 connect(box, SIGNAL(buttonClicked(int)),
126 this, SLOT(onSchemeButtonClicked(int)));
127 connect(orientationBox, SIGNAL(buttonClicked(int)),
128 this, SLOT(onOrientationButtonClicked(int)));
131 void SettingsWindow::onSliderValueChanged(int value)
133 int step = zoomSlider->singleStep();
135 zoomSlider->setValue((value + step / 2) / step * step);
138 zoomLabel->setText(tr("Zoom level: %1%").arg(value));
140 // Re-scaling the book view is too much for the N900
142 Settings::instance()->setValue("zoom", value);
143 #endif // Q_WS_MAEMO_5
146 void SettingsWindow::onCurrentFontChanged(const QFont &font)
151 Settings::instance()->setValue("font", font.family());
152 #endif // Q_WS_MAEMO_5
155 void SettingsWindow::onSchemeButtonClicked(int id)
159 case SchemeDay: scheme = "day"; break;
160 case SchemeNight: scheme = "night"; break;
161 case SchemeSand: scheme = "sand"; break;
162 default: scheme = "default"; break;
164 Settings::instance()->setValue("scheme", scheme);
167 void SettingsWindow::onOrientationButtonClicked(int id)
174 case OrientationLandscape:
175 orientation = "landscape";
178 orientation = "portrait";
181 Settings::instance()->setValue("orientation", orientation);
182 #endif // Q_WS_MAEMO_5
187 void SettingsWindow::closeEvent(QCloseEvent *e)
189 Settings *settings = Settings::instance();
190 settings->setValue("zoom", zoomSlider->value());
191 settings->setValue("font", fontButton->currentFont().family());
192 settings->setValue("orientation",
193 (orientationBox->checkedId() == OrientationLandscape)?
194 "landscape": "portrait");
198 #endif // Q_WS_MAEMO_5
200 void SettingsWindow::onLightsToggled(bool value)
202 Settings::instance()->setValue("lightson", value);
205 void SettingsWindow::onGrabVolumeToggled(bool enable)
207 Settings::instance()->setValue("usevolumekeys", enable);