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);
50 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++);
95 setColumnWidth(0, width()-checkBoxWidth - 20);
96 setColumnWidth(1, checkBoxWidth);
97 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
100 void WordListWidget::wordClicked(QModelIndex index) {
101 emit showTranslation(
102 searchResult[index.data().toString()]);
105 void WordListWidget::wordChecked(QModelIndex index) {
106 Qt::CheckState state =
107 Qt::CheckState(index.data(Qt::CheckStateRole).toInt());
109 QModelIndex item = selectedIndexes().at(0);
111 if(state == Qt::Checked) {
112 qDebug()<<"Added "<<item.data().toString();
113 emit addBookmark(searchResult[item.data().toString()]);
116 qDebug()<<"Removed "<<item.data().toString();
117 emit removeBookmark(searchResult[item.data().toString()]);
122 void WordListWidget::mouseReleaseEvent(QMouseEvent *event) {
123 QTreeView::mouseReleaseEvent(event);
126 QModelIndex index = indexAt(event->pos());
127 if(!index.isValid()) return;
128 int c = index.column();
135 void WordListWidget::resizeEvent(QResizeEvent *event) {
136 setColumnWidth(0, width()-checkBoxWidth - 20);
137 setColumnWidth(1, checkBoxWidth);
138 QTreeView::resizeEvent(event);
141 void WordListWidget::lockList() {
145 void WordListWidget::unlockList() {