From 6e43150fac4affb7e2cb3f6d50ee727bcddba9a1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marcin=20Ka=C5=BAmierczak?= Date: Thu, 16 Dec 2010 16:30:47 +0100 Subject: [PATCH] DictTypeSelectDialog ported to qml. Remove empty qml files. --- src/mdictionary/gui/DictTypeModel.cpp | 30 +++++++++++ src/mdictionary/gui/DictTypeModel.h | 42 +++++++++++++-- src/mdictionary/gui/DictTypeSelectDialog.cpp | 28 +++++++++- src/mdictionary/gui/DictTypeSelectDialog.h | 8 +++ src/mdictionary/gui/WelcomeScreenWidget.cpp | 29 +++++----- src/mdictionary/gui/WelcomeScreenWidget.h | 8 +-- src/mdictionary/mdictionary.pro | 14 ++--- src/mdictionary/qml/DictListDelegate.qml | 6 --- src/mdictionary/qml/DictManagerWidget.qml | 6 +++ src/mdictionary/qml/DictTypeListDelegate.qml | 5 -- src/mdictionary/qml/DictTypeListView.qml | 8 --- src/mdictionary/qml/DictTypeSelectDialog.qml | 74 +++++++++++++++++++------- src/mdictionary/qml/ElementsListView.qml | 31 ++++++++++- src/mdictionary/qml/WordListDelegate.qml | 6 --- src/mdictionary/qml/WordListWidget.qml | 6 +++ 15 files changed, 224 insertions(+), 77 deletions(-) delete mode 100644 src/mdictionary/qml/DictListDelegate.qml create mode 100644 src/mdictionary/qml/DictManagerWidget.qml delete mode 100644 src/mdictionary/qml/DictTypeListDelegate.qml delete mode 100644 src/mdictionary/qml/DictTypeListView.qml delete mode 100644 src/mdictionary/qml/WordListDelegate.qml create mode 100644 src/mdictionary/qml/WordListWidget.qml diff --git a/src/mdictionary/gui/DictTypeModel.cpp b/src/mdictionary/gui/DictTypeModel.cpp index 5823829..b2d09b2 100644 --- a/src/mdictionary/gui/DictTypeModel.cpp +++ b/src/mdictionary/gui/DictTypeModel.cpp @@ -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 . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +/*! \file DictTypeModel.cpp + \brief Implements plugin data for list model + + \author Marcin Kaźmierczak +*/ + #include "DictTypeModel.h" DictTypeModel::DictTypeModel(QList plugins, QObject *parent) : @@ -5,6 +32,7 @@ DictTypeModel::DictTypeModel(QList plugins, QObject *pare { QHash roles; roles[TypeRole] = "type"; + roles[NumberRole] = "number"; setRoleNames(roles); setDictTypes(plugins); @@ -31,6 +59,8 @@ QVariant DictTypeModel::data(const QModelIndex & index, int role) const const CommonDictInterface* plugin = _plugins[index.row()]; if (role == TypeRole) return plugin->type(); + if (role == NumberRole) + return index.row(); return QVariant(); } diff --git a/src/mdictionary/gui/DictTypeModel.h b/src/mdictionary/gui/DictTypeModel.h index 1b24aff..3a35e91 100644 --- a/src/mdictionary/gui/DictTypeModel.h +++ b/src/mdictionary/gui/DictTypeModel.h @@ -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 . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +/*! \file DictTypeModel.h + \brief Implements plugin data for list model + + \author Marcin Kaźmierczak +*/ + #ifndef DICTTYPEMODEL_H #define DICTTYPEMODEL_H @@ -5,24 +32,33 @@ #include #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 + TypeRole = Qt::UserRole + 1, + NumberRole }; + //! Constructor + /*! + \param plugins list of plugin types + \param parent parent of this class. + */ explicit DictTypeModel(QList plugins, QObject *parent = 0); - void setDictTypes(QList plugins); - int rowCount(const QModelIndex & parent = QModelIndex()) const; QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; private: + void setDictTypes(QList plugins); QList _plugins; void addType(CommonDictInterface* plugin); diff --git a/src/mdictionary/gui/DictTypeSelectDialog.cpp b/src/mdictionary/gui/DictTypeSelectDialog.cpp index 62c7f42..8e26c14 100644 --- a/src/mdictionary/gui/DictTypeSelectDialog.cpp +++ b/src/mdictionary/gui/DictTypeSelectDialog.cpp @@ -28,7 +28,7 @@ #include "DictTypeSelectDialog.h" DictTypeSelectDialog::DictTypeSelectDialog(QList plugins, QWidget *parent) : - QDialog(parent) { + QDialog(parent), model(plugins, this) { setWindowTitle(tr("Select dictionary type")); @@ -37,6 +37,26 @@ DictTypeSelectDialog::DictTypeSelectDialog(QList 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 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; } diff --git a/src/mdictionary/gui/DictTypeSelectDialog.h b/src/mdictionary/gui/DictTypeSelectDialog.h index 34b0847..84f8545 100644 --- a/src/mdictionary/gui/DictTypeSelectDialog.h +++ b/src/mdictionary/gui/DictTypeSelectDialog.h @@ -31,6 +31,9 @@ #include #include "../../include/settings.h" #include "../../include/CommonDictInterface.h" +#include "DictTypeModel.h" +#include +#include #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 plugins; QVBoxLayout* verticalLayout; CommonDictInterface* _selectedPlugin; + + QDeclarativeView* qmlView; + QDeclarativeContext* ctxt; + DictTypeModel model; }; #endif // DICTTYPESELECTDIALOG_H diff --git a/src/mdictionary/gui/WelcomeScreenWidget.cpp b/src/mdictionary/gui/WelcomeScreenWidget.cpp index f2ec62c..47a2ac3 100644 --- a/src/mdictionary/gui/WelcomeScreenWidget.cpp +++ b/src/mdictionary/gui/WelcomeScreenWidget.cpp @@ -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); diff --git a/src/mdictionary/gui/WelcomeScreenWidget.h b/src/mdictionary/gui/WelcomeScreenWidget.h index 6e82a87..5c596d3 100644 --- a/src/mdictionary/gui/WelcomeScreenWidget.h +++ b/src/mdictionary/gui/WelcomeScreenWidget.h @@ -31,8 +31,8 @@ #include #include #include -#include -#include +//#include +//#include //! 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; }; diff --git a/src/mdictionary/mdictionary.pro b/src/mdictionary/mdictionary.pro index 08d3050..5101211 100644 --- a/src/mdictionary/mdictionary.pro +++ b/src/mdictionary/mdictionary.pro @@ -85,12 +85,10 @@ OTHER_FILES += \ qml/SearchBarWidget.qml \ qml/IconButton.qml \ qml/MyTextLineEdit.qml \ - qml/DictListDelegate.qml \ - qml/DictTypeListDelegate.qml \ - qml/WordListDelegate.qml \ qml/ElementsListView.qml \ - qml/DictTypeListView.qml \ - qml/DictTypeSelectDialog.qml + qml/DictTypeSelectDialog.qml \ + qml/DictManagerWidget.qml \ + qml/WordListWidget.qml target.path = $$BIN_DIR INSTALLS += target @@ -185,12 +183,10 @@ 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 + 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/DictListDelegate.qml b/src/mdictionary/qml/DictListDelegate.qml deleted file mode 100644 index 15b01c6..0000000 --- a/src/mdictionary/qml/DictListDelegate.qml +++ /dev/null @@ -1,6 +0,0 @@ -import Qt 4.7 - -Rectangle { - width: 100 - height: 62 -} diff --git a/src/mdictionary/qml/DictManagerWidget.qml b/src/mdictionary/qml/DictManagerWidget.qml new file mode 100644 index 0000000..15b01c6 --- /dev/null +++ b/src/mdictionary/qml/DictManagerWidget.qml @@ -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 deleted file mode 100644 index e2ebbe9..0000000 --- a/src/mdictionary/qml/DictTypeListDelegate.qml +++ /dev/null @@ -1,5 +0,0 @@ -import Qt 4.7 - -Text { - text: type -} diff --git a/src/mdictionary/qml/DictTypeListView.qml b/src/mdictionary/qml/DictTypeListView.qml deleted file mode 100644 index 9d83416..0000000 --- a/src/mdictionary/qml/DictTypeListView.qml +++ /dev/null @@ -1,8 +0,0 @@ -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 index 5bf3b73..e57069a 100644 --- a/src/mdictionary/qml/DictTypeSelectDialog.qml +++ b/src/mdictionary/qml/DictTypeSelectDialog.qml @@ -1,33 +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 . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ +/*! + author: Marcin Kaźmierczak +*/ + import Qt 4.7 Rectangle { SystemPalette { id: myPalette; colorGroup: SystemPalette.Active } + signal selectedRow(int nr) id: rectangle1 - //width: (helloText.width > logo.width) ? (helloText.width) : (logo.width) - //height: logo.height + helloText.height - color: myPalette.window + color: myPalette.base anchors.fill: parent - DictTypeListView{ + 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 } -// 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("

Welcome in mDictionary!

") -// anchors.bottom: parent.bottom -// } - } diff --git a/src/mdictionary/qml/ElementsListView.qml b/src/mdictionary/qml/ElementsListView.qml index d365763..c9a7561 100644 --- a/src/mdictionary/qml/ElementsListView.qml +++ b/src/mdictionary/qml/ElementsListView.qml @@ -1,6 +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 . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ +/*! + author: Marcin Kaźmierczak +*/ + import Qt 4.7 ListView { - property int selectedElement: -1 - + 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/WordListDelegate.qml b/src/mdictionary/qml/WordListDelegate.qml deleted file mode 100644 index 15b01c6..0000000 --- a/src/mdictionary/qml/WordListDelegate.qml +++ /dev/null @@ -1,6 +0,0 @@ -import Qt 4.7 - -Rectangle { - width: 100 - height: 62 -} diff --git a/src/mdictionary/qml/WordListWidget.qml b/src/mdictionary/qml/WordListWidget.qml new file mode 100644 index 0000000..15b01c6 --- /dev/null +++ b/src/mdictionary/qml/WordListWidget.qml @@ -0,0 +1,6 @@ +import Qt 4.7 + +Rectangle { + width: 100 + height: 62 +} -- 1.7.9.5