src/hbcore/gui/hbpopup.cpp
changeset 5 627c4a0fd0e7
parent 2 06ff229162e9
child 6 c3690ec91ef8
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
   279     mousePressLocation(None),
   279     mousePressLocation(None),
   280     frameType(HbPopup::Strong),
   280     frameType(HbPopup::Strong),
   281     preferredPosSet(false),
   281     preferredPosSet(false),
   282     mStartEffect(false),
   282     mStartEffect(false),
   283     mScreenMargin(0.0),
   283     mScreenMargin(0.0),
       
   284     mAutoLayouting(true),
   284     mVgMaskEffect(0),
   285     mVgMaskEffect(0),
       
   286     mOrientationEffectHide(false),
   285     timeoutTimerInstance(0)
   287     timeoutTimerInstance(0)
   286 {
   288 {
   287 }
   289 }
   288 
   290 
   289 HbPopupPrivate::~HbPopupPrivate()
   291 HbPopupPrivate::~HbPopupPrivate()
   356         q->deleteLater();
   358         q->deleteLater();
   357     }
   359     }
   358     hidingInProgress = false;
   360     hidingInProgress = false;
   359 }
   361 }
   360 
   362 
   361 void HbPopupPrivate::_q_orientationChange(Qt::Orientation orient, bool animate)
   363 void HbPopupPrivate::_q_orientationAboutToChange(Qt::Orientation orient, bool animate)
   362 {
   364 {
   363     Q_UNUSED(orient);
   365     Q_UNUSED(orient);    
   364     if (animate) {
       
   365     Q_Q(HbPopup);
   366     Q_Q(HbPopup);
   366     HbEffect::start(q, "HB_POPUP", "orientationswitch");
   367     if (animate && q->isVisible()) {
   367     }
   368         HbEffect::start(q, "HB_POPUP", "orient_disappear");
   368 
   369         mOrientationEffectHide = true;
   369 }
   370     }
       
   371 }
       
   372 
   370 #endif // HB_EFFECTS
   373 #endif // HB_EFFECTS
       
   374 
       
   375 void HbPopupPrivate::_q_orientationChanged()
       
   376 {
       
   377     Q_Q(HbPopup);
       
   378     if (q->isVisible()) {
       
   379         QEvent userEvent(QEvent::ContextMenu);
       
   380         QCoreApplication::sendEvent(q, &userEvent);
       
   381     }
       
   382 #ifdef HB_EFFECTS
       
   383     if (mOrientationEffectHide) {
       
   384         HbEffect::cancel(q);
       
   385         HbEffect::start(q, "HB_POPUP", "orient_appear");
       
   386         mOrientationEffectHide = false;
       
   387     }
       
   388 #endif
       
   389 }
   371 
   390 
   372 void HbPopupPrivate::_q_timeoutFinished()
   391 void HbPopupPrivate::_q_timeoutFinished()
   373 {
   392 {
   374     Q_Q(HbPopup);
   393     Q_Q(HbPopup);
   375     timedOut = true;
   394     timedOut = true;
   512                                            "popup_disappear",
   531                                            "popup_disappear",
   513                                            "disappear");
   532                                            "disappear");
   514     }
   533     }
   515     if (hasEffects ) {
   534     if (hasEffects ) {
   516         hasEffects = HbEffectInternal::add("HB_POPUP",
   535         hasEffects = HbEffectInternal::add("HB_POPUP",
   517                                            "dialog_rotate",
   536                                            "popup_orient_disappear",
   518                                            "orientationswitch");
   537                                            "orient_disappear");
       
   538     }
       
   539     if (hasEffects ) {
       
   540         hasEffects = HbEffectInternal::add("HB_POPUP",
       
   541                                            "popup_orient_appear",
       
   542                                            "orient_appear");
   519     }
   543     }
   520 #endif
   544 #endif
   521 }
   545 }
   522 
   546 
   523 
   547 
   790  */
   814  */
   791 QVariant HbPopup::itemChange ( GraphicsItemChange change, const QVariant & value )
   815 QVariant HbPopup::itemChange ( GraphicsItemChange change, const QVariant & value )
   792 {
   816 {
   793     Q_D(HbPopup);
   817     Q_D(HbPopup);
   794 
   818 
   795     /*if (change == QGraphicsItem::ItemVisibleHasChanged) {
   819     if (change == QGraphicsItem::ItemPositionChange) {
       
   820         d->mAutoLayouting = false;
       
   821     }
       
   822     if (change == QGraphicsItem::ItemVisibleHasChanged) {
   796         if (value.toBool()) {
   823         if (value.toBool()) {
   797             if(d->hasEffects && boundingRect().isValid()) {
   824             if(d->hasEffects && boundingRect().isValid()) {
   798 
   825 
   799 #ifdef HB_EFFECTS
   826 #ifdef HB_EFFECTS
   800                 QRectF extRect(0.0,
   827                 QRectF extRect(0.0,
   801                                -boundingRect().height(),
   828                                -boundingRect().height(),
   802                                boundingRect().width(),
   829                                boundingRect().width(),
   803                                0);
   830                                0);
       
   831                 HbEffect::cancel(this);
   804                 HbEffect::start(this, d->effectType, "appear", 0, 0, QVariant(), extRect);
   832                 HbEffect::start(this, d->effectType, "appear", 0, 0, QVariant(), extRect);
   805 #endif//HB_EFFECTS
   833 #endif//HB_EFFECTS
   806                 d->mStartEffect = false;
   834                 d->mStartEffect = false;
   807             } else {
   835             } else {
   808                 d->mStartEffect = true;
   836                 d->mStartEffect = true;
   809             }
   837             }
   810         }
   838         }
   811     }*/
   839     }
   812 
   840 
   813     if (change == QGraphicsItem::ItemVisibleChange) {
   841     if (change == QGraphicsItem::ItemVisibleChange) {
   814         if (value.toBool()) {
   842         if (value.toBool()) {
   815             if(!d->hasEffects){
   843             if(!d->hasEffects){
   816                 d->addPopupEffects();
   844                 d->addPopupEffects();
   835 #ifdef HB_EFFECTS
   863 #ifdef HB_EFFECTS
   836                     QRectF extRect(0.0,
   864                     QRectF extRect(0.0,
   837                                    -boundingRect().height(),
   865                                    -boundingRect().height(),
   838                                    boundingRect().width(),
   866                                    boundingRect().width(),
   839                                    0);
   867                                    0);
       
   868                     HbEffect::cancel(this);
   840                     if (!HbEffect::start(this, d->effectType, "disappear",
   869                     if (!HbEffect::start(this, d->effectType, "disappear",
   841                                          this, "_q_delayedHide",
   870                                          this, "_q_delayedHide",
   842                                          QVariant(), extRect)) {
   871                                          QVariant(), extRect)) {
   843                         d->delayedHide = false;
   872                         d->delayedHide = false;
   844                     }
   873                     }
   854             }
   883             }
   855         }
   884         }
   856     } else if (change == QGraphicsItem::ItemSceneHasChanged) {
   885     } else if (change == QGraphicsItem::ItemSceneHasChanged) {
   857         HbMainWindow* w(mainWindow());
   886         HbMainWindow* w(mainWindow());
   858         if ( w ){
   887         if ( w ){
       
   888             disconnect(this, SLOT(_q_orientationAboutToChange(Qt::Orientation, bool)));
       
   889             connect( w, SIGNAL(aboutToChangeOrientation(Qt::Orientation, bool)),
       
   890                      this, SLOT(_q_orientationAboutToChange(Qt::Orientation, bool)) );
   859             disconnect(this, SLOT(handlePopupPos()));
   891             disconnect(this, SLOT(handlePopupPos()));
   860             connect( w, SIGNAL(orientationChanged(Qt::Orientation)),
   892             connect( w, SIGNAL(orientationChanged(Qt::Orientation)),
   861                      this, SLOT(handlePopupPos()) );
   893                      this, SLOT(_q_orientationChanged()) );
   862         }
   894         }
   863     }
   895     }
   864     return HbWidget::itemChange(change, value);
   896     return HbWidget::itemChange(change, value);
   865 }
   897 }
   866 
   898 
   867 /*!
   899 /*!
   868  Handles the popup position when Orientation changes
   900  Handles the popup position when Orientation changes
   869 */
   901 */
   870 void HbPopup::handlePopupPos()
   902 void HbPopup::handlePopupPos()
   871 {
   903 {
       
   904     //Not used inside hbpopup, deprecate this(?)
   872     QEvent userEvent(QEvent::ContextMenu);
   905     QEvent userEvent(QEvent::ContextMenu);
   873     QCoreApplication::sendEvent(this, &userEvent);
   906     QCoreApplication::sendEvent(this, &userEvent);    
   874 }
   907 }
   875 
   908 
   876 /*!
   909 /*!
   877     \reimp
   910     \reimp
   878  */
   911  */
  1039 /*!
  1072 /*!
  1040     \reimp
  1073     \reimp
  1041  */
  1074  */
  1042 bool HbPopup::event(QEvent *event)
  1075 bool HbPopup::event(QEvent *event)
  1043 {
  1076 {
  1044 /*    Q_D(HbPopup);
  1077     Q_D(HbPopup);
  1045     if (event->type() == QEvent::LayoutRequest) {
  1078     if (event->type() == QEvent::LayoutRequest) {
  1046         //Workaround when showing first time                           
  1079         //Workaround when showing first time                           
  1047 #ifdef HB_EFFECTS
  1080 #ifdef HB_EFFECTS
  1048         if(d->mStartEffect && boundingRect().isValid()) {
  1081         if(d->mStartEffect && boundingRect().isValid()) {
  1049             d->mStartEffect = false;
  1082             d->mStartEffect = false;
  1050             QCoreApplication::sendPostedEvents(this, QEvent::LayoutRequest);
  1083             QCoreApplication::sendPostedEvents(this, QEvent::LayoutRequest);
  1051             QRectF extRect(0.0,
  1084             QRectF extRect(0.0,
  1052                            -boundingRect().height(),
  1085                            -boundingRect().height(),
  1053                            boundingRect().width(),
  1086                            boundingRect().width(),
  1054                            0);
  1087                            0);
       
  1088             HbEffect::cancel(this);
  1055             HbEffect::start(this, d->effectType, "appear", 0, 0, QVariant(), extRect);            
  1089             HbEffect::start(this, d->effectType, "appear", 0, 0, QVariant(), extRect);            
  1056             qDebug() << "effect start";
       
  1057         }
  1090         }
  1058 #endif//HB_EFFECTS
  1091 #endif//HB_EFFECTS
  1059         //workaround ends
  1092         //workaround ends
  1060     }
  1093     }    
  1061     qDebug() << "event: " << event;*/
       
  1062     /*Q_D(HbPopup);
       
  1063     if (event->type() == QEvent::LayoutDirectionChange) {
       
  1064         d->calculateShape();
       
  1065     }*/
       
  1066     return HbWidget::event(event);
  1094     return HbWidget::event(event);
  1067 }
  1095 }
  1068 
  1096 
  1069 /*!
  1097 /*!
  1070   Sets preferred position\a position for popup with \a placement
  1098   Sets preferred position\a position for popup with \a placement
  1071   as origin.
  1099   as origin.
  1072 
  1100 
       
  1101   By default popup is placed in the middle of the screen. If other positions are needed please
       
  1102   ensure that the preferred position is working properly with different screen sizes.
       
  1103 
  1073   \param position is the position at which the popup is shown.
  1104   \param position is the position at which the popup is shown.
  1074   \param placement is the corner or edge which \a position refers to
  1105   \param placement is the corner or edge which \a position refers to
  1075 
  1106 
  1076   Example usage:
  1107   Example usage:
  1077   \code
  1108   \code
  1078   HbDialog popup;
  1109   HbPopup *popup = new HbPopup();
  1079   ...
  1110   ...
  1080   popup.setPreferredPosition( QPointF(x,y), HbPopupBase::BottomEdgeCenter );
  1111   popup->setPreferredPosition( QPointF(x,y), HbPopupBase::BottomEdgeCenter );
  1081   popup.show();
  1112   popup->show();
  1082   \endcode
  1113   \endcode
  1083 
  1114 
  1084  */
  1115  */
  1085 
  1116 
  1086 void HbPopup::setPreferredPos( const QPointF& preferredPos,
  1117 void HbPopup::setPreferredPos( const QPointF& preferredPos,
  1097         layoutFlag = true;
  1128         layoutFlag = true;
  1098     }
  1129     }
  1099     d->preferredPosSet = true;
  1130     d->preferredPosSet = true;
  1100     //If position updated, informing layoutproxy with layoutrequest
  1131     //If position updated, informing layoutproxy with layoutrequest
  1101     if (layoutFlag) {
  1132     if (layoutFlag) {
  1102         QApplication::sendEvent(this, new QEvent(QEvent::LayoutRequest));
  1133         QEvent layoutRequest = QEvent::LayoutRequest;
       
  1134         QApplication::sendEvent(this, &layoutRequest);
  1103     }
  1135     }
  1104 }
  1136 }
  1105 
  1137 
  1106 QPainterPath HbPopup::shape() const
  1138 QPainterPath HbPopup::shape() const
  1107 {    
  1139 {