camerauis/cameraxui/cxui/src/cxuiselftimer.cpp
changeset 29 699651f2666f
parent 21 fa6d9f75d6a6
child 32 5c1e3c6aa4ef
equal deleted inserted replaced
24:2094593137f5 29:699651f2666f
    35     CxuiSelfTimer class handles the selftimer countdown and updates widgets
    35     CxuiSelfTimer class handles the selftimer countdown and updates widgets
    36     accordingly.
    36     accordingly.
    37 */
    37 */
    38 
    38 
    39 // constants
    39 // constants
       
    40 
    40 const int CONTINUOUS_POSTCAPTURE    = -1;
    41 const int CONTINUOUS_POSTCAPTURE    = -1;
    41 const int UNKNOWN                   = -99;
    42 const int UNKNOWN                   = -99;
       
    43 
       
    44 const static QString SELFTIMER_SOUND = "z:\\system\\sounds\\digital\\selftimer.wav";
    42 
    45 
    43 CxuiSelfTimer::CxuiSelfTimer(CxeSettings &settings)
    46 CxuiSelfTimer::CxuiSelfTimer(CxeSettings &settings)
    44 :  mDelay(-1),
    47 :  mDelay(-1),
    45    mCounter(0),
    48    mCounter(0),
    46    mTimer(this),
    49    mTimer(this),
    47    mOldPostCaptureTimeOut(UNKNOWN),
    50    mOldPostCaptureTimeOut(UNKNOWN),
    48    mWidgetContainer(NULL),
    51    mWidgetContainer(NULL),
    49    mTimerLabel(NULL),
    52    mTimerLabel(NULL),
    50    mCancelButton(NULL),
    53    mCancelButton(NULL),
    51    mStartButton(NULL),
    54    mStartButton(NULL),
    52    mSettings(settings)
    55    mSettings(settings),
       
    56    mSound(SELFTIMER_SOUND)
    53 {
    57 {
    54     CX_DEBUG_ENTER_FUNCTION();
    58     CX_DEBUG_ENTER_FUNCTION();
    55 
    59 
    56     connect(&mTimer, SIGNAL(timeout()), this, SLOT(timeout()));
    60     connect(&mTimer, SIGNAL(timeout()), this, SLOT(timeout()));
    57     mTimer.setSingleShot(false);
    61     mTimer.setSingleShot(false);
   171     // Update now to have better looking user experience,
   175     // Update now to have better looking user experience,
   172     // especially when counter elapses: "0" is updated before emitting event,
   176     // especially when counter elapses: "0" is updated before emitting event,
   173     // so the UI seems to update smoother.
   177     // so the UI seems to update smoother.
   174     updateWidgets();
   178     updateWidgets();
   175 
   179 
       
   180     playSound();
       
   181 
   176     // Check if timer ran out
   182     // Check if timer ran out
   177     if (mCounter >= mDelay) {
   183     if (mCounter >= mDelay) {
   178         mTimer.stop();
   184         mTimer.stop();
       
   185         mSound.stop();
       
   186         hideWidgets();
   179         emit timerFinished();
   187         emit timerFinished();
   180     }
   188     }
   181 
   189 
   182     CX_DEBUG_EXIT_FUNCTION();
   190     CX_DEBUG_EXIT_FUNCTION();
   183 }
   191 }
   184 
   192 
   185 /*!
   193 /*!
   186     Slot for resetting the selftimer countdown. Countdown is stopped,
   194  * Play selftimer sound.
   187     and set back to starting value. Start button is set enabled.
   195  */
   188 
   196 void CxuiSelfTimer::playSound()
   189  */
   197 {
   190 void CxuiSelfTimer::reset()
   198     CX_DEBUG_ENTER_FUNCTION();
   191 {
   199 
   192     CX_DEBUG_ENTER_FUNCTION();
   200     int timeLeft = mDelay - mCounter;
   193     reset(true);
   201 
       
   202     if (timeLeft <= 3) {
       
   203         // play as fast as we can
       
   204         if (mSound.isFinished()) {
       
   205             mSound.setLoops(-1);
       
   206             mSound.play();
       
   207         }
       
   208     } else if (timeLeft <= 10) {
       
   209         // play every second
       
   210         mSound.setLoops(1);
       
   211         mSound.play();
       
   212     } else {
       
   213         // play once every two seconds
       
   214         if (mCounter%2) {
       
   215             mSound.setLoops(1);
       
   216             mSound.play();
       
   217         }
       
   218     }
       
   219 
   194     CX_DEBUG_EXIT_FUNCTION();
   220     CX_DEBUG_EXIT_FUNCTION();
   195 }
   221 }
   196 
   222 
   197 /*!
   223 /*!
   198      Slot for starting the countdown. Show postcapture setting is set to
   224      Slot for starting the countdown. Show postcapture setting is set to
   219         mStartButton->setEnabled(false);
   245         mStartButton->setEnabled(false);
   220     }
   246     }
   221 
   247 
   222     // start countdown
   248     // start countdown
   223     mCounter = 0;
   249     mCounter = 0;
       
   250     playSound();
   224     mTimer.start(1000); // 1000 milliseconds == 1 second
   251     mTimer.start(1000); // 1000 milliseconds == 1 second
   225 
   252 
   226     CX_DEBUG_EXIT_FUNCTION();
   253     CX_DEBUG_EXIT_FUNCTION();
   227 }
   254 }
   228 
   255 
   260  */
   287  */
   261 void CxuiSelfTimer::reset(bool update)
   288 void CxuiSelfTimer::reset(bool update)
   262 {
   289 {
   263     // Stop timer and reset counter.
   290     // Stop timer and reset counter.
   264     mTimer.stop();
   291     mTimer.stop();
       
   292     mSound.stop();
   265     mCounter = 0;
   293     mCounter = 0;
   266 
   294 
   267     // Set start buttonback to enabled.
   295     // Set start buttonback to enabled.
   268     if (mStartButton) {
   296     if (mStartButton) {
   269         mStartButton->setEnabled(true);
   297         mStartButton->setEnabled(true);