1 /*******************************************************************************
3 This file is part of mDictionary.
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.
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.
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/>.
18 Copyright 2010 Comarch S.A.
20 *******************************************************************************/
22 /*! \file HistoryListDialog.cpp
23 \brief Implements history list dialog
25 \author Mateusz Półrola <mateusz.polrola@comarch.pl>
28 #include "HistoryListDialog.h"
30 HistoryListDialog::HistoryListDialog(QStringList words, QWidget *parent):
34 verticalLayout = new QVBoxLayout(this);
35 setLayout(verticalLayout);
37 setWindowFlags(Qt::Popup);
41 HistoryListModel *model=new HistoryListModel(words,this);
42 view= new QDeclarativeView();
43 QDeclarativeContext* ctxt=view->rootContext();
44 ctxt->setContextProperty("historyTypeModel", model);
45 view->setSource(QUrl::fromLocalFile("/usr/share/mdictionary/qml/HistoryListDialog.qml"));
46 view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
47 view->setAlignment(Qt::AlignCenter);
50 view->setMinimumWidth(250);
51 view->setMaximumWidth(250);
52 view->setMinimumHeight(300);
53 view->setWindowFlags(Qt::Popup);
54 verticalLayout->addWidget(view);
56 QGraphicsObject *rootObject = view->rootObject();
58 connect(rootObject,SIGNAL(selectedRow(int)),
59 this,SLOT(itemClicked(int)));
63 setWindowFlags(Qt::Popup);
64 QLabel* title = new QLabel(tr("History"));
65 verticalLayout->addWidget(title,0, Qt::AlignCenter);
67 historyListWidget = new QListWidget(this);
68 verticalLayout->addWidget(historyListWidget);
70 for(int i=0; i<words.count(); i++) {
71 QListWidgetItem* item = new QListWidgetItem(
72 QString::number(i+1) + ". " + words[i]);
73 historyListWidget->addItem(item);
76 setWindowTitle(tr("History"));
78 setMinimumHeight(300);
80 connect(historyListWidget, SIGNAL(activated(QModelIndex)),
81 this, SLOT(itemClicked(QModelIndex)));
86 void HistoryListDialog::itemClicked(QModelIndex index) {
87 _selectedWord = oryginalList[index.row()];
88 _selectedRow = index.row();
92 void HistoryListDialog::itemClicked(int index) {
93 _selectedWord = oryginalList[index];
98 QString HistoryListDialog::selectedWord() {
102 int HistoryListDialog::selectedRow() {
106 int HistoryListDialog::exec() {
110 historyListWidget->setFocus();