aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcin Miklas <marcin.miklas@teleca.com>2010-04-02 15:40:44 +0200
committerDaniel d'Andrada <daniel.dandrada@nokia.com>2010-04-14 09:36:36 +0300
commit2672d9880a586abb2007faa3a0691375e06a9fc1 (patch)
tree1977c84a985874653bd8fe684e76abf580e40009 /src
parentb31ba6ba7d2b875818a19ba95a82af54763f90f8 (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.
Diffstat (limited to 'src')
-rw-r--r--src/corelib/widgets/mcombobox.cpp10
-rw-r--r--src/corelib/widgets/mcombobox.h29
-rw-r--r--src/corelib/widgets/mcomboboxmodel.h7
-rw-r--r--src/corelib/widgets/mcontentitem.cpp10
-rw-r--r--src/corelib/widgets/mcontentitem_p.h1
-rw-r--r--src/corelib/widgets/mcontentitemmodel.h7
-rw-r--r--src/views/mcomboboxview.cpp34
-rw-r--r--src/views/mcomboboxview_p.h2
-rw-r--r--src/views/mcontentitemview.cpp52
-rw-r--r--src/views/mcontentitemview_p.h1
10 files changed, 118 insertions, 35 deletions
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();