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 //Created by Mateusz Półrola
24 #include "WordListWidget.h"
26 #include "../../includes/translation.h"
28 #include "WordListProxyStyle.h"
32 #include <QMaemo5InformationBox>
35 WordListWidget::WordListWidget(QWidget *parent):
38 model = new QStandardItemModel(this);
40 setHeaderHidden(true);
41 setRootIsDecorated(false);
42 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
44 setStyle(new WordListProxyStyle);
53 void WordListWidget::addWord(QString word, int row) {
54 QStandardItem* item = new QStandardItem(word);
55 item->setFlags(item->flags() ^ Qt::ItemIsEditable);
56 QStandardItem* itemCheckBox = new QStandardItem();
57 itemCheckBox->setFlags(itemCheckBox->flags() ^ Qt::ItemIsEditable |
58 Qt::ItemIsUserCheckable);
60 bool bookmark = false;
62 foreach(t, searchResult[word]) {
70 itemCheckBox->setCheckState(Qt::Checked);
72 itemCheckBox->setCheckState(Qt::Unchecked);
74 model->setItem(row,0, item);
75 model->setItem(row,1, itemCheckBox);
79 void WordListWidget::showSearchResults(
80 QHash<QString, QList<Translation *> > result) {
84 model->setColumnCount(2);
85 model->setRowCount(result.count());
87 searchResult = result;
89 QHash<QString, QList<Translation*> >::iterator i;
90 for(i = result.begin(); i != result.end(); i++) {
91 addWord(i.key(), row++);
97 void WordListWidget::wordClicked(QModelIndex index) {
99 searchResult[index.data().toString()]);
102 void WordListWidget::wordChecked(QModelIndex index) {
103 Qt::CheckState state =
104 Qt::CheckState(index.data(Qt::CheckStateRole).toInt());
106 QModelIndex item = selectedIndexes().at(0);
107 if(!item.isValid()) return;
109 if(state == Qt::Checked) {
110 emit addBookmark(searchResult[item.data().toString()]);
113 emit removeBookmark(searchResult[item.data().toString()]);
118 void WordListWidget::mouseReleaseEvent(QMouseEvent *event) {
119 QTreeView::mouseReleaseEvent(event);
122 QModelIndex index = indexAt(event->pos());
123 if(!index.isValid()) return;
124 int c = index.column();
131 void WordListWidget::resizeEvent(QResizeEvent *event) {
133 QTreeView::resizeEvent(event);
136 void WordListWidget::resizeColumns() {
137 setColumnWidth(0, viewport()->width() -checkBoxWidth - 20);
138 setColumnWidth(1, checkBoxWidth);
141 void WordListWidget::lockList() {
145 void WordListWidget::unlockList() {