2 /*******************************************************************************
4 This file is part of mDictionary.
6 mDictionary is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 mDictionary is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
19 Copyright 2010 Comarch S.A.
21 *******************************************************************************/
23 //Created by Mateusz Półrola
25 #include "WordListWidget.h"
27 #include "../../includes/translation.h"
29 #include "WordListProxyStyle.h"
33 #include <QMaemo5InformationBox>
36 WordListWidget::WordListWidget(QWidget *parent):
39 model = new QStandardItemModel(this);
41 setHeaderHidden(true);
42 setRootIsDecorated(false);
43 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
45 setStyle(new WordListProxyStyle);
54 void WordListWidget::addWord(QString word, int row) {
55 QStandardItem* item = new QStandardItem(word);
56 item->setFlags(item->flags() ^ Qt::ItemIsEditable);
57 QStandardItem* itemCheckBox = new QStandardItem();
58 itemCheckBox->setFlags(itemCheckBox->flags() ^ Qt::ItemIsEditable |
59 Qt::ItemIsUserCheckable);
61 bool bookmark = false;
63 foreach(t, searchResult[word]) {
71 itemCheckBox->setCheckState(Qt::Checked);
73 itemCheckBox->setCheckState(Qt::Unchecked);
75 model->setItem(row,0, item);
76 model->setItem(row,1, itemCheckBox);
80 void WordListWidget::showSearchResults(
81 QHash<QString, QList<Translation *> > result) {
85 model->setColumnCount(2);
86 model->setRowCount(result.count());
88 searchResult = result;
90 QHash<QString, QList<Translation*> >::iterator i;
91 for(i = result.begin(); i != result.end(); i++) {
92 addWord(i.key(), row++);
99 void WordListWidget::wordClicked(QModelIndex index) {
100 emit showTranslation(
101 searchResult[index.data().toString()]);
104 void WordListWidget::wordChecked(QModelIndex index) {
105 Qt::CheckState state =
106 Qt::CheckState(index.data(Qt::CheckStateRole).toInt());
108 if(selectedIndexes().count()==0) return;
109 QModelIndex item = selectedIndexes().at(0);
110 if(!item.isValid()) return;
112 if(state == Qt::Checked) {
113 emit addBookmark(searchResult[item.data().toString()]);
116 emit removeBookmark(searchResult[item.data().toString()]);
121 void WordListWidget::mouseReleaseEvent(QMouseEvent *event) {
122 QTreeView::mouseReleaseEvent(event);
125 QModelIndex index = indexAt(event->pos());
126 if(!index.isValid()) return;
127 if(selectedIndexes().count() == 0) return;
129 if(selectedIndexes().at(0) != index && selectedIndexes().at(1) != index)
132 int c = index.column();
139 void WordListWidget::resizeEvent(QResizeEvent *event) {
141 QTreeView::resizeEvent(event);
144 void WordListWidget::resizeColumns() {
145 setColumnWidth(0, viewport()->width() -checkBoxWidth - 20);
146 setColumnWidth(1, checkBoxWidth);
149 void WordListWidget::lockList() {
153 void WordListWidget::unlockList() {