3 #include "settingswindow.h"
5 #include "toolbuttonbox.h"
10 #include "flickcharm.h"
14 const char *DEFAULT_ORIENTATION = "portrait";
16 const char *DEFAULT_ORIENTATION = "landscape";
19 const int ZOOM_MIN = 75;
20 const int ZOOM_MAX = 250;
21 const int ZOOM_STEP = 25;
23 SettingsWindow::SettingsWindow(QWidget *parent): AdopterWindow(parent)
26 setAttribute(Qt::WA_Maemo5StackedWindow, true);
27 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
29 setWindowTitle("Settings");
31 Settings *settings = Settings::instance();
32 QScrollArea *scroller = new QScrollArea(this);
33 #if defined(Q_WS_MAEMO_5)
34 scroller->setProperty("FingerScrollable", true);
35 scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
36 #elif defined(Q_OS_SYMBIAN)
37 FlickCharm *charm = new FlickCharm(this);
38 charm->activateOn(scroller);
40 scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
42 scroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
43 scroller->setFrameStyle(QFrame::NoFrame);
45 QWidget *contents = new QWidget(scroller);
46 QVBoxLayout *layout = new QVBoxLayout(contents);
47 contents->setLayout(layout);
50 QCheckBox *backlight = new QCheckBox(tr("Keep backlight on"), contents);
51 layout->addWidget(backlight);
52 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());
60 int zoom = Settings::instance()->value("zoom").toInt();
61 if (zoom < ZOOM_MIN) {
63 } else if (zoom > ZOOM_MAX) {
66 zoomLabel = new QLabel(tr("Zoom level: %1%").arg(zoom), contents);
67 layout->addWidget(zoomLabel);
68 zoomSlider = new QSlider(Qt::Horizontal, contents);
69 zoomSlider->setMinimum(ZOOM_MIN);
70 zoomSlider->setMaximum(ZOOM_MAX);
71 zoomSlider->setSingleStep(ZOOM_STEP);
72 zoomSlider->setPageStep(ZOOM_STEP);
73 zoomSlider->setValue(zoom);
74 layout->addWidget(zoomSlider);
76 QLabel *fontLabel = new QLabel(tr("Font:"), contents);
77 layout->addWidget(fontLabel);
78 QString defaultFamily = fontLabel->fontInfo().family();
80 Settings::instance()->value("font", defaultFamily).toString();
81 fontButton = new QFontComboBox(contents);
82 fontButton->setCurrentFont(QFont(family));
83 fontButton->setEditable(false);
84 layout->addWidget(fontButton);
86 QLabel *colorLabel = new QLabel(tr("Color scheme:"), contents);
87 layout->addWidget(colorLabel);
88 ToolButtonBox *box = new ToolButtonBox(this);
89 layout->addWidget(box);
90 box->addButton(SchemeDefault, tr("Default"),
91 Platform::icon("style-default"));
92 box->addButton(SchemeNight, tr("Night"), Platform::icon("style-night"));
93 box->addButton(SchemeDay, tr("Day"), Platform::icon("style-day"));
94 box->addButton(SchemeSand, tr("Sand"), Platform::icon("style-sand"));
96 QString scheme = settings->value("scheme", "default").toString();
97 if (scheme == "night") {
98 box->toggle(SchemeNight);
99 } else if (scheme == "day") {
100 box->toggle(SchemeDay);
101 } else if (scheme == "sand") {
102 box->toggle(SchemeSand);
104 box->toggle(SchemeDefault);
108 QLabel *orientationLabel = new QLabel(tr("Orientation:"), contents);
109 layout->addWidget(orientationLabel);
110 orientationBox = new ToolButtonBox(this);
111 layout->addWidget(orientationBox);
112 orientationBox->addButton(OrientationPortrait, tr("Portrait"),
113 ":/icons/settings-portrait.png");
114 orientationBox->addButton(OrientationLandscape, tr("Landscape"),
115 ":/icons/settings-landscape.png");
116 orientationBox->addStretch();
117 QString orientation =
118 settings->value("orientation", DEFAULT_ORIENTATION).toString();
119 if (orientation == "portrait") {
120 orientationBox->toggle(OrientationPortrait);
122 orientationBox->toggle(OrientationLandscape);
124 #endif // !Q_OS_SYMBIAN
126 layout->addStretch();
127 scroller->setWidget(contents);
129 scroller->setWidgetResizable(true);
131 setCentralWidget(scroller);
134 connect(backlight, SIGNAL(toggled(bool)),
135 this, SLOT(onLightsToggled(bool)));
137 connect(grabVolume, SIGNAL(toggled(bool)),
138 this, SLOT(onGrabVolumeToggled(bool)));
139 connect(zoomSlider, SIGNAL(valueChanged(int)),
140 this, SLOT(onSliderValueChanged(int)));
141 connect(fontButton, SIGNAL(currentFontChanged(const QFont &)),
142 this, SLOT(onCurrentFontChanged(const QFont &)));
143 connect(box, SIGNAL(buttonClicked(int)),
144 this, SLOT(onSchemeButtonClicked(int)));
146 connect(orientationBox, SIGNAL(buttonClicked(int)),
147 this, SLOT(onOrientationButtonClicked(int)));
151 QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this);
152 closeAction->setSoftKeyRole(QAction::NegativeSoftKey);
153 connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
154 QMainWindow::addAction(closeAction);
158 void SettingsWindow::onSliderValueChanged(int value)
160 int step = zoomSlider->singleStep();
162 zoomSlider->setValue((value + step / 2) / step * step);
165 zoomLabel->setText(tr("Zoom level: %1%").arg(value));
166 #if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
167 // Constant re-scaling of the book view is too much for mobiles
169 Settings::instance()->setValue("zoom", value);
170 #endif // Q_WS_MAEMO_5
173 void SettingsWindow::onCurrentFontChanged(const QFont &font)
178 Settings::instance()->setValue("font", font.family());
179 #endif // Q_WS_MAEMO_5
182 void SettingsWindow::onSchemeButtonClicked(int id)
186 case SchemeDay: scheme = "day"; break;
187 case SchemeNight: scheme = "night"; break;
188 case SchemeSand: scheme = "sand"; break;
189 default: scheme = "default"; break;
191 Settings::instance()->setValue("scheme", scheme);
194 void SettingsWindow::onOrientationButtonClicked(int id)
201 case OrientationLandscape:
202 orientation = "landscape";
205 orientation = "portrait";
208 Settings::instance()->setValue("orientation", orientation);
209 #endif // Q_WS_MAEMO_5
212 #if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
214 void SettingsWindow::closeEvent(QCloseEvent *e)
217 Settings *settings = Settings::instance();
218 settings->setValue("zoom", zoomSlider->value());
219 settings->setValue("font", fontButton->currentFont().family());
221 settings->setValue("orientation",
222 (orientationBox->checkedId() == OrientationLandscape)?
223 "landscape": "portrait");
224 #endif // Q_OS_SYMBIAN
228 #endif // Q_WS_MAEMO_5 || Q_OS_SYMBIAN
230 void SettingsWindow::onLightsToggled(bool value)
232 Settings::instance()->setValue("lightson", value);
235 void SettingsWindow::onGrabVolumeToggled(bool enable)
237 Settings::instance()->setValue("usevolumekeys", enable);