Added setup edit dialog and a string list widget. WARNING: The changes
[emufront] / src / widgets / stringlistwidget.cpp
1 // EmuFront
2 // Copyright 2010 Mikko Keinänen
3 //
4 // This file is part of EmuFront.
5 //
6 //
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.
11 //
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.
16 //
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/>.
19
20 #include "stringlistwidget.h"
21 #include <QtGui>
22
23 StringListWidget::StringListWidget(QWidget *parent, bool sort, int sortIndex) :
24     QWidget(parent), sort(sort), sortIndex(sortIndex)
25 {
26     //model = new QStringListModel(this);
27     initUi();
28     connectSignals();
29 }
30
31 void StringListWidget::initUi()
32 {
33     stringList = new QListWidget(this);
34     //stringList->setModel(model);
35     btnAdd = new QPushButton(tr("&Add"), this);
36     btnRemove = new QPushButton(tr("&Remove"), this);
37
38     QVBoxLayout *rightLayout = new QVBoxLayout;
39     rightLayout->addWidget(btnAdd);
40     rightLayout->addWidget(btnRemove);
41     rightLayout->addStretch();
42
43     QHBoxLayout *mainLayout = new QHBoxLayout;
44     mainLayout->addWidget(stringList);
45     mainLayout->addLayout(rightLayout);
46
47     setLayout(mainLayout);
48 }
49
50 void StringListWidget::connectSignals()
51 {
52     connect(btnAdd, SIGNAL(clicked()), this, SLOT(addClicked()));
53     connect(btnRemove, SIGNAL(clicked()), this, SLOT(removeClicked()));
54 }
55
56 void StringListWidget::addClicked()
57 {
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();
63     l << input;
64     model->setStringList(l);
65     if (sort) model->sort(sortIndex);*/
66     //emit stringListUpdated;
67 }
68
69 void StringListWidget::removeClicked()
70 {
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)
76     {
77         if (!i.isValid()) continue;
78         int row = i.row();
79         model->removeRows(row, 1);
80     }*/
81     //emit stringListUpdated;
82 }
83
84 QStringList StringListWidget::getItems()
85 {
86     //return model->stringList();
87     QStringList l;
88     return l;
89 }
90
91 void StringListWidget::setItems(QStringList list)
92 {
93     //model->setStringList(list);
94 }