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::instance()->icon("style-default"));
92 box->addButton(SchemeNight, tr("Night"),
93 Platform::instance()->icon("style-night"));
94 box->addButton(SchemeDay, tr("Day"), Platform::instance()->icon("style-day"));
95 box->addButton(SchemeSand, tr("Sand"),
96 Platform::instance()->icon("style-sand"));
98 QString scheme = settings->value("scheme", "default").toString();
99 if (scheme == "night") {
100 box->toggle(SchemeNight);
101 } else if (scheme == "day") {
102 box->toggle(SchemeDay);
103 } else if (scheme == "sand") {
104 box->toggle(SchemeSand);
106 box->toggle(SchemeDefault);
110 QLabel *orientationLabel = new QLabel(tr("Orientation:"), contents);
111 layout->addWidget(orientationLabel);
112 orientationBox = new ToolButtonBox(this);
113 layout->addWidget(orientationBox);
114 orientationBox->addButton(OrientationPortrait, tr("Portrait"),
115 ":/icons/settings-portrait.png");
116 orientationBox->addButton(OrientationLandscape, tr("Landscape"),
117 ":/icons/settings-landscape.png");
118 orientationBox->addStretch();
119 QString orientation =
120 settings->value("orientation", DEFAULT_ORIENTATION).toString();
121 if (orientation == "portrait") {
122 orientationBox->toggle(OrientationPortrait);
124 orientationBox->toggle(OrientationLandscape);
126 #endif // !Q_OS_SYMBIAN
128 layout->addStretch();
129 scroller->setWidget(contents);
131 scroller->setWidgetResizable(true);
133 setCentralWidget(scroller);
136 connect(backlight, SIGNAL(toggled(bool)),
137 this, SLOT(onLightsToggled(bool)));
139 connect(grabVolume, SIGNAL(toggled(bool)),
140 this, SLOT(onGrabVolumeToggled(bool)));
141 connect(zoomSlider, SIGNAL(valueChanged(int)),
142 this, SLOT(onSliderValueChanged(int)));
143 connect(fontButton, SIGNAL(currentFontChanged(const QFont &)),
144 this, SLOT(onCurrentFontChanged(const QFont &)));
145 connect(box, SIGNAL(buttonClicked(int)),
146 this, SLOT(onSchemeButtonClicked(int)));
148 connect(orientationBox, SIGNAL(buttonClicked(int)),
149 this, SLOT(onOrientationButtonClicked(int)));
153 QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this);
154 closeAction->setSoftKeyRole(QAction::NegativeSoftKey);
155 connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
156 QMainWindow::addAction(closeAction);
160 void SettingsWindow::onSliderValueChanged(int value)
162 int step = zoomSlider->singleStep();
164 zoomSlider->setValue((value + step / 2) / step * step);
167 zoomLabel->setText(tr("Zoom level: %1%").arg(value));
168 #if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
169 // Constant re-scaling of the book view is too much for mobiles
171 Settings::instance()->setValue("zoom", value);
172 #endif // Q_WS_MAEMO_5
175 void SettingsWindow::onCurrentFontChanged(const QFont &font)
180 Settings::instance()->setValue("font", font.family());
181 #endif // Q_WS_MAEMO_5
184 void SettingsWindow::onSchemeButtonClicked(int id)
188 case SchemeDay: scheme = "day"; break;
189 case SchemeNight: scheme = "night"; break;
190 case SchemeSand: scheme = "sand"; break;
191 default: scheme = "default"; break;
193 Settings::instance()->setValue("scheme", scheme);
196 void SettingsWindow::onOrientationButtonClicked(int id)
203 case OrientationLandscape:
204 orientation = "landscape";
207 orientation = "portrait";
210 Settings::instance()->setValue("orientation", orientation);
211 #endif // Q_WS_MAEMO_5
214 #if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
216 void SettingsWindow::closeEvent(QCloseEvent *e)
219 Settings *settings = Settings::instance();
220 settings->setValue("zoom", zoomSlider->value());
221 settings->setValue("font", fontButton->currentFont().family());
223 settings->setValue("orientation",
224 (orientationBox->checkedId() == OrientationLandscape)?
225 "landscape": "portrait");
226 #endif // Q_OS_SYMBIAN
230 #endif // Q_WS_MAEMO_5 || Q_OS_SYMBIAN
232 void SettingsWindow::onLightsToggled(bool value)
234 Settings::instance()->setValue("lightson", value);
237 void SettingsWindow::onGrabVolumeToggled(bool enable)
239 Settings::instance()->setValue("usevolumekeys", enable);