Ejemplo n.º 1
0
void Tomato::updateTimer()
{
    elapsedSec += 1;

    QTime currentTime(0,elapsedSec/60,elapsedSec%60,0);
    trayIcon->setToolTip(currentTime.toString("mm:ss"));

    // time's up
    if (FOCUS == state && elapsedSec/60 >= focusDuration) {
        timer->stop();
        elapsedSec = 0;
        trayIcon->showMessage("Tomato",
                              "Focus time's up!\nTake a rest~~",
                              QIcon(":/tomato"),
                              1000);
        state = REST;
        setIconState(REST);
        startRest();
    }
    else if (REST == state && elapsedSec/60 >= restDuration) {
        timer->stop();
        elapsedSec = 0;
        trayIcon->showMessage("Tomato",
                              "Rest time's up!\nNeed another round?",
                              QIcon(":/coffee"),
                              1000);
        state = IDLE;
        setIconState(IDLE);

        if ( ui->checkInfinity->isChecked() ) { // infinity mode
            startTomato();
        }
    }
}
void PomodoroTimerApplication::onTimer()
{
    --mMinutesLeft;

    if (mMinutesLeft == 0)
    {
        QSound::play(NotificationSoundPath);
        showEndMessage(mCurrentState);

        switch (mCurrentState)
        {
        case (PomodoroState::Work):
            startRest();
            break;
        case (PomodoroState::Rest):
            startIdle();
            break;
        default:
            Q_ASSERT(false);
        }
    }

    updateSystemTrayIcon();
}