X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fmdictionary%2Fgui%2FDictManagerWidget.cpp;h=e300a26bd56a6216fe2fe23015950476ddb3530c;hb=b7f58d195c9d23d79faff0678ab1e618fb07e690;hp=c9028db42f4189944e99cae9972ba64383fe6d40;hpb=ee90723882d91c2958ae001992535dc4a1802a9c;p=mdictionary diff --git a/src/mdictionary/gui/DictManagerWidget.cpp b/src/mdictionary/gui/DictManagerWidget.cpp index c9028db..e300a26 100644 --- a/src/mdictionary/gui/DictManagerWidget.cpp +++ b/src/mdictionary/gui/DictManagerWidget.cpp @@ -19,9 +19,11 @@ *******************************************************************************/ -//! \file DictManagerWidget.cpp -//! \brief Dictionaries management widget -//! \author Mateusz Półrola +/*! \file DictManagerWidget.cpp + \brief Implements dictionaries management widget + + \author Mateusz Półrola +*/ #include "DictManagerWidget.h" #include "DictTypeSelectDialog.h" @@ -34,13 +36,35 @@ DictManagerWidget::DictManagerWidget(GUIInterface *parent) : 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); @@ -83,20 +107,78 @@ void DictManagerWidget::initalizeUI() { 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 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); @@ -108,9 +190,17 @@ void DictManagerWidget::refreshDictsList() { 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()) { @@ -126,6 +216,7 @@ void DictManagerWidget::refreshDictsList() { } dictList->sortItems(); + #endif } void DictManagerWidget::showEvent(QShowEvent *e) { @@ -180,10 +271,6 @@ void DictManagerWidget::addNewDictButtonClicked() { CommonDictInterface* selectedPlugin = DictTypeSelectDialog::addNewDict(guiInterface->getPlugins(),this); if(selectedPlugin) { - DictTypeSelectDialog::addNewDict( - guiInterface->getPlugins(), - this->parentWidget()); - Settings* settings = selectedPlugin->dictDialog()->addNewDictionary(this->parentWidget()); @@ -201,6 +288,7 @@ void DictManagerWidget::addNewDictButtonClicked() { void DictManagerWidget::itemSelected(QListWidgetItem *) { removeDictButton->setEnabled(true); settingsButton->setEnabled(true); + dictList->setFocus(); } void DictManagerWidget::removeButtonClicked() { @@ -245,3 +333,19 @@ void DictManagerWidget::changed() { 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(); + } +}