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 model = new DictsModel(dicts, this);
55 proxyModel = new DictsProxyModel;
56 proxyModel->setDynamicSortFilter(true);
57 proxyModel->setSourceModel(model);
59 treeView = new QTreeView;
60 treeView->setModel(proxyModel);
61 treeView->setRootIsDecorated(false);
62 treeView->setExpandsOnDoubleClick(false);
64 treeView->setSortingEnabled(true);
65 treeView->sortByColumn(0, Qt::AscendingOrder);
67 treeView->setWordWrap(true);
70 treeView->resizeColumnToContents(0);
71 treeView->resizeColumnToContents(1);
72 treeView->setColumnWidth(2, 300);
73 treeView->resizeColumnToContents(3);
75 treeView->setColumnWidth(0, 150);
76 treeView->setColumnWidth(1, 150);
77 treeView->setColumnWidth(2, 300);
78 treeView->setColumnWidth(3, 150);
81 layout->addWidget(treeView);
83 connect(langFrom, SIGNAL(currentIndexChanged(int)),
84 this, SLOT(refreshDictList()));
86 connect(langTo, SIGNAL(currentIndexChanged(int)),
87 this, SLOT(refreshDictList()));
89 connect(treeView, SIGNAL(activated(QModelIndex)),
90 this, SLOT(itemClicked(QModelIndex)));
93 setMinimumSize(800,500);
95 setMinimumHeight(350);
102 void XdxfDictSelectDialog::initializeDicts() {
103 //scan of all languages of dictionaries, using QSet to get only distinct languages
104 QSet<QString> languagesFrom;
105 QSet<QString> languagesTo;
107 for(int i=0; i < model->rowCount(QModelIndex()); i++) {
108 languagesFrom.insert(
109 model->data(model->index(i, 0, QModelIndex())).toString());
111 model->data(model->index(i, 1, QModelIndex())).toString());
114 //removes one dictionary which from and to languages are empty....
115 //bug in site with dictionaries
116 languagesFrom.remove(QString());
117 languagesTo.remove(QString());
119 //sorting of found languages
120 QList<QString> langFromList = languagesFrom.toList();
123 QList<QString> langToList = languagesTo.toList();
126 //and adding them to combobox, first item in each combobox is "Any"
127 langFrom->addItem(tr("Any"));
128 for(int i=0; i < langFromList.count(); i++) {
129 langFrom->addItem(langFromList.at(i));
132 langTo->addItem(tr("Any"));
133 for(int i=0; i < langToList.count(); i++) {
134 langTo->addItem(langToList.at(i));
139 void XdxfDictSelectDialog::refreshDictList() {
140 //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.
141 if(langTo->currentIndex() == 0)
142 proxyModel->setTo(QString());
144 proxyModel->setTo(langTo->currentText());
146 if(langFrom->currentIndex() == 0)
147 proxyModel->setFrom(QString());
149 proxyModel->setFrom(langFrom->currentText());
153 void XdxfDictSelectDialog::itemClicked(QModelIndex index) {
154 _link = index.model()->data(index, Qt::UserRole).toString();