Merge branch 'qml' of ssh://drop.maemo.org/git/mdictionary into qml
authorMarcin Kaźmierczak <marcin@marcin-desktop.(none)>
Thu, 23 Dec 2010 11:57:13 +0000 (12:57 +0100)
committerMarcin Kaźmierczak <marcin@marcin-desktop.(none)>
Thu, 23 Dec 2010 11:57:13 +0000 (12:57 +0100)
13 files changed:
src/include/CommonDictInterface.h
src/mdictionary/gui/DictManagerModel.cpp [new file with mode: 0644]
src/mdictionary/gui/DictManagerModel.h [new file with mode: 0644]
src/mdictionary/gui/DictManagerWidget.cpp
src/mdictionary/gui/DictManagerWidget.h
src/mdictionary/mdictionary.pro
src/mdictionary/qml/DictManagerWidget.qml
src/plugins/google/GooglePlugin.cpp
src/plugins/google/GooglePlugin.h
src/plugins/stardict/StarDictPlugin.cpp
src/plugins/stardict/StarDictPlugin.h
src/plugins/xdxf/xdxfplugin.cpp
src/plugins/xdxf/xdxfplugin.h

index 0f0c415..73415b1 100644 (file)
@@ -91,6 +91,9 @@ class CommonDictInterface : public QObject, public AccentsNormalizer {
     //! \returns plugin icon
     virtual QIcon* icon() = 0;
 
+    //! \returns plugin icon's path
+    virtual QString iconPath() = 0;
+
     //! \returns empty translation object (to be fetched later) for a given key
     virtual Translation* getTranslationFor(QString ) {return 0;}
 
diff --git a/src/mdictionary/gui/DictManagerModel.cpp b/src/mdictionary/gui/DictManagerModel.cpp
new file mode 100644 (file)
index 0000000..c698ca7
--- /dev/null
@@ -0,0 +1,107 @@
+#include "DictManagerModel.h"
+
+DictManagerModel::DictManagerModel(QHash<CommonDictInterface *, bool> dictionaries, QObject *parent) :
+    QAbstractListModel(parent)
+{
+    QHash<int, QByteArray> roles;
+    roles[NameRole] = "name";
+    roles[IconPathRole] = "iconPath";
+    roles[IsSelectedRole] = "isSelected";
+    roles[NumberRole] = "number";
+    setRoleNames(roles);
+
+    setDictionaries(dictionaries);
+}
+
+int DictManagerModel::rowCount(const QModelIndex &parent) const
+{
+    return _dictList.count();
+}
+
+void DictManagerModel::setDictionaries(QHash<CommonDictInterface *, bool> dictionaries)
+{
+    QHashIterator<CommonDictInterface *, bool> i(dictionaries);
+    while (i.hasNext()) {
+        i.next();
+        addDictionary(i.key(), i.value());
+    }
+}
+
+void DictManagerModel::clear()
+{
+    beginRemoveRows(QModelIndex(), 0, rowCount());
+    _dictionaries.clear();
+    _dictList.clear();
+    endRemoveRows();
+    emit dataChanged(QModelIndex(), QModelIndex());
+}
+
+QVariant DictManagerModel::data(const QModelIndex & index, int role) const
+{
+    if (index.row() < 0 || index.row() > _dictList.count())
+        return QVariant();
+
+    CommonDictInterface* dictionary = _dictList[index.row()];
+    if (role == NameRole)
+    {
+        QString name;
+        if (dictionary->type() == "stardict") {
+            name = dictionary->name() + " (" + dictionary->type() + ")";
+        }
+        else {
+            name = dictionary->langFrom() + " - " + dictionary->langTo() +
+                   " (" + dictionary->type() + " " +
+                   dictionary->name() + ")";
+        }
+        return name;
+    }
+    if (role == NumberRole)
+        return index.row();
+    if (role == IconPathRole)
+        return dictionary->iconPath();
+    if (role == IsSelectedRole)
+        return _dictionaries[dictionary];
+    return QVariant();
+}
+
+bool DictManagerModel::setData(const QModelIndex &index, const QVariant &value, int role)
+{
+    if (index.row() < 0 || index.row() > _dictList.count())
+        return false;
+
+    CommonDictInterface* dictionary = _dictList[index.row()];
+    if (role == NameRole)
+        return true;
+    if (role == NumberRole)
+        return true;
+    if (role == IconPathRole)
+        return true;
+    if (role == IsSelectedRole)
+    {
+        if (value.type() == QVariant::Bool)
+        {
+            _dictionaries[dictionary] = value.toBool();
+            emit dataChanged(index, index);
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+    }
+    return false;
+}
+
+Qt::ItemFlags DictManagerModel::flags(const QModelIndex &index) const
+{
+    Qt::ItemFlags fl = QAbstractItemModel::flags(index);
+    return (fl | Qt::ItemIsEditable);
+}
+
+void DictManagerModel::addDictionary(CommonDictInterface *dictionary, bool isActive)
+{
+    beginInsertRows(QModelIndex(), rowCount(), rowCount());
+    _dictionaries.insert(dictionary, isActive);
+    _dictList << dictionary;
+    endInsertRows();
+}
diff --git a/src/mdictionary/gui/DictManagerModel.h b/src/mdictionary/gui/DictManagerModel.h
new file mode 100644 (file)
index 0000000..c722b2e
--- /dev/null
@@ -0,0 +1,48 @@
+#ifndef DICTMANAGERMODEL_H
+#define DICTMANAGERMODEL_H
+
+#include <QAbstractListModel>
+#include <QHash>
+#include "../../include/GUIInterface.h"
+
+/*!
+  Contains a list of installed dictionaries.
+  Data source for qml list view.
+*/
+class DictManagerModel : public QAbstractListModel
+{
+    Q_OBJECT
+public:
+    enum DictTypeRoles
+    {
+        NameRole = Qt::UserRole + 1,
+        IconPathRole,
+        IsSelectedRole,
+        NumberRole
+    };
+
+    //! Constructor
+    /*!
+      \param dictionaries list of dictionaries
+      \param parent parent of this class.
+    */
+    explicit DictManagerModel(QHash<CommonDictInterface*, bool> dictionaries, QObject *parent = 0);
+
+    int rowCount(const QModelIndex & parent = QModelIndex()) const;
+
+    QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
+    bool setData(const QModelIndex &index, const QVariant &value, int role);
+
+    Qt::ItemFlags flags(const QModelIndex &index) const;
+    void setDictionaries(QHash<CommonDictInterface*, bool> dictionaries);
+
+    void clear();
+
+private:
+    QHash<CommonDictInterface*, bool> _dictionaries;
+    QList<CommonDictInterface*> _dictList;
+
+    void addDictionary(CommonDictInterface* dictionary, bool isActive);
+};
+
+#endif // DICTMANAGERMODEL_H
index 8519c93..5084125 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,26 @@ 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();
+    //model = new DictManagerModel(, this);
+    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 +110,51 @@ 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);
+        //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(closeButton, SIGNAL(clicked()), 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);
@@ -126,6 +166,7 @@ void DictManagerWidget::refreshDictsList() {
 
     while(i.hasNext()) {
         i.next();
+
         QListWidgetItem* item = new QListWidgetItem();
         QString name;
         if (i.key()->type() == "stardict") {
@@ -151,6 +192,7 @@ void DictManagerWidget::refreshDictsList() {
     }
 
     dictList->sortItems();
+    #endif
 }
 
 void DictManagerWidget::showEvent(QShowEvent *e) {
index 3e7e4d7..15befcb 100644 (file)
@@ -32,6 +32,9 @@
 #include <QtGui>
 #include "../../include/GUIInterface.h"
 #include "MenuWidget.h"
+#include "DictManagerModel.h"
+#include <QtDeclarative/QDeclarativeView>
+#include <QtDeclarative/QDeclarativeContext>
 
 
 /*!
@@ -119,6 +122,12 @@ private:
     QHash<QListWidgetItem*, CommonDictInterface*> dictsHash;
     GUIInterface* guiInterface;
 
+    #ifndef Q_WS_MAEMO_5
+    QDeclarativeView* qmlView;
+    QDeclarativeContext* ctxt;
+    DictManagerModel* model;
+    #endif
+
     bool _changed;
 
     void refreshDictsList();
index 8ee4658..cc5af0a 100644 (file)
@@ -39,7 +39,8 @@ SOURCES += gui/main.cpp \
     gui/DBusAdapter.cpp \
     gui/NotifyManager.cpp \
     gui/SpinBox.cpp \
-    gui/DictTypeModel.cpp
+    gui/DictTypeModel.cpp \
+    gui/DictManagerModel.cpp
 
 HEADERS += gui/MainWindow.h \
     backbone/ConfigGenerator.h \
@@ -71,7 +72,8 @@ HEADERS += gui/MainWindow.h \
     gui/DBusAdapter.h \
     gui/NotifyManager.h \
     gui/SpinBox.h \
-    gui/DictTypeModel.h
+    gui/DictTypeModel.h \
+    gui/DictManagerModel.h
 
 RESOURCES += ../../data/gui.qrc
 
index 15b01c6..2f7c1a0 100644 (file)
@@ -1,6 +1,76 @@
+/*******************************************************************************
+
+    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
 
 Rectangle {
-    width: 100
-    height: 62
+    SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
+//    signal selectedRow(int nr)
+
+    id: rectangle1
+    color: myPalette.base
+    anchors.fill: parent
+
+    ElementsListView{
+        id: dictList
+        width: rectangle1.width
+//        height: rectangle1.height
+        anchors.top: parent.top
+        highlightResizeSpeed: 1000
+        delegate: Component{
+            id: dictListDelegate
+            Item {
+                width: rectangle1.width
+                height: typeText.height
+                MouseArea{
+                    anchors.fill: parent
+                    onClicked: {
+                        dictTypeList.currentIndex = number
+                    }
+                    onDoubleClicked: {
+                        selectedRow(number)
+                    }
+                }
+                Row {
+                    //image zaznacz/odznacz
+                    //image logo
+                    Image {
+                        id: logo
+                        source: iconPath
+                    }
+                    Text {
+                        id: nameText
+                        text: name
+//                        width: rectangle1.width
+                    }
+                }
+            }
+
+        }
+        model: dictModel
+    }
+
+    //buttonki
+
 }
index 0374115..733a51f 100644 (file)
@@ -41,7 +41,8 @@ GooglePlugin::GooglePlugin(QObject *parent): CommonDictInterface(parent),
     _settings->setValue("type","google");
     _settings->setValue("connection_accepted","true");
     _dictDialog = new GoogleDictDialog(this,this);
-    _icon = QIcon("/usr/share/mdictionary/google.png");
+    _iconPath = "/usr/share/mdictionary/google.png";
+    _icon = QIcon(_iconPath);
 
     stopped = false;
     initLanguages();
@@ -150,6 +151,10 @@ QIcon* GooglePlugin::icon() {
     return &_icon;
 }
 
+QString GooglePlugin::iconPath(){
+    return _iconPath;
+}
+
 
 CommonDictInterface* GooglePlugin::getNew(const Settings* settings) const {
     GooglePlugin *plugin = new GooglePlugin();
index 2808195..f62603c 100644 (file)
@@ -102,6 +102,9 @@ public:
     //! \returns plugin icon
     QIcon* icon();
 
+    //! \returns plugin icon's resource path
+    QString iconPath();
+
     //! \returns empty translation object (to be fetched later) for a given key
     Translation* getTranslationFor(QString key);
 
@@ -147,6 +150,8 @@ private:
 
     //! icon displayed during translations and when a dictionary is chosen
     QIcon _icon;
+    //! Path to icon
+    QString _iconPath;
     Settings *_settings;
     //! indicates if search is stopped
     bool stopped;
index 67e2db3..229cff4 100644 (file)
@@ -42,7 +42,8 @@ StarDictPlugin::StarDictPlugin(QObject *parent) : CommonDictInterface(parent),
             this, SIGNAL(notify(Notify::NotifyType,QString)));
 
     _settings->setValue("type","stardict");
-    _icon = QIcon("/usr/share/mdictionary/stardict.png");
+    _iconPath = "/usr/share/mdictionary/stardict.png";
+    _icon = QIcon(_iconPath);
     stopped = false;
 
     _settings->setValue("strip_accents","true");
@@ -343,4 +344,8 @@ QIcon* StarDictPlugin::icon() {
     return &_icon;
 }
 
+QString StarDictPlugin::iconPath(){
+    return _iconPath;
+}
+
 Q_EXPORT_PLUGIN2(stardict, StarDictPlugin)
index 5937b3a..94aa674 100644 (file)
@@ -103,6 +103,9 @@ public:
     //! \returns plugin icon
     QIcon* icon();
 
+    //! \returns plugin icon's resource path
+    QString iconPath();
+
     /*!
         plugin should delete any files (eg. cache) that have been created and are ready
         to be deleted
@@ -194,6 +197,8 @@ private:
     QString _name;
     QString _infoNote;
     QIcon _icon;
+    //! Path to icon
+    QString _iconPath;
     volatile bool stopped;
     Settings *_settings;
     StarDictDialog* _dictDialog;
index 17e8eca..044bcca 100644 (file)
@@ -52,7 +52,8 @@ XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
     }
 
     _settings->setValue("type","xdxf");
-    _icon = QIcon("/usr/share/mdictionary/xdxf.png");
+    _iconPath = "/usr/share/mdictionary/xdxf.png";
+    _icon = QIcon(_iconPath);
     _wordsCount = -1;
     stopped = false;
 
@@ -452,6 +453,10 @@ QIcon* XdxfPlugin::icon() {
     return &_icon;
 }
 
+QString XdxfPlugin::iconPath(){
+    return _iconPath;
+}
+
 
 int XdxfPlugin::countWords() {
     if(_wordsCount>0)
index 858fd49..6f32451 100644 (file)
@@ -99,6 +99,9 @@ public:
     //! \returns plugin icon
     QIcon* icon();
 
+    //! \returns plugin icon's resource path
+    QString iconPath();
+
     /*!
         plugin should delete any files (eg. cache) that have been created and are ready
         to be deleted
@@ -185,6 +188,8 @@ private:
     QString _infoNote;
     QString _dictionaryInfo;
     QIcon _icon;
+    //! Path to icon
+    QString _iconPath;
     QSqlDatabase db;
     QString db_name;
     long _wordsCount;