Fixed problem with connects in DictManagerWidget.cpp. Fixed: remove warnings from...
[mdictionary] / src / mdictionary / gui / DictManagerWidget.cpp
index 4353301..e300a26 100644 (file)
 
 *******************************************************************************/
 
-//! \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"
@@ -34,6 +36,9 @@ DictManagerWidget::DictManagerWidget(GUIInterface *parent) :
     setWindowTitle(tr("Dictionaries"));
     this->guiInterface = parent;
 
+    #ifndef Q_WS_MAEMO_5
+    model = 0;
+    #endif
     initalizeUI();
 
     setModal(true);
@@ -43,6 +48,23 @@ 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);
 
@@ -85,34 +107,78 @@ void DictManagerWidget::initalizeUI() {
 
     connect(dictList, SIGNAL(itemChanged(QListWidgetItem*)),
             this, SLOT(changed()));
+    #endif
 
     #ifndef Q_WS_MAEMO_5
-        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()));
+    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);
-
-        setMinimumWidth(sizeHint().width()*1.2);
-        setMaximumWidth(sizeHint().width()*2);
-        setMinimumHeight(sizeHint().height());
-        setMaximumHeight(sizeHint().height()*2);
-        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);
@@ -124,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()) {
@@ -142,6 +216,7 @@ void DictManagerWidget::refreshDictsList() {
     }
 
     dictList->sortItems();
+    #endif
 }
 
 void DictManagerWidget::showEvent(QShowEvent *e) {