7e5837259c76890668d8664c9f865c4a62bf61f4
[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 //! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
24
25 #include "HistoryListDialog.h"
26
27 HistoryListDialog::HistoryListDialog(QStringList words, QWidget *parent):
28         QDialog(parent)
29 {
30     verticalLayout = new QVBoxLayout(this);
31     setLayout(verticalLayout);
32
33     #ifndef Q_WS_MAEMO_5
34         setWindowFlags(Qt::Popup);
35         QLabel* title = new QLabel(tr("History"));
36         verticalLayout->addWidget(title,0, Qt::AlignCenter);
37     #endif
38
39     oryginalList = words;
40
41     historyListWidget = new QListWidget(this);
42     verticalLayout->addWidget(historyListWidget);
43
44     for(int i=0; i<words.count(); i++) {
45         QListWidgetItem* item = new QListWidgetItem(
46                 QString::number(i+1) + ". " + words[i]);
47         historyListWidget->addItem(item);
48     }
49
50      setModal(true);
51
52      setWindowTitle(tr("History"));
53
54      setMinimumHeight(300);
55
56      connect(historyListWidget, SIGNAL(activated(QModelIndex)),
57              this, SLOT(itemClicked(QModelIndex)));
58 }
59
60
61 void HistoryListDialog::itemClicked(QModelIndex index) {
62     _selectedWord = oryginalList[index.row()];
63     _selectedRow = index.row();
64     accept();
65 }
66
67
68 QString HistoryListDialog::selectedWord() {
69     return _selectedWord;
70 }
71
72 int HistoryListDialog::selectedRow() {
73     return _selectedRow;
74 }
75
76 int HistoryListDialog::exec() {
77     historyListWidget->setFocus();
78     QDialog::exec();
79 }