diff options
author | Stanislav Ionascu <stanislav.ionascu@nokia.com> | 2010-07-08 12:30:13 +0300 |
---|---|---|
committer | Sergiy Dubovik <sergiy.dubovik@nokia.com> | 2010-07-09 10:40:55 +0300 |
commit | c86e394e70f080d7acf74109d298b40171710edf (patch) | |
tree | f08835da1fba9dff96c780bb944a05a17815d521 /demos/widgetsgallery | |
parent | e94834623d716de07b303d952f36abfd5ebe32ea (diff) |
Changes: Added a more complex example of custom header usage for lists.
RevBy: Sergiy Dubovik
Details: The header is composed of 2 labels. On the left is the group name,
and on the right the row count of the group.
Diffstat (limited to 'demos/widgetsgallery')
-rw-r--r-- | demos/widgetsgallery/mlistpage.cpp | 36 | ||||
-rw-r--r-- | demos/widgetsgallery/phonebookcell.cpp | 10 | ||||
-rw-r--r-- | demos/widgetsgallery/phonebookheader.cpp | 87 | ||||
-rw-r--r-- | demos/widgetsgallery/phonebookheader.h | 51 | ||||
-rw-r--r-- | demos/widgetsgallery/widgetsgallery.pro | 2 |
5 files changed, 179 insertions, 7 deletions
diff --git a/demos/widgetsgallery/mlistpage.cpp b/demos/widgetsgallery/mlistpage.cpp index 12ddcda3..a578c2a2 100644 --- a/demos/widgetsgallery/mlistpage.cpp +++ b/demos/widgetsgallery/mlistpage.cpp @@ -45,6 +45,7 @@ #include <MWidgetAction> #include "phonebookcell.h" +#include "phonebookheader.h" #include <MListFilter> #include <MTextEdit> @@ -84,6 +85,22 @@ QString MListPage::timedemoTitle() return "List"; } +class MListAdvancedCustomHeaderCreator : public MAbstractCellCreator<PhoneBookHeader> +{ +public: + void updateCell(const QModelIndex &index, MWidget *cell) const { + PhoneBookHeader *header = qobject_cast<PhoneBookHeader*>(cell); + QString title = index.data(Qt::DisplayRole).toString(); + + header->setGroupTitle(title); + header->setGroupCount(index.model()->rowCount(index)); + } + + QSizeF cellSize() const { + return QSizeF(-1, 100); + } +}; + class MListCustomHeaderCreator : public MAbstractCellCreator<MButton> { public: @@ -327,6 +344,7 @@ void MListPage::createActions() QStringList amountOfItemsList; amountOfItemsList << "50 items" << "100 items" << "200 items" << "1000 items"; combo = createComboBoxAction("Items in model", amountOfItemsList); + combo->setCurrentIndex(3); // by default create 1000 items connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(changeAmountOfItemInList(int))); #endif //HAVE_N900 @@ -500,13 +518,19 @@ void MListPage::changeLiveFilteringMode(int index) void MListPage::changeGroupHeadersMode(int index) { - Q_ASSERT(index >=0 && index <= 1); - bool customHeaders = (index == 1); + Q_ASSERT(index >=0 && index <= 2); - if (customHeaders) + switch (index) { + case 1: list->setHeaderCreator(new MListCustomHeaderCreator); - else + break; + case 2: + list->setHeaderCreator(new MListAdvancedCustomHeaderCreator); + break; + default: list->setHeaderCreator(NULL); + break; + }; } void MListPage::itemClick(const QModelIndex &index) @@ -608,7 +632,7 @@ void MListPage::showAdvancedConfigurationDialog() landscapePolicy->addItem(combo); QStringList groupHeadersModes; - groupHeadersModes << "Default - Labels" << "Custom - Buttons"; + groupHeadersModes << "Default - Labels" << "Custom - Buttons" << "Advanced - Custom Widget"; combo = createComboBoxLabelButton("Group Headers", groupHeadersModes, panel); connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(changeGroupHeadersMode(int))); @@ -672,6 +696,8 @@ void MListPage::createContent() connect(list, SIGNAL(itemClicked(QModelIndex)), this, SLOT(itemClick(QModelIndex))); connect(list, SIGNAL(itemLongTapped(QModelIndex)), this, SLOT(itemLongTapped(QModelIndex))); + changeAmountOfItemInList(3); + retranslateUi(); } diff --git a/demos/widgetsgallery/phonebookcell.cpp b/demos/widgetsgallery/phonebookcell.cpp index 2b13e61b..83ecc343 100644 --- a/demos/widgetsgallery/phonebookcell.cpp +++ b/demos/widgetsgallery/phonebookcell.cpp @@ -41,6 +41,11 @@ PhoneBookCell::PhoneBookCell() PhoneBookCell::~PhoneBookCell() { + if (spinner) + delete spinner; + + if (icon) + delete icon; } MLayout *PhoneBookCell::createLayout() @@ -60,6 +65,7 @@ MLayout *PhoneBookCell::createLayout() else landscapePolicy->addItem(imageWidget(), 0, 0, 3, 1, Qt::AlignLeft | Qt::AlignVCenter); + landscapePolicy->addItem(landscapeTitleLabelWidget(), 0, 1, Qt::AlignLeft | Qt::AlignTop); landscapePolicy->addItem(subtitleLabelWidget(), 1, 1, Qt::AlignLeft | Qt::AlignBottom); landscapePolicy->addItem(new QGraphicsWidget(this), 2, 1); @@ -85,7 +91,7 @@ MProgressIndicator *PhoneBookCell::spinnerWidget() { if (!spinner) { // spinner - spinner = new MProgressIndicator(this, MProgressIndicator::spinnerType); + spinner = new MProgressIndicator(NULL, MProgressIndicator::spinnerType); spinner->setUnknownDuration(true); spinner->setObjectName("CommonMainIcon"); @@ -128,7 +134,7 @@ MImageWidget *PhoneBookCell::imageWidget() { if (!icon) { // icon - icon = new MImageWidget(this); + icon = new MImageWidget(); icon->setObjectName("CommonMainIcon"); icon->setVisible(false); } diff --git a/demos/widgetsgallery/phonebookheader.cpp b/demos/widgetsgallery/phonebookheader.cpp new file mode 100644 index 00000000..261c91f7 --- /dev/null +++ b/demos/widgetsgallery/phonebookheader.cpp @@ -0,0 +1,87 @@ +/*************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (directui@nokia.com) +** +** This file is part of libmeegotouch. +** +** If you have questions regarding the use of this file, please contact +** Nokia at directui@nokia.com. +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation +** and appearing in the file LICENSE.LGPL included in the packaging +** of this file. +** +****************************************************************************/ + +#include "phonebookheader.h" + +#include <MLabel> +#include <MLayout> +#include <MLinearLayoutPolicy> + +PhoneBookHeader::PhoneBookHeader(QGraphicsItem *parent) + : MStylableWidget(parent), + layout(NULL), + groupTitleLabel(NULL), + groupCountLabel(NULL) +{ +} + +void PhoneBookHeader::setGroupTitle(const QString &title) +{ + groupTitleLabelWidget()->setText(title); +} + +void PhoneBookHeader::setGroupCount(int count) +{ + groupCountLabelWidget()->setText(QString::number(count)); +} + +MLabel *PhoneBookHeader::groupTitleLabelWidget() +{ + if (!groupTitleLabel) { + groupTitleLabel = new MLabel(this); + groupTitleLabel->setAlignment(Qt::AlignLeft); + } + + return groupTitleLabel; +} + +MLabel *PhoneBookHeader::groupCountLabelWidget() +{ + if (!groupCountLabel) { + groupCountLabel = new MLabel(this); + groupCountLabel->setAlignment(Qt::AlignRight); + } + + return groupCountLabel; +} + +void PhoneBookHeader::resizeEvent(QGraphicsSceneResizeEvent *event) +{ + MWidgetController::resizeEvent(event); + + if (layout == NULL) + setLayout(createLayout()); +} + +MLayout *PhoneBookHeader::createLayout() +{ + if (layout) + delete layout; + + layout = new MLayout(this); + MLinearLayoutPolicy *policy = new MLinearLayoutPolicy(layout, Qt::Horizontal); + + policy->addItem(groupTitleLabelWidget()); + policy->addItem(new QGraphicsWidget(this)); + policy->addItem(groupCountLabelWidget()); + + layout->setPolicy(policy); + + return layout; +} diff --git a/demos/widgetsgallery/phonebookheader.h b/demos/widgetsgallery/phonebookheader.h new file mode 100644 index 00000000..72188920 --- /dev/null +++ b/demos/widgetsgallery/phonebookheader.h @@ -0,0 +1,51 @@ +/*************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (directui@nokia.com) +** +** This file is part of libmeegotouch. +** +** If you have questions regarding the use of this file, please contact +** Nokia at directui@nokia.com. +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation +** and appearing in the file LICENSE.LGPL included in the packaging +** of this file. +** +****************************************************************************/ + +#ifndef PHONEBOOKHEADER_H +#define PHONEBOOKHEADER_H + +#include <MStylableWidget> + +class MLabel; +class MLayout; + +class PhoneBookHeader : public MStylableWidget +{ + Q_OBJECT +public: + PhoneBookHeader(QGraphicsItem *parent=NULL); + + void setGroupTitle(const QString &title); + void setGroupCount(int count); + +protected: + MLabel *groupTitleLabelWidget(); + MLabel *groupCountLabelWidget(); + + void resizeEvent(QGraphicsSceneResizeEvent *event); + MLayout *createLayout(); + +private: + MLayout *layout; + + MLabel *groupTitleLabel; + MLabel *groupCountLabel; +}; + +#endif // PHONEBOOKHEADER_H diff --git a/demos/widgetsgallery/widgetsgallery.pro b/demos/widgetsgallery/widgetsgallery.pro index d8c5e2f4..8faf44b7 100644 --- a/demos/widgetsgallery/widgetsgallery.pro +++ b/demos/widgetsgallery/widgetsgallery.pro @@ -81,6 +81,7 @@ SOURCES += main.cpp \ phonebookcell.cpp \ bubblepage.cpp \ bubblelistmodel.cpp \ + phonebookheader.cpp \ HEADERS += templatepage.h \ mainpage.h \ @@ -126,6 +127,7 @@ HEADERS += templatepage.h \ phonebookcell.h \ bubblepage.h \ bubblelistmodel.h \ + phonebookheader.h \ # theme include(theme/theme.pri) |