Danish Eniro search fixed.
[jenirok] / src / gui / listwidget.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/QApplication>
20 #include <QtGui/QDesktopWidget>
21 #include <QtGui/QHeaderView>
22 #include <QtCore/QDebug>
23 #include "listwidget.h"
24
25 ListWidget::ListWidget(QWidget* parent): QTableWidget(parent)
26 {
27     connect(this, SIGNAL(cellClicked(int, int)), this, SLOT(handleClick(int)));
28     setColumnCount(1);
29     verticalHeader()->hide();
30     horizontalHeader()->hide();
31     setColumnWidth(0, QApplication::desktop()->availableGeometry().width() - 10);
32     setSelectionMode(QAbstractItemView::SingleSelection);
33 }
34
35 void ListWidget::addWidget(QWidget* widget, QVariant const& data)
36 {
37     int row = rowCount();
38     setRowCount(row + 1);
39     setCellWidget(row, 0, widget);
40     data_[row] = data;
41     widgets_[row] = widget;
42     resizeRowToContents (row);
43 }
44
45 QVariant ListWidget::getData(int index) const
46 {
47     if(data_.find(index) != data_.end())
48     {
49         return data_[index];
50     }
51
52     return QVariant();
53 }
54
55 QWidget* ListWidget::getWidget(int index) const
56 {
57     if(widgets_.find(index) != widgets_.end())
58     {
59         return widgets_[index];
60     }
61
62     return 0;
63 }
64
65 void ListWidget::clear()
66 {
67     QTableWidget::clear();
68     data_.clear();
69     widgets_.clear();
70     setRowCount(0);
71 }
72
73 void ListWidget::handleClick(int index)
74 {
75     clearSelection();
76     emit itemClicked(index);
77 }