src/hbplugins/devicedialogs/indicatormenuplugin/hbindicatormenucontent.cpp
changeset 2 06ff229162e9
parent 0 16d8024aca5e
child 5 627c4a0fd0e7
--- a/src/hbplugins/devicedialogs/indicatormenuplugin/hbindicatormenucontent.cpp	Mon May 03 12:48:33 2010 +0300
+++ b/src/hbplugins/devicedialogs/indicatormenuplugin/hbindicatormenucontent.cpp	Fri May 14 16:09:54 2010 +0300
@@ -23,11 +23,8 @@
 **
 ****************************************************************************/
 
-#include <hbstyleoptionindicatormenu.h>
 #include <hbindicatorinterface.h>
 #include "hbindicatormenucontent_p.h"
-#include "hbindicatormenuclock_p.h"
-#include "hbindicatormenudate_p.h"
 
 static const int ListWidgetItemIndicatorTypeRole = Hb::UserRole;
 static const int DefaultItemsVisible = 6;
@@ -46,22 +43,8 @@
     return item;
 }
 
-void HbIndicatorListItem::updateChildItems()
-{
-    QModelIndex index(modelIndex());
-    bool itemContainsLink = false;
-    HbIndicatorInterface *indicator =
-            HbIndicatorMenuContent::indicatorFromIndex(index);
-    if (indicator && indicator->interactionTypes().testFlag(
-            HbIndicatorInterface::InteractionActivated)){
-        itemContainsLink = true;
-    }
-    setProperty("link", itemContainsLink);
-    HbListViewItem::updateChildItems();
-}
-
 IndicatorList::IndicatorList(HbIndicatorMenuContent *content) :
-        HbListView(content), mContent(content), mUpdateListSize(false)
+        HbListView(content), mUpdateListSize(false)
 {
     setItemRecycling(true);
     setUniformItemSizes(true);
@@ -71,9 +54,9 @@
         const QModelIndex &parent, int start, int end)
 {
     HbListView::rowsInserted(parent, start, end);
-    if (static_cast<QGraphicsItem*>(this)->isVisible()) {
+    if (mUpdateListSize == false) {
+        mUpdateListSize = true;
         updateGeometry();
-        mUpdateListSize = true;
     }
 }
 
@@ -81,9 +64,9 @@
         const QModelIndex &parent,int start,int end)
 {
     HbListView::rowsRemoved(parent, start, end);
-    if (static_cast<QGraphicsItem*>(this)->isVisible()) {
+    if (mUpdateListSize == false) {
+        mUpdateListSize = true;
         updateGeometry();
-        mUpdateListSize = true;
     }
 }
 
@@ -91,9 +74,9 @@
                                 const QModelIndex &bottomRight)
 {
     HbListView::dataChanged(topLeft, bottomRight);
-    if (static_cast<QGraphicsItem*>(this)->isVisible()) {
+    if (mUpdateListSize == false) {
+        mUpdateListSize = true;
         updateGeometry();
-        mUpdateListSize = true;
     }
 }
 
@@ -131,8 +114,10 @@
 void IndicatorList::showEvent(QShowEvent *event)
 {
     Q_UNUSED(event)
-    updateGeometry();
-    mUpdateListSize = true;
+    if (mUpdateListSize == false) {
+        mUpdateListSize = true;
+        updateGeometry();
+    }
 }
 
 /*!
@@ -145,12 +130,6 @@
         mGroupTypeIndeces[i] = 0;
     }
 
-    mHeaderBackground = style()->createPrimitive(HbStyle::P_Popup_heading_frame, this);
-
-    mClock = new HbIndicatorMenuClock(this);
-    mDate = new HbIndicatorMenuDate(this);
-    connect(mClock, SIGNAL(dateChanged()), mDate, SLOT(updateDate()));
-
     mIndicatorList = new IndicatorList(this);
     mIndicatorList->setItemPrototype(new HbIndicatorListItem(this));
     mIndicatorList->setModel(&indicatorModel);
@@ -161,19 +140,13 @@
     connect(mIndicatorList, SIGNAL(scrollingEnded()),
             this, SLOT(indicatorlist_scrollingEnded()));
 
-    HbStyle::setItemName(mHeaderBackground, "background");
-    HbStyle::setItemName(mClock, "clock");
-    HbStyle::setItemName(mDate, "date");
     HbStyle::setItemName(mIndicatorList, "list");
-
-    updatePrimitives();
 }
 
 HbIndicatorMenuContent::~HbIndicatorMenuContent()
 {
 }
 
-
 int HbIndicatorMenuContent::indicatorCount() const
 {
      return indicatorModel.rowCount();
@@ -181,15 +154,7 @@
 
 void HbIndicatorMenuContent::updatePrimitives()
 {
-    HbStyleOptionPopup option;
-    if (mHeaderBackground->hasFocus()) {
-        option.headingMode = QIcon::Selected;
-    } else if (mHeaderBackground->isSelected()) {
-        option.headingMode = QIcon::Active;
-    } else {
-        option.headingMode = QIcon::Normal;
-    }
-    style()->updatePrimitive(mHeaderBackground, HbStyle::P_Popup_heading_frame, &option);
+    repolish();
 }
 
 void HbIndicatorMenuContent::itemActivated(const QModelIndex &modelIndex)
@@ -203,16 +168,19 @@
 }
 
 void HbIndicatorMenuContent::indicatorsActivated(
-        QList<HbIndicatorInterface*> activatedIndicators)
+    QList<HbIndicatorInterface*> activatedIndicators)
 {
     foreach(HbIndicatorInterface *indicator, activatedIndicators) {
         indicatorActivated(indicator);
     }
 }
 
-void HbIndicatorMenuContent::indicatorActivated(
-        HbIndicatorInterface *activatedIndicator)
+void HbIndicatorMenuContent::indicatorActivated(HbIndicatorInterface *activatedIndicator)
 {
+    if (!hasMenuData(*activatedIndicator)) {
+        return;
+    }
+
     QStandardItem *item = new QStandardItem();
     HbIndicatorInterface::Category category = activatedIndicator->category();
 
@@ -238,9 +206,7 @@
     repolish();
 }
 
-void HbIndicatorMenuContent::setData(
-        HbIndicatorInterface *source,
-        const QModelIndex &modelIndex)
+void HbIndicatorMenuContent::setData(HbIndicatorInterface *source, const QModelIndex &modelIndex)
 {
     QString primaryText = source->indicatorData(
         HbIndicatorInterface::PrimaryTextRole).toString();
@@ -262,8 +228,7 @@
     }
 }
 
-void HbIndicatorMenuContent::indicatorRemoved(
-        HbIndicatorInterface *indicatorRemoved)
+void HbIndicatorMenuContent::indicatorRemoved(HbIndicatorInterface *indicatorRemoved)
 {
     int index = listIndexFromIndicator(indicatorRemoved);
     if (index >= 0) {
@@ -276,12 +241,6 @@
     repolish();
 }
 
-void HbIndicatorMenuContent::initStyleOption(
-        HbStyleOptionIndicatorMenu *option) const
-{
-    HbWidget::initStyleOption(option);
-}
-
 //data changed inside indicator.
 void HbIndicatorMenuContent::indicatorUpdated()
 {
@@ -293,6 +252,7 @@
             setData(senderIndicator, indicatorModel.item(index)->index());
         }
     }
+    repolish();
 }
 
 void HbIndicatorMenuContent::indicatorlist_scrollingStarted()
@@ -305,17 +265,15 @@
     emit userActivityEnded();
 }
 
-HbIndicatorInterface *HbIndicatorMenuContent::indicatorFromIndex(
-        const QModelIndex &modelIndex)
+HbIndicatorInterface *HbIndicatorMenuContent::indicatorFromIndex(const QModelIndex &modelIndex)
 {
     QObject *ind_ptr =
         modelIndex.data(ListWidgetItemIndicatorTypeRole).value<QObject*>();
     return qobject_cast<HbIndicatorInterface*>(ind_ptr);
 }
 
-int HbIndicatorMenuContent::listIndexFromIndicator(
-        HbIndicatorInterface *indicator) {
-
+int HbIndicatorMenuContent::listIndexFromIndicator(HbIndicatorInterface *indicator) 
+{
     int index = -1;
     int rowCount = mIndicatorList->model()->rowCount();
     for(int i = 0; i < rowCount; ++i) {
@@ -330,3 +288,14 @@
     return index;
 }
 
+bool HbIndicatorMenuContent::hasMenuData(const HbIndicatorInterface &indicator) const
+{
+    if (!indicator.indicatorData(HbIndicatorInterface::PrimaryTextRole).toString().isEmpty() 
+        || !indicator.indicatorData(HbIndicatorInterface::SecondaryTextRole).toString().isEmpty() 
+        || !indicator.indicatorData(HbIndicatorInterface::DecorationNameRole).toString().isEmpty()) {
+        return true;
+    }
+
+    return false;
+}
+