src/hbcore/gui/hbwidgetbase.cpp
changeset 21 4633027730f5
parent 7 923ff622b8b9
child 23 e6ad4ef83b23
equal deleted inserted replaced
7:923ff622b8b9 21:4633027730f5
    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>
       
    31 #ifdef HB_EFFECTS
    29 #ifdef HB_EFFECTS
    32 #include <hbeffect.h>
    30 #include <hbeffect.h>
    33 #include <hbeffectinternal_p.h>
    31 #include <hbeffectinternal_p.h>
    34 #endif
    32 #endif
    35 #include "hbstyleoption_p.h"
    33 #include "hbstyleoption_p.h"
    36 #include "hbfontspec.h"
    34 #include "hbfontspec.h"
    37 #include "hbwidgetbase.h"
    35 #include "hbwidgetbase.h"
    38 #include "hbwidgetbase_p.h"
    36 #include "hbwidgetbase_p.h"
    39 #include "hbevent.h"
    37 #include "hbevent.h"
       
    38 #include <hbwidget.h>
       
    39 #include <QGraphicsLayout>
    40 
    40 
    41 
    41 
    42 /*!
    42 /*!
    43     \class HbWidgetBase
    43     \class HbWidgetBase
    44 
    44 
    49     by default for performance reasons.
    49     by default for performance reasons.
    50     Custom widget should enable ItemSendsGeometryChanges flag to receive notifications for position
    50     Custom widget should enable ItemSendsGeometryChanges flag to receive notifications for position
    51     and transform changes.You should enable ItemUsesExtendedStyleOption if widget uses QStyleOptionGraphicsItem
    51     and transform changes.You should enable ItemUsesExtendedStyleOption if widget uses QStyleOptionGraphicsItem
    52     i.eduring painting.
    52     i.eduring painting.
    53 
    53 
       
    54     HbWidgetBase is optimized to work with layout. ParentWidget is always reponsible
       
    55     of layouting its children. If widget doesnot have a layout than it is responsible for
       
    56     taking care of it's children geometries.HbWidgetBase doesnot guarantee that adjustSize will
       
    57     be called before widget is shown.
       
    58 
    54     Currently HbWidgetBase offers the following functionality:
    59     Currently HbWidgetBase offers the following functionality:
    55         - Layout direction locking                 
    60         - Layout direction locking                 
    56 */
    61 */
    57 
    62 
    58 HbWidgetBasePrivate::HbWidgetBasePrivate() :
    63 HbWidgetBasePrivate::HbWidgetBasePrivate() :
    59         mApiProtectionFlags(0),
    64         mApiProtectionFlags(0),
    60         attributes(0)
    65         attributes(0),
       
    66         polished(0)
       
    67 
    61 {
    68 {
    62     q_ptr = 0;
    69     q_ptr = 0;
    63 }
    70 }
    64 
    71 
    65 HbWidgetBasePrivate::~HbWidgetBasePrivate()
    72 HbWidgetBasePrivate::~HbWidgetBasePrivate()
    91             if (q->testAttribute(Hb::InsidePopup) != widgetBase->testAttribute(Hb::InsidePopup)) {
    98             if (q->testAttribute(Hb::InsidePopup) != widgetBase->testAttribute(Hb::InsidePopup)) {
    92                 setInsidePopup(widgetBase->testAttribute(Hb::InsidePopup));
    99                 setInsidePopup(widgetBase->testAttribute(Hb::InsidePopup));
    93             }
   100             }
    94         }
   101         }
    95     }
   102     }
       
   103 }
       
   104 
       
   105 //Optimizes updateGeometry calls for hbwidget and its descendents.
       
   106 bool HbWidgetBasePrivate::ignoreGeometryUpdate()
       
   107 {
       
   108 
       
   109     return false;
       
   110 }
       
   111 
       
   112 
       
   113 void HbWidgetBasePrivate::activateParentLayout()
       
   114 {
       
   115 
    96 }
   116 }
    97 
   117 
    98 void HbWidgetBasePrivate::setInsidePopup(bool insidePopup)
   118 void HbWidgetBasePrivate::setInsidePopup(bool insidePopup)
    99 {
   119 {
   100     Q_Q( HbWidgetBase );
   120     Q_Q( HbWidgetBase );
   174  */
   194  */
   175 bool HbWidgetBase::event(QEvent *e)
   195 bool HbWidgetBase::event(QEvent *e)
   176 {
   196 {
   177     if (e->type() == HbEvent::ThemeChanged) {
   197     if (e->type() == HbEvent::ThemeChanged) {
   178         changeEvent(e);
   198         changeEvent(e);
   179     }
   199     } 
   180 
       
   181     // This class will be rebased to QGraphicsWidget
       
   182     // that is why direct ancestor is not called
       
   183     return QGraphicsWidget::event(e);
   200     return QGraphicsWidget::event(e);
   184 }
   201 }
   185 
   202 
   186 
   203 
   187 bool HbWidgetBase::sceneEvent(QEvent *event)
   204 bool HbWidgetBase::sceneEvent(QEvent *event)
   202  */
   219  */
   203 QVariant HbWidgetBase::itemChange(GraphicsItemChange change, const QVariant &value)
   220 QVariant HbWidgetBase::itemChange(GraphicsItemChange change, const QVariant &value)
   204 {
   221 {
   205     Q_D(HbWidgetBase);
   222     Q_D(HbWidgetBase);
   206 
   223 
   207     if( change == QGraphicsItem::ItemVisibleChange) {
   224     if (change == QGraphicsItem::ItemVisibleChange) {
   208         if (value.toBool()) {
   225         if (value.toBool()) {
   209             // Applies same initialisation for Hb widgets as QGraphicsWidget.
   226             //For HbWidget/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.
   227             //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, 
   228             //to paint themselves before layouting, if they are added to existing layout.
   212             // if they are added to existing layout.
   229             // If HbWidgets/primitives are used as standalone widgets, 
   213             // If Hb primitives are used standalone, their size and position must be set explicitly.
   230             //their size and position must be set explicitly.
   214 
   231 
   215             // Send Show event before the item has been shown.
   232             // Send Show event before the item has been shown.
   216             QShowEvent event;
   233             QShowEvent event;
   217             QApplication::sendEvent(this, &event);
   234             QApplication::sendEvent(this, &event);
   218             bool resized = testAttribute(Qt::WA_Resized);
   235             bool resized = testAttribute(Qt::WA_Resized);
   219             if (!resized && testAttribute(Hb::Widget)) {
   236             if (!resized && testAttribute(Hb::Widget)) {
   220                 adjustSize();
   237                 adjustSize();
   221                 setAttribute(Qt::WA_Resized, false);
   238                 setAttribute(Qt::WA_Resized, false);
   222             } 
   239             }
   223             return QGraphicsItem::itemChange(change, value);
   240             return QGraphicsItem::itemChange(change, value);
   224         }
   241         }
   225     } else if( change == QGraphicsItem::ItemParentChange) {
   242     } else if (change == QGraphicsItem::ItemParentChange) {
   226         d->handleInsidePopup(value.value<QGraphicsItem *>());
   243         d->handleInsidePopup(value.value<QGraphicsItem *>());
   227     }
   244     }
   228     return QGraphicsWidget::itemChange(change, value);
   245     return QGraphicsWidget::itemChange(change, value);
   229 }
   246 }
   230 
   247 
   419     event->ignore();
   436     event->ignore();
   420     foreach(QGesture *g, event->gestures()) {
   437     foreach(QGesture *g, event->gestures()) {
   421         event->ignore(g);
   438         event->ignore(g);
   422     }
   439     }
   423 }
   440 }
       
   441 
       
   442 
       
   443 /*!
       
   444     \reimp
       
   445  */
       
   446 void HbWidgetBase::updateGeometry()
       
   447 {
       
   448     QGraphicsWidget::updateGeometry();
       
   449 }
       
   450 
       
   451 
       
   452 
       
   453 
       
   454