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 \author Mateusz Półrola <mateusz.polrola@comarch.com>
26 #include "XdxfDictSelectDialog.h"
28 XdxfDictSelectDialog::XdxfDictSelectDialog(QList<DownloadDict> dicts,
31 setWindowTitle(tr("Select dictionary"));
33 layout = new QVBoxLayout;
36 checkBoxLayout = new QHBoxLayout;
37 layout->addLayout(checkBoxLayout);
39 langFrom = new QComboBox;
40 langTo = new QComboBox;
42 langFrom->setInsertPolicy(QComboBox::InsertAlphabetically);
43 langTo->setInsertPolicy(QComboBox::InsertAlphabetically);
45 langFromLabel = new QLabel(tr("From "));
46 langToLabel = new QLabel(tr("To "));
48 checkBoxLayout->addWidget(langFromLabel);
49 checkBoxLayout->addWidget(langFrom, 10);
50 checkBoxLayout->addWidget(langToLabel);
51 checkBoxLayout->addWidget(langTo, 10);
53 //here removing already added dictionary
55 for (int i = 0; i < dicts.size(); i++){
56 if(QFile::exists(QDir::homePath() + "/.mdictionary/" + dicts[i].title() + ".xdxf")){
62 model = new DictsModel(dicts, this);
64 proxyModel = new DictsProxyModel;
65 proxyModel->setDynamicSortFilter(true);
66 proxyModel->setSourceModel(model);
68 treeView = new QTreeView;
69 treeView->setModel(proxyModel);
70 treeView->setRootIsDecorated(false);
71 treeView->setExpandsOnDoubleClick(false);
73 treeView->setSortingEnabled(true);
74 treeView->sortByColumn(0, Qt::AscendingOrder);
76 treeView->setWordWrap(true);
79 treeView->resizeColumnToContents(0);
80 treeView->resizeColumnToContents(1);
81 treeView->setColumnWidth(2, 300);
82 treeView->resizeColumnToContents(3);
84 treeView->setColumnWidth(0, 150);
85 treeView->setColumnWidth(1, 150);
86 treeView->setColumnWidth(2, 300);
87 treeView->setColumnWidth(3, 150);
90 layout->addWidget(treeView);
92 connect(langFrom, SIGNAL(currentIndexChanged(int)),
93 this, SLOT(refreshDictList()));
95 connect(langTo, SIGNAL(currentIndexChanged(int)),
96 this, SLOT(refreshDictList()));
98 connect(treeView, SIGNAL(activated(QModelIndex)),
99 this, SLOT(itemClicked(QModelIndex)));
102 setMinimumSize(800,500);
104 setMinimumHeight(350);
111 void XdxfDictSelectDialog::initializeDicts() {
112 //scan of all languages of dictionaries, using QSet to get only distinct languages
113 QSet<QString> languagesFrom;
114 QSet<QString> languagesTo;
116 for(int i=0; i < model->rowCount(QModelIndex()); i++) {
117 languagesFrom.insert(
118 model->data(model->index(i, 0, QModelIndex())).toString());
120 model->data(model->index(i, 1, QModelIndex())).toString());
123 //removes one dictionary which from and to languages are empty....
124 //bug in site with dictionaries
125 languagesFrom.remove(QString());
126 languagesTo.remove(QString());
128 //sorting of found languages
129 QList<QString> langFromList = languagesFrom.toList();
132 QList<QString> langToList = languagesTo.toList();
135 //and adding them to combobox, first item in each combobox is "Any"
136 langFrom->addItem(tr("Any"));
137 for(int i=0; i < langFromList.count(); i++) {
138 langFrom->addItem(langFromList.at(i));
141 langTo->addItem(tr("Any"));
142 for(int i=0; i < langToList.count(); i++) {
143 langTo->addItem(langToList.at(i));
148 void XdxfDictSelectDialog::refreshDictList() {
149 //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.
150 if(langTo->currentIndex() == 0)
151 proxyModel->setTo(QString());
153 proxyModel->setTo(langTo->currentText());
155 if(langFrom->currentIndex() == 0)
156 proxyModel->setFrom(QString());
158 proxyModel->setFrom(langFrom->currentText());
162 void XdxfDictSelectDialog::itemClicked(QModelIndex index) {
163 _link = index.model()->data(index, Qt::UserRole).toString();