3 #include "settingswindow.h"
7 #define DEFAULT_ORIENTATION "portrait"
9 #define DEFAULT_ORIENTATION "landscape"
12 SettingsWindow::SettingsWindow(QWidget *parent): QMainWindow(parent)
15 setAttribute(Qt::WA_Maemo5StackedWindow, true);
16 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
18 setWindowTitle("Settings");
20 QScrollArea *scroller = new QScrollArea(this);
22 scroller->setProperty("FingerScrollable", true);
23 scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
25 scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
27 scroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
28 scroller->setFrameStyle(QFrame::NoFrame);
30 QWidget *contents = new QWidget(scroller);
31 QVBoxLayout *layout = new QVBoxLayout(contents);
32 contents->setLayout(layout);
34 QLabel *zoomLabel = new QLabel(tr("Zoom level:"), contents);
35 layout->addWidget(zoomLabel);
36 QSlider *zoomSlider = new QSlider(Qt::Horizontal, contents);
37 zoomSlider->setMinimum(50);
38 zoomSlider->setMaximum(300);
39 zoomSlider->setValue(Settings::instance()->value("zoom").toInt());
40 layout->addWidget(zoomSlider);
42 QLabel *fontLabel = new QLabel(tr("Font:"), contents);
43 layout->addWidget(fontLabel);
44 QString defaultFamily = fontLabel->fontInfo().family();
45 QString family = Settings::instance()->value("font", defaultFamily).toString();
46 QFontComboBox *fontButton = new QFontComboBox(contents);
47 fontButton->setCurrentFont(QFont(family));
48 fontButton->setEditable(false);
49 layout->addWidget(fontButton);
51 QLabel *colorLabel = new QLabel(tr("Color scheme:"), contents);
52 layout->addWidget(colorLabel);
53 QFrame *box = new QFrame(this);
54 layout->addWidget(box);
55 QHBoxLayout *boxLayout = new QHBoxLayout(box);
56 boxLayout->setMargin(0);
57 box->setLayout(boxLayout);
58 QButtonGroup *group = new QButtonGroup(this);
60 QToolButton *defaultSchemeButton = new QToolButton(box);
61 defaultSchemeButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
62 defaultSchemeButton->setText(tr("Default"));
63 defaultSchemeButton->setIconSize(QSize(81, 81));
64 defaultSchemeButton->setIcon(QIcon(":/icons/style-default.png"));
65 defaultSchemeButton->setCheckable(true);
66 boxLayout->addWidget(defaultSchemeButton);
67 group->addButton(defaultSchemeButton);
68 group->setId(defaultSchemeButton, SchemeDefault);
70 QToolButton *nightSchemeButton = new QToolButton(box);
71 nightSchemeButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
72 nightSchemeButton->setText(tr("Night"));
73 nightSchemeButton->setCheckable(true);
74 nightSchemeButton->setIconSize(QSize(81, 81));
75 nightSchemeButton->setIcon(QIcon(":/icons/style-night.png"));
76 boxLayout->addWidget(nightSchemeButton);
77 group->addButton(nightSchemeButton);
78 group->setId(nightSchemeButton, SchemeNight);
80 QToolButton *daySchemeButton = new QToolButton(box);
81 daySchemeButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
82 daySchemeButton->setText(tr("Day"));
83 daySchemeButton->setCheckable(true);
84 daySchemeButton->setIconSize(QSize(81, 81));
85 daySchemeButton->setIcon(QIcon(":/icons/style-day.png"));
86 boxLayout->addWidget(daySchemeButton);
87 group->addButton(daySchemeButton);
88 group->setId(daySchemeButton, SchemeDay);
90 QToolButton *sandSchemeButton = new QToolButton(box);
91 sandSchemeButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
92 sandSchemeButton->setText(tr("Sand"));
93 sandSchemeButton->setCheckable(true);
94 sandSchemeButton->setIconSize(QSize(81, 81));
95 sandSchemeButton->setIcon(QIcon(":/icons/style-sand.png"));
96 boxLayout->addWidget(sandSchemeButton);
97 group->addButton(sandSchemeButton);
98 group->setId(sandSchemeButton, SchemeSand);
100 QString scheme = Settings::instance()->value("scheme", "default").toString();
101 if (scheme == "night") {
102 nightSchemeButton->toggle();
104 else if (scheme == "day") {
105 daySchemeButton->toggle();
107 else if (scheme == "sand") {
108 sandSchemeButton->toggle();
111 defaultSchemeButton->toggle();
114 QLabel *orientationLabel = new QLabel(tr("Orientation:"), contents);
115 layout->addWidget(orientationLabel);
117 QFrame *orientationBox = new QFrame(this);
118 layout->addWidget(orientationBox);
119 QHBoxLayout *orientationLayout = new QHBoxLayout(orientationBox);
120 orientationLayout->setMargin(0);
121 orientationBox->setLayout(orientationLayout);
122 QButtonGroup *orientationGroup = new QButtonGroup(this);
124 QToolButton *portraitButton = new QToolButton(box);
125 portraitButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
126 portraitButton->setText(tr("Portrait"));
127 portraitButton->setIconSize(QSize(81, 81));
128 portraitButton->setIcon(QIcon(":/icons/settings-portrait.png"));
129 portraitButton->setCheckable(true);
130 orientationLayout->addWidget(portraitButton);
131 orientationGroup->addButton(portraitButton);
132 orientationGroup->setId(portraitButton, OrientationPortrait);
134 QToolButton *landscapeButton = new QToolButton(box);
135 landscapeButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
136 landscapeButton->setText(tr("Landscape"));
137 landscapeButton->setIconSize(QSize(81, 81));
138 landscapeButton->setIcon(QIcon(":/icons/settings-landscape.png"));
139 landscapeButton->setCheckable(true);
140 orientationLayout->addWidget(landscapeButton);
141 orientationGroup->addButton(landscapeButton);
142 orientationGroup->setId(landscapeButton, OrientationLandscape);
144 orientationLayout->addStretch();
146 QString orientation =
147 Settings::instance()->value("orientation", DEFAULT_ORIENTATION).toString();
148 if (orientation == "portrait") {
149 portraitButton->toggle();
152 landscapeButton->toggle();
155 boxLayout->addStretch();
156 layout->addStretch();
157 scroller->setWidget(contents);
159 scroller->setWidgetResizable(true);
161 setCentralWidget(scroller);
163 connect(zoomSlider, SIGNAL(valueChanged(int)),
164 this, SLOT(onSliderValueChanged(int)));
165 connect(fontButton, SIGNAL(currentFontChanged(const QFont &)),
166 this, SLOT(onCurrentFontChanged(const QFont &)));
167 connect(group, SIGNAL(buttonClicked(int)),
168 this, SLOT(onSchemeButtonClicked(int)));
169 connect(orientationGroup, SIGNAL(buttonClicked(int)),
170 this, SLOT(onOrientationButtonClicked(int)));
173 void SettingsWindow::onSliderValueChanged(int value)
175 Settings::instance()->setValue("zoom", value);
178 void SettingsWindow::onCurrentFontChanged(const QFont &font)
180 Settings::instance()->setValue("font", font.family());
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)
199 case OrientationLandscape: orientation = "landscape"; break;
200 default: orientation = "portrait"; break;
202 Settings::instance()->setValue("orientation", orientation);