Copyright 2010 Comarch S.A.
*******************************************************************************/
-
-//Created by Mateusz Półrola
+/*!
+ \file XdxfDictSelectDialog.cpp
+ \author Mateusz Półrola <mateusz.polrola@comarch.com>
+*/
#include "XdxfDictSelectDialog.h"
XdxfDictSelectDialog::XdxfDictSelectDialog(QList<DownloadDict> dicts,
QWidget *parent) :
- QDialog(parent) {
+ QDialog(parent) {
+ setWindowTitle(tr("Select dictionary"));
layout = new QVBoxLayout;
setLayout(layout);
langFrom->setInsertPolicy(QComboBox::InsertAlphabetically);
langTo->setInsertPolicy(QComboBox::InsertAlphabetically);
- checkBoxLayout->addWidget(langFrom);
- checkBoxLayout->addWidget(langTo);
+ langFromLabel = new QLabel(tr("From "));
+ langToLabel = new QLabel(tr("To "));
+
+ checkBoxLayout->addWidget(langFromLabel);
+ checkBoxLayout->addWidget(langFrom, 10);
+ checkBoxLayout->addWidget(langToLabel);
+ checkBoxLayout->addWidget(langTo, 10);
+
+ //here removing already added dictionary
+
+ for (int i = 0; i < dicts.size(); i++){
+ if(QFile::exists(QDir::homePath() + "/.mdictionary/" + dicts[i].title() + ".xdxf")){
+ dicts.removeAt(i);
+ i--;
+ }
+ }
model = new DictsModel(dicts, this);
proxyModel->setDynamicSortFilter(true);
proxyModel->setSourceModel(model);
-
treeView = new QTreeView;
treeView->setModel(proxyModel);
treeView->setRootIsDecorated(false);
treeView->setExpandsOnDoubleClick(false);
treeView->setSortingEnabled(true);
- // treeView->sortByColumn(0);
+ treeView->sortByColumn(0, Qt::AscendingOrder);
- layout->addWidget(treeView);
+ treeView->setWordWrap(true);
+ #ifndef Q_WS_MAEMO_5
+ treeView->resizeColumnToContents(0);
+ treeView->resizeColumnToContents(1);
+ treeView->setColumnWidth(2, 300);
+ treeView->resizeColumnToContents(3);
+ #else
+ treeView->setColumnWidth(0, 150);
+ treeView->setColumnWidth(1, 150);
+ treeView->setColumnWidth(2, 300);
+ treeView->setColumnWidth(3, 150);
+ #endif
+
+ layout->addWidget(treeView);
connect(langFrom, SIGNAL(currentIndexChanged(int)),
this, SLOT(refreshDictList()));
this, SLOT(itemClicked(QModelIndex)));
#ifndef Q_WS_MAEMO_5
- setMinimumSize(400,200);
+ setMinimumSize(800,500);
#else
setMinimumHeight(350);
#endif
void XdxfDictSelectDialog::initializeDicts() {
-
+ //scan of all languages of dictionaries, using QSet to get only distinct languages
QSet<QString> languagesFrom;
QSet<QString> languagesTo;
model->data(model->index(i, 1, QModelIndex())).toString());
}
+ //removes one dictionary which from and to languages are empty....
+ //bug in site with dictionaries
languagesFrom.remove(QString());
languagesTo.remove(QString());
+ //sorting of found languages
QList<QString> langFromList = languagesFrom.toList();
qSort(langFromList);
QList<QString> langToList = languagesTo.toList();
qSort(langToList);
+ //and adding them to combobox, first item in each combobox is "Any"
langFrom->addItem(tr("Any"));
for(int i=0; i < langFromList.count(); i++) {
langFrom->addItem(langFromList.at(i));
}
}
+
void XdxfDictSelectDialog::refreshDictList() {
+ //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.
if(langTo->currentIndex() == 0)
proxyModel->setTo(QString());
else
proxyModel->setFrom(langFrom->currentText());
}
+
void XdxfDictSelectDialog::itemClicked(QModelIndex index) {
- _link = index.model()->data(index, Qt::UserRole);
+ _link = index.model()->data(index, Qt::UserRole).toString();
accept();
}