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,
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);
60 treeView = new QTreeView;
61 treeView->setModel(proxyModel);
62 treeView->setRootIsDecorated(false);
63 treeView->setExpandsOnDoubleClick(false);
65 treeView->setSortingEnabled(true);
66 treeView->sortByColumn(0, Qt::AscendingOrder);
68 treeView->setWordWrap(true);
71 treeView->resizeColumnToContents(0);
72 treeView->resizeColumnToContents(1);
73 treeView->setColumnWidth(2, 300);
74 treeView->resizeColumnToContents(3);
76 treeView->setColumnWidth(0, 150);
77 treeView->setColumnWidth(1, 150);
78 treeView->setColumnWidth(2, 300);
79 treeView->setColumnWidth(3, 150);
83 layout->addWidget(treeView);
86 connect(langFrom, SIGNAL(currentIndexChanged(int)),
87 this, SLOT(refreshDictList()));
89 connect(langTo, SIGNAL(currentIndexChanged(int)),
90 this, SLOT(refreshDictList()));
92 connect(treeView, SIGNAL(activated(QModelIndex)),
93 this, SLOT(itemClicked(QModelIndex)));
96 setMinimumSize(800,500);
98 setMinimumHeight(350);
105 void XdxfDictSelectDialog::initializeDicts() {
107 QSet<QString> languagesFrom;
108 QSet<QString> languagesTo;
110 for(int i=0; i < model->rowCount(QModelIndex()); i++) {
111 languagesFrom.insert(
112 model->data(model->index(i, 0, QModelIndex())).toString());
114 model->data(model->index(i, 1, QModelIndex())).toString());
117 languagesFrom.remove(QString());
118 languagesTo.remove(QString());
120 QList<QString> langFromList = languagesFrom.toList();
123 QList<QString> langToList = languagesTo.toList();
126 langFrom->addItem(tr("Any"));
127 for(int i=0; i < langFromList.count(); i++) {
128 langFrom->addItem(langFromList.at(i));
131 langTo->addItem(tr("Any"));
132 for(int i=0; i < langToList.count(); i++) {
133 langTo->addItem(langToList.at(i));
137 void XdxfDictSelectDialog::refreshDictList() {
138 if(langTo->currentIndex() == 0)
139 proxyModel->setTo(QString());
141 proxyModel->setTo(langTo->currentText());
143 if(langFrom->currentIndex() == 0)
144 proxyModel->setFrom(QString());
146 proxyModel->setFrom(langFrom->currentText());
149 void XdxfDictSelectDialog::itemClicked(QModelIndex index) {
150 _link = index.model()->data(index, Qt::UserRole).toString();