src/hbcore/gui/hbpopup.cpp
changeset 30 80e4d18b72f5
parent 28 b7da29130b0e
equal deleted inserted replaced
28:b7da29130b0e 30:80e4d18b72f5
   279     {HbPopup::NoTimeout,0},
   279     {HbPopup::NoTimeout,0},
   280     {HbPopup::ConfirmationNoteTimeout,1500},
   280     {HbPopup::ConfirmationNoteTimeout,1500},
   281     {HbPopup::StandardTimeout,3000},
   281     {HbPopup::StandardTimeout,3000},
   282     {HbPopup::ContextMenuTimeout,6000},
   282     {HbPopup::ContextMenuTimeout,6000},
   283 };
   283 };
       
   284 
       
   285 /*
       
   286    Currently, virtual keyboard must be able to position a popup
       
   287    containing an editor to an arbitrary place. VKB does its best to
       
   288    reposition the popup back to original position when needed. At least in
       
   289    orientation switch the old position naturally is wrong, hence popup
       
   290    must be relayouted.
       
   291 
       
   292    It would be unreasonable to make special checks for popup in vkb
       
   293    side. It also would be unreasonable to do special checks for vkb in
       
   294    popup side. Hence this semi-hidden dynamic property for
       
   295    communicating this special case.
       
   296 
       
   297    WARNING: Do not count on this special behaviour, we might remove it
       
   298    without prior notice. If you do require such a behavior, please
       
   299    raise a feature request and we might make this a proper API.
       
   300  */
       
   301 const char* KPositionManagedByVKB("PositionManagedByVKB");
   284 
   302 
   285 /*
   303 /*
   286     \primitives
   304     \primitives
   287     \primitive{background} HbFrameItem representing the popup background. The background can be 
   305     \primitive{background} HbFrameItem representing the popup background. The background can be 
   288     weak or strong (different graphical styles) depending on popup type.
   306     weak or strong (different graphical styles) depending on popup type.
   422     itemFlags |= QGraphicsItem::ItemClipsChildrenToShape;
   440     itemFlags |= QGraphicsItem::ItemClipsChildrenToShape;
   423     itemFlags |= QGraphicsItem::ItemSendsGeometryChanges;
   441     itemFlags |= QGraphicsItem::ItemSendsGeometryChanges;
   424     itemFlags |= QGraphicsItem::ItemIsPanel;
   442     itemFlags |= QGraphicsItem::ItemIsPanel;
   425     q->setFlags(itemFlags);
   443     q->setFlags(itemFlags);
   426     q->setActive(false);
   444     q->setActive(false);
       
   445 
       
   446     q->setAcceptTouchEvents(true);
   427 }
   447 }
   428 
   448 
   429 void HbPopupPrivate::_q_appearEffectEnded(HbEffect::EffectStatus status)
   449 void HbPopupPrivate::_q_appearEffectEnded(HbEffect::EffectStatus status)
   430 {
   450 {
   431     Q_UNUSED(status);
   451     Q_UNUSED(status);
       
   452 }
       
   453 
       
   454 void HbPopupPrivate::_q_maskEffectDestroyed()
       
   455 {
       
   456     mVgMaskEffect = 0;
   432 }
   457 }
   433 
   458 
   434 CSystemToneService* HbPopupPrivate::systemToneService()
   459 CSystemToneService* HbPopupPrivate::systemToneService()
   435 {
   460 {
   436     return HbInstancePrivate::d_ptr()->systemTone();
   461     return HbInstancePrivate::d_ptr()->systemTone();
   484 
   509 
   485 void HbPopupPrivate::_q_orientationChanged()
   510 void HbPopupPrivate::_q_orientationChanged()
   486 {
   511 {
   487     Q_Q(HbPopup);
   512     Q_Q(HbPopup);
   488     if (q->isVisible() || q) {
   513     if (q->isVisible() || q) {
   489         QEvent userEvent(QEvent::ContextMenu);
   514         QEvent userEvent(QEvent::LayoutRequest);
   490         QCoreApplication::sendEvent(q, &userEvent);
   515         QCoreApplication::sendEvent(q, &userEvent);
   491     }
   516     }
   492 
   517 
   493     q->repolish();
   518     q->repolish();
   494 #ifdef HB_EFFECTS
   519 #ifdef HB_EFFECTS
   716             } else {
   741             } else {
   717                 delete mVgMaskEffect;
   742                 delete mVgMaskEffect;
   718                 mVgMaskEffect = 0;
   743                 mVgMaskEffect = 0;
   719             }
   744             }
   720         }
   745         }
       
   746         if (mVgMaskEffect) {
       
   747             // Make sure that mask effect is reset when destroyed
       
   748             QObject::connect(mVgMaskEffect, SIGNAL(destroyed()), q, SLOT(_q_maskEffectDestroyed()));
       
   749         }
   721     }
   750     }
   722     QPixmap image(q->backgroundItem()->boundingRect().size().toSize());
   751     QPixmap image(q->backgroundItem()->boundingRect().size().toSize());
   723     image.fill(Qt::transparent);
   752     image.fill(Qt::transparent);
   724     QPainter imagePainter(&image);
   753     QPainter imagePainter(&image);
   725     q->backgroundItem()->paint(&imagePainter, 0, 0);
   754     q->backgroundItem()->paint(&imagePainter, 0, 0);
   747 HbPopup::HbPopup(QGraphicsItem *parent) :
   776 HbPopup::HbPopup(QGraphicsItem *parent) :
   748     HbWidget(*new HbPopupPrivate,parent)
   777     HbWidget(*new HbPopupPrivate,parent)
   749 {
   778 {
   750     Q_D(HbPopup);
   779     Q_D(HbPopup);
   751     d->q_ptr = this;
   780     d->q_ptr = this;
   752     d->init();    
   781     d->init();
   753 }
   782 }
   754 
   783 
   755 
   784 
   756 /*!
   785 /*!
   757     \internal
   786     \internal
   759 HbPopup::HbPopup(HbPopupPrivate &dd, QGraphicsItem *parent) :
   788 HbPopup::HbPopup(HbPopupPrivate &dd, QGraphicsItem *parent) :
   760     HbWidget(dd, parent)
   789     HbWidget(dd, parent)
   761 {
   790 {
   762     Q_D(HbPopup);
   791     Q_D(HbPopup);
   763     d->q_ptr = this;
   792     d->q_ptr = this;
   764     d->init();    
   793     d->init();
   765 }
   794 }
   766 /*!
   795 /*!
   767     Destructor.
   796     Destructor.
   768 */
   797 */
   769 HbPopup::~HbPopup()
   798 HbPopup::~HbPopup()
   970  */
   999  */
   971 QVariant HbPopup::itemChange ( GraphicsItemChange change, const QVariant & value )
  1000 QVariant HbPopup::itemChange ( GraphicsItemChange change, const QVariant & value )
   972 {
  1001 {
   973     Q_D(HbPopup);
  1002     Q_D(HbPopup);
   974 
  1003 
   975     if (change == QGraphicsItem::ItemPositionChange) {
  1004     if (change == QGraphicsItem::ItemPositionChange) {        
       
  1005         // Skipping X-coordinate changes made by VKB since popupmanager handles popup to be in the
       
  1006         // center of the screen
       
  1007         if (property(KPositionManagedByVKB).isValid() && property(KPositionManagedByVKB).toBool() &&
       
  1008             !d->mAutoLayouting && value.isValid() && !value.toPointF().isNull()) {
       
  1009             QPointF newPointF(geometry().x(), value.toPointF().y());
       
  1010             d->mAutoLayouting = false;
       
  1011             return newPointF;
       
  1012         }
   976         d->mAutoLayouting = false;
  1013         d->mAutoLayouting = false;
   977     }
  1014     }
   978     if (change == QGraphicsItem::ItemVisibleHasChanged) {
  1015     if (change == QGraphicsItem::ItemVisibleHasChanged) {
   979         if (value.toBool()) {
  1016         if (value.toBool()) {
   980             if (d->hasEffects && boundingRect().isValid() && d->polished) {
  1017             if (d->hasEffects && boundingRect().isValid() && d->polished) {
  1222     }
  1259     }
  1223     d->memberToDisconnectOnClose.clear();
  1260     d->memberToDisconnectOnClose.clear();
  1224     HbWidget::closeEvent(event);
  1261     HbWidget::closeEvent(event);
  1225 }
  1262 }
  1226 
  1263 
  1227 
       
  1228 /*
       
  1229    Currently, virtual keyboard must be able to position a popup
       
  1230    containing an editor to an arbitrary place. VKB does its best to
       
  1231    reposition the popup back to original position when needed. At least in
       
  1232    orientation switch the old position naturally is wrong, hence popup
       
  1233    must be relayouted.
       
  1234 
       
  1235    It would be unreasonable to make special checks for popup in vkb
       
  1236    side. It also would be unreasonable to do special checks for vkb in
       
  1237    popup side. Hence this semi-hidden dynamic property for
       
  1238    communicating this special case.
       
  1239 
       
  1240    WARNING: Do not count on this special behaviour, we might remove it
       
  1241    without prior notice. If you do require such a behavior, please
       
  1242    raise a feature request and we might make this a proper API.
       
  1243  */
       
  1244 const char* KPositionManagedByVKB("PositionManagedByVKB");
       
  1245 
       
  1246 /*!
  1264 /*!
  1247     Reimplemented from QGraphicsWidget. 
  1265     Reimplemented from QGraphicsWidget. 
  1248  */
  1266  */
  1249 bool HbPopup::event(QEvent *event)
  1267 bool HbPopup::event(QEvent *event)
  1250 {
  1268 {
  1285             // of times but in this case we have to do it manually.
  1303             // of times but in this case we have to do it manually.
  1286             new HbPopupUpdater(this, this);
  1304             new HbPopupUpdater(this, this);
  1287         }
  1305         }
  1288 #endif //HB_EFFECTS
  1306 #endif //HB_EFFECTS
  1289         //workaround ends
  1307         //workaround ends
       
  1308     } else if (event->type() == QEvent::TouchBegin) {
       
  1309         // Accept all touch begin events to get the full Begin..End sequence
       
  1310         event->accept();
       
  1311         return true;
  1290     } else if (d->mGestureOverride && event->type() == QEvent::GestureOverride) {
  1312     } else if (d->mGestureOverride && event->type() == QEvent::GestureOverride) {
  1291         event->accept();
  1313         event->accept();
  1292         return true;
  1314         return true;
  1293     }
  1315     }
  1294 
  1316