features of DictManagerWidget restored in qml version.
authorMarcin Kaźmierczak <marcin@marcin-desktop.(none)>
Thu, 30 Dec 2010 15:33:46 +0000 (16:33 +0100)
committerMarcin Kaźmierczak <marcin@marcin-desktop.(none)>
Thu, 30 Dec 2010 15:33:46 +0000 (16:33 +0100)
src/mdictionary/gui/DictManagerModel.cpp
src/mdictionary/gui/DictManagerModel.h
src/mdictionary/gui/DictManagerWidget.cpp
src/mdictionary/gui/DictTypeModel.cpp
src/mdictionary/gui/DictTypeModel.h
src/mdictionary/qml/Checkbox.qml
src/mdictionary/qml/DictManagerWidget.qml

index 4714730..ecb93bd 100644 (file)
@@ -1,8 +1,36 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*! \file DictManagerModel.cpp
+    \brief Contains dictionaries data for qml UI
+
+    \author Marcin Kaźmierczak <marcin.kazmierczak@comarch.pl>
+*/
+
 #include "DictManagerModel.h"
 
 DictManagerModel::DictManagerModel(QHash<CommonDictInterface *, bool> dictionaries, QObject *parent) :
     QAbstractListModel(parent)
 {
+    _currentIndex = 0;
     QHash<int, QByteArray> roles;
     roles[NameRole] = "name";
     roles[IconPathRole] = "iconPath";
@@ -35,7 +63,7 @@ void DictManagerModel::clear()
     _dictionaries.clear();
     _dictList.clear();
     endRemoveRows();
-    emit dataChanged(QModelIndex(), QModelIndex());
+    Q_EMIT dataChanged(QModelIndex(), QModelIndex());
 }
 
 QVariant DictManagerModel::data(const QModelIndex & index, int role) const
@@ -98,7 +126,7 @@ int DictManagerModel::setDataPriv(int index, const QVariant &value, int role)
             _dictionaries[dictionary] = value.toBool();
 //            if (index == _dictList.count())
 //                emit dataChanged(this->index(index-1), this->index(index));
-            emit dataChanged(this->index(0), this->index(_dictList.count() - 1));
+            Q_EMIT dataChanged(this->index(0), this->index(_dictList.count() - 1));
             return 2;
         }
         else
@@ -118,6 +146,21 @@ void DictManagerModel::setModelProperty(int index, const QVariant value, QString
 
 }
 
+void DictManagerModel::itemSelected(int index)
+{
+    _currentIndex = index;
+}
+
+CommonDictInterface* DictManagerModel::currentDict()
+{
+    return _dictList[_currentIndex];
+}
+
+bool DictManagerModel::isCurrentDictSelected()
+{
+    return _dictionaries[_dictList[_currentIndex]];
+}
+
 Qt::ItemFlags DictManagerModel::flags(const QModelIndex &index) const
 {
     Qt::ItemFlags fl = QAbstractItemModel::flags(index);
index 6c599f1..034867f 100644 (file)
@@ -1,3 +1,30 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*! \file DictManagerModel.h
+    \brief Contains dictionaries data for qml UI
+
+    \author Marcin Kaźmierczak <marcin.kazmierczak@comarch.pl>
+*/
+
 #ifndef DICTMANAGERMODEL_H
 #define DICTMANAGERMODEL_H
 
@@ -23,7 +50,7 @@ public:
 
     //! Constructor
     /*!
-      \param dictionaries list of dictionaries
+      \param dictionaries hash set (dictionary, is active) with dictionaries
       \param parent parent of this class.
     */
     explicit DictManagerModel(QHash<CommonDictInterface*, bool> dictionaries, QObject *parent = 0);
@@ -34,21 +61,48 @@ public:
     bool setData(const QModelIndex &index, const QVariant &value, int role);
 
     Qt::ItemFlags flags(const QModelIndex &index) const;
+
+    //! Replace model data and refresh ui.
+    /*!
+      \param dictionaries hash set (dictionary, is active) with dictionaries
+    */
     void setDictionaries(QHash<CommonDictInterface*, bool> dictionaries);
+
+    //! Get dictionary hash set
     QHash<CommonDictInterface*, bool> dictionaries();
+
+    //! Get dictionary list
     QList<CommonDictInterface*> dictList();
 
+    //! Clear model data and refresh UI
     void clear();
+    //! Get current selected dictionary
+    CommonDictInterface* currentDict();
+    //! Get true if current selected dictionary was active. Otherwise return false.
+    bool isCurrentDictSelected();
 
 public Q_SLOTS:
+    //! Set value at role in index row of data.
+    /*!
+      \param index dictionary position in data list
+      \param value new value for role
+      \param role role name
+      */
     void setModelProperty(int index, const QVariant value, QString role);
+    //! Set index of current selected dictionary
+    /*!
+      \param index dictionary position in data list
+      */
+    void itemSelected(int index);
 
 Q_SIGNALS:
+    //! emits when user changed data
     void itemChanged();
 
 private:
     QHash<CommonDictInterface*, bool> _dictionaries;
     QList<CommonDictInterface*> _dictList;
+    int _currentIndex;
 
     int setDataPriv(int index, const QVariant &value, int role);
     void addDictionary(CommonDictInterface* dictionary, bool isActive);
index e300a26..86459b7 100644 (file)
@@ -125,24 +125,14 @@ void DictManagerWidget::initalizeUI() {
     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()));
+            this, SLOT(changed()));
+    connect(rootObject, SIGNAL(itemActivated(int)),
+            this, SLOT(saveChanges()));
+    connect(rootObject, SIGNAL(itemActivated(int)),
+            this, SLOT(settingsButtonClicked()));
+
     #endif
 
     #ifdef Q_WS_MAEMO_5
@@ -158,7 +148,6 @@ void DictManagerWidget::initalizeUI() {
 //        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
 }
@@ -237,13 +226,22 @@ void DictManagerWidget::saveChanges() {
                 QMessageBox::question(this, tr("Save"),
                                       tr("Do you want to save changes?"),
                 QMessageBox::Save, QMessageBox::Cancel) == QMessageBox::Save) {
+            QList<CommonDictInterface*> checkedDicts;
+
+            for(int i=0; i<dictList->count(); i++) {
+                QListWidgetItem* item = dictList->item(i);
+                if(item->checkState() == Qt::Checked) {
+                    checkedDicts.push_back(dictsHash[item]);
+                }
+            }
     #endif
         QList<CommonDictInterface*> checkedDicts;
 
-        for(int i=0; i<dictList->count(); i++) {
-            QListWidgetItem* item = dictList->item(i);
-            if(item->checkState() == Qt::Checked) {
-                checkedDicts.push_back(dictsHash[item]);
+        for(int i=0; i<model->dictList().count(); i++) {
+//            QListWidgetItem* item = dictList->item(i);
+            CommonDictInterface* item = model->dictList()[i];
+            if(model->dictionaries()[item] == true) {
+                checkedDicts.push_back(item);
             }
         }
         _changed = false;
@@ -259,9 +257,11 @@ void DictManagerWidget::hideEvent(QHideEvent *e) {
 
 void DictManagerWidget::addNewDictButtonClicked() {
     #ifndef Q_WS_MAEMO_5
+    qDebug()<<"1 "<<_changed;
     if(!_changed || QMessageBox::question(this,
             tr("Save"), tr("Do you want to save changes?"),
             QMessageBox::Save, QMessageBox::Cancel) == QMessageBox::Save) {
+        qDebug()<<"2";
         _save = true;
         saveChanges();
         _save = false;
@@ -295,12 +295,16 @@ void DictManagerWidget::removeButtonClicked() {
     if(QMessageBox::question(this, tr("Remove dictionary"),
             tr("Do you want to remove selected dictionary?"),
             QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) {
-
+#ifndef Q_WS_MAEMO_5
+        emit removeDictionary(model->currentDict());
+        refreshDictsList();
+#else
         QList<QListWidgetItem*> selected = dictList->selectedItems();
         if(selected.count() > 0) {
             emit removeDictionary(dictsHash[selected[0]]);
             refreshDictsList();
         }
+#endif
    }
 }
 
@@ -313,12 +317,15 @@ void DictManagerWidget::settingsButtonClicked() {
         saveChanges();
         _save = false;
     }
-    #endif
+    model->currentDict()->dictDialog()->changeSettings(this->parentWidget());
+    refreshDictsList();
+    #else
    QList<QListWidgetItem*> selected = dictList->selectedItems();
    if(selected.count() > 0) {
        dictsHash[selected[0]]->dictDialog()->changeSettings(this->parentWidget());
    }
    refreshDictsList();
+#endif
 }
 
 
index b2d09b2..aebcc3c 100644 (file)
@@ -20,7 +20,7 @@
 *******************************************************************************/
 
 /*! \file DictTypeModel.cpp
-    \brief Implements plugin data for list model
+    \brief Contains plugins data for qml UI
 
     \author Marcin Kaźmierczak <marcin.kazmierczak@comarch.pl>
 */
index 3a35e91..fa1ae2c 100644 (file)
@@ -20,7 +20,7 @@
 *******************************************************************************/
 
 /*! \file DictTypeModel.h
-    \brief Implements plugin data for list model
+    \brief Contains plugins data for qml UI
 
     \author Marcin Kaźmierczak <marcin.kazmierczak@comarch.pl>
 */
index 1af756f..c1a0ea7 100644 (file)
@@ -1,3 +1,27 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+/*!
+    author: Marcin Kaźmierczak <marcin.kazmierczak@comarch.pl>
+*/
+
 import Qt 4.7
 
 Image {
index 7cb44f3..df43918 100644 (file)
@@ -67,10 +67,10 @@ Rectangle {
                 MouseArea{
                     anchors.fill: parent
                     onClicked: {
-                        console.log("aaaaa")
                         dictList.currentIndex = number
                         rectangle1.setEnableRemove(true)
                         rectangle1.setEnableSettings(true)
+                        dictModel.itemSelected(dictList.currentIndex)
                     }
                     onDoubleClicked: {
                         rectangle1.itemActivated(dictList.currentIndex)
@@ -129,7 +129,7 @@ Rectangle {
             anchors.leftMargin: 4
             anchors.verticalCenter: parent.verticalCenter
             textInButton: qsTr("Add")
-            onClicked: rectangle1.addButtonClicked
+            onClicked: addButtonClicked();
         }
 
         Button {
@@ -141,7 +141,7 @@ Rectangle {
             anchors.verticalCenter: parent.verticalCenter
             textInButton: qsTr("Remove")
             enabled: false
-            onClicked: rectangle1.removeButtonClicked
+            onClicked: removeButtonClicked();
         }
 
         Button {
@@ -153,7 +153,7 @@ Rectangle {
             anchors.verticalCenter: parent.verticalCenter
             textInButton: qsTr("Settings")
             enabled: false
-            onClicked: rectangle1.settingsButtonClicked
+            onClicked: settingsButtonClicked();
         }
 
         Button {
@@ -166,7 +166,7 @@ Rectangle {
             anchors.rightMargin: 4
             anchors.verticalCenter: parent.verticalCenter
             textInButton: qsTr("Save")
-            onClicked: rectangle1.saveButtonClicked
+            onClicked: saveButtonClicked()
         }
 
     }