OSCAR-code/preferencesdialog.cpp

190 lines
6.3 KiB
C++
Raw Normal View History

2011-08-03 03:09:57 +00:00
#include <QLabel>
#include <QColorDialog>
2011-08-02 22:37:15 +00:00
#include "preferencesdialog.h"
#include "ui_preferencesdialog.h"
2011-08-03 03:09:57 +00:00
#include "SleepLib/machine_common.h"
2011-08-02 22:37:15 +00:00
PreferencesDialog::PreferencesDialog(QWidget *parent,Profile * _profile) :
2011-08-02 22:37:15 +00:00
QDialog(parent),
ui(new Ui::PreferencesDialog),
profile(_profile)
2011-08-02 22:37:15 +00:00
{
ui->setupUi(this);
Q_ASSERT(profile!=NULL);
ui->firstNameEdit->setText((*profile)["FirstName"].toString());
ui->lastNameEdit->setText((*profile)["LastName"].toString());
ui->addressEdit->clear();
ui->addressEdit->appendPlainText((*profile)["Address"].toString());
ui->emailEdit->setText((*profile)["EmailAddress"].toString());
ui->phoneEdit->setText((*profile)["Phone"].toString());
2011-09-12 12:32:47 +00:00
QString gender;
if ((*profile).Exists("Gender")) {
2011-09-12 12:32:47 +00:00
gender=(*profile)["Gender"].toString().toLower();
} else gender="male";
// I know this looks sexist.. This was originally a boolean.. :)
if ((gender=="male") || (gender=="true")) ui->genderMale->setChecked(true);
else if ((gender=="female") || (gender=="false")) ui->genderFemale->setChecked(true);
bool ok;
ui->heightEdit->setValue((*profile)["Height"].toDouble(&ok));
if (!(*profile).Exists("DOB")) {
ui->dobEdit->setDate(QDate(1970,1,1));
} else {
ui->dobEdit->setDate((*profile)["DOB"].toDate());
}
int i=ui->unitCombo->findText((*profile)["UnitSystem"].toString());
if (i<0) i=0;
ui->unitCombo->setCurrentIndex(i);
2011-09-08 09:56:20 +00:00
i=ui->timeZoneCombo->findText((*profile)["TimeZone"].toString());
ui->timeZoneCombo->setCurrentIndex(i);
2011-08-05 07:52:32 +00:00
if (pref.Exists("DaySplitTime")) {
QTime t=pref["DaySplitTime"].toTime();
ui->timeEdit->setTime(t);
}
int val;
2011-08-05 07:52:32 +00:00
if (pref.Exists("CombineCloserSessions")) {
val=pref["CombineCloserSessions"].toInt();
ui->combineSlider->setValue(val);
} else {
ui->combineSlider->setValue(val=0);
pref["CombineCloserSessions"]=val;
2011-08-05 07:52:32 +00:00
}
if (val>0) {
ui->combineLCD->display(val);
} else ui->combineLCD->display(tr("OFF"));
2011-08-05 07:52:32 +00:00
if (pref.Exists("IgnoreShorterSessions")) {
val=pref["IgnoreShorterSessions"].toInt();
ui->IgnoreSlider->setValue(val);
} else {
ui->IgnoreSlider->setValue(val=0);
pref["IgnoreShorterSessions"]=val;
2011-08-05 07:52:32 +00:00
}
if (val>0) {
ui->IgnoreLCD->display(val);
} else ui->IgnoreLCD->display(tr("OFF"));
bool b;
2011-08-05 07:52:32 +00:00
if (pref.Exists("MemoryHog")) {
b=pref["MemoryHog"].toBool();
} else {
pref["MemoryHog"]=b=false;
2011-08-05 07:52:32 +00:00
}
ui->memoryHogCheckbox->setChecked(b);
2011-08-05 07:52:32 +00:00
2011-08-03 03:09:57 +00:00
ui->eventTable->setColumnWidth(0,40);
ui->eventTable->setColumnWidth(1,55);
2011-08-03 03:09:57 +00:00
int row=0;
QTableWidgetItem *item;
QHash<ChannelID, Channel>::iterator ci;
for (ci=channel.begin();ci!=channel.end();ci++) {
if ((ci.value().channeltype()==CT_Event) || (ci.value().channeltype()==CT_Graph)) {
ui->eventTable->insertRow(row);
item=new QTableWidgetItem(ci.value().details());
ui->eventTable->setItem(row,2,item);
QCheckBox *c=new QCheckBox(ui->eventTable);
c->setChecked(true);
2011-08-03 03:09:57 +00:00
QLabel *pb=new QLabel(ui->eventTable);
pb->setText("foo");
ui->eventTable->setCellWidget(row,0,c);
ui->eventTable->setCellWidget(row,1,pb);
2011-08-06 01:42:36 +00:00
QColor a(rand() % 255, rand() % 255, rand() % 255, 255);
2011-08-03 03:09:57 +00:00
QPalette p(a,a,a,a,a,a,a);
pb->setPalette(p);
pb->setAutoFillBackground(true);
pb->setBackgroundRole(QPalette::Background);
row++;
}
}
2011-09-12 05:18:31 +00:00
QLocale locale=QLocale::system();
QString shortformat=locale.dateFormat(QLocale::ShortFormat);
if (!shortformat.toLower().contains("yyyy")) {
shortformat.replace("yy","yyyy");
}
ui->dobEdit->setDisplayFormat(shortformat);
ui->profileTab->setTabOrder(ui->firstNameEdit,ui->lastNameEdit);
ui->profileTab->setTabOrder(ui->lastNameEdit,ui->addressEdit);
ui->profileTab->setTabOrder(ui->addressEdit,ui->genderMale);
ui->profileTab->setTabOrder(ui->genderMale,ui->genderFemale);
ui->profileTab->setTabOrder(ui->genderFemale,ui->dobEdit);
ui->profileTab->setTabOrder(ui->dobEdit,ui->heightEdit);
ui->profileTab->setTabOrder(ui->heightEdit,ui->phoneEdit);
ui->profileTab->setTabOrder(ui->phoneEdit,ui->timeZoneCombo);
ui->profileTab->setTabOrder(ui->timeZoneCombo,ui->emailEdit);
ui->profileTab->setTabOrder(ui->emailEdit,ui->unitCombo);
2011-08-03 03:09:57 +00:00
}
2011-08-05 07:52:32 +00:00
2011-08-02 22:37:15 +00:00
PreferencesDialog::~PreferencesDialog()
{
delete ui;
}
2011-08-03 03:09:57 +00:00
void PreferencesDialog::on_eventTable_doubleClicked(const QModelIndex &index)
{
int row=index.row();
int col=index.column();
if (col==1) {
QWidget *w=ui->eventTable->cellWidget(row,col);
QColorDialog a;
QColor color=w->palette().background().color();
a.setCurrentColor(color);
if (a.exec()==QColorDialog::Accepted) {
QColor c=a.currentColor();
QPalette p(c,c,c,c,c,c,c);
w->setPalette(p);
qDebug() << "Color accepted" << col;
}
}
}
2011-08-05 07:52:32 +00:00
void PreferencesDialog::Save()
2011-08-05 07:52:32 +00:00
{
(*profile)["FirstName"]=ui->firstNameEdit->text();
(*profile)["LastName"]=ui->lastNameEdit->text();
2011-09-12 12:32:47 +00:00
if (ui->genderMale->isChecked())
(*profile)["Gender"]="male";
else (*profile)["Gender"]="female";
(*profile)["Height"]=ui->heightEdit->value();
(*profile)["DOB"]=ui->dobEdit->date();
(*profile)["EmailAddress"]=ui->emailEdit->text();
(*profile)["Phone"]=ui->phoneEdit->text();
(*profile)["Address"]=ui->addressEdit->toPlainText();
(*profile)["UnitSystem"]=ui->unitCombo->currentText();
(*profile)["TimeZone"]=ui->timeZoneCombo->currentText();
pref["CombineCloserSessions"]=ui->combineSlider->value();
pref["IgnoreShorterSessions"]=ui->IgnoreSlider->value();
pref["MemoryHog"]=ui->memoryHogCheckbox->isChecked();
2011-08-05 07:52:32 +00:00
pref["DaySplitTime"]=ui->timeEdit->time();
profile->Save();
pref.Save();
2011-08-05 07:52:32 +00:00
}
void PreferencesDialog::on_combineSlider_sliderMoved(int position)
2011-08-05 07:52:32 +00:00
{
if (position>0) {
ui->combineLCD->display(position);
} else ui->combineLCD->display(tr("OFF"));
}
void PreferencesDialog::on_IgnoreSlider_sliderMoved(int position)
2011-08-05 07:52:32 +00:00
{
if (position>0) {
ui->IgnoreLCD->display(position);
} else ui->IgnoreLCD->display(tr("OFF"));
}