src/hbcore/gui/hbpopup.cpp
changeset 28 b7da29130b0e
parent 23 e6ad4ef83b23
child 30 80e4d18b72f5
equal deleted inserted replaced
23:e6ad4ef83b23 28:b7da29130b0e
    37 #include "hbvgchainedeffect_p.h"
    37 #include "hbvgchainedeffect_p.h"
    38 #include <QTimer>
    38 #include <QTimer>
    39 #include <QGraphicsSceneMouseEvent>
    39 #include <QGraphicsSceneMouseEvent>
    40 #include <QShowEvent>
    40 #include <QShowEvent>
    41 #include <QHideEvent>
    41 #include <QHideEvent>
    42 #include <QEventLoop>
       
    43 #include <QPointer>
    42 #include <QPointer>
    44 #include <QDebug>
    43 #include <QDebug>
    45 #include <QBitmap>
    44 #include <QBitmap>
    46 #include <hbinstance_p.h>
    45 #include <hbinstance_p.h>
    47 #include <QGraphicsScene>
    46 #include <QGraphicsScene>
   358     }
   357     }
   359     return QGraphicsItem::sceneEvent(event);
   358     return QGraphicsItem::sceneEvent(event);
   360 }
   359 }
   361 
   360 
   362 HbPopupPrivate::HbPopupPrivate( ) :
   361 HbPopupPrivate::HbPopupPrivate( ) :
   363     eventLoop(0),
       
   364     hasEffects(false),
   362     hasEffects(false),
   365     closed(false),
   363     closed(false),
   366     hidingInProgress(true),
   364     hidingInProgress(true),
   367     delayedHide(false),
   365     delayedHide(false),
   368     deleteOnClose(false),
   366     deleteOnClose(false),
   413 
   411 
   414     // Only for popup without parent
   412     // Only for popup without parent
   415     if (!q->parentItem()) {
   413     if (!q->parentItem()) {
   416         backgroundItem = new HbPopupBackGround(q);
   414         backgroundItem = new HbPopupBackGround(q);
   417         backgroundItem->setVisible(false);
   415         backgroundItem->setVisible(false);
   418 
       
   419         // Popup is invisible by default (explicit show or open call is required)
   416         // Popup is invisible by default (explicit show or open call is required)
   420         q->setVisible(false);
   417         q->setVisible(false);
   421     }
   418     }
   422     hidingInProgress = false; 
   419     hidingInProgress = false; 
   423     QGraphicsItem::GraphicsItemFlags itemFlags = q->flags();
   420     QGraphicsItem::GraphicsItemFlags itemFlags = q->flags();
   424     itemFlags |= QGraphicsItem::ItemClipsToShape;
   421     itemFlags |= QGraphicsItem::ItemClipsToShape;
   425     itemFlags |= QGraphicsItem::ItemClipsChildrenToShape;
   422     itemFlags |= QGraphicsItem::ItemClipsChildrenToShape;
   426     itemFlags |= QGraphicsItem::ItemSendsGeometryChanges;
   423     itemFlags |= QGraphicsItem::ItemSendsGeometryChanges;
   427     //itemFlags |= QGraphicsItem::ItemIsPanel;
   424     itemFlags |= QGraphicsItem::ItemIsPanel;
   428     q->setFlags(itemFlags);
   425     q->setFlags(itemFlags);
   429     //q->setActive(false);
   426     q->setActive(false);
   430 }
   427 }
   431 
   428 
   432 void HbPopupPrivate::_q_appearEffectEnded(HbEffect::EffectStatus status)
   429 void HbPopupPrivate::_q_appearEffectEnded(HbEffect::EffectStatus status)
   433 {
   430 {
   434     Q_UNUSED(status);
   431     Q_UNUSED(status);
   490     Q_Q(HbPopup);
   487     Q_Q(HbPopup);
   491     if (q->isVisible() || q) {
   488     if (q->isVisible() || q) {
   492         QEvent userEvent(QEvent::ContextMenu);
   489         QEvent userEvent(QEvent::ContextMenu);
   493         QCoreApplication::sendEvent(q, &userEvent);
   490         QCoreApplication::sendEvent(q, &userEvent);
   494     }
   491     }
       
   492 
       
   493     q->repolish();
   495 #ifdef HB_EFFECTS
   494 #ifdef HB_EFFECTS
   496     if (mOrientationEffectHide) {
   495     if (mOrientationEffectHide) {
   497         HbEffect::cancel(q);
   496         HbEffect::cancel(q);
   498         HbEffect::start(q, "HB_POPUP", "orient_appear");
   497         HbEffect::start(q, "HB_POPUP", "orient_appear");
   499         mOrientationEffectHide = false;
   498         mOrientationEffectHide = false;
   777     HbGraphicsScene *hbScene = qobject_cast<HbGraphicsScene *>(scene());
   776     HbGraphicsScene *hbScene = qobject_cast<HbGraphicsScene *>(scene());
   778     if (hbScene) {
   777     if (hbScene) {
   779         hbScene->d_ptr->hidePopup(this);
   778         hbScene->d_ptr->hidePopup(this);
   780     }
   779     }
   781 
   780 
   782     if (d->eventLoop) {
       
   783         d->eventLoop->exit();
       
   784     }
       
   785     if (d->backgroundItem) {
   781     if (d->backgroundItem) {
   786         // Set backgroundItem->popup to 0 to avoid double deletion
   782         // Set backgroundItem->popup to 0 to avoid double deletion
   787         // e.g. when popup is deleted by scene before its backgroundItem
   783         // e.g. when popup is deleted by scene before its backgroundItem
   788         d->backgroundItem->popup = 0;
   784         d->backgroundItem->popup = 0;
   789 
   785 
  1009                 emit aboutToShow();
  1005                 emit aboutToShow();
  1010             }
  1006             }
  1011             // Note: when visibility changes to "visible" base class implementation needs
  1007             // Note: when visibility changes to "visible" base class implementation needs
  1012             //       to be called otherwise showEvent() is not called.
  1008             //       to be called otherwise showEvent() is not called.
  1013         } else {
  1009         } else {
       
  1010             if(isPanel() && isActive() && d->mActivePopup) {
       
  1011                 setActive(false);
       
  1012             }
  1014             d->aboutToShowSignalGuard = false;
  1013             d->aboutToShowSignalGuard = false;
  1015             if (!d->hidingInProgress) {
  1014             if (!d->hidingInProgress) {
  1016                 emit aboutToHide();
  1015                 emit aboutToHide();
  1017             }
  1016             }
  1018             if (d->delayedHide &&  // about to hide and we wanna delay hiding
  1017             if (d->delayedHide &&  // about to hide and we wanna delay hiding
  1085 /*!
  1084 /*!
  1086     Reimplemented from QGraphicsItem.
  1085     Reimplemented from QGraphicsItem.
  1087  */
  1086  */
  1088 void HbPopup::mouseReleaseEvent(QGraphicsSceneMouseEvent *event )
  1087 void HbPopup::mouseReleaseEvent(QGraphicsSceneMouseEvent *event )
  1089 {
  1088 {
  1090     QGraphicsItem::mouseReleaseEvent(event);        
  1089     Q_D(HbPopup);
       
  1090     d->handleBackgroundMouseReleaseEvent(event);
       
  1091 
       
  1092     QGraphicsItem::mouseReleaseEvent(event);
  1091     event->accept();
  1093     event->accept();
  1092     // Note: Mouse release event is always handled in handleBackgroundMouseReleaseEvent
       
  1093 }
  1094 }
  1094 
  1095 
  1095 /*!
  1096 /*!
  1096     Reimplemented from QGraphicsWidget. 
  1097     Reimplemented from QGraphicsWidget. 
  1097  */
  1098  */
  1111     //  - can have background item
  1112     //  - can have background item
  1112     //  - timeout
  1113     //  - timeout
  1113     //  - and registered to HbPopupManager
  1114     //  - and registered to HbPopupManager
  1114     //  otherwise popup is treated as normal widget
  1115     //  otherwise popup is treated as normal widget
  1115     if(d->duplicateShowEvent){
  1116     if(d->duplicateShowEvent){
  1116         d->duplicateShowEvent = false;
  1117         d->duplicateShowEvent = false;        
       
  1118         //setting popup as active panel failed in previous showEvent
       
  1119         if (d->mActivePopup) {
       
  1120             setActive(true);
       
  1121         }
  1117         return;
  1122         return;
  1118     }
  1123     }
  1119     if (!parentItem()) {
  1124     if (!parentItem()) {
  1120         //check if popup needs to be added to scene.This can result in duplciate show event,
  1125         //check if popup needs to be added to scene.This can result in duplciate show event,
  1121         // if popup is added to scene here.
  1126         // if popup is added to scene here.
  1122         if(d->addPopupToScene()) {
  1127         if(d->addPopupToScene()) {
  1123               d->duplicateShowEvent = true;
  1128               d->duplicateShowEvent = true;
  1124         }
  1129         }
  1125         /*if (d->mActivePopup) {
  1130         if (d->mActivePopup) {
  1126             setActive(true);
  1131             setActive(true);
  1127         }*/
  1132         }
  1128         // Popup clears closed state
  1133         // Popup clears closed state
  1129         d->closed = false;
  1134         d->closed = false;
  1130         if (d->backgroundItem) {
  1135         if (d->backgroundItem) {
  1131             d->backgroundItem->setVisible(true);
  1136             d->backgroundItem->setVisible(true);
  1132             if (isModal()) {
  1137             if (isModal()) {
  1170         }
  1175         }
  1171         qobject_cast<HbGraphicsScene *>(scene())->d_ptr->hidePopup(this);
  1176         qobject_cast<HbGraphicsScene *>(scene())->d_ptr->hidePopup(this);
  1172     }
  1177     }
  1173 
  1178 
  1174     HbWidgetFeedback::triggered(this, Hb::InstantPopupClosed);
  1179     HbWidgetFeedback::triggered(this, Hb::InstantPopupClosed);
  1175     if (d->eventLoop) {
       
  1176         d->eventLoop->exit();
       
  1177     }
       
  1178 
  1180 
  1179     d->doSetModal( d->modal );
  1181     d->doSetModal( d->modal );
  1180     /*if (d->mActivePopup) {
       
  1181         setActive(false);
       
  1182     }*/
       
  1183 }
  1182 }
  1184 
  1183 
  1185 /*!
  1184 /*!
  1186     Reimplemented from QGraphicsWidget. 
  1185     Reimplemented from QGraphicsWidget. 
  1187  */
  1186  */