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 DictManagerWidget.cpp
23 //! \brief Dicrionaries management widget
24 //! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
26 #include "DictManagerWidget.h"
27 #include "DictTypeSelectDialog.h"
29 #include "../../includes/DictDialog.h"
31 DictManagerWidget::DictManagerWidget(GUIInterface *parent) :
36 setWindowTitle(tr("Dictionaries"));
37 this->guiInterface = parent;
39 verticalLayout = new QVBoxLayout(this);
40 setLayout(verticalLayout);
42 dictListWidget = new QListWidget(this);
43 verticalLayout->addWidget(dictListWidget);
45 dictListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
46 dictListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
48 addNewDictButton = new QPushButton(tr("Add"),this);
49 removeDictButton = new QPushButton(tr("Remove"),this);
50 settingsButton = new QPushButton(tr("Settings"),this);
52 removeDictButton->setEnabled(false);
53 settingsButton->setEnabled(false);
55 buttonGroup = new QHBoxLayout(this);
57 buttonGroup->addWidget(addNewDictButton);
58 buttonGroup->addWidget(removeDictButton);
59 buttonGroup->addWidget(settingsButton);
61 verticalLayout->addLayout(buttonGroup, Qt::AlignBottom);
64 connect(addNewDictButton, SIGNAL(clicked()),
65 this, SLOT(addNewDictButtonClicked()));
67 connect(removeDictButton, SIGNAL(clicked()),
68 this, SLOT(removeButtonClicked()));
70 connect(settingsButton, SIGNAL(clicked()),
71 this, SLOT(settingsButtonClicked()));
73 connect(dictListWidget, SIGNAL(itemClicked(QListWidgetItem*)),
74 this, SLOT(itemSelected(QListWidgetItem*)));
79 setMinimumSize(500,300);
84 void DictManagerWidget::refreshDictsList() {
86 dictListWidget->clear();
88 removeDictButton->setEnabled(false);
89 settingsButton->setEnabled(false);
91 QHash<CommonDictInterface*, bool> dicts = guiInterface->getDictionaries();
93 QHashIterator<CommonDictInterface*, bool> i(dicts);
97 QListWidgetItem* item = new QListWidgetItem();
98 QString name = i.key()->langFrom() + " - " + i.key()->langTo() + " (" +
99 i.key()->type() + " " + i.key()->name() + ")";
101 item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
103 item->setCheckState(Qt::Checked);
106 item->setCheckState(Qt::Unchecked);
108 item->setIcon(*i.key()->icon());
110 dictListWidget->addItem(item);
111 dictsHash.insert(item, i.key());
115 void DictManagerWidget::showEvent(QShowEvent *e) {
117 QWidget::showEvent(e);
120 void DictManagerWidget::hideEvent(QHideEvent *e)
122 QList<CommonDictInterface*> checkedDicts;
124 for(int i=0; i<dictListWidget->count(); i++) {
125 QListWidgetItem* item = dictListWidget->item(i);
126 if(item->checkState() == Qt::Checked) {
127 checkedDicts.push_back(dictsHash[item]);
130 emit selectedDictionaries(checkedDicts);
132 QWidget::hideEvent(e);
136 void DictManagerWidget::addNewDictButtonClicked() {
137 CommonDictInterface* selectedPlugin =
138 DictTypeSelectDialog::addNewDict(guiInterface->getPlugins(),this);
139 if(selectedPlugin != NULL) {
141 selectedPlugin->dictDialog()->addNewDictionary(this);
143 if(settings != NULL) {
144 CommonDictInterface* newDict = selectedPlugin->getNew(settings);
145 emit addDictionary(newDict);
151 void DictManagerWidget::itemSelected(QListWidgetItem *) {
152 removeDictButton->setEnabled(true);
153 settingsButton->setEnabled(true);
156 void DictManagerWidget::removeButtonClicked() {
157 QList<QListWidgetItem*> selected = dictListWidget->selectedItems();
158 if(selected.count() > 0) {
159 emit removeDictionary(dictsHash[selected[0]]);
164 void DictManagerWidget::settingsButtonClicked() {
165 QList<QListWidgetItem*> selected = dictListWidget->selectedItems();
166 if(selected.count() > 0) {
167 dictsHash[selected[0]]->dictDialog()->changeSettings(this);