aboutsummaryrefslogtreecommitdiff
path: root/demos/widgetsgallery/maincategorypage.cpp
diff options
context:
space:
mode:
authorStanislav Ionascu <stanislav.ionascu@nokia.com>2010-05-12 11:14:11 +0300
committerTomas Junnonen <tomas.junnonen@nokia.com>2010-05-28 10:58:49 +0300
commitdaa31018b605208e3c45b02224e014d0e4b3294c (patch)
tree1ceda6322d9a6658dd9926596d18a9a02014c9bc /demos/widgetsgallery/maincategorypage.cpp
parent6d59f110c9a0873100e69434462e708157a45330 (diff)
Changes: Improvements to widgets gallery menu system and page layout.
RevBy: Michal Guminiak, Tomas Junnonen Details: 1) Implementation of the drill-down menu in widgets gallery. 2) New category page for selection of gallery page by category. 3) Added the language settings page to application menu. 4) Some code clean up, and added the language settins page to the application view. 5) Added a content items demonstrantion page. 6) Added separate pages for dialogs and notifications. 7) Includes improved patch from merge request #456 (commits by csklu). 8) Removed dialogs and notifications page due to not being used anymore. 9) Removed image rating possibility from widgets gallery grid page. 10) Implemented pinching zoom of images in widgetsgallery grid page.
Diffstat (limited to 'demos/widgetsgallery/maincategorypage.cpp')
-rw-r--r--demos/widgetsgallery/maincategorypage.cpp107
1 files changed, 107 insertions, 0 deletions
diff --git a/demos/widgetsgallery/maincategorypage.cpp b/demos/widgetsgallery/maincategorypage.cpp
new file mode 100644
index 00000000..95b36179
--- /dev/null
+++ b/demos/widgetsgallery/maincategorypage.cpp
@@ -0,0 +1,107 @@
+#include "maincategorypage.h"
+#include "mainpage.h"
+
+#include <MAbstractCellCreator>
+#include <MContentItem>
+#include <MLayout>
+#include <MLinearLayoutPolicy>
+#include <MList>
+
+class WidgetsGalleryCategoryDataModel : public QAbstractListModel {
+public:
+ WidgetsGalleryCategoryDataModel(QAbstractItemModel *parentModel, const QModelIndex &parentIndex)
+ : QAbstractListModel(), widgetsGalleryModel(parentModel), categoryIndex(parentIndex) {
+
+ }
+
+ QModelIndex parent(const QModelIndex &child) const {
+ Q_UNUSED(child);
+
+ return categoryIndex;
+ }
+
+ int rowCount(const QModelIndex &index) const {
+ Q_UNUSED(index);
+
+ return widgetsGalleryModel->rowCount(categoryIndex);
+ }
+
+ QVariant data(const QModelIndex &index, int role) const {
+ return widgetsGalleryModel->data(index, role);
+ }
+private:
+ QAbstractItemModel *widgetsGalleryModel;
+ QModelIndex categoryIndex;
+};
+
+class WidgetGalleryCellCreator : public MAbstractCellCreator<MContentItem>
+{
+public:
+ WidgetGalleryCellCreator() : MAbstractCellCreator<MContentItem>() {
+ }
+
+ MWidget *createCell(const QModelIndex &index, MWidgetRecycler &recycler) const {
+ Q_UNUSED(index);
+
+ MContentItem *cell = dynamic_cast<MContentItem *>(recycler.take(MContentItem::staticMetaObject.className()));
+ if (cell == NULL) {
+ cell = new MContentItem(MContentItem::SingleTextLabel);
+ cell->setObjectName("wgMainCategoryPageGalleryItem");
+ }
+ updateCell(index, cell);
+
+ return cell;
+ }
+
+ void updateCell(const QModelIndex &index, MWidget *cell) const {
+ MContentItem *item = qobject_cast<MContentItem*>(cell);
+ if(!item)
+ return;
+
+ item->setTitle(index.data().toString());
+ }
+};
+
+MainCategoryPage::MainCategoryPage(QAbstractItemModel *demosDataModel, const QModelIndex &parentIndex) :
+ dataModel(new WidgetsGalleryCategoryDataModel(demosDataModel, parentIndex))
+{
+}
+
+QString MainCategoryPage::timedemoTitle()
+{
+ return "MainCategoryPage";
+}
+
+void MainCategoryPage::createContent()
+{
+ TimedemoPage::createContent();
+
+ QGraphicsWidget *panel = centralWidget();
+
+ MLayout *layout = new MLayout(panel);
+ layout->setContentsMargins(0, 0, 0, 0);
+ panel->setLayout(layout);
+ policy = new MLinearLayoutPolicy(layout, Qt::Vertical);
+ policy->setSpacing(0);
+
+ populateLayout();
+}
+
+void MainCategoryPage::populateLayout()
+{
+ list = new MList(centralWidget());
+ list->setObjectName("wgList");
+ list->setCellCreator(new WidgetGalleryCellCreator());
+ list->setItemModel(dataModel);
+
+ policy->addItem(list, Qt::AlignCenter);
+
+ connect(list, SIGNAL(itemClicked(QModelIndex)), this, SLOT(galleryPageItemClicked(QModelIndex)));
+}
+
+void MainCategoryPage::galleryPageItemClicked(const QModelIndex &index)
+{
+ TemplatePage *page = static_cast<TemplatePage *>(index.data(MainPage::Page).value<void *>());
+ page->setParent(this);
+ page->appear();
+}