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 *******************************************************************************/
23 \file XdxfDictSelectDialog.cpp
24 \author Mateusz Półrola <mateusz.polrola@comarch.com>
27 #include "XdxfDictSelectDialog.h"
29 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 model = new DictsModel(dicts, this);
58 proxyModel = new DictsProxyModel;
59 proxyModel->setDynamicSortFilter(true);
60 proxyModel->setSourceModel(model);
63 treeView = new QTreeView;
64 treeView->setModel(proxyModel);
65 treeView->setRootIsDecorated(false);
66 treeView->setExpandsOnDoubleClick(false);
68 treeView->setSortingEnabled(true);
69 treeView->sortByColumn(0, Qt::AscendingOrder);
71 treeView->setWordWrap(true);
74 treeView->resizeColumnToContents(0);
75 treeView->resizeColumnToContents(1);
76 treeView->setColumnWidth(2, 300);
77 treeView->resizeColumnToContents(3);
79 treeView->setColumnWidth(0, 150);
80 treeView->setColumnWidth(1, 150);
81 treeView->setColumnWidth(2, 300);
82 treeView->setColumnWidth(3, 150);
86 layout->addWidget(treeView);
89 connect(langFrom, SIGNAL(currentIndexChanged(int)),
90 this, SLOT(refreshDictList()));
92 connect(langTo, SIGNAL(currentIndexChanged(int)),
93 this, SLOT(refreshDictList()));
95 connect(treeView, SIGNAL(activated(QModelIndex)),
96 this, SLOT(itemClicked(QModelIndex)));
99 setMinimumSize(800,500);
101 setMinimumHeight(350);
108 void XdxfDictSelectDialog::initializeDicts() {
110 //scan of all languages of dictionaries, using QSet to get only distinct languages
111 QSet<QString> languagesFrom;
112 QSet<QString> languagesTo;
114 for(int i=0; i < model->rowCount(QModelIndex()); i++) {
115 languagesFrom.insert(
116 model->data(model->index(i, 0, QModelIndex())).toString());
118 model->data(model->index(i, 1, QModelIndex())).toString());
121 //removes one dictionary which from and to languages are empty....
122 //bug in site with dictionaries
123 languagesFrom.remove(QString());
124 languagesTo.remove(QString());
126 //sorting of found languages
127 QList<QString> langFromList = languagesFrom.toList();
130 QList<QString> langToList = languagesTo.toList();
133 //and adding them to combobox, first item in each combobox is "Any"
134 langFrom->addItem(tr("Any"));
135 for(int i=0; i < langFromList.count(); i++) {
136 langFrom->addItem(langFromList.at(i));
139 langTo->addItem(tr("Any"));
140 for(int i=0; i < langToList.count(); i++) {
141 langTo->addItem(langToList.at(i));
145 void XdxfDictSelectDialog::refreshDictList() {
146 //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.
147 if(langTo->currentIndex() == 0)
148 proxyModel->setTo(QString());
150 proxyModel->setTo(langTo->currentText());
152 if(langFrom->currentIndex() == 0)
153 proxyModel->setFrom(QString());
155 proxyModel->setFrom(langFrom->currentText());
158 void XdxfDictSelectDialog::itemClicked(QModelIndex index) {
159 _link = index.model()->data(index, Qt::UserRole).toString();