src/hbcore/gui/hbwidget.cpp
changeset 21 4633027730f5
parent 7 923ff622b8b9
child 23 e6ad4ef83b23
--- a/src/hbcore/gui/hbwidget.cpp	Tue Jul 06 14:36:53 2010 +0300
+++ b/src/hbcore/gui/hbwidget.cpp	Wed Aug 18 10:05:37 2010 +0300
@@ -35,6 +35,7 @@
 #include "hbdeviceprofile.h"
 #include "hbtapgesture.h"
 #include "hbnamespace_p.h"
+#include "hbstyle_p.h"
 #include <QCoreApplication>
 #include <QMetaType>
 #include <QAction>
@@ -43,7 +44,6 @@
 #include <QGraphicsLayout>
 #include <QInputContext>
 
-#ifdef HB_TESTABILITY
 /*!
     \internal
  */
@@ -58,30 +58,37 @@
         widget->setFlag(QGraphicsItem::ItemSendsGeometryChanges, enabled);
     }
 }
-#endif //HB_TESTABILITY
 
 HbWidgetPrivate::HbWidgetPrivate()
   : HbWidgetBasePrivate(),
     style(0),
-    backgroundPrimitiveType(HbStyle::P_None),
-    polished(false),
+    backgroundPrimitiveType(HbStylePrivate::P_None),
     polishPending(false),
     themingPending(true),
     repolishOutstanding(false),
     mHandlingRepolishSynchronously(false),
     notifyScene(false),
     focusGroup(0),
-    focusActiveType(HbStyle::P_None),
-    focusResidualType(HbStyle::P_None),
+    focusActiveType(HbStylePrivate::P_None),
+    focusResidualType(HbStylePrivate::P_None),
     highlightExpired(false),
     backgroundItem(0),
     focusActiveItem(0),
     focusResidualItem(0)
 {
     q_ptr = 0;
-#ifdef HB_TESTABILITY 
 	testabilitySignal = new HbTestabilitySignal_p();
-#endif //HB_TESTABILITY 
+}
+
+void HbWidgetPrivate::init()
+{
+    Q_Q(HbWidget);
+    q->setAttribute(Hb::Widget, true);
+
+    if (testabilitySignal) {
+        testabilitySignal->setParent(q);
+        testabilitySignal->notifySignalEnabled(testabilitySignalEnabledChange, q);
+    }
 }
 
 HbWidgetPrivate::~HbWidgetPrivate()
@@ -92,16 +99,16 @@
     }
 }
 
-void HbWidgetPrivate::setBackgroundItem(HbStyle::Primitive type, int zValue)
+void HbWidgetPrivate::setBackgroundItem(HbStylePrivate::Primitive type, int zValue)
 {
     Q_Q(HbWidget);
-    if(type!=backgroundPrimitiveType || type == HbStyle::P_None) {
+    if(type!=backgroundPrimitiveType || type == HbStylePrivate::P_None) {
         if (backgroundItem) {
             delete backgroundItem;
             backgroundItem = 0;
         }
         backgroundPrimitiveType = type;
-        backgroundItem = q->style()->createPrimitive(backgroundPrimitiveType, const_cast<HbWidget*>(q));
+        backgroundItem = HbStylePrivate::createPrimitive(backgroundPrimitiveType, const_cast<HbWidget*>(q));
         if(backgroundItem) {
             backgroundItem->setParentItem(q);
         }
@@ -136,7 +143,7 @@
         delete d->backgroundItem;
         d->backgroundItem = 0;
     }
-    d->backgroundPrimitiveType = HbStyle::P_None;
+    d->backgroundPrimitiveType = HbStylePrivate::P_None;
     d->backgroundItem = item;
     if(d->backgroundItem) {
         d->backgroundItem->setParentItem(this);
@@ -165,15 +172,15 @@
     Q_Q(const HbWidget);
 
     if (highlightType == HbWidget::FocusHighlightActive) {
-        if (!focusActiveItem && focusActiveType != HbStyle::P_None) {
-            focusActiveItem = q->style()->createPrimitive(
+        if (!focusActiveItem && focusActiveType != HbStylePrivate::P_None) {
+            focusActiveItem = HbStylePrivate::createPrimitive(
                                 focusActiveType, const_cast<HbWidget*>(q));
             focusActiveItem->hide();
         }
         return focusActiveItem;
     } else if (highlightType == HbWidget::FocusHighlightResidual) {
-        if (!focusResidualItem && focusResidualType != HbStyle::P_None) {
-            focusResidualItem = q->style()->createPrimitive(
+        if (!focusResidualItem && focusResidualType != HbStylePrivate::P_None) {
+            focusResidualItem = HbStylePrivate::createPrimitive(
                                 focusResidualType, const_cast<HbWidget*>(q));
             focusResidualItem->hide();
         }
@@ -402,14 +409,7 @@
 {
     Q_D( HbWidget );
     d->q_ptr = this;
-    setAttribute(Hb::Widget, true);
-
-#ifdef HB_TESTABILITY 
-	if(d->testabilitySignal) {
-		d->testabilitySignal->setParent(this);
-		d->testabilitySignal->notifySignalEnabled(testabilitySignalEnabledChange, this);
-	}
-#endif //HB_TESTABILITY
+    d->init();
 }
 
 /*!
@@ -421,14 +421,7 @@
 {
     Q_D( HbWidget );
     d->q_ptr = this;
-    setAttribute(Hb::Widget, true);
-
-#ifdef HB_TESTABILITY 
-	if (d->testabilitySignal) {
-		d->testabilitySignal->setParent(this);
-		d->testabilitySignal->notifySignalEnabled(testabilitySignalEnabledChange, this);
-	}
-#endif //HB_TESTABILITY
+    d->init();
 }
 
 /*!
@@ -594,12 +587,12 @@
 void HbWidget::recreatePrimitives()
 {
     Q_D(HbWidget);
-    if(d->backgroundPrimitiveType != HbStyle::P_None) {
+    if(d->backgroundPrimitiveType != HbStylePrivate::P_None) {
         if(d->backgroundItem) {
             delete d->backgroundItem;
             d->backgroundItem = 0;
         }
-        d->backgroundItem = style()->createPrimitive(d->backgroundPrimitiveType, const_cast<HbWidget*>(this));
+        d->backgroundItem = HbStylePrivate::createPrimitive(d->backgroundPrimitiveType, const_cast<HbWidget*>(this));
     }
 }
 
@@ -616,18 +609,18 @@
     initStyleOption(&option);
 
     if (backgroundItem()) {
-        if(d->backgroundPrimitiveType != HbStyle::P_None) {
-            style()->updatePrimitive(backgroundItem(), d->backgroundPrimitiveType, &option);
+        if(d->backgroundPrimitiveType != HbStylePrivate::P_None) {
+            HbStylePrivate::updatePrimitive(backgroundItem(), d->backgroundPrimitiveType, &option);
         }
         d->updateBackgroundItemSize();
     }
     if (d->focusPrimitive(HbWidget::FocusHighlightResidual)) {
-        style()->updatePrimitive(d->focusPrimitive(HbWidget::FocusHighlightResidual),
+        HbStylePrivate::updatePrimitive(d->focusPrimitive(HbWidget::FocusHighlightResidual),
             d->focusResidualType, &option);        
     }
 
     if (d->focusPrimitive(HbWidget::FocusHighlightActive)) {
-        style()->updatePrimitive(d->focusPrimitive(HbWidget::FocusHighlightActive),
+        HbStylePrivate::updatePrimitive(d->focusPrimitive(HbWidget::FocusHighlightActive),
             d->focusActiveType, &option);
     }
    
@@ -754,11 +747,9 @@
 {
     Q_D(HbWidget);
 
-#ifdef HB_TESTABILITY
     if (d->testabilitySignal && d->testabilitySignal->signalEnabled()) {
     	emit d->testabilitySignal->propertyChanges(change, value);
     }
-#endif //HB_TESTABILITY
 
 	if (change == QGraphicsItem::ItemVisibleHasChanged) {
         if (!d->polished && !value.toBool()) {
@@ -779,17 +770,27 @@
             // to be sent when the widget is not polished yet.
             return value;
         }
-        if (d->polishPending && value.toBool()) {
-            d->polishPending = false;
-            HbStyleParameters params;
-            polish( params );
-            if (scene()) {
-             // The widget is polished again or is beign polished now. As we set layout to widget in polishEvent,
-             // inform scene to polish any new child items and handle any resulting layoutrequest
-             // events before drawing.
+        if (value.toBool()) {
+            bool notifyGraphicsScene = d->polishPending;
+            if(d->polishPending) {
+                d->polishPending = false;
+                HbStyleParameters params;
+                polish( params );
+            }
+            //There could be situations where widget is becoming visible and has
+            //polish request pending in event queue.This make's sure we
+            //handle any pending repolish requests of widget before its drawn.
+            if ((notifyGraphicsScene || (d->repolishOutstanding && !d->mHandlingRepolishSynchronously))
+                 &&  scene()) {
+                //Widget is polished again or is being polished now.
+                //As we set layout to widget in polishEvent,inform scene to polish any new
+                //child items and handle any resulting layoutrequest events before drawing.
                 HbGraphicsScene *hbscene = qobject_cast<HbGraphicsScene*>(scene());
                 if (hbscene) {
-                    HbGraphicsScenePrivate::d_ptr(hbscene)->mPolishWidgets = true;
+                    if (d->repolishOutstanding)
+                        HbGraphicsScenePrivate::d_ptr(hbscene)->mRepolishWidgets = true;
+                    else
+                        HbGraphicsScenePrivate::d_ptr(hbscene)->mPolishWidgets = true;
                 }
             }
         }
@@ -817,15 +818,17 @@
         if (d->focusGroup) {
             d->focusGroup->registerChildren(this);
         }
-        if (d->notifyScene && scene()) {
+        if (d->notifyScene) {
             // The widget has been added to a new scene and this would result in
             // polishing widget. As we set layout to widget in polishEvent,
             // inform scene to handle polish and any resulting layoutrequest
             // events before drawing.
             d->notifyScene = false;
-            HbGraphicsScene *hbscene = qobject_cast<HbGraphicsScene*>(scene());
-            if (hbscene) {
-                HbGraphicsScenePrivate::d_ptr(hbscene)->mPolishWidgets = true;
+            if (scene() && isVisible()) {
+                HbGraphicsScene *hbscene = qobject_cast<HbGraphicsScene*>(scene());
+                if (hbscene) {
+                    HbGraphicsScenePrivate::d_ptr(hbscene)->mPolishWidgets = true;
+                }
             }
         }
     }
@@ -873,7 +876,7 @@
     Q_D(HbWidget);
     if (isVisible()) {
         style()->polish(this, params);
-        d->polished = true;
+        d->polished = 1;
         d->repolishOutstanding = false;
         if (d->themingPending) {
             style()->updateThemedParams(this);
@@ -906,7 +909,7 @@
         QCoreApplication::postEvent(this, polishEvent);
         // If no one is handling repolish synchronously, lets make sure they are handled
         // before painting. For example view items handle them synchronously.
-        if (scene() && !d->mHandlingRepolishSynchronously) {
+        if (scene() && isVisible() && !d->mHandlingRepolishSynchronously) {
             // The widget needs to be polished again. As we set layout to widget in polishEvent,
             // inform scene to handle polish and any resulting layoutrequest
             // events before drawing.
@@ -926,13 +929,14 @@
 QGraphicsItem *HbWidget::primitive(HbStyle::Primitive primitive) const
 {
     Q_D(const HbWidget);
-    if (primitive == d->backgroundPrimitiveType) {
+    const HbStylePrivate::Primitive p = (HbStylePrivate::Primitive)primitive;
+    if (p == d->backgroundPrimitiveType) {
         return backgroundItem();
     }
-    if (primitive == d->focusActiveType) {
+    if (p == d->focusActiveType) {
         return d->focusPrimitive(HbWidget::FocusHighlightActive);
     }
-    if (primitive == d->focusResidualType) {
+    if (p == d->focusResidualType) {
         return d->focusPrimitive(HbWidget::FocusHighlightResidual);
     }
 
@@ -1266,17 +1270,17 @@
 {
     Q_D(HbWidget);
     if (focusHighlight == HbWidget::FocusHighlightNone) {
-        d->focusActiveType = HbStyle::P_None;
-        d->focusResidualType = HbStyle::P_None;
+        d->focusActiveType = HbStylePrivate::P_None;
+        d->focusResidualType = HbStylePrivate::P_None;
 
         delete d->focusActiveItem;
         d->focusActiveItem = 0;
         delete d->focusResidualItem;
         d->focusResidualItem = 0;
     } else if (focusHighlight == HbWidget::FocusHighlightActive) {
-        d->focusActiveType = type;
+        d->focusActiveType = (HbStylePrivate::Primitive)type;
     } else {
-        d->focusResidualType = type;
+        d->focusResidualType = (HbStylePrivate::Primitive)type;
     }
 }
 
@@ -1291,19 +1295,19 @@
 HbStyle::Primitive HbWidget::focusHighlight(HbWidget::FocusHighlight highlightType)
 {
     Q_D(HbWidget);
-    HbStyle::Primitive primitive(HbStyle::P_None);
+    HbStylePrivate::Primitive primitive(HbStylePrivate::P_None);
 
     if (highlightType == HbWidget::FocusHighlightActive) {
         primitive = d->focusActiveType;
     } else if (highlightType == HbWidget::FocusHighlightResidual) {
         primitive = d->focusResidualType;
     }
-    return primitive;
+    return (HbStyle::Primitive)primitive;
 }
 
 bool HbWidget::sceneEventFilter (QGraphicsItem *watched, QEvent *event)
 {
-    if(event->type() == QEvent::Gesture && watched->type() == Hb::ItemType_TouchArea) {
+    if(isEnabled() && event->type() == QEvent::Gesture && watched->type() == Hb::ItemType_TouchArea) {
         QGestureEvent* ge = static_cast<QGestureEvent*>(event);
         HbTapGesture* tap = qobject_cast<HbTapGesture*>(ge->gesture(Qt::TapGesture));