Merge branch 'qml' of ssh://drop.maemo.org/git/mdictionary into qml
authorjakub <jakub.jaszczynski@comarch.com>
Thu, 30 Dec 2010 15:40:54 +0000 (16:40 +0100)
committerjakub <jakub.jaszczynski@comarch.com>
Thu, 30 Dec 2010 15:40:54 +0000 (16:40 +0100)
Conflicts:
src/mdictionary/mdictionary.pro

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/mdictionary.pro
src/mdictionary/qml/Checkbox.qml [new file with mode: 0644]
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 ce84a73..b790af9 100644 (file)
@@ -96,6 +96,7 @@ OTHER_FILES += \
     qml/FlickableWebView.qml \
     qml/ScrollBar.qml \
     qml/SpinBox.qml
+    qml/Checkbox.qml
 
 target.path = $$BIN_DIR
 INSTALLS += target
@@ -198,6 +199,7 @@ unix {
         qmls.files += ./qml/TranslationView.qml
         qmls.files += ./qml/FlickableWebView.qml
         qmls.files += ./qml/ScrollBar.qml
+        qmls.files += ./qml/Checkbox.qml
     }
        
     INSTALLS += desktop icon64 shared service css css_images qmls
diff --git a/src/mdictionary/qml/Checkbox.qml b/src/mdictionary/qml/Checkbox.qml
new file mode 100644 (file)
index 0000000..c1a0ea7
--- /dev/null
@@ -0,0 +1,59 @@
+/*******************************************************************************
+
+    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 {
+    id: checkbox
+    property bool selected
+    signal changed
+    height: {
+        var aspectRatio = sourceSize.height / sourceSize.width
+        return checkbox.width * aspectRatio
+    }
+    width: sourceSize.width
+    smooth: true
+    states: [
+        State {
+            name: "checked";
+            when: (checkbox.selected == true);
+
+            PropertyChanges { target: checkbox; source: "qrc:/button/checkboxChecked.png" }
+        },
+        State {
+            name: "unchecked";
+            when: (checkbox.selected == false);
+
+            PropertyChanges { target: checkbox; source: "qrc:/button/checkbox.png" }
+        }
+    ]
+    MouseArea{
+        id: area
+        anchors.fill: parent
+        onClicked: {
+            checkbox.selected = !checkbox.selected
+            changed()
+        }
+    }
+}
index ace01c9..df43918 100644 (file)
@@ -29,6 +29,12 @@ Rectangle {
 
     function setEnableRemove(Boolean) { removeButton.enabled = Boolean }
     function setEnableSettings(Boolean) { settingsButton.enabled = Boolean }
+    function changeDictionaryState(nr, state) {
+        dictList.currentIndex = nr
+        dictModel.setModelProperty(dictList.currentIndex, state, "isSelected")
+        rectangle1.setEnableRemove(true)
+        rectangle1.setEnableSettings(true)
+    }
 
     signal addButtonClicked;
     signal removeButtonClicked;
@@ -64,6 +70,7 @@ Rectangle {
                         dictList.currentIndex = number
                         rectangle1.setEnableRemove(true)
                         rectangle1.setEnableSettings(true)
+                        dictModel.itemSelected(dictList.currentIndex)
                     }
                     onDoubleClicked: {
                         rectangle1.itemActivated(dictList.currentIndex)
@@ -71,40 +78,14 @@ Rectangle {
                 }
                 Row {
                     anchors.fill: parent
-                    Image {
-                        id: checkbox
-                        height: {
-                            var aspectRatio = sourceSize.height / sourceSize.width
-                            return checkbox.width * aspectRatio
-                        }
-                        anchors.verticalCenter: parent.verticalCenter
+                    Checkbox{
+                        id: check
                         width: nameText.height
-                        smooth: true
-                        states: [
-                            State {
-                                name: "checked";
-                                when: (isSelected == true);
-
-                                PropertyChanges { target: checkbox; source: "qrc:/button/checkboxChecked.png" }
-                            },
-                            State {
-                                name: "unchecked";
-                                when: (isSelected == false);
-
-                                PropertyChanges { target: checkbox; source: "qrc:/button/checkbox.png" }
-                            }
-                        ]
-                        MouseArea{
-                            anchors.fill: parent
-                            onClicked: {
-                                dictList.currentIndex = number
-                                dictModel.setModelProperty(dictList.currentIndex, !isSelected, "isSelected")
-                                rectangle1.setEnableRemove(true)
-                                rectangle1.setEnableSettings(true)
-                            }
-                        }
+                        selected: isSelected
+                        onChanged: rectangle1.changeDictionaryState(number, selected)
                     }
 
+
                     Image {
                         id: logo
                         source: iconPath
@@ -148,7 +129,7 @@ Rectangle {
             anchors.leftMargin: 4
             anchors.verticalCenter: parent.verticalCenter
             textInButton: qsTr("Add")
-            onClicked: rectangle1.addButtonClicked
+            onClicked: addButtonClicked();
         }
 
         Button {
@@ -160,7 +141,7 @@ Rectangle {
             anchors.verticalCenter: parent.verticalCenter
             textInButton: qsTr("Remove")
             enabled: false
-            onClicked: rectangle1.removeButtonClicked
+            onClicked: removeButtonClicked();
         }
 
         Button {
@@ -172,7 +153,7 @@ Rectangle {
             anchors.verticalCenter: parent.verticalCenter
             textInButton: qsTr("Settings")
             enabled: false
-            onClicked: rectangle1.settingsButtonClicked
+            onClicked: settingsButtonClicked();
         }
 
         Button {
@@ -185,7 +166,7 @@ Rectangle {
             anchors.rightMargin: 4
             anchors.verticalCenter: parent.verticalCenter
             textInButton: qsTr("Save")
-            onClicked: rectangle1.saveButtonClicked
+            onClicked: saveButtonClicked()
         }
 
     }