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

src/mdictionary/gui/DictTypeModel.cpp [new file with mode: 0644]
src/mdictionary/gui/DictTypeModel.h [new file with mode: 0644]
src/mdictionary/gui/DictTypeSelectDialog.cpp
src/mdictionary/gui/DictTypeSelectDialog.h
src/mdictionary/gui/WelcomeScreenWidget.cpp
src/mdictionary/gui/WelcomeScreenWidget.h
src/mdictionary/mdictionary.pro
src/mdictionary/qml/DictManagerWidget.qml [new file with mode: 0644]
src/mdictionary/qml/DictTypeSelectDialog.qml [new file with mode: 0644]
src/mdictionary/qml/ElementsListView.qml [new file with mode: 0644]
src/mdictionary/qml/WordListWidget.qml [new file with mode: 0644]

diff --git a/src/mdictionary/gui/DictTypeModel.cpp b/src/mdictionary/gui/DictTypeModel.cpp
new file mode 100644 (file)
index 0000000..b2d09b2
--- /dev/null
@@ -0,0 +1,72 @@
+/*******************************************************************************
+
+    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 DictTypeModel.cpp
+    \brief Implements plugin data for list model
+
+    \author Marcin Kaźmierczak <marcin.kazmierczak@comarch.pl>
+*/
+
+#include "DictTypeModel.h"
+
+DictTypeModel::DictTypeModel(QList<CommonDictInterface *> plugins, QObject *parent) :
+    QAbstractListModel(parent)
+{
+    QHash<int, QByteArray> roles;
+    roles[TypeRole] = "type";
+    roles[NumberRole] = "number";
+    setRoleNames(roles);
+
+    setDictTypes(plugins);
+}
+
+int DictTypeModel::rowCount(const QModelIndex &parent) const
+{
+    return _plugins.count();
+}
+
+void DictTypeModel::setDictTypes(QList<CommonDictInterface *> plugins)
+{
+    for(int i = 0; i < plugins.count(); i++)
+    {
+        addType(plugins[i]);
+    }
+}
+
+QVariant DictTypeModel::data(const QModelIndex & index, int role) const
+{
+    if (index.row() < 0 || index.row() > _plugins.count())
+        return QVariant();
+
+    const CommonDictInterface* plugin = _plugins[index.row()];
+    if (role == TypeRole)
+        return plugin->type();
+    if (role == NumberRole)
+        return index.row();
+    return QVariant();
+}
+
+void DictTypeModel::addType(CommonDictInterface *plugin)
+{
+    beginInsertRows(QModelIndex(), rowCount(), rowCount());
+    _plugins << plugin;
+    endInsertRows();
+}
diff --git a/src/mdictionary/gui/DictTypeModel.h b/src/mdictionary/gui/DictTypeModel.h
new file mode 100644 (file)
index 0000000..3a35e91
--- /dev/null
@@ -0,0 +1,67 @@
+/*******************************************************************************
+
+    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 DictTypeModel.h
+    \brief Implements plugin data for list model
+
+    \author Marcin Kaźmierczak <marcin.kazmierczak@comarch.pl>
+*/
+
+#ifndef DICTTYPEMODEL_H
+#define DICTTYPEMODEL_H
+
+#include <QAbstractListModel>
+#include <QHash>
+#include "../../include/GUIInterface.h"
+
+/*!
+  Contains a list of plugin types.
+  Data source for qml list view.
+*/
+class DictTypeModel : public QAbstractListModel
+{
+    Q_OBJECT
+public:
+    enum DictTypeRoles
+    {
+        TypeRole = Qt::UserRole + 1,
+        NumberRole
+    };
+
+    //! Constructor
+    /*!
+      \param plugins list of plugin types
+      \param parent parent of this class.
+    */
+    explicit DictTypeModel(QList<CommonDictInterface*> plugins, QObject *parent = 0);
+
+    int rowCount(const QModelIndex & parent = QModelIndex()) const;
+
+    QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
+
+private:
+    void setDictTypes(QList<CommonDictInterface*> plugins);
+    QList<CommonDictInterface*> _plugins;
+
+    void addType(CommonDictInterface* plugin);
+};
+
+#endif // DICTTYPEMODEL_H
index 62c7f42..8e26c14 100644 (file)
@@ -28,7 +28,7 @@
 #include "DictTypeSelectDialog.h"
 
 DictTypeSelectDialog::DictTypeSelectDialog(QList<CommonDictInterface *> plugins, QWidget *parent) :
-    QDialog(parent) {
+    QDialog(parent), model(plugins, this) {
 
     setWindowTitle(tr("Select dictionary type"));
 
@@ -37,6 +37,26 @@ DictTypeSelectDialog::DictTypeSelectDialog(QList<CommonDictInterface *> plugins,
     verticalLayout = new QVBoxLayout(this);
     setLayout(verticalLayout);
 
+#ifndef Q_WS_MAEMO_5
+    qmlView = new QDeclarativeView(this);
+    qmlView->setSource(QUrl::fromLocalFile("/usr/share/mdictionary/qml/DictTypeSelectDialog.qml"));
+    ctxt = qmlView->rootContext();
+
+//    model = new DictTypeModel(plugins, this);
+    ctxt->setContextProperty("dictTypeModel", &model);
+
+    _selectedPlugin = 0;
+
+    QGraphicsObject *rootObject = qmlView->rootObject();
+    connect(rootObject, SIGNAL(selectedRow(int)),
+            this, SLOT(pluginSelected(int)));
+
+    qmlView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
+    verticalLayout->addWidget(qmlView);
+
+#endif
+#ifdef Q_WS_MAEMO_5
+
     pluginsListWidget = new QListWidget(this);
 
     verticalLayout->addWidget(pluginsListWidget);
@@ -51,6 +71,7 @@ DictTypeSelectDialog::DictTypeSelectDialog(QList<CommonDictInterface *> plugins,
 
     connect(pluginsListWidget, SIGNAL(itemActivated(QListWidgetItem*)),
             this, SLOT(pluginSelected(QListWidgetItem*)));
+#endif
 }
 
 void DictTypeSelectDialog::pluginSelected(QListWidgetItem *item) {
@@ -58,6 +79,11 @@ void DictTypeSelectDialog::pluginSelected(QListWidgetItem *item) {
     accept();
 }
 
+void DictTypeSelectDialog::pluginSelected(int item) {
+    _selectedPlugin = plugins[item];
+    accept();
+}
+
 CommonDictInterface* DictTypeSelectDialog::selectedPlugin() {
     return _selectedPlugin;
 }
index 34b0847..84f8545 100644 (file)
@@ -31,6 +31,9 @@
 #include <QtGui>
 #include "../../include/settings.h"
 #include "../../include/CommonDictInterface.h"
+#include "DictTypeModel.h"
+#include <QtDeclarative/QDeclarativeView>
+#include <QtDeclarative/QDeclarativeContext>
 
 #define PLUGIN_ROW_ROLE 99      //TODO remove this
 
@@ -60,12 +63,17 @@ protected:
                                   QWidget *parent = 0);
 private Q_SLOTS:
     void pluginSelected(QListWidgetItem* item);
+    void pluginSelected(int item);
 
 private:
     QListWidget* pluginsListWidget;
     QList<CommonDictInterface*> plugins;
     QVBoxLayout* verticalLayout;
     CommonDictInterface* _selectedPlugin;
+
+    QDeclarativeView* qmlView;
+    QDeclarativeContext* ctxt;
+    DictTypeModel model;
 };
 
 #endif // DICTTYPESELECTDIALOG_H
index f2ec62c..47a2ac3 100644 (file)
@@ -37,27 +37,30 @@ WelcomeScreenWidget::WelcomeScreenWidget(QWidget *parent) :
     mainLayout = new QVBoxLayout(this);
     setLayout(mainLayout);
 
-    qmlView = new QDeclarativeView;
+    #ifndef Q_WS_MAEMO_5
+    qmlView = new QDeclarativeView(this);
     qmlView->setSource(QUrl::fromLocalFile("/usr/share/mdictionary/qml/WelcomeScreenWidget.qml"));
 
     mainLayout->addWidget(qmlView, 0, Qt::AlignCenter);
 
-    //stary kod:
-    //imageLabel = new QLabel(this);
-    //mainLabel = new QLabel(infoNote, this);
+    #endif
+    #ifdef Q_WS_MAEMO_5
 
-    //mainLayout->addStretch(0);
-    //mainLayout->addWidget(imageLabel, 0, Qt::AlignCenter);
-    //mainLayout->addWidget(mainLabel, 0, Qt::AlignCenter);
-    //mainLayout->addStretch(0);
+    imageLabel = new QLabel(this);
+    mainLabel = new QLabel(infoNote, this);
 
-    //QImage img(":/icons/logo/mdictionary.png");
-    //imageLabel->setPixmap(QPixmap::fromImage(img));
-    //imageLabel->resize(imageLabel->pixmap()->size());
+    mainLayout->addStretch(0);
+    mainLayout->addWidget(imageLabel, 0, Qt::AlignCenter);
+    mainLayout->addWidget(mainLabel, 0, Qt::AlignCenter);
+    mainLayout->addStretch(0);
 
+    QImage img(":/icons/logo/mdictionary.png");
+    imageLabel->setPixmap(QPixmap::fromImage(img));
+    imageLabel->resize(imageLabel->pixmap()->size());
 
-    //mainLabel->setWordWrap(true);
-    //koniec kodu
+
+    mainLabel->setWordWrap(true);
+    #endif
 
     #ifdef Q_WS_MAEMO_5
         //mainLayout->addSpacing(20);
index 6e82a87..5c596d3 100644 (file)
@@ -31,8 +31,8 @@
 #include <QScrollArea>
 #include <QtGui>
 #include <QtDeclarative/QDeclarativeView>
-#include <QtDeclarative/QDeclarativeEngine>
-#include <QtDeclarative/QDeclarativeContext>
+//#include <QtDeclarative/QDeclarativeEngine>
+//#include <QtDeclarative/QDeclarativeContext>
 
 //! Displays welcome screen with logo and name of application
 class WelcomeScreenWidget : public QScrollArea
@@ -46,8 +46,8 @@ private:
     QLabel* mainLabel, * licenseLabel, *imageLabel;
 
     QDeclarativeView* qmlView;
-    QDeclarativeEngine* engine;
-    QDeclarativeContext* context;
+//    QDeclarativeEngine* engine;
+//    QDeclarativeContext* context;
     QWidget* widget;
 };
 
index c31eed0..8701e4e 100644 (file)
@@ -38,7 +38,8 @@ SOURCES += gui/main.cpp \
     gui/TranslationView.cpp \
     gui/DBusAdapter.cpp \
     gui/NotifyManager.cpp \
-    gui/SpinBox.cpp
+    gui/SpinBox.cpp \
+    gui/DictTypeModel.cpp
 
 HEADERS += gui/MainWindow.h \
     backbone/ConfigGenerator.h \
@@ -69,7 +70,8 @@ HEADERS += gui/MainWindow.h \
     ../include/DictDialog.h \
     gui/DBusAdapter.h \
     gui/NotifyManager.h \
-    gui/SpinBox.h
+    gui/SpinBox.h \
+    gui/DictTypeModel.h
 
 RESOURCES += ../../data/gui.qrc
 
@@ -83,7 +85,11 @@ OTHER_FILES += \
     qml/SearchBarWidget.qml \
     qml/IconButton.qml \
     qml/MyTextLineEdit.qml \
-    qml/ProgressBar.qml
+    qml/ProgressBar.qml \
+    qml/ElementsListView.qml \
+    qml/DictTypeSelectDialog.qml \
+    qml/DictManagerWidget.qml \
+    qml/WordListWidget.qml
 
 target.path = $$BIN_DIR
 INSTALLS += target
@@ -179,6 +185,10 @@ unix {
        qmls.files += ./qml/IconButton.qml
        qmls.files += ./qml/MyTextLineEdit.qml
         qmls.files += ./qml/ProgressBar.qml
+        qmls.files += ./qml/ElementsListView.qml
+        qmls.files += ./qml/DictTypeSelectDialog.qml
+        qmls.files += ./qml/DictManagerWidget.qml
+        qmls.files += ./qml/WordListWidget.qml
     }
        
     INSTALLS += desktop icon64 shared service css css_images qmls
diff --git a/src/mdictionary/qml/DictManagerWidget.qml b/src/mdictionary/qml/DictManagerWidget.qml
new file mode 100644 (file)
index 0000000..15b01c6
--- /dev/null
@@ -0,0 +1,6 @@
+import Qt 4.7
+
+Rectangle {
+    width: 100
+    height: 62
+}
diff --git a/src/mdictionary/qml/DictTypeSelectDialog.qml b/src/mdictionary/qml/DictTypeSelectDialog.qml
new file mode 100644 (file)
index 0000000..e57069a
--- /dev/null
@@ -0,0 +1,67 @@
+/*******************************************************************************
+
+    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 {
+    SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
+    signal selectedRow(int nr)
+
+    id: rectangle1
+    color: myPalette.base
+    anchors.fill: parent
+
+    ElementsListView{
+        id: dictTypeList
+        width: rectangle1.width
+        height: rectangle1.height
+        highlightResizeSpeed: 1000
+        delegate: Component{
+            id: dictTypeListDelegate
+            Item {
+                width: rectangle1.width
+                height: typeText.height
+                MouseArea{
+                    anchors.fill: parent
+                    onClicked: {
+                        dictTypeList.currentIndex = number
+                    }
+                    onDoubleClicked: {
+                        selectedRow(number)
+                    }
+                }
+                Row {
+                    Text {
+                        id: typeText
+                        text: type
+                        width: rectangle1.width
+                    }
+                }
+            }
+
+        }
+        model: dictTypeModel
+    }
+
+}
diff --git a/src/mdictionary/qml/ElementsListView.qml b/src/mdictionary/qml/ElementsListView.qml
new file mode 100644 (file)
index 0000000..c9a7561
--- /dev/null
@@ -0,0 +1,33 @@
+/*******************************************************************************
+
+    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
+
+ListView {
+    anchors.fill: parent
+    focus: true
+    currentIndex: 0
+    highlight: Rectangle { color: "lightsteelblue"; radius: 5; width: parent.parent.width }
+    highlightMoveSpeed: 1000
+}
diff --git a/src/mdictionary/qml/WordListWidget.qml b/src/mdictionary/qml/WordListWidget.qml
new file mode 100644 (file)
index 0000000..15b01c6
--- /dev/null
@@ -0,0 +1,6 @@
+import Qt 4.7
+
+Rectangle {
+    width: 100
+    height: 62
+}