Clean and order documentation in source files. Source ready to beta 2 release
[mdictionary] / src / mdictionary / gui / HistoryListDialog.cpp
1 /*******************************************************************************
2
3     This file is part of mDictionary.
4
5     mDictionary is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9
10     mDictionary is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
17
18     Copyright 2010 Comarch S.A.
19
20 *******************************************************************************/
21
22 /*! \file HistoryListDialog.cpp
23     \brief Implements history list dialog
24
25     \author Mateusz Półrola <mateusz.polrola@comarch.pl>
26 */
27
28 #include "HistoryListDialog.h"
29
30 HistoryListDialog::HistoryListDialog(QStringList words, QWidget *parent):
31         QDialog(parent)
32 {
33     verticalLayout = new QVBoxLayout(this);
34     setLayout(verticalLayout);
35
36     #ifndef Q_WS_MAEMO_5
37         setWindowFlags(Qt::Popup);
38         QLabel* title = new QLabel(tr("History"));
39         verticalLayout->addWidget(title,0, Qt::AlignCenter);
40     #endif
41
42     oryginalList = words;
43
44     historyListWidget = new QListWidget(this);
45     verticalLayout->addWidget(historyListWidget);
46
47     for(int i=0; i<words.count(); i++) {
48         QListWidgetItem* item = new QListWidgetItem(
49                 QString::number(i+1) + ". " + words[i]);
50         historyListWidget->addItem(item);
51     }
52
53      setModal(true);
54
55      setWindowTitle(tr("History"));
56
57      setMinimumHeight(300);
58
59      connect(historyListWidget, SIGNAL(activated(QModelIndex)),
60              this, SLOT(itemClicked(QModelIndex)));
61 }
62
63
64 void HistoryListDialog::itemClicked(QModelIndex index) {
65     _selectedWord = oryginalList[index.row()];
66     _selectedRow = index.row();
67     accept();
68 }
69
70
71 QString HistoryListDialog::selectedWord() {
72     return _selectedWord;
73 }
74
75 int HistoryListDialog::selectedRow() {
76     return _selectedRow;
77 }
78
79 int HistoryListDialog::exec() {
80     historyListWidget->setFocus();
81     QDialog::exec();
82 }