*******************************************************************************/
-//! \file DictManagerWidget.cpp
-//! \brief Dictionaries management widget
-//! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
+/*! \file DictManagerWidget.cpp
+ \brief Implements dictionaries management widget
+
+ \author Mateusz Półrola <mateusz.polrola@comarch.pl>
+*/
#include "DictManagerWidget.h"
#include "DictTypeSelectDialog.h"
setWindowTitle(tr("Dictionaries"));
this->guiInterface = parent;
+ #ifndef Q_WS_MAEMO_5
+ model = 0;
+ #endif
initalizeUI();
+
+ setModal(true);
}
void DictManagerWidget::initalizeUI() {
verticalLayout = new QVBoxLayout;
setLayout(verticalLayout);
+ #ifndef Q_WS_MAEMO_5
+ qmlView = new QDeclarativeView(this);
+
+ ctxt = qmlView->rootContext();
+
+ refreshDictsList();
+ ctxt->setContextProperty("dictModel", &(*model));
+ qmlView->setSource(QUrl::fromLocalFile("/usr/share/mdictionary/qml/DictManagerWidget.qml"));
+
+ QGraphicsObject *rootObject = qmlView->rootObject();
+
+ qmlView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
+ verticalLayout->addWidget(qmlView);
+
+ #endif
+
+ #ifdef Q_WS_MAEMO_5
dictList = new QListWidget;
verticalLayout->addWidget(dictList);
connect(dictList, SIGNAL(itemChanged(QListWidgetItem*)),
this, SLOT(changed()));
+ #endif
+
+ #ifndef Q_WS_MAEMO_5
+ connect(rootObject, SIGNAL(addButtonClicked()),
+ this, SLOT(saveChanges()));
+ connect(rootObject, SIGNAL(addButtonClicked()),
+ this, SLOT(addNewDictButtonClicked()));
+ connect(rootObject, SIGNAL(removeButtonClicked()),
+ this, SLOT(saveChanges()));
+ connect(rootObject, SIGNAL(removeButtonClicked()),
+ this, SLOT(removeButtonClicked()));
+
+ connect(rootObject, SIGNAL(settingsButtonClicked()),
+ this, SLOT(saveChanges()));
+ connect(rootObject, SIGNAL(settingsButtonClicked()),
+ this, SLOT(settingsButtonClicked()));
+
+ //z modelu sygnał, oraz z okienka zmian ustawień w pluginie, gdy są zmiany
+// oryginalnie:
+// connect(dictList, SIGNAL(itemChanged(QListWidgetItem*)),
+// this, SLOT(changed()));
+ connect(model, SIGNAL(itemChanged()),
+ this, SLOT(changed()));
+ //pozmieniać connecty, to jest na dwuklik mysza na liście, sprawdzić, zrobic alternatywne sloty
+ connect(rootObject, SIGNAL(itemActivated(int)),
+ this, SLOT(saveChanges()));
+ connect(rootObject, SIGNAL(itemActivated(int)),
+ this, SLOT(settingsButtonClicked()));
+
+// connect(dictList, SIGNAL(itemActivated(QListWidgetItem*)),
+// this, SLOT(saveChanges()));
+// connect(dictList, SIGNAL(itemActivated(QListWidgetItem*)),
+// this, SLOT(itemSelected(QListWidgetItem*)));
+// connect(dictList, SIGNAL(itemActivated(QListWidgetItem*)),
+// settingsButton, SIGNAL(clicked()));
+ #endif
+
+ #ifdef Q_WS_MAEMO_5
refreshDictsList();
+ #endif
#ifndef Q_WS_MAEMO_5
setMinimumSize(500,300);
- closeButton = new QPushButton(tr("Save"));
- buttonGroup->addWidget(closeButton);
- connect(closeButton, SIGNAL(clicked()), this, SLOT(save()));
+ //closeButton = new QPushButton(tr("Save"));
+ //buttonGroup->addWidget(closeButton);
+
+// setMinimumWidth(sizeHint().width()*1.2);
+// setMaximumWidth(sizeHint().width()*2);
+// setMinimumHeight(sizeHint().height());
+// setMaximumHeight(sizeHint().height()*2);
+ //connect(closeButton, SIGNAL(clicked()), this, SLOT(save()));
+ connect(rootObject, SIGNAL(saveButtonClicked()), this, SLOT(save()));
#endif
}
void DictManagerWidget::refreshDictsList() {
+ #ifndef Q_WS_MAEMO_5
+ QHash<CommonDictInterface*, bool> dicts = guiInterface->getDictionaries();
+
+ if (model == 0){
+ model = new DictManagerModel(dicts, this);
+ } else {
+ model->clear();
+ model->setDictionaries(dicts);
+ }
+
+ #endif
+
+ #ifdef Q_WS_MAEMO_5
dictList->clear();
dictsHash.clear();
removeDictButton->setEnabled(false);
while(i.hasNext()) {
i.next();
+
QListWidgetItem* item = new QListWidgetItem();
- QString name = i.key()->langFrom() + " - " + i.key()->langTo() + " (" +
- i.key()->type() + " " + i.key()->name() + ")";
+ QString name;
+ if (i.key()->type() == "stardict") {
+ name = i.key()->name() + " (" + i.key()->type() + ")";
+ }
+ else {
+ name = i.key()->langFrom() + " - " + i.key()->langTo() +
+ " (" + i.key()->type() + " " +
+ i.key()->name() + ")";
+ }
item->setText(name);
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
if(i.value()) {
}
dictList->sortItems();
+ #endif
}
void DictManagerWidget::showEvent(QShowEvent *e) {
#endif
CommonDictInterface* selectedPlugin =
- DictTypeSelectDialog::addNewDict(
- guiInterface->getPlugins(),
- this->parentWidget());
-
- if(selectedPlugin != NULL) {
+ DictTypeSelectDialog::addNewDict(guiInterface->getPlugins(),this);
+ if(selectedPlugin) {
Settings* settings =
selectedPlugin->dictDialog()->addNewDictionary(this->parentWidget());
- if(settings != NULL) {
+ if(settings) {
CommonDictInterface* newDict = selectedPlugin->getNew(settings);
if(newDict) {
delete settings;
void DictManagerWidget::itemSelected(QListWidgetItem *) {
removeDictButton->setEnabled(true);
settingsButton->setEnabled(true);
+ dictList->setFocus();
}
void DictManagerWidget::removeButtonClicked() {
hide();
}
#endif
+
+
+void DictManagerWidget::keyPressEvent(QKeyEvent *e) {
+ if (!e->modifiers() || (e->modifiers() & Qt::KeypadModifier && e->key() == Qt::Key_Enter)) {
+ switch (e->key()) {
+ case Qt::Key_Escape:
+ reject();
+ break;
+ default:
+ e->ignore();
+ return;
+ }
+ } else {
+ e->ignore();
+ }
+}