0.7.1
[fapman] / filterselect.cpp
1 /*
2         This file is part of Faster Application Manager.
3
4         Faster Application Manager 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         Faster Application Manager 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 Faster Application Manager.  If not, see <http://www.gnu.org/licenses/>.
16
17         (C) Heikki Holstila 2010
18 */
19
20 #include "filterselect.h"
21 #include "ui_filterselect.h"
22
23 FilterSelect::FilterSelect(QString title, QWidget *parent) :
24     QDialog(parent),
25     ui(new Ui::FilterSelect)
26 {
27     ui->setupUi(this);
28         connect(ui->listWidget,SIGNAL(itemActivated(QListWidgetItem*)),this,SLOT(accept()));
29         this->setWindowTitle(title);
30 }
31
32 FilterSelect::~FilterSelect()
33 {
34     delete ui;
35 }
36
37 void FilterSelect::changeEvent(QEvent *e)
38 {
39     QDialog::changeEvent(e);
40     switch (e->type()) {
41     case QEvent::LanguageChange:
42         ui->retranslateUi(this);
43         break;
44     default:
45         break;
46     }
47 }
48
49 void FilterSelect::setList(QStringList labels, int selected)
50 {
51         ui->listWidget->addItems(labels);
52         ui->listWidget->item(selected)->setSelected(true);
53 }
54
55 int FilterSelect::selection()
56 {
57         for( int i=0; i<ui->listWidget->count(); i++)
58         {
59                 if( ui->listWidget->item(i)->isSelected() )
60                         return i;
61         }
62
63         return 0;
64 }