2 * This file is part of Jenirok.
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.
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.
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/>.
19 #include <QtGui/QStandardItem>
20 #include "buttonselector.h"
22 ButtonSelector::ButtonSelector(QString const& text, QWidget* parent): QMaemo5ValueButton(text, parent),
23 selector_(0), model_(0)
25 setValueLayout(QMaemo5ValueButton::ValueBesideText);
26 selector_ = new QMaemo5ListPickSelector(this);
27 model_ = new QStandardItemModel(0, 1);
28 selector_->setModel(model_);
29 setPickSelector(selector_);
32 void ButtonSelector::addItem(QString const& text)
34 addItem(text, QVariant(text));
37 void ButtonSelector::addItem(QString const& text, QVariant const& value)
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);
45 if(selector_->currentIndex() < 0)
47 selector_->setCurrentIndex(0);
51 void ButtonSelector::clear()
56 void ButtonSelector::setCurrentIndex(int index)
58 selector_->setCurrentIndex(index);
61 int ButtonSelector::currentIndex() const
63 return selector_->currentIndex();
66 QString ButtonSelector::text() const
68 return selector_->currentValueText();
71 QVariant ButtonSelector::value() const
73 int currentIndex = selector_->currentIndex();
80 QStandardItem* item = model_->item(currentIndex);
82 return item->data(Qt::UserRole);