camerauis/cameraxui/cxui/src/cxuistandby.cpp
changeset 36 b12f3922a74f
parent 21 fa6d9f75d6a6
equal deleted inserted replaced
32:5c1e3c6aa4ef 36:b12f3922a74f
    18 #include <QTimer>
    18 #include <QTimer>
    19 #include <QApplication>
    19 #include <QApplication>
    20 #include <QGraphicsSceneEvent>
    20 #include <QGraphicsSceneEvent>
    21 #include <hblabel.h>
    21 #include <hblabel.h>
    22 #include <hbdialog.h>
    22 #include <hbdialog.h>
       
    23 #include <hbinstantfeedback.h>
    23 #include <QGraphicsRectItem>
    24 #include <QGraphicsRectItem>
    24 #include <QColor>
    25 #include <QColor>
    25 
    26 
    26 #include "cxutils.h"
    27 #include "cxutils.h"
    27 #include "cxeengine.h"
    28 #include "cxeengine.h"
    33 #include "cxestillcapturecontrol.h"
    34 #include "cxestillcapturecontrol.h"
    34 #include "cxevideocapturecontrol.h"
    35 #include "cxevideocapturecontrol.h"
    35 
    36 
    36 
    37 
    37 
    38 
    38 /*
    39 /*!
    39 * CxuiStandby::CxuiStandby
    40  * Constructor
    40 */
    41  */
    41 CxuiStandby::CxuiStandby(CxuiCaptureKeyHandler &keyHandler,CxuiDocumentLoader *documentLoader, CxeEngine *engine)
    42 CxuiStandby::CxuiStandby(CxuiCaptureKeyHandler &keyHandler,CxuiDocumentLoader *documentLoader, CxeEngine *engine)
    42 : mKeyHandler(keyHandler),
    43 : mKeyHandler(keyHandler),
    43   mDocumentLoader(documentLoader),
    44   mDocumentLoader(documentLoader),
    44   mEngine(engine),
    45   mEngine(engine),
    45   mStandbyPopup(NULL),
    46   mStandbyPopup(NULL),
    46   mStandbyDialogVisible(false)
    47   mStandbyDialogVisible(false),
       
    48   mAllowDismiss(true)
    47 {
    49 {
    48     CX_DEBUG_ENTER_FUNCTION();
    50     CX_DEBUG_ENTER_FUNCTION();
    49     CX_ASSERT_ALWAYS(engine);
    51     CX_ASSERT_ALWAYS(engine);
    50 
    52 
    51     // initialize standby timer
    53     // initialize standby timer
    53 
    55 
    54     // install event filter for application wide events
    56     // install event filter for application wide events
    55     QCoreApplication::instance()->installEventFilter(this);
    57     QCoreApplication::instance()->installEventFilter(this);
    56 
    58 
    57     CX_ASSERT_ALWAYS(mStandbyTimer);
    59     CX_ASSERT_ALWAYS(mStandbyTimer);
    58     connect(mStandbyTimer, SIGNAL(timeout()), this, SLOT(toStandby()));
    60     connect(mStandbyTimer, SIGNAL(timeout()), this, SLOT(enterStandby()));
    59     mStandbyTimer->setSingleShot(true);
    61     mStandbyTimer->setSingleShot(true);
    60 
    62 
    61     CX_DEBUG_EXIT_FUNCTION();
    63     CX_DEBUG_EXIT_FUNCTION();
    62 }
    64 }
    63 
    65 
    64 
    66 
    65 
    67 
    66 /*
    68 /*!
    67 * CxuiStandby::~CxuiStandby()
    69  * Destructor
    68 */
    70  */
    69 CxuiStandby::~CxuiStandby()
    71 CxuiStandby::~CxuiStandby()
    70 {
    72 {
    71     CX_DEBUG_IN_FUNCTION();
    73     CX_DEBUG_IN_FUNCTION();
    72     // remove the event filter
    74     // remove the event filter
    73     QCoreApplication::instance()->removeEventFilter(this);
    75     QCoreApplication::instance()->removeEventFilter(this);
    74     // stop standby timer
    76     // stop standby timer
    75     stopTimer();
    77     stopTimer();
    76 }
    78 }
    77 
    79 
    78 
    80 
    79 /*
    81 /*!
    80 * stops standby timer
    82 * Allow dismissing standby mode with AF or capture key?
       
    83 * @param allow Is dismissing allowed.
    81 */
    84 */
       
    85 void CxuiStandby::allowDismiss(bool allow)
       
    86 {
       
    87     CX_DEBUG_ENTER_FUNCTION();
       
    88     mAllowDismiss = allow;
       
    89     if (allow) {
       
    90         if (mStandbyDialogVisible) {
       
    91             // Reconnect the close signals if dialog is visible
       
    92             connect(&mKeyHandler, SIGNAL(autofocusKeyPressed()), mStandbyPopup, SLOT(close()), Qt::UniqueConnection);
       
    93             connect(&mKeyHandler, SIGNAL(captureKeyPressed()),   mStandbyPopup, SLOT(close()), Qt::UniqueConnection);
       
    94         }
       
    95     } else {
       
    96         disconnect(&mKeyHandler, SIGNAL(autofocusKeyPressed()), mStandbyPopup, SLOT(close()));
       
    97         disconnect(&mKeyHandler, SIGNAL(captureKeyPressed()),   mStandbyPopup, SLOT(close()));
       
    98     }
       
    99 
       
   100     CX_DEBUG_EXIT_FUNCTION();
       
   101 }
       
   102 
       
   103 
       
   104 /*!
       
   105 * Is standby mode active?
       
   106 * @return True, if standby mode is active, false if not.
       
   107 */
       
   108 bool CxuiStandby::isActive() const
       
   109 {
       
   110     return mStandbyDialogVisible;
       
   111 }
       
   112 
       
   113 /*!
       
   114  * stops standby timer
       
   115  */
    82 void CxuiStandby::stopTimer()
   116 void CxuiStandby::stopTimer()
    83 {
   117 {
    84     if(mStandbyTimer) {
   118     if(mStandbyTimer) {
    85         mStandbyTimer->stop();
   119         mStandbyTimer->stop();
    86     }
   120     }
    87 }
   121 }
    88 
   122 
    89 /*
   123 /*!
    90 * starts standby timer
   124  * starts standby timer
    91 */
   125  */
    92 void CxuiStandby::startTimer()
   126 void CxuiStandby::startTimer()
    93 {
   127 {
    94     if(mStandbyTimer) {
   128     if(mStandbyTimer) {
    95         mStandbyTimer->start(CXUI_STANDBY_CAMERA_TIMEOUT);
   129         mStandbyTimer->start(CXUI_STANDBY_CAMERA_TIMEOUT);
    96     }
   130     }
    97 }
   131 }
    98 
   132 
    99 
   133 /*!
   100 /*
   134  * Handles mouse press events
   101 * handles mouse press events
   135  * returns if mouse key press is consumed.
   102 * returns if mouse key press is consumed.
   136  * \param event event to be handled
   103 */
   137  * \return boolean to indicate whether the event was handled or not
   104 bool CxuiStandby::handleMouseEvent()
   138  */
       
   139 bool CxuiStandby::handleMouseEvent(QEvent *event)
   105 {
   140 {
   106     bool keyHandled = false;
   141     bool keyHandled = false;
   107 
   142 
   108     // close the dialog if it's visible
   143     // close the dialog if it's visible
   109     if (mStandbyDialogVisible && mStandbyPopup) {
   144     if (mStandbyDialogVisible && mStandbyPopup) {
   110         CX_DEBUG(( "closing the popup mStandbyDialogVisible = : %d", mStandbyDialogVisible ));
   145         HbInstantFeedback feedback(HbFeedback::BasicItem);
   111         mStandbyPopup->close();
   146         switch (event->type()) {
       
   147             case QEvent::GraphicsSceneMousePress:
       
   148                 feedback.play();
       
   149                 break;
       
   150             case QEvent::GraphicsSceneMouseRelease:
       
   151                 if (mAllowDismiss) {
       
   152                     CX_DEBUG(( "closing the popup mStandbyDialogVisible = : %d", mStandbyDialogVisible ));
       
   153                     // todo: sound disabling doesn't work in orbit yet so don't do feedback on release
       
   154                     // needs to be enabled when orbit support is done
       
   155                     //feedback.setModalities(HbFeedback::Tactile);
       
   156                     //feedback.play();
       
   157                     exitStandby();
       
   158                 }
       
   159                 break;
       
   160             default:
       
   161                 break;
       
   162         }
       
   163         // eat all mouse events when standby is active
   112         keyHandled = true;
   164         keyHandled = true;
   113     } else if (mStandbyTimer && mStandbyTimer->isActive()) {
   165     } else if (mStandbyTimer && mStandbyTimer->isActive()) {
   114         // restart the timer only if it's running
   166         // restart the timer only if it's running
   115         startTimer();
   167         startTimer();
   116     }
   168     }
   117 
   169 
   118     return keyHandled;
   170     return keyHandled;
   119 }
   171 }
   120 
   172 
   121 
   173 
   122 /*
   174 /*!
   123 * switching to standby.
   175  * switching to standby.
   124 */
   176  */
   125 void CxuiStandby::toStandby()
   177 void CxuiStandby::enterStandby()
   126 {
   178 {
   127     CX_DEBUG_ENTER_FUNCTION();
   179     CX_DEBUG_ENTER_FUNCTION();
   128 
   180 
   129     if (proceedToStandy()) {
   181     if (proceedToStandy()) {
   130 
   182 
   163 
   215 
   164         CX_ASSERT_ALWAYS(mStandbyPopup);
   216         CX_ASSERT_ALWAYS(mStandbyPopup);
   165 
   217 
   166         mStandbyPopup->show();
   218         mStandbyPopup->show();
   167         // connecting half press or full press key signal to dismiss standby
   219         // connecting half press or full press key signal to dismiss standby
   168         connect(&mKeyHandler, SIGNAL(autofocusKeyPressed()), mStandbyPopup, SLOT(close()));
   220         connect(&mKeyHandler, SIGNAL(autofocusKeyPressed()), mStandbyPopup, SLOT(close()), Qt::UniqueConnection);
   169         connect(&mKeyHandler, SIGNAL(captureKeyPressed()),   mStandbyPopup, SLOT(close()));
   221         connect(&mKeyHandler, SIGNAL(captureKeyPressed()),   mStandbyPopup, SLOT(close()), Qt::UniqueConnection);
   170     }
   222     }
   171 
   223 
   172     CX_DEBUG_EXIT_FUNCTION();
   224     CX_DEBUG_EXIT_FUNCTION();
   173 }
   225 }
   174 
   226 
   175 
   227 /*!
   176 /*
   228 * Close the standby dialog.
   177 * dismisses standby
       
   178 */
   229 */
       
   230 void CxuiStandby::exitStandby()
       
   231 {
       
   232     CX_DEBUG_ENTER_FUNCTION();
       
   233 
       
   234     if (mAllowDismiss && mStandbyDialogVisible && mStandbyPopup) {
       
   235         mStandbyPopup->close();
       
   236     }
       
   237 
       
   238     CX_DEBUG_EXIT_FUNCTION();
       
   239 }
       
   240 
       
   241 
       
   242 /*!
       
   243  * dismisses standby
       
   244  */
   179 void CxuiStandby::dismissStandby()
   245 void CxuiStandby::dismissStandby()
   180 {
   246 {
   181     CX_DEBUG_ENTER_FUNCTION();
   247     CX_DEBUG_ENTER_FUNCTION();
   182 
   248 
   183     if(mStandbyDialogVisible) {
   249     if(mStandbyDialogVisible) {
   192     CX_DEBUG_EXIT_FUNCTION();
   258     CX_DEBUG_EXIT_FUNCTION();
   193 }
   259 }
   194 
   260 
   195 
   261 
   196 
   262 
   197 /*
   263 /*!
   198 * checks if we can swtich to standby
   264  * checks if we can switch to standby
   199 */
   265  */
   200 bool CxuiStandby::proceedToStandy()
   266 bool CxuiStandby::proceedToStandy()
   201 {
   267 {
   202     CX_DEBUG_ENTER_FUNCTION();
   268     CX_DEBUG_ENTER_FUNCTION();
   203     CX_ASSERT_ALWAYS(mEngine);
   269     CX_ASSERT_ALWAYS(mEngine);
   204 
   270 
   205     bool ok = false;
   271     bool ok = false;
   206     if(!mStandbyDialogVisible &&
   272     if (!mStandbyDialogVisible) {
   207         mEngine->isEngineReady()) {
       
   208         CX_DEBUG(("show standby dialog"));
   273         CX_DEBUG(("show standby dialog"));
   209         ok = true;
   274         ok = true;
   210     }
   275     }
   211 
   276 
   212     CX_DEBUG(( "CxuiStandby::proceedToStandy proceedToStandy: %d", ok ));
   277     CX_DEBUG(( "CxuiStandby::proceedToStandy proceedToStandy: %d", ok ));
   214     return ok;
   279     return ok;
   215 }
   280 }
   216 
   281 
   217 
   282 
   218 
   283 
   219 /*
   284 /*!
   220 *  Event filter which filters application wide mouse events.
   285  *  Event filter which filters application wide mouse events.
   221 */
   286  */
   222 
       
   223 bool CxuiStandby::eventFilter(QObject *object, QEvent *event)
   287 bool CxuiStandby::eventFilter(QObject *object, QEvent *event)
   224 {
   288 {
   225     Q_UNUSED(object);
   289     Q_UNUSED(object);
   226 
   290 
   227     bool eventWasConsumed = false;
   291     bool eventWasConsumed = false;
   228     switch (event->type()) {
   292     switch (event->type()) {
   229         case QEvent::GraphicsSceneMouseMove:
   293         case QEvent::GraphicsSceneMouseMove:
   230         case QEvent::GraphicsSceneMousePress:
   294         case QEvent::GraphicsSceneMousePress:
   231         case QEvent::GraphicsSceneMouseRelease:
   295         case QEvent::GraphicsSceneMouseRelease:
   232             eventWasConsumed = handleMouseEvent();
   296             eventWasConsumed = handleMouseEvent(event);
   233             break;
   297             break;
   234         default:
   298         default:
   235             break;
   299             break;
   236     }
   300     }
   237     return eventWasConsumed;
   301     return eventWasConsumed;