working optins with orientation and column order/selection
[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     setLayout(mainLayout);
75     setWindowTitle("Settings");
76 }
77
78 void OptionDialog::orderControl (QString link)
79 {
80     QString str = sender ()->property("row").toString();
81     qDebug () << "Col action " << link << " on " << str;
82     int i = availableHeaders.indexOf(str);
83     if (link == "up" && i > 0)
84     {
85         QString tmp = availableHeaders[i];
86         availableHeaders[i] = availableHeaders[i - 1];
87         availableHeaders[i - 1] = tmp;
88     }
89     else if (link == "down" && i < availableHeaders.size() - 1)
90     {
91         QString tmp = availableHeaders[i];
92         availableHeaders[i] = availableHeaders[i + 1];
93         availableHeaders[i + 1] = tmp;
94     }
95     QStringList h;
96     foreach (QObject* child, children())
97     {
98         QCheckBox* cb = qobject_cast<QCheckBox*>(child);
99         if (cb && cb->isChecked ())
100         {
101             h << cb->text ();
102         }
103     }
104     settings.setValue("headers", h);
105     delete layout ();
106     foreach (QObject* child, children ())
107         delete child;
108 //    update ();
109     setupUi();
110 }
111
112 void OptionDialog::upColumn (int i)
113 {
114 }
115
116 void OptionDialog::downColumn (int i)
117 {
118 }
119