diff options
author | Marcin Miklas <marcin.miklas@teleca.com> | 2010-04-02 15:40:44 +0200 |
---|---|---|
committer | Daniel d'Andrada <daniel.dandrada@nokia.com> | 2010-04-14 09:36:36 +0300 |
commit | 2672d9880a586abb2007faa3a0691375e06a9fc1 (patch) | |
tree | 1977c84a985874653bd8fe684e76abf580e40009 | |
parent | b31ba6ba7d2b875818a19ba95a82af54763f90f8 (diff) |
New: Progress bar added to MComboBox.
RevBy: Daniel d'Andrada
Details:
Now, for long taking selections, MComboBox can display progress indicator.
I've added ProgressIndicatorVisible property to MComboBox and helper functions:
showProgressIndicator, hideProgressIndicator
My changes also required to update MContentItem, so I moved
additionalItem to MContentItemModel class, and changed MContentItemView
to update layout when additionalItem property is changed.
WidgetsGallery comboboxpage updated to show new feature of MComboBox.
-rw-r--r-- | demos/widgetsgallery/comboboxpage.cpp | 20 | ||||
-rw-r--r-- | demos/widgetsgallery/comboboxpage.h | 1 | ||||
-rw-r--r-- | doc/src/news.dox | 2 | ||||
-rw-r--r-- | src/corelib/widgets/mcombobox.cpp | 10 | ||||
-rw-r--r-- | src/corelib/widgets/mcombobox.h | 29 | ||||
-rw-r--r-- | src/corelib/widgets/mcomboboxmodel.h | 7 | ||||
-rw-r--r-- | src/corelib/widgets/mcontentitem.cpp | 10 | ||||
-rw-r--r-- | src/corelib/widgets/mcontentitem_p.h | 1 | ||||
-rw-r--r-- | src/corelib/widgets/mcontentitemmodel.h | 7 | ||||
-rw-r--r-- | src/views/mcomboboxview.cpp | 34 | ||||
-rw-r--r-- | src/views/mcomboboxview_p.h | 2 | ||||
-rw-r--r-- | src/views/mcontentitemview.cpp | 52 | ||||
-rw-r--r-- | src/views/mcontentitemview_p.h | 1 | ||||
-rw-r--r-- | tests/ut_mcombobox/ut_mcombobox.cpp | 4 |
14 files changed, 143 insertions, 37 deletions
diff --git a/demos/widgetsgallery/comboboxpage.cpp b/demos/widgetsgallery/comboboxpage.cpp index 85a358d8..6aa0a935 100644 --- a/demos/widgetsgallery/comboboxpage.cpp +++ b/demos/widgetsgallery/comboboxpage.cpp @@ -30,6 +30,7 @@ #include <QStringListModel> #include <QSortFilterProxyModel> #include <QStringList> +#include <QTimer> ComboBoxPage::ComboBoxPage() : model1(0), @@ -78,8 +79,25 @@ void ComboBoxPage::createContent() comboBox2->setItemModel(proxyModel); + comboBox3 = new MComboBox; + comboBox3->setIconID("Icon-music"); + comboBox3->setTitle("Time-consuming setting"); + comboBox3->addItem("Setting 1"); + comboBox3->addItem("Setting 2"); + comboBox3->addItem("Setting 3"); + comboBox3->addItem("Setting 4"); + comboBox3->addItem("Setting 5"); + + QTimer* timer = new QTimer(this); + timer->setSingleShot(true); + timer->setInterval(3000); + QObject::connect(comboBox3, SIGNAL(currentIndexChanged(int)), comboBox3, SLOT(showProgressIndicator())); + QObject::connect(comboBox3, SIGNAL(currentIndexChanged(int)), timer, SLOT(start())); + QObject::connect(timer, SIGNAL(timeout()), comboBox3, SLOT(hideProgressIndicator())); + containerPolicy->addItem(comboBox1); containerPolicy->addItem(comboBox2); + containerPolicy->addItem(comboBox3); retranslateUi(); } @@ -94,6 +112,8 @@ void ComboBoxPage::retranslateUi() comboBox1->setTitle(qtTrId("xx_popup_generic_title")); //% "Sort - DescendingOrder" comboBox2->setTitle(qtTrId("xx_popup_sort_descending_order")); + //% "Time-consuming setting" + comboBox3->setTitle(qtTrId("xx_popup_time_consuming")); //% "The MComboBox widget is a combined button and popup list. " //% "It is very similar to QComboBox, but does not allow editing the text." diff --git a/demos/widgetsgallery/comboboxpage.h b/demos/widgetsgallery/comboboxpage.h index 55c5d50f..32bbf61a 100644 --- a/demos/widgetsgallery/comboboxpage.h +++ b/demos/widgetsgallery/comboboxpage.h @@ -46,6 +46,7 @@ protected: private: MComboBox *comboBox1; MComboBox *comboBox2; + MComboBox *comboBox3; QStringListModel *model1; QSortFilterProxyModel *proxyModel; diff --git a/doc/src/news.dox b/doc/src/news.dox index cd89b9a1..7f1607e1 100644 --- a/doc/src/news.dox +++ b/doc/src/news.dox @@ -56,6 +56,8 @@ - DuiPannableViewport now allows changing the position indicator to a custom made one. +- MComboBox now have the progress indicator that can be shown for long taking selections. + \subsection removed Removed or Renamed - DuiRmiClient and DuiRmiServer was removed. diff --git a/src/corelib/widgets/mcombobox.cpp b/src/corelib/widgets/mcombobox.cpp index 262c17dc..ce6bfb7e 100644 --- a/src/corelib/widgets/mcombobox.cpp +++ b/src/corelib/widgets/mcombobox.cpp @@ -183,6 +183,11 @@ QString MComboBox::title() const return model()->title(); } +bool MComboBox::isProgressIndicatorVisible() const +{ + return model()->progressIndicatorVisible(); +} + void MComboBox::addItem(const QString &text) { insertItem(count(), text); @@ -351,6 +356,11 @@ void MComboBox::setTitle(const QString &title) model()->setTitle(title); } +void MComboBox::setProgressIndicatorVisible(bool enable) +{ + model()->setProgressIndicatorVisible(enable); +} + void MComboBox::setCurrentIndex(int index) { if (index == currentIndex()) return; diff --git a/src/corelib/widgets/mcombobox.h b/src/corelib/widgets/mcombobox.h index 7d777603..d09c6e75 100644 --- a/src/corelib/widgets/mcombobox.h +++ b/src/corelib/widgets/mcombobox.h @@ -94,6 +94,12 @@ class M_EXPORT MComboBox : public MWidgetController Q_PROPERTY(QString title READ title WRITE setTitle) /*! + \property MComboBox::progressIndicatorVisible + \brief See MComboBoxModel::progressIndicatorVisible + */ + Q_PROPERTY(bool progressIndicatorVisible READ isProgressIndicatorVisible WRITE setProgressIndicatorVisible ) + + /*! \property MComboBox::itemModel QAbstractItemModel which used by MComboBox */ Q_PROPERTY(QAbstractItemModel *itemModel READ itemModel WRITE setItemModel) @@ -169,6 +175,11 @@ public: */ QString title() const; + /*! + \brief Returns true if progress indicator is visible + */ + bool isProgressIndicatorVisible() const; + /** \brief Adds an item to the combobox with the given \a text. The item is appended to the list of existing items. @@ -301,6 +312,24 @@ public Q_SLOTS: */ void setTitle(const QString &title); + /*! + \brief shows\hides progress indicator + */ + void setProgressIndicatorVisible(bool visible); + + /*! + \brief shows progress indicator + */ + inline void showProgressIndicator() { + setProgressIndicatorVisible(true); + } + /*! + \brief hides progress indicator + */ + inline void hideProgressIndicator() { + setProgressIndicatorVisible(false); + } + /** \brief Set current index */ diff --git a/src/corelib/widgets/mcomboboxmodel.h b/src/corelib/widgets/mcomboboxmodel.h index 5711b4a2..a057cda5 100644 --- a/src/corelib/widgets/mcomboboxmodel.h +++ b/src/corelib/widgets/mcomboboxmodel.h @@ -57,6 +57,13 @@ class M_EXPORT MComboBoxModel : public MWidgetModel M_MODEL_PROPERTY(QString, title, Title, true, QString()) /*! + \property MComboBoxModel::progressIndicatorVisible + \brief Boolean value that defines whether a progress indicator is visible or not. + If the progress indicator is visible, a subtitle is hidden. + */ + M_MODEL_PROPERTY(bool, progressIndicatorVisible, ProgressIndicatorVisible, true, false) + + /*! \property MComboBoxModel::itemModel \brief QAbstractItemModel which used by MComboBox */ diff --git a/src/corelib/widgets/mcontentitem.cpp b/src/corelib/widgets/mcontentitem.cpp index 211f33f8..10b64829 100644 --- a/src/corelib/widgets/mcontentitem.cpp +++ b/src/corelib/widgets/mcontentitem.cpp @@ -31,7 +31,6 @@ M_REGISTER_WIDGET(MContentItem) MContentItemPrivate::MContentItemPrivate(): MWidgetControllerPrivate(), - additionalItem(0), smallItem(0) { } @@ -159,23 +158,20 @@ QImage MContentItem::optionalImage() const void MContentItem::setAdditionalItem(MWidget* widget) { - Q_D(MContentItem); - d->additionalItem = widget; + model()->setAdditionalItem(widget); } MWidget* MContentItem::additionalItem() const { - Q_D(const MContentItem); - return d->additionalItem; + return model()->additionalItem(); } void MContentItem::enableProgressBar() { - Q_D(MContentItem); MProgressIndicator* progressIndicator = new MProgressIndicator; progressIndicator->setViewType(MProgressIndicator::barType); progressIndicator->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Expanding); - d->additionalItem = progressIndicator; + model()->setAdditionalItem(progressIndicator); } void MContentItem::setSmallItem(MWidget* widget) diff --git a/src/corelib/widgets/mcontentitem_p.h b/src/corelib/widgets/mcontentitem_p.h index 0af0d937..e5e6cfe3 100644 --- a/src/corelib/widgets/mcontentitem_p.h +++ b/src/corelib/widgets/mcontentitem_p.h @@ -34,7 +34,6 @@ public: QImage image; QPixmap optionalPixmap; QImage optionalImage; - MWidget* additionalItem; MWidget* smallItem; }; diff --git a/src/corelib/widgets/mcontentitemmodel.h b/src/corelib/widgets/mcontentitemmodel.h index 9ac49782..b65392d0 100644 --- a/src/corelib/widgets/mcontentitemmodel.h +++ b/src/corelib/widgets/mcontentitemmodel.h @@ -94,6 +94,13 @@ public: \brief Contains optional icon on the right-hand side */ M_MODEL_PROPERTY(QImage, optionalImage, OptionalImage, false, QImage()) + + /*! + \property MContentItemModel::additionalItem + \brief MWidget as e.g. progress bar, visible below the title. + In case there is already a subtitle it will be replaced. + */ + M_MODEL_PTR_PROPERTY(MWidget*, additionalItem, AdditionalItem, true, NULL) }; #endif diff --git a/src/views/mcomboboxview.cpp b/src/views/mcomboboxview.cpp index f5889982..eac30f5a 100644 --- a/src/views/mcomboboxview.cpp +++ b/src/views/mcomboboxview.cpp @@ -36,7 +36,7 @@ #include <QGraphicsSceneMouseEvent> MComboBoxViewPrivate::MComboBoxViewPrivate() - : q_ptr(0), controller(0), contentItem(0), popuplist(0), pixmap(0) + : q_ptr(0), controller(0), contentItem(0), popuplist(0), pixmap(0), progressIndicator(0) { } @@ -45,6 +45,7 @@ MComboBoxViewPrivate::~MComboBoxViewPrivate() delete contentItem; delete popuplist; delete pixmap; + delete progressIndicator; } void MComboBoxViewPrivate::init() @@ -56,7 +57,7 @@ void MComboBoxViewPrivate::init() layout->setSpacing(0); controller->setLayout(layout); - contentItem = new MContentItem(MContentItem::TwoTextLabels); + contentItem = new MContentItem(MContentItem::TwoIconsTwoWidgets); layout->addItem(contentItem); updateSubtitle(controller->currentIndex()); @@ -69,10 +70,12 @@ void MComboBoxViewPrivate::initLayout() { Q_Q(MComboBoxView); - MContentItem::ContentItemStyle newStyle;; + MContentItem::ContentItemStyle newStyle; if (controller->isIconVisible() && !controller->iconID().isEmpty()) - newStyle = MContentItem::IconAndTwoTextLabels; + newStyle = MContentItem::TwoIconsTwoWidgets; + else if (controller->isProgressIndicatorVisible()) + newStyle = MContentItem::TwoIconsTwoWidgets; else newStyle = MContentItem::TwoTextLabels; @@ -89,13 +92,30 @@ void MComboBoxViewPrivate::initLayout() QObject::connect(contentItem, SIGNAL(clicked()), controller, SLOT(click())); } - if (newStyle == MContentItem::IconAndTwoTextLabels) { + if (controller->isIconVisible() && !controller->iconID().isEmpty()) { // TODO: Use MTheme::pixmap() when MContentItem starts to support // pixmaps that are loaded asynchronously if (!pixmap) pixmap = MTheme::pixmapCopy(controller->iconID()); contentItem->setPixmap(*pixmap); } + + if (controller->isProgressIndicatorVisible()) { + if (!progressIndicator) { + progressIndicator = new MProgressIndicator; + progressIndicator->setViewType(MProgressIndicator::spinnerType); + progressIndicator->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Expanding); + progressIndicator->setUnknownDuration(true); + } + else { + progressIndicator->setVisible(true); + } + contentItem->setAdditionalItem(progressIndicator); + } else { + if (progressIndicator) + progressIndicator->setVisible(false); + contentItem->setAdditionalItem(NULL); + } } void MComboBoxViewPrivate::updateSubtitle(int currentIndex) { @@ -177,7 +197,9 @@ void MComboBoxView::updateData(const QList<const char *>& modifications) delete d->pixmap; d->pixmap = NULL; d->initLayout(); - } else if (member == MComboBoxModel::IconVisible) { + } else if (member == MComboBoxModel::IconVisible || + member == MComboBoxModel::ProgressIndicatorVisible) + { d->initLayout(); } else if (member == MComboBoxModel::Title) { d->contentItem->setTitle(model()->title()); diff --git a/src/views/mcomboboxview_p.h b/src/views/mcomboboxview_p.h index 7ef9a56e..36a10ed9 100644 --- a/src/views/mcomboboxview_p.h +++ b/src/views/mcomboboxview_p.h @@ -24,6 +24,7 @@ class QGraphicsLinearLayout; class MComboBox; class MContentItem; class MPopupList; +class MProgressIndicator; class MComboBoxViewPrivate { @@ -48,6 +49,7 @@ public: MContentItem *contentItem; MPopupList *popuplist; QPixmap *pixmap; + MProgressIndicator *progressIndicator; }; #endif diff --git a/src/views/mcontentitemview.cpp b/src/views/mcontentitemview.cpp index e2ce5ab6..15682fe3 100644 --- a/src/views/mcontentitemview.cpp +++ b/src/views/mcontentitemview.cpp @@ -16,7 +16,6 @@ ** of this file. ** ****************************************************************************/ - #include <MScalableImage> #include <MImageWidget> #include <MLabel> @@ -217,36 +216,42 @@ void MContentItemViewPrivate::initLayout(MContentItem::ContentItemStyle style) break; case MContentItem::TwoIconsTwoWidgets: + initTwoIconsTwoWidgetsLayout(); + break; + }; +} - layout->addItem( image(), 0,0, 2,1, Qt::AlignCenter ); - image()->setVisible(true); - image()->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); +void MContentItemViewPrivate::initTwoIconsTwoWidgetsLayout() +{ + layout->addItem( image(), 0,0, 2,1, Qt::AlignCenter ); + image()->setVisible(true); + image()->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); - layout->addItem( title(), 0,1, Qt::AlignLeft ); + layout->addItem( title(), 0,1, Qt::AlignLeft ); - // first free widget or subtitle - int columnSpan = 1; - if( !controller->smallItem() ) - columnSpan = 2; - if( controller->additionalItem() ) { - layout->addItem( controller->additionalItem(), 1,1, 1,columnSpan, Qt::AlignLeft ); - subtitle()->setVisible( false ); - } else - layout->addItem( subtitle(), 1,1, 1,columnSpan, Qt::AlignLeft ); + // first free widget or subtitle + int columnSpan = 1; + if( !controller->smallItem() ) + columnSpan = 2; - layout->addItem( optionalImage(), 0,2, Qt::AlignRight ); - optionalImage()->setVisible(true); + if( controller->additionalItem() ) { + layout->addItem( controller->additionalItem(), 1,1, 1,columnSpan, Qt::AlignLeft ); + subtitle()->setVisible(false); + } else { + layout->addItem( subtitle(), 1,1, 1,columnSpan, Qt::AlignLeft ); + subtitle()->setVisible(true); + } - if( controller->smallItem() ) - layout->addItem( controller->smallItem(), 1,2, Qt::AlignRight ); + layout->addItem( optionalImage(), 0,2, Qt::AlignRight ); + optionalImage()->setVisible(true); - break; - }; + if( controller->smallItem() ) + layout->addItem( controller->smallItem(), 1,2, Qt::AlignRight ); } void MContentItemViewPrivate::clearLayout() { - for (int i = 0; i < layout->count(); i++) + for (int i = layout->count(); i>0; i--) layout->removeAt(0); } @@ -346,6 +351,11 @@ void MContentItemView::updateData(const QList<const char *> &modifications) d->setOptionalImage(model()->optionalImage()); } else if(member == MContentItemModel::ItemImage) { d->setImage(model()->itemImage()); + } else if(member == MContentItemModel::AdditionalItem) { + if (d->configuredStyle == MContentItem::TwoIconsTwoWidgets) { + d->clearLayout(); + d->initTwoIconsTwoWidgetsLayout(); + } } } } diff --git a/src/views/mcontentitemview_p.h b/src/views/mcontentitemview_p.h index 19aaca9e..28de1481 100644 --- a/src/views/mcontentitemview_p.h +++ b/src/views/mcontentitemview_p.h @@ -52,6 +52,7 @@ public: void initLayout(MContentItem::ContentItemStyle style); void clearLayout(); + void initTwoIconsTwoWidgetsLayout(); void applyStyle(); diff --git a/tests/ut_mcombobox/ut_mcombobox.cpp b/tests/ut_mcombobox/ut_mcombobox.cpp index 13cc3ffd..8ac7284f 100644 --- a/tests/ut_mcombobox/ut_mcombobox.cpp +++ b/tests/ut_mcombobox/ut_mcombobox.cpp @@ -210,7 +210,7 @@ void Ut_MComboBox::testIconVisibility() m_combobox->setIconID("Icon-music"); view->updateData(QList<const char *>() << MComboBoxModel::IconID); - QCOMPARE(viewPrivate->contentItem->itemStyle(), MContentItem::IconAndTwoTextLabels); + QCOMPARE(viewPrivate->contentItem->itemStyle(), MContentItem::TwoIconsTwoWidgets); QVERIFY(!viewPrivate->contentItem->pixmap().isNull()); m_combobox->setIconVisible(false); @@ -221,7 +221,7 @@ void Ut_MComboBox::testIconVisibility() m_combobox->setIconVisible(true); view->updateData(QList<const char *>() << MComboBoxModel::IconVisible); - QCOMPARE(viewPrivate->contentItem->itemStyle(), MContentItem::IconAndTwoTextLabels); + QCOMPARE(viewPrivate->contentItem->itemStyle(), MContentItem::TwoIconsTwoWidgets); QVERIFY(!viewPrivate->contentItem->pixmap().isNull()); } |