Fixed some inconsistencies in code indentation
[jenirok] / src / gui / buttonselector.cpp
1 /*
2  * This file is part of Jenirok.
3  *
4  * Jenirok is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Jenirok is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Jenirok.  If not, see <http://www.gnu.org/licenses/>.
16  *
17  */
18
19 #include <QtGui/QStandardItem>
20 #include "buttonselector.h"
21
22 ButtonSelector::ButtonSelector(QString const& text, QWidget* parent):
23 QMaemo5ValueButton(text, parent), selector_(0), model_(0)
24 {
25     setValueLayout(QMaemo5ValueButton::ValueBesideText);
26     selector_ = new QMaemo5ListPickSelector(this);
27     model_ = new QStandardItemModel(0, 1);
28     selector_->setModel(model_);
29     setPickSelector(selector_);
30 }
31
32 void ButtonSelector::addItem(QString const& text)
33 {
34     addItem(text, QVariant(text));
35 }
36
37 void ButtonSelector::addItem(QString const& text, QVariant const& value)
38 {
39     QStandardItem* item = new QStandardItem(text);
40     item->setData(value, Qt::UserRole);
41     item->setTextAlignment(Qt::AlignCenter);
42     item->setEditable(false);
43     model_->appendRow(item);
44
45     if(selector_->currentIndex() < 0)
46     {
47         selector_->setCurrentIndex(0);
48     }
49 }
50
51 void ButtonSelector::clear()
52 {
53     model_->clear();
54 }
55
56 void ButtonSelector::setCurrentIndex(int index)
57 {
58     selector_->setCurrentIndex(index);
59 }
60
61 int ButtonSelector::currentIndex() const
62 {
63     return selector_->currentIndex();
64 }
65
66 QString ButtonSelector::text() const
67 {
68     return selector_->currentValueText();
69 }
70
71 QVariant ButtonSelector::value() const
72 {
73     int currentIndex = selector_->currentIndex();
74
75     if(currentIndex < 0)
76     {
77         return QVariant("");
78     }
79
80     QStandardItem* item = model_->item(currentIndex);
81
82     return item->data(Qt::UserRole);
83 }