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 "XdxfDictSelectDialog.h"
26 XdxfDictSelectDialog::XdxfDictSelectDialog(QList<DownloadDict> dicts,
30 layout = new QVBoxLayout;
33 checkBoxLayout = new QHBoxLayout;
34 layout->addLayout(checkBoxLayout);
36 langFrom = new QComboBox;
37 langTo = new QComboBox;
39 langFrom->setInsertPolicy(QComboBox::InsertAlphabetically);
40 langTo->setInsertPolicy(QComboBox::InsertAlphabetically);
42 checkBoxLayout->addWidget(langFrom);
43 checkBoxLayout->addWidget(langTo);
45 model = new DictsModel(dicts, this);
47 proxyModel = new DictsProxyModel;
48 proxyModel->setDynamicSortFilter(true);
49 proxyModel->setSourceModel(model);
52 treeView = new QTreeView;
53 treeView->setModel(proxyModel);
54 treeView->setRootIsDecorated(false);
55 treeView->setExpandsOnDoubleClick(false);
57 treeView->setSortingEnabled(true);
58 treeView->sortByColumn(0, Qt::AscendingOrder);
60 treeView->resizeColumnToContents(0);
61 treeView->resizeColumnToContents(1);
62 treeView->resizeColumnToContents(2);
63 treeView->resizeColumnToContents(3);
65 // treeView->sortByColumn(0);
67 layout->addWidget(treeView);
70 connect(langFrom, SIGNAL(currentIndexChanged(int)),
71 this, SLOT(refreshDictList()));
73 connect(langTo, SIGNAL(currentIndexChanged(int)),
74 this, SLOT(refreshDictList()));
76 connect(treeView, SIGNAL(activated(QModelIndex)),
77 this, SLOT(itemClicked(QModelIndex)));
80 setMinimumSize(400,200);
82 setMinimumHeight(350);
89 void XdxfDictSelectDialog::initializeDicts() {
91 QSet<QString> languagesFrom;
92 QSet<QString> languagesTo;
94 for(int i=0; i < model->rowCount(QModelIndex()); i++) {
96 model->data(model->index(i, 0, QModelIndex())).toString());
98 model->data(model->index(i, 1, QModelIndex())).toString());
101 languagesFrom.remove(QString());
102 languagesTo.remove(QString());
104 QList<QString> langFromList = languagesFrom.toList();
107 QList<QString> langToList = languagesTo.toList();
110 langFrom->addItem(tr("Any"));
111 for(int i=0; i < langFromList.count(); i++) {
112 langFrom->addItem(langFromList.at(i));
115 langTo->addItem(tr("Any"));
116 for(int i=0; i < langToList.count(); i++) {
117 langTo->addItem(langToList.at(i));
121 void XdxfDictSelectDialog::refreshDictList() {
122 if(langTo->currentIndex() == 0)
123 proxyModel->setTo(QString());
125 proxyModel->setTo(langTo->currentText());
127 if(langFrom->currentIndex() == 0)
128 proxyModel->setFrom(QString());
130 proxyModel->setFrom(langFrom->currentText());
133 void XdxfDictSelectDialog::itemClicked(QModelIndex index) {
134 _link = index.model()->data(index, Qt::UserRole).toString();