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());
45 QCheckBox *grabVolume =
46 new QCheckBox(tr("Navigate with volume keys"), contents);
47 layout->addWidget(grabVolume);
48 grabVolume->setChecked(settings->value("usevolumekeys", false).toBool());
51 int zoom = Settings::instance()->value("zoom").toInt();
52 if (zoom < ZOOM_MIN) {
54 } else if (zoom > ZOOM_MAX) {
57 zoomLabel = new QLabel(tr("Zoom level: %1%").arg(zoom), contents);
58 layout->addWidget(zoomLabel);
59 zoomSlider = new QSlider(Qt::Horizontal, contents);
60 zoomSlider->setMinimum(ZOOM_MIN);
61 zoomSlider->setMaximum(ZOOM_MAX);
62 zoomSlider->setSingleStep(ZOOM_STEP);
63 zoomSlider->setPageStep(ZOOM_STEP);
64 zoomSlider->setValue(zoom);
65 layout->addWidget(zoomSlider);
67 QLabel *fontLabel = new QLabel(tr("Font:"), contents);
68 layout->addWidget(fontLabel);
69 QString defaultFamily = fontLabel->fontInfo().family();
71 Settings::instance()->value("font", defaultFamily).toString();
72 fontButton = new QFontComboBox(contents);
73 fontButton->setCurrentFont(QFont(family));
74 fontButton->setEditable(false);
75 layout->addWidget(fontButton);
77 QLabel *colorLabel = new QLabel(tr("Color scheme:"), contents);
78 layout->addWidget(colorLabel);
79 ToolButtonBox *box = new ToolButtonBox(this);
80 layout->addWidget(box);
81 box->addButton(SchemeDefault, tr("Default"), ":/icons/style-default.png");
82 box->addButton(SchemeNight, tr("Night"), ":/icons/style-night.png");
83 box->addButton(SchemeDay, tr("Day"), ":/icons/style-day.png");
84 box->addButton(SchemeSand, tr("Sand"), ":/icons/style-sand.png");
86 QString scheme = settings->value("scheme", "default").toString();
87 if (scheme == "night") {
88 box->toggle(SchemeNight);
89 } else if (scheme == "day") {
90 box->toggle(SchemeDay);
91 } else if (scheme == "sand") {
92 box->toggle(SchemeSand);
94 box->toggle(SchemeDefault);
97 QLabel *orientationLabel = new QLabel(tr("Orientation:"), contents);
98 layout->addWidget(orientationLabel);
99 orientationBox = new ToolButtonBox(this);
100 layout->addWidget(orientationBox);
101 orientationBox->addButton(OrientationPortrait, tr("Portrait"),
102 ":/icons/settings-portrait.png");
103 orientationBox->addButton(OrientationLandscape, tr("Landscape"),
104 ":/icons/settings-landscape.png");
105 orientationBox->addStretch();
106 QString orientation =
107 settings->value("orientation", DEFAULT_ORIENTATION).toString();
108 if (orientation == "portrait") {
109 orientationBox->toggle(OrientationPortrait);
111 orientationBox->toggle(OrientationLandscape);
114 layout->addStretch();
115 scroller->setWidget(contents);
117 scroller->setWidgetResizable(true);
119 setCentralWidget(scroller);
121 connect(backlight, SIGNAL(toggled(bool)),
122 this, SLOT(onLightsToggled(bool)));
124 connect(grabVolume, SIGNAL(toggled(bool)),
125 this, SLOT(onGrabVolumeToggled(bool)));
127 connect(zoomSlider, SIGNAL(valueChanged(int)),
128 this, SLOT(onSliderValueChanged(int)));
129 connect(fontButton, SIGNAL(currentFontChanged(const QFont &)),
130 this, SLOT(onCurrentFontChanged(const QFont &)));
131 connect(box, SIGNAL(buttonClicked(int)),
132 this, SLOT(onSchemeButtonClicked(int)));
133 connect(orientationBox, SIGNAL(buttonClicked(int)),
134 this, SLOT(onOrientationButtonClicked(int)));
137 QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this);
138 closeAction->setSoftKeyRole(QAction::NegativeSoftKey);
139 connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
140 QMainWindow::addAction(closeAction);
144 void SettingsWindow::onSliderValueChanged(int value)
146 int step = zoomSlider->singleStep();
148 zoomSlider->setValue((value + step / 2) / step * step);
151 zoomLabel->setText(tr("Zoom level: %1%").arg(value));
152 #if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
153 // Constant re-scaling of the book view is too much for mobiles
155 Settings::instance()->setValue("zoom", value);
156 #endif // Q_WS_MAEMO_5
159 void SettingsWindow::onCurrentFontChanged(const QFont &font)
164 Settings::instance()->setValue("font", font.family());
165 #endif // Q_WS_MAEMO_5
168 void SettingsWindow::onSchemeButtonClicked(int id)
172 case SchemeDay: scheme = "day"; break;
173 case SchemeNight: scheme = "night"; break;
174 case SchemeSand: scheme = "sand"; break;
175 default: scheme = "default"; break;
177 Settings::instance()->setValue("scheme", scheme);
180 void SettingsWindow::onOrientationButtonClicked(int id)
187 case OrientationLandscape:
188 orientation = "landscape";
191 orientation = "portrait";
194 Settings::instance()->setValue("orientation", orientation);
195 #endif // Q_WS_MAEMO_5
200 void SettingsWindow::closeEvent(QCloseEvent *e)
202 Settings *settings = Settings::instance();
203 settings->setValue("zoom", zoomSlider->value());
204 settings->setValue("font", fontButton->currentFont().family());
205 settings->setValue("orientation",
206 (orientationBox->checkedId() == OrientationLandscape)?
207 "landscape": "portrait");
211 #endif // Q_WS_MAEMO_5
213 void SettingsWindow::onLightsToggled(bool value)
215 Settings::instance()->setValue("lightson", value);
218 void SettingsWindow::onGrabVolumeToggled(bool enable)
220 Settings::instance()->setValue("usevolumekeys", enable);