Fix button graphics when button was pressed or disabled. Add disabled state to button...
[mdictionary] / src / mdictionary / gui / DictManagerWidget.cpp
index 8519c93..692ea26 100644 (file)
@@ -36,6 +36,9 @@ DictManagerWidget::DictManagerWidget(GUIInterface *parent) :
     setWindowTitle(tr("Dictionaries"));
     this->guiInterface = parent;
 
+    #ifndef Q_WS_MAEMO_5
+    model = 0;
+    #endif
     initalizeUI();
 
     setModal(true);
@@ -45,6 +48,25 @@ void DictManagerWidget::initalizeUI() {
     verticalLayout = new QVBoxLayout;
     setLayout(verticalLayout);
 
+    #ifndef Q_WS_MAEMO_5
+    qmlView = new QDeclarativeView(this);
+    qmlView->setSource(QUrl::fromLocalFile("/usr/share/mdictionary/qml/DictManagerWidget.qml"));
+    ctxt = qmlView->rootContext();
+
+    refreshDictsList();
+    ctxt->setContextProperty("dictModel", &(*model));
+
+    QGraphicsObject *rootObject = qmlView->rootObject();
+    //connect(rootObject, SIGNAL(selectedRow(int)),
+    //        this, SLOT(pluginSelected(int)));
+
+    qmlView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
+    verticalLayout->addWidget(qmlView);
+
+    //connecty zwrotne
+    #endif
+
+    #ifdef Q_WS_MAEMO_5
     dictList = new QListWidget;
     verticalLayout->addWidget(dictList);
 
@@ -87,34 +109,53 @@ 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()));
+    //pozmieniać connecty
+//        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()));
     #endif
 }
 
 
 void DictManagerWidget::refreshDictsList() {
 
+    #ifndef Q_WS_MAEMO_5
+    QHash<CommonDictInterface*, bool> dicts = guiInterface->getDictionaries();
+
+    if (model == 0){
+        qDebug("ok");
+        model = new DictManagerModel(dicts, this);
+    } else {
+        qDebug("lol");
+        model->clear();
+        model->setDictionaries(dicts);
+    }
+
+    #endif
+
+    #ifdef Q_WS_MAEMO_5
     dictList->clear();
     dictsHash.clear();
     removeDictButton->setEnabled(false);
@@ -126,6 +167,7 @@ void DictManagerWidget::refreshDictsList() {
 
     while(i.hasNext()) {
         i.next();
+
         QListWidgetItem* item = new QListWidgetItem();
         QString name;
         if (i.key()->type() == "stardict") {
@@ -151,6 +193,7 @@ void DictManagerWidget::refreshDictsList() {
     }
 
     dictList->sortItems();
+    #endif
 }
 
 void DictManagerWidget::showEvent(QShowEvent *e) {