#include "unitselector.h"
#include "buttonselector.h"
#include "settings.h"
+#include "buttonbox.h"
UnitSelector::UnitSelector(QWidget* parent): QDialog(parent)
{
- setWindowTitle(tr("Set unit"));
+ setWindowTitle(tr("Options"));
unit_ = Settings::instance().value("unit", "km").toString();
- QHBoxLayout* layout = new QHBoxLayout;
+ QHBoxLayout* mainLayout = new QHBoxLayout;
+
+ QVBoxLayout* layout = new QVBoxLayout;
selector_ = new ButtonSelector(tr("Unit"));
selector_->setCurrentIndex(1);
}
- layout->addWidget(selector_, Qt::AlignLeft);
+ layout->addWidget(selector_);
+
+ orientation_ = Settings::instance().value("orientation", "auto").toString();
- QPushButton* button = new QPushButton(tr("Save"));
- connect(button, SIGNAL(clicked(bool)), this, SLOT(saveUnit()));
- QDialogButtonBox* buttons = new QDialogButtonBox;
- buttons->setCenterButtons(false);
- buttons->addButton(button, QDialogButtonBox::AcceptRole);
+ orientationSelector_ = new ButtonSelector(tr("Screen orientation"));
- layout->addWidget(buttons);
+ orientationSelector_->addItem(tr("Automatic"), "auto");
+ orientationSelector_->addItem(tr("Landscape"), "landscape");
+ orientationSelector_->addItem(tr("Portrait"), "portrait");
+
+ if(orientation_ == "landscape")
+ {
+ orientationSelector_->setCurrentIndex(1);
+ }
+ else if(orientation_ == "portrait")
+ {
+ orientationSelector_->setCurrentIndex(2);
+ }
- setLayout(layout);
+ layout->addWidget(orientationSelector_);
+
+ ButtonBox* buttons = new ButtonBox;
+ buttons->setOrientation(Qt::Horizontal);
+ connect(buttons->addButton(tr("Save"), QDialogButtonBox::AcceptRole), SIGNAL(clicked(bool)), this, SLOT(saveUnit()));
+
+ mainLayout->addLayout(layout, Qt::AlignLeft);
+ mainLayout->addWidget(buttons);
+
+ setLayout(mainLayout);
}
void UnitSelector::saveUnit()
{
- QString value = selector_->value().toString();
+ QString unitValue = selector_->value().toString();
+ QString orientationValue = orientationSelector_->value().toString();
+
+ if(unitValue != unit_)
+ {
+ Settings::instance().setValue("unit", unitValue);
+ unit_ = unitValue;
+ emit unitChanged();
+ }
- if(value == unit_)
+ if(orientationValue != orientation_)
{
- hide();
- return;
+ Settings::instance().setValue("orientation", orientationValue);
+ orientation_ = orientationValue;
+ emit orientationChanged();
}
- Settings::instance().setValue("unit", value);
- unit_ = value;
hide();
- emit unitChanged();
}