3 #include "settingswindow.h"
5 #include "toolbuttonbox.h"
8 #define DEFAULT_ORIENTATION "portrait"
10 #define DEFAULT_ORIENTATION "landscape"
13 SettingsWindow::SettingsWindow(QWidget *parent): QMainWindow(parent)
16 setAttribute(Qt::WA_Maemo5StackedWindow, true);
17 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
19 setWindowTitle("Settings");
21 Settings *settings = Settings::instance();
22 QScrollArea *scroller = new QScrollArea(this);
24 scroller->setProperty("FingerScrollable", true);
25 scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
27 scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
29 scroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
30 scroller->setFrameStyle(QFrame::NoFrame);
32 QWidget *contents = new QWidget(scroller);
33 QVBoxLayout *layout = new QVBoxLayout(contents);
34 contents->setLayout(layout);
36 QCheckBox *backlight = new QCheckBox(tr("Keep backlight on"), contents);
37 layout->addWidget(backlight);
38 backlight->setChecked(settings->value("lightson", false).toBool());
40 QLabel *zoomLabel = new QLabel(tr("Zoom level:"), contents);
41 layout->addWidget(zoomLabel);
42 zoomSlider = new QSlider(Qt::Horizontal, contents);
43 zoomSlider->setMinimum(50);
44 zoomSlider->setMaximum(300);
45 zoomSlider->setValue(Settings::instance()->value("zoom").toInt());
46 layout->addWidget(zoomSlider);
48 QLabel *fontLabel = new QLabel(tr("Font:"), contents);
49 layout->addWidget(fontLabel);
50 QString defaultFamily = fontLabel->fontInfo().family();
51 QString family = Settings::instance()->value("font", defaultFamily).toString();
52 fontButton = new QFontComboBox(contents);
53 fontButton->setCurrentFont(QFont(family));
54 fontButton->setEditable(false);
55 layout->addWidget(fontButton);
57 QLabel *colorLabel = new QLabel(tr("Color scheme:"), contents);
58 layout->addWidget(colorLabel);
59 ToolButtonBox *box = new ToolButtonBox(this);
60 layout->addWidget(box);
61 box->addButton(SchemeDefault, tr("Default"), ":/icons/style-default.png");
62 box->addButton(SchemeNight, tr("Night"), ":/icons/style-night.png");
63 box->addButton(SchemeDay, tr("Day"), ":/icons/style-day.png");
64 box->addButton(SchemeSand, tr("Sand"), ":/icons/style-sand.png");
66 QString scheme = settings->value("scheme", "default").toString();
67 if (scheme == "night") {
68 box->toggle(SchemeNight);
69 } else if (scheme == "day") {
70 box->toggle(SchemeDay);
71 } else if (scheme == "sand") {
72 box->toggle(SchemeSand);
74 box->toggle(SchemeDefault);
77 QLabel *orientationLabel = new QLabel(tr("Orientation:"), contents);
78 layout->addWidget(orientationLabel);
79 orientationBox = new ToolButtonBox(this);
80 layout->addWidget(orientationBox);
81 orientationBox->addButton(OrientationPortrait, tr("Portrait"),
82 ":/icons/settings-portrait.png");
83 orientationBox->addButton(OrientationLandscape, tr("Landscape"),
84 ":/icons/settings-landscape.png");
85 orientationBox->addStretch();
87 settings->value("orientation", DEFAULT_ORIENTATION).toString();
88 if (orientation == "portrait") {
89 orientationBox->toggle(OrientationPortrait);
91 orientationBox->toggle(OrientationLandscape);
95 scroller->setWidget(contents);
97 scroller->setWidgetResizable(true);
99 setCentralWidget(scroller);
101 connect(backlight, SIGNAL(toggled(bool)), this, SLOT(onLightsToggled(bool)));
102 connect(zoomSlider, SIGNAL(valueChanged(int)),
103 this, SLOT(onSliderValueChanged(int)));
104 connect(fontButton, SIGNAL(currentFontChanged(const QFont &)),
105 this, SLOT(onCurrentFontChanged(const QFont &)));
106 connect(box, SIGNAL(buttonClicked(int)),
107 this, SLOT(onSchemeButtonClicked(int)));
108 connect(orientationBox, SIGNAL(buttonClicked(int)),
109 this, SLOT(onOrientationButtonClicked(int)));
112 void SettingsWindow::onSliderValueChanged(int value)
114 #ifdef Q_WS_MAEMO_5 // Re-scaling the book view is too much for the N900
117 Settings::instance()->setValue("zoom", value);
118 #endif // Q_WS_MAEMO_5
121 void SettingsWindow::onCurrentFontChanged(const QFont &font)
126 Settings::instance()->setValue("font", font.family());
127 #endif // Q_WS_MAEMO_5
130 void SettingsWindow::onSchemeButtonClicked(int id)
134 case SchemeDay: scheme = "day"; break;
135 case SchemeNight: scheme = "night"; break;
136 case SchemeSand: scheme = "sand"; break;
137 default: scheme = "default"; break;
139 Settings::instance()->setValue("scheme", scheme);
142 void SettingsWindow::onOrientationButtonClicked(int id)
149 case OrientationLandscape:
150 orientation = "landscape";
153 orientation = "portrait";
156 Settings::instance()->setValue("orientation", orientation);
157 #endif // Q_WS_MAEMO_5
162 void SettingsWindow::closeEvent(QCloseEvent *e)
164 Settings *settings = Settings::instance();
165 settings->setValue("zoom", zoomSlider->value());
166 settings->setValue("font", fontButton->currentFont().family());
167 settings->setValue("orientation",
168 (orientationBox->checkedId() == OrientationLandscape)?
169 "landscape": "portrait");
173 #endif // Q_WS_MAEMO_5
175 void SettingsWindow::onLightsToggled(bool value)
177 Settings::instance()->setValue("lightson", value);