src/hbcore/gui/hbpopup.cpp
changeset 7 923ff622b8b9
parent 6 c3690ec91ef8
child 21 4633027730f5
child 34 ed14f46c0e55
equal deleted inserted replaced
6:c3690ec91ef8 7:923ff622b8b9
    32 #include "hbgraphicsscene.h"
    32 #include "hbgraphicsscene.h"
    33 #include "hbgraphicsscene_p.h"
    33 #include "hbgraphicsscene_p.h"
    34 #include "hbtooltip.h"
    34 #include "hbtooltip.h"
    35 #include "hbglobal_p.h"
    35 #include "hbglobal_p.h"
    36 #include "hbvgmaskeffect_p.h"
    36 #include "hbvgmaskeffect_p.h"
       
    37 #include "hbvgchainedeffect_p.h"
    37 #include <QTimer>
    38 #include <QTimer>
    38 #include <QGraphicsSceneMouseEvent>
    39 #include <QGraphicsSceneMouseEvent>
    39 #include <QShowEvent>
    40 #include <QShowEvent>
    40 #include <QHideEvent>
    41 #include <QHideEvent>
    41 #include <QEventLoop>
    42 #include <QEventLoop>
    42 #include <QPointer>
    43 #include <QPointer>
    43 #include <QDebug>
    44 #include <QDebug>
    44 #include <QBitmap>
    45 #include <QBitmap>
       
    46 #include <hbinstance_p.h>
    45 #include <QApplication> // krazy:exclude=qclasses
    47 #include <QApplication> // krazy:exclude=qclasses
    46 
    48 
    47 #include <hbwidgetfeedback.h>
    49 #include <hbwidgetfeedback.h>
    48 
    50 
    49 #ifdef HB_EFFECTS
    51 #ifdef HB_EFFECTS
   301 {
   303 {
   302 }
   304 }
   303 
   305 
   304 HbPopupPrivate::~HbPopupPrivate()
   306 HbPopupPrivate::~HbPopupPrivate()
   305 {
   307 {
       
   308     stopTimeout();
       
   309     delete timeoutTimerInstance;
   306 }
   310 }
   307 
   311 
   308 void HbPopupPrivate::init()
   312 void HbPopupPrivate::init()
   309 {
   313 {
   310     Q_Q(HbPopup);
   314     Q_Q(HbPopup);
   311 
   315 
   312     q->setAttribute(Hb::InsidePopup);
   316     q->setAttribute(Hb::InsidePopup);
   313 
   317 
   314     // By default popups are focusable
   318     // By default popups are focusable
   315     q->setFocusPolicy(Qt::StrongFocus);    
   319     q->setFocusPolicy(Qt::StrongFocus);    
   316     q->setBackgroundItem(HbStyle::P_Popup_background);    
   320     setBackgroundItem(HbStyle::P_Popup_background);
       
   321     q->updatePrimitives();
       
   322 
   317 
   323 
   318     // Only for popup without parent
   324     // Only for popup without parent
   319     if (!q->parentItem()) {
   325     if (!q->parentItem()) {
   320         backgroundItem = new HbPopupBackGround(q);
   326         backgroundItem = new HbPopupBackGround(q);
   321         backgroundItem->setVisible(false);
   327         backgroundItem->setVisible(false);
   322 
   328 
   323         // Popup is invisible by default (explicit show or open call is required)
   329         // Popup is invisible by default (explicit show or open call is required)
   324         q->setVisible(false);
   330         q->setVisible(false);
   325     }
   331     }
   326     hidingInProgress = false;   
   332     hidingInProgress = false; 
   327 
   333     QGraphicsItem::GraphicsItemFlags itemFlags = q->flags();
   328     q->setFlag(QGraphicsItem::ItemClipsToShape);
   334     itemFlags |= QGraphicsItem::ItemClipsToShape;
   329     q->setFlag(QGraphicsItem::ItemClipsChildrenToShape);
   335     itemFlags |= QGraphicsItem::ItemClipsChildrenToShape;
   330 
   336     itemFlags |= QGraphicsItem::ItemSendsGeometryChanges;
   331 #if QT_VERSION > 0x040602
   337     //itemFlags |= QGraphicsItem::ItemIsPanel;
   332     q->grabGesture(Qt::TapGesture);
   338     q->setFlags(itemFlags);  
   333     q->grabGesture(Qt::TapAndHoldGesture);
   339 }
   334     q->grabGesture(Qt::PanGesture);
   340 void HbPopupPrivate::_q_appearEffectEnded(HbEffect::EffectStatus status)
   335     q->grabGesture(Qt::SwipeGesture);
   341 {
   336     q->grabGesture(Qt::PinchGesture);
   342 	Q_UNUSED(status);
   337 #endif
   343 }
   338 
   344 
   339 }
   345 CSystemToneService* HbPopupPrivate::systemToneService()
   340 
   346 {
       
   347 	return HbInstancePrivate::d_ptr()->systemTone();
       
   348 }
   341 /*
   349 /*
   342  Sets the priority for a popup.
   350  Sets the priority for a popup.
   343  A popup with higher priority is always shown on top of a popup with lower priority.
   351  A popup with higher priority is always shown on top of a popup with lower priority.
   344  In case of popups with same priority the lastly shown will be on top.
   352  In case of popups with same priority the lastly shown will be on top.
   345  Default priority is HbPopup::Default
   353  Default priority is HbPopup::Default
   440 
   448 
   441 QTimer *HbPopupPrivate::timeoutTimer()
   449 QTimer *HbPopupPrivate::timeoutTimer()
   442 {
   450 {
   443     Q_Q(HbPopup);
   451     Q_Q(HbPopup);
   444     if (!timeoutTimerInstance) {
   452     if (!timeoutTimerInstance) {
   445         timeoutTimerInstance = new QTimer(q);
   453         timeoutTimerInstance = new QTimer();
   446         timeoutTimerInstance->setSingleShot(true);
   454         timeoutTimerInstance->setSingleShot(true);
   447         q->connect(timeoutTimerInstance, SIGNAL(timeout()), q, SLOT(_q_timeoutFinished()));
   455         q->connect(timeoutTimerInstance, SIGNAL(timeout()), q, SLOT(_q_timeoutFinished()));
   448     }
   456     }
   449 
   457 
   450     return timeoutTimerInstance;
   458     return timeoutTimerInstance;
   576 
   584 
   577 void HbPopupPrivate::calculateShape()
   585 void HbPopupPrivate::calculateShape()
   578 {
   586 {
   579 #if 0
   587 #if 0
   580     Q_Q(HbPopup);
   588     Q_Q(HbPopup);
       
   589     // Contrary to the name, HbVgMaskEffect has a software
       
   590     // implementation too, and we will actually force the usage of
       
   591     // that here, ignoring the pure OpenVG version.
   581     if (!mVgMaskEffect) {
   592     if (!mVgMaskEffect) {
   582         mVgMaskEffect = new HbVgMaskEffect();
   593         mVgMaskEffect = new HbVgMaskEffect;
   583         mVgMaskEffect->install(q);
   594         // Masking does not work reliably on HW.
   584     }
   595         mVgMaskEffect->setForceSwMode(true);
   585 
   596         // There may be children (like the scroll area in menus) that
       
   597         // would mess up the masking so exclude those.
       
   598         mVgMaskEffect->setIncludeSourceItemOnly(true);
       
   599         if (!q->graphicsEffect()) {
       
   600             // Attach the effect. Ownership is transferred to q.
       
   601             mVgMaskEffect->install(q);
       
   602         } else {
       
   603             // Avoid replacing already set effects. Do not mask if
       
   604             // this is not possible, otherwise we would unexpectedly
       
   605             // delete the previously set graphics effect.
       
   606             HbVgChainedEffect *c = qobject_cast<HbVgChainedEffect *>(q->graphicsEffect());
       
   607             if (c) {
       
   608                 c->add(mVgMaskEffect);
       
   609             } else {
       
   610                 delete mVgMaskEffect;
       
   611             }
       
   612         }
       
   613     }
   586     QPixmap image(QSize(static_cast<int>(q->backgroundItem()->boundingRect().width()),
   614     QPixmap image(QSize(static_cast<int>(q->backgroundItem()->boundingRect().width()),
   587                             static_cast<int>(q->backgroundItem()->boundingRect().height())));
   615                         static_cast<int>(q->backgroundItem()->boundingRect().height())));
   588     image.fill(Qt::transparent);
   616     image.fill(Qt::transparent);
   589 
       
   590     QPainter imagePainter(&image);
   617     QPainter imagePainter(&image);
   591 
       
   592     q->backgroundItem()->paint(&imagePainter, 0, 0);
   618     q->backgroundItem()->paint(&imagePainter, 0, 0);
   593 
       
   594     imagePainter.end();
   619     imagePainter.end();
   595 
       
   596     mVgMaskEffect->setMask(image);
   620     mVgMaskEffect->setMask(image);
   597 
       
   598 #endif
   621 #endif
   599 }
   622 }
   600 
   623 
   601 /*!
   624 /*!
   602  Constructs a popup with given  \a parent graphics item.\n
   625  Constructs a popup with given  \a parent graphics item.\n
   787 {
   810 {
   788     Q_D(HbPopup);
   811     Q_D(HbPopup);
   789     if ( d->frameType != frameType ) {
   812     if ( d->frameType != frameType ) {
   790         switch( frameType ) {
   813         switch( frameType ) {
   791         case HbPopup::Weak:
   814         case HbPopup::Weak:
   792             setBackgroundItem(HbStyle::P_Popup_background_weak);
   815             d->setBackgroundItem(HbStyle::P_Popup_background_weak);
   793             break;
   816             break;
   794         case HbPopup::Strong:
   817         case HbPopup::Strong:
   795         default:
   818         default:
   796             setBackgroundItem(HbStyle::P_Popup_background);
   819             d->setBackgroundItem(HbStyle::P_Popup_background);
   797             break;
   820             break;
   798         }
   821         }
   799         d->frameType = frameType;
   822         d->frameType = frameType;
   800         updatePrimitives();
   823         updatePrimitives();
   801     }
   824     }
   840 #ifdef HB_EFFECTS
   863 #ifdef HB_EFFECTS
   841                 QRectF extRect(0.0,
   864                 QRectF extRect(0.0,
   842                                -boundingRect().height(),
   865                                -boundingRect().height(),
   843                                boundingRect().width(),
   866                                boundingRect().width(),
   844                                0);
   867                                0);
       
   868                 d->mStartEffect = true;
   845                 HbEffect::cancel(this);
   869                 HbEffect::cancel(this);
   846                 HbEffect::start(this, d->effectType, "appear", 0, 0, QVariant(), extRect);
   870                 d->mStartEffect = false;
       
   871                 HbEffect::start(this, d->effectType, "appear", this, "_q_appearEffectEnded", QVariant(), extRect);
   847 #endif//HB_EFFECTS
   872 #endif//HB_EFFECTS
   848                 d->mStartEffect = false;
       
   849             } else {
   873             } else {
   850                 d->mStartEffect = true;
   874                 d->mStartEffect = true;
   851             }
   875             }
   852         }
   876         }
   853     }
   877     }
   883                     HbEffect::cancel(this);
   907                     HbEffect::cancel(this);
   884                     if (!HbEffect::start(this, d->effectType, "disappear",
   908                     if (!HbEffect::start(this, d->effectType, "disappear",
   885                                          this, "_q_delayedHide",
   909                                          this, "_q_delayedHide",
   886                                          QVariant(), extRect)) {
   910                                          QVariant(), extRect)) {
   887                         d->delayedHide = false;
   911                         d->delayedHide = false;
       
   912                         return HbWidget::itemChange(change, value);
   888                     }
   913                     }
   889 #endif
   914 #endif
   890                 }
   915                 }
   891                 if (hideDelayed) {
   916                 if (hideDelayed) {
   892                     return true;
   917                     return true;
   905                      this, SLOT(_q_orientationAboutToChange(Qt::Orientation, bool)) );
   930                      this, SLOT(_q_orientationAboutToChange(Qt::Orientation, bool)) );
   906             disconnect(this, SLOT(_q_orientationChanged()));
   931             disconnect(this, SLOT(_q_orientationChanged()));
   907             connect( w, SIGNAL(orientationChanged(Qt::Orientation)),
   932             connect( w, SIGNAL(orientationChanged(Qt::Orientation)),
   908                      this, SLOT(_q_orientationChanged()) );
   933                      this, SLOT(_q_orientationChanged()) );
   909         }
   934         }
       
   935 
   910     }
   936     }
   911     return HbWidget::itemChange(change, value);
   937     return HbWidget::itemChange(change, value);
   912 }
   938 }
   913 
   939 
   914 /*!
   940 /*!
   983         //check if popup needs to be added to scene.This can result in duplciate show event,
  1009         //check if popup needs to be added to scene.This can result in duplciate show event,
   984         // if popup is added to scene here.
  1010         // if popup is added to scene here.
   985         if(d->addPopupToScene()) {
  1011         if(d->addPopupToScene()) {
   986               d->duplicateShowEvent = true;
  1012               d->duplicateShowEvent = true;
   987         }
  1013         }
       
  1014         //setActive(true);
   988         // Popup clears closed state
  1015         // Popup clears closed state
   989         d->closed = false;
  1016         d->closed = false;
   990         if (d->backgroundItem) {
  1017         if (d->backgroundItem) {
   991             d->backgroundItem->setVisible(true);
  1018             d->backgroundItem->setVisible(true);
   992             d->backgroundItem->setAcceptHoverEvents(isModal());
  1019             d->backgroundItem->setAcceptHoverEvents(isModal());
  1046  */
  1073  */
  1047 void HbPopup::resizeEvent( QGraphicsSceneResizeEvent * event )
  1074 void HbPopup::resizeEvent( QGraphicsSceneResizeEvent * event )
  1048 {    
  1075 {    
  1049     HbWidget::resizeEvent(event);
  1076     HbWidget::resizeEvent(event);
  1050     updatePrimitives();
  1077     updatePrimitives();
  1051 #if 1
       
  1052     Q_D(HbPopup);
  1078     Q_D(HbPopup);
  1053     if (d->polished) {
  1079     if (d->polished) {
  1054         d->calculateShape();
  1080         d->calculateShape();
  1055     }
  1081     }
  1056 #endif
       
  1057 }
  1082 }
  1058 
  1083 
  1059 /*!
  1084 /*!
  1060     \reimp
  1085     \reimp
  1061  */
  1086  */
  1134             QCoreApplication::sendPostedEvents(this, QEvent::LayoutRequest);
  1159             QCoreApplication::sendPostedEvents(this, QEvent::LayoutRequest);
  1135             QRectF extRect(0.0,
  1160             QRectF extRect(0.0,
  1136                            -boundingRect().height(),
  1161                            -boundingRect().height(),
  1137                            boundingRect().width(),
  1162                            boundingRect().width(),
  1138                            0);
  1163                            0);
       
  1164             d->mStartEffect = true;
  1139             HbEffect::cancel(this);
  1165             HbEffect::cancel(this);
  1140             HbEffect::start(this, d->effectType, "appear", 0, 0, QVariant(), extRect);            
  1166             d->mStartEffect = false;
       
  1167             HbEffect::start(this, d->effectType, "appear", this, "_q_appearEffectEnded", QVariant(), extRect);            
  1141         }
  1168         }
  1142 #endif//HB_EFFECTS
  1169 #endif//HB_EFFECTS
  1143         //workaround ends
  1170         //workaround ends
  1144     }    
  1171     }
  1145     return HbWidget::event(event);
  1172     return HbWidget::event(event);
  1146 }
  1173 }
  1147 
  1174 
  1148 /*!
  1175 /*!
  1149   Sets preferred position\a position for popup with \a placement
  1176   Sets preferred position\a position for popup with \a placement