first version of list element in qml
authorMarcin Kaźmierczak <marcin@marcin-desktop.(none)>
Thu, 16 Dec 2010 09:10:51 +0000 (10:10 +0100)
committerMarcin Kaźmierczak <marcin@marcin-desktop.(none)>
Thu, 16 Dec 2010 09:10:51 +0000 (10:10 +0100)
src/mdictionary/gui/DictTypeModel.cpp [new file with mode: 0644]
src/mdictionary/gui/DictTypeModel.h [new file with mode: 0644]
src/mdictionary/mdictionary.pro
src/mdictionary/qml/DictListDelegate.qml [new file with mode: 0644]
src/mdictionary/qml/DictTypeListDelegate.qml [new file with mode: 0644]
src/mdictionary/qml/DictTypeListView.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/WordListDelegate.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..5823829
--- /dev/null
@@ -0,0 +1,42 @@
+#include "DictTypeModel.h"
+
+DictTypeModel::DictTypeModel(QList<CommonDictInterface *> plugins, QObject *parent) :
+    QAbstractListModel(parent)
+{
+    QHash<int, QByteArray> roles;
+    roles[TypeRole] = "type";
+    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();
+    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..1b24aff
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef DICTTYPEMODEL_H
+#define DICTTYPEMODEL_H
+
+#include <QAbstractListModel>
+#include <QHash>
+#include "../../include/GUIInterface.h"
+
+class DictTypeModel : public QAbstractListModel
+{
+    Q_OBJECT
+public:
+    enum DictTypeRoles
+    {
+        TypeRole = Qt::UserRole + 1
+    };
+
+    explicit DictTypeModel(QList<CommonDictInterface*> plugins, QObject *parent = 0);
+
+    void setDictTypes(QList<CommonDictInterface*> plugins);
+
+    int rowCount(const QModelIndex & parent = QModelIndex()) const;
+
+    QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
+
+private:
+    QList<CommonDictInterface*> _plugins;
+
+    void addType(CommonDictInterface* plugin);
+};
+
+#endif // DICTTYPEMODEL_H
index fd4b0bc..08d3050 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
 
@@ -82,7 +84,13 @@ OTHER_FILES += \
     qml/AboutWidget.qml \
     qml/SearchBarWidget.qml \
     qml/IconButton.qml \
-    qml/MyTextLineEdit.qml
+    qml/MyTextLineEdit.qml \
+    qml/DictListDelegate.qml \
+    qml/DictTypeListDelegate.qml \
+    qml/WordListDelegate.qml \
+    qml/ElementsListView.qml \
+    qml/DictTypeListView.qml \
+    qml/DictTypeSelectDialog.qml
 
 target.path = $$BIN_DIR
 INSTALLS += target
@@ -177,6 +185,12 @@ unix {
        qmls.files += ./qml/SearchBarWidget.qml
        qmls.files += ./qml/IconButton.qml
        qmls.files += ./qml/MyTextLineEdit.qml
+        qmls.files += ./qml/DictListDelegate.qml
+        qmls.files += ./qml/DictTypeListDelegate.qml
+        qmls.files += ./qml/WordListDelegate.qml
+        qmls.files += ./qml/ElementsListView.qml
+        qmls.files += ./qml/DictTypeListView.qml
+        qmls.files += ./qml/DictTypeSelectDialog.qml
     }
        
     INSTALLS += desktop icon64 shared service css css_images qmls
diff --git a/src/mdictionary/qml/DictListDelegate.qml b/src/mdictionary/qml/DictListDelegate.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/DictTypeListDelegate.qml b/src/mdictionary/qml/DictTypeListDelegate.qml
new file mode 100644 (file)
index 0000000..e2ebbe9
--- /dev/null
@@ -0,0 +1,5 @@
+import Qt 4.7
+
+Text {
+    text: type
+}
diff --git a/src/mdictionary/qml/DictTypeListView.qml b/src/mdictionary/qml/DictTypeListView.qml
new file mode 100644 (file)
index 0000000..9d83416
--- /dev/null
@@ -0,0 +1,8 @@
+import Qt 4.7
+
+ElementsListView{
+    anchors.fill: parent
+    delegate: DictTypeListDelegate{}
+    model: dictTypeModel
+    focus: true
+}
diff --git a/src/mdictionary/qml/DictTypeSelectDialog.qml b/src/mdictionary/qml/DictTypeSelectDialog.qml
new file mode 100644 (file)
index 0000000..5bf3b73
--- /dev/null
@@ -0,0 +1,33 @@
+import Qt 4.7
+
+Rectangle {
+    SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
+
+    id: rectangle1
+    //width: (helloText.width > logo.width) ? (helloText.width) : (logo.width)
+    //height: logo.height + helloText.height
+    color: myPalette.window
+    anchors.fill: parent
+
+    DictTypeListView{
+        id: dictTypeList
+
+    }
+
+//        Image {
+//            id: logo
+//            source: "qrc:/icons/logo/mdictionary.png"
+//            width: 240
+//            height: 200
+//            anchors.horizontalCenter: parent.horizontalCenter
+//            fillMode: Image.PreserveAspectFit
+//            anchors.top: parent.top
+//        }
+
+//        Text {
+//            id: helloText
+//            text: qsTr("<center><h1>Welcome in mDictionary!</h1></center>")
+//            anchors.bottom: parent.bottom
+//        }
+
+}
diff --git a/src/mdictionary/qml/ElementsListView.qml b/src/mdictionary/qml/ElementsListView.qml
new file mode 100644 (file)
index 0000000..d365763
--- /dev/null
@@ -0,0 +1,6 @@
+import Qt 4.7
+
+ListView {
+    property int selectedElement: -1
+
+}
diff --git a/src/mdictionary/qml/WordListDelegate.qml b/src/mdictionary/qml/WordListDelegate.qml
new file mode 100644 (file)
index 0000000..15b01c6
--- /dev/null
@@ -0,0 +1,6 @@
+import Qt 4.7
+
+Rectangle {
+    width: 100
+    height: 62
+}