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 QCheckBox *grabVolume =
41 new QCheckBox(tr("Navigate with volume keys"), contents);
42 layout->addWidget(grabVolume);
43 grabVolume->setChecked(settings->value("usevolumekeys", false).toBool());
45 QLabel *zoomLabel = new QLabel(tr("Zoom level:"), contents);
46 layout->addWidget(zoomLabel);
47 zoomSlider = new QSlider(Qt::Horizontal, contents);
48 zoomSlider->setMinimum(50);
49 zoomSlider->setMaximum(300);
50 zoomSlider->setValue(Settings::instance()->value("zoom").toInt());
51 layout->addWidget(zoomSlider);
53 QLabel *fontLabel = new QLabel(tr("Font:"), contents);
54 layout->addWidget(fontLabel);
55 QString defaultFamily = fontLabel->fontInfo().family();
56 QString family = Settings::instance()->value("font", defaultFamily).toString();
57 fontButton = new QFontComboBox(contents);
58 fontButton->setCurrentFont(QFont(family));
59 fontButton->setEditable(false);
60 layout->addWidget(fontButton);
62 QLabel *colorLabel = new QLabel(tr("Color scheme:"), contents);
63 layout->addWidget(colorLabel);
64 ToolButtonBox *box = new ToolButtonBox(this);
65 layout->addWidget(box);
66 box->addButton(SchemeDefault, tr("Default"), ":/icons/style-default.png");
67 box->addButton(SchemeNight, tr("Night"), ":/icons/style-night.png");
68 box->addButton(SchemeDay, tr("Day"), ":/icons/style-day.png");
69 box->addButton(SchemeSand, tr("Sand"), ":/icons/style-sand.png");
71 QString scheme = settings->value("scheme", "default").toString();
72 if (scheme == "night") {
73 box->toggle(SchemeNight);
74 } else if (scheme == "day") {
75 box->toggle(SchemeDay);
76 } else if (scheme == "sand") {
77 box->toggle(SchemeSand);
79 box->toggle(SchemeDefault);
82 QLabel *orientationLabel = new QLabel(tr("Orientation:"), contents);
83 layout->addWidget(orientationLabel);
84 orientationBox = new ToolButtonBox(this);
85 layout->addWidget(orientationBox);
86 orientationBox->addButton(OrientationPortrait, tr("Portrait"),
87 ":/icons/settings-portrait.png");
88 orientationBox->addButton(OrientationLandscape, tr("Landscape"),
89 ":/icons/settings-landscape.png");
90 orientationBox->addStretch();
92 settings->value("orientation", DEFAULT_ORIENTATION).toString();
93 if (orientation == "portrait") {
94 orientationBox->toggle(OrientationPortrait);
96 orientationBox->toggle(OrientationLandscape);
100 scroller->setWidget(contents);
102 scroller->setWidgetResizable(true);
104 setCentralWidget(scroller);
106 connect(backlight, SIGNAL(toggled(bool)), this, SLOT(onLightsToggled(bool)));
107 connect(grabVolume, SIGNAL(toggled(bool)),
108 this, SLOT(onGrabVolumeToggled(bool)));
109 connect(zoomSlider, SIGNAL(valueChanged(int)),
110 this, SLOT(onSliderValueChanged(int)));
111 connect(fontButton, SIGNAL(currentFontChanged(const QFont &)),
112 this, SLOT(onCurrentFontChanged(const QFont &)));
113 connect(box, SIGNAL(buttonClicked(int)),
114 this, SLOT(onSchemeButtonClicked(int)));
115 connect(orientationBox, SIGNAL(buttonClicked(int)),
116 this, SLOT(onOrientationButtonClicked(int)));
119 void SettingsWindow::onSliderValueChanged(int value)
121 #ifdef Q_WS_MAEMO_5 // Re-scaling the book view is too much for the N900
124 Settings::instance()->setValue("zoom", value);
125 #endif // Q_WS_MAEMO_5
128 void SettingsWindow::onCurrentFontChanged(const QFont &font)
133 Settings::instance()->setValue("font", font.family());
134 #endif // Q_WS_MAEMO_5
137 void SettingsWindow::onSchemeButtonClicked(int id)
141 case SchemeDay: scheme = "day"; break;
142 case SchemeNight: scheme = "night"; break;
143 case SchemeSand: scheme = "sand"; break;
144 default: scheme = "default"; break;
146 Settings::instance()->setValue("scheme", scheme);
149 void SettingsWindow::onOrientationButtonClicked(int id)
156 case OrientationLandscape:
157 orientation = "landscape";
160 orientation = "portrait";
163 Settings::instance()->setValue("orientation", orientation);
164 #endif // Q_WS_MAEMO_5
169 void SettingsWindow::closeEvent(QCloseEvent *e)
171 Settings *settings = Settings::instance();
172 settings->setValue("zoom", zoomSlider->value());
173 settings->setValue("font", fontButton->currentFont().family());
174 settings->setValue("orientation",
175 (orientationBox->checkedId() == OrientationLandscape)?
176 "landscape": "portrait");
180 #endif // Q_WS_MAEMO_5
182 void SettingsWindow::onLightsToggled(bool value)
184 Settings::instance()->setValue("lightson", value);
187 void SettingsWindow::onGrabVolumeToggled(bool enable)
189 Settings::instance()->setValue("usevolumekeys", enable);