3 #include "settingswindow.h"
5 #include "toolbuttonbox.h"
9 #include "flickcharm.h"
13 const char *DEFAULT_ORIENTATION = "portrait";
15 const char *DEFAULT_ORIENTATION = "landscape";
18 const int ZOOM_MIN = 75;
19 const int ZOOM_MAX = 250;
20 const int ZOOM_STEP = 25;
22 SettingsWindow::SettingsWindow(QWidget *parent): AdopterWindow(parent)
25 setAttribute(Qt::WA_Maemo5StackedWindow, true);
26 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
28 setWindowTitle("Settings");
30 Settings *settings = Settings::instance();
31 QScrollArea *scroller = new QScrollArea(this);
32 #if defined(Q_WS_MAEMO_5)
33 scroller->setProperty("FingerScrollable", true);
34 scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
35 #elif defined(Q_OS_SYMBIAN)
36 FlickCharm *charm = new FlickCharm(this);
37 charm->activateOn(scroller);
39 scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
41 scroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
42 scroller->setFrameStyle(QFrame::NoFrame);
44 QWidget *contents = new QWidget(scroller);
45 QVBoxLayout *layout = new QVBoxLayout(contents);
46 contents->setLayout(layout);
49 QCheckBox *backlight = new QCheckBox(tr("Keep backlight on"), contents);
50 layout->addWidget(backlight);
51 backlight->setChecked(settings->value("lightson", false).toBool());
55 QCheckBox *grabVolume =
56 new QCheckBox(tr("Navigate with volume keys"), contents);
57 layout->addWidget(grabVolume);
58 grabVolume->setChecked(settings->value("usevolumekeys", false).toBool());
61 int zoom = Settings::instance()->value("zoom").toInt();
62 if (zoom < ZOOM_MIN) {
64 } else if (zoom > ZOOM_MAX) {
67 zoomLabel = new QLabel(tr("Zoom level: %1%").arg(zoom), contents);
68 layout->addWidget(zoomLabel);
69 zoomSlider = new QSlider(Qt::Horizontal, contents);
70 zoomSlider->setMinimum(ZOOM_MIN);
71 zoomSlider->setMaximum(ZOOM_MAX);
72 zoomSlider->setSingleStep(ZOOM_STEP);
73 zoomSlider->setPageStep(ZOOM_STEP);
74 zoomSlider->setValue(zoom);
75 layout->addWidget(zoomSlider);
77 QLabel *fontLabel = new QLabel(tr("Font:"), contents);
78 layout->addWidget(fontLabel);
79 QString defaultFamily = fontLabel->fontInfo().family();
81 Settings::instance()->value("font", defaultFamily).toString();
82 fontButton = new QFontComboBox(contents);
83 fontButton->setCurrentFont(QFont(family));
84 fontButton->setEditable(false);
85 layout->addWidget(fontButton);
87 QLabel *colorLabel = new QLabel(tr("Color scheme:"), contents);
88 layout->addWidget(colorLabel);
89 ToolButtonBox *box = new ToolButtonBox(this);
90 layout->addWidget(box);
91 box->addButton(SchemeDefault, tr("Default"),
92 Platform::icon("style-default"));
93 box->addButton(SchemeNight, tr("Night"), Platform::icon("style-night"));
94 box->addButton(SchemeDay, tr("Day"), Platform::icon("style-day"));
95 box->addButton(SchemeSand, tr("Sand"), Platform::icon("style-sand"));
97 QString scheme = settings->value("scheme", "default").toString();
98 if (scheme == "night") {
99 box->toggle(SchemeNight);
100 } else if (scheme == "day") {
101 box->toggle(SchemeDay);
102 } else if (scheme == "sand") {
103 box->toggle(SchemeSand);
105 box->toggle(SchemeDefault);
109 QLabel *orientationLabel = new QLabel(tr("Orientation:"), contents);
110 layout->addWidget(orientationLabel);
111 orientationBox = new ToolButtonBox(this);
112 layout->addWidget(orientationBox);
113 orientationBox->addButton(OrientationPortrait, tr("Portrait"),
114 ":/icons/settings-portrait.png");
115 orientationBox->addButton(OrientationLandscape, tr("Landscape"),
116 ":/icons/settings-landscape.png");
117 orientationBox->addStretch();
118 QString orientation =
119 settings->value("orientation", DEFAULT_ORIENTATION).toString();
120 if (orientation == "portrait") {
121 orientationBox->toggle(OrientationPortrait);
123 orientationBox->toggle(OrientationLandscape);
125 #endif // !Q_OS_SYMBIAN
127 layout->addStretch();
128 scroller->setWidget(contents);
130 scroller->setWidgetResizable(true);
132 setCentralWidget(scroller);
135 connect(backlight, SIGNAL(toggled(bool)),
136 this, SLOT(onLightsToggled(bool)));
137 connect(grabVolume, SIGNAL(toggled(bool)),
138 this, SLOT(onGrabVolumeToggled(bool)));
140 connect(zoomSlider, SIGNAL(valueChanged(int)),
141 this, SLOT(onSliderValueChanged(int)));
142 connect(fontButton, SIGNAL(currentFontChanged(const QFont &)),
143 this, SLOT(onCurrentFontChanged(const QFont &)));
144 connect(box, SIGNAL(buttonClicked(int)),
145 this, SLOT(onSchemeButtonClicked(int)));
147 connect(orientationBox, SIGNAL(buttonClicked(int)),
148 this, SLOT(onOrientationButtonClicked(int)));
152 QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this);
153 closeAction->setSoftKeyRole(QAction::NegativeSoftKey);
154 connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
155 QMainWindow::addAction(closeAction);
159 void SettingsWindow::onSliderValueChanged(int value)
161 int step = zoomSlider->singleStep();
163 zoomSlider->setValue((value + step / 2) / step * step);
166 zoomLabel->setText(tr("Zoom level: %1%").arg(value));
167 #if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
168 // Constant re-scaling of the book view is too much for mobiles
170 Settings::instance()->setValue("zoom", value);
171 #endif // Q_WS_MAEMO_5
174 void SettingsWindow::onCurrentFontChanged(const QFont &font)
179 Settings::instance()->setValue("font", font.family());
180 #endif // Q_WS_MAEMO_5
183 void SettingsWindow::onSchemeButtonClicked(int id)
187 case SchemeDay: scheme = "day"; break;
188 case SchemeNight: scheme = "night"; break;
189 case SchemeSand: scheme = "sand"; break;
190 default: scheme = "default"; break;
192 Settings::instance()->setValue("scheme", scheme);
195 void SettingsWindow::onOrientationButtonClicked(int id)
202 case OrientationLandscape:
203 orientation = "landscape";
206 orientation = "portrait";
209 Settings::instance()->setValue("orientation", orientation);
210 #endif // Q_WS_MAEMO_5
215 void SettingsWindow::closeEvent(QCloseEvent *e)
217 Settings *settings = Settings::instance();
218 settings->setValue("zoom", zoomSlider->value());
219 settings->setValue("font", fontButton->currentFont().family());
220 settings->setValue("orientation",
221 (orientationBox->checkedId() == OrientationLandscape)?
222 "landscape": "portrait");
226 #endif // Q_WS_MAEMO_5
228 void SettingsWindow::onLightsToggled(bool value)
230 Settings::instance()->setValue("lightson", value);
233 void SettingsWindow::onGrabVolumeToggled(bool enable)
235 Settings::instance()->setValue("usevolumekeys", enable);