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 XdxfDictSelectDialog.cpp
23 \brief Shows dialog with list of dictionaries allowing user
24 to select one of them.
26 \author Mateusz Półrola <mateusz.polrola@comarch.com>
29 #include "XdxfDictSelectDialog.h"
31 XdxfDictSelectDialog::XdxfDictSelectDialog(QList<DownloadDict> dicts,
34 setWindowTitle(tr("Select dictionary"));
36 layout = new QVBoxLayout;
39 checkBoxLayout = new QHBoxLayout;
40 layout->addLayout(checkBoxLayout);
42 langFrom = new QComboBox;
43 langTo = new QComboBox;
45 langFrom->setInsertPolicy(QComboBox::InsertAlphabetically);
46 langTo->setInsertPolicy(QComboBox::InsertAlphabetically);
48 langFromLabel = new QLabel(tr("From "));
49 langToLabel = new QLabel(tr("To "));
51 checkBoxLayout->addWidget(langFromLabel);
52 checkBoxLayout->addWidget(langFrom, 10);
53 checkBoxLayout->addWidget(langToLabel);
54 checkBoxLayout->addWidget(langTo, 10);
56 //here removing already added dictionary
58 for (int i = 0; i < dicts.size(); i++){
59 if(QFile::exists(QDir::homePath() + "/.mdictionary/" + dicts[i].title() + ".xdxf")){
65 model = new DictsModel(dicts, this);
67 proxyModel = new DictsProxyModel;
68 proxyModel->setDynamicSortFilter(true);
69 proxyModel->setSourceModel(model);
71 treeView = new QTreeView;
72 treeView->setModel(proxyModel);
73 treeView->setRootIsDecorated(false);
74 treeView->setExpandsOnDoubleClick(false);
76 treeView->setSortingEnabled(true);
77 treeView->sortByColumn(0, Qt::AscendingOrder);
79 treeView->setWordWrap(true);
82 treeView->resizeColumnToContents(0);
83 treeView->resizeColumnToContents(1);
84 treeView->setColumnWidth(2, 300);
85 treeView->resizeColumnToContents(3);
87 treeView->setColumnWidth(0, 150);
88 treeView->setColumnWidth(1, 150);
89 treeView->setColumnWidth(2, 300);
90 treeView->setColumnWidth(3, 150);
93 layout->addWidget(treeView);
95 connect(langFrom, SIGNAL(currentIndexChanged(int)),
96 this, SLOT(refreshDictList()));
98 connect(langTo, SIGNAL(currentIndexChanged(int)),
99 this, SLOT(refreshDictList()));
101 connect(treeView, SIGNAL(activated(QModelIndex)),
102 this, SLOT(itemClicked(QModelIndex)));
105 setMinimumSize(800,500);
107 setMinimumHeight(350);
114 void XdxfDictSelectDialog::initializeDicts() {
115 //scan of all languages of dictionaries, using QSet to get only distinct languages
116 QSet<QString> languagesFrom;
117 QSet<QString> languagesTo;
119 for(int i=0; i < model->rowCount(QModelIndex()); i++) {
120 languagesFrom.insert(
121 model->data(model->index(i, 0, QModelIndex())).toString());
123 model->data(model->index(i, 1, QModelIndex())).toString());
126 //removes one dictionary which from and to languages are empty....
127 //bug in site with dictionaries
128 languagesFrom.remove(QString());
129 languagesTo.remove(QString());
131 //sorting of found languages
132 QList<QString> langFromList = languagesFrom.toList();
135 QList<QString> langToList = languagesTo.toList();
138 //and adding them to combobox, first item in each combobox is "Any"
139 langFrom->addItem(tr("Any"));
140 for(int i=0; i < langFromList.count(); i++) {
141 langFrom->addItem(langFromList.at(i));
144 langTo->addItem(tr("Any"));
145 for(int i=0; i < langToList.count(); i++) {
146 langTo->addItem(langToList.at(i));
151 void XdxfDictSelectDialog::refreshDictList() {
152 //if selected language is "Any"(index 0), from filter string is set to empty string, proxy model uses empty string as special case and don't filter by this field.
153 if(langTo->currentIndex() == 0)
154 proxyModel->setTo(QString());
156 proxyModel->setTo(langTo->currentText());
158 if(langFrom->currentIndex() == 0)
159 proxyModel->setFrom(QString());
161 proxyModel->setFrom(langFrom->currentText());
165 void XdxfDictSelectDialog::itemClicked(QModelIndex index) {
166 _link = index.model()->data(index, Qt::UserRole).toString();