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