cleanup
[tomamp] / tomamp / optiondialog.cpp
1 #include <QtGui>
2 #include "optiondialog.h"
3
4 OptionDialog::OptionDialog(QWidget *parent, QSettings& set) :
5     QDialog(parent), settings (set)
6 {
7     availableHeaders = settings.value("headerOrder", QStringList()).toStringList();
8     if (!availableHeaders.size())
9         availableHeaders << "Artist" << "Title" << "Album" << "Controls";
10     setupUi();
11 }
12
13 OptionDialog::~OptionDialog ()
14 {
15 #ifdef Q_WS_MAEMO_5
16     settings.setValue("orientation", orient->currentText());
17 #endif
18     settings.setValue("headerOrder", availableHeaders);
19     QStringList h;
20     foreach (QObject* child, children())
21     {
22         QCheckBox* cb = qobject_cast<QCheckBox*>(child);
23         if (cb && cb->isChecked ())
24         {
25             h << cb->text ();
26         }
27     }
28     settings.setValue("headers", h);
29 }
30
31
32 void OptionDialog::setupUi()
33 {
34     QVBoxLayout *mainLayout = new QVBoxLayout;
35 #ifdef Q_WS_MAEMO_5
36     QString ori = settings.value("orientation", "Automatic").toString();
37     orient = new QComboBox();
38     orient->addItem(tr ("Automatic"));
39     orient->addItem(tr ("Landscape"));
40     orient->addItem(tr ("Portrait"));
41     if (ori == "Landscape")
42         orient->setCurrentIndex(1);
43     if (ori == "Portrait")
44         orient->setCurrentIndex(2);
45     QLabel *label = new QLabel (tr ("Orientation"));
46     QHBoxLayout *subLayout = new QHBoxLayout;
47     subLayout->addWidget(label);
48     subLayout->addWidget(orient);
49     mainLayout->addLayout(subLayout);
50 #endif
51     QLabel* lab = new QLabel (tr ("Enabled columns: "));
52     QHBoxLayout *sub = new QHBoxLayout;
53     sub->addWidget(lab);
54     headerLayout = new QVBoxLayout;
55     QStringList headers = settings.value ("headers", QStringList ()).toStringList();
56     qDebug () << "Available headers: " << availableHeaders;
57     foreach (QString str, availableHeaders)
58     {\
59         QHBoxLayout *cont = new QHBoxLayout;
60         QCheckBox* box = new QCheckBox (str);
61         if (headers.indexOf(str) >= 0)
62             box->setChecked(true);
63         QLabel* label = new QLabel;
64         label->setText(QString::fromUtf8("<b><a style='text-decoration:none' href='up'>▲</a> <a style='text-decoration:none' href='down'>▼</a></b>"));
65         label->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
66         label->setProperty("row", str);
67         cont->addWidget(box);
68         cont->addWidget(label);
69         headerLayout->addLayout(cont);
70         connect (label, SIGNAL(linkActivated(QString)), this, SLOT (orderControl(QString)));
71     }
72     sub->addLayout(headerLayout);
73     mainLayout->addLayout(sub);
74     QCheckBox *cb = new QCheckBox (tr ("Flip UI controls"));
75     cb->setChecked(settings.value("uiflipped", false).toBool());
76     connect (cb, SIGNAL(toggled(bool)), this, SLOT(toggleFlip(bool)));
77     mainLayout->addWidget(cb);
78     setLayout(mainLayout);
79     setWindowTitle("Settings");
80 }
81
82 void OptionDialog::toggleFlip (bool val)
83 {
84     settings.setValue("uiflipped", val);
85 }
86
87
88 void OptionDialog::orderControl (QString link)
89 {
90     QString str = sender ()->property("row").toString();
91     qDebug () << "Col action " << link << " on " << str;
92     int i = availableHeaders.indexOf(str);
93     if (link == "up" && i > 0)
94     {
95         QString tmp = availableHeaders[i];
96         availableHeaders[i] = availableHeaders[i - 1];
97         availableHeaders[i - 1] = tmp;
98     }
99     else if (link == "down" && i < availableHeaders.size() - 1)
100     {
101         QString tmp = availableHeaders[i];
102         availableHeaders[i] = availableHeaders[i + 1];
103         availableHeaders[i + 1] = tmp;
104     }
105     QStringList h;
106     foreach (QObject* child, children())
107     {
108         QCheckBox* cb = qobject_cast<QCheckBox*>(child);
109         if (cb && cb->isChecked ())
110         {
111             h << cb->text ();
112         }
113     }
114     settings.setValue("headers", h);
115     delete layout ();
116     foreach (QObject* child, children ())
117         delete child;
118 //    update ();
119     setupUi();
120 }
121
122