src/hbcore/gui/hbwidgetbase.cpp
changeset 7 923ff622b8b9
parent 2 06ff229162e9
child 21 4633027730f5
child 34 ed14f46c0e55
equal deleted inserted replaced
6:c3690ec91ef8 7:923ff622b8b9
    43     \class HbWidgetBase
    43     \class HbWidgetBase
    44 
    44 
    45     \brief HbWidgetBase is a common base for all Hb widgets and primitives. 
    45     \brief HbWidgetBase is a common base for all Hb widgets and primitives. 
    46     It contains common functionality shared between these two types.
    46     It contains common functionality shared between these two types.
    47 
    47 
       
    48     HbWidgetBase disables the ItemSendsGeometryChanges and ItemUsesExtendedStyleOption flags
       
    49     by default for performance reasons.
       
    50     Custom widget should enable ItemSendsGeometryChanges flag to receive notifications for position
       
    51     and transform changes.You should enable ItemUsesExtendedStyleOption if widget uses QStyleOptionGraphicsItem
       
    52     i.eduring painting.
       
    53 
    48     Currently HbWidgetBase offers the following functionality:
    54     Currently HbWidgetBase offers the following functionality:
    49         - Layout direction locking                 
    55         - Layout direction locking                 
    50 */
    56 */
    51 
    57 
    52 HbWidgetBasePrivate::HbWidgetBasePrivate() :
    58 HbWidgetBasePrivate::HbWidgetBasePrivate() :
    62 
    68 
    63 void HbWidgetBasePrivate::init()
    69 void HbWidgetBasePrivate::init()
    64 {
    70 {
    65     Q_Q( HbWidgetBase );
    71     Q_Q( HbWidgetBase );
    66     QGraphicsItem *item = q->parentItem();
    72     QGraphicsItem *item = q->parentItem();
       
    73     QGraphicsItem::GraphicsItemFlags itemFlags = q->flags();
       
    74 #if QT_VERSION >= 0x040600
       
    75     itemFlags &=  ~QGraphicsItem::ItemSendsGeometryChanges;
       
    76 #endif
       
    77     itemFlags &= ~QGraphicsItem::ItemUsesExtendedStyleOption;
       
    78     q->setFlags(itemFlags);
    67     if ( item ) {
    79     if ( item ) {
    68         handleInsidePopup(item);
    80         handleInsidePopup(item);
    69     }
    81     }
    70 }
    82 }
    71 
    83 
   190  */
   202  */
   191 QVariant HbWidgetBase::itemChange(GraphicsItemChange change, const QVariant &value)
   203 QVariant HbWidgetBase::itemChange(GraphicsItemChange change, const QVariant &value)
   192 {
   204 {
   193     Q_D(HbWidgetBase);
   205     Q_D(HbWidgetBase);
   194 
   206 
   195     if( change == QGraphicsItem::ItemParentChange) {
   207     if( change == QGraphicsItem::ItemVisibleChange) {
       
   208         if (value.toBool()) {
       
   209             // Applies same initialisation for Hb widgets as QGraphicsWidget.
       
   210             // For Hb primitives size is not set as they will be later layouted by Hb widgets.
       
   211             // This is done to avoid flickering as primitives tend to paint themselves before layouting, 
       
   212             // if they are added to existing layout.
       
   213             // If Hb primitives are used standalone, their size and position must be set explicitly.
       
   214 
       
   215             // Send Show event before the item has been shown.
       
   216             QShowEvent event;
       
   217             QApplication::sendEvent(this, &event);
       
   218             bool resized = testAttribute(Qt::WA_Resized);
       
   219             if (!resized && testAttribute(Hb::Widget)) {
       
   220                 adjustSize();
       
   221                 setAttribute(Qt::WA_Resized, false);
       
   222             } 
       
   223             return QGraphicsItem::itemChange(change, value);
       
   224         }
       
   225     } else if( change == QGraphicsItem::ItemParentChange) {
   196         d->handleInsidePopup(value.value<QGraphicsItem *>());
   226         d->handleInsidePopup(value.value<QGraphicsItem *>());
   197     }
   227     }
   198     return QGraphicsWidget::itemChange(change, value);
   228     return QGraphicsWidget::itemChange(change, value);
   199 }
   229 }
   200 
   230