src/hbcore/gui/hbpopup.cpp
changeset 21 4633027730f5
parent 7 923ff622b8b9
child 23 e6ad4ef83b23
equal deleted inserted replaced
7:923ff622b8b9 21:4633027730f5
    42 #include <QEventLoop>
    42 #include <QEventLoop>
    43 #include <QPointer>
    43 #include <QPointer>
    44 #include <QDebug>
    44 #include <QDebug>
    45 #include <QBitmap>
    45 #include <QBitmap>
    46 #include <hbinstance_p.h>
    46 #include <hbinstance_p.h>
       
    47 #include <QGraphicsScene>
    47 #include <QApplication> // krazy:exclude=qclasses
    48 #include <QApplication> // krazy:exclude=qclasses
    48 
    49 
    49 #include <hbwidgetfeedback.h>
    50 #include <hbwidgetfeedback.h>
    50 
    51 
    51 #ifdef HB_EFFECTS
    52 #ifdef HB_EFFECTS
    54 #endif
    55 #endif
    55 /*!
    56 /*!
    56     @beta
    57     @beta
    57     @hbcore
    58     @hbcore
    58     \class HbPopup
    59     \class HbPopup
    59     \brief HbPopup is a base class for different popups in Hb library.
    60     \brief The HbPopup class defines a set of properties that control the behavior of 
    60 
    61     the many dialog and popup classes that derive from it. 
    61     Popup is a widget that is displayed above other widgets in the view.
    62     
    62 
    63     Objects of classes derived from %HbPopup are called \b popups. Typically they
    63     Lastly shown popup is always positioned in Z order on the the top
    64     are displayed above other objects within the view, at the highest z-order. The %HbPopup
    64     of already visible popups.  
    65     class simply defines a frame with a number of properties. If you want to create an
    65 
    66     application dialog with a heading, content and a toolbar, use the HbDialog class (which
    66     A popup can be permanent or automatically dismissed after a
    67     is derived from %HbPopup) or one of its convenience subclasses.
    67     time-out.  Modal popups interrupt any other user interaction
    68     
    68     outside of the popup while they are visible, whereas non-modal
    69     %HbPopup provides properties that you can use to customize the following aspects of a popup:
    69     popups do not.
    70     
    70 
    71     - \b Modality. You can define whether the popup is modal or non-modal. A modal popup stops
    71     \sa HbDialog
    72       the user interacting with anything outside of the popup until it closes. A non-modal 
    72 */
    73       popup does not block the user's interaction with things outside of the popup. You 
    73 
    74       set and get the modality by calling setModal() and isModal(), respectively.  
    74 /*!
    75     
    75     \reimp
    76     - <b>Dismiss policy</b>. You can define which user actions, if any, cause the popup to 
       
    77       close. Possible values are defined by HbPopup::DismissPolicy. You set and get the dismiss 
       
    78       policy by calling setDismissPolicy() and dismissPolicy(), respectively.
       
    79     
       
    80     - <b>Background fade policy</b>. You can set a policy to fade everything behind the 
       
    81       popup. This is useful for modal dialogs, because the user cannot interact with 
       
    82       anything behind the popup. You control this policy by calling setBackgroundFaded() and 
       
    83       get the current policy by calling isBackgroundFaded().
       
    84     
       
    85     - \b Timeout. You can define a timeout that causes the popup to be dismissed automatically
       
    86       after a set a period. You set and get this property by calling setTimeout() and 
       
    87       timeout(), respectively. Call the setTimeout(HbPopup::DefaultTimeout) overload to use the 
       
    88       default value for the popup type, which provides a common look and feel.
       
    89       
       
    90     - <b>Frame background type</b>. You can define the popup's background style. However, 
       
    91       the actual appearance of the popup depends on the theme. You set and get this property by
       
    92       calling setFrameType() and frameType(), respectively.
       
    93       
       
    94     By default, popups are displayed in the center of the screen. Typically you should not override
       
    95     the default position of modal dialogs. However, some popups, such as context menus, need to be 
       
    96     in a specific position. For these, you can use the setPreferredPos() method to set the 
       
    97     preferred position.
       
    98     
       
    99     Popups that contain an editor may be repositioned by the virtual keyboard when it opens. 
       
   100     When the virtual keyboard closes, it attempts to reposition the popup back to its 
       
   101     previous position. However, this is not always possible, particularly when there has also
       
   102     been an orientation switch.
       
   103 
       
   104     \section _usecases_hbpopup Using the HbPopup class
       
   105     
       
   106     Although it is possible to create an instance of the HbPopup class, it is designed as a
       
   107     base class to provide common features to the many popup and dialog classes that are 
       
   108     derived from it (such as HbMenu, HbDialog, HbToolBarExtension, HbZoomSliderPopup). 
       
   109     
       
   110     How you open a popup depends on whether it is modal. It is important to use the 
       
   111     appropriate method, because this ensures the correct touch event handling.
       
   112     
       
   113     <table border="1" style="border-collapse: collapse; border: solid;">
       
   114     <tr><th>To open</TH><TH>Call</th></tr>
       
   115     <tr><td>Modal popups</td><td>open()</td></tr>
       
   116     <tr><td>Non-modal popups</td><td>\link QGraphicsItem::show() show()\endlink</td></tr>
       
   117     </table>
       
   118 
       
   119     \sa HbDialog, HbMenu
       
   120 */
       
   121 
       
   122 /*!
    76     \fn int HbPopup::type() const
   123     \fn int HbPopup::type() const
    77  */
   124  */
    78 
   125 
    79 /*!
   126 /*!
    80     \enum HbPopup::DefaultTimeout
   127     \enum HbPopup::DefaultTimeout
    81 
   128 
    82     This enum defines available default timeout values to be used in method
   129     Identifies default timeout values for various popup types. The timeout defines a time
    83     setTimeout(HbPopup::DefaultTimeout).
   130     period after which the popup is automatically closed. Using these default values 
       
   131     provides a consistent look and feel.
       
   132     \sa setTimeout(HbPopup::DefaultTimeout)
    84  */
   133  */
    85 
   134 
    86 /*!
   135 /*!
    87     \var HbPopup::NoTimeout
   136     \var HbPopup::NoTimeout
    88 
   137     Defines a permanent popup, for which no timeout is defined.
    89     No timeout is defined for automatically closing the popup. i.e. the popup is permanent.
       
    90  */
   138  */
    91 
   139 
    92 /*!
   140 /*!
    93     \var HbPopup::ConfirmationNoteTimeout
   141     \var HbPopup::ConfirmationNoteTimeout
    94 
   142     The default timeout value for confirmation notes.
    95     Timeout value intended to be used by confirmation notes.
       
    96  */
   143  */
    97 
   144 
    98 /*!
   145 /*!
    99     \var HbPopup::StandardTimeout
   146     \var HbPopup::StandardTimeout
   100 
   147     The default timeout value for standard non-permanent popups, such as notes.
   101     The default timeout value intended to be used by most non-permanent popups e.g. by notes.
       
   102  */
   148  */
   103 
   149 
   104 /*!
   150 /*!
   105     \var HbPopup::ContextMenuTimeout
   151     \var HbPopup::ContextMenuTimeout
   106 
   152     The default timeout value for context menus.
   107     The default timeout value intended to be used by context menus.
       
   108  */
   153  */
   109 
   154 
   110 /*!
   155 /*!
   111     \enum HbPopup::DismissPolicy
   156     \enum HbPopup::DismissPolicy
   112 
   157 
   113     This enum defines available dismiss policy values.
   158     Defines the available dismiss policy values. The dismiss policy defines which
   114 
   159     user actions cause the popup to close.
   115     The dismiss policy defines what user actions will cause the popup to be dismissed i.e. closed.
   160     
       
   161     \sa setDismissPolicy(), dismissPolicy()
   116  */
   162  */
   117 
   163 
   118 /*!
   164 /*!
   119     \var HbPopup::NoDismiss
   165     \var HbPopup::NoDismiss
   120 
   166     The popup cannot be closed by the user.
   121     The popup cannot be dismissed automatically by user interaction.
       
   122  */
   167  */
   123 
   168 
   124 /*!
   169 /*!
   125     \var HbPopup::TapInside
   170     \var HbPopup::TapInside
   126 
   171     Closes the popup when the user taps within the popup's bounding rectangle.
   127     The popup is dismissed when user taps within the bounding rectangle of the popup.
       
   128  */
   172  */
   129 
   173 
   130 /*!
   174 /*!
   131     \var HbPopup::TapOutside
   175     \var HbPopup::TapOutside
   132 
   176 
   133     The popup is dismissed when user taps outside of the bounding rectangle of the popup.
   177     Closes the popup when the user taps outside of the popup's bounding rectangle.
   134  */
   178  */
   135 
   179 
   136 /*!
   180 /*!
   137     \var HbPopup::TapAnywhere
   181     \var HbPopup::TapAnywhere
   138 
   182     Closes the popup when the user taps either inside or outside the popup's bounding 
   139     The popup is dismissed when user taps either within or outside
   183     rectangle.
   140     of the bounding rectangle of the popup.
       
   141  */
   184  */
   142 
   185 
   143 /*!
   186 /*!
   144     \enum HbPopup::FrameType
   187     \enum HbPopup::FrameType
   145 
   188 
   146     This enum defines available frame type values.
   189     Identifies the background graphical styles of the popup's frame.
   147 
   190 
   148     The frame types defines what frame item backgrounds will be used
   191     \sa setFrameType(), frameType()
   149     by the popup. Actual appearance is dependent on theme.
       
   150  */
   192  */
   151 
   193 
   152 /*!
   194 /*!
   153     \var HbPopup::Strong
   195     \var HbPopup::Strong
   154 
   196     Use the "strong" frame background style.
   155     The popup is using strong frame.
       
   156  */
   197  */
   157 
   198 
   158 /*!
   199 /*!
   159     \var HbPopup::Weak
   200     \var HbPopup::Weak
   160 
   201     Use the "weak" frame background style.
   161     The popup is using weak frame.
       
   162  */
   202  */
   163 
   203 
   164 /*!
   204 /*!
   165     \fn void HbPopup::aboutToShow();
   205     \fn void HbPopup::aboutToShow();
   166 
   206 
   167     This signal is emitted when the popup is about to be shown i.e. when method show() is called.
   207     This signal is emitted when the popup is about to be shown; that is, when 
       
   208     \link QGraphicsItem::show() show()\endlink is called.
   168  */
   209  */
   169 
   210 
   170 /*!
   211 /*!
   171     \fn void HbPopup::aboutToHide();
   212     \fn void HbPopup::aboutToHide();
   172 
   213 
   173     This signal is emitted when the popup is about to be hidden i.e. when method hide() is called.
   214     This signal is emitted when the popup is about to be hidden; that is, when 
       
   215     \link QGraphicsItem::hide() hide()\endlink is called.
   174  */
   216  */
   175 
   217 
   176 
   218 
   177 /*!
   219 /*!
   178     \fn void HbPopup::aboutToClose();
   220     \fn void HbPopup::aboutToClose();
   179 
   221 
   180     This signal is emitted when the popup is about to be closed i.e. when method close() is called
   222     This signal is emitted when the popup is about to close; that is, when 
   181     or the popup is
   223     \link QGraphicsWidget::close() close()\endlink is called or the popup is dismissed 
   182     dismissed by the user or timeout.
   224     by the user or timeout.
   183  */
   225  */
   184 
   226 
   185 /*!
   227 /*!
   186     \enum HbPopup::Placement
   228     \enum HbPopup::Placement
   187 
   229     Identifies the corners and edges of the popup for use when setting its position
   188     Placement is the corner or edge to which position of the popup refers to.
   230     using setPreferredPos(). 
   189   */
   231   */
   190 
   232   
   191 /*!
   233 /*!
   192     \primitives
   234     \var HbPopup::TopLeftCorner
   193     \primitive{background} HbFrameItem representing the popup background. The background can be weak or strong (different graphical styles) depending on popup type.
   235     The popup's top left corner.
   194     \primitive{P_Popup_heading_frame} HbFrameItem representing the popup heading text background
   236  */
   195   */
   237   
       
   238 /*!
       
   239     \var HbPopup::TopRightCorner
       
   240     The popup's top right corner.
       
   241  */
       
   242    
       
   243 /*!
       
   244     \var HbPopup::BottomLeftCorner
       
   245     The popup's bottom left corner.
       
   246  */
       
   247    
       
   248 /*!
       
   249     \var HbPopup::BottomRightCorner
       
   250     The popup's bottom right corner.
       
   251  */
       
   252    
       
   253 /*!
       
   254     \var HbPopup::TopEdgeCenter
       
   255     The center of the popup's top edge.
       
   256  */
       
   257    
       
   258 /*!
       
   259     \var HbPopup::RightEdgeCenter
       
   260     The center of the popup's rightmost edge.
       
   261  */
       
   262     
       
   263 /*!
       
   264     \var HbPopup::BottomEdgeCenter
       
   265     The center of the popup's bottom edge.
       
   266  */
       
   267     
       
   268 /*!
       
   269     \var HbPopup::LeftEdgeCenter
       
   270     The center of the popup's leftmost edge.
       
   271  */
       
   272  
       
   273  /*!
       
   274     \var HbPopup::Center
       
   275     The center of the popup.
       
   276  */
   196 
   277 
   197 static const struct { HbPopup::DefaultTimeout timeout; int value; } timeoutValues[] =
   278 static const struct { HbPopup::DefaultTimeout timeout; int value; } timeoutValues[] =
   198 {
   279 {
   199     {HbPopup::NoTimeout,0},
   280     {HbPopup::NoTimeout,0},
   200     {HbPopup::ConfirmationNoteTimeout,1500},
   281     {HbPopup::ConfirmationNoteTimeout,1500},
   201     {HbPopup::StandardTimeout,3000},
   282     {HbPopup::StandardTimeout,3000},
   202     {HbPopup::ContextMenuTimeout,6000},
   283     {HbPopup::ContextMenuTimeout,6000},
   203 };
   284 };
   204 
   285 
       
   286 /*
       
   287     \primitives
       
   288     \primitive{background} HbFrameItem representing the popup background. The background can be 
       
   289     weak or strong (different graphical styles) depending on popup type.
       
   290     \primitive{P_Popup_heading_frame} HbFrameItem representing the popup heading text background
       
   291   */
   205 HbPopupBackGround::HbPopupBackGround(HbPopup * popup, QGraphicsItem *parent) :
   292 HbPopupBackGround::HbPopupBackGround(HbPopup * popup, QGraphicsItem *parent) :
   206         QGraphicsItem(parent),
   293         QGraphicsItem(parent),
   207         popup(popup)
   294         popup(popup)
   208 {
   295 {
   209     // This is needed to be able to block moving the focus to items behind background item by
   296     // This is needed to be able to block moving the focus to items behind background item by
   291     dismissPolicy(HbPopup::TapOutside),
   378     dismissPolicy(HbPopup::TapOutside),
   292     backgroundItem(0),
   379     backgroundItem(0),
   293     mousePressLocation(None),
   380     mousePressLocation(None),
   294     frameType(HbPopup::Strong),
   381     frameType(HbPopup::Strong),
   295     preferredPosSet(false),
   382     preferredPosSet(false),
   296     mStartEffect(false),
   383     placement(HbPopup::TopLeftCorner),
       
   384     mStartEffect(true),
   297     mScreenMargin(0.0),
   385     mScreenMargin(0.0),
   298     mAutoLayouting(true),
   386     mAutoLayouting(true),
   299     mOriginalAutoLayouting(mAutoLayouting),
   387     mOriginalAutoLayouting(mAutoLayouting),
       
   388     mActivePopup(true),
   300     mVgMaskEffect(0),
   389     mVgMaskEffect(0),
   301     mOrientationEffectHide(false),
   390     mOrientationEffectHide(false),
       
   391     mGestureOverride(false),
   302     timeoutTimerInstance(0)
   392     timeoutTimerInstance(0)
   303 {
   393 {
   304 }
   394 }
   305 
   395 
   306 HbPopupPrivate::~HbPopupPrivate()
   396 HbPopupPrivate::~HbPopupPrivate()
   315 
   405 
   316     q->setAttribute(Hb::InsidePopup);
   406     q->setAttribute(Hb::InsidePopup);
   317 
   407 
   318     // By default popups are focusable
   408     // By default popups are focusable
   319     q->setFocusPolicy(Qt::StrongFocus);    
   409     q->setFocusPolicy(Qt::StrongFocus);    
   320     setBackgroundItem(HbStyle::P_Popup_background);
   410     setBackgroundItem(HbStylePrivate::P_Popup_background);
   321     q->updatePrimitives();
   411     q->updatePrimitives();
   322 
   412 
   323 
   413 
   324     // Only for popup without parent
   414     // Only for popup without parent
   325     if (!q->parentItem()) {
   415     if (!q->parentItem()) {
   332     hidingInProgress = false; 
   422     hidingInProgress = false; 
   333     QGraphicsItem::GraphicsItemFlags itemFlags = q->flags();
   423     QGraphicsItem::GraphicsItemFlags itemFlags = q->flags();
   334     itemFlags |= QGraphicsItem::ItemClipsToShape;
   424     itemFlags |= QGraphicsItem::ItemClipsToShape;
   335     itemFlags |= QGraphicsItem::ItemClipsChildrenToShape;
   425     itemFlags |= QGraphicsItem::ItemClipsChildrenToShape;
   336     itemFlags |= QGraphicsItem::ItemSendsGeometryChanges;
   426     itemFlags |= QGraphicsItem::ItemSendsGeometryChanges;
   337     //itemFlags |= QGraphicsItem::ItemIsPanel;
   427     itemFlags |= QGraphicsItem::ItemIsPanel;
   338     q->setFlags(itemFlags);  
   428     q->setFlags(itemFlags);    
   339 }
   429 }
       
   430 
   340 void HbPopupPrivate::_q_appearEffectEnded(HbEffect::EffectStatus status)
   431 void HbPopupPrivate::_q_appearEffectEnded(HbEffect::EffectStatus status)
   341 {
   432 {
   342 	Q_UNUSED(status);
   433     Q_UNUSED(status);
   343 }
   434 }
   344 
   435 
   345 CSystemToneService* HbPopupPrivate::systemToneService()
   436 CSystemToneService* HbPopupPrivate::systemToneService()
   346 {
   437 {
   347 	return HbInstancePrivate::d_ptr()->systemTone();
   438 	return HbInstancePrivate::d_ptr()->systemTone();
   363 
   454 
   364 #ifdef HB_EFFECTS
   455 #ifdef HB_EFFECTS
   365 void HbPopupPrivate::_q_delayedHide(HbEffect::EffectStatus status)
   456 void HbPopupPrivate::_q_delayedHide(HbEffect::EffectStatus status)
   366 {
   457 {
   367     Q_UNUSED(status);
   458     Q_UNUSED(status);
   368 
       
   369     Q_Q(HbPopup);
   459     Q_Q(HbPopup);
   370 
   460 
   371     // Apply forceHide only if the effect started successfully
   461     // Apply forceHide only if the effect started successfully
   372     if (status.reason != Hb::EffectNotStarted) {
   462     if (status.reason != Hb::EffectNotStarted) {
   373         forceHide();
   463         forceHide();
   377 
   467 
   378     if (deleteOnClose) {
   468     if (deleteOnClose) {
   379         q->deleteLater();
   469         q->deleteLater();
   380     }
   470     }
   381     hidingInProgress = false;
   471     hidingInProgress = false;
       
   472     mGestureOverride = false;
   382 }
   473 }
   383 
   474 
   384 void HbPopupPrivate::_q_orientationAboutToChange(Qt::Orientation orient, bool animate)
   475 void HbPopupPrivate::_q_orientationAboutToChange(Qt::Orientation orient, bool animate)
   385 {
   476 {
   386     Q_UNUSED(orient);    
   477     Q_UNUSED(orient);    
   394 #endif // HB_EFFECTS
   485 #endif // HB_EFFECTS
   395 
   486 
   396 void HbPopupPrivate::_q_orientationChanged()
   487 void HbPopupPrivate::_q_orientationChanged()
   397 {
   488 {
   398     Q_Q(HbPopup);
   489     Q_Q(HbPopup);
   399     if (q->isVisible()) {
   490     if (q->isVisible() || q) {
   400         QEvent userEvent(QEvent::ContextMenu);
   491         QEvent userEvent(QEvent::ContextMenu);
   401         QCoreApplication::sendEvent(q, &userEvent);
   492         QCoreApplication::sendEvent(q, &userEvent);
   402     }
   493     }
   403 #ifdef HB_EFFECTS
   494 #ifdef HB_EFFECTS
   404     if (mOrientationEffectHide) {
   495     if (mOrientationEffectHide) {
   479 
   570 
   480 void HbPopupPrivate::handleBackgroundMousePressEvent()
   571 void HbPopupPrivate::handleBackgroundMousePressEvent()
   481 {
   572 {
   482     Q_Q(HbPopup);
   573     Q_Q(HbPopup);
   483     mousePressLocation = Background;
   574     mousePressLocation = Background;
   484     if (dismissPolicy & HbPopup::TapOutside) {
   575     if (dismissPolicy & HbPopup::TapOutside && !modal) {
   485         q->close();
   576         q->close();
   486     }
   577     }
   487 }
   578 }
   488 
   579 
   489 void HbPopupPrivate::handleBackgroundMouseReleaseEvent(QGraphicsSceneMouseEvent *event)
   580 void HbPopupPrivate::handleBackgroundMouseReleaseEvent(QGraphicsSceneMouseEvent *event)
   507                 // Close popup if mouse press is initiated within popup or TapOutside is set
   598                 // Close popup if mouse press is initiated within popup or TapOutside is set
   508                 if (mousePressLocation == Popup || dismissPolicy & HbPopup::TapOutside) {
   599                 if (mousePressLocation == Popup || dismissPolicy & HbPopup::TapOutside) {
   509                     q->close();
   600                     q->close();
   510                 }
   601                 }
   511             }
   602             }
       
   603         } else if ( mousePressLocation == Background &&
       
   604                     dismissPolicy & HbPopup::TapOutside && modal) {
       
   605             q->close();
   512         }
   606         }
   513     }
   607     }
   514 
   608 
   515     // reset mousePressLocation
   609     // reset mousePressLocation
   516     mousePressLocation = None;
   610     mousePressLocation = None;
   582     }
   676     }
   583 }
   677 }
   584 
   678 
   585 void HbPopupPrivate::calculateShape()
   679 void HbPopupPrivate::calculateShape()
   586 {
   680 {
   587 #if 0
       
   588     Q_Q(HbPopup);
   681     Q_Q(HbPopup);
       
   682     // Only used for HbMenu currently, this is not fully correct as some dialogs may need masking too.
       
   683     if (q->type() != Hb::ItemType_Menu) {
       
   684         return;
       
   685     }
       
   686     // Cannot set up masking if the background item is not available.
       
   687     if (!q->backgroundItem() || !q->backgroundItem()->boundingRect().isValid()) {
       
   688         return;
       
   689     }
   589     // Contrary to the name, HbVgMaskEffect has a software
   690     // Contrary to the name, HbVgMaskEffect has a software
   590     // implementation too, and we will actually force the usage of
   691     // implementation too, and we will actually force the usage of
   591     // that here, ignoring the pure OpenVG version.
   692     // that here, ignoring the pure OpenVG version.
   592     if (!mVgMaskEffect) {
   693     if (!mVgMaskEffect) {
   593         mVgMaskEffect = new HbVgMaskEffect;
   694         mVgMaskEffect = new HbVgMaskEffect;
   595         mVgMaskEffect->setForceSwMode(true);
   696         mVgMaskEffect->setForceSwMode(true);
   596         // There may be children (like the scroll area in menus) that
   697         // There may be children (like the scroll area in menus) that
   597         // would mess up the masking so exclude those.
   698         // would mess up the masking so exclude those.
   598         mVgMaskEffect->setIncludeSourceItemOnly(true);
   699         mVgMaskEffect->setIncludeSourceItemOnly(true);
   599         if (!q->graphicsEffect()) {
   700         if (!q->graphicsEffect()) {
   600             // Attach the effect. Ownership is transferred to q.
   701             // Attach the effect. Ownership is transferred to the chain. The
   601             mVgMaskEffect->install(q);
   702             // ownership of the chain is transferred to q.  The chain is needed
       
   703             // because we must co-exist with FXML-based filter effects.
       
   704             HbVgChainedEffect *c = new HbVgChainedEffect;
       
   705             c->add(mVgMaskEffect);
       
   706             c->install(q);
   602         } else {
   707         } else {
   603             // Avoid replacing already set effects. Do not mask if
   708             // Avoid replacing already set effects. Do not mask if this is not
   604             // this is not possible, otherwise we would unexpectedly
   709             // possible, otherwise we would unexpectedly delete the previously
   605             // delete the previously set graphics effect.
   710             // set graphics effect. However by being able to add the effect to a
       
   711             // chain makes it possible to co-exist with FXML-based filter
       
   712             // effects. Similar solution is also present in HbEffectGroup.
   606             HbVgChainedEffect *c = qobject_cast<HbVgChainedEffect *>(q->graphicsEffect());
   713             HbVgChainedEffect *c = qobject_cast<HbVgChainedEffect *>(q->graphicsEffect());
   607             if (c) {
   714             if (c) {
   608                 c->add(mVgMaskEffect);
   715                 c->add(mVgMaskEffect);
   609             } else {
   716             } else {
   610                 delete mVgMaskEffect;
   717                 delete mVgMaskEffect;
       
   718                 mVgMaskEffect = 0;
   611             }
   719             }
   612         }
   720         }
   613     }
   721     }
   614     QPixmap image(QSize(static_cast<int>(q->backgroundItem()->boundingRect().width()),
   722     QPixmap image(q->backgroundItem()->boundingRect().size().toSize());
   615                         static_cast<int>(q->backgroundItem()->boundingRect().height())));
       
   616     image.fill(Qt::transparent);
   723     image.fill(Qt::transparent);
   617     QPainter imagePainter(&image);
   724     QPainter imagePainter(&image);
   618     q->backgroundItem()->paint(&imagePainter, 0, 0);
   725     q->backgroundItem()->paint(&imagePainter, 0, 0);
   619     imagePainter.end();
   726     imagePainter.end();
   620     mVgMaskEffect->setMask(image);
   727     mVgMaskEffect->setMask(image);
   621 #endif
   728 }
   622 }
   729 
   623 
   730 void HbPopupPrivate::resizePopup()
   624 /*!
   731 {
   625  Constructs a popup with given  \a parent graphics item.\n
   732 
   626  Note: popups with \a parent set as 0 are behaving as real popups.
   733 }
   627  This is actually the intended use.
   734 
   628 
   735 /*!
   629  However in some situation could be useful to embedd a popup into a QGraphicsItem.
   736     Constructs a popup with the given \a parent graphics item. For true popup 
   630  In this case a non zero \a parent value must be passed.
   737     behavior (which means that it opens above other objects, at the highest z-order) 
   631  Popups with parent items behaving just like any other QGraphicsWidget.
   738     set \a parent to 0. This is the primary intended use of this class.
   632  The following features are not supported (i.e. ignored) for popup with parents:
   739 
   633 
   740     However, it may sometimes be useful to embed a popup into a QGraphicsItem. To do 
   634        - modality
   741     this, pass a non-zero \a parent value. HbPopup objects that have a parent are 
   635        - timeout
   742     not real popups: they behave like any other QGraphicsWidget object and following
   636        - unfadedItems
   743     properties are ignored. In addition the aboutToClose() signal is not emitted.
   637        - dismissPolicy
   744     
   638        - signal aboutToClose
   745     - \link isModal() modal\endlink property
       
   746     - \link timeout() timeout\endlink  property
       
   747     - \link isBackgroundFaded() Backgroundfaded\endlink property
       
   748     - \link  dismissPolicy() dismissPolicy\endlink property
   639 */
   749 */
   640 HbPopup::HbPopup(QGraphicsItem *parent) :
   750 HbPopup::HbPopup(QGraphicsItem *parent) :
   641     HbWidget(*new HbPopupPrivate,parent)
   751     HbWidget(*new HbPopupPrivate,parent)
   642 {
   752 {
   643     Q_D(HbPopup);
   753     Q_D(HbPopup);
   655     Q_D(HbPopup);
   765     Q_D(HbPopup);
   656     d->q_ptr = this;
   766     d->q_ptr = this;
   657     d->init();    
   767     d->init();    
   658 }
   768 }
   659 /*!
   769 /*!
   660  Destroys the popup.
   770     Destructor.
   661 */
   771 */
   662 HbPopup::~HbPopup()
   772 HbPopup::~HbPopup()
   663 {
   773 {
   664     Q_D(HbPopup);
   774     Q_D(HbPopup);
   665     d->inDestruction = true;
   775     d->inDestruction = true;
   686             delete d->backgroundItem;
   796             delete d->backgroundItem;
   687         }
   797         }
   688     }
   798     }
   689 }
   799 }
   690 
   800 
   691 
   801 /*!
   692 /*!
   802     Returns the popup's timeout property in milliseconds. The timeout causes the popup to
   693  Returns the popup timeout property in milliseconds.
   803     be dismissed automatically after the specified time period has elapsed. A value of
   694  If this property is not set the deafult is HbPopup::StandardTimeout.
   804     zero or less than zero, means that the popup is permanent and the user must take 
   695  \sa setTimeout()
   805     some explicit action in order to close the popup. 
       
   806     
       
   807     The default value for this property is HbPopup::StandardTimeout.
       
   808       
       
   809     \sa setTimeout(), setTimeout(HbPopup::DefaultTimeout)
   696 */
   810 */
   697 int HbPopup::timeout() const
   811 int HbPopup::timeout() const
   698 {
   812 {
   699     Q_D(const HbPopup);
   813     Q_D(const HbPopup);
   700     return d->timeout;
   814     return d->timeout;
   701 }
   815 }
   702 
   816 
   703 /*!
   817 /*!
   704  Sets the popup timeout property in milliseconds.
   818     Sets the popup's timeout property in milliseconds. A value of zero or less than zero
   705  If timeout <= 0 then the popup is permanent and not closed automatically.
   819     means that the popup is permanent and is not closed automatically.
   706  \sa timeout() setTimeout(HbPopup::DefaultTimeout) QGraphicsWidget::close()
   820     
       
   821     \overload
       
   822     \sa timeout() setTimeout(HbPopup::DefaultTimeout), QGraphicsWidget::close()
   707 */
   823 */
   708 void HbPopup::setTimeout(int timeout)
   824 void HbPopup::setTimeout(int timeout)
   709 {
   825 {
   710     Q_D(HbPopup);
   826     Q_D(HbPopup);
   711     d->setTimeout(timeout);
   827     d->setTimeout(timeout);
   712     //d->timeout = timeout;
   828     //d->timeout = timeout;
   713 }
   829 }
   714 
   830 
   715 /*!
   831 /*!
   716  It is a convenience overload of \a timeout() for setting HbPopup::DefaultTimeout values
   832     Sets the popup's timeout property to the default value for a standard popup type.
   717  to achieve common look & feel.
   833     This has the advantage of creating a common look and feel.
   718  \sa enum DefaultTimeout
   834 
   719  \sa timeout() setTimeout(int) QGraphicsWidget::close()
   835     \overload
       
   836     \sa timeout(), setTimeout(int), QGraphicsWidget::close()
   720 */
   837 */
   721 void HbPopup::setTimeout(HbPopup::DefaultTimeout timeout)
   838 void HbPopup::setTimeout(HbPopup::DefaultTimeout timeout)
   722 {
   839 {
   723     setTimeout(HbPopupPrivate::timeoutValue(timeout));
   840     setTimeout(HbPopupPrivate::timeoutValue(timeout));
   724 }
   841 }
   725 
   842 
   726 /*!
   843 /*!
   727  Returns the popup modality property.
   844     Returns the popup's modality property. A modal popup blocks any user-initiated
   728  A modal popup blocks any user initiated events outside of the popup
   845     events outside of the popup until it is closed.
   729  until it is closed.
   846     \sa setModal()
   730  \sa setModal()
       
   731 */
   847 */
   732 bool HbPopup::isModal() const
   848 bool HbPopup::isModal() const
   733 {
   849 {
   734     Q_D(const HbPopup);
   850     Q_D(const HbPopup);
   735     return d->modal;
   851     return d->modal;
   736 }
   852 }
   737 
   853 
   738 /*!
   854 /*!
   739  Sets the popup modality property.
   855     Sets the popup's modality property.
   740  \sa isModal()
   856     
       
   857     To open a modal popup, call open(). To open a non-modal popup, call 
       
   858     \link QGraphicsItem::show() show()\endlink.
       
   859     \sa isModal()
   741 */
   860 */
   742 void HbPopup::setModal(bool enabled)
   861 void HbPopup::setModal(bool enabled)
   743 {
   862 {
   744     Q_D(HbPopup);
   863     Q_D(HbPopup);
   745     d->modal = enabled;
   864     d->modal = enabled;
   746     d->doSetModal( d->modal );
   865     d->doSetModal( d->modal );
   747 }
   866 }
   748 
   867 
   749 /*!
   868 /*!
   750  Sets the background of popup faded if \a fadeBackground is true otherwise
   869     Sets the popup's background fade policy property. When this is set to true, it causes
   751  the background will not be faded.
   870     everything behind the popup to be faded. 
   752  \sa isBackgroundFaded()
   871     \sa isBackgroundFaded()
   753 */
   872 */
   754 void HbPopup::setBackgroundFaded(bool fadeBackground)
   873 void HbPopup::setBackgroundFaded(bool fadeBackground)
   755 {
   874 {
   756     Q_D(HbPopup);
   875     Q_D(HbPopup);
   757     d->fadeBackground = fadeBackground;
   876     d->fadeBackground = fadeBackground;
   758 }
   877 }
   759 
   878 
   760 /*!
   879 /*!
   761  Returns if the background of the popup is faded or not.
   880     Returns the popup's background fade policy property. This controls whether 
   762  Default: true
   881     everything behind the popup is faded while the popup is on the screen. Typically
   763  \sa isBackgroundFaded()
   882     this property is set to true for modal dialogs only. The default is true.
       
   883     \sa setBackgroundFaded()
   764 */
   884 */
   765 bool HbPopup::isBackgroundFaded() const
   885 bool HbPopup::isBackgroundFaded() const
   766 {
   886 {
   767     Q_D(const HbPopup);
   887     Q_D(const HbPopup);
   768     return d->backgroundItem && d->fadeBackground;
   888     return d->backgroundItem && d->fadeBackground;
   769 }
   889 }
   770 
   890 
   771 /*!
   891 /*!
   772  Returns the dismiss policy of the popup.
   892     Returns the popup's dismiss policy. This defines which user actions (if any) cause 
   773  Default is HbPopup::TapOutside.
   893     the popup to close. The default is HbPopup::TapOutside.
   774  \sa setDismissPolicy()
   894     \sa setDismissPolicy()
   775 */
   895 */
   776 HbPopup::DismissPolicy HbPopup::dismissPolicy() const
   896 HbPopup::DismissPolicy HbPopup::dismissPolicy() const
   777 {
   897 {
   778     Q_D(const HbPopup);
   898     Q_D(const HbPopup);
   779     return d->dismissPolicy;
   899     return d->dismissPolicy;
   780 }
   900 }
   781 
   901 
   782 /*!
   902 /*!
   783  Sets the dismiss policy property for the the popup.
   903     Sets the popup's dismiss policy property.
   784 
   904 
   785  \sa dismissPolicy()
   905     \sa dismissPolicy()
   786 */
   906 */
   787 void HbPopup::setDismissPolicy(HbPopup::DismissPolicy dismissPolicy)
   907 void HbPopup::setDismissPolicy(HbPopup::DismissPolicy dismissPolicy)
   788 {
   908 {
   789     Q_D(HbPopup);
   909     Q_D(HbPopup);
   790     d->dismissPolicy = dismissPolicy;
   910     d->dismissPolicy = dismissPolicy;
   791 }
   911 }
   792 
   912 
   793 /*!
   913 /*!
   794  Returns the frame type of the popup.
   914     Returns the popup's frame type. This controls the popup's background style. However, 
   795  Default is HbPopup::Strong
   915     the actual appearance depends on the theme. The default value is HbPopup::Strong.
   796  \sa setFrameType()
   916     
       
   917     \sa setFrameType()
   797 */
   918 */
   798 HbPopup::FrameType HbPopup::frameType() const
   919 HbPopup::FrameType HbPopup::frameType() const
   799 {
   920 {
   800     Q_D(const HbPopup);
   921     Q_D(const HbPopup);
   801     return d->frameType;
   922     return d->frameType;
   802 }
   923 }
   803 
   924 
   804 /*!
   925 /*!
   805  Sets the frame typeproperty for the the popup.
   926     Sets the popup's frame type, which controls the popup's background style.
   806 
   927 
   807  \sa frameType()
   928     \sa frameType()
   808 */
   929 */
   809 void HbPopup::setFrameType(HbPopup::FrameType frameType)
   930 void HbPopup::setFrameType(HbPopup::FrameType frameType)
   810 {
   931 {
   811     Q_D(HbPopup);
   932     Q_D(HbPopup);
   812     if ( d->frameType != frameType ) {
   933     if ( d->frameType != frameType ) {
   813         switch( frameType ) {
   934         switch( frameType ) {
   814         case HbPopup::Weak:
   935         case HbPopup::Weak:
   815             d->setBackgroundItem(HbStyle::P_Popup_background_weak);
   936             d->setBackgroundItem(HbStylePrivate::P_Popup_background_weak);
   816             break;
   937             break;
   817         case HbPopup::Strong:
   938         case HbPopup::Strong:
   818         default:
   939         default:
   819             d->setBackgroundItem(HbStyle::P_Popup_background);
   940             d->setBackgroundItem(HbStylePrivate::P_Popup_background);
   820             break;
   941             break;
   821         }
   942         }
   822         d->frameType = frameType;
   943         d->frameType = frameType;
   823         updatePrimitives();
   944         updatePrimitives();
   824     }
   945     }
   825 }
   946 }
   826 
   947 
   827 
   948 
   828 /*!
   949 /*!
   829  Shows the popup as modal popup returning immediately.  
   950     Displays the popup on the screen and returns immediately. This function also 
   830 
   951     connects the popup's aboutToClose() signal to a specified slot. The signal 
   831  Connects aboutToClose() signal to the slot specified by \a receiver and
   952     is disconnected from the slot when the popup closes.
   832  \a member. The signal will be disconnected from the slot when the
   953     
   833  popup is closed.
   954     Use this function to open modal popups. To open non-modal popups, call 
   834 
   955     \link QGraphicsItem::show() show()\endlink.  
   835  For non modal popups, use show().  
   956 
       
   957     \param receiver  The object that is to receive the signal.  
       
   958     \param member  The slot on the receiver to which the signal is to connect. 
       
   959     
       
   960     \sa isModal() 
   836 */
   961 */
   837 void HbPopup::open( QObject *receiver, const char *member )
   962 void HbPopup::open( QObject *receiver, const char *member )
   838 {
   963 {
   839     Q_D(HbPopup);
   964     Q_D(HbPopup);
   840     if (receiver) {
   965     if (receiver) {
   845 
   970 
   846     show();
   971     show();
   847 }
   972 }
   848 
   973 
   849 /*!
   974 /*!
   850     \reimp
   975     
   851  */
   976  */
   852 QVariant HbPopup::itemChange ( GraphicsItemChange change, const QVariant & value )
   977 QVariant HbPopup::itemChange ( GraphicsItemChange change, const QVariant & value )
   853 {
   978 {
   854     Q_D(HbPopup);
   979     Q_D(HbPopup);
   855 
   980 
   856     if (change == QGraphicsItem::ItemPositionChange) {
   981     if (change == QGraphicsItem::ItemPositionChange) {
   857         d->mAutoLayouting = false;
   982         d->mAutoLayouting = false;
   858     }
   983     }
   859     if (change == QGraphicsItem::ItemVisibleHasChanged) {
   984     if (change == QGraphicsItem::ItemVisibleHasChanged) {
   860         if (value.toBool()) {
   985         if (value.toBool()) {
   861             if(d->hasEffects && boundingRect().isValid()) {
   986             if (d->hasEffects && boundingRect().isValid() && d->polished) {
   862 
   987 
   863 #ifdef HB_EFFECTS
   988 #ifdef HB_EFFECTS
   864                 QRectF extRect(0.0,
   989                 QRectF extRect(0.0,
   865                                -boundingRect().height(),
   990                                -boundingRect().height(),
   866                                boundingRect().width(),
   991                                boundingRect().width(),
   867                                0);
   992                                0);
   868                 d->mStartEffect = true;
       
   869                 HbEffect::cancel(this);
   993                 HbEffect::cancel(this);
   870                 d->mStartEffect = false;
   994                 d->mStartEffect = false;
   871                 HbEffect::start(this, d->effectType, "appear", this, "_q_appearEffectEnded", QVariant(), extRect);
   995                 HbEffectInternal::start(this, this, HbEffectInternal::UpdateAtEachStep,
   872 #endif//HB_EFFECTS
   996                                         d->effectType, "appear", this, "_q_appearEffectEnded",
   873             } else {
   997                                         QVariant(), extRect);
   874                 d->mStartEffect = true;
   998 #endif //HB_EFFECTS
   875             }
   999             }
   876         }
  1000         }
   877     }
  1001     }
   878 
  1002 
   879     if (change == QGraphicsItem::ItemVisibleChange) {
  1003     if (change == QGraphicsItem::ItemVisibleChange) {
   891         } else {
  1015         } else {
   892             d->aboutToShowSignalGuard = false;
  1016             d->aboutToShowSignalGuard = false;
   893             if (!d->hidingInProgress) {
  1017             if (!d->hidingInProgress) {
   894                 emit aboutToHide();
  1018                 emit aboutToHide();
   895             }
  1019             }
   896 
       
   897             if (d->delayedHide &&  // about to hide and we wanna delay hiding
  1020             if (d->delayedHide &&  // about to hide and we wanna delay hiding
   898                 d->hasEffects && !parentItem()) { // only for popup without parent
  1021                 d->hasEffects && !parentItem()) { // only for popup without parent
   899                 bool hideDelayed = d->delayedHide;
  1022                 bool hideDelayed = d->delayedHide;
   900                 if (!d->hidingInProgress) { // Prevent reentrance
  1023                 if (!d->hidingInProgress) { // Prevent reentrance
   901                     d->hidingInProgress = true;
  1024                     d->hidingInProgress = true;
   903                     QRectF extRect(0.0,
  1026                     QRectF extRect(0.0,
   904                                    -boundingRect().height(),
  1027                                    -boundingRect().height(),
   905                                    boundingRect().width(),
  1028                                    boundingRect().width(),
   906                                    0);
  1029                                    0);
   907                     HbEffect::cancel(this);
  1030                     HbEffect::cancel(this);
   908                     if (!HbEffect::start(this, d->effectType, "disappear",
  1031                     if (!HbEffectInternal::start(this, this, HbEffectInternal::UpdateAtEachStep,
   909                                          this, "_q_delayedHide",
  1032                                                  d->effectType, "disappear",
   910                                          QVariant(), extRect)) {
  1033                                                  this, "_q_delayedHide",
       
  1034                                                  QVariant(), extRect)) {
   911                         d->delayedHide = false;
  1035                         d->delayedHide = false;
   912                         return HbWidget::itemChange(change, value);
  1036                         return HbWidget::itemChange(change, value);
   913                     }
  1037                     }
       
  1038                     d->mGestureOverride = true;
   914 #endif
  1039 #endif
   915                 }
  1040                 }
   916                 if (hideDelayed) {
  1041                 if (hideDelayed) {
   917                     return true;
  1042                     return true;
   918                 } else {
  1043                 } else {
   936     }
  1061     }
   937     return HbWidget::itemChange(change, value);
  1062     return HbWidget::itemChange(change, value);
   938 }
  1063 }
   939 
  1064 
   940 /*!
  1065 /*!
   941  \deprecated HbPopup::handlePopupPos()
  1066     Reimplemented from QGraphicsItem.
   942          is deprecated. This function should not be used from the application side.
       
   943  Handles the popup position when Orientation changes
       
   944 */
       
   945 void HbPopup::handlePopupPos()
       
   946 {
       
   947     HB_DEPRECATED("HbPopup::handlePopupPos() is deprecated.");
       
   948     QEvent userEvent(QEvent::ContextMenu);
       
   949     QCoreApplication::sendEvent(this, &userEvent);    
       
   950 }
       
   951 
       
   952 /*!
       
   953     \reimp
       
   954  */
  1067  */
   955 void HbPopup::mousePressEvent(QGraphicsSceneMouseEvent *event )
  1068 void HbPopup::mousePressEvent(QGraphicsSceneMouseEvent *event )
   956 {
  1069 {
   957     Q_D(HbPopup);
  1070     Q_D(HbPopup);
   958 
  1071 
   970     // to ignored
  1083     // to ignored
   971     event->accept();
  1084     event->accept();
   972 }
  1085 }
   973 
  1086 
   974 /*!
  1087 /*!
   975     \reimp
  1088     Reimplemented from QGraphicsItem.
   976  */
  1089  */
   977 void HbPopup::mouseReleaseEvent(QGraphicsSceneMouseEvent *event )
  1090 void HbPopup::mouseReleaseEvent(QGraphicsSceneMouseEvent *event )
   978 {
  1091 {
   979     QGraphicsItem::mouseReleaseEvent(event);        
  1092     QGraphicsItem::mouseReleaseEvent(event);        
   980     event->accept();
  1093     event->accept();
   981     // Note: Mouse release event is always handled in handleBackgroundMouseReleaseEvent
  1094     // Note: Mouse release event is always handled in handleBackgroundMouseReleaseEvent
   982 }
  1095 }
   983 
  1096 
   984 /*!
  1097 /*!
   985     \reimp
  1098     Reimplemented from QGraphicsWidget. 
   986  */
  1099  */
   987 //
  1100 //
   988 // Shows the popup with an animation and starts the timer to dismiss the popup,
  1101 // Shows the popup with an animation and starts the timer to dismiss the popup,
   989 // unless it is a permanent popup.
  1102 // unless it is a permanent popup.
   990 //
  1103 //
  1009         //check if popup needs to be added to scene.This can result in duplciate show event,
  1122         //check if popup needs to be added to scene.This can result in duplciate show event,
  1010         // if popup is added to scene here.
  1123         // if popup is added to scene here.
  1011         if(d->addPopupToScene()) {
  1124         if(d->addPopupToScene()) {
  1012               d->duplicateShowEvent = true;
  1125               d->duplicateShowEvent = true;
  1013         }
  1126         }
  1014         //setActive(true);
  1127         if (d->mActivePopup) {
       
  1128             setActive(true);
       
  1129         }
  1015         // Popup clears closed state
  1130         // Popup clears closed state
  1016         d->closed = false;
  1131         d->closed = false;
  1017         if (d->backgroundItem) {
  1132         if (d->backgroundItem) {
  1018             d->backgroundItem->setVisible(true);
  1133             d->backgroundItem->setVisible(true);
  1019             d->backgroundItem->setAcceptHoverEvents(isModal());
       
  1020             if (isModal()) {
  1134             if (isModal()) {
  1021                 d->backgroundItem->setFlag(QGraphicsItem::ItemIsPanel);
  1135                 d->backgroundItem->setFlag(QGraphicsItem::ItemIsPanel);
  1022              }
  1136              }
  1023         }
  1137         }
  1024         if (qobject_cast<HbGraphicsScene *>(scene())) {
  1138         if (qobject_cast<HbGraphicsScene *>(scene())) {
  1041         }
  1155         }
  1042     }
  1156     }
  1043 }
  1157 }
  1044 
  1158 
  1045 /*!
  1159 /*!
  1046     \reimp
  1160     Reimplemented from QGraphicsWidget. 
  1047  */
  1161  */
  1048 void HbPopup::hideEvent(QHideEvent *event)
  1162 void HbPopup::hideEvent(QHideEvent *event)
  1049 {
  1163 {
  1050     Q_D(HbPopup);
  1164     Q_D(HbPopup);
  1051 
  1165 
  1063     if (d->eventLoop) {
  1177     if (d->eventLoop) {
  1064         d->eventLoop->exit();
  1178         d->eventLoop->exit();
  1065     }
  1179     }
  1066 
  1180 
  1067     d->doSetModal( d->modal );
  1181     d->doSetModal( d->modal );
  1068 
  1182     if (d->mActivePopup) {
  1069 }
  1183         setActive(false);
  1070 
  1184     }
  1071 /*!
  1185 }
  1072     \reimp
  1186 
       
  1187 /*!
       
  1188     Reimplemented from QGraphicsWidget. 
  1073  */
  1189  */
  1074 void HbPopup::resizeEvent( QGraphicsSceneResizeEvent * event )
  1190 void HbPopup::resizeEvent( QGraphicsSceneResizeEvent * event )
  1075 {    
  1191 {    
  1076     HbWidget::resizeEvent(event);
  1192     HbWidget::resizeEvent(event);
  1077     updatePrimitives();
  1193     updatePrimitives();
  1080         d->calculateShape();
  1196         d->calculateShape();
  1081     }
  1197     }
  1082 }
  1198 }
  1083 
  1199 
  1084 /*!
  1200 /*!
  1085     \reimp
  1201     Reimplemented from QGraphicsWidget. 
  1086  */
  1202  */
  1087 void HbPopup::closeEvent ( QCloseEvent * event )
  1203 void HbPopup::closeEvent ( QCloseEvent * event )
  1088 {
  1204 {
  1089     Q_D(HbPopup);
  1205     Q_D(HbPopup);
  1090     d->stopTimeout();
  1206     d->stopTimeout();
  1110     d->memberToDisconnectOnClose.clear();
  1226     d->memberToDisconnectOnClose.clear();
  1111     HbWidget::closeEvent(event);
  1227     HbWidget::closeEvent(event);
  1112 }
  1228 }
  1113 
  1229 
  1114 
  1230 
  1115 /* Currently, virtual keyboard must be able to position a popup
  1231 /*
  1116    containing a editor to an arbitrary place. VKB does it's best to
  1232    Currently, virtual keyboard must be able to position a popup
  1117    reposition popup back to original position when needed. At least in
  1233    containing an editor to an arbitrary place. VKB does its best to
       
  1234    reposition the popup back to original position when needed. At least in
  1118    orientation switch the old position naturally is wrong, hence popup
  1235    orientation switch the old position naturally is wrong, hence popup
  1119    must be relayouted.
  1236    must be relayouted.
  1120 
  1237 
  1121    It would be unreasonable to make special checks for popup in vkb
  1238    It would be unreasonable to make special checks for popup in vkb
  1122    side. It also would be unreasonable to do special checks for vkb in
  1239    side. It also would be unreasonable to do special checks for vkb in
  1128    raise a feature request and we might make this a proper API.
  1245    raise a feature request and we might make this a proper API.
  1129  */
  1246  */
  1130 const char* KPositionManagedByVKB("PositionManagedByVKB");
  1247 const char* KPositionManagedByVKB("PositionManagedByVKB");
  1131 
  1248 
  1132 /*!
  1249 /*!
  1133     \reimp
  1250     Reimplemented from QGraphicsWidget. 
  1134  */
  1251  */
  1135 bool HbPopup::event(QEvent *event)
  1252 bool HbPopup::event(QEvent *event)
  1136 {
  1253 {
  1137     Q_D(HbPopup);
  1254     Q_D(HbPopup);
  1138     if ( event->type() == QEvent::DynamicPropertyChange ) {
  1255     if ( event->type() == QEvent::DynamicPropertyChange ) {
  1152             }
  1269             }
  1153         }
  1270         }
  1154     } else if (event->type() == QEvent::LayoutRequest) {
  1271     } else if (event->type() == QEvent::LayoutRequest) {
  1155         //Workaround when showing first time                           
  1272         //Workaround when showing first time                           
  1156 #ifdef HB_EFFECTS
  1273 #ifdef HB_EFFECTS
  1157         if(d->mStartEffect && boundingRect().isValid()) {
  1274         if (d->mStartEffect && boundingRect().isValid()) {
  1158             d->mStartEffect = false;
  1275             d->mStartEffect = false;
  1159             QCoreApplication::sendPostedEvents(this, QEvent::LayoutRequest);
  1276             QCoreApplication::sendPostedEvents(this, QEvent::LayoutRequest);
  1160             QRectF extRect(0.0,
  1277             QRectF extRect(0.0,
  1161                            -boundingRect().height(),
  1278                            -boundingRect().height(),
  1162                            boundingRect().width(),
  1279                            boundingRect().width(),
  1163                            0);
  1280                            0);
  1164             d->mStartEffect = true;
       
  1165             HbEffect::cancel(this);
  1281             HbEffect::cancel(this);
  1166             d->mStartEffect = false;
  1282             HbEffectInternal::start(this, this, HbEffectInternal::UpdateAtEachStep,
  1167             HbEffect::start(this, d->effectType, "appear", this, "_q_appearEffectEnded", QVariant(), extRect);            
  1283                                     d->effectType, "appear", this, "_q_appearEffectEnded",
  1168         }
  1284                                     QVariant(), extRect);
  1169 #endif//HB_EFFECTS
  1285         } else if (d->mStartEffect) {
       
  1286             // Workaround for submenus that do not have any effect when shown
       
  1287             // first. The appear/disappear effect would call update() a number
       
  1288             // of times but in this case we have to do it manually.
       
  1289             new HbPopupUpdater(this, this);
       
  1290         }
       
  1291 #endif //HB_EFFECTS
  1170         //workaround ends
  1292         //workaround ends
  1171     }
  1293     } else if (d->mGestureOverride && event->type() == QEvent::GestureOverride) {
       
  1294         event->accept();
       
  1295         return true;
       
  1296     }
       
  1297 
  1172     return HbWidget::event(event);
  1298     return HbWidget::event(event);
  1173 }
  1299 }
  1174 
  1300 
  1175 /*!
  1301 /*!
  1176   Sets preferred position\a position for popup with \a placement
  1302     Sets the preferred position of the popup. By default, the popup is placed in the middle
  1177   as origin.
  1303     of the screen. If you use this function to set the preferred position, it is your 
  1178 
  1304     responsibility to ensure that this position works correctly on devices with different 
  1179   By default popup is placed in the middle of the screen. If other positions are needed please
  1305     screen sizes.
  1180   ensure that the preferred position is working properly with different screen sizes.
  1306   
  1181 
  1307     Typically you should set the preferred position only for context aware popups, such as 
  1182   \param position is the position at which the popup is shown.
  1308     context menus and slider popups. The position is not relevant for most dialogs and
  1183   \param placement is the corner or edge which \a position refers to
  1309     popups and you should use the default position for these.
  1184 
  1310 
  1185   Example usage:
  1311     \param preferredPos Defines the coordinates of preferred position on the screen where 
  1186   \code
  1312            the popup is to open.
  1187   HbPopup *popup = new HbPopup();
  1313     \param placement The corner or edge of the dialog that is to be placed at \a preferredPos.
  1188   ...
  1314 
  1189   popup->setPreferredPosition( QPointF(x,y), HbPopupBase::BottomEdgeCenter );
  1315     \b Example:
  1190   popup->show();
  1316     \code
  1191   \endcode
  1317     HbPopup *popup = new HbPopup();
       
  1318   
       
  1319     popup->setPreferredPos( QPointF(x,y), HbPopup::BottomEdgeCenter );
       
  1320     popup->show();
       
  1321     \endcode
  1192  */
  1322  */
  1193 void HbPopup::setPreferredPos( const QPointF& preferredPos,
  1323 void HbPopup::setPreferredPos( const QPointF& preferredPos,
  1194                                HbPopup::Placement placement )
  1324                                HbPopup::Placement placement )
  1195 {
  1325 {
  1196     Q_D(HbPopup);
  1326     Q_D(HbPopup);
  1210         QApplication::sendEvent(this, &layoutRequest);
  1340         QApplication::sendEvent(this, &layoutRequest);
  1211     }
  1341     }
  1212 }
  1342 }
  1213 
  1343 
  1214 /*!
  1344 /*!
  1215   \reimp
  1345      Returns the shape of this item as a QPainterPath.
  1216   Returns the shape of this item as a QPainterPath.
  1346  */
  1217   */
       
  1218 QPainterPath HbPopup::shape() const
  1347 QPainterPath HbPopup::shape() const
  1219 {    
  1348 {    
  1220 #if 0
  1349 #if 0
  1221    /*Q_D(const HbPopup);
  1350    /*Q_D(const HbPopup);
  1222     if (backgroundItem() && d->mPath) {
  1351     if (backgroundItem() && d->mPath) {
  1227 #else
  1356 #else
  1228     return HbWidget::shape();
  1357     return HbWidget::shape();
  1229 #endif
  1358 #endif
  1230 }
  1359 }
  1231 
  1360 
       
  1361 /*!
       
  1362     Reimplemented from HbWidget.
       
  1363  */
       
  1364 void HbPopup::polish(HbStyleParameters &params)
       
  1365 {
       
  1366     HbWidget::polish(params);
       
  1367 }
       
  1368 
  1232 #include "moc_hbpopup.cpp"
  1369 #include "moc_hbpopup.cpp"