2 // Copyright 2010 Mikko Keinänen
4 // This file is part of EmuFront.
7 // EmuFront is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
12 // Foobar is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with Foobar. If not, see <http://www.gnu.org/licenses/>.
20 #include "stringlistwidget.h"
23 StringListWidget::StringListWidget(QWidget *parent, bool sort, int sortIndex) :
24 QWidget(parent), sort(sort), sortIndex(sortIndex)
26 //model = new QStringListModel(this);
31 void StringListWidget::initUi()
33 stringList = new QListWidget(this);
34 //stringList->setModel(model);
35 btnAdd = new QPushButton(tr("&Add"), this);
36 btnRemove = new QPushButton(tr("&Remove"), this);
38 QVBoxLayout *rightLayout = new QVBoxLayout;
39 rightLayout->addWidget(btnAdd);
40 rightLayout->addWidget(btnRemove);
41 rightLayout->addStretch();
43 QHBoxLayout *mainLayout = new QHBoxLayout;
44 mainLayout->addWidget(stringList);
45 mainLayout->addLayout(rightLayout);
47 setLayout(mainLayout);
50 void StringListWidget::connectSignals()
52 connect(btnAdd, SIGNAL(clicked()), this, SLOT(addClicked()));
53 connect(btnRemove, SIGNAL(clicked()), this, SLOT(removeClicked()));
56 void StringListWidget::addClicked()
58 QString input = QInputDialog::getText(this, tr("Add"), tr("Add new item"));
59 if (input.isEmpty()) return;
60 stringList->addItem(input);
61 stringList->sortItems();
62 /*QStringList l = model->stringList();
64 model->setStringList(l);
65 if (sort) model->sort(sortIndex);*/
66 //emit stringListUpdated;
69 void StringListWidget::removeClicked()
71 qDebug() << "StringListWidget::removeClicked";
72 /*QModelIndexList selected = stringList->selectedIndexes();
73 if (selected.count() < 1) return;
74 qDebug() << selected.count() << " items selected for removal.";
75 foreach(QModelIndex i, selected)
77 if (!i.isValid()) continue;
79 model->removeRows(row, 1);
81 //emit stringListUpdated;
84 QStringList StringListWidget::getItems()
86 //return model->stringList();
91 void StringListWidget::setItems(QStringList list)
93 //model->setStringList(list);