src/hbcore/gui/hbwidgetbase.cpp
changeset 34 ed14f46c0e55
parent 7 923ff622b8b9
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    23 **
    23 **
    24 ****************************************************************************/
    24 ****************************************************************************/
    25 
    25 
    26 #include <QApplication>
    26 #include <QApplication>
    27 #include <QGraphicsWidget>
    27 #include <QGraphicsWidget>
    28 #include <QPainter>
       
    29 #include <QDebug>
    28 #include <QDebug>
    30 #include <hbtextitem.h>
    29 #include <hbstyleprimitivedata.h>
    31 #ifdef HB_EFFECTS
    30 #ifdef HB_EFFECTS
    32 #include <hbeffect.h>
    31 #include <hbeffect.h>
    33 #include <hbeffectinternal_p.h>
    32 #include <hbeffectinternal_p.h>
    34 #endif
    33 #endif
    35 #include "hbstyleoption_p.h"
    34 #include "hbstyleoption_p.h"
    36 #include "hbfontspec.h"
    35 #include "hbfontspec.h"
    37 #include "hbwidgetbase.h"
    36 #include "hbwidgetbase.h"
    38 #include "hbwidgetbase_p.h"
    37 #include "hbwidgetbase_p.h"
    39 #include "hbevent.h"
    38 #include "hbevent.h"
       
    39 #include <hbwidget.h>
       
    40 #include <QGraphicsLayout>
    40 
    41 
    41 
    42 
    42 /*!
    43 /*!
    43     \class HbWidgetBase
    44     \class HbWidgetBase
    44 
    45 
    49     by default for performance reasons.
    50     by default for performance reasons.
    50     Custom widget should enable ItemSendsGeometryChanges flag to receive notifications for position
    51     Custom widget should enable ItemSendsGeometryChanges flag to receive notifications for position
    51     and transform changes.You should enable ItemUsesExtendedStyleOption if widget uses QStyleOptionGraphicsItem
    52     and transform changes.You should enable ItemUsesExtendedStyleOption if widget uses QStyleOptionGraphicsItem
    52     i.eduring painting.
    53     i.eduring painting.
    53 
    54 
       
    55     HbWidgetBase is optimized to work with layout. ParentWidget is always reponsible
       
    56     of layouting its children. If widget doesnot have a layout than it is responsible for
       
    57     taking care of it's children geometries.HbWidgetBase doesnot guarantee that adjustSize will
       
    58     be called before widget is shown.
       
    59 
    54     Currently HbWidgetBase offers the following functionality:
    60     Currently HbWidgetBase offers the following functionality:
    55         - Layout direction locking                 
    61         - Layout direction locking                 
    56 */
    62 */
    57 
    63 
    58 HbWidgetBasePrivate::HbWidgetBasePrivate() :
    64 HbWidgetBasePrivate::HbWidgetBasePrivate() :
    59         mApiProtectionFlags(0),
    65         mApiProtectionFlags(0),
    60         attributes(0)
    66         attributes(0)
       
    67 
    61 {
    68 {
    62     q_ptr = 0;
    69     q_ptr = 0;
    63 }
    70 }
    64 
    71 
    65 HbWidgetBasePrivate::~HbWidgetBasePrivate()
    72 HbWidgetBasePrivate::~HbWidgetBasePrivate()
   174  */
   181  */
   175 bool HbWidgetBase::event(QEvent *e)
   182 bool HbWidgetBase::event(QEvent *e)
   176 {
   183 {
   177     if (e->type() == HbEvent::ThemeChanged) {
   184     if (e->type() == HbEvent::ThemeChanged) {
   178         changeEvent(e);
   185         changeEvent(e);
   179     }
   186     } 
   180 
       
   181     // This class will be rebased to QGraphicsWidget
       
   182     // that is why direct ancestor is not called
       
   183     return QGraphicsWidget::event(e);
   187     return QGraphicsWidget::event(e);
   184 }
   188 }
   185 
   189 
   186 
   190 
   187 bool HbWidgetBase::sceneEvent(QEvent *event)
   191 bool HbWidgetBase::sceneEvent(QEvent *event)
   202  */
   206  */
   203 QVariant HbWidgetBase::itemChange(GraphicsItemChange change, const QVariant &value)
   207 QVariant HbWidgetBase::itemChange(GraphicsItemChange change, const QVariant &value)
   204 {
   208 {
   205     Q_D(HbWidgetBase);
   209     Q_D(HbWidgetBase);
   206 
   210 
   207     if( change == QGraphicsItem::ItemVisibleChange) {
   211     if (change == QGraphicsItem::ItemVisibleChange) {
   208         if (value.toBool()) {
   212         if (value.toBool()) {
   209             // Applies same initialisation for Hb widgets as QGraphicsWidget.
   213             //For Primitives size is not set as they will be layouted
   210             // For Hb primitives size is not set as they will be later layouted by Hb widgets.
   214             //after being polished. This is done to avoid flickering as primitives tend
   211             // This is done to avoid flickering as primitives tend to paint themselves before layouting, 
   215             //to paint themselves before layouting, if they are added to existing layout.
   212             // if they are added to existing layout.
       
   213             // If Hb primitives are used standalone, their size and position must be set explicitly.
       
   214 
   216 
   215             // Send Show event before the item has been shown.
   217             // Send Show event before the item has been shown.
   216             QShowEvent event;
   218             QShowEvent event;
   217             QApplication::sendEvent(this, &event);
   219             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);
   220             return QGraphicsItem::itemChange(change, value);
   224         }
   221         }
   225     } else if( change == QGraphicsItem::ItemParentChange) {
   222     } else if (change == QGraphicsItem::ItemParentChange) {
   226         d->handleInsidePopup(value.value<QGraphicsItem *>());
   223         d->handleInsidePopup(value.value<QGraphicsItem *>());
   227     }
   224     }
   228     return QGraphicsWidget::itemChange(change, value);
   225     return QGraphicsWidget::itemChange(change, value);
   229 }
   226 }
   230 
   227 
   403     option->direction = layoutDirection();
   400     option->direction = layoutDirection();
   404     option->rect = rect().toRect(); 
   401     option->rect = rect().toRect(); 
   405     option->boundingRect = boundingRect();
   402     option->boundingRect = boundingRect();
   406 }
   403 }
   407 
   404 
       
   405 
       
   406 /*!
       
   407   Initializes the common primitive data. This method sets the common \a state parameter.
       
   408   
       
   409   The state style option consists of flags. If this widget is enabled the flag QStyle::State_Enabled is set. 
       
   410   If this widget is active the flag QStyle::State_Active will be set.    
       
   411   Derived implementations should create a base call to this method.
       
   412   
       
   413   This function does not call the base class implementation.
       
   414   \param primitiveData pointer to the primitive data
       
   415   \param primitive primitive pointer, in case there is a need to query data from the primitive (e.g. item name)
       
   416     
       
   417 */
       
   418 void HbWidgetBase::initPrimitiveData(HbStylePrimitiveData *primitiveData, const QGraphicsObject *primitive)
       
   419 {
       
   420 
       
   421     Q_ASSERT(primitiveData);
       
   422     Q_UNUSED(primitive);
       
   423 
       
   424     primitiveData->state = QStyle::State_None;
       
   425     if (isEnabled())
       
   426         primitiveData->state |= QStyle::State_Enabled;
       
   427     
       
   428     if (QGraphicsWidget *w = window()) {
       
   429         if (w->isActiveWindow())
       
   430             primitiveData->state |= QStyle::State_Active;
       
   431     }
       
   432 }
       
   433 
       
   434 
   408 /*!
   435 /*!
   409     This event handler, for \a event, receives gesture events. Its base
   436     This event handler, for \a event, receives gesture events. Its base
   410     implementation ignores all gestures delivered in the \a event.
   437     implementation ignores all gestures delivered in the \a event.
   411 
   438 
   412     You can reimplement this handler in a subclass of HbWidgetBase to
   439     You can reimplement this handler in a subclass of HbWidgetBase to
   419     event->ignore();
   446     event->ignore();
   420     foreach(QGesture *g, event->gestures()) {
   447     foreach(QGesture *g, event->gestures()) {
   421         event->ignore(g);
   448         event->ignore(g);
   422     }
   449     }
   423 }
   450 }
       
   451 
       
   452 
       
   453 /*!
       
   454     \reimp
       
   455  */
       
   456 void HbWidgetBase::updateGeometry()
       
   457 {
       
   458     QGraphicsWidget::updateGeometry();
       
   459 }
       
   460 
       
   461 
       
   462 
       
   463 
       
   464