src/hbcore/gui/hbpopup.cpp
changeset 6 c3690ec91ef8
parent 5 627c4a0fd0e7
child 7 923ff622b8b9
equal deleted inserted replaced
5:627c4a0fd0e7 6:c3690ec91ef8
   178     This signal is emitted when the popup is about to be closed i.e. when method close() is called
   178     This signal is emitted when the popup is about to be closed i.e. when method close() is called
   179     or the popup is
   179     or the popup is
   180     dismissed by the user or timeout.
   180     dismissed by the user or timeout.
   181  */
   181  */
   182 
   182 
       
   183 /*!
       
   184     \enum HbPopup::Placement
       
   185 
       
   186     Placement is the corner or edge to which position of the popup refers to.
       
   187   */
       
   188 
       
   189 /*!
       
   190     \primitives
       
   191     \primitive{background} HbFrameItem representing the popup background. The background can be weak or strong (different graphical styles) depending on popup type.
       
   192     \primitive{P_Popup_heading_frame} HbFrameItem representing the popup heading text background
       
   193   */
       
   194 
   183 static const struct { HbPopup::DefaultTimeout timeout; int value; } timeoutValues[] =
   195 static const struct { HbPopup::DefaultTimeout timeout; int value; } timeoutValues[] =
   184 {
   196 {
   185     {HbPopup::NoTimeout,0},
   197     {HbPopup::NoTimeout,0},
   186     {HbPopup::ConfirmationNoteTimeout,1500},
   198     {HbPopup::ConfirmationNoteTimeout,1500},
   187     {HbPopup::StandardTimeout,3000},
   199     {HbPopup::StandardTimeout,3000},
   280     frameType(HbPopup::Strong),
   292     frameType(HbPopup::Strong),
   281     preferredPosSet(false),
   293     preferredPosSet(false),
   282     mStartEffect(false),
   294     mStartEffect(false),
   283     mScreenMargin(0.0),
   295     mScreenMargin(0.0),
   284     mAutoLayouting(true),
   296     mAutoLayouting(true),
       
   297     mOriginalAutoLayouting(mAutoLayouting),
   285     mVgMaskEffect(0),
   298     mVgMaskEffect(0),
   286     mOrientationEffectHide(false),
   299     mOrientationEffectHide(false),
   287     timeoutTimerInstance(0)
   300     timeoutTimerInstance(0)
   288 {
   301 {
   289 }
   302 }
   298 
   311 
   299     q->setAttribute(Hb::InsidePopup);
   312     q->setAttribute(Hb::InsidePopup);
   300 
   313 
   301     // By default popups are focusable
   314     // By default popups are focusable
   302     q->setFocusPolicy(Qt::StrongFocus);    
   315     q->setFocusPolicy(Qt::StrongFocus);    
   303     q->setBackgroundItem(HbStyle::P_Popup_background);
   316     q->setBackgroundItem(HbStyle::P_Popup_background);    
   304 
   317 
   305     // Only for popup without parent
   318     // Only for popup without parent
   306     if (!q->parentItem()) {
   319     if (!q->parentItem()) {
   307         backgroundItem = new HbPopupBackGround(q);
   320         backgroundItem = new HbPopupBackGround(q);
   308         backgroundItem->setVisible(false);
   321         backgroundItem->setVisible(false);
   539     if (hasEffects ) {
   552     if (hasEffects ) {
   540         hasEffects = HbEffectInternal::add("HB_POPUP",
   553         hasEffects = HbEffectInternal::add("HB_POPUP",
   541                                            "popup_orient_appear",
   554                                            "popup_orient_appear",
   542                                            "orient_appear");
   555                                            "orient_appear");
   543     }
   556     }
       
   557     hasEffects = true; //Workaround until orient appear effects are in place
   544 #endif
   558 #endif
   545 }
   559 }
   546 
   560 
   547 
   561 
   548 void HbPopupPrivate::doSetModal( bool modal ) {
   562 void HbPopupPrivate::doSetModal( bool modal ) {
   856                 emit aboutToHide();
   870                 emit aboutToHide();
   857             }
   871             }
   858 
   872 
   859             if (d->delayedHide &&  // about to hide and we wanna delay hiding
   873             if (d->delayedHide &&  // about to hide and we wanna delay hiding
   860                 d->hasEffects && !parentItem()) { // only for popup without parent
   874                 d->hasEffects && !parentItem()) { // only for popup without parent
       
   875                 bool hideDelayed = d->delayedHide;
   861                 if (!d->hidingInProgress) { // Prevent reentrance
   876                 if (!d->hidingInProgress) { // Prevent reentrance
   862                     d->hidingInProgress = true;
   877                     d->hidingInProgress = true;
   863 #ifdef HB_EFFECTS
   878 #ifdef HB_EFFECTS
   864                     QRectF extRect(0.0,
   879                     QRectF extRect(0.0,
   865                                    -boundingRect().height(),
   880                                    -boundingRect().height(),
   871                                          QVariant(), extRect)) {
   886                                          QVariant(), extRect)) {
   872                         d->delayedHide = false;
   887                         d->delayedHide = false;
   873                     }
   888                     }
   874 #endif
   889 #endif
   875                 }
   890                 }
   876                 if (d->delayedHide) {
   891                 if (hideDelayed) {
   877                     return true;
   892                     return true;
   878                 } else {
   893                 } else {
   879                     d->delayedHide = d->hasEffects;
   894                     d->delayedHide = d->hasEffects;
   880                     d->hidingInProgress = false;
   895                     d->hidingInProgress = false;
   881                     // fallback to base class imp
   896                     // fallback to base class imp
   886         HbMainWindow* w(mainWindow());
   901         HbMainWindow* w(mainWindow());
   887         if ( w ){
   902         if ( w ){
   888             disconnect(this, SLOT(_q_orientationAboutToChange(Qt::Orientation, bool)));
   903             disconnect(this, SLOT(_q_orientationAboutToChange(Qt::Orientation, bool)));
   889             connect( w, SIGNAL(aboutToChangeOrientation(Qt::Orientation, bool)),
   904             connect( w, SIGNAL(aboutToChangeOrientation(Qt::Orientation, bool)),
   890                      this, SLOT(_q_orientationAboutToChange(Qt::Orientation, bool)) );
   905                      this, SLOT(_q_orientationAboutToChange(Qt::Orientation, bool)) );
   891             disconnect(this, SLOT(handlePopupPos()));
   906             disconnect(this, SLOT(_q_orientationChanged()));
   892             connect( w, SIGNAL(orientationChanged(Qt::Orientation)),
   907             connect( w, SIGNAL(orientationChanged(Qt::Orientation)),
   893                      this, SLOT(_q_orientationChanged()) );
   908                      this, SLOT(_q_orientationChanged()) );
   894         }
   909         }
   895     }
   910     }
   896     return HbWidget::itemChange(change, value);
   911     return HbWidget::itemChange(change, value);
   897 }
   912 }
   898 
   913 
   899 /*!
   914 /*!
       
   915  \deprecated HbPopup::handlePopupPos()
       
   916          is deprecated. This function should not be used from the application side.
   900  Handles the popup position when Orientation changes
   917  Handles the popup position when Orientation changes
   901 */
   918 */
   902 void HbPopup::handlePopupPos()
   919 void HbPopup::handlePopupPos()
   903 {
   920 {
   904     //Not used inside hbpopup, deprecate this(?)
   921     HB_DEPRECATED("HbPopup::handlePopupPos() is deprecated.");
   905     QEvent userEvent(QEvent::ContextMenu);
   922     QEvent userEvent(QEvent::ContextMenu);
   906     QCoreApplication::sendEvent(this, &userEvent);    
   923     QCoreApplication::sendEvent(this, &userEvent);    
   907 }
   924 }
   908 
   925 
   909 /*!
   926 /*!
  1067     }
  1084     }
  1068     d->memberToDisconnectOnClose.clear();
  1085     d->memberToDisconnectOnClose.clear();
  1069     HbWidget::closeEvent(event);
  1086     HbWidget::closeEvent(event);
  1070 }
  1087 }
  1071 
  1088 
       
  1089 
       
  1090 /* Currently, virtual keyboard must be able to position a popup
       
  1091    containing a editor to an arbitrary place. VKB does it's best to
       
  1092    reposition popup back to original position when needed. At least in
       
  1093    orientation switch the old position naturally is wrong, hence popup
       
  1094    must be relayouted.
       
  1095 
       
  1096    It would be unreasonable to make special checks for popup in vkb
       
  1097    side. It also would be unreasonable to do special checks for vkb in
       
  1098    popup side. Hence this semi-hidden dynamic property for
       
  1099    communicating this special case.
       
  1100 
       
  1101    WARNING: Do not count on this special behaviour, we might remove it
       
  1102    without prior notice. If you do require such a behavior, please
       
  1103    raise a feature request and we might make this a proper API.
       
  1104  */
       
  1105 const char* KPositionManagedByVKB("PositionManagedByVKB");
       
  1106 
  1072 /*!
  1107 /*!
  1073     \reimp
  1108     \reimp
  1074  */
  1109  */
  1075 bool HbPopup::event(QEvent *event)
  1110 bool HbPopup::event(QEvent *event)
  1076 {
  1111 {
  1077     Q_D(HbPopup);
  1112     Q_D(HbPopup);
  1078     if (event->type() == QEvent::LayoutRequest) {
  1113     if ( event->type() == QEvent::DynamicPropertyChange ) {
       
  1114         QVariant v(property(KPositionManagedByVKB));
       
  1115         if (v.isValid() ){
       
  1116             if (v.toBool()) {
       
  1117                 // position is now managed by vkb
       
  1118                 d->mOriginalAutoLayouting = d->mAutoLayouting;
       
  1119                 d->mAutoLayouting = false;
       
  1120             } else {
       
  1121                 d->mAutoLayouting = d->mOriginalAutoLayouting;
       
  1122 
       
  1123                 // vkb has finished, and we might be on totally wrong
       
  1124                 // place.
       
  1125                 QEvent layoutRequest = QEvent::LayoutRequest;
       
  1126                 QApplication::sendEvent(this, &layoutRequest);
       
  1127             }
       
  1128         }
       
  1129     } else if (event->type() == QEvent::LayoutRequest) {
  1079         //Workaround when showing first time                           
  1130         //Workaround when showing first time                           
  1080 #ifdef HB_EFFECTS
  1131 #ifdef HB_EFFECTS
  1081         if(d->mStartEffect && boundingRect().isValid()) {
  1132         if(d->mStartEffect && boundingRect().isValid()) {
  1082             d->mStartEffect = false;
  1133             d->mStartEffect = false;
  1083             QCoreApplication::sendPostedEvents(this, QEvent::LayoutRequest);
  1134             QCoreApplication::sendPostedEvents(this, QEvent::LayoutRequest);
  1109   HbPopup *popup = new HbPopup();
  1160   HbPopup *popup = new HbPopup();
  1110   ...
  1161   ...
  1111   popup->setPreferredPosition( QPointF(x,y), HbPopupBase::BottomEdgeCenter );
  1162   popup->setPreferredPosition( QPointF(x,y), HbPopupBase::BottomEdgeCenter );
  1112   popup->show();
  1163   popup->show();
  1113   \endcode
  1164   \endcode
  1114 
  1165  */
  1115  */
       
  1116 
       
  1117 void HbPopup::setPreferredPos( const QPointF& preferredPos,
  1166 void HbPopup::setPreferredPos( const QPointF& preferredPos,
  1118                                HbPopup::Placement placement )
  1167                                HbPopup::Placement placement )
  1119 {
  1168 {
  1120     Q_D(HbPopup);
  1169     Q_D(HbPopup);
  1121     bool layoutFlag = false;
  1170     bool layoutFlag = false;
  1133         QEvent layoutRequest = QEvent::LayoutRequest;
  1182         QEvent layoutRequest = QEvent::LayoutRequest;
  1134         QApplication::sendEvent(this, &layoutRequest);
  1183         QApplication::sendEvent(this, &layoutRequest);
  1135     }
  1184     }
  1136 }
  1185 }
  1137 
  1186 
       
  1187 /*!
       
  1188   \reimp
       
  1189   Returns the shape of this item as a QPainterPath.
       
  1190   */
  1138 QPainterPath HbPopup::shape() const
  1191 QPainterPath HbPopup::shape() const
  1139 {    
  1192 {    
  1140 #if 0
  1193 #if 0
  1141    /*Q_D(const HbPopup);
  1194    /*Q_D(const HbPopup);
  1142     if (backgroundItem() && d->mPath) {
  1195     if (backgroundItem() && d->mPath) {